Class Symbol
- All Implemented Interfaces:
Serializable, ISymbol, ISymbolNature, ITokenReference
- Direct Known Subclasses:
ConstantSymbol, ExpressionSymbol, ParamExpressionSymbol, ScopedSymbol, StreamPipeLineSymbol, VariableSymbol
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClone the symbol and re-parent if this symbol like a method should have a parent.protected SymbolcloneIntoSymbol(Symbol newCopy) copySymbolProperties(Symbol newCopy) Just copies the properties over.booleanTwo symbols are the same symbol when they agree on name, category, genus, mutability AND the declaration site they came from.doubledoubleProvide the name an end user would need to see on the screen.Provide the internal fully qualified name of this symbol.getGenus()getName()Provide the internal name of this symbol - not fully qualified in terms of the module it is in.booleanprotected StringgetSymbolTypeAsString(Optional<ISymbol> type) getType()doubleinthashCode()Mixes in exactly the fieldsequals(Object)compares, and nothing else.booleanbooleanbooleanbooleanIs this a core thing from EK9.booleanisExactSameType(ISymbol symbolType) Checks if the type match exactly.booleanbooleanbooleanThis symbol itself can be marked as pure - i.e.booleanEven constants can be mutable until set.booleanbooleanFor some symbols we might support the _promote method via coercion.booleanvoidputSquirrelledData(CommonValues key, String value) Sometimes it's important to 'squirrel' away information during different phases of the compilation.voidsetCategory(SymbolCategory category) voidsetEk9Core(boolean ek9Core) set this symbol as an EK9 core symbol.voidsetGenus(SymbolGenus genus) voidsetInitialisedBy(IToken initialisedBy) voidsetInjectionExpected(boolean injectionExpected) voidsetMarkedPure(boolean markedPure) voidvoidvoidsetNullAllowed(boolean nullAllowed) voidsetParsedModule(Optional<Module> module) For some symbols you may wish to specify the parsed module they were defined in.voidsetProduceFullyQualifiedName(boolean produceFullyQualifiedName) voidsetReferenced(boolean referenced) voidsetSourceToken(IToken sourceToken) toString()Methods inherited from interface ISymbol
isDeclaredAsConstant, isExtensionOfInjectable, isFromLiteral, isIncomingParameter, isInitialised, isInjectable, isLoopVariable, isMarkedAbstract, isPrivate, isPropertyField, isProtected, isPublic, isReturningParameter, setTypeMethods inherited from interface ISymbolNature
isApplication, isConceptualTypeParameter, isConstant, isControl, isFunction, isGenericInNature, isMethod, isParameterisedType, isPrimitiveType, isTemplateFunction, isTemplateType, isType, isVariable
-
Constructor Details
-
Symbol
-
Symbol
-
-
Method Details
-
clone
-
cloneIntoSymbol
-
copySymbolProperties
-
isMarkedPure
public boolean isMarkedPure()Description copied from interface:ISymbolThis symbol itself can be marked as pure - i.e. an operator with no side effects.- Specified by:
isMarkedPurein interfaceISymbol- 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:
isReferencedin interfaceISymbol
-
setReferenced
public void setReferenced(boolean referenced) - Specified by:
setReferencedin interfaceISymbol
-
putSquirrelledData
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:
putSquirrelledDatain interfaceISymbol
-
getSquirrelledData
- Specified by:
getSquirrelledDatain interfaceISymbol
-
isMutable
public boolean isMutable()Description copied from interface:ISymbolEven 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. -
setNotMutable
public void setNotMutable()- Specified by:
setNotMutablein interfaceISymbol
-
isNullAllowed
public boolean isNullAllowed()- Specified by:
isNullAllowedin interfaceISymbol
-
setNullAllowed
public void setNullAllowed(boolean nullAllowed) - Specified by:
setNullAllowedin interfaceISymbol
-
isInjectionExpected
public boolean isInjectionExpected()- Specified by:
isInjectionExpectedin interfaceISymbol
-
setInjectionExpected
public void setInjectionExpected(boolean injectionExpected) - Specified by:
setInjectionExpectedin interfaceISymbol
-
isEk9Core
public boolean isEk9Core()Description copied from interface:ISymbolNatureIs this a core thing from EK9.- Specified by:
isEk9Corein interfaceISymbolNature
-
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:
isDevSourcein interfaceISymbol
-
isLibSource
public boolean isLibSource()- Specified by:
isLibSourcein interfaceISymbol
-
getProduceFullyQualifiedName
public boolean getProduceFullyQualifiedName() -
setProduceFullyQualifiedName
public void setProduceFullyQualifiedName(boolean produceFullyQualifiedName) -
getSourceToken
- Specified by:
getSourceTokenin interfaceISymbol- Specified by:
getSourceTokenin interfaceITokenReference
-
setSourceToken
- Specified by:
setSourceTokenin interfaceITokenReference
-
getInitialisedBy
- Specified by:
getInitialisedByin interfaceISymbol
-
setInitialisedBy
- Specified by:
setInitialisedByin interfaceISymbol
-
clearInitialisedBy
public void clearInitialisedBy()- Specified by:
clearInitialisedByin interfaceISymbol
-
getParsedModule
- Specified by:
getParsedModulein interfaceISymbol
-
setParsedModule
Description copied from interface:ISymbolFor some symbols you may wish to specify the parsed module they were defined in.- Specified by:
setParsedModulein interfaceISymbol- Parameters:
module- The parsedModule the symbol was defined in.
-
getFullyQualifiedName
Description copied from interface:ISymbolProvide 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:
getFullyQualifiedNamein interfaceISymbol
-
isExactSameType
Checks if the type match exactly.- Specified by:
isExactSameTypein interfaceISymbol
-
isAssignableTo
- Specified by:
isAssignableToin interfaceISymbol
-
isAssignableTo
- Specified by:
isAssignableToin interfaceISymbol
-
getAssignableCostTo
- Specified by:
getAssignableCostToin interfaceISymbol
-
getAssignableCostTo
- Specified by:
getAssignableCostToin interfaceISymbol
-
isPromotionSupported
Description copied from interface:ISymbolFor 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:
isPromotionSupportedin interfaceISymbol
-
getUnCoercedAssignableCostTo
- Specified by:
getUnCoercedAssignableCostToin interfaceISymbol
-
getCategory
- Specified by:
getCategoryin interfaceISymbolNature
-
setCategory
-
getGenus
- Specified by:
getGenusin interfaceISymbolNature
-
setGenus
- Specified by:
setGenusin interfaceISymbolNature
-
equals
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 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
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. -
hashCode
public int hashCode()Mixes in exactly the fieldsequals(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 byequals(Object). SeeSymbolEqualsHashCodeContractTest. -
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- Returns:
- a user presentable of the symbol name.
-
getSymbolTypeAsString
-
toString
-
getName
-
setName
-
getType
-
setType
-