Skip to content

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
SgDeclarationStatement
SgDeclarationStatement(); [constructor]
Constructors
~SgDeclarationStatement
virtual ~SgDeclarationStatement(); [destructor] [virtual]
Destructor
accept
virtual void accept(ROSE_VisitorPattern& visitor) override; [virtual]
support for the classic visitor pattern done in GoF
appendDestructorOwnedNodes
virtual void appendDestructorOwnedNodes(std::vector<SgNode*>& nodes) const override; [virtual]
class_name
virtual std::string class_name() const override; [virtual]
returns a string representing the class name
clear_translation_unit_source_order_for_transformation
void 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.
copy
virtual SgNode* copy(SgCopyHelp& help) const override; [virtual]
fixupCopy_references
virtual void fixupCopy_references( SgNode* copy, SgCopyHelp& help) const override; [virtual]
fixupCopy_scopes
virtual void fixupCopy_scopes( SgNode* copy, SgCopyHelp& help) const override; [virtual]
fixupCopy_symbols
virtual void fixupCopy_symbols( SgNode* copy, SgCopyHelp& help) const override; [virtual]
get_alignment_specifiers
SgAlignmentSpecifierPtrList const& get_alignment_specifiers() const;
get_ast_json_external_role
ast_json_external_role_enum get_ast_json_external_role() const;
get_ast_json_external_source_file
std::string const& get_ast_json_external_source_file() const;
get_binding_cdefined
bool get_binding_cdefined() const;
get_binding_label
std::string get_binding_label() const;
get_binding_label_present
bool get_binding_label_present() const;
get_childIndex
virtual size_t get_childIndex(SgNode* child) const override; [virtual]
index-based access to traversal successors by child node
get_declarationModifier
SgDeclarationModifier const& get_declarationModifier() const;
get_declarationScope
SgDeclarationScope* get_declarationScope() const;
get_definingDeclaration
SgDeclarationStatement* get_definingDeclaration() const;
get_externBrace
bool get_externBrace() const;
get_firstNondefiningDeclaration
SgDeclarationStatement* get_firstNondefiningDeclaration() const;
get_forward
bool get_forward() const;
get_linkage
std::string get_linkage() const;
get_mangled_name
virtual SgName get_mangled_name() const; [virtual]
get_nameOnly
bool get_nameOnly() const;
get_nonreal_decl_scope
SgDeclarationScope* get_nonreal_decl_scope() const;
get_numberOfTraversalSuccessors
virtual size_t get_numberOfTraversalSuccessors() const override; [virtual]
return number of children in the traversal successor list
get_scope
virtual SgScopeStatement* get_scope() const override; [virtual]
get_skipElaborateType
bool get_skipElaborateType() const;
get_source_declarator_scope
SgDeclarationScope* get_source_declarator_scope() const;
get_source_name_global_qualification
bool get_source_name_global_qualification() const;
get_source_name_qualification_present
bool get_source_name_qualification_present() const;
get_source_name_qualification_tokens
SgStringList const& get_source_name_qualification_tokens() const;
get_symbol_from_symbol_table
virtual SgSymbol* get_symbol_from_symbol_table() const override; [virtual]
get_translation_unit_source_order
std::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_traversalSuccessorByIndex
virtual SgNode* get_traversalSuccessorByIndex(size_t idx) const override; [virtual]
index-based access to traversal successors by index number
get_traversalSuccessorContainer
virtual 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_traversalSuccessorIsListElement
virtual std::vector<bool> get_traversalSuccessorIsListElement() const override; [virtual]
get_traversalSuccessorNamesContainer
virtual 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_type
SgType* get_type() const;
get_unparse_template_ast
bool get_unparse_template_ast() const;
has_semantic_mangled_name
bool 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_provenance
void initialize_ast_json_external_provenance( ast_json_external_role_enum role, std::string const& source_file);
initialize_translation_unit_source_order
void 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.
isExternBrace
bool isExternBrace() const;
isForward
bool isForward() const;
isNameOnly
bool isNameOnly() const;
operator delete
void operator delete( void* pointer, size_t size);
deallocated memory for IR node (returns memory to memory pool for reuse)
operator new
void* operator new(size_t size);
returns pointer to newly allocated IR node
post_construction_initialization
virtual void post_construction_initialization() override; [virtual]
processDataMemberReferenceToPointers
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler*) override; [virtual]
Pass references to stored node pointers to a handler.
returnDataMemberPointers
virtual std::vector<std::pair<SgNode*, std::string>> returnDataMemberPointers() const override; [virtual]
Return the node pointers stored in this node's data members.
roseRTI
virtual RTIReturnType roseRTI() override; [virtual]
return C++ Runtime-Time-Information
sage_class_name
virtual char const* sage_class_name() const override; [virtual]
returns a C style string (char*) representing the class name
search_for_symbol_from_symbol_table
SgSymbol* search_for_symbol_from_symbol_table() const;
setExternBrace
void setExternBrace();
setForward
void setForward();
setNameOnly
void setNameOnly();
setSkipElaborateType
void setSkipElaborateType();
set_binding_cdefined
void set_binding_cdefined(bool binding_cdefined);
set_binding_label
void set_binding_label(std::string binding_label);
set_binding_label_present
void set_binding_label_present(bool binding_label_present);
set_declarationScope
void set_declarationScope(SgDeclarationScope* declarationScope);
set_definingDeclaration
void set_definingDeclaration(SgDeclarationStatement* definingDeclaration);
set_externBrace
void set_externBrace(bool externBrace);
set_firstNondefiningDeclaration
void set_firstNondefiningDeclaration(SgDeclarationStatement* firstNondefiningDeclaration);
set_forward
void set_forward(bool forward);
set_linkage
void set_linkage(std::string linkage);
set_nameOnly
void set_nameOnly(bool nameOnly);
set_nonreal_decl_scope
void set_nonreal_decl_scope(SgDeclarationScope* nonreal_decl_scope);
set_scope
virtual void set_scope(SgScopeStatement* newScope) override; [virtual]
set_skipElaborateType
void set_skipElaborateType(bool skipElaborateType);
set_source_declarator_scope
void set_source_declarator_scope(SgDeclarationScope* source_declarator_scope);
set_source_name_global_qualification
void set_source_name_global_qualification(bool source_name_global_qualification);
set_source_name_qualification_present
void set_source_name_qualification_present(bool source_name_qualification_present);
set_unparse_template_ast
void set_unparse_template_ast(bool unparse_template_ast);
skipElaborateType
bool skipElaborateType() const;
unsetExternBrace
void unsetExternBrace();
unsetForward
void unsetForward();
unsetNameOnly
void unsetNameOnly();
unsetSkipElaborateType
void unsetSkipElaborateType();
variantT
virtual VariantT variantT() const override; [virtual]
returns new style SageIII enum values

Static Member Functions

Name Description
memoryUsage
static size_t memoryUsage();
Returns the size in bytes of the total memory allocated for all IR nodes of this type
numberOfNodes
static size_t numberOfNodes();
Returns the total number of IR nodes of this type
traverseMemoryPoolNodes
static void traverseMemoryPoolNodes(ROSE_VisitTraversal& visit);
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
traverseMemoryPoolVisitorPattern
static void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern& visitor);
FOR INTERNAL USE Support for visitor pattern.
visitRepresentativeNode
static 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

Name
p_alignment_specifiers
p_ast_json_external_role
p_ast_json_external_source_file
p_binding_cdefined
p_binding_label
p_binding_label_present
p_declarationModifier
p_declarationScope
p_definingDeclaration
p_externBrace
p_firstNondefiningDeclaration
p_forward
p_linkage
p_nameOnly
p_nonreal_decl_scope
p_skipElaborateType
p_source_declarator_scope
p_source_name_global_qualification
p_source_name_qualification_present
p_source_name_qualification_tokens
p_translation_unit_source_order
p_unparse_template_ast

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

Name Description
SgAccessLabelStatement
SgAsmStmt This class represents the concept of a C Assembler statement.
SgAttributeSpecificationStatement
SgC_PreprocessorDirectiveStatement
SgClassDeclaration This class represents the concept of a class declaration statement. It includes the
SgClinkageDeclarationStatement
SgCommonBlock
SgContainsStatement
SgCtorInitializerList This class represents the concept of a contructor initializer list (used in
SgDeclarationGroupStatement
SgEmptyDeclaration
SgEnumDeclaration This class represents the concept of an enum declaration.
SgEquivalenceStatement
SgFormatStatement
SgFortranIncludeLine
SgFriendTypeDeclaration
SgFunctionDeclaration
SgFunctionParameterList The ordered parameter declarations of a function.
SgImplicitStatement
SgImportStatement
SgInterfaceStatement
SgNamelistStatement
SgNamespaceAliasDeclarationStatement This class represents the concept of a C++ namespace alias declaration statement.
SgNamespaceDeclarationStatement This class represents the concept of a C++ namespace declaration.
SgNonrealDecl
SgOmpAssumesStatement
SgOmpBeginAssumesStatement
SgOmpBeginDeclareTargetStatement
SgOmpBeginDeclareVariantStatement
SgOmpDeclareMapperStatement
SgOmpDeclareSimdStatement
SgOmpDeclareTargetStatement
SgOmpDeclareVariantStatement
SgOmpEndAssumesStatement
SgOmpEndDeclareTargetStatement
SgOmpEndDeclareVariantStatement
SgOmpGroupprivateStatement
SgOmpRequiresStatement
SgOmpThreadprivateStatement
SgPragmaDeclaration A pragma declaration containing an SgPragma node.
SgStatementFunctionStatement
SgStaticAssertionDeclaration
SgTemplateDeclaration This class represents the concept of a template declaration.
SgTemplateInstantiationDirectiveStatement This class represents the concept of a C++ template instantiation directive.
SgTypedefDeclaration This class represents the notion of a typedef declaration.
SgUseStatement
SgUsingDeclarationStatement This class represents the concept of a C++ using declaration.
SgUsingDirectiveStatement This class represents the concept of a C++ using directive.
SgVariableDeclaration This class represents the concept of a C or C++ variable declaration.
SgVariableDefinition This class represents the definition (initialization) of a variable.

Created with MrDocs