retdec
|
An if/else-if/else statement. More...
#include <if_stmt.h>
Public Types | |
using | IfClause = std::pair< ShPtr< Expression >, ShPtr< Statement > > |
If clause (condition and body). More... | |
using | IfClauseList = std::list< IfClause > |
A list of if clauses. More... | |
using | clause_iterator = IfClauseList::const_iterator |
![]() | |
using | predecessor_iterator = StmtSet::const_iterator |
Predecessor iterator. More... | |
![]() | |
using | ConcreteObserver = Observer< Value, Value > |
A concrete observer. More... | |
using | ObserverPtr = WkPtr< ConcreteObserver > |
A pointer to an observer. More... | |
Public Member Functions | |
virtual ShPtr< Value > | clone () override |
Returns a clone of the value. More... | |
virtual bool | isEqualTo (ShPtr< Value > otherValue) const override |
Returns true if this value is equal to otherValue, false otherwise. More... | |
virtual bool | isCompound () override |
Returns true if the statement is a compound statement, false otherwise. More... | |
virtual void | replace (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override |
Replaces all occurrences of oldExpr with newExpr in the current statement. More... | |
virtual ShPtr< Expression > | asExpression () const override |
Returns the statement as an expression. More... | |
Observer Interface | |
virtual void | update (ShPtr< Value > subject, ShPtr< Value > arg=nullptr) override |
Updates the statement according to the changes of subject. More... | |
Clause Accessors | |
clause_iterator | clause_begin () const |
Returns an iterator to the first if clause (if cond then body ). More... | |
clause_iterator | clause_end () const |
Returns an iterator past the last else-if clause. More... | |
void | addClause (ShPtr< Expression > cond, ShPtr< Statement > body) |
Adds a new clause ([else] if cond then body ). More... | |
clause_iterator | removeClause (clause_iterator clauseIterator) |
Removes the given clause, specified by an iterator. More... | |
bool | hasClauses () const |
Returns true if there is at least one clause, false otherwise. More... | |
bool | hasIfClause () const |
Returns true if the statement has the if clause, false otherwise. More... | |
ShPtr< Expression > | getFirstIfCond () const |
Returns the condition of the first if clause in the statement. More... | |
ShPtr< Statement > | getFirstIfBody () const |
Returns the body of the first if clause in the statement. More... | |
void | setFirstIfCond (ShPtr< Expression > newCond) |
Sets a new condition of the first if clause. More... | |
void | setFirstIfBody (ShPtr< Statement > newBody) |
Sets a new body of the first if clause. More... | |
bool | hasElseIfClauses () const |
Returns true if there is at least one else-if clause, false otherwise. More... | |
ShPtr< Statement > | getElseClause () const |
Returns the else clause (if any), the null pointer otherwise. More... | |
bool | hasElseClause () const |
Returns true if this if statement has an else clause, false otherwise. More... | |
void | setElseClause (ShPtr< Statement > body) |
Sets the else clause (else body ). More... | |
void | removeElseClause () |
Removes the else clause (if any). More... | |
Visitor Interface | |
virtual void | accept (Visitor *v) override |
Visitor pattern implementation. More... | |
![]() | |
ShPtr< Statement > | getParent () const |
Returns the parent of the given statement. More... | |
Address | getAddress () const |
Returns statement's address. More... | |
bool | hasSuccessor () const |
Returns true if the statement has a successor, false otherwise. More... | |
ShPtr< Statement > | getSuccessor () const |
Returns the successor of statement. More... | |
void | setSuccessor (ShPtr< Statement > newSucc) |
Sets newSucc as the current statement's successor. More... | |
void | removeSuccessor () |
Removes the successor of the statement (if there is any). More... | |
void | appendStatement (ShPtr< Statement > stmt) |
Appends stmt to the statement. More... | |
bool | hasPredecessors () const |
Returns true if the statement has any predecessor, false otherwise. More... | |
std::size_t | getNumberOfPredecessors () const |
Returns the number of predecessors of the current statement. More... | |
void | addPredecessor (ShPtr< Statement > stmt) |
Adds a new predecessor: stmt. More... | |
ShPtr< Statement > | getUniquePredecessor () const |
Returns the unique predecessor of the current statement. More... | |
void | removePredecessor (ShPtr< Statement > stmt) |
Removes the predecessor stmt. More... | |
void | removePredecessors (bool onlyNonGoto=false) |
Removes all predecessors of the statement. More... | |
void | prependStatement (ShPtr< Statement > stmt) |
Prepends stmt to the statement. More... | |
predecessor_iterator | predecessor_begin () const |
Returns an iterator to the first predecessor (if any). More... | |
predecessor_iterator | predecessor_end () const |
Returns an iterator past the last predecessor. More... | |
bool | hasLabel () const |
Does the statement has a label set? More... | |
std::string | getLabel () const |
Returns the statement's label. More... | |
void | setLabel (const std::string &newLabel) |
Sets a new label of the statement. More... | |
void | removeLabel () |
Removes the statement's label (if any). More... | |
void | transferLabelFrom (ShPtr< Statement > stmt) |
Transfers the label from the given statement to the current statement. More... | |
void | transferLabelTo (ShPtr< Statement > stmt) |
Transfers the label from the current statement to the given statement. More... | |
bool | isGotoTarget () const |
Returns true if the statement is the target of a goto statement, false otherwise. More... | |
void | redirectGotosTo (ShPtr< Statement > stmt) |
Redirects gotos to the statement to the given statement stmt. More... | |
![]() | |
virtual | ~Value ()=default |
virtual ShPtr< Value > | getSelf () override |
Returns a shared pointer of self. More... | |
std::string | getTextRepr () |
Returns a textual representation of the value. More... | |
![]() | |
void | setMetadata (std::string data) |
Attaches new metadata. More... | |
std::string | getMetadata () const |
Returns the attached metadata. More... | |
bool | hasMetadata () const |
Are there any non-empty metadata? More... | |
![]() | |
Observer ()=default | |
Creates a new observer. More... | |
virtual | ~Observer ()=default |
Destructs the observer. More... | |
![]() | |
Subject () | |
Creates a new subject. More... | |
virtual | ~Subject ()=default |
Destructs the subject. More... | |
void | addObserver (ObserverPtr observer) |
Adds a new observer to the list of observers. More... | |
void | removeObserver (ObserverPtr observer) |
Removes the selected observer from the list of observers. More... | |
void | removeObservers () |
Removes all observers. More... | |
void | notifyObservers (ShPtr< Value > arg=nullptr) |
Notifies all observers by calling Observer::update() on them. More... | |
Static Public Member Functions | |
static ShPtr< IfStmt > | create (ShPtr< Expression > cond, ShPtr< Statement > body, ShPtr< Statement > succ=nullptr, Address a=Address::Undefined) |
Constructs a new if statement. More... | |
![]() | |
static void | removeStatement (ShPtr< Statement > stmt) |
Removes this statement from a block which contains it. More... | |
static void | removeStatementButKeepDebugComment (ShPtr< Statement > stmt) |
Removes the given statement, but keeps its debug comment (if any). More... | |
static bool | areEqualStatements (ShPtr< Statement > stmts1, ShPtr< Statement > stmts2) |
Returns true if stmts1 and stmts are equal, false otherwise. More... | |
static bool | isStatementInStatements (ShPtr< Statement > stmt, ShPtr< Statement > stmts) |
Returns true if statement stmt is in the sequence of statements stmts, false otherwise. More... | |
static void | replaceStatement (ShPtr< Statement > oldStmt, ShPtr< Statement > newStmt) |
Replaces oldStmt with newStmt. More... | |
static void | removeLastStatement (ShPtr< Statement > stmts) |
Removes the last statements in the sequence of statements stmts. More... | |
static ShPtr< Statement > | mergeStatements (ShPtr< Statement > stmt1, ShPtr< Statement > stmt2) |
Merges the two given statements. More... | |
static ShPtr< Statement > | cloneStatements (ShPtr< Statement > stmts) |
Clones the given list of statements. More... | |
static ShPtr< Statement > | getLastStatement (ShPtr< Statement > stmts) |
Returns the last statement in stmts. More... | |
Private Member Functions | |
IfStmt (ShPtr< Expression > cond, ShPtr< Statement > body, Address a=Address::Undefined) | |
Constructs a new if/else-if/else statement. More... | |
Private Attributes | |
IfClauseList | ifClauseList |
A list of if clauses. More... | |
ShPtr< Statement > | elseClause |
The else clause (if any). More... | |
Additional Inherited Members | |
![]() | |
using | ObserverContainer = std::vector< ObserverPtr > |
A container to store observers. More... | |
using | observer_iterator = typename ObserverContainer::const_iterator |
![]() | |
Statement (Address a=Address::Undefined) | |
Constructs a new statement. More... | |
![]() | |
Value ()=default | |
![]() | |
Visitable ()=default | |
~Visitable ()=default | |
![]() | |
Metadatable () | |
Constructs a new metadatable object. More... | |
![]() | |
observer_iterator | observer_begin () const |
Returns a constant iterator to the first observer. More... | |
observer_iterator | observer_end () const |
Returns a constant iterator past the last observer. More... | |
![]() | |
ShPtr< Statement > | succ |
Successor statement. More... | |
StmtSet | preds |
Predecessor statements. More... | |
std::string | label |
Label. More... | |
Address | address |
Address of ASM instruction from which this statement was created from. More... | |
An if/else-if/else statement.
Use create() to create instances. Instances of this class have reference object semantics. This class is not meant to be subclassed.
using retdec::llvmir2hll::IfStmt::clause_iterator = IfClauseList::const_iterator |
If/else-if
clause iterator. Attributes (i
is an iterator):
i->first
is the clause's condition,i->second
is the clause's body. using retdec::llvmir2hll::IfStmt::IfClause = std::pair<ShPtr<Expression>, ShPtr<Statement> > |
If
clause (condition and body).
using retdec::llvmir2hll::IfStmt::IfClauseList = std::list<IfClause> |
A list of if
clauses.
|
private |
Constructs a new if/else-if/else statement.
See create() for more information.
|
overridevirtual |
Visitor pattern implementation.
Subclasses should implement this method as:
where T
is the name of the subclass, and shared_from_this() and ucast<>
are from Decompiler/Support/SmartPtr.h.
Implements retdec::llvmir2hll::Visitable.
void retdec::llvmir2hll::IfStmt::addClause | ( | ShPtr< Expression > | cond, |
ShPtr< Statement > | body | ||
) |
Adds a new clause ([else] if cond then body
).
[in] | cond | Clause condition. |
[in] | body | Clause body. |
If there are no clauses, the added clause is the if clause; otherwise, it is an else-if clause.
Does not invalidate any existing iterators to this if statement.
|
overridevirtual |
Returns the statement as an expression.
If the statement cannot be converted into an expression, the null pointer is returned.
Parts of the statement are not cloned (if you want a clone, call clone()
on the returned expression).
Implements retdec::llvmir2hll::Statement.
IfStmt::clause_iterator retdec::llvmir2hll::IfStmt::clause_begin | ( | ) | const |
Returns an iterator to the first if clause (if cond then body
).
Use getElseClause() to obtain the else clause (it cannot be accessed by iterators).
IfStmt::clause_iterator retdec::llvmir2hll::IfStmt::clause_end | ( | ) | const |
Returns an iterator past the last else-if clause.
Use getElseClause() to obtain the else clause (it cannot be accessed by iterators).
Returns a clone of the value.
A clone is (in most cases) an exact copy of the value. This member function provides the copy mechanism for reference objects.
The following parts of values are not cloned:
The following subclasses of Value are not cloned, i.e. they are returned without any copying:
Statements in compound statements (i.e. statements where isCompound()
returns true
) are cloned without their successors; therefore, e.g., just the first statement of every if's clause is cloned.
Implements retdec::llvmir2hll::Value.
|
static |
Returns the else clause (if any), the null pointer otherwise.
Returns the body of the first if clause in the statement.
If there are no if clauses, the null pointer is returned.
ShPtr< Expression > retdec::llvmir2hll::IfStmt::getFirstIfCond | ( | ) | const |
Returns the condition of the first if clause in the statement.
If there are no if clauses, the null pointer is returned.
bool retdec::llvmir2hll::IfStmt::hasClauses | ( | ) | const |
Returns true
if there is at least one clause, false
otherwise.
This function takes into account all the types of clauses: the if clause, else-if clauses, and the else clause (if any).
bool retdec::llvmir2hll::IfStmt::hasElseClause | ( | ) | const |
Returns true
if this if statement has an else clause, false
otherwise.
bool retdec::llvmir2hll::IfStmt::hasElseIfClauses | ( | ) | const |
Returns true
if there is at least one else-if clause, false
otherwise.
An else-if clause is a clause which is not the main if's clause or the else clause.
bool retdec::llvmir2hll::IfStmt::hasIfClause | ( | ) | const |
Returns true
if the statement has the if clause, false
otherwise.
Note that if this function returns false
, then the statement is most probably not valid (every if statement should have an if clause).
|
inlineoverridevirtual |
Returns true
if the statement is a compound statement, false
otherwise.
A compound statement is a statement with nested statements, e.g. an if statement, a switch statement, a while loop, and a for loop.
Implements retdec::llvmir2hll::Statement.
Returns true
if this value is equal to otherValue, false
otherwise.
This member function brings the support of value object semantics into reference objects, namely equality based not only on identity.
This function doesn't consider observers, metadata, etc.
Implements retdec::llvmir2hll::Value.
IfStmt::clause_iterator retdec::llvmir2hll::IfStmt::removeClause | ( | clause_iterator | clauseIterator | ) |
Removes the given clause, specified by an iterator.
After this function is called, existing iterators to the removed clause are invalidated. To provide an easy way of removing clauses while iterating over them, the iterator returned from this function can be used. Example:
You cannot remove the else clause by this function; use removeElseClause() instead.
If you remove the only clause of the statement, then the statement becomes a statement without any clauses. Such a statement is useless.
void retdec::llvmir2hll::IfStmt::removeElseClause | ( | ) |
Removes the else clause (if any).
Calling this function is the same as calling setElseClause(ShPtr<Statement>())
.
|
overridevirtual |
Replaces all occurrences of oldExpr with newExpr in the current statement.
[in] | oldExpr | Old expression to be replaced. |
[in] | newExpr | Replacement. |
In compound statements, their body is left untouched, i.e. this function doesn't replace expressions in the bodies of statements.
Implements retdec::llvmir2hll::Statement.
Sets the else clause (else body
).
[in] | body | Clause body. |
If body is the null pointer, then there is no else clause.
Sets a new body of the first if clause.
void retdec::llvmir2hll::IfStmt::setFirstIfCond | ( | ShPtr< Expression > | newCond | ) |
Sets a new condition of the first if clause.
|
overridevirtual |
Updates the statement according to the changes of subject.
[in] | subject | Observable object. |
[in] | arg | Optional argument. |
Replaces subject with arg. For example, if subject is the conditions of some if-clause, this function replaces it with arg.
This function does nothing when:
Reimplemented from retdec::llvmir2hll::Observer< Value >.
|
private |
A list of if
clauses.