Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
Ocarina
Commits
0034174c
Commit
0034174c
authored
May 11, 2019
by
Rahma BOUAZIZ
Committed by
yoogx
May 11, 2019
Browse files
* Clean the C AST, improve the generation of C expressions
For openaadl/ocarina#190
parent
5757bf49
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/backends/ast_c/ocarina-backends-c_tree-generator.adb
View file @
0034174c
...
...
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-201
7
ESA & ISAE. --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-201
9
ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
...
...
@@ -665,6 +665,10 @@ package body Ocarina.Backends.C_Tree.Generator is
Write
(
Tok_Asterisk
);
end
if
;
if
Is_Variable_Address
(
N
)
then
Write
(
Tok_Ampersand
);
end
if
;
Write_Name
(
Name
(
N
));
end
Generate_Defining_Identifier
;
...
...
@@ -680,11 +684,53 @@ package body Ocarina.Backends.C_Tree.Generator is
-- Each expression having a right part and a left part is
-- systematically put between two parentheses.
Generate
(
L_Expr
);
Write_Space
;
Write_Name
(
Operator_Image
(
Standard
.
Integer
(
Op
)));
Write_Space
;
Generate
(
R_Expr
);
if
Get_Name_String
(
Operator_Image
(
Standard
.
Integer
(
Op
)))
=
"*"
or
else
Get_Name_String
(
Operator_Image
(
Standard
.
Integer
(
Op
)))
=
"/"
or
else
Get_Name_String
(
Operator_Image
(
Standard
.
Integer
(
Op
)))
=
"&&"
or
else
Get_Name_String
(
Operator_Image
(
Standard
.
Integer
(
Op
)))
=
"||"
then
if
Kind
(
L_Expr
)
=
K_Expression
then
Write
(
Tok_Left_Paren
);
Generate
(
L_Expr
);
Write
(
Tok_Right_Paren
);
else
Generate
(
L_Expr
);
end
if
;
Write_Space
;
Write_Name
(
Operator_Image
(
Standard
.
Integer
(
Op
)));
Write_Space
;
if
Kind
(
R_Expr
)
=
K_Expression
then
Write
(
Tok_Left_Paren
);
Generate
(
R_Expr
);
Write
(
Tok_Right_Paren
);
else
Generate
(
R_Expr
);
end
if
;
elsif
Get_Name_String
(
Operator_Image
(
Standard
.
Integer
(
Op
)))
=
"!"
then
Write_Name
(
Operator_Image
(
Standard
.
Integer
(
Op
)));
if
Kind
(
L_Expr
)
=
K_Expression
then
Write
(
Tok_Left_Paren
);
Generate
(
L_Expr
);
Write
(
Tok_Right_Paren
);
else
Generate
(
L_Expr
);
end
if
;
else
Generate
(
L_Expr
);
Write_Space
;
Write_Name
(
Operator_Image
(
Standard
.
Integer
(
Op
)));
Write_Space
;
Generate
(
R_Expr
);
end
if
;
end
Generate_Expression
;
...
...
src/backends/ast_c/ocarina-backends-c_tree-nutils.adb
View file @
0034174c
...
...
@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-201
7
ESA & ISAE. --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-201
9
ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
...
...
@@ -348,9 +348,9 @@ package body Ocarina.Backends.C_Tree.Nutils is
New_Token
(
Tok_Arrow
,
"->"
);
New_Token
(
Tok_Vertical_Bar
,
"|"
);
for
O
in
Op_And
..
Op_Or_Else
loop
New_Operator
(
O
);
end
loop
;
New_Operator
(
Op_Not
,
"!"
);
New_Operator
(
O
p_And
,
"&&"
);
New_Operator
(
Op_Or
,
"||"
)
;
New_Operator
(
Op_And_Symbol
,
"&"
);
New_Operator
(
Op_Double_Asterisk
,
"**"
);
New_Operator
(
Op_Asterisk
,
"**"
);
...
...
@@ -369,6 +369,7 @@ package body Ocarina.Backends.C_Tree.Nutils is
New_Operator
(
Op_Less_Less
,
"<<"
);
New_Operator
(
Op_Semicolon
,
";"
);
New_Operator
(
Op_Arrow
,
"=>"
);
New_Operator
(
Op_Modulo
,
"%"
);
New_Operator
(
Op_Vertical_Bar
,
"|"
);
for
A
in
Attribute_Id
loop
...
...
@@ -495,10 +496,11 @@ package body Ocarina.Backends.C_Tree.Nutils is
------------------------------
function
Make_Defining_Identifier
(
Name
:
Name_Id
;
C_Conversion
:
Boolean
:=
True
;
Ada_Conversion
:
Boolean
:=
False
;
Pointer
:
Boolean
:=
False
)
return
Node_Id
(
Name
:
Name_Id
;
C_Conversion
:
Boolean
:=
True
;
Ada_Conversion
:
Boolean
:=
False
;
Pointer
:
Boolean
:=
False
;
Variable_Address
:
Boolean
:=
False
)
return
Node_Id
is
N
:
Node_Id
;
...
...
@@ -514,6 +516,10 @@ package body Ocarina.Backends.C_Tree.Nutils is
CTN
.
Set_Is_Pointer
(
N
,
True
);
end
if
;
if
Variable_Address
then
CTN
.
Set_Is_Variable_Address
(
N
,
True
);
end
if
;
return
N
;
end
Make_Defining_Identifier
;
...
...
@@ -540,8 +546,7 @@ package body Ocarina.Backends.C_Tree.Nutils is
------------------------
function
Make_For_Statement
(
Defining_Identifier
:
Node_Id
;
Pre_Cond
:
Node_Id
;
(
Pre_Cond
:
Node_Id
;
Condition
:
Node_Id
;
Post_Cond
:
Node_Id
;
Statements
:
List_Id
)
return
Node_Id
...
...
@@ -549,7 +554,6 @@ package body Ocarina.Backends.C_Tree.Nutils is
N
:
Node_Id
;
begin
N
:=
New_Node
(
K_For_Statement
);
Set_Defining_Identifier
(
N
,
Defining_Identifier
);
Set_Pre_Cond
(
N
,
Pre_Cond
);
Set_Condition
(
N
,
Condition
);
Set_Post_Cond
(
N
,
Post_Cond
);
...
...
@@ -1023,11 +1027,8 @@ package body Ocarina.Backends.C_Tree.Nutils is
procedure
New_Operator
(
O
:
Operator_Type
;
I
:
String
:=
""
)
is
begin
if
O
in
Keyword_Operator
then
Set_Str_To_Name_Buffer
(
Image
(
O
));
else
Set_Str_To_Name_Buffer
(
I
);
end
if
;
Set_Str_To_Name_Buffer
(
I
);
Operator_Image
(
Operator_Type
'
Pos
(
O
))
:=
Name_Find
;
end
New_Operator
;
...
...
src/backends/ast_c/ocarina-backends-c_tree-nutils.ads
View file @
0034174c
...
...
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-201
7
ESA & ISAE. --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-201
9
ESA & ISAE. --
-- --
-- Ocarina is free software; you can redistribute it and/or modify under --
-- terms of the GNU General Public License as published by the Free Soft- --
...
...
@@ -116,12 +116,12 @@ package Ocarina.Backends.C_Tree.Nutils is
subtype
Keyword_Type
is
Token_Type
range
Tok_Null
..
Tok_Typedef
;
type
Operator_Type
is
(
Op_Not
,
-- not
Op_And
,
--
and
Op_In
,
-- in
Op_And_Then
,
-- and then
Op_Or
,
--
or
Op_Or_Else
,
-- or else
(
Op_Not
,
--
! --
not
Op_And
,
--
&&
--
Op_In, -- in
--
Op_And_Then, -- and then
Op_Or
,
--
||
--
Op_Or_Else, -- or else
Op_And_Symbol
,
-- &
Op_Double_Asterisk
,
-- **
Op_Minus
,
-- -
...
...
@@ -139,16 +139,14 @@ package Ocarina.Backends.C_Tree.Nutils is
Op_Less_Less
,
-- <<
Op_Semicolon
,
-- ;
Op_Arrow
,
-- ->
Op_Modulo
,
-- %
Op_Vertical_Bar
,
-- |
Op_None
);
-- No operation
Operator_Image
:
array
(
Operator_Type
'
Pos
(
Op_
And
)
..
(
Operator_Type
'
Pos
(
Op_
Not
)
..
Operator_Type
'
Pos
(
Op_Vertical_Bar
))
of
Name_Id
;
subtype
Keyword_Operator
is
Operator_Type
range
Operator_Type
'
First
..
Op_Or_Else
;
type
Parameter_Id
is
(
P_From
,
P_To
,
...
...
@@ -340,10 +338,11 @@ package Ocarina.Backends.C_Tree.Nutils is
Expression
:
Node_Id
)
return
Node_Id
;
function
Make_Defining_Identifier
(
Name
:
Name_Id
;
C_Conversion
:
Boolean
:=
True
;
Ada_Conversion
:
Boolean
:=
False
;
Pointer
:
Boolean
:=
False
)
return
Node_Id
;
(
Name
:
Name_Id
;
C_Conversion
:
Boolean
:=
True
;
Ada_Conversion
:
Boolean
:=
False
;
Pointer
:
Boolean
:=
False
;
Variable_Address
:
Boolean
:=
False
)
return
Node_Id
;
function
Make_Expression
(
Left_Expr
:
Node_Id
;
...
...
@@ -351,8 +350,7 @@ package Ocarina.Backends.C_Tree.Nutils is
Right_Expr
:
Node_Id
:=
No_Node
)
return
Node_Id
;
function
Make_For_Statement
(
Defining_Identifier
:
Node_Id
;
Pre_Cond
:
Node_Id
;
(
Pre_Cond
:
Node_Id
;
Condition
:
Node_Id
;
Post_Cond
:
Node_Id
;
Statements
:
List_Id
)
return
Node_Id
;
...
...
src/backends/ocarina-backends-c_tree-nodes.idl
View file @
0034174c
...
...
@@ -62,6 +62,7 @@ module Ocarina::Backends::C_Tree::Nodes {
Node_Id
Corresponding_Node
;
Node_Id
Compile_Unit
;
boolean
Is_Pointer
;
boolean
Is_Variable_Address
;
}
;
interface
Ifdef_Clause
:
Node_Id
{
...
...
@@ -238,7 +239,7 @@ module Ocarina::Backends::C_Tree::Nodes {
Node_Id
Expression
;
}
;
interface
For_Statement
:
Definition
{
interface
For_Statement
:
Node_Id
{
Node_Id
Pre_Cond
;
Node_Id
Condition
;
Node_Id
Post_Cond
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment