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

A definition of a global variable. More...

#include <global_var_def.h>

Inheritance diagram for retdec::llvmir2hll::GlobalVarDef:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::GlobalVarDef:
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...
 
void replace (ShPtr< Expression > oldExpr, ShPtr< Expression > newExpr)
 
ShPtr< VariablegetVar () const
 Return the variable. More...
 
ShPtr< ExpressiongetInitializer () const
 Returns the variable initializer. More...
 
bool hasInitializer () const
 Returns true if the global variable has an initializer, false otherwise. More...
 
bool definesExternalVar () const
 Checks if it defines an external global variable. More...
 
Address getAddress () const
 
void setVar (ShPtr< Variable > newVar)
 Sets a new variable. More...
 
void setInitializer (ShPtr< Expression > newInit)
 Sets a new initializer. More...
 
void removeInitializer ()
 Removes the initializer. More...
 
Observer Interface
virtual void update (ShPtr< Value > subject, ShPtr< Value > arg=nullptr) override
 Updates the definition 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::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< GlobalVarDefcreate (ShPtr< Variable > var, ShPtr< Expression > init=nullptr)
 Creates a new definition of a global variable. More...
 

Private Member Functions

 GlobalVarDef (ShPtr< Variable > var, ShPtr< Expression > init=nullptr)
 Constructs a new definition of a global variable. More...
 

Private Attributes

ShPtr< Variablevar
 Global variable. More...
 
ShPtr< Expressioninit
 Initializer of the variable. May be empty. 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
 
- 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 definition of a global 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

◆ GlobalVarDef()

retdec::llvmir2hll::GlobalVarDef::GlobalVarDef ( ShPtr< Variable var,
ShPtr< Expression init = nullptr 
)
explicitprivate

Constructs a new definition of a global variable.

See create() for more information.

Member Function Documentation

◆ accept()

void retdec::llvmir2hll::GlobalVarDef::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::GlobalVarDef::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< GlobalVarDef > retdec::llvmir2hll::GlobalVarDef::create ( ShPtr< Variable var,
ShPtr< Expression init = nullptr 
)
static

Creates a new definition of a global variable.

Parameters
[in]varGlobal variable to be defined.
[in]initInitializer of var.
Preconditions
  • var is non-null

◆ definesExternalVar()

bool retdec::llvmir2hll::GlobalVarDef::definesExternalVar ( ) const

Checks if it defines an external global variable.

Returns
true if it defines an external global variable, false otherwise.

◆ getAddress()

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

◆ getInitializer()

ShPtr< Expression > retdec::llvmir2hll::GlobalVarDef::getInitializer ( ) const

Returns the variable initializer.

If there is no initializer, it returns the null pointer.

◆ getVar()

ShPtr< Variable > retdec::llvmir2hll::GlobalVarDef::getVar ( ) const

Return the variable.

◆ hasInitializer()

bool retdec::llvmir2hll::GlobalVarDef::hasInitializer ( ) const

Returns true if the global variable has an initializer, false otherwise.

◆ isEqualTo()

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

◆ removeInitializer()

void retdec::llvmir2hll::GlobalVarDef::removeInitializer ( )

Removes the initializer.

◆ replace()

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

◆ setInitializer()

void retdec::llvmir2hll::GlobalVarDef::setInitializer ( ShPtr< Expression newInit)

Sets a new initializer.

◆ setVar()

void retdec::llvmir2hll::GlobalVarDef::setVar ( ShPtr< Variable newVar)

Sets a new variable.

Preconditions
  • newVar is non-null

◆ update()

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

Updates the definition according to the changes of subject.

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

It replaces subject with

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

This function does nothing when:

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

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

Member Data Documentation

◆ init

ShPtr<Expression> retdec::llvmir2hll::GlobalVarDef::init
private

Initializer of the variable. May be empty.

◆ var

ShPtr<Variable> retdec::llvmir2hll::GlobalVarDef::var
private

Global variable.


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