Skip to content

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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/goto-programs/remove_instanceof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);
Copy link
Collaborator

Choose a reason for hiding this comment

The 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".

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
};
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/goto-programs/remove_instanceof.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down