Commit b4721732 authored by yoogx's avatar yoogx

* Add support for 'static' keyword for the C backend

parent f4f0b0ea
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -1198,6 +1198,10 @@ package body Ocarina.Backends.C_Tree.Generator is ...@@ -1198,6 +1198,10 @@ package body Ocarina.Backends.C_Tree.Generator is
procedure Generate_Variable_Declaration (N : Node_Id) is procedure Generate_Variable_Declaration (N : Node_Id) is
begin begin
Generate (Used_Type (N)); Generate (Used_Type (N));
if Is_Static (N) then
Write_Space;
Write (Tok_Static);
end if;
Write_Space; Write_Space;
Generate (Defining_Identifier (N)); Generate (Defining_Identifier (N));
end Generate_Variable_Declaration; end Generate_Variable_Declaration;
......
...@@ -61,7 +61,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -61,7 +61,7 @@ module Ocarina::Backends::C_Tree::Nodes {
Name_Id Name; Name_Id Name;
Node_Id Corresponding_Node; Node_Id Corresponding_Node;
Node_Id Compile_Unit; Node_Id Compile_Unit;
boolean Is_Pointer; boolean Is_Pointer;
}; };
interface Ifdef_Clause : Node_Id { interface Ifdef_Clause : Node_Id {
...@@ -73,7 +73,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -73,7 +73,7 @@ module Ocarina::Backends::C_Tree::Nodes {
interface Include_Clause : Node_Id { interface Include_Clause : Node_Id {
Node_Id Header_Name; Node_Id Header_Name;
boolean Is_Local; boolean Is_Local;
}; };
interface Includes : List_Id {}; interface Includes : List_Id {};
...@@ -163,7 +163,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -163,7 +163,7 @@ module Ocarina::Backends::C_Tree::Nodes {
Node_Id Subprograms_Source; Node_Id Subprograms_Source;
Node_Id Subprograms_Header; Node_Id Subprograms_Header;
}; };
interface Parameter_Specification : Definition { interface Parameter_Specification : Definition {
Node_Id Parameter_Type; Node_Id Parameter_Type;
}; };
...@@ -178,7 +178,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -178,7 +178,7 @@ module Ocarina::Backends::C_Tree::Nodes {
Node_Id Return_Type; Node_Id Return_Type;
Node_Id Compile_Unit; Node_Id Compile_Unit;
}; };
/* /*
* int myfunc (int arg1 , char arg2) * int myfunc (int arg1 , char arg2)
* { * {
...@@ -192,7 +192,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -192,7 +192,7 @@ module Ocarina::Backends::C_Tree::Nodes {
List_Id Statements; List_Id Statements;
Node_Id Compile_Unit; Node_Id Compile_Unit;
}; };
/* /*
* myfunc (arg1, arg2); * myfunc (arg1, arg2);
*/ */
...@@ -206,7 +206,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -206,7 +206,7 @@ module Ocarina::Backends::C_Tree::Nodes {
/* /*
* Example : * Example :
* - typedef int my_integer; * - typedef int my_integer;
* - typedef struct{....} my_type; * - typedef struct{....} my_type;
*/ */
...@@ -297,7 +297,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -297,7 +297,7 @@ module Ocarina::Backends::C_Tree::Nodes {
*/ */
interface Continue_Statement : Node_Id { interface Continue_Statement : Node_Id {
}; };
interface C_Comment : Definition { interface C_Comment : Definition {
boolean Has_Header_Spaces; boolean Has_Header_Spaces;
}; };
...@@ -339,7 +339,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -339,7 +339,7 @@ module Ocarina::Backends::C_Tree::Nodes {
/* /*
* Struct_Aggregate interface is used * Struct_Aggregate interface is used
* to generated code like * to generated code like
* struct struct_name { * struct struct_name {
* member_type member1; * member_type member1;
* member_type member2; * member_type member2;
...@@ -351,7 +351,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -351,7 +351,7 @@ module Ocarina::Backends::C_Tree::Nodes {
/* /*
* Used to generate Union, generated code looks like * Used to generate Union, generated code looks like
* the Struct_Aggregate * the Struct_Aggregate
*/ */
interface Union_Aggregate : Definition { interface Union_Aggregate : Definition {
List_Id Union_Members; List_Id Union_Members;
...@@ -365,15 +365,16 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -365,15 +365,16 @@ module Ocarina::Backends::C_Tree::Nodes {
List_Id Enum_Members; List_Id Enum_Members;
}; };
/* Definition is used in functions to /* Definition is used in functions to
* declare variables * declare variables
* Generated code looks like : * Generated code looks like :
* used_type variable_name; * used_type variable_name;
*/ */
interface Variable_Declaration : Definition { interface Variable_Declaration : Definition {
Node_Id Used_Type; Node_Id Used_Type;
boolean Is_Static;
}; };
/* /*
* Member_Declaration is used in unions * Member_Declaration is used in unions
* or structures * or structures
...@@ -403,7 +404,7 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -403,7 +404,7 @@ module Ocarina::Backends::C_Tree::Nodes {
interface Literal : Node_Id { interface Literal : Node_Id {
Value_Id Value; Value_Id Value;
}; };
interface Expression : Node_Id { interface Expression : Node_Id {
Operator_Id Operator; Operator_Id Operator;
...@@ -457,16 +458,16 @@ module Ocarina::Backends::C_Tree::Nodes { ...@@ -457,16 +458,16 @@ module Ocarina::Backends::C_Tree::Nodes {
interface Tree_Bindings : Node_Id { interface Tree_Bindings : Node_Id {
/* Units */ /* Units */
Node_Id Main_Node; Node_Id Main_Node;
/* Entities */ /* Entities */
Node_Id Type_Definition_Node; Node_Id Type_Definition_Node;
Node_Id Feature_Subprogram_Node; Node_Id Feature_Subprogram_Node;
Node_Id Subprogram_Node; Node_Id Subprogram_Node;
}; };
interface HI_Tree_Bindings : Tree_Bindings { interface HI_Tree_Bindings : Tree_Bindings {
/* Units */ /* Units */
Node_Id Internals_Node; Node_Id Internals_Node;
Node_Id System_Time_Node; Node_Id System_Time_Node;
Node_Id Marshaller_Node; Node_Id Marshaller_Node;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -735,13 +735,15 @@ package body Ocarina.Backends.C_Tree.Nutils is ...@@ -735,13 +735,15 @@ package body Ocarina.Backends.C_Tree.Nutils is
function Make_Variable_Declaration function Make_Variable_Declaration
(Defining_Identifier : Node_Id; (Defining_Identifier : Node_Id;
Used_Type : Node_Id) return Node_Id Used_Type : Node_Id;
Is_Static : Boolean := False) return Node_Id
is is
P : Node_Id; P : Node_Id;
begin begin
P := New_Node (K_Variable_Declaration); P := New_Node (K_Variable_Declaration);
Set_Defining_Identifier (P, Defining_Identifier); Set_Defining_Identifier (P, Defining_Identifier);
Set_Used_Type (P, Used_Type); Set_Used_Type (P, Used_Type);
Set_Is_Static (P, Is_Static);
return P; return P;
end Make_Variable_Declaration; end Make_Variable_Declaration;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2015 ESA & ISAE. -- -- Copyright (C) 2008-2009 Telecom ParisTech, 2010-2016 ESA & ISAE. --
-- -- -- --
-- Ocarina is free software; you can redistribute it and/or modify under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -70,6 +70,7 @@ package Ocarina.Backends.C_Tree.Nutils is ...@@ -70,6 +70,7 @@ package Ocarina.Backends.C_Tree.Nutils is
Tok_Until, -- UNTIL Tok_Until, -- UNTIL
Tok_For, -- FOR Tok_For, -- FOR
Tok_While, -- WHILE Tok_While, -- WHILE
Tok_Static, -- STATIC
Tok_Switch, -- SWITCH Tok_Switch, -- SWITCH
Tok_Typedef, -- TYPEDEF Tok_Typedef, -- TYPEDEF
...@@ -354,7 +355,8 @@ package Ocarina.Backends.C_Tree.Nutils is ...@@ -354,7 +355,8 @@ package Ocarina.Backends.C_Tree.Nutils is
function Make_Variable_Declaration function Make_Variable_Declaration
(Defining_Identifier : Node_Id; (Defining_Identifier : Node_Id;
Used_Type : Node_Id) return Node_Id; Used_Type : Node_Id;
Is_Static : Boolean := False) return Node_Id;
function Make_Member_Declaration function Make_Member_Declaration
(Defining_Identifier : Node_Id; (Defining_Identifier : Node_Id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment