Skip to content

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

Merged
merged 7 commits into from
Jun 3, 2019
Merged

Conversation

xbauch
Copy link
Contributor

@xbauch xbauch commented May 21, 2019

We were adding into the symbol table in a number of places across tree_walk. This PR wraps every access into a helper function in goto_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.

@@ -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;

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?

Copy link
Contributor

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?

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

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.

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;

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.

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the procedure.

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;

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?

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

@@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un-removed.

@@ -120,6 +121,22 @@ package body GOTO_Utils is
return Ret;
end Symbol_Expr;

procedure New_Constant_Symbol_Entry (N : Node_Id;

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.

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

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.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Contributor

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.

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@@ -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;

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.

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

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?

@@ -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;

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

Copy link
Contributor Author

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 :=

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?

Copy link
Contributor Author

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;

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.

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

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.

Member_Symbol : Symbol;
begin
Member_Symbol.Name := Intern (Member_Name);
Member_Symbol.PrettyName := Intern (Base_Name);
Copy link
Contributor

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.

Copy link
Contributor Author

@xbauch xbauch May 21, 2019

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.

@@ -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;
Copy link
Contributor

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?

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.
Copy link
Contributor

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.

@xbauch xbauch force-pushed the refactor-symtab-inserts branch from adeb7fc to 3e48299 Compare May 22, 2019 08:01
@@ -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;

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.

Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xbauch xbauch force-pushed the refactor-symtab-inserts branch from 3e48299 to 0eec6b1 Compare June 3, 2019 15:48
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.
in do_subprogram_specification.
and check that everything declared is there after declaration.
@xbauch xbauch force-pushed the refactor-symtab-inserts branch 2 times, most recently from 211717d to 30ea446 Compare June 3, 2019 19:09
@xbauch xbauch merged commit 7aedc79 into diffblue:master Jun 3, 2019
@xbauch xbauch deleted the refactor-symtab-inserts branch June 10, 2019 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants