retdec
|
A representation of a function. More...
#include <function.h>
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... | |
ShPtr< Type > | getRetType () const |
Returns function type. More... | |
const std::string & | getInitialName () const |
Returns the initial name of the function. More... | |
const std::string & | getName () const |
Returns function name. More... | |
const VarVector & | getParams () const |
Returns function parameters. More... | |
ShPtr< Variable > | getParam (std::size_t n) const |
Returns the n-th parameter. More... | |
std::size_t | getParamPos (ShPtr< Variable > param) const |
Returns the position of the given parameter. More... | |
std::size_t | getNumOfParams () const |
Returns the number of parameters. More... | |
VarSet | getLocalVars (bool includeParams=false) const |
Returns local variables of the function. More... | |
std::size_t | getNumOfLocalVars (bool includeParams=false) const |
Returns the number of local variables. More... | |
bool | hasLocalVar (ShPtr< Variable > var, bool includeParams=false) const |
Returns true if var is a local variable of the function, false otherwise. More... | |
ShPtr< Statement > | getBody () const |
Returns function body. More... | |
ShPtr< Variable > | getAsVar () const |
Returns a variable corresponding the function. More... | |
ShPtr< Type > | getType () const |
Returns the type of the function. More... | |
ShPtr< Module > | getModule () const |
AddressRange | getAddressRange () const |
Address | getStartAddress () const |
Address | getEndAddress () const |
bool | isVarArg () const |
Returns true if the function takes a variable number of arguments, false otherwise. More... | |
bool | isDeclaration () const |
Returns true if the function is just a declaration, false otherwise. More... | |
bool | isDefinition () const |
Returns true if the function is a definition, false otherwise. More... | |
bool | hasParam (ShPtr< Variable > var) const |
Returns true if var is a parameter of the function, false otherwise. More... | |
bool | hasParam (std::size_t n) const |
Returns true if the function has an n-th parameter, false otherwise. More... | |
void | setRetType (ShPtr< Type > newRetType) |
Sets a new return type;. More... | |
void | setName (const std::string &newName) |
Sets a new name. More... | |
void | setParams (VarVector newParams) |
Sets a new parameter list. More... | |
void | setLocalVars (VarSet newLocalVars) |
Sets a new set of local variables. More... | |
void | addParam (ShPtr< Variable > var) |
Adds a new parameter to the function. More... | |
void | addLocalVar (ShPtr< Variable > var) |
Adds a new local variable to the function. More... | |
void | replaceParam (ShPtr< Variable > oldParam, ShPtr< Variable > newParam) |
Replaces oldParam with newParam. More... | |
void | replaceLocalVar (ShPtr< Variable > oldVar, ShPtr< Variable > newVar) |
Replaces oldVar with newVar. More... | |
void | removeLocalVar (ShPtr< Variable > var) |
Removes the given variable from the set of local variables. More... | |
void | removeParam (ShPtr< Variable > param) |
Removes the given parameter. More... | |
void | setBody (ShPtr< Statement > newBody) |
Sets a new body. More... | |
void | setVarArg (bool isVarArg=true) |
Sets the function's status concerning the number of arguments it takes. More... | |
void | convertToDeclaration () |
Makes the function to be a declaration. 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... | |
![]() | |
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< Function > | create (ShPtr< Module > module, ShPtr< Type > retType, std::string name, VarVector params, VarSet localVars=VarSet(), ShPtr< Statement > body=nullptr, bool isVarArg=false) |
Constructs a new function. More... | |
Private Member Functions | |
Function (ShPtr< Module > module, ShPtr< Type >, std::string name, VarVector params, VarSet localVars=VarSet(), ShPtr< Statement > body=nullptr, bool isVarArg=false) | |
Constructs a new function. More... | |
void | updateUnderlyingVarType () |
Updates the type of the underlying variable. More... | |
void | includeParamsIntoLocalVars () |
Includes all parameters into the set of local variables. More... | |
Private Attributes | |
WkPtr< Module > | module |
The module to which the function belongs. More... | |
ShPtr< Type > | retType |
Return type. More... | |
VarVector | params |
Parameters. More... | |
VarSet | localVars |
Local variables, including parameters. More... | |
ShPtr< Statement > | body |
Function body. More... | |
ShPtr< Variable > | funcVar |
bool | varArg |
Additional Inherited Members | |
![]() | |
using | ConcreteObserver = Observer< Value, Value > |
A concrete observer. More... | |
using | ObserverPtr = WkPtr< ConcreteObserver > |
A pointer to an observer. More... | |
![]() | |
using | ObserverContainer = std::vector< ObserverPtr > |
A container to store observers. More... | |
using | observer_iterator = typename ObserverContainer::const_iterator |
![]() | |
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... | |
A representation of a function.
Use either create() or FunctionBuilder to create instances. Instances of this class have reference object semantics. This class is not meant to be subclassed.
|
private |
Constructs a new function.
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.
Adds a new local variable to the function.
If var is already a local variable in the function, this function does nothing.
To add a local variable including a VarDefStmt, use addLocalVar() from Support/Utils.
Adds a new parameter to the function.
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.
void retdec::llvmir2hll::Function::convertToDeclaration | ( | ) |
Makes the function to be a declaration.
If the function is already a declaration, nothing happens. Once you make a function a declaration, the only way of making it a definition again is to set its body to a non-null pointer by setBody().
When the function is converted from a definition into a declaration, observers are notified.
|
static |
Constructs a new function.
[in] | module | Module this function belongs to. |
[in] | retType | Function return type. |
[in] | name | Function name. |
[in] | params | Parameter list. |
[in] | localVars | Local variables (without parameters). |
[in] | body | Function body. |
[in] | isVarArg | true if the function takes a variable number of arguments, false otherwise. |
If body is the null pointer, then the function is a declaration. Otherwise, it is a definition.
To build functions in a simpler way, use FunctionBuilder.
AddressRange retdec::llvmir2hll::Function::getAddressRange | ( | ) | const |
Returns a variable corresponding the function.
This variable may be used when calling this function.
Address retdec::llvmir2hll::Function::getEndAddress | ( | ) | const |
const std::string & retdec::llvmir2hll::Function::getInitialName | ( | ) | const |
Returns the initial name of the function.
This is the name that was assigned to the function before any renaming.
VarSet retdec::llvmir2hll::Function::getLocalVars | ( | bool | includeParams = false | ) | const |
Returns local variables of the function.
[in] | includeParams | If true , function parameters will be included. |
const std::string & retdec::llvmir2hll::Function::getName | ( | ) | const |
Returns function name.
std::size_t retdec::llvmir2hll::Function::getNumOfLocalVars | ( | bool | includeParams = false | ) | const |
Returns the number of local variables.
[in] | includeParams | If true , function parameters will be included. |
std::size_t retdec::llvmir2hll::Function::getNumOfParams | ( | ) | const |
Returns the number of parameters.
Returns the n-th parameter.
The parameters are numbered in the following way:
0 < n <= NUM_OF_PARAMS
, where NUM_OF_PARAMS
is the number of parameters that the function has Returns the position of the given parameter.
The parameter numbering is described in getParam().
const VarVector & retdec::llvmir2hll::Function::getParams | ( | ) | const |
Returns function parameters.
Address retdec::llvmir2hll::Function::getStartAddress | ( | ) | const |
Returns the type of the function.
Currently, it returns the return type of the function, not the complete type of the function. This simplifies the fixing of signed/unsigned types.
bool retdec::llvmir2hll::Function::hasLocalVar | ( | ShPtr< Variable > | var, |
bool | includeParams = false |
||
) | const |
Returns true
if var is a local variable of the function, false
otherwise.
[in] | var | Variable to be checked. |
[in] | includeParams | If true , function parameters will be also considered as local variables. |
Returns true
if var is a parameter of the function, false
otherwise.
bool retdec::llvmir2hll::Function::hasParam | ( | std::size_t | n | ) | const |
Returns true
if the function has an n-th parameter, false
otherwise.
The parameters are numbered in the following way:
|
private |
Includes all parameters into the set of local variables.
Parameters are local variables, too.
bool retdec::llvmir2hll::Function::isDeclaration | ( | ) | const |
Returns true
if the function is just a declaration, false
otherwise.
bool retdec::llvmir2hll::Function::isDefinition | ( | ) | const |
Returns true
if the function is a definition, false
otherwise.
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.
bool retdec::llvmir2hll::Function::isVarArg | ( | ) | const |
Returns true
if the function takes a variable number of arguments, false
otherwise.
Removes the given variable from the set of local variables.
This function does nothing if var is either a parameter of the function or the function does not have any local variable var.
Removes the given parameter.
If param is not a parameter of this function, this function does nothing.
void retdec::llvmir2hll::Function::replaceLocalVar | ( | ShPtr< Variable > | oldVar, |
ShPtr< Variable > | newVar | ||
) |
Replaces oldVar with newVar.
If oldVar does not correspond to any local variable, this function does nothing.
void retdec::llvmir2hll::Function::replaceParam | ( | ShPtr< Variable > | oldParam, |
ShPtr< Variable > | newParam | ||
) |
Replaces oldParam with newParam.
If oldParam does not correspond to any parameter, this function does nothing.
Sets a new body.
If newBody is the null pointer, this function becomes a declaration. Conversely, if newBody is non-null, this function becomes a definition.
void retdec::llvmir2hll::Function::setLocalVars | ( | VarSet | newLocalVars | ) |
Sets a new set of local variables.
void retdec::llvmir2hll::Function::setName | ( | const std::string & | newName | ) |
Sets a new name.
void retdec::llvmir2hll::Function::setParams | ( | VarVector | newParams | ) |
Sets a new parameter list.
void retdec::llvmir2hll::Function::setVarArg | ( | bool | isVarArg = true | ) |
Sets the function's status concerning the number of arguments it takes.
If isVarArg is true
, it marks the function as with a variable number of arguments. Otherwise, it marks it as a function with a fixed number of arguments.
|
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 one of the parameters of this function, this function replaces it with arg. If subject is the null pointer and corresponds to a part of the function, this part of the function is removed.
This function does nothing when:
Reimplemented from retdec::llvmir2hll::Observer< Value >.
|
private |
Updates the type of the underlying variable.
This function has to be called whenever the signature of the function is changed (e.g. its return type or parameters).
Variable corresponding to the function. This variable may be used when calling this function.
|
private |
Local variables, including parameters.
The module to which the function belongs.
|
private |
Parameters.
|
private |