Skip to content

Commit 9a737b0

Browse files
tjj2017Petr Bauch
authored andcommitted
Set return value in Do_Compilation_Unit
to Unit_Symbol for a package body. To determine a symbol value for a package body a symbol is determined from its specification and registered in the symbol table. This required checking for the package being a child. N.b.: The same check may be required for child subprograms!
1 parent 8653f52 commit 9a737b0

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

gnat2goto/driver/tree_walk.adb

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ package body Tree_Walk is
946946
return Symbol
947947
is
948948
U : constant Node_Id := Unit (N);
949+
Unit_Name : constant Symbol_Id :=
950+
Intern (Unique_Name (Unique_Defining_Entity (U)));
949951
Unit_Symbol : Symbol;
950952
begin
951953
-- Insert all all specifications of all withed units including the
@@ -954,29 +956,26 @@ package body Tree_Walk is
954956

955957
case Nkind (U) is
956958
when N_Subprogram_Body =>
957-
declare
958-
Unit_Name : constant Symbol_Id :=
959-
Intern (Unique_Name (Unique_Defining_Entity (U)));
960-
begin
961-
-- The specification of the subprogram body has already
962-
-- been inserted into the symbol table by the call to
963-
-- Do_Withed_Unit_Specs.
964-
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
965-
Unit_Symbol := Global_Symbol_Table (Unit_Name);
959+
-- The specification of the subprogram body has already
960+
-- been inserted into the symbol table by the call to
961+
-- Do_Withed_Unit_Specs.
962+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
963+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
966964

967-
-- Now compile the body of the subprogram
968-
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
965+
-- Now compile the body of the subprogram
966+
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
969967

970-
-- and update the symbol table entry for this subprogram.
971-
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
972-
Add_Start := True;
973-
end;
968+
-- and update the symbol table entry for this subprogram.
969+
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
970+
Add_Start := True;
974971

975972
when N_Package_Body =>
976973
declare
977974
Dummy : constant Irep := Do_Subprogram_Or_Block (U);
978975
pragma Unreferenced (Dummy);
979976
begin
977+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
978+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
980979
Add_Start := False;
981980
end;
982981

@@ -3501,7 +3500,35 @@ package body Tree_Walk is
35013500

35023501
procedure Do_Package_Specification (N : Node_Id) is
35033502
Package_Decs : constant Irep := New_Irep (I_Code_Block);
3503+
Package_Name : Symbol_Id;
3504+
Package_Symbol : Symbol;
3505+
Def_Unit_Name : Node_Id;
3506+
Entity_Node : Node_Id;
3507+
35043508
begin
3509+
Def_Unit_Name := Defining_Unit_Name (N);
3510+
3511+
-- Defining_Unit_Name will return a N_Defining_Identifier
3512+
-- for non-child package but a N_Package_Specification when it is a
3513+
-- child package.
3514+
-- To obtain the Entity N_Defining_Identifier is required.
3515+
-- The actual parameter for Unique_Name must be an Entity node.
3516+
if Nkind (Def_Unit_Name) = N_Defining_Identifier then
3517+
Entity_Node := Def_Unit_Name;
3518+
else
3519+
Entity_Node := Defining_Identifier (Def_Unit_Name);
3520+
end if;
3521+
3522+
Package_Name := Intern (Unique_Name (Entity_Node));
3523+
Package_Symbol.Name := Package_Name;
3524+
Package_Symbol.BaseName := Package_Name;
3525+
Package_Symbol.PrettyName := Package_Name;
3526+
Package_Symbol.SymType := New_Irep (I_Void_Type);
3527+
Package_Symbol.Mode := Intern ("C");
3528+
Package_Symbol.Value := Make_Nil (Sloc (N));
3529+
3530+
Global_Symbol_Table.Insert (Package_Name, Package_Symbol);
3531+
35053532
Set_Source_Location (Package_Decs, Sloc (N));
35063533
if Present (Visible_Declarations (N)) then
35073534
Process_Declarations (Visible_Declarations (N), Package_Decs);
@@ -4303,8 +4330,9 @@ package body Tree_Walk is
43034330
when N_Package_Body =>
43044331
null;
43054332
when others =>
4306-
Put_Line (Standard_Error,
4307-
"This type of library_unit is not yet handled");
4333+
Report_Unhandled_Node_Empty
4334+
(N, "Do_Withed_Unit_Spec",
4335+
"This type of library_unit is not yet handled");
43084336
end case;
43094337

43104338
end if;

0 commit comments

Comments
 (0)