ROSE
0.11.96.11
|
Functions that are useful when operating on the AST.
The Sage III IR design attempts to be minimalist. Thus additional functionality is intended to be presented using separate higher level interfaces which work with the IR. This namespace collects functions that operate on the IR and support numerous types of operations that are common to general analysis and transformation of the AST.
Classes | |
struct | const_int_expr_t |
class | DeclarationSets |
struct | DeferredTransformation |
class | OutputLocalSymbolTables |
class | StatementGenerator |
Interface for creating a statement whose computation writes its answer into a given variable. More... | |
struct | Transformation_Record |
class | UniqueNameAttribute |
A persistent attribute to represent a unique name for an expression. More... | |
Functions | |
DeclarationSets * | buildDeclarationSets (SgNode *) |
void | addMessageStatement (SgStatement *stmt, std::string message) |
Function to add "C" style comment to statement. | |
Variables | |
ROSE_DLL_API Transformation_Record | trans_records |
ROSE_DLL_API int | gensym_counter |
An internal counter for generating unique SgName. | |
Stringify | |
Generate a useful string (name) to describe a SgNode | |
std::map< std::string, int > | local_name_collision_map |
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function. | |
std::map< std::string, SgNode * > | local_name_to_node_map |
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function. | |
std::map< SgNode *, std::string > | local_node_to_name_map |
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function. | |
std::string | get_name (const SgNode *node) |
Generate a useful name to describe the SgNode. | |
std::string | get_name (const SgStatement *stmt) |
Generate a useful name to describe the declaration. | |
std::string | get_name (const SgExpression *expr) |
Generate a useful name to describe the expression. | |
std::string | get_name (const SgDeclarationStatement *declaration) |
Generate a useful name to describe the declaration. | |
std::string | get_name (const SgScopeStatement *scope) |
Generate a useful name to describe the scope. | |
std::string | get_name (const SgSymbol *symbol) |
Generate a useful name to describe the SgSymbol. | |
std::string | get_name (const SgType *type) |
Generate a useful name to describe the SgType. | |
std::string | get_name (const SgSupport *node) |
Generate a useful name to describe the SgSupport IR node. | |
std::string | get_name (const SgLocatedNodeSupport *node) |
Generate a useful name to describe the SgLocatedNodeSupport IR node. | |
std::string | get_name (const SgC_PreprocessorDirectiveStatement *directive) |
Generate a useful name to describe the SgC_PreprocessorDirectiveStatement IR node. | |
std::string | get_name (const SgToken *token) |
Generate a useful name to describe the SgToken IR node. | |
SgType * | getDeclaredType (const SgDeclarationStatement *declaration) |
Returns the type introduced by a declaration. | |
std::string | generateUniqueNameForUseAsIdentifier (SgDeclarationStatement *declaration) |
Generate a useful name to support construction of identifiers from declarations. More... | |
std::string | generateUniqueNameForUseAsIdentifier_support (SgDeclarationStatement *declaration) |
Global map of name collisions to support generateUniqueNameForUseAsIdentifier() function. | |
void | computeUniqueNameForUseAsIdentifier (SgNode *astNode) |
Traversal to set the global map of names to node and node to names.collisions to support generateUniqueNameForUseAsIdentifier() function. | |
void | reset_name_collision_map () |
Reset map variables used to support generateUniqueNameForUseAsIdentifier() function. | |
ROSE_DLL_API int SageInterface::set_name | ( | SgInitializedName * | initializedNameNode, |
SgName | new_name | ||
) |
set_name of symbol in symbol table.
This function extracts the symbol from the relavant symbol table, changes the name (at the declaration) and reinserts it into the symbol table.
ROSE_DLL_API void SageInterface::outputLocalSymbolTables | ( | SgNode * | node | ) |
Output the local symbol tables.
\implementation Each symbol table is output with the file infor where it is located in the source code.
void SageInterface::rebuildSymbolTable | ( | SgScopeStatement * | scope | ) |
Regenerate the symbol table.
\implementation current symbol table must be NULL pointer before calling this function (for safety, but is this a good idea?)
std::string SageInterface::generateUniqueNameForUseAsIdentifier | ( | SgDeclarationStatement * | declaration | ) |
Generate a useful name to support construction of identifiers from declarations.
This function permits names to be generated that will be unique across translation units (a specific requirement different from the context of the get_name() functions above).
std::string SageInterface::generateUniqueName | ( | const SgNode * | node, |
bool | ignoreDifferenceBetweenDefiningAndNondefiningDeclarations | ||
) |
Generate unique name from C and C++ constructs. The name may contain space.
This is support for the AST merge, but is generally useful as a more general mechanism than name mangling which is more closely ties to the generation of names to support link-time function name resolution. This is more general than common name mangling in that it resolves more relevant differences between C and C++ declarations. (e.g. the type within the declaration: "struct { int:8; } foo;").
\implementation current work does not support expressions.
std::string SageInterface::generateUniqueVariableName | ( | SgScopeStatement * | scope, |
std::string | baseName = "temp" |
||
) |
Generate a name like temp# that is unique in the current scope and any parent and children scopes.
# is a unique integer counter.
baseName | the word to be included in the variable names. |
void SageInterface::clearMangledNameCache | ( | SgGlobal * | globalScope | ) |
Support for faster mangled name generation (caching avoids recomputation).
ROSE_DLL_API std::vector< SgNode * > SageInterface::astIntersection | ( | SgNode * | original, |
SgNode * | copy, | ||
SgCopyHelp * | help = NULL |
||
) |
Compute the intersection set for two ASTs.
This is part of a test done by the copy function to compute those IR nodes in the copy that still reference the original AST.
bool SageInterface::isAssignmentStatement | ( | SgNode * | _s, |
SgExpression ** | lhs = NULL , |
||
SgExpression ** | rhs = NULL , |
||
bool * | readlhs = NULL |
||
) |
Check if a SgNode _s is an assignment statement (any of =,+=,-=,&=,/=, ^=, etc)
Return the left hand, right hand expressions and if the left hand variable is also being read
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 649 of file sageInterface.h.
References Rose::is_C_language.
Referenced by is_C_language().
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 650 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 651 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 652 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 653 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 654 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 655 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 656 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 657 of file sageInterface.h.
|
inline |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
Definition at line 658 of file sageInterface.h.
ROSE_DLL_API bool SageInterface::is_mixed_C_and_Cxx_language | ( | ) |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
ROSE_DLL_API bool SageInterface::is_mixed_Fortran_and_C_language | ( | ) |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
ROSE_DLL_API bool SageInterface::is_mixed_Fortran_and_Cxx_language | ( | ) |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
ROSE_DLL_API bool SageInterface::is_mixed_Fortran_and_C_and_Cxx_language | ( | ) |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
ROSE_DLL_API bool SageInterface::is_language_case_insensitive | ( | ) |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
ROSE_DLL_API bool SageInterface::language_may_contain_nondeclarations_in_scope | ( | ) |
Brief These traverse the memory pool of SgFile IR nodes and determine what languages are in use!
void SageInterface::resetScopeNumbers | ( | SgFunctionDefinition * | functionDeclaration | ) |
Assigns unique numbers to each SgScopeStatement of a function.
This is used to provide unique names for variables and types defined is different nested scopes of a function (used in mangled name generation).
void SageInterface::clearScopeNumbers | ( | SgFunctionDefinition * | functionDefinition | ) |
Clears the cache of scope,integer pairs for the input function.
This is used to clear the cache of computed unique labels for scopes in a function. This function should be called after any transformation on a function that might effect the allocation of scopes and cause the existing unique numbers to be incorrect. This is part of support to provide unique names for variables and types defined is different nested scopes of a function (used in mangled name generation).
bool SageInterface::isPrototypeInScope | ( | SgScopeStatement * | scope, |
SgFunctionDeclaration * | functionDeclaration, | ||
SgDeclarationStatement * | startingAtDeclaration | ||
) |
Assigns unique numbers to each SgScopeStatement of a function.
This is used to provide unique names for variables and types defined is different nested scopes of a function (used in mangled name generation).
void SageInterface::guardNode | ( | SgLocatedNode * | target, |
std::string | guard | ||
) |
Add preproccessor guard around a given node.
It surrounds the node with "#if guard" and "#endif"
ROSE_DLL_API bool SageInterface::insideSystemHeader | ( | SgLocatedNode * | node | ) |
Set source position info(Sg_File_Info) as transformation generated for all SgNodes in memory pool.
Check if a node is from a system header file
ROSE_DLL_API bool SageInterface::isStrictIntegerType | ( | SgType * | t | ) |
Check if a type is an integral type, only allowing signed/unsigned short, int, long, long long. /! /! There is another similar function named SgType::isIntegerType(), which allows additional types char, wchar, and bool to be treated as integer types.
Check if a type is an integral type, only allowing signed/unsigned short, int, long, long long.
There is another similar function named SgType::isIntegerType(), which allows additional types char, wchar, and bool.
ROSE_DLL_API bool SageInterface::isPureVirtualClass | ( | SgType * | type, |
const ClassHierarchyWrapper & | classHierarchy | ||
) |
Check if a class type is a pure virtual class.
True means that there is at least one pure virtual function that has not been overridden. In the case of an incomplete class type (forward declaration), this function returns false.
ROSE_DLL_API bool SageInterface::isPointerToNonConstType | ( | SgType * | type | ) |
Is this a pointer to a non-const type? Note that this function will return true for const pointers pointing to non-const types.
For example, (int* const y) points to a modifiable int, so this function returns true. Meanwhile, it returns false for (int const * x) and (int const * const x) because these types point to a const int. Also, only the outer layer of nested pointers is unwrapped. So the function returns true for (const int ** y), but returns false for const (int * const * x)
ROSE_DLL_API bool SageInterface::isScalarType | ( | SgType * | t | ) |
Is this a scalar type?
We define the following SgType as scalar types: char, short, int, long , void, Wchar, Float, double, long long, string, bool, complex, imaginary
std::vector<SgExpression*> SageInterface::get_C_array_dimensions | ( | const SgArrayType & | arrtype | ) |
returns the array dimensions in an array as defined for arrtype
arrtype | the type of a C/C++ array |
std::vector<SgExpression*> SageInterface::get_C_array_dimensions | ( | const SgArrayType & | arrtype, |
const SgVarRefExp & | varref | ||
) |
returns the array dimensions in an array as defined for arrtype
arrtype | the type of a C/C++ array |
varref | a reference to an array variable (the variable of type arrtype) |
std::vector<SgExpression*> SageInterface::get_C_array_dimensions | ( | const SgArrayType & | arrtype, |
SgInitializedName & | initname | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ROSE_DLL_API bool SageInterface::hasUpcSharedType | ( | SgType * | t, |
SgModifierType ** | mod_type_out = NULL |
||
) |
Has a UPC shared type of any kinds (shared-to-shared, private-to-shared, shared-to-private, shared scalar/array)? An optional parameter, mod_type_out, stores the first SgModifierType with UPC access information.
Note: we classify private-to-shared as 'has shared' type for convenience here. It is indeed a private type in strict sense. AST graph for some examples:
ROSE_DLL_API bool SageInterface::isUpcSharedType | ( | SgType * | t, |
SgModifierType ** | mod_type_out = NULL |
||
) |
Check if a type is a UPC shared type, including shared array, shared pointers etc. Exclude private pointers to shared types. Optionally return the modifier type with the UPC shared property.
ROSE uses SgArrayType of SgModifierType to represent shared arrays, not SgModifierType points to SgArrayType. Also typedef may cause a chain of nodes before reach the actual SgModifierType with UPC shared property.
ROSE_DLL_API bool SageInterface::isEquivalentFunctionType | ( | const SgFunctionType * | lhs, |
const SgFunctionType * | rhs | ||
) |
Test if two types are equivalent SgFunctionType nodes.
This is necessary for template function types They may differ in one SgTemplateType pointer but identical otherwise.
ROSE_DLL_API void SageInterface::addStepToLoopBody | ( | SgScopeStatement * | loopStmt, |
SgStatement * | step | ||
) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
ROSE_DLL_API void SageInterface::moveForStatementIncrementIntoBody | ( | SgForStatement * | f | ) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
ROSE_DLL_API void SageInterface::convertForToWhile | ( | SgForStatement * | f | ) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
ROSE_DLL_API void SageInterface::convertAllForsToWhiles | ( | SgNode * | top | ) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
ROSE_DLL_API bool SageInterface::hasMultipleInitStatmentsOrExpressions | ( | SgForStatement * | for_loop | ) |
Check if a for loop uses C99 style initialization statement with multiple expressions like for (int i=0, j=0; ..) or for (i=0,j=0;...)
for (int i=0, j=0; ..) is stored as two variable declarations under SgForInitStatement's init_stmt member for (i=0,j=0;...) is stored as a single expression statement, with comma expression (i=0,j=0).
ROSE_DLL_API void SageInterface::setLoopBody | ( | SgScopeStatement * | loop, |
SgStatement * | body | ||
) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
ROSE_DLL_API bool SageInterface::isCanonicalForLoop | ( | SgNode * | loop, |
SgInitializedName ** | ivar = NULL , |
||
SgExpression ** | lb = NULL , |
||
SgExpression ** | ub = NULL , |
||
SgExpression ** | step = NULL , |
||
SgStatement ** | body = NULL , |
||
bool * | hasIncrementalIterationSpace = NULL , |
||
bool * | isInclusiveUpperBound = NULL |
||
) |
Check if a for-loop has a canonical form, return loop index, bounds, step, and body if requested.
A canonical form is defined as : one initialization statement, a test expression, and an increment expression , loop index variable should be of an integer type. IsInclusiveUpperBound is true when <= or >= is used for loop condition
ROSE_DLL_API bool SageInterface::forLoopNormalization | ( | SgForStatement * | loop, |
bool | foldConstant = true |
||
) |
Normalize a for loop, return true if successful.
Generated constants will be fold by default.
Translations are : For the init statement: for (int i=0;... ) becomes int i; for (i=0;..) For test expression: i<x is normalized to i<= (x-1) and i>x is normalized to i>= (x+1) For increment expression: i++ is normalized to i+=1 and i– is normalized to i+=-1 i-=s is normalized to i+= -s
ROSE_DLL_API bool SageInterface::normalizeForLoopIncrement | ( | SgForStatement * | loop | ) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
SgExprListExp* SageInterface::loopCollapsing | ( | SgForStatement * | target_loop, |
size_t | collapsing_factor | ||
) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
bool SageInterface::getForLoopInformations | ( | SgForStatement * | for_loop, |
SgVariableSymbol *& | iterator, | ||
SgExpression *& | lower_bound, | ||
SgExpression *& | upper_bound, | ||
SgExpression *& | stride | ||
) |
Add a step statement to the end of a loop body Add a new label to the end of the loop, with the step statement after it; then change all continue statements in the old loop body into jumps to the label.
For example: while (a < 5) {if (a < -3) continue;} (adding "a++" to end) becomes while (a < 5) {if (a < -3) goto label; label: a++;}
std::vector< SgFile * > SageInterface::generateFileList | ( | ) |
ROSE_DLL_API SgProject* SageInterface::getProject | ( | ) |
Get the current SgProject IR Node.
The library should never have more than one project and it asserts such. If no project has been created yet then this function returns the null pointer.
std::vector<SgBreakStmt*> SageInterface::findBreakStmts | ( | SgStatement * | code, |
const std::string & | fortranLabel = "" |
||
) |
Find break statements inside a particular statement, stopping at nested loops or switches.
loops or switch statements defines their own contexts for break statements. The function will stop immediately if run on a loop or switch statement. If fortranLabel is non-empty, breaks (EXITs) to that label within nested loops are included in the returned list.
std::vector<SgContinueStmt*> SageInterface::findContinueStmts | ( | SgStatement * | code, |
const std::string & | fortranLabel = "" |
||
) |
Find all continue statements inside a particular statement, stopping at nested loops.
Nested loops define their own contexts for continue statements. The function will stop immediately if run on a loop statement. If fortranLabel is non-empty, continues (CYCLEs) to that label within nested loops are included in the returned list.
NodeType* SageInterface::getEnclosingNode | ( | const SgNode * | astNode, |
const bool | includingSelf = false |
||
) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
Definition at line 1437 of file sageInterface.h.
References SgNode::class_name(), SgDeclarationStatement::get_definingDeclaration(), SgNode::get_file_info(), SgDeclarationStatement::get_firstNondefiningDeclaration(), and SgNode::get_parent().
ROSE_DLL_API SgFunctionDefinition* SageInterface::getEnclosingFunctionDefinition | ( | SgNode * | astNode, |
const bool | includingSelf = false |
||
) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API bool SageInterface::isInSubTree | ( | SgExpression * | subtree, |
SgExpression * | exp | ||
) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API SgFunctionDeclaration* SageInterface::getFunctionDeclaration | ( | SgFunctionCallExp * | functionCallExp | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API bool SageInterface::isDataMemberReference | ( | SgVarRefExp * | varRefExp | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API bool SageInterface::isAddressTaken | ( | SgExpression * | refExp | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API bool SageInterface::isMemberFunctionMemberReference | ( | SgMemberFunctionRefExp * | memberFunctionRefExp | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API std::list<SgClassType*> SageInterface::getClassTypeChainForMemberReference | ( | SgExpression * | refExp | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API std::set<SgNode*> SageInterface::getFrontendSpecificNodes | ( | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API void SageInterface::outputSharedNodes | ( | SgNode * | node | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API void SageInterface::displayScope | ( | SgScopeStatement * | scope | ) |
Find a node by type using upward traversal.
Traverse backward through a specified node's ancestors, starting with the node's parent and progressing to more distant ancestors, to find the first node matching the specified or derived type. If includingSelf
is true then the starting node, astNode
, is returned if its type matches, otherwise the search starts at the parent of astNode
.
For the purposes of this function, the parent (P) of an SgDeclarationStatement node (N) is considered to be the first non-defining declaration of N if N has both a defining declaration and a first non-defining declaration and the defining declaration is different than the first non-defining declaration.
If no ancestor of the requisite type of subtypes is found then this function returns a null pointer.
If astNode
is the null pointer, then the return value is a null pointer. That is, if there is no node, then there cannot be an enclosing node of the specified type.
ROSE_DLL_API bool SageInterface::isSameFunction | ( | SgFunctionDeclaration * | func1, |
SgFunctionDeclaration * | func2 | ||
) |
Check if two function declarations refer to the same one. Two function declarations are the same when they are a) identical, b) same name in C c) same qualified named and mangled name in C++. A nondefining (prototype) declaration and a defining declaration of a same function are treated as the same.
There is a similar function bool compareFunctionDeclarations(SgFunctionDeclaration *f1, SgFunctionDeclaration *f2) from Classhierarchy.C
ROSE_DLL_API bool SageInterface::hasSimpleChildrenList | ( | SgScopeStatement * | scope | ) |
Check if a scope statement has a simple children statement list so insert additional statements under the scope is straightforward and unambiguous .
for example, SgBasicBlock has a simple statement list while IfStmt does not.
ROSE_DLL_API bool SageInterface::statementCanBeTransformed | ( | SgStatement * | stmt | ) |
If header file unparsing and token-based unparsing are used, then some statements in header files used with the same name and different include syntax can't be transformed.
This is currently because there is no way to generally test the resulting transformed code generated by ROSE.
std::pair<SgVariableDeclaration*, SgExpression* > SageInterface::createTempVariableForExpression | ( | SgExpression * | expression, |
SgScopeStatement * | scope, | ||
bool | initializeInDeclaration, | ||
SgAssignOp ** | reEvaluate = NULL |
||
) |
Given an expression, generates a temporary variable whose initializer optionally evaluates that expression.
Then, the var reference expression returned can be used instead of the original expression. The temporary variable created can be reassigned to the expression by the returned SgAssignOp; this can be used when the expression the variable represents needs to be evaluated. NOTE: This handles reference types correctly by using pointer types for the temporary.
expression | Expression which will be replaced by a variable |
scope | scope in which the temporary variable will be generated |
reEvaluate | an assignment op to reevaluate the expression. Leave NULL if not needed |
ROSE_DLL_API SgVariableSymbol* SageInterface::appendArg | ( | SgFunctionParameterList * | , |
SgInitializedName * | |||
) |
Append an argument to SgFunctionParameterList, transparently set parent,scope, and symbols for arguments when possible.
We recommend to build SgFunctionParameterList before building a function declaration However, it is still allowed to append new arguments for existing function declarations.
ROSE_DLL_API void SageInterface::replaceSubexpressionWithStatement | ( | SgExpression * | from, |
SageInterface::StatementGenerator * | to | ||
) |
Similar to replaceExpressionWithStatement, but with more restrictions.
Assumptions: from is not within the test of a loop or ifStmt, not currently traversing from or the statement it is in
ROSE_DLL_API int SageInterface::fixVariableReferences | ( | SgNode * | root, |
bool | cleanUnusedSymbol = true |
||
) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API void SageInterface::fixVariableDeclaration | ( | SgVariableDeclaration * | varDecl, |
SgScopeStatement * | scope | ||
) |
Patch up symbol, scope, and parent information when a SgVariableDeclaration's scope is known.
It is possible to build a variable declaration without knowing its scope information during bottom-up construction of AST, though top-down construction is recommended in general. In this case, we have to patch up symbol table, scope and parent information when the scope is known. This function is usually used internally within appendStatment(), insertStatement().
ROSE_DLL_API void SageInterface::reportModifiedStatements | ( | const std::string & | label, |
SgNode * | node | ||
) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API void SageInterface::translateToUseCppDeclarations | ( | SgNode * | n | ) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API void SageInterface::translateScopeToUseCppDeclarations | ( | SgScopeStatement * | scope | ) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API std::vector<SgC_PreprocessorDirectiveStatement*> SageInterface::translateStatementToUseCppDeclarations | ( | SgStatement * | statement, |
SgScopeStatement * | scope | ||
) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API void SageInterface::printOutComments | ( | SgLocatedNode * | locatedNode | ) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API bool SageInterface::skipTranslateToUseCppDeclaration | ( | PreprocessingInfo * | currentPreprocessingInfo | ) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API void SageInterface::outputFileIds | ( | SgNode * | node | ) |
Connect variable reference to the right variable symbols when feasible, return the number of references being fixed.
In AST translation, it is possible to build a variable reference before the variable is being declared. buildVarRefExp() will use fake initialized name and symbol as placeholders to get the work done. Users should call fixVariableReference() when AST is complete and all variable declarations are in place.
ROSE_DLL_API void SageInterface::updateDefiningNondefiningLinks | ( | SgFunctionDeclaration * | func, |
SgScopeStatement * | scope | ||
) |
Update defining and nondefining links due to a newly introduced function declaration. Should be used after inserting the function into a scope.
This function not only set the defining and nondefining links of the newly introduced function declaration inside a scope, but also update other same function declarations' links accordingly if there are any. Assumption: The function has already inserted/appended/prepended into the scope before calling this function.
ROSE_DLL_API void SageInterface::constantFolding | ( | SgNode * | r | ) |
Constant folding an AST subtree rooted at 'r' (replacing its children with their constant values, if applicable). Please be advised that constant folding on floating point computation may decrease the accuracy of floating point computations!
It is a wrapper function for ConstantFolding::constantFoldingOptimization(). Note that only r's children are replaced with their corresponding constant values, not the input SgNode r itself. You have to call this upon an expression's parent node if you want to fold the expression.
ROSE_DLL_API int SageInterface::instrumentEndOfFunction | ( | SgFunctionDeclaration * | func, |
SgStatement * | s | ||
) |
Instrument(Add a statement, often a function call) into a function right before the return points, handle multiple return statements (with duplicated statement s) and return expressions with side effects. Return the number of statements inserted.
Useful when adding a runtime library call to terminate the runtime system right before the end of a program, especially for OpenMP and UPC runtime systems. Return with complex expressions with side effects are rewritten using an additional assignment statement.
ROSE_DLL_API bool SageInterface::mergeDeclarationAndAssignment | ( | SgVariableDeclaration * | decl, |
SgExprStatement * | assign_stmt, | ||
bool | removeAssignStmt = true |
||
) |
Merge a variable assignment statement into a matching variable declaration statement. Callers should make sure the merge is semantically correct (by not introducing compilation errors). This function simply does the merge transformation, without eligibility check.
e.g. int i; i=10; becomes int i=10; the original i=10 will be deleted after the merge if success, return true, otherwise return false (e.g. variable declaration does not match or already has an initializer) The original assignment stmt will be removed by default This function is a bit ambiguous about the merge direction, to be phased out.
ROSE_DLL_API bool SageInterface::mergeDeclarationWithAssignment | ( | SgVariableDeclaration * | decl, |
SgExprStatement * | assign_stmt | ||
) |
Merge a declaration statement into a matching followed variable assignment. Callers should make sure the merge is semantically correct (by not introducing compilation errors). This function simply does the merge transformation, without eligibility check.
e.g. int i; i=10; becomes int i=10; the original int i; will be deleted after the merge
ROSE_DLL_API SgExprStatement* SageInterface::splitVariableDeclaration | ( | SgVariableDeclaration * | decl | ) |
Split a variable declaration with an rhs assignment into two statements: a declaration and an assignment.
Return the generated assignment statement, if any e.g. int i =10; becomes int i; i=10; This can be seen as a normalization of declarations
ROSE_DLL_API SgAssignInitializer* SageInterface::splitExpression | ( | SgExpression * | from, |
std::string | newName = "" |
||
) |
Replace an expression with a temporary variable and an assignment statement.
Add a new temporary variable to contain the value of 'from'. Change reference to 'from' to use this new variable. Assumptions: (1)'from' is not within the test of a loop or 'if'; (2)not currently traversing 'from' or the statement it is in. Return value: the new temp variable declaration's assign initializer containing the from expression.
unsigned long long SageInterface::getIntegerConstantValue | ( | SgValueExp * | expr | ) |
Get the constant value from a constant integer expression; abort on everything else.
Note that signed long longs are converted to unsigned.
std::pair<SgStatement*, SgInitializedName*> SageInterface::wrapFunction | ( | SgFunctionDeclaration & | definingDeclaration, |
SgName | newName | ||
) |
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
.
definingDeclaration | the defining function declaration of f |
newName | the name of function f \details 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)
is the next entry in the statement list; the forward declaration of f is the previous entry in the statement list. |
Referenced by wrapFunction().
std::pair<SgStatement*, SgInitializedName*> SageInterface::wrapFunction | ( | SgFunctionDeclaration & | definingDeclaration, |
NameGen | nameGen | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
NameGen | functor that generates a new name based on the old name. interface: SgName nameGen(const SgName&) |
nameGen | name generator |
see wrapFunction for details
Definition at line 2483 of file sageInterface.h.
References wrapFunction().
bool SageInterface::isTemplateInstantiationFromTemplateDeclarationSatisfyingFilter | ( | SgFunctionDeclaration * | function, |
T * | filter | ||
) |
This function detects template instantiations that are relevant when filters are used.
EDG normalizes some in-class template functions and member functions to be redefined outside of a class. this causes the associated template instantiations to be declared outside of the class, and to be marked as compiler generated (since the compiler generated form outside of the class declaration). ROSE captures the function definitions, but in the new location (defined outside of the class declaration). This can confuse some simple tests for template instantiations that are a part of definitions in a file, thus we have this function to detect this specific normalization.
Definition at line 2804 of file sageInterface.h.
References SgDeclarationStatement::get_firstNondefiningDeclaration(), SgTemplateInstantiationMemberFunctionDecl::get_templateDeclaration(), and SgTemplateInstantiationFunctionDecl::get_templateDeclaration().