Skip to content

Commit c243f55

Browse files
committed
Squashed commits from prerequisite PRs #231 and #251
Not need to review here.
1 parent 021a06e commit c243f55

File tree

4 files changed

+111
-25
lines changed

4 files changed

+111
-25
lines changed

gnat2goto/driver/tree_walk.adb

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
with Uname; use Uname;
21
with Namet; use Namet;
32
with Nlists; use Nlists;
43
with Sem;
@@ -1000,6 +999,8 @@ package body Tree_Walk is
1000999
return Symbol
10011000
is
10021001
U : constant Node_Id := Unit (N);
1002+
Unit_Name : constant Symbol_Id :=
1003+
Intern (Unique_Name (Unique_Defining_Entity (U)));
10031004
Unit_Symbol : Symbol;
10041005
begin
10051006
-- Insert all all specifications of all withed units including the
@@ -1008,29 +1009,29 @@ package body Tree_Walk is
10081009

10091010
case Nkind (U) is
10101011
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);
1012+
-- The specification of the subprogram body has already
1013+
-- been inserted into the symbol table by the call to
1014+
-- Do_Withed_Unit_Specs.
1015+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1016+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
10201017

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

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;
1021+
-- and update the symbol table entry for this subprogram.
1022+
Global_Symbol_Table.Replace (Unit_Name, Unit_Symbol);
1023+
Unit_Is_Subprogram := True;
10281024

10291025
when N_Package_Body =>
10301026
declare
10311027
Dummy : constant Irep := Do_Subprogram_Or_Block (U);
10321028
pragma Unreferenced (Dummy);
10331029
begin
1030+
-- The specification of the package body has already
1031+
-- been inserted into the symbol table by the call to
1032+
-- Do_Withed_Unit_Specs.
1033+
pragma Assert (Global_Symbol_Table.Contains (Unit_Name));
1034+
Unit_Symbol := Global_Symbol_Table (Unit_Name);
10341035
Unit_Is_Subprogram := False;
10351036
end;
10361037

@@ -3575,7 +3576,35 @@ package body Tree_Walk is
35753576

35763577
procedure Do_Package_Specification (N : Node_Id) is
35773578
Package_Decs : constant Irep := New_Irep (I_Code_Block);
3579+
Package_Name : Symbol_Id;
3580+
Package_Symbol : Symbol;
3581+
Def_Unit_Name : Node_Id;
3582+
Entity_Node : Node_Id;
3583+
35783584
begin
3585+
Def_Unit_Name := Defining_Unit_Name (N);
3586+
3587+
-- Defining_Unit_Name will return a N_Defining_Identifier
3588+
-- for non-child package but a N_Package_Specification when it is a
3589+
-- child package.
3590+
-- To obtain the Entity N_Defining_Identifier is required.
3591+
-- The actual parameter for Unique_Name must be an Entity node.
3592+
if Nkind (Def_Unit_Name) = N_Defining_Identifier then
3593+
Entity_Node := Def_Unit_Name;
3594+
else
3595+
Entity_Node := Defining_Identifier (Def_Unit_Name);
3596+
end if;
3597+
3598+
Package_Name := Intern (Unique_Name (Entity_Node));
3599+
Package_Symbol.Name := Package_Name;
3600+
Package_Symbol.BaseName := Package_Name;
3601+
Package_Symbol.PrettyName := Package_Name;
3602+
Package_Symbol.SymType := New_Irep (I_Void_Type);
3603+
Package_Symbol.Mode := Intern ("C");
3604+
Package_Symbol.Value := Make_Nil (Sloc (N));
3605+
3606+
Global_Symbol_Table.Insert (Package_Name, Package_Symbol);
3607+
35793608
Set_Source_Location (Package_Decs, Sloc (N));
35803609
if Present (Visible_Declarations (N)) then
35813610
Process_Declarations (Visible_Declarations (N), Package_Decs);
@@ -4338,12 +4367,9 @@ package body Tree_Walk is
43384367
-------------------------
43394368

43404369
procedure Do_Withed_Unit_Spec (N : Node_Id) is
4341-
Unit_Name : constant String := Get_Name_String (Get_Unit_Name (N));
43424370
begin
4343-
if Defining_Entity (N) = Stand.Standard_Standard or else
4344-
Unit_Name = "system%s"
4345-
then
4346-
-- At the moment Standard or System are not processed: TODO
4371+
if Defining_Entity (N) = Stand.Standard_Standard then
4372+
-- At the moment Standard is not processed: TODO
43474373
null;
43484374
else
43494375
-- Handle all other withed library unit declarations
@@ -4373,8 +4399,9 @@ package body Tree_Walk is
43734399
when N_Package_Body =>
43744400
null;
43754401
when others =>
4376-
Put_Line (Standard_Error,
4377-
"This type of library_unit is not yet handled");
4402+
Report_Unhandled_Node_Empty
4403+
(N, "Do_Withed_Unit_Spec",
4404+
"This type of library_unit is not yet handled");
43784405
end case;
43794406

43804407
end if;
@@ -4915,8 +4942,40 @@ package body Tree_Walk is
49154942
-- be called from Ada, or a foreign-language variable to be
49164943
-- accessed from Ada. This would (probably) require gnat2goto to
49174944
-- understand the foreign code, which we do not at the moment.
4918-
Put_Line (Standard_Error,
4919-
"Warning: Multi-language analysis unsupported.");
4945+
-- However, if the calling convention is specified as "Intrinsic"
4946+
-- then the subprogram is built into the compiler and gnat2goto
4947+
-- can safely ignore the pragma.
4948+
declare
4949+
-- If the pragma is specified with positional parameter
4950+
-- association, then the calling convention is the first
4951+
-- parameter. Check to see if it is Intrinsic.
4952+
Next_Ass : Node_Id := First (Pragma_Argument_Associations (N));
4953+
Is_Intrinsic : Boolean := Present (Next_Ass) and then
4954+
Nkind (Expression (Next_Ass)) = N_Identifier and then
4955+
Get_Name_String (Chars (Expression (Next_Ass))) = "intrinsic";
4956+
begin
4957+
-- If the first parameter is not Intrinsic, check named
4958+
-- parameters for calling convention
4959+
while not Is_Intrinsic and Present (Next_Ass) loop
4960+
if Chars (Next_Ass) /= No_Name and then
4961+
Get_Name_String (Chars (Next_Ass)) = "convention"
4962+
then
4963+
-- The named parameter is Convention, check to see if it
4964+
-- is Intrinsic
4965+
Is_Intrinsic :=
4966+
Get_Name_String (Chars (Expression (Next_Ass))) =
4967+
"intrinsic";
4968+
end if;
4969+
-- Get the next parameter association
4970+
Next_Ass := Next (Next_Ass);
4971+
end loop;
4972+
4973+
if not Is_Intrinsic then
4974+
Put_Line (Standard_Error,
4975+
"Warning: Multi-language analysis unsupported.");
4976+
end if;
4977+
end;
4978+
49204979
when Name_Elaborate =>
49214980
-- Specifies that the body of the named library unit is elaborated
49224981
-- before the current library_item. We will support packages.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Standard_Error from gnat2goto use_import:
2+
Warning: Multi-language analysis unsupported.
3+
Warning: Multi-language analysis unsupported.
4+
5+
[overflow.1] file use_import.adb line 16 arithmetic overflow on signed unary minus in -use_import__i: SUCCESS
6+
VERIFICATION SUCCESSFUL
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from test_support import *
2+
3+
prove("--signed-overflow-check")
4+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
procedure Use_Import is
2+
procedure P (X : Integer);
3+
pragma Import (C, P);
4+
5+
procedure Q (X : Integer);
6+
pragma Import (Convention => C, Entity => Q);
7+
8+
function "-" (X : Integer) return Integer;
9+
pragma Import (Convention => Intrinsic, Entity => "-");
10+
11+
function "+" (Left, Right : Integer) return Integer;
12+
pragma Import (Intrinsic, "+");
13+
14+
I : Integer := 1;
15+
begin
16+
I := -I;
17+
end Use_Import;

0 commit comments

Comments
 (0)