Skip to content

SgNodeHelper

Namespaces

Name

Description

Pattern

Provides functions which match a certain AST pattern and return a pointer to a node of interest inside that pattern.

Types

Name

Description

ExtendedCallInfo

Result structure of extended C++ function call matching matchExtendedNormalizedCall

LineColPair

Functions for simplifying access to SgNode information

OmpSectionList

PragmaList

collects all pragmas with name 'pragmaName' and creates a list of all pragma strings (with stripped off prefix) and the associated SgNode.

Functions

Name

Description

abbreviatedLocationToString
std::string abbreviatedLocationToString(SgNode* node, size_t maxFileNameLength = 30);

returns location (consisting of filename, line, column) Abbreviates fileName if too long, max file name length can be set

classDeclarationNestingSequence
std::list<SgClassDeclaration*> classDeclarationNestingSequence(SgDeclarationStatement*);

computes a list representing the nesting structure of classes (including structs and unions). It traverses the AST upwards and collects SgClassDeclaration(s) only. This covers nested classes, nested structs, and nested unions, and combinations of those.

collectPragmaLines
PragmaList collectPragmaLines(std::string pragmaName, SgNode* root);

correspondingSgFunctionDefinition
SgFunctionDefinition* correspondingSgFunctionDefinition(SgNode* node);

this function should only be called for a node in the subtree of a SgFunctionDefinition node. For a given 'node' it determines the correspondnig functionDefinition node when searching upwards in the AST for such a SgFunctionDefinition node. It is useful as a simple lookup function from inside the AST subtree of a SgFunctionDefinition. Returns 0 if no SgFunctionDefinition is found (e.g. global scope).

determineChildIndex
size_t determineChildIndex(SgNode* node);

computes for a given node the index number of it from the parent. e.g. node1(node2,node3,node4) : node4 has index 2 (starting at 0) For the root node of an AST (e.g. SgProject) this function returns ‐1.

determineFunctionDefinition
SgFunctionDefinition* determineFunctionDefinition(SgFunctionCallExp* fCall);

This function determines for a given function‐call‐expression its corresponding function‐definition (by using get_definingDeclaration). This function has constant complexity. It does not perform a search, but uses the information as present in the AST. If this information is not sufficient to determine the definition of a function it returns 0. For a consistent AST this will find all definitions in the same file, but not in a other SgFile.

determineVariablesInSubtree
std::vector<SgVarRefExp*> determineVariablesInSubtree(SgNode* node);

determines all VarRefExp in the subtree of 'node'. The order in the vector corresponds to the traversal order on the AST.

doubleQuotedEscapedHTMLString
std::string doubleQuotedEscapedHTMLString(std::string s1);

Same as doubleQuotedEscapedString but also replaces <,<=,>=,> with the corresponding HTML codes. This is required when printing program code inside HTML tables of a dot file.

doubleQuotedEscapedString
std::string doubleQuotedEscapedString(std::string s1);

computes a new string from s1 where each doublequote is replaced with a backslash followed by the doublequote. This is helpful when printing unparsed program fragments which contain doublequoted strings to a dot file (used by nodeToString). This function also replaces <,<=,>=,> with the corresponding HTML codes.

findFunctionDeclarationWithFunctionSymbol
SgFunctionDeclaration* findFunctionDeclarationWithFunctionSymbol(SgNode* node);

returns the function declaration statement found for a given function symbol.

findVariableDeclarationWithVariableSymbol
SgDeclarationStatement* findVariableDeclarationWithVariableSymbol(SgNode* node);

returns the declaration statement found for a given variable symbol.

getCalleeFunctionType
SgFunctionType* getCalleeFunctionType(SgFunctionCallExp* call);

getCalleeOfCall
SgExpression* getCalleeOfCall(SgFunctionCallExp* call);

getClosestParentFunctionDefinitionOfLocatedNode
SgFunctionDefinition* getClosestParentFunctionDefinitionOfLocatedNode(SgLocatedNode* locatedNode);

schroder3 (2016‐07‐22): Returns the closest function definition that contains the given node

getCond
SgNode* getCond(SgNode* node);

returns the root node representing the AST of the condition of If, While, DoWhile, For, CondOperator, switch.

getExprRootChild
SgNode* getExprRootChild(SgNode* node);

returns the child of SgExpressionRoot (which is guaranteed to be unique and to exist)

getExprStmtChild
SgNode* getExprStmtChild(SgNode* node);

returns the child of SgExprStatement (which is guaranteed to be unique and to exist)

getFalseBranch
SgNode* getFalseBranch(SgNode* node);

returns the root node representing the AST of the false branch of If, CondOperator.

getFirstChild
SgNode* getFirstChild(SgNode* node);

returns the first child of an arbitrary AST node (throws exception if numChildren==0)

getFirstOfBlock
SgNode* getFirstOfBlock(SgNode* node);

returns the first Statement of SgBasicBlock (throws exception if numChildren==0)

getForIncExpr
SgExpression* getForIncExpr(SgNode* node);

returns the incr/derc‐expr of For.

getForInitList
std::vector<SgStatement*>& getForInitList(SgNode* node);

returns the initializer‐list of For.

getFunctionCallActualParameterList
std::vector<SgExpression*>& getFunctionCallActualParameterList(SgNode* node);

return a function‐call's argument list

getFunctionDefinitionFormalParameterList
std::vector<SgInitializedName*>& getFunctionDefinitionFormalParameterList(SgNode* node);

return a function‐definition's list of formal paramters

getFunctionName
std::string getFunctionName(SgNode* node);

returns function name of SgFunctionDefinition, SgFunctionDeclaration, SgFunctionCall.

getFunctionReturnType
SgType* getFunctionReturnType(SgNode* node);

return a function‐definition's return type

getInitializedNameOfVariableDeclaration
SgInitializedName* getInitializedNameOfVariableDeclaration(SgVariableDeclaration* decl);

returns the initialized name object of a variable declaration. Otherwise it throws an exception.

getInitializerExpressionOfVariableDeclaration
SgExpression* getInitializerExpressionOfVariableDeclaration(SgVariableDeclaration* decl);

returns the initializer expression of a variable declaration. If no initializer exists it returns 0.

getInitializerListOfAggregateDeclaration
std::vector<SgExpression*>& getInitializerListOfAggregateDeclaration(SgVariableDeclaration* decl);

getLabelName
std::string getLabelName(SgNode* node);

returns the label name of a SgLabelStatement without trailing ":"

getLastOfBlock
SgNode* getLastOfBlock(SgNode* node);

returns the last Statement of SgBasicBlock (throws exception if numChildren==0)

getLhs
SgNode* getLhs(SgNode* node);

return lhs of a binary node (if it is not a binary node it throws an exception)

getLoopBody
SgNode* getLoopBody(SgNode* node);

returns the root node representing the AST of the loop body of While, DoWhile, For.

getOmpSectionList
OmpSectionList getOmpSectionList(SgOmpSectionsStatement* sectionsStmt);

getParent
SgNode* getParent(SgNode* node);

returns the parent of a node. Essentially a wrapper function of the ROSE get_parent() function, but throws an exception if no parent exists. For SgProject node no exception is thrown if no parent exists because it is the root node of a ROSE AST.

getPragmaDeclarationString
std::string getPragmaDeclarationString(SgPragmaDeclaration* pragmaDecl);

return the verbatim pragma string as it is found in the source code this string includes the leading "#pragma".

getReferenceBaseType
SgType* getReferenceBaseType(SgType const* t);

getRhs
SgNode* getRhs(SgNode* node);

return rhs of a binary node (if it is not a binary node it throws an exception)

getSymbolOfFunction
SgFunctionSymbol* getSymbolOfFunction(SgFunctionRefExp* funcRefExp);

returns the SgSymbol* of the function in a SgFunctionRefExp

getSymbolOfFunctionDeclaration
SgFunctionSymbol* getSymbolOfFunctionDeclaration(SgFunctionDeclaration* decl);

returns the SgSymbol* of the variable in a function declaration

getSymbolOfInitializedName
SgSymbol* getSymbolOfInitializedName(SgInitializedName* initName);

returns the SgSymbol* of a SgInitializedName

getSymbolOfVariable
SgSymbol* getSymbolOfVariable(SgVarRefExp* varRefExp);

returns the SgSymbol* of the variable in a SgVarRefExp

getSymbolOfVariableDeclaration
SgSymbol* getSymbolOfVariableDeclaration(SgVariableDeclaration* decl);

returns the SgSymbol* of the variable in a variable declaration

getTrueBranch
SgNode* getTrueBranch(SgNode* node);

returns the root node representing the AST of the true branch of If, CondOperator.

getUnaryOpChild
SgNode* getUnaryOpChild(SgNode* node);

returns the child of a SgUnaryExp (which is guaranteed to be unique and to exist)

hasAssignInitializer
bool hasAssignInitializer(SgVariableDeclaration* decl);

returns true if the declaration has an assign initializer (e.g. char[2]="";)

hasOmpNoWait
bool hasOmpNoWait(SgOmpClauseBodyStatement* ompNode);

Checks if an OpenMP construct is marked with a nowait clause

isAggregateDeclaration
bool isAggregateDeclaration(SgVariableDeclaration* decl);

isAggregateDeclarationWithInitializerList
bool isAggregateDeclarationWithInitializerList(SgVariableDeclaration* decl);

returns true if the declaration has an initializer list (e.g. char[2]={'a',0};

isArrayAccess
bool isArrayAccess(SgNode* node);

isArrayDeclaration
bool isArrayDeclaration(SgVariableDeclaration* decl);

isArrayElementAssignment
bool isArrayElementAssignment(SgNode* node);

checks whether the expression 'node' represents an assignment to an array's element considers all assignment operators and arrays of any size

isAstRoot
bool isAstRoot(SgNode* node);

checks whether the node 'node' is the root node of the AST by using the get_parent function.

isCallableExpression
SgFunctionType* isCallableExpression(SgExpression* expr);

isCallableType
SgFunctionType* isCallableType(SgType* type);

isCond
bool isCond(SgNode* node);

is true if 'node' is the root node of the AST representing the condition of If, While, DoWhile, For, switch, CondExp.

isCondInBranchStmt
bool isCondInBranchStmt(SgNode* node);

is true if 'node' is the root node of the AST representing the condition of If, While, DoWhile, For, switch.

isCondStmt
bool isCondStmt(SgNode* node);

is true if 'node' is the root node of the AST representing If, While, DoWhile, For, switch.

isCondStmtOrExpr
bool isCondStmtOrExpr(SgNode* node);

is true if 'node' is the root node of the AST representing If, While, DoWhile, For, switch, CondExp.

isFloatingPointAssignment
bool isFloatingPointAssignment(SgNode* exp);

isFloatingPointType
bool isFloatingPointType(SgType* type);

isForIncExpr
bool isForIncExpr(SgNode* node);

determines whether a node is the root node of an AST representing the inc‐expr in a SgForStatement. This function is helpful to deal with this special case in the ROSE AST where an expression does not have a root node which can be easily determined to be a root node of an expression (i.e. here it can be any binary or unary node in constrast to all other expressions in the ROSE AST which are either a SgExprStatement or have a SgExpressionRoot node.

isForwardFunctionDeclaration
bool isForwardFunctionDeclaration(SgNode* declaration);

Determines whether a provided function declaration is a forward declaration

isFunctionParameterVariableSymbol
SgVariableSymbol* isFunctionParameterVariableSymbol(SgNode* node);

checks whether a SgVariableSymbol is representing a function parameter (this does not apply for forward declarations)

isFunctionPointerType
SgPointerType const* isFunctionPointerType(SgType const* type);

isGlobalVariableDeclaration
bool isGlobalVariableDeclaration(SgVariableDeclaration* varDecl);

isGlobalVariableDeclarationSymbol
bool isGlobalVariableDeclarationSymbol(SgSymbol* varDecl);

Determines if a variable is declared in global name space

isLastChildOf
bool isLastChildOf(SgNode* elem, SgNode* parent);

checks whether 'elem' is the last child (in traversal order) of node 'parent'.

isLoopCond
bool isLoopCond(SgNode* node);

is true if 'node' is the root node of the AST representing the condition of a Loop construct (While, DoWhile, For).

isLoopStmt
bool isLoopStmt(SgNode* node);

is true if 'node' is the root node of the AST representing a Loop construct (While, DoWhile, For).

isLvalueReferenceType
SgReferenceType const* isLvalueReferenceType(SgType const* t);

isPointerType
SgPointerType const* isPointerType(SgType const* t);

isPointerVariable
bool isPointerVariable(SgVarRefExp* var);

isPostfixIncDecOp
bool isPostfixIncDecOp(SgNode* node);

returns true for Expr‐‐ and Expr‐‐, otherwise false;

isPrefix
bool isPrefix(std::string const& prefix, std::string const& s);

checks whether prefix 'prefix' is a prefix in string 's'.

isPrefixIncDecOp
bool isPrefixIncDecOp(SgNode* node);

returns true for ‐‐Expr and ++Expr, otherwise false.

isReferenceType
SgType const* isReferenceType(SgType const* t);

isRvalueReferenceType
SgRvalueReferenceType const* isRvalueReferenceType(SgType const* t);

isTypeEligibleForFunctionToPointerConversion
SgFunctionType const* isTypeEligibleForFunctionToPointerConversion(SgType const* type);

isVariableSymbolInFunctionForwardDeclaration
bool isVariableSymbolInFunctionForwardDeclaration(SgNode* node);

checks whether a SgVariableSymbol is representing a variable in

lineColumnAndSourceCodeToString
std::string lineColumnAndSourceCodeToString(SgNode* node);

returns line, column, and unparsed node in one string.

lineColumnNodeToString
std::string lineColumnNodeToString(SgNode* node);

lineColumnPair
SgNodeHelper::LineColPair lineColumnPair(SgNode* node);

returns a std::pair of line and column number. If no file info exists at this node it returns (‐1,‐1).

listOfFunctionDeclarations
std::list<SgFunctionDeclaration*> listOfFunctionDeclarations(SgNode* node);

listOfFunctionDefinitions
std::list<SgFunctionDefinition*> listOfFunctionDefinitions(SgNode* node);

listOfGlobalFields
std::list<SgVariableDeclaration*> listOfGlobalFields(SgGlobal* global);

listOfGlobalFunctionDefinitions
std::list<SgFunctionDefinition*> listOfGlobalFunctionDefinitions(SgGlobal* global);

identifies the list of SgFunctionDefinitions in global scope Functions/methods of classes are NOT included in this list. Note: static/external can be resolved by further processing those objects

listOfGlobalVars
std::list<SgVariableDeclaration*> listOfGlobalVars(SgGlobal* global);

identifies the list of global variables Note: static/external can be resolved by further processing those objects

listOfSgGlobal
std::list<SgGlobal*> listOfSgGlobal(SgProject* project);

searches in the provided Project for SgGlobal nodes

listOfUsedVarsInFunctions
std::list<SgVarRefExp*> listOfUsedVarsInFunctions(SgProject* SgProject);

localVariableDeclarationsOfFunction
std::set<SgVariableDeclaration*> localVariableDeclarationsOfFunction(SgFunctionDefinition* funDef);

returns the set of all local variable‐declarations of a function

locationAndSourceCodeToString
std::string locationAndSourceCodeToString(SgNode* node, size_t maxFileNameLength = 30, size_t maxSourceLength = 20);

returns location (consisting of filename, line, column) and source code of unparsed node in one string. Abbreviates fileName and unparsed source if too long (defaults are 30,20)

locationToString
std::string locationToString(SgNode* node);

returns location (consisting of filename, line, column)

loopRelevantBreakStmtNodes
std::set<SgNode*> loopRelevantBreakStmtNodes(SgNode* node);

returns a set of SgNode where each node is a break node, but properly excludes all nested loops.

loopRelevantContinueStmtNodes
std::set<SgContinueStmt*> loopRelevantContinueStmtNodes(SgNode* node);

matchExtendedNormalizedCall
ExtendedCallInfo matchExtendedNormalizedCall(SgNode*, bool matchExtended = false);

matches C and C++ function calls (also ctor and dtor)

memberVariableDeclarationsList
std::list<SgVariableDeclaration*> memberVariableDeclarationsList(SgClassType* sgType);

Returns for a given class/struct/union a list with the variable declarations of the member variables. Note this is a filtered list returned by the SgType::returnDataMemberPointers function which also returns pointers to methods

nodeCanBeChanged
bool nodeCanBeChanged(SgLocatedNode* lnode);

nodeToString
std::string nodeToString(SgNode* node);

returns a string representing the node (excluding the subtree)

numChildren
int numChildren(SgNode* node);

returns the number of children as int (intentionally not as t_size) ensures that the number of children fits into an int, otherwise throws exception.

replaceAstWithString
void replaceAstWithString(SgNode* node, std::string s);

replaces the ast with root 'node' with the string 's'. The string is attached to the AST and the unparser uses string s instead of unparsing this substree. This function can be used to generate C++ extensions.

replaceExpression
void replaceExpression(SgExpression* e1, SgExpression* e2, bool mode = false);

replaces expression e1 by expression e2. Currently it uses the SageInterface::rewriteExpression function but wraps around some addtional checks that significantly improve performance of the replace operation.

replaceString
void replaceString(std::string& str, std::string const& from, std::string const& to);

replace in string 'str' each string 'from' with string 'to'.

scopeNestingLevel
int scopeNestingLevel(SgNode* node);

computes for a given node at which scope nesting level this node is in its AST

scopeSequenceNumber
int scopeSequenceNumber(SgNode* node);

computes for a given node at which scope nesting level this node is in its AST

setCond
void setCond(SgStatement* stmt, SgNode* cond);

sets 'cond' as the root node of the AST representing the condition in statements if, while, dowhile, for, switch.

sourceFilenameLineColumnToString
std::string sourceFilenameLineColumnToString(SgNode* node);

returns filename+line+column information of AST fragment in format "filename:line:column". Used for generating readable output

sourceFilenameToString
std::string sourceFilenameToString(SgNode* node);

returns filename as stored in AST node. Used for generating readable output.

sourceLineColumnToString
std::string sourceLineColumnToString(SgNode* node);

sourceLineColumnToString overloads

sourceLocationAndNodeToString
std::string sourceLocationAndNodeToString(SgNode* node);

switchRelevantCaseStmtNodes
std::set<SgCaseOptionStmt*> switchRelevantCaseStmtNodes(SgNode* node);

collects all case labels from the switch it started in (excludes nested switch stmts). This function also works for Duff's device code where 'case' labels can be inside nested loop/if constructs.

switchRelevantDefaultStmtNode
SgDefaultOptionStmt* switchRelevantDefaultStmtNode(SgNode* node);

returns the default stmt if it exists. Otherwise return 0 and can be used to test whether a default stmt exists in a given switch stmt. This function also works for Duff's device code. code where 'default' labels can be inside nested loop/if constructs.

symbolToString
std::string symbolToString(SgSymbol* symbol);

returns name of symbol as string

uniqueLongVariableName
std::string uniqueLongVariableName(SgNode* node);

Creates a long unique variable name for a given node of type SgVariableDeclaration or SgVarRefExp

unparseCond
std::string unparseCond(SgNode* node);

returns the string representing the condition (removes trailing ';')

Created with MrDocs