retdec
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::ForLoopStmt Class Referencefinal

A for loop statement. More...

#include <for_loop_stmt.h>

Inheritance diagram for retdec::llvmir2hll::ForLoopStmt:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::ForLoopStmt:
Collaboration graph
[legend]

Public Member Functions

virtual ShPtr< Valueclone () 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< ExpressionasExpression () const override
 Returns the statement as an expression. More...
 
ShPtr< VariablegetIndVar () const
 Returns the induction variable. More...
 
ShPtr< ExpressiongetStartValue () const
 Returns the starting value. More...
 
ShPtr< ExpressiongetEndCond () const
 Returns the end condition. More...
 
ShPtr< ExpressiongetStep () const
 Returns the step. More...
 
ShPtr< StatementgetBody () const
 Returns the body. More...
 
void setIndVar (ShPtr< Variable > newIndVar)
 Sets a new induction variable. More...
 
void setStartValue (ShPtr< Expression > newStartValue)
 Sets a new start value. More...
 
void setEndCond (ShPtr< Expression > newEndCond)
 Sets a new end condition. More...
 
void setStep (ShPtr< Expression > newStep)
 Sets a new step. More...
 
void setBody (ShPtr< Statement > newBody)
 Sets a new body. More...
 
Observer Interface
virtual void update (ShPtr< Value > subject, ShPtr< Value > arg=nullptr) override
 Updates the statement according to the changes of subject. More...
 
Visitor Interface
virtual void accept (Visitor *v) override
 Visitor pattern implementation. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Statement
ShPtr< StatementgetParent () 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< StatementgetSuccessor () 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< StatementgetUniquePredecessor () 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...
 
- Public Member Functions inherited from retdec::llvmir2hll::Value
virtual ~Value ()=default
 
virtual ShPtr< ValuegetSelf () override
 Returns a shared pointer of self. More...
 
std::string getTextRepr ()
 Returns a textual representation of the value. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Metadatable< std::string >
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...
 
- Public Member Functions inherited from retdec::llvmir2hll::Observer< Value >
 Observer ()=default
 Creates a new observer. More...
 
virtual ~Observer ()=default
 Destructs the observer. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Subject< Value >
 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< ForLoopStmtcreate (ShPtr< Variable > indVar, ShPtr< Expression > startValue, ShPtr< Expression > endCond, ShPtr< Expression > step, ShPtr< Statement > body, ShPtr< Statement > succ=nullptr, Address a=Address::Undefined)
 Constructs a new for loop statement. More...
 
- Static Public Member Functions inherited from retdec::llvmir2hll::Statement
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< StatementmergeStatements (ShPtr< Statement > stmt1, ShPtr< Statement > stmt2)
 Merges the two given statements. More...
 
static ShPtr< StatementcloneStatements (ShPtr< Statement > stmts)
 Clones the given list of statements. More...
 
static ShPtr< StatementgetLastStatement (ShPtr< Statement > stmts)
 Returns the last statement in stmts. More...
 

Private Member Functions

 ForLoopStmt (ShPtr< Variable > indVar, ShPtr< Expression > startValue, ShPtr< Expression > endCond, ShPtr< Expression > step, ShPtr< Statement > body, Address a)
 Constructs a new for loop statement. More...
 

Private Attributes

ShPtr< VariableindVar
 Induction variable. More...
 
ShPtr< ExpressionstartValue
 Starting value. More...
 
ShPtr< ExpressionendCond
 End condition. More...
 
ShPtr< Expressionstep
 Step. More...
 
ShPtr< Statementbody
 Body. More...
 

Additional Inherited Members

- Public Types inherited from retdec::llvmir2hll::Statement
using predecessor_iterator = StmtSet::const_iterator
 Predecessor iterator. More...
 
- Public Types inherited from retdec::llvmir2hll::Subject< Value >
using ConcreteObserver = Observer< Value, Value >
 A concrete observer. More...
 
using ObserverPtr = WkPtr< ConcreteObserver >
 A pointer to an observer. More...
 
- Protected Types inherited from retdec::llvmir2hll::Subject< Value >
using ObserverContainer = std::vector< ObserverPtr >
 A container to store observers. More...
 
using observer_iterator = typename ObserverContainer::const_iterator
 
- Protected Member Functions inherited from retdec::llvmir2hll::Statement
 Statement (Address a=Address::Undefined)
 Constructs a new statement. More...
 
- Protected Member Functions inherited from retdec::llvmir2hll::Value
 Value ()=default
 
- Protected Member Functions inherited from retdec::llvmir2hll::Visitable
 Visitable ()=default
 
 ~Visitable ()=default
 
- Protected Member Functions inherited from retdec::llvmir2hll::Metadatable< std::string >
 Metadatable ()
 Constructs a new metadatable object. More...
 
- Protected Member Functions inherited from retdec::llvmir2hll::Subject< Value >
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...
 
- Protected Attributes inherited from retdec::llvmir2hll::Statement
ShPtr< Statementsucc
 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...
 

Detailed Description

A for loop statement.

Use create() to create instances. Instances of this class have reference object semantics. This class is not meant to be subclassed.

Constructor & Destructor Documentation

◆ ForLoopStmt()

retdec::llvmir2hll::ForLoopStmt::ForLoopStmt ( ShPtr< Variable indVar,
ShPtr< Expression startValue,
ShPtr< Expression endCond,
ShPtr< Expression step,
ShPtr< Statement body,
Address  a 
)
private

Constructs a new for loop statement.

See create() for more information.

Member Function Documentation

◆ accept()

void retdec::llvmir2hll::ForLoopStmt::accept ( Visitor v)
overridevirtual

Visitor pattern implementation.

Subclasses should implement this method as:

v->visit(ucast<T>(shared_from_this()));

where T is the name of the subclass, and shared_from_this() and ucast<> are from Decompiler/Support/SmartPtr.h.

Implements retdec::llvmir2hll::Visitable.

◆ asExpression()

ShPtr< Expression > retdec::llvmir2hll::ForLoopStmt::asExpression ( ) const
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.

◆ clone()

ShPtr< Value > retdec::llvmir2hll::ForLoopStmt::clone ( )
overridevirtual

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:

  • predecessors and successors of statements

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.

◆ create()

ShPtr< ForLoopStmt > retdec::llvmir2hll::ForLoopStmt::create ( ShPtr< Variable indVar,
ShPtr< Expression startValue,
ShPtr< Expression endCond,
ShPtr< Expression step,
ShPtr< Statement body,
ShPtr< Statement succ = nullptr,
Address  a = Address::Undefined 
)
static

Constructs a new for loop statement.

Parameters
[in]indVarInduction variable.
[in]startValueStarting value.
[in]endCondEnd condition.
[in]stepStep.
[in]bodyBody.
[in]succFollower of the statement in the program flow.
[in]aAddress.

The loop is of the following form (written in C):

ShPtr< Expression > step
Step.
Definition: for_loop_stmt.h:79
ShPtr< Expression > endCond
End condition.
Definition: for_loop_stmt.h:76
ShPtr< Variable > indVar
Induction variable.
Definition: for_loop_stmt.h:70
ShPtr< Expression > startValue
Starting value.
Definition: for_loop_stmt.h:73
ShPtr< Statement > body
Body.
Definition: for_loop_stmt.h:82
Preconditions
  • all operands except succ are non-null

◆ getBody()

ShPtr< Statement > retdec::llvmir2hll::ForLoopStmt::getBody ( ) const

Returns the body.

◆ getEndCond()

ShPtr< Expression > retdec::llvmir2hll::ForLoopStmt::getEndCond ( ) const

Returns the end condition.

◆ getIndVar()

ShPtr< Variable > retdec::llvmir2hll::ForLoopStmt::getIndVar ( ) const

Returns the induction variable.

◆ getStartValue()

ShPtr< Expression > retdec::llvmir2hll::ForLoopStmt::getStartValue ( ) const

Returns the starting value.

◆ getStep()

ShPtr< Expression > retdec::llvmir2hll::ForLoopStmt::getStep ( ) const

Returns the step.

◆ isCompound()

virtual bool retdec::llvmir2hll::ForLoopStmt::isCompound ( )
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.

◆ isEqualTo()

bool retdec::llvmir2hll::ForLoopStmt::isEqualTo ( ShPtr< Value otherValue) const
overridevirtual

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.

◆ replace()

void retdec::llvmir2hll::ForLoopStmt::replace ( ShPtr< Expression oldExpr,
ShPtr< Expression newExpr 
)
overridevirtual

Replaces all occurrences of oldExpr with newExpr in the current statement.

Parameters
[in]oldExprOld expression to be replaced.
[in]newExprReplacement.

In compound statements, their body is left untouched, i.e. this function doesn't replace expressions in the bodies of statements.

Preconditions
  • oldExpr is non-null

Implements retdec::llvmir2hll::Statement.

◆ setBody()

void retdec::llvmir2hll::ForLoopStmt::setBody ( ShPtr< Statement newBody)

Sets a new body.

Preconditions
  • newBody is non-null

◆ setEndCond()

void retdec::llvmir2hll::ForLoopStmt::setEndCond ( ShPtr< Expression newEndCond)

Sets a new end condition.

Preconditions
  • newEndCond is non-null

◆ setIndVar()

void retdec::llvmir2hll::ForLoopStmt::setIndVar ( ShPtr< Variable newIndVar)

Sets a new induction variable.

Preconditions
  • newIndVar is non-null

◆ setStartValue()

void retdec::llvmir2hll::ForLoopStmt::setStartValue ( ShPtr< Expression newStartValue)

Sets a new start value.

Preconditions
  • newStartValue is non-null

◆ setStep()

void retdec::llvmir2hll::ForLoopStmt::setStep ( ShPtr< Expression newStep)

Sets a new step.

Preconditions
  • newStep is non-null

◆ update()

void retdec::llvmir2hll::ForLoopStmt::update ( ShPtr< Value subject,
ShPtr< Value arg = nullptr 
)
overridevirtual

Updates the statement according to the changes of subject.

Parameters
[in]subjectObservable object.
[in]argOptional argument.

Replaces subject with arg. For example, if subject is the induction variable, this function replaces it with arg.

This function does nothing when:

  • subject does not correspond to any part of the statement
  • arg is not a statement/variable/expression
Preconditions
  • subject is non-null
See also
Subject::update()

Reimplemented from retdec::llvmir2hll::Observer< Value >.

Member Data Documentation

◆ body

ShPtr<Statement> retdec::llvmir2hll::ForLoopStmt::body
private

Body.

◆ endCond

ShPtr<Expression> retdec::llvmir2hll::ForLoopStmt::endCond
private

End condition.

◆ indVar

ShPtr<Variable> retdec::llvmir2hll::ForLoopStmt::indVar
private

Induction variable.

◆ startValue

ShPtr<Expression> retdec::llvmir2hll::ForLoopStmt::startValue
private

Starting value.

◆ step

ShPtr<Expression> retdec::llvmir2hll::ForLoopStmt::step
private

Step.


The documentation for this class was generated from the following files: