Skip to content

SageInterface::wrapFunction

moves the body of a function f to a new function f`; f's body is replaced with code that forwards the call to f`.

Synopsis

Declared in <SageIII/sageInterface/sageInterface.h>

std::pair<SgStatement*, SgInitializedName*>
wrapFunction(
    SgFunctionDeclaration& definingDeclaration,
    SgName newName);

Description

f's new body becomes { f`(...); } and { int res = f`(...); return res; } for functions returning void and a value, respectively. two function declarations are inserted in f's enclosing scope

result_type f`(...);                       <--- (1)
result_type f (...) { forward call to f` }
result_type f`(...) { original code }      <--- (2)

Calls to f are not updated, thus in the transformed code all calls will continue calling f (this is also true for recursive function calls from within the body of f`). After the function has created the wrapper, definingDeclaration becomes the wrapper function The definition of f` is the next entry in the statement list; the forward declaration of f` is the previous entry in the statement list.

Return Value

a pair indicating the statement containing the call of f` and an initialized name refering to the temporary variable holding the result of f`. In case f returns void the initialized name is NULL.

Parameters

Name

Description

definingDeclaration

the defining function declaration of f

newName

the name of function f`

Preconditions

  • definingDeclaration must be a defining declaration of a free standing function. typeid(SgFunctionDeclaration) == typeid(definingDeclaration) i.e., this function is NOT implemented for class member functions, template functions, procedures, etc.

Created with MrDocs