-
Notifications
You must be signed in to change notification settings - Fork 273
Allow to remove instanceof when remove exceptions #1710
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,16 +28,17 @@ class remove_instanceoft | |
class_hierarchy(symbol_table); | ||
} | ||
|
||
// Lower instanceof for a single functions | ||
// Lower instanceof for a single function | ||
bool lower_instanceof(goto_programt &); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question to compiler experts: is "lowering" a well-defined technical term? I would have used "translate" or "rewrite". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, for example http://www.drdobbs.com/architecture-and-design/so-you-want-to-write-your-own-language/240165488?pgno=2 -- "rewriting more complex semantic constructs in terms of simpler ones", here "instanceof" in terms of classid equality comparisons. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not that I consider Dr Dobbs an authoritative reference, but ok. But then you made me search and it seems that GCC and LLVM do use that terminology. So maybe not Dragon-book style, but apparently common in practice. |
||
|
||
// Lower instanceof for a single instruction | ||
bool lower_instanceof(goto_programt &, goto_programt::targett); | ||
|
||
protected: | ||
symbol_tablet &symbol_table; | ||
namespacet ns; | ||
class_hierarchyt class_hierarchy; | ||
|
||
bool lower_instanceof(goto_programt &, goto_programt::targett); | ||
|
||
std::size_t lower_instanceof( | ||
exprt &, goto_programt &, goto_programt::targett); | ||
}; | ||
|
@@ -168,9 +169,24 @@ bool remove_instanceoft::lower_instanceof(goto_programt &goto_program) | |
} | ||
|
||
|
||
/// Replace an instanceof in the expression or guard of the passed instruction | ||
/// of the given function body with an explicit class-identifier test. | ||
/// \remarks Extra auxiliary variables may be introduced into symbol_table. | ||
/// \param target: The instruction to work on. | ||
/// \param goto_program: The function body containing the instruction. | ||
/// \param symbol_table: The symbol table to add symbols to. | ||
void remove_instanceof( | ||
goto_programt::targett target, | ||
goto_programt &goto_program, | ||
symbol_tablet &symbol_table) | ||
{ | ||
remove_instanceoft rem(symbol_table); | ||
rem.lower_instanceof(goto_program, target); | ||
} | ||
|
||
/// Replace every instanceof in the passed function with an explicit | ||
/// class-identifier test. | ||
/// Extra auxiliary variables may be introduced into symbol_table. | ||
/// \remarks Extra auxiliary variables may be introduced into symbol_table. | ||
/// \param function: The function to work on. | ||
/// \param symbol_table: The symbol table to add symbols to. | ||
void remove_instanceof( | ||
|
@@ -183,7 +199,7 @@ void remove_instanceof( | |
|
||
/// Replace every instanceof in every function with an explicit | ||
/// class-identifier test. | ||
/// Extra auxiliary variables may be introduced into symbol_table. | ||
/// \remarks Extra auxiliary variables may be introduced into symbol_table. | ||
/// \param goto_functions: The functions to work on. | ||
/// \param symbol_table: The symbol table to add symbols to. | ||
void remove_instanceof( | ||
|
@@ -198,6 +214,11 @@ void remove_instanceof( | |
goto_functions.compute_location_numbers(); | ||
} | ||
|
||
/// Replace every instanceof in every function with an explicit | ||
/// class-identifier test. | ||
/// \remarks Extra auxiliary variables may be introduced into symbol_table. | ||
/// \param goto_model: The functions to work on and the symbol table to add | ||
/// symbols to. | ||
void remove_instanceof(goto_modelt &goto_model) | ||
{ | ||
remove_instanceof(goto_model.goto_functions, goto_model.symbol_table); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,11 @@ Author: Chris Smowton, [email protected] | |
#include "goto_functions.h" | ||
#include "goto_model.h" | ||
|
||
void remove_instanceof( | ||
goto_programt::targett target, | ||
goto_programt &goto_program, | ||
symbol_tablet &symbol_table); | ||
|
||
void remove_instanceof( | ||
goto_functionst::goto_functiont &function, | ||
symbol_tablet &symbol_table); | ||
|
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.
Is this more than a Boolean?
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 favour keeping the enum since it makes the callsite clearer
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.
Ok, makes sense, but might warrant a comment to clarify that that's the sole intent?