Class FunctionSymbol
- All Implemented Interfaces:
Serializable, ICanBeGeneric, ICanCaptureVariables, IFunctionSymbol, IMayReturnSymbol, IScope, IScopedSymbol, ISymbol, ISymbolNature, ITokenReference
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface IScope
IScope.ScopeType -
Constructor Summary
ConstructorsConstructorDescriptionFunctionSymbol(String name, IScope enclosingScope) Create a new Function Symbol with a specific unique name (in the enclosing scope).FunctionSymbol(String name, IScope enclosingScope, List<AggregateSymbol> typeParameterOrArguments) A function that can be parameterised, i.e. -
Method Summary
Modifier and TypeMethodDescriptionClone the symbol and re-parent if this symbol like a method should have a parent.protected FunctionSymbolcloneIntoFunctionSymbol(FunctionSymbol newCopy) protected StringdoGetFriendlyName(String withName, Optional<ISymbol> theType) booleanTwo symbols are the same symbol when they agree on name, category, genus, mutability AND the declaration site they came from.doubleAdded convenience method to make the parameters a bit more obvious.Provide the name an end user would need to see on the screen.Useful for printing out errors and information.Provide a symbol that is returned from this function.getType()doubleinthashCode()Mixes in exactly the fieldsSymbol.equals(Object)compares, and nothing else.booleanisImplementingInSomeWay(IFunctionSymbol function) Does this function directly implement or through its hierarchy implement the function passed in.booleanSome functions have a named return symbol 'like rtn as String' for example.booleanisSignatureMatchTo(Optional<ISymbol> theirReturnType, List<ISymbol> theirParams) Check if the parameter types and return types match.protected voidjustSetReturningSymbol(VariableSymbol returningSymbol) resolveInThisScopeOnly(SymbolSearch search) Just look in own scope.voidsetReturningSymbol(VariableSymbol returningSymbol) voidsetSuperFunction(Optional<IFunctionSymbol> superFunctionSymbol) voidsetSuperFunction(IFunctionSymbol superFunctionSymbol) Methods inherited from class PossibleGenericSymbol
addGenericSymbolReference, addTypeParameterOrArgument, cloneIntoPossibleGenericSymbol, getAnyConceptualTypeParameters, getAnyGenericParamsAsFriendlyNames, getDefinitionContext, getGenericSymbolReferences, getGenericType, getTypeParameterOrArguments, isConceptualTypeParameter, isGenericInNature, isOpenForExtension, isParameterisedType, resolve, resolveFromParameterTypes, setConceptualTypeParameter, setDefinitionContext, setGenericType, setGenericType, setOpenForExtensionMethods inherited from class CaptureScopedSymbol
cloneIntoCaptureScopedSymbol, getCapturedVariables, getModuleScope, getPrivateVariablesForDisplay, isMarkedAbstract, resolveExcludingCapturedVariables, setCapturedVariables, setCapturedVariables, setCapturedVariablesVisibility, setMarkedAbstract, setModuleScopeMethods inherited from class ScopedSymbol
cloneIntoScopeSymbol, copyScopedSymbolProperties, define, findNearestDynamicBlockScopeInEnclosingScopes, findNearestNonBlockScopeInEnclosingScopes, getActualScope, getAllSymbolsMatchingName, getEnclosingScope, getEncounteredExceptionToken, getOuterMostTypeOrFunction, getScopeName, getScopeType, getSymbolsForThisScope, isMarkedPure, isMutable, isNotMarkedPure, isScopeAMatchForEnclosingScope, isTerminatedNormally, resolveMatchingMethods, resolveMatchingMethodsInThisScopeOnly, resolveMember, resolveWithParentScope, setEncounteredExceptionToken, setMarkedPure, setOuterMostTypeOrFunction, setScopeTypeMethods inherited from class Symbol
clearInitialisedBy, cloneIntoSymbol, copySymbolProperties, getAssignableCostTo, getCategory, getFullyQualifiedName, getGenus, getInitialisedBy, getName, getParsedModule, getProduceFullyQualifiedName, getSourceToken, getSquirrelledData, getSymbolTypeAsString, isAssignableTo, isAssignableTo, isDevSource, isEk9Core, isExactSameType, isInjectionExpected, isLibSource, isNullAllowed, isPromotionSupported, isReferenced, putSquirrelledData, setCategory, setEk9Core, setGenus, setInitialisedBy, setInjectionExpected, setName, setNotMutable, setNullAllowed, setParsedModule, setProduceFullyQualifiedName, setReferenced, setSourceToken, toStringMethods inherited from interface ICanBeGeneric
addGenericSymbolReference, addTypeParameterOrArgument, getAnyConceptualTypeParameters, getGenericSymbolReferences, getGenericType, getTypeParameterOrArguments, isOpenForExtensionMethods inherited from interface IScope
define, findNearestDynamicBlockScopeInEnclosingScopes, findNearestNonBlockScopeInEnclosingScopes, getAllSymbolsMatchingName, getEnclosingScope, getEncounteredExceptionToken, getScopeName, getScopeType, getSymbolsForThisScope, isMarkedPure, isScopeAMatchForEnclosingScope, isTerminatedNormally, resolve, resolveMatchingMethods, resolveMatchingMethodsInThisScopeOnly, resolveMember, setEncounteredExceptionTokenMethods inherited from interface ISymbol
clearInitialisedBy, getAssignableCostTo, getFullyQualifiedName, getInitialisedBy, getName, getParsedModule, getSourceToken, getSquirrelledData, isAssignableTo, isAssignableTo, isDeclaredAsConstant, isDevSource, isExactSameType, isExtensionOfInjectable, isFromLiteral, isIncomingParameter, isInitialised, isInjectable, isInjectionExpected, isLibSource, isLoopVariable, isMarkedAbstract, isMarkedPure, isMutable, isNullAllowed, isPrivate, isPromotionSupported, isPropertyField, isProtected, isPublic, isReferenced, isReturningParameter, putSquirrelledData, setInitialisedBy, setInjectionExpected, setName, setNotMutable, setNullAllowed, setParsedModule, setReferencedMethods inherited from interface ISymbolNature
getCategory, getGenus, isApplication, isConceptualTypeParameter, isConstant, isControl, isEk9Core, isFunction, isGenericInNature, isMethod, isParameterisedType, isPrimitiveType, isTemplateFunction, isTemplateType, isType, isVariable, setGenusMethods inherited from interface ITokenReference
setSourceToken
-
Constructor Details
-
FunctionSymbol
-
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
Description copied from interface:ISymbolClone the symbol and re-parent if this symbol like a method should have a parent. Other symbols like VariableSymbols are un-parented- Specified by:
clonein interfaceIScope- Specified by:
clonein interfaceIScopedSymbol- Specified by:
clonein interfaceISymbol- Overrides:
clonein classPossibleGenericSymbol
-
cloneIntoFunctionSymbol
-
getCallParameters
Added convenience method to make the parameters a bit more obvious.- Specified by:
getCallParametersin interfaceIFunctionSymbol
-
isImplementingInSomeWay
Does this function directly implement or through its hierarchy implement the function passed in.- Specified by:
isImplementingInSomeWayin interfaceIFunctionSymbol
-
getAnySuperTypeOrFunction
- Overrides:
getAnySuperTypeOrFunctionin classScopedSymbol
-
isSignatureMatchTo
-
getSuperFunction
- Specified by:
getSuperFunctionin interfaceIFunctionSymbol
-
setSuperFunction
-
setSuperFunction
-
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:
isReturningSymbolPresentin interfaceIMayReturnSymbol
-
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:
getReturningSymbolin interfaceIMayReturnSymbol
-
setReturningSymbol
- Specified by:
setReturningSymbolin interfaceIMayReturnSymbol
-
justSetReturningSymbol
-
getAssignableCostTo
- Specified by:
getAssignableCostToin interfaceISymbol- Overrides:
getAssignableCostToin classSymbol
-
getUnCoercedAssignableCostTo
- Specified by:
getUnCoercedAssignableCostToin interfaceISymbol- Overrides:
getUnCoercedAssignableCostToin classSymbol
-
getFriendlyScopeName
Description copied from interface:IScopeUseful 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:
getFriendlyScopeNamein interfaceIScope- Overrides:
getFriendlyScopeNamein classScopedSymbol- Returns:
- The friendly name to be used for the developer.
-
getFriendlyName
Description copied from interface:ISymbolProvide 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:
getFriendlyNamein interfaceISymbol- Overrides:
getFriendlyNamein classPossibleGenericSymbol- Returns:
- a user presentable of the symbol name.
-
doGetFriendlyName
-
getType
-
setType
-
setType
-
resolveInThisScopeOnly
Description copied from interface:IScopeJust look in own scope.- Specified by:
resolveInThisScopeOnlyin interfaceIScope- Overrides:
resolveInThisScopeOnlyin classPossibleGenericSymbol
-
equals
Description copied from class:SymbolTwo 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 calledFooin different modules, would otherwise compare equal. The compiler relies on telling those apart -CodeFlowMapkeys initialisation state onMap<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 directequalscall saw them as one. Encoding it here makes the two agree. SeeSymbolEqualsHashCodeContractTest.- Overrides:
equalsin classPossibleGenericSymbol
-
hashCode
public int hashCode()Description copied from class:SymbolMixes in exactly the fieldsSymbol.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 bySymbol.equals(Object). SeeSymbolEqualsHashCodeContractTest.- Overrides:
hashCodein classPossibleGenericSymbol
-