java.lang.Object
de.fraunhofer.aisec.cpg.graph.Node
de.fraunhofer.aisec.cpg.graph.statements.Statement
de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression
All Implemented Interfaces:
DeclarationHolder, HasType, Persistable, IVisitable<de.fraunhofer.aisec.cpg.graph.Node>
Direct Known Subclasses:
ArrayCreationExpression, ArrayRangeExpression, ArraySubscriptionExpression, BinaryOperator, CallExpression, CastExpression, CompoundStatementExpression, ConditionalExpression, DeclaredReferenceExpression, DeleteExpression, DesignatedInitializerExpression, ExpressionList, InitializerListExpression, Literal, NewExpression, TypeExpression, TypeIdExpression, UnaryOperator, UninitializedValue

public abstract class Expression
extends Statement
implements HasType
Represents one expression. It is used as a base class for multiple different types of expressions. The only constraint is, that each expression has a type.

Note: In our graph, Expression is inherited from Statement. This is a constraint of the C++ language. In C++, it is valid to have an expression (for example a Literal) as part of a function body, even though the expression value is not used. Consider the following code: int main() { 1; }

This is not possible in Java, the aforementioned code example would prompt a compile error.

  • Field Details

    • type

      protected Type type
      The type of the value after evaluation.
  • Constructor Details

    • Expression

      public Expression()
  • Method Details

    • getType

      public Type getType()
      Specified by:
      getType in interface HasType
    • getPropagationType

      public Type getPropagationType()
      Specified by:
      getPropagationType in interface HasType
      Returns:
      The returned Type is always the same as getType() with the exception of ReferenceType since there is no case in which we want to propagate a reference when using typeChanged()
    • updateType

      public void updateType​(Type type)
      Description copied from interface: HasType
      Sideeffect free type modification WARNING: This should only be used by the TypeSystem Pass
      Specified by:
      updateType in interface HasType
      Parameters:
      type - new type
    • updatePossibleSubtypes

      public void updatePossibleSubtypes​(java.util.Set<Type> types)
      Specified by:
      updatePossibleSubtypes in interface HasType
    • setType

      public void setType​(Type type, java.util.Collection<HasType> root)
      Description copied from interface: HasType
      Set the node's type. This may start a chain of type listener notifications
      Specified by:
      setType in interface HasType
      Parameters:
      type - new type
      root - The nodes which we have seen in the type change chain. When a node receives a type setting command where root.contains(this), we know that we have a type listener circle and can abort. If root is an empty list, the type change is seen as an externally triggered event and subsequent type listeners receive the current node as their root.
    • getPossibleSubTypes

      public java.util.Set<Type> getPossibleSubTypes()
      Specified by:
      getPossibleSubTypes in interface HasType
    • setPossibleSubTypes

      public void setPossibleSubTypes​(java.util.Set<Type> possibleSubTypes, @NotNull java.util.Collection<HasType> root)
      Description copied from interface: HasType
      Set the node's possible subtypes. Listener circle detection works the same way as with HasType.setType(Type, Collection)
      Specified by:
      setPossibleSubTypes in interface HasType
      Parameters:
      possibleSubTypes - the set of possible sub types
      root - A list of already seen nodes which is used for detecting loops.
    • resetTypes

      public void resetTypes​(Type type)
      Description copied from interface: HasType
      Used to set the type and clear the possible subtypes list for when a type is more precise than the current.
      Specified by:
      resetTypes in interface HasType
      Parameters:
      type - the more precise type
    • registerTypeListener

      public void registerTypeListener​(HasType.TypeListener listener)
      Specified by:
      registerTypeListener in interface HasType
    • unregisterTypeListener

      public void unregisterTypeListener​(HasType.TypeListener listener)
      Specified by:
      unregisterTypeListener in interface HasType
    • getTypeListeners

      public java.util.Set<HasType.TypeListener> getTypeListeners()
      Specified by:
      getTypeListeners in interface HasType
    • refreshType

      public void refreshType()
      Specified by:
      refreshType in interface HasType
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class de.fraunhofer.aisec.cpg.graph.Node
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class Statement
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Statement