ROSE 0.11.145.147
|
Function declaration.
A function declaration consists of a return type, a list of argument types, and a calling convention. The declaration can be built directly from those pieces, or parsed from a C-like function declaration.
Although the specification language for this API is C-like, it does not necessarily follow C semantics. For instance, if you're describing a C function that takes a 16-bit unsigned short
argument, and this function is intended to describe the situation on a machine where C int
is 32 bits, then the declaration string for the constructor should give the type as u32
because the C language specifies that unsigned short
is promoted to unsigned int
in the function call.
Definition at line 30 of file Declaration.h.
#include <Rose/BinaryAnalysis/CallingConvention/Declaration.h>
Public Types | |
using | Ptr = DeclarationPtr |
Shared-ownership pointer. | |
Public Member Functions | |
const std::string & | toString () const |
Source code from which declaration was parsed. | |
DefinitionPtr | callingConvention () const |
Property: Calling convention. | |
SgAsmType * | returnType () const |
Property: Return type. | |
size_t | nArguments () const |
Property: Number of arguments. | |
SgAsmType * | argumentType (size_t index) const |
Property: Argument type. | |
const std::string & | argumentName (size_t index) const |
Property: Optional argument name. | |
const std::vector< std::pair< SgAsmType *, std::string > > & | arguments () const |
Property: The type and name for each argument. | |
Sawyer::Result< std::vector< ConcreteLocation >, std::string > | returnLocation () const |
Return concrete location for the function return value, if any, or an error string. | |
const std::string & | name () const |
Property: Name. | |
void | name (const std::string &) |
Property: Name. | |
const std::string & | comment () const |
Property: Comment. | |
void | comment (const std::string &) |
Property: Comment. | |
Sawyer::Result< std::vector< ConcreteLocation >, std::string > | argumentLocation (size_t index) const |
Return the concrete location(s) for a function argument, or an error string. | |
Sawyer::Result< std::vector< ConcreteLocation >, std::string > | argumentLocation (const std::string &argName) const |
Return the concrete location(s) for a function argument, or an error string. | |
Public Member Functions inherited from Sawyer::SharedObject | |
SharedObject () | |
Default constructor. | |
SharedObject (const SharedObject &) | |
Copy constructor. | |
virtual | ~SharedObject () |
Virtual destructor. | |
SharedObject & | operator= (const SharedObject &) |
Assignment. | |
Static Public Member Functions | |
static Ptr | instance (const DefinitionPtr &, const std::string &) |
Create a function declaration by parsing a C-like declaration. | |
Protected Member Functions | |
Declaration (const DefinitionPtr &) | |
Shared-ownership pointer.
Definition at line 33 of file Declaration.h.
|
static |
Create a function declaration by parsing a C-like declaration.
The string is of the form "RETURN_TYPE(ARG_TYPE_1, ...)".
The following types are recognized:
uN
indicates an unsigned integral type whose width is N
bits, where N
must be 8, 16, 32, or 64. iN
indicates a signed integral type whose width is N
bits, where N
must be 8, 16, 32, or 64. fN
indicates a floating-point type whose width is N
bits, where N
must be 32 or 64. T*
indicates a pointer to type T
. void
as a return type indicates that the function does not return a value. The type void*
can be used as an argument type to indicate that the argument is a pointer to something that is unknown. The pointer width is equal to the default word width defined in the calling convention.An argument type may be followed by an argument name, in which case the name must be unique for this declaration. The return type may be followed by a function name.
This intentionally small list of types might be extended in the future.
Examples:
const std::string & Rose::BinaryAnalysis::CallingConvention::Declaration::name | ( | ) | const |
Property: Name.
Optional name for this declaration.
void Rose::BinaryAnalysis::CallingConvention::Declaration::name | ( | const std::string & | ) |
Property: Name.
Optional name for this declaration.
const std::string & Rose::BinaryAnalysis::CallingConvention::Declaration::comment | ( | ) | const |
Property: Comment.
Optional comment for this declaration.
void Rose::BinaryAnalysis::CallingConvention::Declaration::comment | ( | const std::string & | ) |
Property: Comment.
Optional comment for this declaration.
DefinitionPtr Rose::BinaryAnalysis::CallingConvention::Declaration::callingConvention | ( | ) | const |
Property: Calling convention.
The calling convention is never null.
SgAsmType * Rose::BinaryAnalysis::CallingConvention::Declaration::returnType | ( | ) | const |
Property: Return type.
The return type is never null. If the function doesn't return a value then the return type is an instance of SgAsmVoidType. The return type is read-only, set by the constructor.
size_t Rose::BinaryAnalysis::CallingConvention::Declaration::nArguments | ( | ) | const |
Property: Number of arguments.
The number of arguments is read-only, set by the constructor.
SgAsmType * Rose::BinaryAnalysis::CallingConvention::Declaration::argumentType | ( | size_t | index | ) | const |
Property: Argument type.
Returns the type for the specified argument. The type is never null, nor can it be an instance of SgAsmVoidType. The zero-origin index must be valid for the number of arguments (see nArguments). This property is read-only, set by the constructor.
const std::string & Rose::BinaryAnalysis::CallingConvention::Declaration::argumentName | ( | size_t | index | ) | const |
Property: Optional argument name.
Returns an optional name for the argument. If an argument has a name, then it is guaranteed to be unique among all the argument names in this declaration. The zero-origin index must be valid for the number of arguments (see nArguments). This property is read-only, set by the constructor.
Sawyer::Result< std::vector< ConcreteLocation >, std::string > Rose::BinaryAnalysis::CallingConvention::Declaration::argumentLocation | ( | size_t | index | ) | const |
Return the concrete location(s) for a function argument, or an error string.
Locations that are relative to the stack pointer assume that instruction pointer is at the first instruction of the called function and the instruction has not yet been executed.
A successful return value always has at least one concrete location, and most arguments are allocated at only one location. In a few rare cases, an argument might have more than one location, such as when a 64-bit integer is split across two 32-bit registers on a 32-bit system.
Sawyer::Result< std::vector< ConcreteLocation >, std::string > Rose::BinaryAnalysis::CallingConvention::Declaration::argumentLocation | ( | const std::string & | argName | ) | const |
Return the concrete location(s) for a function argument, or an error string.
Locations that are relative to the stack pointer assume that instruction pointer is at the first instruction of the called function and the instruction has not yet been executed.
A successful return value always has at least one concrete location, and most arguments are allocated at only one location. In a few rare cases, an argument might have more than one location, such as when a 64-bit integer is split across two 32-bit registers on a 32-bit system.
Sawyer::Result< std::vector< ConcreteLocation >, std::string > Rose::BinaryAnalysis::CallingConvention::Declaration::returnLocation | ( | ) | const |
Return concrete location for the function return value, if any, or an error string.
Locations that are relative to the stack pointer assume that instruction pointer is at the first instruction of the called function and the instruction has not yet been executed.
If the function returns void
then a successful result contains no locations, otherwise it contains at least one location. In a few rare cases, an return value might have more than one location, such as when a 64-bit integer is split across two 32-bit registers on a 32-bit system.
If the return value cannot be located, then an error string is returned.