public interface SymbolTable
Represents a symbol table in the Qilletni type system. A symbol table is a collection of scopes, each of which
contains a mapping of names to
Symbol, allowing the resolution and definition of symbols. The current scope
is represented by a stack of scopes, and may be pushed, popped, or swapped with another scope.-
Method Summary
Modifier and TypeMethodDescriptionGets the current scope.Ends a function call's scope as created viafunctionCall(), bringing it back to the original.Resets the current scope to one that is only parents with the global one, or the function definitions' parent entity.Gets all available scopes, both used and unused.intgetId()Gets the unique ID of theSymbolTable, generally for debugging purposes.Initializes the symbol table with a given global scope as the parent.voidpopScope()Pops the current scope off the stack, and sets the parent scope as the current one.Creates a new scope as a child of the previous parent one and returns it.Swaps the current scope with a new one, and returns the new scope.Restores a previous scope that was swapped out viaswapScope(Scope).
-
Method Details
-
initScope
Initializes the symbol table with a given global scope as the parent. This method is invoked when each file is parsed. The global scope is the parent of all other scopes.- Parameters:
globalScope- The scope to set as the parent, shared by all other scopes- Returns:
- The created
Scope
-
pushScope
Scope pushScope()Creates a new scope as a child of the previous parent one and returns it.- Returns:
- The new, empty scope
-
swapScope
Swaps the current scope with a new one, and returns the new scope. The previous scope is added to a stack, and can be restored viaunswapScope().- Parameters:
newScope- The new scope to swap to- Returns:
- The new scope
-
unswapScope
Scope unswapScope()Restores a previous scope that was swapped out viaswapScope(Scope).- Returns:
- The new current scope
-
popScope
void popScope()Pops the current scope off the stack, and sets the parent scope as the current one. -
currentScope
-
functionCall
Scope functionCall()Resets the current scope to one that is only parents with the global one, or the function definitions' parent entity.- Returns:
- The new current scope
-
endFunctionCall
Scope endFunctionCall()Ends a function call's scope as created viafunctionCall(), bringing it back to the original.- Returns:
- The new current scope
-
getAllScopes
-
getId
int getId()Gets the unique ID of theSymbolTable, generally for debugging purposes.- Returns:
- The ID of the symbol table
-