Skip to content

Commit 30ea446

Browse files
committed
Introduce declared object into symbol table
and check that everything declared is there after declaration.
1 parent 06173f9 commit 30ea446

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

gnat2goto/driver/goto_utils.adb

+18
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ package body GOTO_Utils is
121121
return Ret;
122122
end Symbol_Expr;
123123

124+
procedure New_Object_Symbol_Entry (Object_Name : Symbol_Id;
125+
Object_Type : Irep;
126+
Object_Init_Value : Irep;
127+
A_Symbol_Table : in out Symbol_Table)
128+
is
129+
Object_Symbol : Symbol;
130+
begin
131+
Object_Symbol.Name := Object_Name;
132+
Object_Symbol.BaseName := Object_Name;
133+
Object_Symbol.PrettyName := Object_Name;
134+
Object_Symbol.SymType := Object_Type;
135+
Object_Symbol.Mode := Intern ("C");
136+
Object_Symbol.Value := Object_Init_Value;
137+
Object_Symbol.IsLValue := True;
138+
139+
A_Symbol_Table.Insert (Object_Name, Object_Symbol);
140+
end New_Object_Symbol_Entry;
141+
124142
procedure New_Subprogram_Symbol_Entry (Subprog_Name : Symbol_Id;
125143
Subprog_Type : Irep;
126144
A_Symbol_Table : in out Symbol_Table)

gnat2goto/driver/goto_utils.ads

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ package GOTO_Utils is
4141
function Symbol_Expr (Sym : Symbol) return Irep
4242
with Post => Kind (Symbol_Expr'Result) = I_Symbol_Expr;
4343

44+
procedure New_Object_Symbol_Entry (Object_Name : Symbol_Id;
45+
Object_Type : Irep;
46+
Object_Init_Value : Irep;
47+
A_Symbol_Table : in out Symbol_Table)
48+
with Pre => Kind (Object_Type) in Class_Type
49+
and (Object_Init_Value = Ireps.Empty
50+
or else Kind (Object_Init_Value) in Class_Expr);
51+
4452
procedure New_Subprogram_Symbol_Entry (Subprog_Name : Symbol_Id;
4553
Subprog_Type : Irep;
4654
A_Symbol_Table : in out Symbol_Table)

gnat2goto/driver/tree_walk.adb

+12-4
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,9 @@ package body Tree_Walk is
26702670
Decl : constant Irep := New_Irep (I_Code_Decl);
26712671
Init_Expr : Irep := Ireps.Empty;
26722672

2673+
Obj_Id : constant Symbol_Id := Intern (Unique_Name (Defined));
2674+
Obj_Type : constant Irep := Get_Type (Id);
2675+
26732676
function Has_Defaulted_Components (E : Entity_Id) return Boolean;
26742677
function Needs_Default_Initialisation (E : Entity_Id) return Boolean;
26752678
function Disc_Expr (N : Node_Id) return Node_Id;
@@ -2923,9 +2926,6 @@ package body Tree_Walk is
29232926
end Make_Default_Initialiser;
29242927

29252928
-- Begin processing for Do_Object_Declaration_Full_Declaration
2926-
2927-
Is_In_Symtab : constant Boolean :=
2928-
Global_Symbol_Table.Contains (Intern (Get_Identifier (Id)));
29292929
begin
29302930
Set_Source_Location (Decl, (Sloc (N)));
29312931
Set_Symbol (Decl, Id);
@@ -2946,14 +2946,22 @@ package body Tree_Walk is
29462946
end;
29472947
end if;
29482948

2949+
if not Global_Symbol_Table.Contains (Obj_Id)
2950+
then
2951+
New_Object_Symbol_Entry (Object_Name => Obj_Id,
2952+
Object_Type => Obj_Type,
2953+
Object_Init_Value => Init_Expr,
2954+
A_Symbol_Table => Global_Symbol_Table);
2955+
end if;
2956+
29492957
if Init_Expr /= Ireps.Empty then
29502958
Append_Op (Block, Make_Code_Assign (Lhs => Id,
29512959
Rhs => Typecast_If_Necessary (Init_Expr, Get_Type (Id),
29522960
Global_Symbol_Table),
29532961
Source_Location => Sloc (N)));
29542962
end if;
29552963

2956-
if not Is_In_Symtab then
2964+
if not Global_Symbol_Table.Contains (Intern (Get_Identifier (Id))) then
29572965
Register_Identifier_In_Symbol_Table
29582966
(Id, Init_Expr, Global_Symbol_Table);
29592967
end if;

0 commit comments

Comments
 (0)