Skip to content

Commit 0e56882

Browse files
tjj2017Petr Bauch
authored andcommitted
Added processing for packages
Introduces: 1) Do_Package_Declaration 2) Do_Package_Specification -- processes private and visible declarations as a new code block 3) Do_Withed_Unit_Spec -- case analysis for registering program specification/processing subprogram declarations/package declarations 4) Do_Withed_Units_Specs
1 parent 0c2b0f3 commit 0e56882

File tree

1 file changed

+113
-19
lines changed

1 file changed

+113
-19
lines changed

gnat2goto/driver/tree_walk.adb

Lines changed: 113 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
with Uname; use Uname;
2+
13
with Einfo; use Einfo;
24
with Namet; use Namet;
35
with Nlists; use Nlists;
6+
with Sem;
47
with Sem_Util; use Sem_Util;
58
with Sem_Aux; use Sem_Aux;
69
with Snames; use Snames;
@@ -204,6 +207,12 @@ package body Tree_Walk is
204207
function Do_Op_Not (N : Node_Id) return Irep
205208
with Pre => Nkind (N) in N_Op;
206209

210+
procedure Do_Package_Declaration (N : Node_Id)
211+
with Pre => Nkind (N) = N_Package_Declaration;
212+
213+
procedure Do_Package_Specification (N : Node_Id)
214+
with Pre => Nkind (N) = N_Package_Specification;
215+
207216
function Do_Procedure_Call_Statement (N : Node_Id) return Irep
208217
with Pre => Nkind (N) = N_Procedure_Call_Statement,
209218
Post => Kind (Do_Procedure_Call_Statement'Result) =
@@ -276,6 +285,16 @@ package body Tree_Walk is
276285
Post => Kind (Do_Unconstrained_Array_Definition'Result) =
277286
I_Struct_Type;
278287

288+
procedure Do_Withed_Unit_Spec (N : Node_Id);
289+
-- Enters the specification of the withed unit, N, into the symbol table
290+
291+
procedure Do_Withed_Units_Specs is new Sem.Walk_Library_Items
292+
(Action => Do_Withed_Unit_Spec);
293+
-- Traverses tree applying the procedure Do_With_Unit_Spec to all nodes
294+
-- which are specifications of library units withed by the GNAT_Root unit
295+
-- (that is, the body being compiled).
296+
-- It starts with the unit Standard and finishes with GNAT_Root
297+
279298
function Find_Record_Variant (Variant_Part : Node_Id;
280299
Actual_Disc : Node_Id) return Node_Id
281300
with Pre => Nkind (Variant_Part) = N_Variant_Part,
@@ -1245,24 +1264,26 @@ package body Tree_Walk is
12451264
U : constant Node_Id := Unit (N);
12461265
Unit_Symbol : Symbol;
12471266
begin
1267+
-- Insert all all specifications of all withed units including the
1268+
-- specification of the given compilation unit into the symbol table.
1269+
Do_Withed_Units_Specs;
1270+
12481271
case Nkind (U) is
12491272
when N_Subprogram_Body =>
12501273
declare
1251-
Unit_Type : constant Irep :=
1252-
Do_Subprogram_Specification (Specification (U));
12531274
Unit_Name : constant Symbol_Id :=
12541275
Intern (Unique_Name (Unique_Defining_Entity (U)));
12551276
begin
1256-
-- Register the symbol *before* we compile the body, for
1257-
-- recursive calls.
1258-
Unit_Symbol.Name := Unit_Name;
1259-
Unit_Symbol.PrettyName := Unit_Name;
1260-
Unit_Symbol.BaseName := Unit_Name;
1261-
Unit_Symbol.Mode := Intern ("C");
1262-
Unit_Symbol.SymType := Unit_Type;
1263-
Global_Symbol_Table.Insert (Unit_Name, Unit_Symbol);
1264-
1265-
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
1277+
-- The specification of the subprogram body has already
1278+
-- been inserted into the symbol table by the call to
1279+
-- Do_Withed_Unit_Specs.
1280+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1281+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
1282+
1283+
-- Now compile the body of the subprogram
1284+
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
1285+
1286+
-- and update the symbol table entry for this subprogram.
12661287
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
12671288
Add_Start := True;
12681289
end;
@@ -3502,6 +3523,31 @@ package body Tree_Walk is
35023523
return Ret;
35033524
end Do_Operator_Simple;
35043525

3526+
----------------------------
3527+
-- Do_Package_Declaration --
3528+
----------------------------
3529+
3530+
procedure Do_Package_Declaration (N : Node_Id) is
3531+
begin
3532+
Do_Package_Specification (Specification (N));
3533+
end Do_Package_Declaration;
3534+
3535+
----------------------------
3536+
-- Do_Package_Specification --
3537+
----------------------------
3538+
3539+
procedure Do_Package_Specification (N : Node_Id) is
3540+
Package_Decs : constant Irep := New_Irep (I_Code_Block);
3541+
begin
3542+
Set_Source_Location (Package_Decs, Sloc (N));
3543+
if Present (Visible_Declarations (N)) then
3544+
Process_Declarations (Visible_Declarations (N), Package_Decs);
3545+
end if;
3546+
if Present (Private_Declarations (N)) then
3547+
Process_Declarations (Private_Declarations (N), Package_Decs);
3548+
end if;
3549+
end Do_Package_Specification;
3550+
35053551
---------------------------------
35063552
-- Do_Procedure_Call_Statement --
35073553
---------------------------------
@@ -3985,18 +4031,18 @@ package body Tree_Walk is
39854031
function Do_Subprogram_Or_Block (N : Node_Id) return Irep is
39864032
Decls : constant List_Id := Declarations (N);
39874033
HSS : constant Node_Id := Handled_Statement_Sequence (N);
3988-
Decls_Rep : Irep;
4034+
Reps : constant Irep := New_Irep (I_Code_Block);
39894035
begin
3990-
Decls_Rep := (if Present (Decls)
3991-
then Process_Statements (Decls)
3992-
else New_Irep (I_Code_Block));
4036+
if Present (Decls) then
4037+
Process_Declarations (Decls, Reps);
4038+
end if;
39934039

3994-
Set_Source_Location (Decls_Rep, Sloc (N));
4040+
Set_Source_Location (Reps, Sloc (N));
39954041
if Present (HSS) then
3996-
Process_Statement (HSS, Decls_Rep);
4042+
Process_Statement (HSS, Reps);
39974043
end if;
39984044

3999-
return Decls_Rep;
4045+
return Reps;
40004046
end Do_Subprogram_Or_Block;
40014047

40024048
--------------------------------
@@ -4256,6 +4302,54 @@ package body Tree_Walk is
42564302

42574303
end Do_Unconstrained_Array_Definition;
42584304

4305+
-------------------------
4306+
-- Do_Withed_Unit_Spec --
4307+
-------------------------
4308+
4309+
procedure Do_Withed_Unit_Spec (N : Node_Id) is
4310+
Unit_Name : constant String := Get_Name_String (Get_Unit_Name (N));
4311+
begin
4312+
if Defining_Entity (N) = Stand.Standard_Standard or else
4313+
Unit_Name = "system%s"
4314+
then
4315+
null;
4316+
-- At the moment Standard or System are not processed - to be done
4317+
else
4318+
4319+
case Nkind (N) is
4320+
when N_Subprogram_Body =>
4321+
if Acts_As_Spec (N) then
4322+
-- The unit is a withed library unit which subprogram body
4323+
-- that has no separate declaration, or,
4324+
-- it is the subprogram body of the compilation unit being
4325+
-- compiled and it has no separate declaration.
4326+
-- Obtain the subprogram specification from the body
4327+
-- and insert it into the symbol table.
4328+
Register_Subprogram_Specification (Specification (N));
4329+
else
4330+
null;
4331+
end if;
4332+
when N_Subprogram_Declaration =>
4333+
-- The unit is withed library unit that is a subprogram
4334+
-- declaration, or,
4335+
-- it is the declaration of the compilation unit body being
4336+
-- compiled.
4337+
-- Do_Subprogram_Declaration enters the specification of the
4338+
-- subprogram into the symbol table.
4339+
Do_Subprogram_Declaration (N);
4340+
when N_Package_Declaration =>
4341+
Do_Package_Declaration (N);
4342+
when N_Package_Body =>
4343+
null;
4344+
when others =>
4345+
Put_Line (Standard_Error,
4346+
"This type of library_unit is not yet handled");
4347+
end case;
4348+
4349+
end if;
4350+
4351+
end Do_Withed_Unit_Spec;
4352+
42594353
-------------------------
42604354
-- Find_Record_Variant --
42614355
-------------------------

0 commit comments

Comments
 (0)