Skip to content

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
SgExpression
SgExpression(); [constructor]
Constructors
~SgExpression
virtual ~SgExpression(); [destructor] [virtual]
Destructor
accept
virtual void accept(ROSE_VisitorPattern& visitor) override; [virtual]
support for the classic visitor pattern done in GoF
add_semantic_wrapper
void add_semantic_wrapper(semantic_wrapper_mask_enum wrapper);
appendDestructorOwnedNodes
virtual void appendDestructorOwnedNodes(std::vector<SgNode*>& nodes) const override; [virtual]
cfgFindChildIndex
virtual unsigned int cfgFindChildIndex(SgNode* n) override; [virtual]
cfgFindNextChildIndex
virtual unsigned int cfgFindNextChildIndex(SgNode* n) override; [virtual]
cfgInEdges
virtual std::vector<VirtualCFG::CFGEdge> cfgInEdges(unsigned int index) override; [virtual]
cfgIndexForEnd
virtual unsigned int cfgIndexForEnd() const override; [virtual]
cfgIsIndexInteresting
virtual bool cfgIsIndexInteresting(unsigned int index) const override; [virtual]
cfgOutEdges
virtual std::vector<VirtualCFG::CFGEdge> cfgOutEdges(unsigned int index) override; [virtual]
class_name
virtual std::string class_name() const override; [virtual]
returns a string representing the class name
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_alternativeExpr
SgExpression* get_alternativeExpr() const;
get_bound_temporary_destructor
SgMemberFunctionDeclaration* get_bound_temporary_destructor() const;
get_childIndex
virtual size_t get_childIndex(SgNode* child) const override; [virtual]
index-based access to traversal successors by child node
get_file_info
virtual Sg_File_Info* get_file_info() const override; [virtual]
get_fortran_integer_constant_value
int64_t get_fortran_integer_constant_value() const;
get_fortran_integer_constant_value_is_available
bool get_fortran_integer_constant_value_is_available() const;
get_global_qualification_for_pointer_to_member_class_required
virtual bool get_global_qualification_for_pointer_to_member_class_required() const; [virtual]
get_global_qualification_required
virtual bool get_global_qualification_required() const; [virtual]
get_global_qualified_name
bool get_global_qualified_name() const;
get_lvalue
bool get_lvalue() const;
get_materialized_lifetime_owner
SgInitializedName* get_materialized_lifetime_owner() const;
get_materialized_storage_duration
temporary_storage_duration_enum get_materialized_storage_duration() const;
get_name_qualification_for_pointer_to_member_class_length
virtual int get_name_qualification_for_pointer_to_member_class_length() const; [virtual]
get_name_qualification_length
virtual int get_name_qualification_length() const; [virtual]
get_need_paren
bool get_need_paren() const;
get_numberOfTraversalSuccessors
virtual size_t get_numberOfTraversalSuccessors() const override; [virtual]
return number of children in the traversal successor list
get_operatorPosition
Sg_File_Info* get_operatorPosition() const;
get_originalExpressionTree
virtual SgExpression* get_originalExpressionTree() const; [virtual]
get_semantic_wrapper_mask
semantic_wrapper_mask_enum get_semantic_wrapper_mask() const;
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
virtual SgType* get_type() const; [virtual]
get_type_elaboration_for_pointer_to_member_class_required
virtual bool get_type_elaboration_for_pointer_to_member_class_required() const; [virtual]
get_type_elaboration_required
virtual bool get_type_elaboration_required() const; [virtual]
hasExplicitType
bool 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_type
bool 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_wrapper
bool has_semantic_wrapper(semantic_wrapper_mask_enum wrapper) const;
has_type_qualification_payload
bool has_type_qualification_payload() const;
isChildUsedAsLValue
virtual bool isChildUsedAsLValue(SgExpression const* child) const; [virtual]
isDefinable
virtual bool isDefinable() const; [virtual]
isLValue
virtual bool isLValue() const; [virtual]
isUsedAsDefinable
virtual bool isUsedAsDefinable() const; [virtual]
isUsedAsLValue
virtual bool isUsedAsLValue() const; [virtual]
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]
precedence
virtual int precedence() const; [virtual]
processDataMemberReferenceToPointers
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler*) override; [virtual]
Pass references to stored node pointers to a handler.
replace_expression
virtual int replace_expression( SgExpression* oldChild, SgExpression* newChild); [virtual]
Replace an expression child of this node with another one.
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
set_alternativeExpr
void set_alternativeExpr(SgExpression* alternativeExpr);
set_explicitly_stored_type
void 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_info
virtual void set_file_info(Sg_File_Info* X) override; [virtual]
set_fortran_integer_constant_value
void set_fortran_integer_constant_value(int64_t fortran_integer_constant_value);
set_fortran_integer_constant_value_is_available
void set_fortran_integer_constant_value_is_available(bool fortran_integer_constant_value_is_available);
set_global_qualification_for_pointer_to_member_class_required
virtual void set_global_qualification_for_pointer_to_member_class_required(bool global_qualification_required); [virtual]
set_global_qualification_required
virtual void set_global_qualification_required(bool global_qualification_required); [virtual]
set_global_qualified_name
void set_global_qualified_name(bool global_qualified_name);
set_lvalue
void set_lvalue(bool lvalue);
set_name_qualification_for_pointer_to_member_class_length
virtual void set_name_qualification_for_pointer_to_member_class_length(int name_qualification_length); [virtual]
set_name_qualification_length
virtual void set_name_qualification_length(int name_qualification_length); [virtual]
set_need_paren
void set_need_paren(bool need_paren);
set_operatorPosition
void set_operatorPosition(Sg_File_Info* position);
set_originalExpressionTree
virtual void set_originalExpressionTree(SgExpression* X); [virtual]
set_semantic_wrapper_mask
void 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_required
virtual void set_type_elaboration_for_pointer_to_member_class_required(bool type_elaboration_required); [virtual]
set_type_elaboration_required
virtual void set_type_elaboration_required(bool type_elaboration_required); [virtual]
variantT
virtual VariantT variantT() const override; [virtual]
returns new style SageIII enum values

Static Member Functions

Name Description
is_valid_bound_temporary_destructor
static bool is_valid_bound_temporary_destructor( SgType* type, SgMemberFunctionDeclaration* destructor);
is_valid_temporary_materialization
static bool is_valid_temporary_materialization( temporary_storage_duration_enum storage, SgInitializedName* owner);
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_alternativeExpr
p_bound_temporary_destructor
p_fortran_integer_constant_value
p_fortran_integer_constant_value_is_available
p_global_qualified_name
p_lvalue
p_materialized_lifetime_owner
p_materialized_storage_duration
p_need_paren
p_operatorPosition
p_originalExpressionTree
p_semantic_wrapper_mask

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

Name Description
SgActualArgumentExpression
SgAlignOfOp
SgAsmOp
SgAssumedRankExp
SgAsteriskShapeExp
SgAwaitExpression
SgBinaryOp This class represents the notion of a binary operator.
SgCAFCoExpression
SgCAFImageSelectorExp
SgCallExpression This class represents the concept of a generic call expression.
SgChooseExpression
SgClassNameRefExp This class represents the concept of a C++ expression built from a class name.
SgColonShapeExp
SgCompoundLiteralExp
SgCompoundRequirement
SgConditionalExp This class represents the concept of a C trinary conditional expression (e.g. "test ? true : false")
SgCudaKernelExecConfig
SgCxxArrayInitLoop
SgCxxArrayInitReference
SgCxxDecompositionRefExp
SgCxxDefaultInitExp
SgCxxSubobjectDestruction
SgDeleteExp This class represents the concept of a C++ call to the delete operator.
SgDesignator
SgExprListExp This class represents the concept of a C and C++ expression list.
SgFoldExpression
SgFortranCommonBlockRefExp
SgFunctionParameterRefExp
SgFunctionRefExp This class represents the function being called and must be assembled in the
SgImpliedDo
SgInitializer This class represents the notion of an initializer for a variable declaration or
SgLabelRefExp
SgLambdaExp
SgMacroExpansionExp
SgMemberFunctionRefExp This class represents the member function being called and must be assembled in the
SgNestedRequirement
SgNewExp This class represents the concept of a C++ call to the new operator.
SgNoexceptOp
SgNonrealRefExp
SgNullExpression
SgOmpAppendArgsOperation
SgOmpApplyTransformation
SgOmpDirectiveLocalRefExp
SgOmpInductionItem
SgOmpInitModifier
SgOmpInitModifierList
SgOmpMapDistDataPolicy
SgOmpMapItem
SgOmpNameExpression
SgOmpSourceExpression
SgOpaqueValueBinding
SgOpaqueValueReference
SgPackExpansionExpr
SgPseudoDestructorRefExp
SgPseudoObjectExp
SgRangeExp
SgRefExp This class represents the "&" operator (applied to any lvalue).
SgRequirementSubstitutionFailure
SgRequiresExpr
SgSimpleRequirement
SgSizeOfOp This class represents the "sizeof()" operator (applied to any type).
SgSourceLocationBuiltinExp
SgStatementExpression This class represents the GNU extension "statement expression" (thus is
SgSubscriptExpression
SgTemplateFunctionRefExp
SgTemplateMemberFunctionRefExp
SgThisExp This class represents the "this" operator (can be applied to any member data).
SgTypeExpression
SgTypeIdOp
SgTypeRequirement
SgTypeTraitBuiltinOperator
SgUnaryOp This class represents the notion of a unary operator.
SgValueExp This class represents the notion of an value (expression value).
SgVarArgCopyOp
SgVarArgEndOp
SgVarArgOp
SgVarArgStartOneOperandOp
SgVarArgStartOp
SgVarRefExp This class represents the variable refernece in expressions.
SgVariantExpression

Created with MrDocs