retdec
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
retdec::llvmir2hll::Expression Class Referenceabstract

A base class of all expressions. More...

#include <expression.h>

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

Public Member Functions

virtual ShPtr< TypegetType () const =0
 Returns the type of the expression. More...
 
virtual void replace (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr)=0
 Replaces all occurrences of oldExpr with newExpr in the current expression. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Value
virtual ~Value ()=default
 
virtual ShPtr< ValuegetSelf () override
 Returns a shared pointer of self. More...
 
virtual ShPtr< Valueclone ()=0
 Returns a clone of the value. More...
 
virtual bool isEqualTo (ShPtr< Value > otherValue) const =0
 Returns true if this value is equal to otherValue, false otherwise. More...
 
std::string getTextRepr ()
 Returns a textual representation of the value. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Visitable
virtual void accept (Visitor *v)=0
 Visitor pattern implementation. 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...
 
virtual void update (ShPtr< Value > subject, ShPtr< Value > arg=nullptr)
 Subject has changed its state. 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 void replaceExpression (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr)
 Replaces oldExpr with newExpr. More...
 

Protected Member Functions

 Expression ()=default
 
- 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...
 

Additional Inherited Members

- 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
 

Detailed Description

A base class of all expressions.

Instances of this class have reference object semantics.

Constructor & Destructor Documentation

◆ Expression()

retdec::llvmir2hll::Expression::Expression ( )
protecteddefault

Member Function Documentation

◆ getType()

virtual ShPtr<Type> retdec::llvmir2hll::Expression::getType ( ) const
pure virtual

◆ replace()

virtual void retdec::llvmir2hll::Expression::replace ( ShPtr< Expression oldExpr,
ShPtr< Expression newExpr 
)
pure virtual

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

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

Note that if oldExpr is the current expression on which this function is called, nothing gets replaced, i.e. the replacements are done only in the members of the current expression on which this function is called.

Preconditions
  • oldExpr is non-null

Implemented in retdec::llvmir2hll::Variable, retdec::llvmir2hll::UnaryOpExpr, retdec::llvmir2hll::TernaryOpExpr, retdec::llvmir2hll::ConstSymbol, retdec::llvmir2hll::ConstStruct, retdec::llvmir2hll::ConstString, retdec::llvmir2hll::ConstNullPointer, retdec::llvmir2hll::ConstInt, retdec::llvmir2hll::ConstFloat, retdec::llvmir2hll::ConstBool, retdec::llvmir2hll::ConstArray, retdec::llvmir2hll::CastExpr, retdec::llvmir2hll::CallExpr, and retdec::llvmir2hll::BinaryOpExpr.

◆ replaceExpression()

void retdec::llvmir2hll::Expression::replaceExpression ( ShPtr< Expression oldExpr,
ShPtr< Expression newExpr 
)
static

Replaces oldExpr with newExpr.

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

If you want to replace oldExpr with newExpr only in a single expression (where), then use where->replace(oldExpr, newExpr). However, if where is identical to oldExpr, then it has to be replaced manually. For example, if where is the return value of a return statement stmt, the following code can be used:

if (retVal == oldExpr) {
returnStmt->setRetVal(newExpr);
} else {
retVal->replace(oldExpr, newExpr);
}
Preconditions
  • oldExpr is non-null

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