Skip to content

Commit 0c2fc6b

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 d9166e6 commit 0c2fc6b

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;
@@ -207,6 +210,12 @@ package body Tree_Walk is
207210
function Do_Op_Not (N : Node_Id) return Irep
208211
with Pre => Nkind (N) in N_Op;
209212

213+
procedure Do_Package_Declaration (N : Node_Id)
214+
with Pre => Nkind (N) = N_Package_Declaration;
215+
216+
procedure Do_Package_Specification (N : Node_Id)
217+
with Pre => Nkind (N) = N_Package_Specification;
218+
210219
function Do_Procedure_Call_Statement (N : Node_Id) return Irep
211220
with Pre => Nkind (N) = N_Procedure_Call_Statement,
212221
Post => Kind (Do_Procedure_Call_Statement'Result) =
@@ -279,6 +288,16 @@ package body Tree_Walk is
279288
Post => Kind (Do_Unconstrained_Array_Definition'Result) =
280289
I_Struct_Type;
281290

291+
procedure Do_Withed_Unit_Spec (N : Node_Id);
292+
-- Enters the specification of the withed unit, N, into the symbol table
293+
294+
procedure Do_Withed_Units_Specs is new Sem.Walk_Library_Items
295+
(Action => Do_Withed_Unit_Spec);
296+
-- Traverses tree applying the procedure Do_With_Unit_Spec to all nodes
297+
-- which are specifications of library units withed by the GNAT_Root unit
298+
-- (that is, the body being compiled).
299+
-- It starts with the unit Standard and finishes with GNAT_Root
300+
282301
function Find_Record_Variant (Variant_Part : Node_Id;
283302
Actual_Disc : Node_Id) return Node_Id
284303
with Pre => Nkind (Variant_Part) = N_Variant_Part,
@@ -1271,24 +1290,26 @@ package body Tree_Walk is
12711290
U : constant Node_Id := Unit (N);
12721291
Unit_Symbol : Symbol;
12731292
begin
1293+
-- Insert all all specifications of all withed units including the
1294+
-- specification of the given compilation unit into the symbol table.
1295+
Do_Withed_Units_Specs;
1296+
12741297
case Nkind (U) is
12751298
when N_Subprogram_Body =>
12761299
declare
1277-
Unit_Type : constant Irep :=
1278-
Do_Subprogram_Specification (Specification (U));
12791300
Unit_Name : constant Symbol_Id :=
12801301
Intern (Unique_Name (Unique_Defining_Entity (U)));
12811302
begin
1282-
-- Register the symbol *before* we compile the body, for
1283-
-- recursive calls.
1284-
Unit_Symbol.Name := Unit_Name;
1285-
Unit_Symbol.PrettyName := Unit_Name;
1286-
Unit_Symbol.BaseName := Unit_Name;
1287-
Unit_Symbol.Mode := Intern ("C");
1288-
Unit_Symbol.SymType := Unit_Type;
1289-
Global_Symbol_Table.Insert (Unit_Name, Unit_Symbol);
1290-
1291-
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
1303+
-- The specification of the subprogram body has already
1304+
-- been inserted into the symbol table by the call to
1305+
-- Do_Withed_Unit_Specs.
1306+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1307+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
1308+
1309+
-- Now compile the body of the subprogram
1310+
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
1311+
1312+
-- and update the symbol table entry for this subprogram.
12921313
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
12931314
Add_Start := True;
12941315
end;
@@ -3528,6 +3549,31 @@ package body Tree_Walk is
35283549
return Ret;
35293550
end Do_Operator_Simple;
35303551

3552+
----------------------------
3553+
-- Do_Package_Declaration --
3554+
----------------------------
3555+
3556+
procedure Do_Package_Declaration (N : Node_Id) is
3557+
begin
3558+
Do_Package_Specification (Specification (N));
3559+
end Do_Package_Declaration;
3560+
3561+
----------------------------
3562+
-- Do_Package_Specification --
3563+
----------------------------
3564+
3565+
procedure Do_Package_Specification (N : Node_Id) is
3566+
Package_Decs : constant Irep := New_Irep (I_Code_Block);
3567+
begin
3568+
Set_Source_Location (Package_Decs, Sloc (N));
3569+
if Present (Visible_Declarations (N)) then
3570+
Process_Declarations (Visible_Declarations (N), Package_Decs);
3571+
end if;
3572+
if Present (Private_Declarations (N)) then
3573+
Process_Declarations (Private_Declarations (N), Package_Decs);
3574+
end if;
3575+
end Do_Package_Specification;
3576+
35313577
---------------------------------
35323578
-- Do_Procedure_Call_Statement --
35333579
---------------------------------
@@ -4011,18 +4057,18 @@ package body Tree_Walk is
40114057
function Do_Subprogram_Or_Block (N : Node_Id) return Irep is
40124058
Decls : constant List_Id := Declarations (N);
40134059
HSS : constant Node_Id := Handled_Statement_Sequence (N);
4014-
Decls_Rep : Irep;
4060+
Reps : constant Irep := New_Irep (I_Code_Block);
40154061
begin
4016-
Decls_Rep := (if Present (Decls)
4017-
then Process_Statements (Decls)
4018-
else New_Irep (I_Code_Block));
4062+
if Present (Decls) then
4063+
Process_Declarations (Decls, Reps);
4064+
end if;
40194065

4020-
Set_Source_Location (Decls_Rep, Sloc (N));
4066+
Set_Source_Location (Reps, Sloc (N));
40214067
if Present (HSS) then
4022-
Process_Statement (HSS, Decls_Rep);
4068+
Process_Statement (HSS, Reps);
40234069
end if;
40244070

4025-
return Decls_Rep;
4071+
return Reps;
40264072
end Do_Subprogram_Or_Block;
40274073

40284074
--------------------------------
@@ -4282,6 +4328,54 @@ package body Tree_Walk is
42824328

42834329
end Do_Unconstrained_Array_Definition;
42844330

4331+
-------------------------
4332+
-- Do_Withed_Unit_Spec --
4333+
-------------------------
4334+
4335+
procedure Do_Withed_Unit_Spec (N : Node_Id) is
4336+
Unit_Name : constant String := Get_Name_String (Get_Unit_Name (N));
4337+
begin
4338+
if Defining_Entity (N) = Stand.Standard_Standard or else
4339+
Unit_Name = "system%s"
4340+
then
4341+
null;
4342+
-- At the moment Standard or System are not processed - to be done
4343+
else
4344+
4345+
case Nkind (N) is
4346+
when N_Subprogram_Body =>
4347+
if Acts_As_Spec (N) then
4348+
-- The unit is a withed library unit which subprogram body
4349+
-- that has no separate declaration, or,
4350+
-- it is the subprogram body of the compilation unit being
4351+
-- compiled and it has no separate declaration.
4352+
-- Obtain the subprogram specification from the body
4353+
-- and insert it into the symbol table.
4354+
Register_Subprogram_Specification (Specification (N));
4355+
else
4356+
null;
4357+
end if;
4358+
when N_Subprogram_Declaration =>
4359+
-- The unit is withed library unit that is a subprogram
4360+
-- declaration, or,
4361+
-- it is the declaration of the compilation unit body being
4362+
-- compiled.
4363+
-- Do_Subprogram_Declaration enters the specification of the
4364+
-- subprogram into the symbol table.
4365+
Do_Subprogram_Declaration (N);
4366+
when N_Package_Declaration =>
4367+
Do_Package_Declaration (N);
4368+
when N_Package_Body =>
4369+
null;
4370+
when others =>
4371+
Put_Line (Standard_Error,
4372+
"This type of library_unit is not yet handled");
4373+
end case;
4374+
4375+
end if;
4376+
4377+
end Do_Withed_Unit_Spec;
4378+
42854379
-------------------------
42864380
-- Find_Record_Variant --
42874381
-------------------------

0 commit comments

Comments
 (0)