SgExpression¶
This class represents the notion of an expression. Expressions
Synopsis¶
Declared in <src/frontend/SageIII/Cxx_Grammar.h> (not stored in Git)
class [[visibility("default")]] SgExpression
: public SgLocatedNode 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. Value expressions expose their semantic type through get_type(); syntax-only expression nodes reject that query.
- 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. Expression types and declaration references are published by the language frontend. Flang semantic analysis resolves array references and procedure calls before constructing their distinct expression nodes.
- 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::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)
Base Classes¶
| Name | Description |
|---|---|
SgLocatedNode | This class represents the notion of an expression or statement which |
Type Aliases¶
| Name |
|---|
base_node_type |
Enums¶
| Name | Description |
|---|---|
Unnamed enum | static variant value |
semantic_wrapper_mask_enum | Records semantic-only Clang expression wrappers without inventing a second source surface. These flags are deliberately typed AST state: the wrapped Sage expression continues to own the written spelling, while analyses can still observe lifetime, cleanup, and constant- evaluation boundaries that do not have C++ tokens of their own. |
temporary_storage_duration_enum | |
unary_type_trait_kind_enum | This class represents the base class of all the expressions within this grammar. It contains all the base functionality for the construction, manipulation, and unparsing support. |
Member Functions¶
| Name | Description |
|---|---|
SgExpressionSgExpression(); [constructor] | Constructors |
~SgExpressionvirtual ~SgExpression(); [destructor] [virtual] | Destructor |
acceptvirtual void accept(ROSE_VisitorPattern& visitor) override; [virtual] | support for the classic visitor pattern done in GoF |
add_semantic_wrappervoid add_semantic_wrapper(semantic_wrapper_mask_enum wrapper); | |
appendDestructorOwnedNodesvirtual void appendDestructorOwnedNodes(std::vector<SgNode*>& nodes) const override; [virtual] | |
cfgFindChildIndexvirtual unsigned int cfgFindChildIndex(SgNode* n) override; [virtual] | |
cfgFindNextChildIndexvirtual unsigned int cfgFindNextChildIndex(SgNode* n) override; [virtual] | |
cfgInEdgesvirtual std::vector<VirtualCFG::CFGEdge> cfgInEdges(unsigned int index) override; [virtual] | |
cfgIndexForEndvirtual unsigned int cfgIndexForEnd() const override; [virtual] | |
cfgIsIndexInterestingvirtual bool cfgIsIndexInteresting(unsigned int index) const override; [virtual] | |
cfgOutEdgesvirtual std::vector<VirtualCFG::CFGEdge> cfgOutEdges(unsigned int index) override; [virtual] | |
class_namevirtual std::string class_name() const override; [virtual] | returns a string representing the class name |
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_alternativeExprSgExpression* get_alternativeExpr() const; | |
get_bound_temporary_destructorSgMemberFunctionDeclaration* get_bound_temporary_destructor() const; | |
get_childIndexvirtual size_t get_childIndex(SgNode* child) const override; [virtual] | index-based access to traversal successors by child node |
get_file_infovirtual Sg_File_Info* get_file_info() const override; [virtual] | |
get_fortran_integer_constant_valueint64_t get_fortran_integer_constant_value() const; | |
get_fortran_integer_constant_value_is_availablebool get_fortran_integer_constant_value_is_available() const; | |
get_global_qualification_for_pointer_to_member_class_requiredvirtual bool get_global_qualification_for_pointer_to_member_class_required() const; [virtual] | |
get_global_qualification_requiredvirtual bool get_global_qualification_required() const; [virtual] | |
get_global_qualified_namebool get_global_qualified_name() const; | |
get_lvaluebool get_lvalue() const; | |
get_materialized_lifetime_ownerSgInitializedName* get_materialized_lifetime_owner() const; | |
get_materialized_storage_durationtemporary_storage_duration_enum get_materialized_storage_duration() const; | |
get_name_qualification_for_pointer_to_member_class_lengthvirtual int get_name_qualification_for_pointer_to_member_class_length() const; [virtual] | |
get_name_qualification_lengthvirtual int get_name_qualification_length() const; [virtual] | |
get_need_parenbool get_need_paren() const; | |
get_numberOfTraversalSuccessorsvirtual size_t get_numberOfTraversalSuccessors() const override; [virtual] | return number of children in the traversal successor list |
get_operatorPositionSg_File_Info* get_operatorPosition() const; | |
get_originalExpressionTreevirtual SgExpression* get_originalExpressionTree() const; [virtual] | |
get_semantic_wrapper_masksemantic_wrapper_mask_enum get_semantic_wrapper_mask() const; | |
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_typevirtual SgType* get_type() const; [virtual] | |
get_type_elaboration_for_pointer_to_member_class_requiredvirtual bool get_type_elaboration_for_pointer_to_member_class_required() const; [virtual] | |
get_type_elaboration_requiredvirtual bool get_type_elaboration_required() const; [virtual] | |
hasExplicitTypebool hasExplicitType(); | Some expressions store internal SgType pointers explicitly while others compute them from other expressions. This function is true if it has a data member that is a type (pointer, array, etc.). |
has_semantic_value_typebool has_semantic_value_type() const; | True only for expression nodes that denote a semantic value. Directive syntax nodes deliberately derive from SgExpression for traversal and child replacement, but have no value type and hard-reject get_type(). |
has_semantic_wrapperbool has_semantic_wrapper(semantic_wrapper_mask_enum wrapper) const; | |
has_type_qualification_payloadbool has_type_qualification_payload() const; | |
isChildUsedAsLValuevirtual bool isChildUsedAsLValue(SgExpression const* child) const; [virtual] | |
isDefinablevirtual bool isDefinable() const; [virtual] | |
isLValuevirtual bool isLValue() const; [virtual] | |
isUsedAsDefinablevirtual bool isUsedAsDefinable() const; [virtual] | |
isUsedAsLValuevirtual bool isUsedAsLValue() const; [virtual] | |
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] | |
precedencevirtual int precedence() const; [virtual] | |
processDataMemberReferenceToPointersvirtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler*) override; [virtual] | Pass references to stored node pointers to a handler. |
replace_expressionvirtual int replace_expression( SgExpression* oldChild, SgExpression* newChild); [virtual] | Replace an expression child of this node with another one. |
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 |
set_alternativeExprvoid set_alternativeExpr(SgExpression* alternativeExpr); | |
set_explicitly_stored_typevoid set_explicitly_stored_type(SgType* type); | Some expressions store internal SgType pointers explicitly, this allows these IR nodes to be reset with new types (used in the snippet support). |
set_file_infovirtual void set_file_info(Sg_File_Info* X) override; [virtual] | |
set_fortran_integer_constant_valuevoid set_fortran_integer_constant_value(int64_t fortran_integer_constant_value); | |
set_fortran_integer_constant_value_is_availablevoid set_fortran_integer_constant_value_is_available(bool fortran_integer_constant_value_is_available); | |
set_global_qualification_for_pointer_to_member_class_requiredvirtual void set_global_qualification_for_pointer_to_member_class_required(bool global_qualification_required); [virtual] | |
set_global_qualification_requiredvirtual void set_global_qualification_required(bool global_qualification_required); [virtual] | |
set_global_qualified_namevoid set_global_qualified_name(bool global_qualified_name); | |
set_lvaluevoid set_lvalue(bool lvalue); | |
set_name_qualification_for_pointer_to_member_class_lengthvirtual void set_name_qualification_for_pointer_to_member_class_length(int name_qualification_length); [virtual] | |
set_name_qualification_lengthvirtual void set_name_qualification_length(int name_qualification_length); [virtual] | |
set_need_parenvoid set_need_paren(bool need_paren); | |
set_operatorPositionvoid set_operatorPosition(Sg_File_Info* position); | |
set_originalExpressionTreevirtual void set_originalExpressionTree(SgExpression* X); [virtual] | |
set_semantic_wrapper_maskvoid set_semantic_wrapper_mask( semantic_wrapper_mask_enum mask, SgMemberFunctionDeclaration* bound_temporary_destructor = nullptr, temporary_storage_duration_enum materialized_storage_duration = e_temporary_storage_none, SgInitializedName* materialized_lifetime_owner = nullptr); | |
set_type_elaboration_for_pointer_to_member_class_requiredvirtual void set_type_elaboration_for_pointer_to_member_class_required(bool type_elaboration_required); [virtual] | |
set_type_elaboration_requiredvirtual void set_type_elaboration_required(bool type_elaboration_required); [virtual] | |
variantTvirtual VariantT variantT() const override; [virtual] | returns new style SageIII enum values |
Static Member Functions¶
| Name | Description |
|---|---|
is_valid_bound_temporary_destructorstatic bool is_valid_bound_temporary_destructor( SgType* type, SgMemberFunctionDeclaration* destructor); | |
is_valid_temporary_materializationstatic bool is_valid_temporary_materialization( temporary_storage_duration_enum storage, SgInitializedName* owner); | |
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 |
|---|---|
isSgExpression | Casts pointer from base class to derived class (for const pointers) |
isSgExpression | Casts pointer from base class to derived class |
Derived Classes¶
Created with MrDocs