Class PossibleGenericSymbol
- All Implemented Interfaces:
Serializable, ICanBeGeneric, ICanCaptureVariables, IScope, IScopedSymbol, ISymbol, ISymbolNature, ITokenReference
- Direct Known Subclasses:
AggregateSymbol, FunctionSymbol
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface IScope
IScope.ScopeType -
Constructor Summary
ConstructorsConstructorDescriptionPossibleGenericSymbol(String name, Optional<ISymbol> type, IScope enclosingScope) PossibleGenericSymbol(String name, IScope enclosingScope) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGenericSymbolReference(PossibleGenericSymbol genericSymbolReference) Add a reference to a parameterised function.voidaddTypeParameterOrArgument(ISymbol typeParameterOrArgument) Add a parameter type to this scope.Clone the symbol and re-parent if this symbol like a method should have a parent.protected PossibleGenericSymbolbooleanTwo symbols are the same symbol when they agree on name, category, genus, mutability AND the declaration site they came from.If this scope has been parameterised, then go through those parameters and return a list of all those that are generic 'T' in nature and not actually concrete types.protected StringOptional<org.antlr.v4.runtime.ParserRuleContext> Get the definition context (AST node) for this generic type.Provide the name an end user would need to see on the screen.Used to keep track of any generic types/functions used in a generic type that use some or all of the generic type parameters or arguments.Not only can a class/function that implements this interface be generic in nature, they can also be a 'parameterised type'.inthashCode()Mixes in exactly the fieldsSymbol.equals(Object)compares, and nothing else.booleanIs this itself a 'conceptual' type.booleanIs this symbol a type that is generic in nature i.e.booleanIs the symbol open for extension or not.booleanSo just to add to the confusion.resolve(SymbolSearch search) So this is where we alter the mechanism of normal symbol resolution.Used when the type/function is one that is generic/template.resolveInThisScopeOnly(SymbolSearch search) Just look in own scope.voidsetConceptualTypeParameter(boolean conceptualTypeParameter) Set this type symbol to be conceptual in nature.voidsetDefinitionContext(org.antlr.v4.runtime.ParserRuleContext ctx) Set the definition context (AST node) for this generic type.voidsetGenericType(Optional<PossibleGenericSymbol> genericType) Used parameterizing a generic type with type arguments.voidsetGenericType(PossibleGenericSymbol genericType) voidsetOpenForExtension(boolean open) Methods 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, getAnySuperTypeOrFunction, getEnclosingScope, getEncounteredExceptionToken, getFriendlyScopeName, 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, getAssignableCostTo, getCategory, getFullyQualifiedName, getGenus, getInitialisedBy, getName, getParsedModule, getProduceFullyQualifiedName, getSourceToken, getSquirrelledData, getSymbolTypeAsString, getType, getUnCoercedAssignableCostTo, isAssignableTo, isAssignableTo, isDevSource, isEk9Core, isExactSameType, isInjectionExpected, isLibSource, isNullAllowed, isPromotionSupported, isReferenced, putSquirrelledData, setCategory, setEk9Core, setGenus, setInitialisedBy, setInjectionExpected, setName, setNotMutable, setNullAllowed, setParsedModule, setProduceFullyQualifiedName, setReferenced, setSourceToken, setType, toStringMethods inherited from interface ISymbol
clearInitialisedBy, getAssignableCostTo, getAssignableCostTo, getFullyQualifiedName, getInitialisedBy, getName, getParsedModule, getSourceToken, getSquirrelledData, getType, getUnCoercedAssignableCostTo, 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, setReferenced, setType, setTypeMethods inherited from interface ISymbolNature
getCategory, getGenus, isApplication, isConstant, isControl, isEk9Core, isFunction, isMethod, isPrimitiveType, isTemplateFunction, isTemplateType, isType, isVariable, setGenusMethods inherited from interface ITokenReference
setSourceToken
-
Constructor Details
-
PossibleGenericSymbol
-
PossibleGenericSymbol
-
-
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 classCaptureScopedSymbol
-
cloneIntoPossibleGenericSymbol
-
isParameterisedType
public boolean isParameterisedType()Description copied from interface:ISymbolNatureSo just to add to the confusion. A type that has been used with a type that is generic in nature with some parameters. So this would normally result in a type that is now concrete. i.e. List (generic in nature) and String (concrete) so this resulting type 'List of String' isAParameterisedType=true and isGenericInNature=false. But if List were parameterised with another generic parameter it would still be of a generic nature. For example, consider List T and Iterator I when we defined List T and use the Iterator with it; we parameterise Iterator with 'T'. But they are still both 'isGenericTypeParameter' it only when we use List (and by implication Iterator) with String do they both stop being generic in nature.- Specified by:
isParameterisedTypein interfaceISymbolNature- Returns:
- true if a parameterised type (note parameterised not just of a generic nature).
-
getGenericType
Description copied from interface:ICanBeGenericNot only can a class/function that implements this interface be generic in nature, they can also be a 'parameterised type'.- Specified by:
getGenericTypein interfaceICanBeGeneric
-
setGenericType
Used parameterizing a generic type with type arguments. -
setGenericType
-
isGenericInNature
public boolean isGenericInNature()Description copied from interface:ISymbolNatureIs this symbol a type that is generic in nature i.e. can it be parameterised with types. Aggregate Symbols can be defined to accept one or more parameters ie S and T.- Specified by:
isGenericInNaturein interfaceISymbolNature
-
isOpenForExtension
public boolean isOpenForExtension()Description copied from interface:ICanBeGenericIs the symbol open for extension or not. Typically, this means a function is open/abstract and therefore can/must be extended. The same with classes and components.- Specified by:
isOpenForExtensionin interfaceICanBeGeneric
-
setOpenForExtension
public void setOpenForExtension(boolean open) -
isConceptualTypeParameter
public boolean isConceptualTypeParameter()Is this itself a 'conceptual' type.- Specified by:
isConceptualTypeParameterin interfaceISymbolNature
-
setConceptualTypeParameter
public void setConceptualTypeParameter(boolean conceptualTypeParameter) Set this type symbol to be conceptual in nature. -
getGenericSymbolReferences
Description copied from interface:ICanBeGenericUsed to keep track of any generic types/functions used in a generic type that use some or all of the generic type parameters or arguments. For example a 'List of type T' might use or return an 'Iterator of type T'. It is the 'Iterator' that would be a generic symbol reference.- Specified by:
getGenericSymbolReferencesin interfaceICanBeGeneric
-
addGenericSymbolReference
Add a reference to a parameterised function. I'm still in two minds about adding these references. Leave as is at the moment, and then see what I think later on.- Specified by:
addGenericSymbolReferencein interfaceICanBeGeneric
-
addTypeParameterOrArgument
Add a parameter type to this scope.- Specified by:
addTypeParameterOrArgumentin interfaceICanBeGeneric
-
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 classSymbol- Returns:
- a user presentable of the symbol name.
-
getAnyGenericParamsAsFriendlyNames
-
getAnyConceptualTypeParameters
If this scope has been parameterised, then go through those parameters and return a list of all those that are generic 'T' in nature and not actually concrete types.- Specified by:
getAnyConceptualTypeParametersin interfaceICanBeGeneric
-
getTypeParameterOrArguments
- Specified by:
getTypeParameterOrArgumentsin interfaceICanBeGeneric
-
resolveFromParameterTypes
Used when the type/function is one that is generic/template. It will have a number of parameterTypes, these are 'T' and the like. The conceptual or concrete types. -
resolveInThisScopeOnly
Description copied from interface:IScopeJust look in own scope.- Specified by:
resolveInThisScopeOnlyin interfaceIScope- Overrides:
resolveInThisScopeOnlyin classCaptureScopedSymbol
-
resolve
So this is where we alter the mechanism of normal symbol resolution.- Specified by:
resolvein interfaceIScope- Overrides:
resolvein classScopedSymbol
-
getDefinitionContext
Get the definition context (AST node) for this generic type. Only present for generic types (isGenericInNature() == true) that were created from EK9 source code (not extern/built-in types).- Returns:
- The ParserRuleContext (ClassDeclarationContext or FunctionDeclarationContext) where this generic type was defined, or empty if not available.
-
setDefinitionContext
public void setDefinitionContext(org.antlr.v4.runtime.ParserRuleContext ctx) Set the definition context (AST node) for this generic type. Called during Phase 1 symbol definition when creating generic types from EK9 source.- Parameters:
ctx- The ParserRuleContext where this generic type was defined.
-
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 classCaptureScopedSymbol
-
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 classCaptureScopedSymbol
-