Skip to content

Commit bad10de

Browse files
authored
Merge pull request #231 from xbauch/feature/define-package-body-symbol
Define package body symbol
2 parents 0e3a640 + a6aacc3 commit bad10de

File tree

6 files changed

+85
-17
lines changed

6 files changed

+85
-17
lines changed

experiments/golden-results/StratoX-summary.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ Calling function: Do_Expression
2828
Error message: Unknown attribute
2929
Nkind: N_Attribute_Reference
3030
--
31+
Occurs: 36 times
32+
Calling function: Do_Withed_Unit_Spec
33+
Error message: This type of library_unit is not yet handled
34+
Nkind: N_Generic_Subprogram_Declaration
35+
--
3136
Occurs: 35 times
3237
Calling function: Process_Pragma_Declaration
3338
Error message: Unsupported pragma: No strict aliasing
3439
Nkind: N_Pragma
3540
--
3641
Occurs: 31 times
42+
Calling function: Do_Withed_Unit_Spec
43+
Error message: This type of library_unit is not yet handled
44+
Nkind: N_Generic_Package_Declaration
45+
--
46+
Occurs: 31 times
3747
Calling function: Process_Declaration
3848
Error message: Package declaration
3949
Nkind: N_Package_Declaration

experiments/golden-results/libkeccak-summary.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ Calling function: Process_Pragma_Declaration
3838
Error message: Unsupported pragma: Ada 05
3939
Nkind: N_Pragma
4040
--
41+
Occurs: 1 times
42+
Calling function: Do_Withed_Unit_Spec
43+
Error message: This type of library_unit is not yet handled
44+
Nkind: N_Generic_Package_Declaration
45+
--
46+
Occurs: 1 times
47+
Calling function: Do_Withed_Unit_Spec
48+
Error message: This type of library_unit is not yet handled
49+
Nkind: N_Generic_Subprogram_Declaration
50+
--
4151
Occurs: 3 times
4252
Redacted compiler error message:
4353
generic parameter "REDACTED" is missing from input dependence list

experiments/golden-results/libsparkcrypto-summary.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Occurs: 2 times
2+
Calling function: Do_Withed_Unit_Spec
3+
Error message: This type of library_unit is not yet handled
4+
Nkind: N_Generic_Subprogram_Declaration
5+
--
16
Occurs: 32 times
27
Redacted compiler error message:
38
file "REDACTED" not found

experiments/golden-results/muen-summary.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ Calling function: Process_Pragma_Declaration
4343
Error message: Unsupported pragma: Initializes
4444
Nkind: N_Pragma
4545
--
46+
Occurs: 10 times
47+
Calling function: Do_Withed_Unit_Spec
48+
Error message: This type of library_unit is not yet handled
49+
Nkind: N_Generic_Subprogram_Declaration
50+
--
51+
Occurs: 9 times
52+
Calling function: Do_Withed_Unit_Spec
53+
Error message: This type of library_unit is not yet handled
54+
Nkind: N_Generic_Package_Declaration
55+
--
4656
Occurs: 8 times
4757
Calling function: Process_Declaration
4858
Error message: Use type clause declaration

experiments/golden-results/vct-summary.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ Error message: func name not in symbol table
5959
Nkind: N_Function_Call
6060
--
6161
Occurs: 1 times
62+
Calling function: Do_Withed_Unit_Spec
63+
Error message: This type of library_unit is not yet handled
64+
Nkind: N_Generic_Package_Declaration
65+
--
66+
Occurs: 1 times
6267
Calling function: Process_Declaration
6368
Error message: Generic instantiation declaration
6469
Nkind: N_Package_Instantiation

gnat2goto/driver/tree_walk.adb

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,8 @@ package body Tree_Walk is
10001000
return Symbol
10011001
is
10021002
U : constant Node_Id := Unit (N);
1003+
Unit_Name : constant Symbol_Id :=
1004+
Intern (Unique_Name (Unique_Defining_Entity (U)));
10031005
Unit_Symbol : Symbol;
10041006
begin
10051007
-- Insert all all specifications of all withed units including the
@@ -1008,29 +1010,26 @@ package body Tree_Walk is
10081010

10091011
case Nkind (U) is
10101012
when N_Subprogram_Body =>
1011-
declare
1012-
Unit_Name : constant Symbol_Id :=
1013-
Intern (Unique_Name (Unique_Defining_Entity (U)));
1014-
begin
1015-
-- The specification of the subprogram body has already
1016-
-- been inserted into the symbol table by the call to
1017-
-- Do_Withed_Unit_Specs.
1018-
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1019-
Unit_Symbol := Global_Symbol_Table (Unit_Name);
1013+
-- The specification of the subprogram body has already
1014+
-- been inserted into the symbol table by the call to
1015+
-- Do_Withed_Unit_Specs.
1016+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1017+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
10201018

1021-
-- Now compile the body of the subprogram
1022-
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
1019+
-- Now compile the body of the subprogram
1020+
Unit_Symbol.Value := Do_Subprogram_Or_Block (U);
10231021

1024-
-- and update the symbol table entry for this subprogram.
1025-
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
1026-
Unit_Is_Subprogram := True;
1027-
end;
1022+
-- and update the symbol table entry for this subprogram.
1023+
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
1024+
Unit_Is_Subprogram := True;
10281025

10291026
when N_Package_Body =>
10301027
declare
10311028
Dummy : constant Irep := Do_Subprogram_Or_Block (U);
10321029
pragma Unreferenced (Dummy);
10331030
begin
1031+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1032+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
10341033
Unit_Is_Subprogram := False;
10351034
end;
10361035

@@ -3575,7 +3574,35 @@ package body Tree_Walk is
35753574

35763575
procedure Do_Package_Specification (N : Node_Id) is
35773576
Package_Decs : constant Irep := New_Irep (I_Code_Block);
3577+
Package_Name : Symbol_Id;
3578+
Package_Symbol : Symbol;
3579+
Def_Unit_Name : Node_Id;
3580+
Entity_Node : Node_Id;
3581+
35783582
begin
3583+
Def_Unit_Name := Defining_Unit_Name (N);
3584+
3585+
-- Defining_Unit_Name will return a N_Defining_Identifier
3586+
-- for non-child package but a N_Package_Specification when it is a
3587+
-- child package.
3588+
-- To obtain the Entity N_Defining_Identifier is required.
3589+
-- The actual parameter for Unique_Name must be an Entity node.
3590+
if Nkind (Def_Unit_Name) = N_Defining_Identifier then
3591+
Entity_Node := Def_Unit_Name;
3592+
else
3593+
Entity_Node := Defining_Identifier (Def_Unit_Name);
3594+
end if;
3595+
3596+
Package_Name := Intern (Unique_Name (Entity_Node));
3597+
Package_Symbol.Name := Package_Name;
3598+
Package_Symbol.BaseName := Package_Name;
3599+
Package_Symbol.PrettyName := Package_Name;
3600+
Package_Symbol.SymType := New_Irep (I_Void_Type);
3601+
Package_Symbol.Mode := Intern ("C");
3602+
Package_Symbol.Value := Make_Nil (Sloc (N));
3603+
3604+
Global_Symbol_Table.Insert (Package_Name, Package_Symbol);
3605+
35793606
Set_Source_Location (Package_Decs, Sloc (N));
35803607
if Present (Visible_Declarations (N)) then
35813608
Process_Declarations (Visible_Declarations (N), Package_Decs);
@@ -4373,8 +4400,9 @@ package body Tree_Walk is
43734400
when N_Package_Body =>
43744401
null;
43754402
when others =>
4376-
Put_Line (Standard_Error,
4377-
"This type of library_unit is not yet handled");
4403+
Report_Unhandled_Node_Empty
4404+
(N, "Do_Withed_Unit_Spec",
4405+
"This type of library_unit is not yet handled");
43784406
end case;
43794407

43804408
end if;

0 commit comments

Comments
 (0)