Skip to content

Commit a9f178c

Browse files
tjj2017Petr Bauch
authored andcommitted
Separate Subprogram specification
Introduces Register_Subprogram_Specification procedure that creates a new symbol table entry with the subprogram name.
1 parent dfe5c87 commit a9f178c

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

gnat2goto/driver/tree_walk.adb

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ package body Tree_Walk is
360360
with Post => Kind (Process_Statements'Result) = I_Code_Block;
361361
-- Process list of statements or declarations
362362

363+
procedure Register_Subprogram_Specification (N : Node_Id)
364+
with Pre => Nkind (N) in N_Subprogram_Specification;
365+
-- Insert the subprogram specification into the symbol table
366+
363367
procedure Remove_Entity_Substitution (E : Entity_Id);
364368

365369
function Create_Dummy_Irep return Irep;
@@ -3920,27 +3924,22 @@ package body Tree_Walk is
39203924
Proc_Symbol : Symbol;
39213925
begin
39223926
if not Global_Symbol_Table.Contains (Proc_Name) then
3923-
Put_Line (Standard_Error, "Warning: Subprogram " &
3924-
Unintern (Proc_Name) & " not in symbol table");
3925-
declare
3926-
Proc_Type : constant Irep :=
3927-
Do_Subprogram_Specification (Specification (N));
3928-
New_Proc_Symbol : Symbol;
3929-
begin
3930-
New_Proc_Symbol.Name := Proc_Name;
3931-
New_Proc_Symbol.BaseName := Proc_Name;
3932-
New_Proc_Symbol.PrettyName := Proc_Name;
3933-
New_Proc_Symbol.SymType := Proc_Type;
3934-
New_Proc_Symbol.Mode := Intern ("C");
3935-
3936-
Global_Symbol_Table.Insert (Proc_Name, New_Proc_Symbol);
3937-
end;
3927+
-- A subprogram body does not have to have a separate declaration
3928+
-- so it may not be in the symbol table.
3929+
-- The subprogram specification of the subprogram body is used to
3930+
-- populate the symbol table instead.
3931+
Register_Subprogram_Specification (Specification (N));
39383932
end if;
3933+
-- Todo aspect_specification
3934+
-- Now the subprogram should registered in the stmbol table
3935+
-- whether a separate declaration was provided or not.
39393936
if not Global_Symbol_Table.Contains (Proc_Name) then
39403937
Report_Unhandled_Node_Empty (N, "Do_Subprogram_Body",
39413938
"Proc name not in symbol table");
39423939
end if;
39433940
Proc_Symbol := Global_Symbol_Table (Proc_Name);
3941+
3942+
-- Compile the subprogram body and update its entry in the symbol table.
39443943
Proc_Symbol.Value := Proc_Body;
39453944
Global_Symbol_Table.Replace (Proc_Name, Proc_Symbol);
39463945
end Do_Subprogram_Body;
@@ -3950,23 +3949,9 @@ package body Tree_Walk is
39503949
-------------------------------
39513950

39523951
procedure Do_Subprogram_Declaration (N : Node_Id) is
3953-
Proc_Type : constant Irep :=
3954-
Do_Subprogram_Specification (Specification (N));
3955-
3956-
Proc_Name : constant Symbol_Id := Intern
3957-
(Unique_Name (Defining_Unit_Name (Specification (N))));
3958-
-- take from spec, because body could be absent (null procedure)
3959-
3960-
Proc_Symbol : Symbol;
3961-
39623952
begin
3963-
Proc_Symbol.Name := Proc_Name;
3964-
Proc_Symbol.BaseName := Proc_Name;
3965-
Proc_Symbol.PrettyName := Proc_Name;
3966-
Proc_Symbol.SymType := Proc_Type;
3967-
Proc_Symbol.Mode := Intern ("C");
3968-
3969-
Global_Symbol_Table.Insert (Proc_Name, Proc_Symbol);
3953+
Register_Subprogram_Specification (Specification (N));
3954+
-- Todo Aspect specifications
39703955
end Do_Subprogram_Declaration;
39713956

39723957
----------------------------
@@ -4960,6 +4945,29 @@ package body Tree_Walk is
49604945
return Reps;
49614946
end Process_Statements;
49624947

4948+
---------------------------------------
4949+
-- Register_Subprogram_Specification --
4950+
---------------------------------------
4951+
4952+
procedure Register_Subprogram_Specification (N : Node_Id) is
4953+
Subprog_Type : constant Irep :=
4954+
Do_Subprogram_Specification (N);
4955+
Subprog_Name : constant Symbol_Id :=
4956+
Intern (Unique_Name (Defining_Unit_Name (N)));
4957+
4958+
Subprog_Symbol : Symbol;
4959+
4960+
begin
4961+
Subprog_Symbol.Name := Subprog_Name;
4962+
Subprog_Symbol.BaseName := Subprog_Name;
4963+
Subprog_Symbol.PrettyName := Subprog_Name;
4964+
Subprog_Symbol.SymType := Subprog_Type;
4965+
Subprog_Symbol.Mode := Intern ("C");
4966+
Subprog_Symbol.Value := Make_Nil (Sloc (N));
4967+
4968+
Global_Symbol_Table.Insert (Subprog_Name, Subprog_Symbol);
4969+
end Register_Subprogram_Specification;
4970+
49634971
procedure Remove_Entity_Substitution (E : Entity_Id) is
49644972
begin
49654973
Identifier_Substitution_Map.Delete (E);

0 commit comments

Comments
 (0)