-
Notifications
You must be signed in to change notification settings - Fork 12
Refactor symtab inserts #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
gnat2goto/driver/goto_utils.adb
Outdated
@@ -120,6 +120,23 @@ package body GOTO_Utils is | |||
return Ret; | |||
end Symbol_Expr; | |||
|
|||
procedure New_Member_Symbol_Entry (Member_Name : String; Base_Name : String; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a Member
symbol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Element of a product type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now it is enum
specific. Renamed to New_Enum_Member_Symbol_Entry
.
gnat2goto/driver/goto_utils.ads
Outdated
with Post => Kind (Symbol_Expr'Result) = I_Symbol_Expr; | ||
|
||
procedure New_Member_Symbol_Entry (Member_Name : String; Base_Name : String; | ||
Enum_Type : Irep; Value_Expr : Irep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Enum_Type
? If this is enum specific, this should be made explicit in the name I'd say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the procedure.
gnat2goto/driver/goto_utils.ads
Outdated
procedure New_Member_Symbol_Entry (Member_Name : String; Base_Name : String; | ||
Enum_Type : Irep; Value_Expr : Irep; | ||
A_Symbol_Table : in out Symbol_Table) | ||
with Pre => Kind (Enum_Type) = I_Symbol_Type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to a be a symbol type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
gnat2goto/driver/tree_walk.adb
Outdated
@@ -1221,7 +1221,7 @@ package body Tree_Walk is | |||
UI_Image (Enumeration_Rep (Member)); | |||
Val_Name : constant String := Unique_Name (Member); | |||
Base_Name : constant String := Get_Name_String (Chars (Member)); | |||
Member_Symbol : Symbol; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un-removed.
gnat2goto/driver/goto_utils.adb
Outdated
@@ -120,6 +121,22 @@ package body GOTO_Utils is | |||
return Ret; | |||
end Symbol_Expr; | |||
|
|||
procedure New_Constant_Symbol_Entry (N : Node_Id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the Node_Id
is just used to get a name and a source location, can we just pass those to the function instead? The function doesn't seem node specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inlined into the calls. This procedure now takes Symbol_Id
.
gnat2goto/driver/goto_utils.ads
Outdated
A_Symbol_Table : in out Symbol_Table) | ||
with Pre => Nkind (N) = N_Object_Declaration; | ||
-- Adds a dummy entry to the symbol table to register that a | ||
-- constant has already been processed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Petr didn't add this, this was already there, and I agree that it was weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that, but if we're changing this already my opinion is
A) Either we figure out what this means and reword it so it's easier to understand
B) If we can't figure out what this means between the 3 of us I'd posit it's clearly not a very useful comment, so I'd rather remove it in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the comment makes more sense in the call-site: we call it when declaring a constant object, that does not have initial expression -- deferred constant declaration. It's completion is somewhere down the tree but we do not want to process is again which is why store it in the symbol table without the value it will be eventually initialised with.
I moved the comment to the call-site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also renamed the procedure to New_Valueless_Object_Symbol_Entry
.
gnat2goto/driver/goto_utils.adb
Outdated
@@ -121,6 +121,19 @@ package body GOTO_Utils is | |||
return Ret; | |||
end Symbol_Expr; | |||
|
|||
procedure New_Type_Symbol_Entry (Type_Name : String; Type_Type : Irep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type_Type
type type type type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Type_Of_Type
?
gnat2goto/driver/goto_utils.ads
Outdated
@@ -40,6 +40,10 @@ package GOTO_Utils is | |||
function Symbol_Expr (Sym : Symbol) return Irep | |||
with Post => Kind (Symbol_Expr'Result) = I_Symbol_Expr; | |||
|
|||
procedure New_Type_Symbol_Entry (Type_Name : String; Type_Type : Irep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Type_Name
is only used Intern
'ed, so IMHO this should probably just use a Symbol_Id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intern was inlined at call-site.
Fn_Symbol.Value := Assertion; | ||
Fn_Symbol.SymType := Fn_Type; | ||
Global_Symbol_Table.Insert (Fn_Symbol.Name, Fn_Symbol); | ||
Fn_Symbol := |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be moved up to the declaration, and the symbol be made constant now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we are changing the assertion
that will comprise the value
of this symbol.
@@ -121,6 +121,23 @@ package body GOTO_Utils is | |||
return Ret; | |||
end Symbol_Expr; | |||
|
|||
procedure New_Object_Symbol_Entry (Object_Name : Symbol_Id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's "object" in this context? We don't usually use that terminology in CBMC. I believe that's what GNAT calls an LValue? If so, this should have IsLValue set to true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The object
from do_object_declaration
. I this it takes place when we declare variables. I've added setting the lvalue
flag.
gnat2goto/driver/goto_utils.adb
Outdated
Member_Symbol : Symbol; | ||
begin | ||
Member_Symbol.Name := Intern (Member_Name); | ||
Member_Symbol.PrettyName := Intern (Base_Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the symbols getting interned here? In all the similar implementations of this we had the symbols where not interned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intern was inline at call-site.
gnat2goto/driver/goto_utils.adb
Outdated
@@ -120,6 +120,23 @@ package body GOTO_Utils is | |||
return Ret; | |||
end Symbol_Expr; | |||
|
|||
procedure New_Member_Symbol_Entry (Member_Name : String; Base_Name : String; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Element of a product type?
gnat2goto/driver/goto_utils.ads
Outdated
A_Symbol_Table : in out Symbol_Table) | ||
with Pre => Nkind (N) = N_Object_Declaration; | ||
-- Adds a dummy entry to the symbol table to register that a | ||
-- constant has already been processed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Petr didn't add this, this was already there, and I agree that it was weird.
adeb7fc
to
3e48299
Compare
@@ -154,52 +154,51 @@ package body GOTO_Utils is | |||
A_Symbol_Table.Insert (Subprog_Name, Subprog_Symbol); | |||
end New_Subprogram_Symbol_Entry; | |||
|
|||
procedure New_Type_Symbol_Entry (Type_Name : String; Type_Type : Irep; | |||
procedure New_Type_Symbol_Entry (Type_Name : Symbol_Id; Type_Of_Type : Irep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That kind of makes it sound like we have higher kinded types? I honestly don't really have a fantastic idea of what to name this either though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
3e48299
to
0eec6b1
Compare
and create a new wrapper in goto_utils.
and introduce a new wrapper in goto_utils.
and create a wrapper for it.
in make_runtime_check.
into a wrapper.
in do_subprogram_specification.
and check that everything declared is there after declaration.
211717d
to
30ea446
Compare
We were adding into the symbol table in a number of places across
tree_walk
. This PR wraps every access into a helper function ingoto_utils
. Checks that declared objects are present in the symbol table and introduces them otherwise. In the last bit, there is an overlap with #238.