Class ExpressionSymbol

java.lang.Object
org.ek9lang.compiler.symbols.Symbol
org.ek9lang.compiler.symbols.ExpressionSymbol
All Implemented Interfaces:
Serializable, ISymbol, ISymbolNature, ITokenReference

public class ExpressionSymbol extends Symbol
While we don't add these in the scoped structures when compiling. We do use these to augment the parse tree for the appropriate context. We do this so that we can work out what type of result will be returned from an expression. See methods like isExactSameType and isAssignableTo for type checking in the Symbol class. The idea is to augment the parse tree with these expression symbols so that once we've been through sufficient passes of the tree we have sufficient information to add in any promotions/coercions and also check the type of parameters on operations are compatible. We can then add in explicit IR type conversions if needed. This information will also be used in the semantic analysis phase.
See Also:
  • Constructor Details

    • ExpressionSymbol

      public ExpressionSymbol(ISymbol symbol)
      Create a new expression based around an existing symbol.
    • ExpressionSymbol

      public ExpressionSymbol(String name)
  • Method Details

    • clone

      public ExpressionSymbol clone(IScope withParentAsAppropriate)
      Description copied from interface: ISymbol
      Clone the symbol and re-parent if this symbol like a method should have a parent. Other symbols like VariableSymbols are un-parented
      Specified by:
      clone in interface ISymbol
      Overrides:
      clone in class Symbol
    • cloneIntoExpressionSymbol

      protected ExpressionSymbol cloneIntoExpressionSymbol(ExpressionSymbol newCopy)
    • getFriendlyName

      public String getFriendlyName()
      Description copied from interface: ISymbol
      Provide the name an end user would need to see on the screen. Normally this is just 'getName' but in the case of Templates We use a very nasty internal naming for List of SomeClass - which will probably be something like _List_hashed_version_of_ComeClass and the end user needs to see 'List of SomeClass' for it to be meaningful.
      Specified by:
      getFriendlyName in interface ISymbol
      Overrides:
      getFriendlyName in class Symbol
      Returns:
      a user presentable of the symbol name.
    • isDeclaredAsConstant

      public boolean isDeclaredAsConstant()
      Description copied from interface: ISymbol
      Only use on symbols, to see if they are directly defined as a constant.
    • setDeclaredAsConstant

      public void setDeclaredAsConstant(boolean declaredAsConstant)
    • isMutable

      public boolean isMutable()
      Description copied from interface: ISymbol
      Even constants can be mutable until set. then they change to being none mutable. Likewise in 'pure' scopes a variable can be mutable until it is first set then none mutable.
      Specified by:
      isMutable in interface ISymbol
      Overrides:
      isMutable in class Symbol
      Returns:
      If this symbol is mutable or not.
    • isConstant

      public boolean isConstant()
    • setNotMutable

      public void setNotMutable()
      Specified by:
      setNotMutable in interface ISymbol
      Overrides:
      setNotMutable in class Symbol
    • isPromotionRequired

      public boolean isPromotionRequired()
    • setPromotionRequired

      public void setPromotionRequired(boolean promotionRequired)
    • isUseStringOperator

      public boolean isUseStringOperator()
    • setUseStringOperator

      public void setUseStringOperator(boolean useStringOperator)
    • setSourceToken

      public void setSourceToken(IToken sourceToken)
      Specified by:
      setSourceToken in interface ITokenReference
      Overrides:
      setSourceToken in class Symbol
    • equals

      public boolean equals(Object o)
      Description copied from class: Symbol
      Two symbols are the same symbol when they agree on name, category, genus, mutability AND the declaration site they came from.

      The source token is part of identity deliberately. Name alone is not enough: symbol names are unqualified here, so two unrelated variables both called count, or two types called Foo in different modules, would otherwise compare equal. The compiler relies on telling those apart - CodeFlowMap keys initialisation state on Map<IScope, Map<ISymbol, SymbolAccess>>, and conflating two same-named declarations there makes flow analysis attribute one variable's initialisation to another.

      That distinction used to be present ONLY in Symbol.hashCode(), which is why this looked like it worked: two same-named symbols compared equal yet hashed apart, so hash collections usually - but not reliably - kept them separate, while any direct equals call saw them as one. Encoding it here makes the two agree. See SymbolEqualsHashCodeContractTest.

      Overrides:
      equals in class Symbol
    • hashCode

      public int hashCode()
      Description copied from class: Symbol
      Mixes in exactly the fields Symbol.equals(Object) compares, and nothing else.

      A hashCode may legitimately use FEWER fields than equals (that only causes collisions, which are correct), but never MORE: any extra field makes two symbols that compare equal land in different buckets, so a HashSet silently holds visible duplicates and a HashMap lookup misses an entry that is present. This method used to mix in purity, which no equals at THIS level consults - purity belongs in FunctionSymbol, the level whose equals compares it. The source token stays, and is now matched by Symbol.equals(Object). See SymbolEqualsHashCodeContractTest.

      Overrides:
      hashCode in class Symbol