Class FunctionSymbol

All Implemented Interfaces:
Serializable, ICanBeGeneric, ICanCaptureVariables, IFunctionSymbol, IMayReturnSymbol, IScope, IScopedSymbol, ISymbol, ISymbolNature, ITokenReference

public class FunctionSymbol extends PossibleGenericSymbol implements IFunctionSymbol, Serializable
Scope for functions that are part of a module. While in ek9 these are just functions, when mapped to java we can implement in any way we like i.e. classes. We need to ensure that any functions we extend have the same method signature.
See Also:
  • Constructor Details

    • FunctionSymbol

      public FunctionSymbol(String name, IScope enclosingScope)
      Create a new Function Symbol with a specific unique name (in the enclosing scope).
    • FunctionSymbol

      public FunctionSymbol(String name, IScope enclosingScope, List<AggregateSymbol> typeParameterOrArguments)
      A function that can be parameterised, i.e. like a 'List of T'. So the name would be 'List' and the parameterTypes would be a single aggregate of a conceptual T.
  • Method Details

    • clone

      public FunctionSymbol 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 IScope
      Specified by:
      clone in interface IScopedSymbol
      Specified by:
      clone in interface ISymbol
      Overrides:
      clone in class PossibleGenericSymbol
    • cloneIntoFunctionSymbol

      protected FunctionSymbol cloneIntoFunctionSymbol(FunctionSymbol newCopy)
    • getCallParameters

      public List<ISymbol> getCallParameters()
      Added convenience method to make the parameters a bit more obvious.
      Specified by:
      getCallParameters in interface IFunctionSymbol
    • isImplementingInSomeWay

      public boolean isImplementingInSomeWay(IFunctionSymbol function)
      Does this function directly implement or through its hierarchy implement the function passed in.
      Specified by:
      isImplementingInSomeWay in interface IFunctionSymbol
    • getAnySuperTypeOrFunction

      public Optional<IScope> getAnySuperTypeOrFunction()
      Overrides:
      getAnySuperTypeOrFunction in class ScopedSymbol
    • isSignatureMatchTo

      public boolean isSignatureMatchTo(Optional<ISymbol> theirReturnType, List<ISymbol> theirParams)
      Check if the parameter types and return types match.
    • getSuperFunction

      public Optional<IFunctionSymbol> getSuperFunction()
      Specified by:
      getSuperFunction in interface IFunctionSymbol
    • setSuperFunction

      public void setSuperFunction(Optional<IFunctionSymbol> superFunctionSymbol)
    • setSuperFunction

      public void setSuperFunction(IFunctionSymbol superFunctionSymbol)
    • isReturningSymbolPresent

      public boolean isReturningSymbolPresent()
      Some functions have a named return symbol 'like rtn as String' for example. In other cases a function will not return anything (We use 'Void') in the case as the 'type'. So when a Returning Symbol is set we use the type of the returning variable as the type return on the function.
      Specified by:
      isReturningSymbolPresent in interface IMayReturnSymbol
    • getReturningSymbol

      public VariableSymbol getReturningSymbol()
      Provide a symbol that is returned from this function. Note in EK9 this is not just a type but actually a variable symbol (that has a type).
      Specified by:
      getReturningSymbol in interface IMayReturnSymbol
    • setReturningSymbol

      public void setReturningSymbol(VariableSymbol returningSymbol)
      Specified by:
      setReturningSymbol in interface IMayReturnSymbol
    • justSetReturningSymbol

      protected void justSetReturningSymbol(VariableSymbol returningSymbol)
    • getAssignableCostTo

      public double getAssignableCostTo(ISymbol s)
      Specified by:
      getAssignableCostTo in interface ISymbol
      Overrides:
      getAssignableCostTo in class Symbol
    • getUnCoercedAssignableCostTo

      public double getUnCoercedAssignableCostTo(ISymbol s)
      Specified by:
      getUnCoercedAssignableCostTo in interface ISymbol
      Overrides:
      getUnCoercedAssignableCostTo in class Symbol
    • getFriendlyScopeName

      public String getFriendlyScopeName()
      Description copied from interface: IScope
      Useful for printing out errors and information. The scope name might be a complex generated name used internally a bit like symbol names are. So some items are both scopes and symbols - so ideally we'd want to use a friendly name where possible.
      Specified by:
      getFriendlyScopeName in interface IScope
      Overrides:
      getFriendlyScopeName in class ScopedSymbol
      Returns:
      The friendly name to be used for the developer.
    • 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 PossibleGenericSymbol
      Returns:
      a user presentable of the symbol name.
    • doGetFriendlyName

      protected String doGetFriendlyName(String withName, Optional<ISymbol> theType)
    • getType

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

      public ISymbol setType(ISymbol type)
      Specified by:
      setType in interface ISymbol
    • setType

      public ISymbol setType(Optional<ISymbol> type)
      Specified by:
      setType in interface ISymbol
      Overrides:
      setType in class Symbol
    • resolveInThisScopeOnly

      public Optional<ISymbol> resolveInThisScopeOnly(SymbolSearch search)
      Description copied from interface: IScope
      Just look in own scope.
      Specified by:
      resolveInThisScopeOnly in interface IScope
      Overrides:
      resolveInThisScopeOnly in class PossibleGenericSymbol
    • 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 PossibleGenericSymbol
    • 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 PossibleGenericSymbol