Class Symbol

java.lang.Object
org.ek9lang.compiler.symbols.Symbol
All Implemented Interfaces:
Serializable, ISymbol, ITokenReference
Direct Known Subclasses:
ConstantSymbol, ExpressionSymbol, ParamExpressionSymbol, ScopedSymbol, StreamPipeLineSymbol, VariableSymbol

public class Symbol extends Object implements ISymbol
A bit of a beast. The 'Symbol' can be a type, a function, a variable, a control statement, i.e. it can be used in a very wide range of contexts. Is extended widely for particular types of symbol.
See Also:
  • Constructor Details

  • Method Details

    • clone

      public Symbol 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
    • cloneIntoSymbol

      protected Symbol cloneIntoSymbol(Symbol newCopy)
    • copySymbolProperties

      public Symbol copySymbolProperties(Symbol newCopy)
      Just copies the properties over.
    • isMarkedPure

      public boolean isMarkedPure()
      Description copied from interface: ISymbol
      This symbol itself can be marked as pure - i.e. an operator with no side effects.
      Specified by:
      isMarkedPure in interface ISymbol
      Returns:
      true if pure, false otherwise. By default, false - lets assume the worst.
    • setMarkedPure

      public void setMarkedPure(boolean markedPure)
    • isReferenced

      public boolean isReferenced()
      Specified by:
      isReferenced in interface ISymbol
    • setReferenced

      public void setReferenced(boolean referenced)
      Specified by:
      setReferenced in interface ISymbol
    • putSquirrelledData

      public void putSquirrelledData(String key, String value)
      Sometimes it's important to 'squirrel' away information during different phases of the compilation. This mechanism on a symbol enables arbitrary data to be recorded against a symbol. This can then be retrieved in later stages of compilation.
      Specified by:
      putSquirrelledData in interface ISymbol
    • getSquirrelledData

      public String getSquirrelledData(String key)
      Specified by:
      getSquirrelledData in interface ISymbol
    • 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
      Returns:
      If this symbol is mutable or not.
    • setNotMutable

      public void setNotMutable()
      Specified by:
      setNotMutable in interface ISymbol
    • isNullAllowed

      public boolean isNullAllowed()
      Specified by:
      isNullAllowed in interface ISymbol
    • setNullAllowed

      public void setNullAllowed(boolean nullAllowed)
      Specified by:
      setNullAllowed in interface ISymbol
    • isInjectionExpected

      public boolean isInjectionExpected()
      Specified by:
      isInjectionExpected in interface ISymbol
    • setInjectionExpected

      public void setInjectionExpected(boolean injectionExpected)
      Specified by:
      setInjectionExpected in interface ISymbol
    • isEk9Core

      public boolean isEk9Core()
      Description copied from interface: ISymbol
      Is this a core thing from EK9.
      Specified by:
      isEk9Core in interface ISymbol
    • setEk9Core

      public void setEk9Core(boolean ek9Core)
      set this symbol as an EK9 core symbol. This means it is designed and built right into the language or is part of the standard EK9 library.
    • isDevSource

      public boolean isDevSource()
      Specified by:
      isDevSource in interface ISymbol
    • isLibSource

      public boolean isLibSource()
      Specified by:
      isLibSource in interface ISymbol
    • getProduceFullyQualifiedName

      public boolean getProduceFullyQualifiedName()
    • setProduceFullyQualifiedName

      public void setProduceFullyQualifiedName(boolean produceFullyQualifiedName)
    • getSourceToken

      public IToken getSourceToken()
      Specified by:
      getSourceToken in interface ISymbol
      Specified by:
      getSourceToken in interface ITokenReference
    • setSourceToken

      public void setSourceToken(IToken sourceToken)
      Specified by:
      setSourceToken in interface ITokenReference
    • getInitialisedBy

      public IToken getInitialisedBy()
      Specified by:
      getInitialisedBy in interface ISymbol
    • setInitialisedBy

      public void setInitialisedBy(IToken initialisedBy)
      Specified by:
      setInitialisedBy in interface ISymbol
    • clearInitialisedBy

      public void clearInitialisedBy()
      Specified by:
      clearInitialisedBy in interface ISymbol
    • getParsedModule

      public Optional<Module> getParsedModule()
      Specified by:
      getParsedModule in interface ISymbol
    • setParsedModule

      public void setParsedModule(Optional<Module> module)
      Description copied from interface: ISymbol
      For some symbols you may wish to specify the parsed module they were defined in.
      Specified by:
      setParsedModule in interface ISymbol
      Parameters:
      module - The parsedModule the symbol was defined in.
    • getFullyQualifiedName

      public String getFullyQualifiedName()
      Description copied from interface: ISymbol
      Provide the internal fully qualified name of this symbol. Defaults to just the name unless overridden. -Useful for generating output where you want to ensure fully qualified names are used.
      Specified by:
      getFullyQualifiedName in interface ISymbol
    • isExactSameType

      public boolean isExactSameType(ISymbol symbolType)
      Checks if the type match exactly.
      Specified by:
      isExactSameType in interface ISymbol
    • isAssignableTo

      public boolean isAssignableTo(ISymbol s)
      Specified by:
      isAssignableTo in interface ISymbol
    • isAssignableTo

      public boolean isAssignableTo(Optional<ISymbol> s)
      Specified by:
      isAssignableTo in interface ISymbol
    • getAssignableWeightTo

      public double getAssignableWeightTo(Optional<ISymbol> s)
      Specified by:
      getAssignableWeightTo in interface ISymbol
    • getAssignableWeightTo

      public double getAssignableWeightTo(ISymbol s)
      Specified by:
      getAssignableWeightTo in interface ISymbol
    • isPromotionSupported

      public boolean isPromotionSupported(ISymbol s)
      Description copied from interface: ISymbol
      For some symbols we might support the _promote method via coercion. i.e. Long -> Float for example But with class structures and traits/interfaces there is a time when objects are assignable because of base and super classes/types but don't need coercion. The isAssignable deals with mingling both coercion and super/trait type compatibility. But we need to know when it comes to IR generation whether to include a PromoteNode or whether the code generated will just work because of class inheritance/interface implementation.
      Specified by:
      isPromotionSupported in interface ISymbol
    • getUnCoercedAssignableWeightTo

      public double getUnCoercedAssignableWeightTo(ISymbol s)
      Specified by:
      getUnCoercedAssignableWeightTo in interface ISymbol
    • getCategory

      public ISymbol.SymbolCategory getCategory()
      Specified by:
      getCategory in interface ISymbol
    • setCategory

      public void setCategory(ISymbol.SymbolCategory category)
    • getGenus

      public ISymbol.SymbolGenus getGenus()
      Specified by:
      getGenus in interface ISymbol
    • setGenus

      public void setGenus(ISymbol.SymbolGenus genus)
      Specified by:
      setGenus in interface ISymbol
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • 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
      Returns:
      a user presentable of the symbol name.
    • getSymbolTypeAsString

      protected String getSymbolTypeAsString(Optional<ISymbol> type)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getName

      public String getName()
      Description copied from interface: ISymbol
      Provide the internal name of this symbol - not fully qualified in terms of the module it is in.
      Specified by:
      getName in interface ISymbol
      Returns:
      The basic internal name we'd use to resolve the symbol
    • setName

      public void setName(String name)
      Specified by:
      setName in interface ISymbol
    • getType

      public Optional<ISymbol> getType()
      Specified by:
      getType in interface ISymbol
    • setType

      public ISymbol setType(Optional<ISymbol> type)
      Specified by:
      setType in interface ISymbol