public interface Scope
Represents a scope in the Qilletni type system. A scope is a mapping of names to symbols and functions, allowing the
resolution and definition of variables and functions within different levels of visibility, such as global, local,
or within specific entities. This interface provides methods for looking up symbols and functions, defining new
variables or functions, and retrieving metadata about the scope.
Scopes have parents, and depending on the condition, will look up to their parent to see if a symbol exists.
Scopes have parents, and depending on the condition, will look up to their parent to see if a symbol exists.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumHow the scope is used or defined. -
Method Summary
Modifier and TypeMethodDescription<T extends QilletniType>
voidDefines the given symbol this scope.voiddefineFunction(Symbol<FunctionType> functionSymbol) Defines the given function in this scope.Gets all function symbols in the current scope, as a map of names and list of matching functions with the name.Gets all symbols in the current scope, as a map of names and values.Gets a unique readable name of the scope, for debugging purposes.Gets the parent scope, if any.Gets the type of the scope, meaning how it is used or defined.booleanChecks if the given symbol name is defined in this scope or any applicable parent scopes.booleanisDirectlyDefined(String name) Checks if the given symbol name is defined in this direct scope.booleanisFunctionDefined(String name) Checks if the given function name is defined in this scope or any applicable parent scopes.<T extends QilletniType>
Symbol<T> Looks up a symbol or function in the current scope and any parents by name.lookupFunction(String name) Looks up all functions with the given name.lookupFunction(String name, int params) Looks up a function with a given name and number of parameters.lookupFunction(String name, int params, QilletniTypeClass<?> onType) Looks up a function with a given name and number of parameters, that is on a type (either defined in an entity or is an extension method).lookupFunctionOptionally(String name, int params, QilletniTypeClass<?> onType) Looks up a function with a given name and number of parameters.voidsetDebugDesc(String desc) Sets the debug description, for identification.
-
Method Details
-
lookup
Looks up a symbol or function in the current scope and any parents by name. If the name begins with a_the parent scope (if any) will not be checked. If the symbol is not found, an exception is thrown. To check beforehand if the variable would be found, checkisDefined(String).- Type Parameters:
T- The type of the symbol- Parameters:
name- The name of the symbol to look up- Returns:
- The found symbol
-
lookupFunction
Looks up a function with a given name and number of parameters. If the function is not found, an exception is thrown. To check beforehand if the variable would be found, checkisFunctionDefined(String).- Parameters:
name- The name of the functionparams- The number of parameters the function has- Returns:
- The found symbol
-
lookupFunction
Looks up a function with a given name and number of parameters, that is on a type (either defined in an entity or is an extension method). If the function is not found, an exception is thrown. To check beforehand if the variable would be found, checkisFunctionDefined(String).- Parameters:
name- The name of the functionparams- The number of parameters the function has- Returns:
- The found symbol
-
lookupFunctionOptionally
Optional<Symbol<FunctionType>> lookupFunctionOptionally(String name, int params, QilletniTypeClass<?> onType) Looks up a function with a given name and number of parameters. If theonTypeis not null, it will look one up that is on a type (either defined in an entity or is an extension method). If the function is not found, an empty optional is returned.- Parameters:
name- The name of the functionparams- The number of parameters the function has- Returns:
- The found symbol, if any
-
lookupFunction
Looks up all functions with the given name. Each one will have different parameters.- Parameters:
name- The name of the function- Returns:
- All found symbols, or an empty list
-
isDefined
Checks if the given symbol name is defined in this scope or any applicable parent scopes.- Parameters:
name- The name of the symbol to look up- Returns:
- If the symbol is defined
-
isDirectlyDefined
Checks if the given symbol name is defined in this direct scope. This does not check any parents.- Parameters:
name- The name of the symbol to look up- Returns:
- If the symbol is defined
-
isFunctionDefined
Checks if the given function name is defined in this scope or any applicable parent scopes.- Parameters:
name- The name of the function to look up- Returns:
- If the function is defined
-
define
Defines the given symbol this scope. An exception will be thrown if the symbol is already defined.- Type Parameters:
T- The type of the symbol- Parameters:
symbol- The symbol to define
-
defineFunction
Defines the given function in this scope. An exception will be thrown if the function is already defined with the same signature.- Parameters:
functionSymbol- The function to define
-
getAllSymbols
-
getAllFunctionSymbols
Map<String,List<Symbol<FunctionType>>> getAllFunctionSymbols()Gets all function symbols in the current scope, as a map of names and list of matching functions with the name. The value is a list because multiple functions with different argument counts can have the same name.- Returns:
- The map of function symbols
-
getScopeType
Scope.ScopeType getScopeType()Gets the type of the scope, meaning how it is used or defined.- Returns:
- The type of the scope
-
getParent
-
getDebugDesc
String getDebugDesc()Gets a unique readable name of the scope, for debugging purposes.- Returns:
- The identifying string, for debugging
-
setDebugDesc
Sets the debug description, for identification.- Parameters:
desc- The new description
-