Module dev.civl.abc

Interface ExpressionNode

All Superinterfaces:
ASTNode, ForLoopInitializerNode, InitializerNode, SizeableNode
All Known Subinterfaces:
AlignOfNode, ArrayLambdaNode, ArrowNode, CastNode, CharacterConstantNode, CompoundLiteralNode, ConstantNode, DerivativeExpressionNode, DotNode, EnumerationConstantNode, ExtendedQuantifiedExpressionNode, FloatingConstantNode, FunctionCallNode, GenericSelectionNode, HereOrRootNode, IdentifierExpressionNode, IntegerConstantNode, LambdaNode, NothingNode, ObjectOrRegionOfNode, OperatorNode, ProcnullNode, QuantifiedExpressionNode, RegularRangeNode, RemoteOnExpressionNode, ResultNode, ScopeOfNode, SelfNode, SizeofNode, SpawnNode, StatementExpressionNode, StatenullNode, StringLiteralNode, WildcardNode

public interface ExpressionNode extends InitializerNode, SizeableNode, ForLoopInitializerNode

A node representing any kind of C expression. This is the root of a type hierarchy of expression nodes.

This interface extends InitializerNode because an expression can be used as an initializer for a scalar variable.

This interface extends SizeableNode because an expression can be used as an argument to the sizeof operator.

This interface extends ForLoopInitializerNode to indicate that an expression can be used as the first clause of a "for" loop (as can a variable declaration).

There are many different subtypes of this interface, for the different kinds of expressions. An enumerated type ExpressionNode.ExpressionKind is provided to make it easy to identify the subtype and, for example, switch on it.

Every expression has an initial type, and then some number (possibly 0) of implicit conversions. Each conversion specifies an old type and a new type. The conversions form a chain: the first conversion (conversion number 0) has as its old type the initial type of the expression. The old type of conversion n (for any n≥1) equals the new type of conversion n-1. The new type of the last conversion is the final "converted type" of the expression.

  • Method Details

    • addConversion

      void addConversion(Conversion conversion)
      Adds a conversion to the sequence of conversions for this expression. The added conversion must satisfy the following, else an IllegalArgumentException will be thrown: (1) if this is the first conversion (index 0) to be added, the old type of the conversion must equal the initial type; (2) if this is not the first conversion (index > 0) to be added, the old type of the conversion must equal the newType of the previous conversion.
      Parameters:
      conversion - the conversion to add to the conversion chain for this expression
    • copy

      Description copied from interface: ASTNode
      Returns a deep copy of this AST node. The node and all of its descendants will be cloned. The cloning does not copy analysis or attribute information.
      Specified by:
      copy in interface ASTNode
      Specified by:
      copy in interface ForLoopInitializerNode
      Specified by:
      copy in interface InitializerNode
      Specified by:
      copy in interface SizeableNode
      Returns:
      deep copy of this node
    • expressionKind

      Returns the kind of this expression. Every expression belongs to exactly one kind.
      Returns:
      the kind of this expression
    • getConversion

      Conversion getConversion(int index)
      Returns the index-th conversion in the chain of types for this expression.
      Parameters:
      index - an integer in the range [0,numTypes-1]
      Returns:
      the index-th conversion associated to this expression
    • getConvertedType

      Type getConvertedType()
      Returns the final converted type of the expression. This is the type the expression has after going through all conversions in its conversion sequence (if any). If there are no conversions, it is the same as the initial type. Otherwise, it is the newType of the last conversion.
      Returns:
      the final converted type of the expression
    • getInitialType

      Type getInitialType()
      Returns the initial type of the expression. This is the type the expression has independent of any context in which the expression occurs.
      Returns:
      initial type of expression
    • getNumConversions

      int getNumConversions()
      Returns the number of conversions in the chain leading from the initial type of the expression to the final converted type. The type of an expression may go through a number of type conversions before arriving at its final "converted type". These conversions depend upon the context in which the expression occurs. The sequence of conversions leading from the initial type to the final converted type form a chain in which the "newType" of conversion i equals the "oldType" of conversion i+1 for each i. The oldType of conversion 0 is the original type of the expression; the newType of the last conversion is the converted type of the expression. This method returns the total number of conversions in that chain. The method will return a nonnegative integer. If there are no conversions, this method returns 0 and the initial and final types are equal.
      Returns:
      the number of type conversions between the original type and the converted type
    • isConstantExpression

      boolean isConstantExpression()
      Is this expression a "constant expression" in the sense of the C11 Standard?
      Returns:
      true iff this expression is a constant expression
    • removeConversions

      void removeConversions()
      Removes all conversions from this node
    • setInitialType

      void setInitialType(Type type)
      Sets the initial type of the expression. This must be set before any conversions are added.
      Parameters:
      type - the type that will be the initial type of this expression
    • isLvalue

      boolean isLvalue()
      checks if this expression is an lvalue expression.