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

A representation of a variable. More...

#include <variable.h>

Inheritance diagram for retdec::llvmir2hll::Variable:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::Variable:
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 ShPtr< TypegetType () const override
 Returns the type of the variable. More...
 
virtual void replace (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr) override
 Replaces all occurrences of oldExpr with newExpr in the current expression. More...
 
const std::string & getInitialName () const
 Returns the initial name of the variable. More...
 
const std::string & getName () const
 Returns the name of the variable. More...
 
Address getAddress () const
 
bool hasName () const
 Returns true if the variable has name, false otherwise. More...
 
bool isInternal () const
 Returns true if the variable is internal, false otherwise. More...
 
bool isExternal () const
 Returns true if the variable is external, false otherwise. More...
 
ShPtr< Variablecopy () const
 Returns a copy of this variable. More...
 
void setName (const std::string &newName)
 Sets the variable's name to newName. More...
 
void setType (ShPtr< Type > newType)
 Sets the variable's type to newType. More...
 
void setAddress (Address a)
 
void markAsInternal ()
 Sets the variable as internal. More...
 
void markAsExternal ()
 Sets the variable as external. More...
 
Visitor Interface
virtual void accept (Visitor *v) override
 Visitor pattern implementation. 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...
 
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 ShPtr< Variablecreate (const std::string &name, ShPtr< Type > type, Address a=Address::Undefined)
 Creates a new variable. More...
 
- Static Public Member Functions inherited from retdec::llvmir2hll::Expression
static void replaceExpression (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr)
 Replaces oldExpr with newExpr. More...
 

Private Member Functions

 Variable (const std::string &name, ShPtr< Type > type, Address a=Address::Undefined)
 Constructs a new variable. More...
 

Private Attributes

std::string initialName
 Initial name of the variable. More...
 
std::string name
 Name of the variable. More...
 
ShPtr< Typetype
 Type of the variable. More...
 
bool internal
 Is the variable internal? More...
 
Address address
 

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
 
- Protected Member Functions inherited from retdec::llvmir2hll::Expression
 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...
 

Detailed Description

A representation of a variable.

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

Constructor & Destructor Documentation

◆ Variable()

retdec::llvmir2hll::Variable::Variable ( const std::string &  name,
ShPtr< Type type,
Address  a = Address::Undefined 
)
private

Constructs a new variable.

See create() for more information.

Member Function Documentation

◆ accept()

void retdec::llvmir2hll::Variable::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.

◆ clone()

ShPtr< Value > retdec::llvmir2hll::Variable::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.

◆ copy()

ShPtr< Variable > retdec::llvmir2hll::Variable::copy ( ) const

Returns a copy of this variable.

Since clone() does not clone variables (see the description of Value::clone()), this function may be used instead to create a copy of the variable.

◆ create()

ShPtr< Variable > retdec::llvmir2hll::Variable::create ( const std::string &  name,
ShPtr< Type type,
Address  a = Address::Undefined 
)
static

Creates a new variable.

Parameters
[in]nameName of the variable.
[in]typeType of the variable.
[in]aAddress.

By default, the created variable is internal. See isInternal() for more details.

Preconditions
  • type is non-null

◆ getAddress()

Address retdec::llvmir2hll::Variable::getAddress ( ) const

◆ getInitialName()

const std::string & retdec::llvmir2hll::Variable::getInitialName ( ) const

Returns the initial name of the variable.

This is the name that was assigned to the variable before any renaming.

◆ getName()

const std::string & retdec::llvmir2hll::Variable::getName ( ) const

Returns the name of the variable.

◆ getType()

ShPtr< Type > retdec::llvmir2hll::Variable::getType ( ) const
overridevirtual

Returns the type of the variable.

Implements retdec::llvmir2hll::Expression.

◆ hasName()

bool retdec::llvmir2hll::Variable::hasName ( ) const

Returns true if the variable has name, false otherwise.

◆ isEqualTo()

bool retdec::llvmir2hll::Variable::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.

◆ isExternal()

bool retdec::llvmir2hll::Variable::isExternal ( ) const

Returns true if the variable is external, false otherwise.

See the description of isInternal() for more details.

◆ isInternal()

bool retdec::llvmir2hll::Variable::isInternal ( ) const

Returns true if the variable is internal, false otherwise.

An internal variable is a variable for which we have complete information, i.e. we know all its uses and it cannot be modified on other places. If a variable is not internal, it is an external variable.

Currently, we use this flag for the following purposes:

  • Internal variables correspond to variables that either have 'internal linkage' in LLVM IR or are ordinary local variables.
  • External variables correspond to variables that either have 'external linkage' or are used in a volatile load/store operation.

By default, variables are created as internal variables. To make them external, call markAsExternal().

◆ markAsExternal()

void retdec::llvmir2hll::Variable::markAsExternal ( )

Sets the variable as external.

See the description of isExternal() for more information about the meaning of external variables.

◆ markAsInternal()

void retdec::llvmir2hll::Variable::markAsInternal ( )

Sets the variable as internal.

See the description of isInternal() for more information about the meaning of internal variables.

◆ replace()

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

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

Implements retdec::llvmir2hll::Expression.

◆ setAddress()

void retdec::llvmir2hll::Variable::setAddress ( Address  a)

◆ setName()

void retdec::llvmir2hll::Variable::setName ( const std::string &  newName)

Sets the variable's name to newName.

◆ setType()

void retdec::llvmir2hll::Variable::setType ( ShPtr< Type newType)

Sets the variable's type to newType.

Preconditions
  • newType is non-null

Member Data Documentation

◆ address

Address retdec::llvmir2hll::Variable::address
private

Some variables may have addresses:

  • Local variables created from temporary LLVM variables: LLVM insn addr.
  • Global variables: address in global data sections.

◆ initialName

std::string retdec::llvmir2hll::Variable::initialName
private

Initial name of the variable.

◆ internal

bool retdec::llvmir2hll::Variable::internal
private

Is the variable internal?

◆ name

std::string retdec::llvmir2hll::Variable::name
private

Name of the variable.

◆ type

ShPtr<Type> retdec::llvmir2hll::Variable::type
private

Type of the variable.


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