SgExpression
This class represents the notion of an expression. Expressions
Synopsis
Declared in <src/frontend/SageIII/Cxx_Grammar.h>
class SgExpression
: public SgLocatedNode
Base Classes
Name |
Description |
This class represents the notion of an expression or statement which |
Friends
Name |
Description |
Casts pointer from base class to derived class (for const pointers) |
|
Casts pointer from base class to derived class |
Non-Member Functions
Name |
Description |
This does all post‐processing fixup and translation of the Sage III AST. |
|
Fixups transformations that have added template instantiations or caused template instantiations to be output so that there is a proper prototype declaration before the template instantation is called. |
|
Change all members in a program to be public. There should really be a smarter procedure for this that only changes members used by inlined code. |
|
Checks whether appropriate nodes of an AST are marked as compiler‐generated. |
|
Checks whether appropriate nodes of an AST are marked as front‐end specific. |
|
Checks whether the physical source position information is consistant in the Sg_File_Info object |
|
Check for consistancy of isTransformation flags for nodes marked as a transformation. |
|
Combined procedure for cleaning up code after inlining. Does not do variable renaming or block flattening, however. |
|
Detect nodes marked as transformations (should not be present coming out of the frontend translation). |
|
Do finite differencing on one expression within one context. The expression must be defined and valid within the entire body of root. The rewrite rules are used to simplify expressions. When a variable var is updated from old_value to new_value, an expression of the form (var, (old_value, new_value)) is created and rewritten. The rewrite rules may either produce an arbitrary expression (which will be used as‐is) or one of the form (var, (something, value)) (which will be changed to (var = value)). |
|
Traverse the AST |
|
Are two expressions equal (using a deep comparison)? |
|
Find all variables referenced in a region |
|
Workaround for ROSE bug. Should be used whenever expressions in a program are modified. |
|
Fixup all SgDeclarationStatement to have a consistant scope (between the defining and all non‐defining declarations). |
|
Fixup all SgDeclarationStatement references to defining and non‐defining declarations. |
|
Fixup global and local symbol tables. |
|
Fixup C++ symbol tables to use aliasing symbols for using declarations. |
|
Fixup definingDeclaration and firstNondefiningDeclaration pointers in SgDeclarationStatement. |
|
Checks and fixes up inconsistanties in the settings of Sg_File_Info flags (e.g. isTransformation flag) in the Sg_File_Info object |
|
Fixup Fortran array vs. function references. |
|
Fixup Fortran Use declarations. |
|
Fixup specific pointers in the AST that we would like to not have be NULL. |
|
Fixup known macros that reference themselves and cause recursive macro expansion in the generated (unparsed) code. |
|
Fixup the storage access of all compiler‐generated forward declarations (non‐defining declarations) to match that of the defining declaration. |
|
Fixups template specializations generated by ROSE from template instantiations. |
|
Flatten nested blocks of code in a program. This code requires that variable names in the region being processed are already distinct, and it may extend variable lifetimes to the end of the outer block of code. |
|
Get the topmost enclosing expression of a given expression. Needs to be moved. |
|
Get the statement of an expression. Somewhat smarter than the standard version of this routine, but needs to be merged. |
|
Does expression expr potentially have its address taken somewhere in the tree pointed to by root? |
|
Initialize explicit scopes (support function should not be called). |
|
Initialize explicit scopes (located only at specific IR nodes). |
|
Insert Fortran "CONTAINS" statement. |
|
Internal routine to check whether a given variable declaration is a member variable. |
|
Is expression expr potentially modified (assigned to, address taken, passed by non‐const reference) somewhere in the tree pointed to by root? |
|
Casts pointer from base class to derived class (for const pointers) |
|
Casts pointer from base class to derived class |
|
Casts pointer from base class to derived class |
|
Casts pointer from base class to derived class (for const pointers) |
|
Mangles a constant expression, needed for template arguments. |
|
Mark an AST subtree as compiler generated (used for instatiated templates generated by ROSE as specializations). |
|
Mark an backend specific functions as compiler generated. |
|
Mark an AST subtree as compiler generated and to be output in the source file (code generation phase). |
|
Mark relavant expressions as l‐values explicitly. |
|
Mark any template instatiations that are overloaded (we can't output these since g++ can't resolve them). |
|
Mark an AST subtree to be unparsed using an alternative file (for multi‐file unparsing). |
|
Fixups template instantiations generated by ROSE from template declarations. |
|
Fixups transformations (which are often marked at a high level and need to be marked properly through their subtree). |
|
Move variables declared in a for statement to just outside that statement. |
|
Inequality operator |
|
Equality operator |
|
Postprocessing that is not likely to be handled in the legacy frontend/Sage III translation. |
|
Fixup template instantiations to unmark them for output followingsemantics of gnu template options |
|
Propagate hidden list information for variables, types, and class elaboration. |
|
Change all variable and label references to point to new symbols, created to point to the matching declaration found in the program. This needs to be moved into somewhere in FixSgTree. |
|
Remove all null statements (those with only an integer constant or a null expression) |
|
Remove unused variables in a scope |
|
Rename all labels in a block of code. |
|
Rename all variables in a block of code, and ensure that all variable references point to the correct declarations. |
|
Replace a child of a node. |
|
Replace the expression "from" with another expression "to", wherever it appears in the AST. The expression "from" is not deleted, and may be reused elsewhere in the AST. |
|
This function acts in two different ways |
|
Interface function to reset parent pointers. |
|
This traversal calles ResetParentPointersInMemoryPool Memory Pool traversal. |
|
This is a top level function not called recursively. |
|
Sets names of template classes (calls custom traversal). |
|
affineInequalitiesPlacer * |
|
In code with declarations such as "int foo = bar", where foo and bar are not modified, replace "foo" with "bar" and remove the declaration |
|
Do a simple form of finite differencing on all functions contained within root (which should be a project, file, or function definition). |
|
This is a top level function not called recursively. |
|
Create a deep‐copy of an SgNode |
|
Returns 'true' if this node is contained in a C99‐only project. |
|
Reset source position as transformation for the current node only |
|
|
Reset source position as transformation recursively |
Convert a node's location to a string‐friendly form. |
|
**** The function Result querySubTree ( SgNode * subTree, _Result (__x)(SgNode_,_Arg), Arg x_arg, AstQueryNamespace::QueryDepth defineQueryType =AstQueryNamespace::AllNodes ) will query the subtree of the IR node in the first argument for nodessatisfying the criteria specified in and returned by the function pointer inthe second argument.** |
|
** The function Result querySubTree ( SgNode * subTree, _Result (__x)(SgNode_), AstQueryNamespace::QueryDepth defineQueryType =AstQueryNamespace::AllNodes )* will query the subtree of the IR node in the first argument for nodessatisfying the criteria specified in and returned by the function pointer inthe second argument.** |
|
**** The function std::list<ListElement> querySubTree<ListElement>(SgNode* node,Predicate& _pred) will query the subtree of the IR node in the first argumentfor nodes satisfying the criteria specified in and returned by the predicatein the second argument.** |
|
Collect non‐local variables that are read and written within the given ast. This is a wrapper of the ComputeAstSideEffects function to provide a more convenient user interface. Returns true if the returned variables are guaranteed to be complete; returns false otherwise. |
|
Returns the collection of memory references modified, read, and invoked (as function calls) as potential side effects of running the given ast, inside the given scope. |
|
Extracts the '#if' directive structure from a project. |
|
Locate the '#if' directive context at a node. |
|
Populates functionList with declarations of all functions that may get called. This is basically a wrapper around getPropertiesForExpression. |
|
Populates functionList with definitions of all functions that may get called. This is basically a wrapper around getPropertiesForExpression that extracts the SgFunctionDefinition from the Properties object. This returns only callees that have definitions ‐ to get all possible callees, use getDeclarationsForExpression |
|
Checks if the functionDeclaration (node) matches functionType |
|
This is the external interface of constant folding: |
|
**** |
|
**** |
|
**** |
|
**** |
|
** The function NodeQuerySynthesizedAttributeType queryMemoryPool ( SgNode * subTree, Result (*x)(SgNode*,_Arg), Arg x_arg, VariantVector ){ will on every node of the memory pool which has a corresponding variant inVariantVector performa the action specified by the second argument and returna NodeQuerySynthesizedAttributeType.* |
|
** The function Result queryMemoryPool ( SgNode * subTree, SgNode, TypeOfQueryTypeTwoParameters, VariantVector* ){ will on every node of the memory pool which has a corresponding variant inVariantVector performa the predefined action specified by the second argumentand return a NodeQuerySynthesizedAttributeType.** |
|
** The function Result queryMemoryPool ( SgNode * subTree, _Result (__x)(SgNode_), VariantVector* ){ will on every node of the memory pool which has a corresponding variant inVariantVector performa the action specified by the second argument and returna NodeQuerySynthesizedAttributeType.** |
|
**** |
|
**** |
|
**** |
|
The function querySubTree (SgNode * subTree, VariantVector targetVariantVector, AstQueryNamespace::QueryDepth defineQueryType =AstQueryNamespace::AllNodes); reutnrs a list of all SgNodes us the ASTsub‐tree of the variable 'subTree' conforming to the variants inVariantVector.***** |
|
**** |
|
**** |
|
**** |
|
**** |
|
**** |
|
**** |
|
**** |
|
Create an initial value according to reduction operator type |
|
A helper function to generate implicit or explicit task for either omp parallel or omp task |
|
Collect expression from given types of OpenMP clauses associated with an omp statement: private, reduction, etc |
|
Find an enclosing parallel region or function definition's body |
|
Replace references to oldVar within root with references to newVar, return the number of references replaced. |
|
Replace variable references within root based on a map from old symbols to new symbols |
|
Replace all variable references in a set by pointers to the variable |
|
Translate omp atomic |
|
Translate omp barrier |
|
Translate omp critical |
|
Translate omp flush |
|
Translate omp for or omp do loops |
|
Translate omp master |
|
Translate omp metadirective |
|
Translate the ordered directive (not the ordered clause) |
|
Translate omp parallel |
|
Translate omp sections |
|
Translate omp simd |
|
Translate omp single |
|
Translate "omp target" |
|
Translate "omp target data" |
|
Translate omp for or omp do loops affected by the "omp target" directive, using naive 1‐to‐1 mapping Liao 1/28/2013 |
|
Translate omp for or omp do loops affected by the "omp target" directive, using a round robin‐scheduler Liao 7/10/2014 |
|
Translate omp parallel under "omp target" |
|
Translate omp task |
|
Translate omp taskwait |
|
Translate omp threadprivate |
|
Translate omp tile |
|
Translate omp unroll |
|
Helper Function to process Left Hand Side of an Expression |
|
Helper Function to process Right Hand Side of an Expression |
|
Build alignof() expression with an expression parameter |
|
Build the rhs of a variable declaration which includes an assignment |
|
Build an assignment statement from lefthand operand and right hand operand |
|
This version does not recursively reset the file info as a transformation. |
|
Template function to build a binary expression of type T, taking care of parent pointers, file info, lvalue, etc. Available instances include: buildAddOp(), buildAndAssignOp(), buildAndOp(), buildArrowExp(),buildArrowStarOp(),buildAtOp, buildAssignOp(),buildBitAndOp(),buildBitOrOp(),buildBitXorOp(),buildCommaOpExp(), buildConcatenationOp(),buildDivAssignOp(),buildDivideOp(),buildDotExp(),buildEqualityOp(),buildExponentiationOp(),buildGreaterOrEqualOp(),buildGreaterThanOp(),buildIntegerDivideOp(),buildIorAssignOp(),buildLessOrEqualOp(),buildLessThanOp(),buildLshiftAssignOp(),buildLshiftOp(),buildMinusAssignOp(),buildModAssignOp(),buildModOp(),buildMultAssignOp(),buildMultiplyOp(),buildNotEqualOp(),buildOrOp(),buildPlusAssignOp(),buildPntrArrRefExp(),buildRshiftAssignOp(),buildRshiftOp(),buildReplicationOp,buildScopeOp(),buildSubtractOp()buildXorAssignOp() The instantiated functions' prototypes are not shown since they are expanded using macros. Documentation tools do not expand these macros. |
|
Template function to build a binary expression of type T, taking care of parent pointers, but without file‐info. Available instances include: buildAddOp(), buildAndAssignOp(), buildAndOp(), buildArrowExp(),buildArrowStarOp(),buildAtOp, buildAssignOp(),buildBitAndOp(),buildBitOrOp(),buildBitXorOp(),buildCommaOpExp(), buildConcatenationOp(),buildDivAssignOp(),buildDivideOp(),buildDotExp(),buildEqualityOp(),buildExponentiationOp(),buildGreaterOrEqualOp(),buildGreaterThanOp(),buildIntegerDivideOp(),buildIorAssignOp(),buildLessOrEqualOp(),buildLessThanOp(),buildLshiftAssignOp(),buildLshiftOp(),buildMinusAssignOp(),buildModAssignOp(),buildModOp(),buildMultAssignOp(),buildMultiplyOp(),buildNotEqualOp(),buildOrOp(),buildPlusAssignOp(),buildPntrArrRefExp(),buildRshiftAssignOp(),buildRshiftOp(),buildReplicationOp(),buildScopeOp(),buildSubtractOp()buildXorAssignOp() The instantiated functions' prototypes are not shown since they are expanded using macros. Documentation tools do not expand these macros. |
|
Builder functions for primitive types with type size (kind) expressions |
|
Build a case option statement |
|
Build a type casting expression |
|
Build and attach a comment, comment style is inferred from the language type of the target node if not provided. It is indeed a wrapper of SageInterface::attachComment(). |
|
Build a conditional expression ?: |
|
Build and attach #define XX directives, pass "#define xxx xxx" as content. |
|
Build a CUDA kernel call expression (kernel<[config]>(parameters)) |
|
Build a CUDA kernel execution configuration (<blocks, shared, stream>) |
|
Build a decltype reference type |
|
Build a delete statement |
|
Build a SgExprListExp, used for function call parameter list etc. |
|
Build a SgExprStatement, set File_Info automatically |
|
Build a Fortran do construct |
|
Build a function call statement using function expression and argument list only, like (*funcPtr)(args); |
|
Build a goto statement from a label expression, supporting only C/C++ and not Fortran cases |
|
Build member function calls. objectExpression: the variable reference expression to an object of template class instantiation: vector<int> var1; |
|
Build ‐‐ expression, Sgop_mode is a value of either SgUnaryOp::prefix or SgUnaryOp::postfix |
|
Build noexcept operator expression with an expression parameter |
|
Build ++x or x++ , specify prefix or postfix using either SgUnaryOp::prefix or SgUnaryOp::postfix |
|
Build a return statement |
|
Build sizeof() expression with an expression parameter |
|
DQ (7/25/2014): Adding support for C11 static assertions. |
|
Build a SgSubscriptExpression, used for array shape expressions. The lower bound and stride may be nullptrs |
|
Build a ThrowOp expression |
|
DQ (1/25/2013): Added support for typeId operators. |
|
Build a GNU typeof operator |
|
Template function to build a unary expression of type T. Instantiated functions include:buildAddressOfOp(),buildBitComplementOp(),buildBitComplementOp(),buildMinusOp(),buildNotOp(),buildPointerDerefExp(),buildUnaryAddOp(),buildMinusMinusOp(),buildPlusPlusOp(). They are also used for the unary vararg operators (which are not technically unary operators). The instantiated functions' prototypes are not shown since they are expanded using macros. Documentation tools do not expand these macros. |
|
Template function to build a unary expression of type T with no file info. Instantiated functions include:buildAddressOfOp(),buildBitComplementOp(),buildBitComplementOp(),buildMinusOp(),buildNotOp(),buildPointerDerefExp(),buildUnaryAddOp(),buildMinusMinusOp(),buildPlusPlusOp(). They are also used for the unary vararg operators (which are not technically unary operators). The instantiated functions' prototypes are not shown since they are expanded using macros. Documentation tools do not expand these macros. |
|
Build vararg op expression |
|
Error checking the inserted snippet AST. |
|
Sharing IR nodes requires that the file id be added to the fileIDsToUnparse held in the Sg_File_Info object. |
|
Add a string to be unparsed to support code generation for back‐end specific tools or compilers. |
|
Find all SgPntrArrRefExp under astNode, then add SgVarRefExp (if any) of SgPntrArrRefExp's dim_info into NodeList_t |
|
Compute the intersection set for two ASTs. |
|
Attach an arbitrary string to a located node. A workaround to insert irregular statements or vendor‐specific attributes. |
|
Build and attach comment, comment style is inferred from the language type of the target node if not provided |
|
Fix up ifs, loops, while, switch, Catch, OmpBodyStatement, etc. to have blocks as body components. It also adds an empty else body to if statements that don't have them. |
|
Clear those variable symbols with unknown type (together with initialized names) which are also not referenced by any variable references or declarations under root. If root is NULL, all symbols with unknown type will be deleted. |
|
This collects the SgLocatedNodes that are marked as modified (a flag automatically set by all set_* generated functions) (useful in debugging). |
|
This collects the statements that are marked as modified (a flag automatically set by all set_* generated functions) (useful in debugging). |
|
This collects the statements that are marked as transformed (useful in debugging). |
|
Collect all variable references in a subtree |
|
Collect variable references in array types. The default NodeQuery::querySubTree() will miss variables referenced in array type's index list. e.g. double *buffer = new double[numItems]; |
|
Traversal to set the global map of names to node and node to names.collisions to support generateUniqueNameForUseAsIdentifier() function. |
|
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. |
|
|
XXX This function operates on the new file used to support outlined function definitions. We use a copy of the file where the code will be outlined FROM, so that if there are references to declarations in the outlined code we can support the outpiled code with those references. This approach has the added advantage of also supporting the same include file tree as the original file where the outlined code is being taken from. |
Variable references can be introduced by SgVarRef, SgPntrArrRefExp, SgInitializedName, SgMemberFunctionRef etc. For Dot and Arrow Expressions, their lhs is used to obtain SgInitializedName (coarse grain) by default. Otherwise, fine‐grain rhs is used. |
|
Deep copy an expression |
|
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. |
|
Cut preprocessing information from a source node and save it into a buffer. Used in combination of pastePreprocessingInfo(). The cut‐paste operation is similar to moveUpPreprocessingInfo() but it is more flexible in that the destination node can be unknown during the cut operation. |
|
Deep copy an arbitrary subtree |
|
Deep delete a sub AST tree. It uses postorder traversal to delete each child node. Users must take care of any dangling pointers, symbols or types that result. This is identical to deleteAST() |
|
|
Special purpose function for deleting AST expression tress containing valid original expression trees in constant folded expressions (for internal use only). |
Dump information about a SgNode for debugging |
|
Dumps a located node's preprocessing information. |
|
The function tries to evaluate const integer expressions (such as are used in array dimension sizes). It follows variable symbols, and requires constness. |
|
Topdown traverse a subtree from root to find the first declaration given its name, scope (optional, can be NULL), and defining or nondefining flag. |
|
Topdown traverse a subtree from root to find the first function declaration matching the given name, scope (optional, can be NULL), and defining or nondefining flag. This is an instantiation of findDeclarationStatement<T>. |
|
top‐down traversal from current node to find the main() function declaration |
|
Find unused labels which are not targets of any goto statements |
|
Mostly used internally when some AST pieces are built without knowing their target scope/parent, especially during bottom‐up construction of AST. The associated symbols, parent and scope pointers cannot be set on construction then. A set of utility functions are provided to patch up scope, parent, symbol for them when the target scope/parent become know. |
|
Get the mask expression from the header of a SgForAllStatement |
|
Generate unique name from C and C++ constructs. The name may contain space. |
|
Get the enclosing type of this associated node, not used other than in ./src/backend/unparser/nameQualificationSupport.C |
|
Get the type of the associated argument expression from the function type. |
|
Get the right bool type according to C or C++ language input |
|
Given a SgExpression that represents a named function (or bound member function), return the mentioned function |
|
Get the closest class declaration enclosing the specified AST node, |
|
Get the closest class definition enclosing the specified AST node, |
|
Get the enclosing SgExprListExp (used as part of function argument index evaluation in subexpressions). |
|
get the SgFile node from current node |
|
Find the enclosing function declaration, including its derived instances like isSgProcedureHeaderStatement, isSgProgramHeaderStatement, and isSgMemberFunctionDeclaration. |
|
Get the closest module statement enclosing the specified AST node, |
|
Find a node by type using upward traversal. |
|
Find the function definition |
|
Get the enclosing scope from a node n |
|
Find enclosing source file node |
|
Find the closest enclosing statement, including the given node |
|
Traverse back through a node's parents to find the enclosing global scope |
|
Get the initializer containing an expression if it is within an initializer. |
|
Return the loop index variable for a for loop |
|
Get the closest scope from astNode. Return astNode if it is already a scope. |
|
Find referenced symbols within an expression |
|
Get the enclosing TemplateDeclaration statement |
|
returns the array dimensions in an array as defined for arrtype |
|
returns the array dimensions in an array as defined for arrtype |
|
Generate a useful name to describe the SgNode |
|
Generate a useful name to describe the expression |
|
Add preproccessor guard around a given node. It surrounds the node with "#if guard" and "#endif" |
|
Insert an expression (new_exp ) after another expression (anchor_exp) has possible side effects, without changing the original semantics. This is done by using two comma operators: type T1; ... ((T1 = anchor_exp, new_exp),T1) )... , where T1 is a temp variable saving the possible side effect of anchor_exp. The top level comma op exp is returned. The reference to T1 in T1 = anchor_exp is saved in temp_ref. |
|
Insert an expression (new_exp )before another expression (anchor_exp) has possible side effects, without changing the original semantics. This is achieved by using a comma operator: (new_exp, anchor_exp). The comma operator is returned. |
|
Check if a node is from a header file |
|
Check if a node is from a system header file |
|
check if node1 is a strict ancestor of node 2. (a node is not considered its own ancestor) |
|
Check if an expression is an array access (SgPntrArrRefExp). If so, return its name expression and subscripts if requested. Users can use convertRefToInitializedName() to get the possible name. It does not check if the expression is a top level SgPntrArrRefExp. |
|
Check if a SgNode _s is an assignment statement (any of =,+=,‐=,&=,/=, ˆ=, etc) |
|
Check if a for‐loop has a canonical form, return loop index, bounds, step, and body if requested |
|
Check if a bool or int constant expression evaluates to be a false value |
|
Check if a bool or int constant expression evaluates to be a true value |
|
Compare AST nodes, subtree, etc |
|
Is an overloaded operator an index operator (also referred to as call or subscript operators). (e.g. X & operator()() or X & operator[]). |
|
Check if a SgNode is a main() function declaration |
|
Check if a node is SgOmp*Statement |
|
Return true if expr refers to an overloaded operator‐> or operator‐>*. |
|
Return true if expr is part of an overloaded operator‐> call chain. |
|
Is an overloaded operator a postfix operator. (e.g. ). |
|
Check if a SgNode is a declaration for a structure |
|
Check if a SgNode is a declaration for a union |
|
Convert all code within root matching the patern of (&left)‐>right, and translate them into left.right. Return the number of matches of the pattern. Be default, only transformation generated nodes will be normalized. |
|
Output the local symbol tables. |
|
Paste preprocessing information from a buffer to a destination node. Used in combination of cutPreprocessingInfo() |
|
Pretty print AST horizontally, output to std output. |
|
Pretty print AST horizontally, output to a specified file, a simpiler interface than printAST2TextFile() |
|
Pretty print AST horizontally, output to a specified text file. If printType is set to false, don't print out type info. |
|
Pretty print AST horizontally, output to a specified text file. If printType is set to false, don't print out types info. |
|
Query a subtree to get all nodes of a given type, with an appropriate downcast. |
|
Recursively print current and parent nodes. used within gdb to probe the context of a node. |
|
Set original expression trees to NULL for SgValueExp or SgCastExp expressions, so you can change the value and have it unparsed correctly. |
|
Remove consecutive labels |
|
Remove jumps whose label is immediately after the jump. Used to clean up inlined code fragments. |
|
Remove labeled goto statements |
|
Remove labels which are not targets of any goto statements: its child statement is also removed by default. |
|
Replace an expression with another, used for variable reference substitution and others. the old expression can be deleted (default case) or kept. |
|
Replace a given expression with a list of statements produced by a generator |
|
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 |
|
Replace an anchor node with a specified pattern subtree with optional SgVariantExpression. All SgVariantExpression in the pattern will be replaced with copies of the anchor node. |
|
Save AST into a pdf file. Start from a node to find its enclosing file node. The entire file's AST will be saved into a pdf. |
|
we have two serialize() functions, one for a single node, the other for a list of pointers |
|
set left hand operand for binary expressions, transparently downcasting target expressions when necessary |
|
Set the lower bound of a loop header for (i=lb; ...) |
|
Set the stride(step) of a loop 's incremental expression, regardless the expression types (i+=s; i= i+s, etc) |
|
Set the upper bound of a loop header,regardless the condition expression type. for (i=lb; i op up, ...) |
|
Set current node's source position as transformation generated |
|
Set current node's source position as NULL |
|
Set operands for expressions with single operand, such as unary expressions. handle file info, lvalue, pointer downcasting, parent pointer etc. |
|
set left hand operand for binary expression |
|
Set the source code positon for the current (input) node. |
|
DQ (5/1/2012): New function with improved name. |
|
Set the source code positon for the subtree (including the root). |
|
Recursively set source position info(Sg_File_Info) as transformation generated |
|
Replace an expression with a temporary variable and an assignment statement |
|
Split long expressions into blocks of statements |
|
Diagnostic function for tracing back through the parent list to understand at runtime where in the AST a failure happened. |
|
returns location (consisting of filename, line, column) Abbreviates fileName if too long, max file name length can be set |
|
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). |
|
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. |
|
determines all VarRefExp in the subtree of 'node'. The order in the vector corresponds to the traversal order on the AST. |
|
returns the function declaration statement found for a given function symbol. |
|
returns the declaration statement found for a given variable symbol. |
|
|
schroder3 (2016‐07‐22): Returns the closest function definition that contains the given node |
returns the root node representing the AST of the condition of If, While, DoWhile, For, CondOperator, switch. |
|
returns the child of SgExpressionRoot (which is guaranteed to be unique and to exist) |
|
returns the child of SgExprStatement (which is guaranteed to be unique and to exist) |
|
returns the root node representing the AST of the false branch of If, CondOperator. |
|
returns the first child of an arbitrary AST node (throws exception if numChildren==0) |
|
returns the first Statement of SgBasicBlock (throws exception if numChildren==0) |
|
returns the incr/derc‐expr of For. |
|
returns the initializer‐list of For. |
|
return a function‐call's argument list |
|
return a function‐definition's list of formal paramters |
|
returns function name of SgFunctionDefinition, SgFunctionDeclaration, SgFunctionCall. |
|
return a function‐definition's return type |
|
returns the initializer expression of a variable declaration. If no initializer exists it returns 0. |
|
returns the label name of a SgLabelStatement without trailing ":" |
|
returns the last Statement of SgBasicBlock (throws exception if numChildren==0) |
|
return lhs of a binary node (if it is not a binary node it throws an exception) |
|
returns the root node representing the AST of the loop body of While, DoWhile, For. |
|
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. |
|
return rhs of a binary node (if it is not a binary node it throws an exception) |
|
returns the root node representing the AST of the true branch of If, CondOperator. |
|
returns the child of a SgUnaryExp (which is guaranteed to be unique and to exist) |
|
checks whether the expression 'node' represents an assignment to an array's element considers all assignment operators and arrays of any size |
|
checks whether the node 'node' is the root node of the AST by using the get_parent function. |
|
is true if 'node' is the root node of the AST representing the condition of If, While, DoWhile, For, switch, CondExp. |
|
is true if 'node' is the root node of the AST representing the condition of If, While, DoWhile, For, switch. |
|
is true if 'node' is the root node of the AST representing If, While, DoWhile, For, switch. |
|
is true if 'node' is the root node of the AST representing If, While, DoWhile, For, switch, CondExp. |
|
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. |
|
Determines whether a provided function declaration is a forward declaration |
|
checks whether a SgVariableSymbol is representing a function parameter (this does not apply for forward declarations) |
|
checks whether 'elem' is the last child (in traversal order) of node 'parent'. |
|
is true if 'node' is the root node of the AST representing the condition of a Loop construct (While, DoWhile, For). |
|
is true if 'node' is the root node of the AST representing a Loop construct (While, DoWhile, For). |
|
returns true for Expr‐‐ and Expr‐‐, otherwise false; |
|
returns true for ‐‐Expr and ++Expr, otherwise false. |
|
checks whether a SgVariableSymbol is representing a variable in |
|
returns line, column, and unparsed node in one string. |
|
returns a std::pair of line and column number. If no file info exists at this node it returns (‐1,‐1). |
|
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) |
|
returns location (consisting of filename, line, column) |
|
returns a set of SgNode where each node is a break node, but properly excludes all nested loops. |
|
matches C and C++ function calls (also ctor and dtor) |
|
returns a string representing the node (excluding the subtree) |
|
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. |
|
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. |
|
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. |
|
computes for a given node at which scope nesting level this node is in its AST |
|
computes for a given node at which scope nesting level this node is in its AST |
|
returns filename+line+column information of AST fragment in format "filename:line:column". Used for generating readable output |
|
returns filename as stored in AST node. Used for generating readable output. |
|
returns filename followed by line:column in one string. Used for generating readable output. |
|
returns filename followed by line, separator, and column in one string. Used for generating readable output. |
|
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. |
|
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. |
|
Creates a long unique variable name for a given node of type SgVariableDeclaration or SgVarRefExp |
|
returns the string representing the condition (removes trailing ';') |
|
Assign Ids and save current File Info. |
|
The first CFG node for a construct (before the construct starts to execute) |
|
The last CFG node for a construct (after the entire construct has finished executing). This node may not actually be reached if, for example, a goto causes a loop to be exited in the middle |
|
Dump the filtered dot graph of a virtual control flow graph starting from SgNode (start) |
|
Dump the full dot graph of a virtual control flow graph starting from SgNode (start) |
|
Dump a CFG with only interesting nodes for a SgNode |
|
Returns CFG node for just before start |
|
* CALL‐BACK FUNCTIONS FOR cfgRWTransaction::transform() ** |
|
/ SgExpression that is that/ assignment (effectively a type cast) or NULL otherwise |
|
Count how many computations of expr are within root. Same caveats as expressionComputedIn. |
|
Is the expression expr computed within root? This test is simple, and does not account for changes to the variables in expr. |
|
finds an ancestor node with a given type |
|
asserts that n has type SageNode |
|
unchecked down cast from SgNode to SageNode |
|
tests pattern for an assert |
|
|
tests pattern SgExprStatement(SgAssignOp(VarRefExp,FunctionCallExp)) and returns pointer to FunctionCallExp otherwise 0. |
tests pattern SgExprStatement(FunctionCallExp) and returns pointer to FunctionCallExp, otherwise 0. |
|
tests several patterns and returns pointer to FunctionCallExp inside that matched pattern, otherwise 0. |
|
|
tests pattern for function call in variable declaration and returns pointer to FunctionCallExp otherwise 0. |
tests pattern SgReturnStmt(FunctionCallExp) and returns pointer to FunctionCallExp, otherwise 0. |
|
tests pattern SgFunctionCall(...) where the name of the function is fprintf with 3 params |
|
tests pattern SgFunctionCall(...) where the name of the function is printf with 2 params |
|
tests pattern SgFunctionCall(...) where the name of the function is scanf with 2 params |
|
|
checks variable declaration with function call, returns variable declaration. Otherwise 0. e.g. int x=f(); |
|
checks variable declaration with function call, returns both in a pair, or a with (0,0). |
Get the function definition containing a given node |
|
Do partial redundancy elimination on all functions within the scope n. |
|
Do partial redundancy elimination, looking for copies of one expression expr within the basic block root. A control flow graph for root must be provided in cfg, with a map from nodes to their statements in node_statements, a map from edges to their CFG edge types in edge_type, and a map from edges to their insertion points in edge_insertion_point. The algorithm used is that of Paleri, Srikant, and Shankar ("Partial redundancy elimination: a simple, pragmatic, and provably correct algorithm", Science of Computer Programming 48 (2003) 1‐‐20). |
Derived Classes
Name |
Description |
This class represents the notion of a binary operator. |
|
This class represents the concept of a generic call expression. |
|
This class represents the concept of a C++ expression built from a class name. |
|
This class represents the concept of a C trinary conditional expression (e.g. "test ? true : false") |
|
This class represents the concept of a C++ call to the delete operator. |
|
This class represents the concept of a C and C++ expression list. |
|
This class represents the function being called and must be assembled in the |
|
This class represents the notion of an initializer for a variable declaration or |
|
This class represents a lambda expression. |
|
This class represents the member function being called and must be assembled in the |
|
This class represents the concept of a C++ call to the new operator. |
|
This class represents the "&" operator (applied to any lvalue). |
|
This class represents the "sizeof()" operator (applied to any type). |
|
This class represents the GNU extension "statement expression" (thus is |
|
This class represents the "this" operator (can be applied to any member data). |
|
This class represents the notion of a unary operator. |
|
This class represents the notion of an value (expression value). |
|
This class represents the variable refernece in expressions. |
Description
are derived from SgLocatedNodes, since similar to statement, expressions have a concrete location within the user's source code. There are no direct uses of this IR node anywhere. All expressions are derived from this IR node to build derived classes such as unary and binary operators, conditional expressions, delete expression, variable reference expressions, etc. ‐ Note: The SgExpression class has a virtual get_type() member function which returns the type associated with any expression. The get_type() support has the following properties: ‐ The type is not explicitly stored in the IR, except for: ‐# SgCastExp ‐# SgNewExp ‐# SgAssignInitializer ‐# SgAggregateInitializer ‐# SgConstructorInitializer ‐# SgVarArgOp ‐# SgVarArgStartOp ‐# SgVarArgEndOp ‐# SgVarArgCopyOp ‐# SgVarArgStartOneOperandOp ‐ Binary operators return the type associated with the lhs operand, except for (which return the type associated with the rhs operand): ‐# SgDotExp ‐# SgArrowExp ‐# SgDotStarOp ‐# SgArrowStarOp ‐ Unary operators return the type of their operand ‐ Value expressions return predefined types (that or their value) ‐ Other special cases include: ‐# SgPntrArrRefExp, returns the element type of the array being referenced by the lhs (non‐trivial implementation), must handle cases of: ‐# SgArrayType ‐# SgPointerType ‐# SgTypedefType ‐# SgPointerDerefExp, returns the type of the dereferenced pointer (non‐trivial implementation), must handle cases of: ‐# SgArrayType ‐# SgPointerType ‐# SgTypedefType ‐# SgReferenceType ‐# SgFunctionType ‐# SgMemberFunctionType ‐# SgAddressOfOp, creates a pointer to the base type which is stored internally. ‐# SgFunctionCallExp, returns the return type of the function being called (except in special cases, this might require more work later). Migration to the correct implementation is more complex due to requirements of backward compatability with older design. ‐# SgSizeOfOp, returns SgTypeUnsignedInt ‐# SgTypeIdOp, returns type of stored operand (not clear if this is correct) ‐# SgConditionalExp, tests for matching of types from true and false branches, but returns type associated with true branch. The types from each branch frequently don't match in application codes. ‐# SgDeleteExp, returns SgTypeVoid (used to return SgDefaultType) ‐# SgExprListExp, returns SgDefaultType, but should return type of last expression. ‐# SgVarRefExp, returns the type associated with the SgSymbol stored internally. ‐# SgFunctionRefExp, returns the type associated with the SgSymbol stored internally. ‐# SgMemberFunctionRefExp, returns the type associated with the SgSymbol stored internally. ‐# SgThisExp, returns a SgPointerType constructed from the type of the class symbol (stored inteernally). ‐# SgEnumVal, returns a SgTypeInt ‐# SgLongLongIntVal, returns SgTypeLong (should return SgTypeLongLong) ‐# SgNewExp, returns a pointer to p_specified_type (explicitly stored there) ‐ Logical operators return SgTypeInt, these include: ‐# SgAndOp ‐# SgOrOp ‐# SgNotOp ‐# All others operate as a SgBinaryOp (type of lhs operand) or SgUnaryOp (type of operand). not clear if this is the correct behavior. ‐ The following expressions return a SgTypeDefault: ‐# SgThrowOp ‐# SgNullExpression ‐# SgVariantExpression ‐ Note: get_type() vs. get_expression_type(). Note that there is of some IR nodes a get_expression_type() which is always a data access function to a stored type. The get_expression_type() function is for internal use only. Where used, this function can return NULL if the explicitly stored p_expression_type variable is not needed (this is to support it later being removed). Although the type should be computed most of the time, there are some IR nodes where it must be stored explicitly (detailed above; for example where the SgTypeDefault is used and for SgCastExp, etc.). The function get_expression_type() is not a part of the user interface and users should call get_type() instead. ‐ Internal: This is a base class for all expressions. As a design point IPR has an empty expression, not an empty statement. And empty statement can be built as an expression statement with an empty expression (which IPR does have). We should consider having such an empty expression. Currently we have and expression statement with a null pointer (none too elegant). Sage III now has both a SgNullStatement and a SgNullExpression. ‐ Todo: Consider placing the VARARGS expression nodes into a common base class derived from SgExpression. ‐ Todo: I have removed the access functions from the explicit storage of type information in SgExpression objects as phase 1 of a 2 phase approach to eliminate the storage of the type in the SgExpression IR nodes. This type should be computed where required. This would avoid it being held redundently. This mechanism is being redone internally. Some IR nodes will have likely have to store there type explicaitly (function expressions for example, though it might be better computed through the symbol). It is not clear it this computing of the type will be better than stroing of the type explicitly. It might be required for SgBinaryOp IR nodes to store the type if it is not clearly from either the lhs or rhs (if no simple rule exists). ‐ Todo: SgScopeOp is deprecated and will be removed in a future version of ROSE. It is a hold over from support for CC++ which is not supported in SAGE III anymore. ‐ Todo: SgRefExp is deprecated and will be removed in a future version of ROSE. It is not used anywhere within SAGE III and I don't know why it is there. ‐ Todo: Need to find an example of where SgClassNameRefExp is used. It is build in the EDG/Sage III translation, but not in a way that it is obvious that it is still used within Sage III. So this may have to be removed at a latr date. ‐ Todo: To support Fortran parser we need an IR node which will represent the ambiguity of an array access or function call expression. These are then resolved within the AST after parsing (requires AST Fixup rule). ‐ Todo: Fortran support requires support for function call using: "foo(temp=*<label>)" this might force the development of a label expression to support this. Code using this compiles with Flang, so it appears to be F90. ‐ See also: Example of using a SgExpression object
Data members
#### SgExpression::p_lvalue This boolean variable marks the current expression as a left hand side value (lvalue). ‐ Deprecated: This computation of this value is innacurate. It identifies expressions which have been assigned to. This does not include all lvalues as defined by the C++ standard. For "int* p", "*p" and "&p" are both lvalues, despite not being assigned to (section 3.10).
#### SgExpression::p_need_paren This boolean value marks the current expression as requiring parenthises. This boolean value marks the current expression as requiring parenthises (the information comes from the frontend's interpretation of the requirement and is almost always overly conservative. The unparser currently backs out more accurate rules based on operator precedence and removed then where they are not truely required. Thus the purpose of this variable is to capture the interpritation of the frontend regarding the use of parenthesis.
Member functions
#### SgExpression::SgExpression ( Sg_File_Info* startOfConstruct = NULL ) This is the constructor. This constructor builds the SgExpression base class. ‐ Param startOfConstruct: represents the position in the source code ‐ See also: Example:create an SgExpression object
#### SgExpression::~SgExpression() This is the destructor. Only the Sg_File_Info object can be deleted in this object.
#### SgExpression::isSgExpression (SgNode *s) Cast function (from derived class to SgExpression pointer). This functions returns a SgExpression pointer for any input of a pointer to an object derived from a SgExpression. ‐ Return: Returns valid pointer to SgExpression if input is derived from a SgExpression.
#### SgExpression::isSgExpression (const SgNode *s) Cast function (from derived class to SgExpression pointer). This functions returns a SgExpression pointer for any input of a pointer to an object derived from a SgExpression. ‐ Return: Returns valid pointer to SgExpression if input is derived from a SgExpression.
#### SgExpression::get_need_paren (void) const returns bool value if front‐end considers parenthesis to be required. This function returns a boolean value which is true if parenthesis are required for the proper eveluation of the current expression. The frontend is however overly conservative and introduces parenthesis too often. The value as determined by the frontend is saved in the SAGE III AST because it is sometimes required for more complex expressions and contructor calls with initializers. At present the unparser applies operator precedence rules to eliminate some of the redundent parenthesis within expressions (this makes the output more appealing). ‐ Return: Returns bool value (true if parenthesis are needed around the expression).
#### SgExpression::set_need_paren (bool need_paren) This function allows the p_need_paren flag to be set (used internally). This function is mostly used internally but would required for the construction of specific expression trees where the operator precedence would be insufficent to generate the correct code (which si the purpose of adding parenthesis in source code). ‐ Param need_paren: ‐ sets value of internal p_need_paren flag (true if parenthesis are needed around the expression). ‐ Return: Returns void.
#### SgExpression::get_lvalue (void) const Returns a bool value if the current expression is assigned to. ‐ Deprecated: The computation of this value is innacurate in terms of the lvalue as defined by the standard. It identifies expressions which have been assigned to. This does not include all lvalues as defined by the C++ standard. For "int* p", "*p" and "&p" are both lvalues, despite not being assigned to (section 3.10). See SgExpression::p_lvalue. ‐ Return: Returns true if the current expression is assigned to.
#### SgExpression::set_lvalue (bool lvalue) This function allows the p_lvalue flag to be set (used internally). This function is mostly used internally but would required for the construction of specific expression trees. In general it is set by the frontend, but not used elsewhere within SAGE III (will be tested in the future). ‐ Param lvalue: ‐ sets value of internal p_lvalue flag (true if the current is to be a left hand side value (lvalue)). ‐ Return: Returns void.
#### SgExpression::isDefinable (void) const For Fortran. When called from a node of any other language, behavior is undefined (see SageInterface::is_Fortran_language). Returns a bool value which is true if the current expression is "almost definable". "Almost definable" here means as defined by the Fortran standard (2.5.5), with the caveat that allocatable variables are always called an lvalue. The Fortran standard dictates that an allocatable variable which has not been allocated is not definable. In the general case, it cannot be statically determined whether an allocatable variable has been allocated or not. Note: constants in Fortran are not lvalues, while in C and C++ lvalues may be const. ‐ Return: Returns true if the current expression is almost definable.
#### SgExpression::isUsedAsDefinable (void) const For Fortran. When called from a node of any other language, behavior is undefined (see SageInterface::is_Fortran_language). Returns a bool value which is true if the current expression is used as a definable value. That is, it is definable (assigned to). ‐ Return: Returns true if the current expression is used as a definable value.
#### SgExpression::isLValue (void) const For C and C++. When called from a node of any other language, behavior is undefined (see SageInterface::is_C*_language). Returns a bool value which is true if the current expression is an lvalue, as defined by the C++ standard. ‐ Return: Returns true if the current expression is an lvalue.
#### SgExpression::isUsedAsLValue (void) const For C and C++. When called from a node of any other language, behavior is undefined (see SageInterface::is_C*_language). Returns a bool value which is true if the current expression is used as an lvalue. That is, it is an lvalue and does not get converted to an rvalue by its parent expression. ‐ Return: Returns true if the current expression is used as an lvalue.
#### SgExpression::isChildUsedAsLValue (SGExpression) const For C and C++. When called from a node of any other language, behavior is undefined (see SageInterface::is_C*_language). Returns a bool value which is true if the specified expression is used as an lvalue. That is, it is an lvalue and does not get converted to an rvalue by its parent expression. ‐ Internal: For use by children calling their parents. ‐ Return: Returns true if the specified expression is used as an lvalue.
#### SgExpression::get_type() const Get the type associated with this expression. This function is the correct user function to call to get the type (note that get_expression_type() is for internal use only). ‐ Return: Returns pointer to SgType (base class for all possible types)
#### SgExpression::set_type() Set the type associated with this expression This is an internally call function, it sets up the type of the expression based upon the types of the subexpressions (if any). Thus it takes no arguments. ‐ Return: Returns void
#### SgExpression::get_expression_type() const FOR INTERNAL USE Data access function for explicitly stored type. This access function is used internally to access explicitly stored types (where it is required to be stored). Currently a larger number of IR nodes have this data member than where it is explicitly required, this will be fixed in the future. Where used, this function can return NULL if the explicitly stored p_expression_type variable is not needed (this is to support it later being removed). ‐ Return: Returns pointer to SgType (base class for all possible types)
#### SgExpression::set_expression_type() FOR INTERNAL USE Data access function for explicitly stored type. This function is only meaningful where the type is explicitly stored. It is an internally called function, it sets up the type of the expression based upon the types of the subexpressions (if any). Thus it takes no arguments. ‐ Return: Returns void
Created with MrDocs