SgNode¶
This class represents the base class for all IR nodes within Sage III.
Synopsis¶
Declared in <src/frontend/SageIII/Cxx_Grammar.h> (not stored in Git)
class [[visibility("default")]] SgNode; Description¶
This class is used as a base class for all IR nodes in Sage III.
-
Note: AST attributes should not be used for the following IR nodes:
-
SgName
-
SgModifier (and all derived modifier IR nodes)
-
SgUnparse_Info
-
SgSymbolTable
- Internal: Need to remove unused error() and variant() functions.
- Todo: Consider eliminating the set_freepointer() function since only the internal memory allocation mechanisms should use it (and they are forced to access the data member directly since they traverse the memory pools directly and member function can onl be called on allocated object initialized vi the new operator (with a proper constructor call, so that the this pointer is set properly)). Perhaps we don't need access functions for this data member at all.
- See also: Example of using a SgNode object
- See also: Enforced AST Properties
Data members
SgNode::p_parent¶
This is the pointer to the parent IR node in the AST. Owning AST edges have reciprocal parent links when the producer publishes the node. Semantic references to shared types and declarations are distinct from owning edges; a reference does not reparent its target. Symbols belong to their symbol tables.
SgNode::p_freepointer¶
This is the pointer to the chain of previously freed objects.
- Internal: This is part of the support for memory pools within ROSE. The freepointer is only manipulated by the delete operator which constructs a chain of previously freed objects embedded within the memory pools. The chain of objects link by the freepointer variables are traversed by the new operator to allocate (reuse) previously deleted objects. The new operator does not reset the freepointers since once allocated the freepointer is ignored.
SgNode::p_isModified¶
Records if IR node has been modified (data members reset). This is part of an internal mechanism that records if IR nodes have been modified, either by a transformation or a access function to set a value on the IR node. All access functions that set IR node data members are automatically generated (except the ones for this data member) and include code to set this boolean flag to true. This is also part of the support for copy based code generation where source file is copied except where the AST was modified an for these subtrees new code is generated from the AST.
- Internal: true if IR node has been modified, else false.
SgNode::p_globalFunctionTypeTable¶
Pointer to symbol table specific to function types.
- Internal: Always a valid pointer.
SgNode::p_globalMangledNameMap¶
Cache of mangled names to avoid regeneration of previously build mangled names or parts of mangled names. This is a performance optimization.
- Internal: This cache should be cleared automatically where required.
SgNode::p_shortMangledNameCache¶
STL map used as a cache to shorten generated mangled names. This is mostly a space optimization ofr mangled names of templates.
- Internal: This cache should be cleared before regenerating mangled names.
Member functions
SgNode::copy(const SgCopyHelp & help ) const¶
This function clones the current IR node object recursively or not, depending on the argument This function performs a copy based on the specification of the input parameter. The input parameter is used to determin which data members are copied by reference and which are copied by value.
- Param
help: - If this argument is of type SgTreeCopy, then the IR node is cloned recursively. If its of type SgShallowCopy only the first level of the IR node is copied, everything else is left pointing to the the original IR node's object's data members. - Return: a pointer to the new clone. Copy construction establishes the copied owning edges before publication. Shared semantic identities remain references according to SgCopyHelp's copy policy. AstPostProcessing does not repair missing ownership in a copy.
SgNode::SgNode()¶
This is the constructor This constructor builds a SgNode, always used as a base class. All Sage III IR nodes are derived from this class.
- See also: Example:create an SgNode object
SgNode::sage_class_name() const¶
generates string representing the class name: (e.g. for SgNode returns "SgNode"). This function is useful for debugging and error reporting. It returns the name of the IR node.
- Deprecated: Use class_name() which returns a C++ string object.
- Return: a char* pointer to a C style string.
string SgNode::class_name() const¶
generates string representing the class name: (e.g. for SgNode returns "SgNode"). This function is useful for debugging and error reporting. It returns the name of the IR node.
- Return: a C++ string object.
SgNode::variant() const¶
Older version function returns enum value "NODE" This function is an older version of the variant function. This function is useful for debugging and error reporting. It returns the name of the IR node.
- Return: an int value.
- Deprecated: Use variantT() instead. Older enum values have inconsistant names and are being removed.
SgNode::variantT() const¶
returns enum value "V_SgNode" This function is useful for debugging and error reporting. It returns the name of the IR node. Once the variant() function is removed this function will be deprecated and replaced by a new function named "variant()". The new "variant()" function will return the new enum type (with consistant naming convention in place). The name of the enum type might be changed to make it more clear.
- Return: an enum value (type: VariantT).
SgNode::get_isModified() const¶
FOR INTERNAL USE All nodes in the AST contain a isModified flag. This flag can be set but this is typically an internal function used to track the updates to AST.
- Return: Returns bool; true if IR node has been modified.
SgNode::set_isModified(bool isModified)¶
Acess function for isModified flag. This flag records if the current IR node has been modified. It is set to false after and ROSE front-end processing.
SgNode::set_parent (SgNode *parent)¶
Sets parent node for any IR node. The parent node in the AST can be set but this is typically an internal function used to build the AST.
- Param
parent: - Pointer to parent node to store within the current IR node. - Return: returns void.
SgNode::get_parent() const¶
Access function for parent node in AST. Returns the structural owner established during construction. Shared semantic references do not change the referenced node's parent. Semantic scope is represented separately where it differs from structural ownership.
- Return: Returns pointer to SgNode
SgNode::unparseToString( SgUnparse_Info* info )¶
This function unparses the AST node (source code only, excluding comments and white space)
- Param
info: is optional (used only to specify code generation options). This function is useful for debugging. It uses SgUnparse_Info as an inherited attribute internally and using this attribute it will correctly handled many subtle details that will be ignored if the attribute is not provided. For example, the SgUnparse_Info can record if the statement is in a conditional and if so then the trailing ";" will be omitted in the generated code. See the SgUnparse_Info documentation for the numerous other internal settings that can effect the generated code. Because of these details, the unparseToString() function can not always be used to generate compiliable code. - Return: Returns std::string
SgNode::unparseToCompleteString()¶
This function unparses the AST node (including comments and white space) This function is a complement to the unparseToString() function and includes any associated comments and preprocessor control directives. Because C preprocessor control directives can be included, the resulting string may not be a complete translation unit.
- Todo: This function needs a better name since it is unclear what the "complete" string is.
- Return: Returns std::string
SgNode::get_traversalSuccessorContainer()¶
FOR INTERNAL USE within ROSE traverals mechanism only. This function builds and returns a copy of ordered container holding pointers to children of this node in a traversal. It is associated with the definition of a tree that is travered by the AST traversal mechanism; a tree that is embeded in the AST (which is a more general graph). This function is used within the implementation of the AST traversal and has a semantics may change in subtle ways that makes it difficult to use in user code. It can return unexpected data members and thus the order and the number of elements is unpredicable and subject to change.
- Warning: This function can return unexpected data members and thus the order and the number of elements is unpredicable and subject to change.
- Return: Returns ordered STL Container of pointers to children nodes in AST.
SgNode::get_traversalSuccessorNamesContainer()¶
FOR INTERNAL USE within ROSE traverals mechanism only. This function builds and returns a copy of ordered container holding strings used to name data members that are traversed in the IR node. It is associated with the definition of a tree that is travered by the AST traversal mechanism; a tree that is embeded in the AST (which is a more general graph). This function is used within the implementation of the AST traversal and has a semantics may change in subtle ways that makes it difficult to use in user code. It can return unexpected data members and thus the order and the number of elements is unpredicable and subject to change.
- Warning: This function can return unexpected data members and thus the order and the number of elements is unpredicable and subject to change. Each string is a name of a member variable holding a pointer to a child in the AST. The names are the same as used in the generated enums for accessing attributes in a traversal. The order is the same in which they are traversed and the same in which the access enums are defined. Therefore this method can be used to get the corresponding name (string) of an access enum which allows to produce more meaningful messages for attribute computations.
- Return: Returns ordered STL container of names (strings) of access names to children nodes in AST.
SgNode::roseRTI ()¶
FOR INTERNAL USE Access to Runtime Type Information (RTI) for this IR nodes. This function provides runtime type information for accessing the structure of the current node. It is useful for generating code which would dump out or rebuild IR nodes.
- Return: Returns a RTIReturnType object (runtime type information).
Types¶
| Name |
|---|
PoolEntry |
PoolResetter |
SourceStateConstruction |
Enums¶
| Name | Description |
|---|---|
Unnamed enum | static variant value |
Member Functions¶
| Name | Description |
|---|---|
SgNodeSgNode(); [constructor] | Default constructor |
~SgNodevirtual ~SgNode(); [destructor] [virtual] | Destructor |
acceptvirtual void accept(ROSE_VisitorPattern& visitor); [virtual] | support for the classic visitor pattern done in GoF |
addNewAttributevirtual void addNewAttribute( std::string s, AstAttribute* a); [virtual] | Add a new attribute represented by the named string. |
appendDestructorOwnedNodesvirtual void appendDestructorOwnedNodes(std::vector<SgNode*>& nodes) const; [virtual] | |
attributeExistsvirtual bool attributeExists(std::string s) const; [virtual] | Tests if attribute of name 's' is present. |
cfgFindChildIndexvirtual unsigned int cfgFindChildIndex(SgNode* n); [virtual] | Find the index of n in this node's CFG children. |
cfgFindNextChildIndexvirtual unsigned int cfgFindNextChildIndex(SgNode* n); [virtual] | Find the index just after n in this node's CFG children. |
cfgForBeginningVirtualCFG::CFGNode cfgForBeginning(); | Returns the CFG node for just before this AST node |
cfgForEndVirtualCFG::CFGNode cfgForEnd(); | Returns the CFG node for just after this AST node |
cfgInEdgesvirtual std::vector<VirtualCFG::CFGEdge> cfgInEdges(unsigned int index = false); [virtual] | Find the in edges of a CFG node -- internal version. |
cfgIndexForEndvirtual unsigned int cfgIndexForEnd() const; [virtual] | Determine the CFG index for the end of this construct. |
cfgIsIndexInterestingvirtual bool cfgIsIndexInteresting(unsigned int index) const; [virtual] | Determine whether a particular CFG node index is "interesting" for this kind of node. |
cfgOutEdgesvirtual std::vector<VirtualCFG::CFGEdge> cfgOutEdges(unsigned int index = false); [virtual] | Find the out edges of a CFG node -- internal version. |
class_namevirtual std::string class_name() const; [virtual] | returns a string representing the class name |
copyvirtual SgNode* copy(SgCopyHelp& help) const; [virtual] | |
depthOfSubtreeint depthOfSubtree(); | Computes the depth of the current defined subtree of the AST. |
fixupCopy_referencesvirtual void fixupCopy_references( SgNode* copy, SgCopyHelp& help) const; [virtual] | |
fixupCopy_scopesvirtual void fixupCopy_scopes( SgNode* copy, SgCopyHelp& help) const; [virtual] | |
fixupCopy_symbolsvirtual void fixupCopy_symbols( SgNode* copy, SgCopyHelp& help) const; [virtual] | |
getAttributevirtual AstAttribute* getAttribute(std::string s) const; [virtual] | Returns attribute of name 's'. |
get_ast_json_node_iduint64_t get_ast_json_node_id() const; | |
get_attributeMechanismvirtual AstAttributeMechanism* get_attributeMechanism() const; [virtual] | FOR INTERNAL USE Access function; if an attribute exists then a pointer to it is returned, else error. |
get_childIndexvirtual size_t get_childIndex(SgNode* child) const; [virtual] | index-based access to traversal successors by child node |
get_containsTransformationbool get_containsTransformation() const; | Acess function for containsTransformation flag |
get_endOfConstructvirtual Sg_File_Info* get_endOfConstruct() const; [virtual] | New function interface for Sg_File_Info data stores ending location of contruct (typically the closing brace). |
get_file_infovirtual Sg_File_Info* get_file_info() const; [virtual] | File information containing filename, line number, column number, and if the SgNode is a part of a new transformation, etc. |
get_freepointerSgNode* get_freepointer() const; | |
get_isModifiedbool get_isModified() const; | Acess function for isModified flag |
get_lastMutationSequenceuint64_t get_lastMutationSequence() const; | |
get_numberOfTraversalSuccessorsvirtual size_t get_numberOfTraversalSuccessors() const; [virtual] | return number of children in the traversal successor list |
get_parentSgNode* get_parent() const; | Access function for parent node. |
get_startOfConstructvirtual Sg_File_Info* get_startOfConstruct() const; [virtual] | New function interface for Sg_File_Info data stores starting location of contruct (typically the opening brace or first letter of keyword). |
get_traversalSuccessorByIndexvirtual SgNode* get_traversalSuccessorByIndex(size_t idx) const; [virtual] | index-based access to traversal successors by index number |
get_traversalSuccessorContainervirtual std::vector<SgNode*> get_traversalSuccessorContainer() const; [virtual] | container of pointers to AST successor nodes used in the traversal overridden in every class by generated implementation |
get_traversalSuccessorIsListElementvirtual std::vector<bool> get_traversalSuccessorIsListElement() const; [virtual] | |
get_traversalSuccessorNamesContainervirtual std::vector<std::string> get_traversalSuccessorNamesContainer() const; [virtual] | container of names of variables or container indices used used in the traversal to access AST successor nodes overridden in every class by generated implementation |
isChildbool isChild(SgNode* node) const; | Query function for if the input IR nodes is a child of the current IR node. |
isUnderConstructionbool isUnderConstruction() const; | |
markAsModifiedvoid markAsModified(); | Records that this node was mutated. |
markSourceMetadataAsModifiedvoid markSourceMetadataAsModified(); | |
numberOfAttributesvirtual int numberOfAttributes() const; [virtual] | Returns the number of attributes on this IR node. |
numberOfNodesInSubtreeint numberOfNodesInSubtree(); | Computes the number of nodes in the defined subtree of the AST. |
operator deletevoid operator delete( void* pointer, size_t size); | deallocated memory for IR node (returns memory to memory pool for reuse) |
operator newvoid* operator new(size_t size); | returns pointer to newly allocated IR node |
processDataMemberReferenceToPointersvirtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler*); [virtual] | Pass references to stored node pointers to a handler. |
removeAttributevirtual void removeAttribute(std::string s); [virtual] | Remove attribute of name 's' if present. |
returnDataMemberPointersvirtual std::vector<std::pair<SgNode*, std::string>> returnDataMemberPointers() const; [virtual] | Return the node pointers stored in this node's data members. |
roseRTIvirtual RTIReturnType roseRTI(); [virtual] | return C++ Runtime-Time-Information |
sage_class_namevirtual char const* sage_class_name() const; [virtual] | returns a C style string (char*) representing the class name |
setAttributevirtual void setAttribute( std::string s, AstAttribute* a); [virtual] | This is a wrapper function with the following semantics: if no attribute of name 's' exists then addNewAttribute(s,a); is called, otherwise updateAttribute(s,a); is called. |
set_ast_json_node_idvoid set_ast_json_node_id(uint64_t id); | |
set_attributeMechanismvirtual void set_attributeMechanism(AstAttributeMechanism* a); [virtual] | FOR INTERNAL USE Access function; sets poiner to value AstAttributeMechanism. |
set_containsTransformationvoid set_containsTransformation(bool containsTransformation); | Many nodes can hide other AST nodes and we need to track when outer nodes contain modified nodes even if they are not themselves modified. |
set_freepointervoid set_freepointer(SgNode* freepointer); | |
set_isModifiedvoid set_isModified(bool isModified); | All nodes in the AST contain a isModified flag used to track changes to the AST. |
set_parentvoid set_parent(SgNode* parent); | All nodes in the AST contain a reference to a parent node |
unparseToCompleteStringstd::string unparseToCompleteString(); | This function unparses the AST node (including comments and white space) |
unparseToStringstd::string unparseToString() const; | This function unparses the AST node (excluding comments and unnecessary white space) |
updateAttributevirtual void updateAttribute( std::string s, AstAttribute* a); [virtual] | Replace existing attribute of name 's' with new AstAttribute. |
variantint variant() const; | |
variantTvirtual VariantT variantT() const; [virtual] | returns new style SageIII enum values |
Static Member Functions¶
| Name | Description |
|---|---|
clearGlobalMangledNameMapstatic void clearGlobalMangledNameMap(); | Support to clear the performance optimizing global mangled name map. |
clearMemoryPoolstatic void clearMemoryPool(); | |
getClassHierarchySubTreeFunctionstatic std::vector<VariantT> getClassHierarchySubTreeFunction(VariantT v); | |
get_globalAstModificationSequencestatic uint64_t get_globalAstModificationSequence(); | Returns a process-wide sequence that advances whenever ROSE records an AST modification. |
get_globalFunctionTypeTablestatic SgFunctionTypeTable* get_globalFunctionTypeTable(); | Access function for symbol table specific to function types. |
get_globalMangledNameMapstatic SgUnorderedMapNodeToString& get_globalMangledNameMap(); | Access function for performance optimizing global mangled name map. |
get_globalTypeTablestatic SgTypeTable* get_globalTypeTable(); | Access function for symbol table specific to non-function types. |
get_shortMangledNameCachestatic std::map<std::string, uint64_t>& get_shortMangledNameCache(); | Access function for lower level optimizing of global mangled name map. |
initializeAstTeardownstatic void initializeAstTeardown(); | |
isLiveNodestatic bool isLiveNode(SgNode const* node); | |
memoryUsagestatic size_t memoryUsage(); | Returns the size in bytes of the total memory allocated for all IR nodes of this type |
numberOfNodesstatic size_t numberOfNodes(); | Returns the total number of IR nodes of this type |
set_globalFunctionTypeTablestatic void set_globalFunctionTypeTable(SgFunctionTypeTable* globalFunctionTypeTable); | Access function for symbol table specific to function types. |
set_globalTypeTablestatic void set_globalTypeTable(SgTypeTable* globalTypeTable); | Access function for symbol table specific to non-function types. |
traverseMemoryPoolNodesstatic void traverseMemoryPoolNodes(ROSE_VisitTraversal& visit); | FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node. |
traverseMemoryPoolVisitorPatternstatic void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern& visitor); | FOR INTERNAL USE Support for visitor pattern. |
variantFromPoolstatic VariantT variantFromPool(SgNode const* n); | |
visitRepresentativeNodestatic void visitRepresentativeNode(ROSE_VisitTraversal& visit); | FOR INTERNAL USE Support for type-based traversal. |
Static Data Members¶
| Name | Description |
|---|---|
free_slots | Free slots, each numbered pool_index * pool_size + slot_index. The last entry is allocated next. |
pool_live_flags | |
pool_size | |
pools |
Protected Member Functions¶
| Name | Description |
|---|---|
post_construction_initializationvirtual void post_construction_initialization(); [virtual] | Final initialization for constructors This function is called at the end of generated constructors to allow the specification writer to add special initialization functions or tests. Default is to do nothing. Otherwise it should be overridden in the spec file, in NewHeaderCode/NewOutlinedCode. |
Protected Static Member Functions¶
| Name | Description |
|---|---|
allPoolsstatic std::vector<PoolEntry>& allPools(); | |
appendOwnedAstNodetemplate<class T> static void appendOwnedAstNode( std::vector<SgNode*>& nodes, std::vector<T*> const& objects); | |
destroyOwnedDatatemplate<class T> static void destroyOwnedData(std::vector<T*>& objects); | ROSETTA destructor support for fields declared DEF_DELETE. Shared AST teardown can already have released a pooled node; ordinary owned objects obey C++ delete semantics and must not be discarded by a type-name filter. |
findPoolEntrystatic PoolEntry const* findPoolEntry(unsigned char const* ptr); |
Protected Data Members¶
| Name |
|---|
p_ast_json_node_id |
p_constructionEpoch |
p_containsTransformation |
p_freepointer |
p_isModified |
p_lastMutationSequence |
p_parent |
Protected Static Data Members¶
| Name |
|---|
p_globalFunctionTypeTable |
p_globalMangledNameMap |
p_globalTypeTable |
p_shortMangledNameCache |
Private Member Functions¶
| Name | Description |
|---|---|
operator=SgNode& operator=(SgNode const& other) = delete; [deleted] | Delete operator= (to avoid it being used) |
Friends¶
| Name | Description |
|---|---|
isSgNode | Casts pointer from base class to derived class (for const pointers) |
isSgNode | Casts pointer from base class to derived class |
Derived Classes¶
| Name | Description |
|---|---|
SgCxxArrayInitBinding | |
SgLocatedNode | This class represents the notion of an expression or statement which |
SgSupport | This class represents the base class of a numbr of IR nodes that don't otherwise fit |
SgSymbol | This class represents the concept of a name within the compiler. |
SgType | This class represents the base class for all types. |
Created with MrDocs