SgDeclarationStatement¶
This class represents the concept of a declaration statement.
Synopsis¶
Declared in <src/frontend/SageIII/Cxx_Grammar.h> (not stored in Git)
class [[visibility("default")]] SgDeclarationStatement
: public SgStatement Description¶
Declaration statements are where variables and types are defined and become available for use within a program. Declarations are strored in symbols (SgSymbol) and used to associate the symbol with a location within a scope within the application source code. There are many different types of declarations, within Sage III the SgDeclaration forms a base class for numerous IR nodes such as: class declarations (including structs and unions), enum declarations, function declarations, namespace declarations, pragma declarations, template declarations, typedef declarations, using declarations, using directives, variable declarations, etc. A declaration family records its canonical first nondefining declaration and its defining declaration, when one exists. Multiple nondefining declarations can refer to the same entity.
- Todo: Current issues to look at:
- Current classes derived from SgDeclarationStatement and the SgInitializedName class have ways of generating names, qualified names, and mangled names, but we lack a uniform mechanism to generate mangled qualified names. The implementation is not uniform within the IR and this is a problem for applications which must generate unique names for C++ constructs. Specific to functions names:
-
We have:
-
get_name()
-
get_qualified_name()
-
get_mangled_name()
-
While we need (on ALL SgDeclarationStatement IR nodes):
-
get_name()
-
get_qualified_name()
-
get_mangled_name()
-
get_qualified_mangled_name()
-
It has been suggested that we eliminate get_qualified_mangled_name() and have get_mangled_name() return a mangled qualified name. Thus the semantics of get_mangled_name() would be changed to generate a mangled qualified name. The purpose of get_mangled_name is to generate a unique name for all declarations. Note that some declarations should not return a unique name:
-
SgAsmStmt
-
SgCtorInitializerList
-
SgFunctionParameterList
-
SgUsingDeclarationStatement
-
SgVariableDefinition It may be that this should be the same as for the SgVariableDeclaration.
- Related to the above problem we wish to provide a definition under which all declarations (SgDeclarationStatement IR nodes) can be defined to be unique. Under One-time Definition Rule (ODR) definitions must be the same within a linked application (in each compilation unit). We define a unique name for a declaration IR node as:
- Any declaration which matches another declaration under ODR must generate the same unique string.
- Any two declarations that are different must generate different unique strings.
- Important cases are:
- The IR nodes for which there is an obvious mangled name (and a get_mangled_name() exists) are:
- SgClassDeclaration
- SgFunctionDeclaration
- SgEnumDeclaration
- SgNamespaceDeclarationStatement
- SgTypedefDeclaration
- IR nodes for which it is less obvious (or for which there is no present get_mangled_name() member function) are:
- SgAsmStmt
- SgCtorInitializerList
- SgFunctionParameterList
- SgNamespaceAliasDeclarationStatement
- SgPragmaDeclaration
- SgTemplateDeclaration (can this have a mangled name?)
- SgTemplateInstantiationDirectiveStatement
- SgUsingDeclarationStatement
- SgUsingDirectiveStatement
- SgVariableDeclaration
- SgVariableDefinition
- Other IR nodes (not derived from SgDeclarationStatement) but for which we need to generate mangled names (and a get_mangled_name() member functions exists) are:
- SgTemplateArgument
- SgFunctionDefinition
- SgNamespaceDefinitionStatement
- SgClassDefinition
- SgType (and all IR nodes derived from SgType)
- Other IR nodes (not derived from SgDeclarationStatement) but for which I think we need to generate mangled names (and a get_mangled_name() member functions does NOT exist) are:
- SgInitializedName
- SgFile (this might not really be required, but it might make sense)
- SgDirectory (this might not really be required, but it might make sense)
- SgBaseClass (this is questionable)
- Class declarations often point to their definition independently of if they are defining or non-defining declaration (true at least for SgTemplateInstantiationDecl objects). This is different from how function declarations are handled, where only the defining declaration has a valid pointer to the function definition. This should be made more consistant. There are more comments about this is the documentation for SgTemplateInstantiationDecl.
- The specification of "extern" is not the same as extern "C", one is handled in the SgDeclarationStatement (extern "C") and the other is handled in the SgStorageModifier (extern). It is confusing that the two are so far a part. Perhaps they could be together so that setting "C" linkage could declare a SgDeclarationStatement as "extern" at the same time. It makes no sense to have something marked as "C" linkage and have it not be extern (I think); so this could be considered an error (I think).
- To support debugging of applications using the mangled names to build unique strings we should provide a global map between the unique names and the associated declarations. This would avoid the creation of alternative name mangling mechanisms whose sole purpose it to fold into the mangled name debugging information.
- Test: To test the mangled name generation we should construct a program using the mangled names and compile it to verify uniquenss of the veriable names. Since functions of the same name can be repeated, mangled names from functions should generate functions in the test program and mangled names of veriables should generate variables, etc.
- See also: Example of using a SgDeclarationStatement object
Data members
SgDeclarationStatement::p_definingDeclaration¶
This pointer is valid only if a defining declaration exists, and stores the defining declaration where the declaration was defined. It is important to note that this is the only defining declaration as opposed to the non-defining declarations (where there can, depending on IR node, often be many).
- Internal: The value held is not shared within the Sage III AST (except though this data member in each defining and non-defining declaration).
SgDeclarationStatement::p_firstNondefiningDeclaration¶
This pointer is valid if there is a non-defining declaration, and stores the first non-defining declaration where a declaration was made explicitly (as in forward declaration) or implicitly as in the case of a few IR nodes (e.g. SgClassDeclaration). See description of SgDeclarationStatement. It is important to note that this is the first non-defining declaration as opposed to the defining declaration. Thus it is usually the first forward declaration.
- Internal: The value held is sharable across many references where as the defining declaration (not held by this variable) should have one unique reference within the AST, except where reference though the declarations definingDeclaration data member pointer. See declarations for details (SgDeclarationStatements).
SgDeclarationStatement::p_linkage¶
This string stores the value "C", "C++", or "fortran" to define the external linkage for generating linkable names. The only values that make sense here are "C", "C++" is the assumed default and requires a NULL pointer value. And the use of "fortran" would be backend specific (may be rejected by some backend vendor compilers).
SgDeclarationStatement::p_declarationModifier¶
This is the mechanism to handle declaration modifiers. See Stroustrup 3rd edition, Appendix A, for details of how modifiers are represented in ROSE.
- Internal: There is no interface to declaration modifiers implemented directly in this SgDeclarationStatement class. This was done to simplify the implementation. Users are expected to access the SgDeclarationmodifier object (returned by reference) directly to get/set its values.
SgDeclarationStatement::p_nameOnly¶
When set on a variable declaration, get_next does not traverse its base-type declaration links.
SgDeclarationStatement::p_forward¶
This marks a declaration as being an explicit forward declaration. All non-defining declaations are marked as forward declarations, while a defining declaration is NOT a marked as a forward declaration.
- Internal: It is not clear enough to just use defining vs. nondefining declarations to know when something is a forward declaration!
SgDeclarationStatement::p_externBrace¶
This marks that the declaration appeared with "extern". Note that I think this is also set even if it appears between "extern {" and "}". It might be that this is a way to specify the first "extern {", but I don't think it is used interanlly and it is not clear if attaching the "extern {" to a declaration is a great way to handle this problem generally (appears to be overlly sensative to transformations that would add, remove, or move declarations (e.g in inlining and outlining transformations). Currently the lex pass saves all "extern "C" {" declarations and treats them as CPP directive (along with comments), they are then woven back into the AST as a separate pass.
- Deprecated: This is now redundant with the seperate preprocessing phase.
- Internal: Not sure that we need or want this mechanism (or this implementation of it). Not that the mechanism that we have is better and based on the scanning for extern "X" in the source code directly (where "X" is either "C", "C++", or "fortran".
SgDeclarationStatement::p_skipElaborateType¶
This marks "type elaboration" which is the use of the keyword "class" before variables of type class. This is not often required, but is routinely output by the unparser to be conservative. The support for hidden lists allows the unparser to more precisely output the type elaboration, and so this variable is redundant.
- Deprecated: This is now redundant with the hidden list analysis done to support more accurate code generation.
- Internal: This field is used in a default mode and could be set to be more accurate.
SgDeclarationStatement::p_need_name_qualifier¶
This marks a declaration are requiring qualification in its output in the unparser.
- Deprecated: This is now redundant with the hidden list analysis done to support more accurate code generation.
- Internal: Although this variable is specific to unparing, I think it may be required. Although the name qualifications were recently reimplemented to be more uniform and robust I'm not clear if this variable is a part of that new implementation (and thus required).
Member functions
SgDeclarationStatement::get_declarationModifier()¶
Returns SgDeclarationModifier object by reference (so that it can be set).
- Return: Returns SgDeclarationModifier by reference.
SgDeclarationStatement::isForward() const¶
Returns boolean value indicating if this is a forward declaration.
- Return: Returns bool.
SgDeclarationStatement::setForward()¶
Marks a declaration as a forward declaration.
- Return: Returns void.
SgDeclarationStatement::unsetForward()¶
Marks a forward declaration as a non-forward declaration.
- Return: Returns void.
SgDeclarationStatement::get_definingDeclaration() const¶
This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see that variable's documentation for details).
`SgDeclarationStatement::set_definingDeclaration(¶
SgDeclarationStatement* definingDeclaration )` This is an access function for the SgDeclarationStatement::p_definingDeclaration data member (see that variable's documentation for details).
SgDeclarationStatement::get_firstNondefiningDeclaration() const¶
This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member (see that variable's documentation for details).
`SgDeclarationStatement::set_firstNondefiningDeclaration(¶
SgDeclarationStatement* firstNondefiningDeclaration )` This is an access function for the SgDeclarationStatement::p_firstNondefiningDeclaration data member (see that variable's documentation for details).
SgDeclarationStatement::get_symbol_from_symbol_table() const¶
FOR INTERNAL USE Get the associated symbol from the symbol table in the stored scope. Users should use the SgDeclarationStatement::search_for_symbol_from_symbol_table() instead.
SgDeclarationStatement::search_for_symbol_from_symbol_table() const¶
User interface for retrieving the associated symbol from the declaration.
- Return: Returns SgSymbol pointer.
Base Classes¶
| Name | Description |
|---|---|
SgStatement | This class represents the notion of a statement. |
Type Aliases¶
| Name |
|---|
base_node_type |
Enums¶
| Name | Description |
|---|---|
Unnamed enum | static variant value |
ast_json_external_role_enum | Semantic provenance of declarations reconstructed outside a JSON file's owned AST. A source path is text; the declaration role is typed state. |
template_specialization_enum | Template Specialization Support |
Member Functions¶
| Name | Description |
|---|---|
SgDeclarationStatementSgDeclarationStatement(); [constructor] | Constructors |
~SgDeclarationStatementvirtual ~SgDeclarationStatement(); [destructor] [virtual] | Destructor |
acceptvirtual void accept(ROSE_VisitorPattern& visitor) override; [virtual] | support for the classic visitor pattern done in GoF |
appendDestructorOwnedNodesvirtual void appendDestructorOwnedNodes(std::vector<SgNode*>& nodes) const override; [virtual] | |
class_namevirtual std::string class_name() const override; [virtual] | returns a string representing the class name |
clear_translation_unit_source_order_for_transformationvoid clear_translation_unit_source_order_for_transformation(); | End source-token ownership when this declaration becomes a transformation. A transformed declaration is ordered by its new structural owner, not by the frontend occurrence from which it may have been copied. |
copyvirtual SgNode* copy(SgCopyHelp& help) const override; [virtual] | |
fixupCopy_referencesvirtual void fixupCopy_references( SgNode* copy, SgCopyHelp& help) const override; [virtual] | |
fixupCopy_scopesvirtual void fixupCopy_scopes( SgNode* copy, SgCopyHelp& help) const override; [virtual] | |
fixupCopy_symbolsvirtual void fixupCopy_symbols( SgNode* copy, SgCopyHelp& help) const override; [virtual] | |
get_alignment_specifiersSgAlignmentSpecifierPtrList const& get_alignment_specifiers() const; | |
get_ast_json_external_roleast_json_external_role_enum get_ast_json_external_role() const; | |
get_ast_json_external_source_filestd::string const& get_ast_json_external_source_file() const; | |
get_binding_cdefinedbool get_binding_cdefined() const; | |
get_binding_labelstd::string get_binding_label() const; | |
get_binding_label_presentbool get_binding_label_present() const; | |
get_childIndexvirtual size_t get_childIndex(SgNode* child) const override; [virtual] | index-based access to traversal successors by child node |
get_declarationModifierSgDeclarationModifier const& get_declarationModifier() const; | |
get_declarationScopeSgDeclarationScope* get_declarationScope() const; | |
get_definingDeclarationSgDeclarationStatement* get_definingDeclaration() const; | |
get_externBracebool get_externBrace() const; | |
get_firstNondefiningDeclarationSgDeclarationStatement* get_firstNondefiningDeclaration() const; | |
get_forwardbool get_forward() const; | |
get_linkagestd::string get_linkage() const; | |
get_mangled_namevirtual SgName get_mangled_name() const; [virtual] | |
get_nameOnlybool get_nameOnly() const; | |
get_nonreal_decl_scopeSgDeclarationScope* get_nonreal_decl_scope() const; | |
get_numberOfTraversalSuccessorsvirtual size_t get_numberOfTraversalSuccessors() const override; [virtual] | return number of children in the traversal successor list |
get_scopevirtual SgScopeStatement* get_scope() const override; [virtual] | |
get_skipElaborateTypebool get_skipElaborateType() const; | |
get_source_declarator_scopeSgDeclarationScope* get_source_declarator_scope() const; | |
get_source_name_global_qualificationbool get_source_name_global_qualification() const; | |
get_source_name_qualification_presentbool get_source_name_qualification_present() const; | |
get_source_name_qualification_tokensSgStringList const& get_source_name_qualification_tokens() const; | |
get_symbol_from_symbol_tablevirtual SgSymbol* get_symbol_from_symbol_table() const override; [virtual] | |
get_translation_unit_source_orderstd::optional<unsigned int> const& get_translation_unit_source_order() const; | Exact producer-wide lexical order when published by the frontend. Absence means this declaration has no ordered token producer. |
get_traversalSuccessorByIndexvirtual SgNode* get_traversalSuccessorByIndex(size_t idx) const override; [virtual] | index-based access to traversal successors by index number |
get_traversalSuccessorContainervirtual std::vector<SgNode*> get_traversalSuccessorContainer() const override; [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 override; [virtual] | |
get_traversalSuccessorNamesContainervirtual std::vector<std::string> get_traversalSuccessorNamesContainer() const override; [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 |
get_typeSgType* get_type() const; | |
get_unparse_template_astbool get_unparse_template_ast() const; | |
has_semantic_mangled_namebool has_semantic_mangled_name() const; | True only for declarations that denote an independently mangled semantic identity. Source-surface grouping declarations deliberately own no such identity and hard-reject get_mangled_name(). |
initialize_ast_json_external_provenancevoid initialize_ast_json_external_provenance( ast_json_external_role_enum role, std::string const& source_file); | |
initialize_translation_unit_source_ordervoid initialize_translation_unit_source_order(unsigned int source_order); | Initialize the exact translation-unit order once. Reinitialization is a malformed producer contract, including attempts to publish the same value. |
isExternBracebool isExternBrace() const; | |
isForwardbool isForward() const; | |
isNameOnlybool isNameOnly() const; | |
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 |
post_construction_initializationvirtual void post_construction_initialization() override; [virtual] | |
processDataMemberReferenceToPointersvirtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler*) override; [virtual] | Pass references to stored node pointers to a handler. |
returnDataMemberPointersvirtual std::vector<std::pair<SgNode*, std::string>> returnDataMemberPointers() const override; [virtual] | Return the node pointers stored in this node's data members. |
roseRTIvirtual RTIReturnType roseRTI() override; [virtual] | return C++ Runtime-Time-Information |
sage_class_namevirtual char const* sage_class_name() const override; [virtual] | returns a C style string (char*) representing the class name |
search_for_symbol_from_symbol_tableSgSymbol* search_for_symbol_from_symbol_table() const; | |
setExternBracevoid setExternBrace(); | |
setForwardvoid setForward(); | |
setNameOnlyvoid setNameOnly(); | |
setSkipElaborateTypevoid setSkipElaborateType(); | |
set_binding_cdefinedvoid set_binding_cdefined(bool binding_cdefined); | |
set_binding_labelvoid set_binding_label(std::string binding_label); | |
set_binding_label_presentvoid set_binding_label_present(bool binding_label_present); | |
set_declarationScopevoid set_declarationScope(SgDeclarationScope* declarationScope); | |
set_definingDeclarationvoid set_definingDeclaration(SgDeclarationStatement* definingDeclaration); | |
set_externBracevoid set_externBrace(bool externBrace); | |
set_firstNondefiningDeclarationvoid set_firstNondefiningDeclaration(SgDeclarationStatement* firstNondefiningDeclaration); | |
set_forwardvoid set_forward(bool forward); | |
set_linkagevoid set_linkage(std::string linkage); | |
set_nameOnlyvoid set_nameOnly(bool nameOnly); | |
set_nonreal_decl_scopevoid set_nonreal_decl_scope(SgDeclarationScope* nonreal_decl_scope); | |
set_scopevirtual void set_scope(SgScopeStatement* newScope) override; [virtual] | |
set_skipElaborateTypevoid set_skipElaborateType(bool skipElaborateType); | |
set_source_declarator_scopevoid set_source_declarator_scope(SgDeclarationScope* source_declarator_scope); | |
set_source_name_global_qualificationvoid set_source_name_global_qualification(bool source_name_global_qualification); | |
set_source_name_qualification_presentvoid set_source_name_qualification_present(bool source_name_qualification_present); | |
set_unparse_template_astvoid set_unparse_template_ast(bool unparse_template_ast); | |
skipElaborateTypebool skipElaborateType() const; | |
unsetExternBracevoid unsetExternBrace(); | |
unsetForwardvoid unsetForward(); | |
unsetNameOnlyvoid unsetNameOnly(); | |
unsetSkipElaborateTypevoid unsetSkipElaborateType(); | |
variantTvirtual VariantT variantT() const override; [virtual] | returns new style SageIII enum values |
Static Member Functions¶
| Name | Description |
|---|---|
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 |
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. |
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 Data Members¶
Friends¶
| Name | Description |
|---|---|
isSgDeclarationStatement | Casts pointer from base class to derived class (for const pointers) |
isSgDeclarationStatement | Casts pointer from base class to derived class |
Derived Classes¶
Created with MrDocs