Package gw.lang.parser
Class StandardSymbolTable
java.lang.Object
gw.lang.parser.StandardSymbolTable
- All Implemented Interfaces:
IStackProvider
,ISymbolTable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private int[]
The sizes of the scopes are maintained in the array.private LinkedList
private ArrayList
static final Method
Fields inherited from interface gw.lang.parser.IStackProvider
START_POS, SUPER_POS, THIS_POS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate IScope
copy()
Perform a semi-deep copy of this symbol table.private IScope
createScope
(IActivationContext activationCtx) void
Define symbols that are considered ubiquitous.private void
private ISymbol
getGlobalSymbol
(CharSequence strName) private void
getGlobalSymbols
(Map symbols, int iPrivateGlobalIndex) private int
getIndexOfGlobalScope
(IScope globalScope) private int
int
For compile-time assignment of stack indexes.int
getNextStackIndexForScope
(IScope scope) For compile-time assignment of stack indexes.private int
getNextStackIndexForScopeIndex
(int csr) int
private ISymbol
getPrivateGlobalSymbol
(CharSequence strName) private void
getPrivateGlobalSymbols
(Map symbols, int iPrivateGlobalIndex) int
getSymbol
(CharSequence name) private ISymbol
getSymbol
(CharSequence strName, int iStartIndex) getSymbols
(int iStartIndex, int iPrivateGlobalIndex) private void
getSymbols
(Map symbols, int iStartIndex, int iPrivateGlobalIndex) Get the 'this' symbol from either the stack or the table.int
boolean
For compile-time use.private void
init()
boolean
isSymbolWithinScope
(ISymbol symToFind, IScope containingScope) peekScope
(int iPos) void
popGlobalScope
(IScope scope) Pops a global scope previously pushed viapushGlobalScope( IScope )
orpushPrivateGlobalScope( IScope )
.popScope()
Pop a local scope context from the symbol table.pushIsolatedScope
(IActivationContext activationCtx) Push a scope that demarcates an activation record.void
pushPrivateGlobalScope
(IScope scope) Push a global scope you specify onto the private global scope space.Push a local scope context onto the symbol table.Push a local scope context onto the symbol table.void
Maps a name to a symbol in the table.private void
removeGlobalScope
(IScope globalScope) removeSymbol
(CharSequence name) Removes a previously mapped symbol.toString()
-
Field Details
-
PRINT
-
_stackScopes
-
_stackPrivateGlobalScopes
-
_scopeSizes
private int[] _scopeSizesThe sizes of the scopes are maintained in the array. Note the zeroth one is reserved for the Global scope, which may or may not be meainingful depending on the context e.g., plain expressions have a global scope, but gosu classes don't. -
_iScopeCsr
private int _iScopeCsr
-
-
Constructor Details
-
StandardSymbolTable
public StandardSymbolTable() -
StandardSymbolTable
public StandardSymbolTable(boolean bDefineCommonSymbols) - Parameters:
bDefineCommonSymbols
-
-
StandardSymbolTable
- Parameters:
source
-
-
-
Method Details
-
init
private void init() -
getSymbol
- Specified by:
getSymbol
in interfaceISymbolTable
- Returns:
- The symbol mapped to the specified name.
-
putSymbol
Description copied from interface:ISymbolTable
Maps a name to a symbol in the table.- Specified by:
putSymbol
in interfaceISymbolTable
-
removeSymbol
Description copied from interface:ISymbolTable
Removes a previously mapped symbol.- Specified by:
removeSymbol
in interfaceISymbolTable
- Parameters:
name
- The name mapped to the symbol to remove.
-
getTotalSymbolCount
public int getTotalSymbolCount()- Specified by:
getTotalSymbolCount
in interfaceISymbolTable
- Returns:
- the number of symbols exist in this table.
-
getSymbols
- Specified by:
getSymbols
in interfaceISymbolTable
- Returns:
- A list of currently mapped ISymbols e.g., the values in a hash table based implementation.
-
getSymbols
- Specified by:
getSymbols
in interfaceISymbolTable
- Parameters:
iStartIndex
- Scopes positioned on the stack at an index greater than this number are not included. Very useful for examining a specific scope e.g., for a debugger. Note an index < 0 indicates that all scopes are included.- Returns:
- A list of currently mapped ISymbols e.g., the values in a hash table based implementation.
-
getScopeCount
public int getScopeCount()- Specified by:
getScopeCount
in interfaceISymbolTable
- Returns:
- The number of scopes on the stack. These include all scopes: global, isolated, and local. Useful for recording a specific offset in the symbol table e.g., a debugger needs this to jump to a position in a call stack.
- See Also:
-
getPrivateGlobalScopeCount
public int getPrivateGlobalScopeCount()- Specified by:
getPrivateGlobalScopeCount
in interfaceISymbolTable
- Returns:
- The number of scopes on the private global stack. Useful for recording a specific offset in the symbol table e.g., a debugger needs this to jump to a position in a call stack.
- See Also:
-
pushScope
Description copied from interface:ISymbolTable
Push a local scope context onto the symbol table.- Specified by:
pushScope
in interfaceISymbolTable
- Returns:
- The pushed scope.
-
pushScope
Description copied from interface:ISymbolTable
Push a local scope context onto the symbol table.- Specified by:
pushScope
in interfaceISymbolTable
- Parameters:
scope
- the scope to push- Returns:
- The pushed scope.
-
pushPrivateGlobalScope
Description copied from interface:ISymbolTable
Push a global scope you specify onto the private global scope space. Useful for handling private global scopes for libraries, namespaces, etc. As this functionality is primarily for Gosu runtime, you'll likely never need to call this. If you need to push a scope with restricted visibility, consider callingpushIsolatedScope()
instead.- Specified by:
pushPrivateGlobalScope
in interfaceISymbolTable
- See Also:
-
popGlobalScope
Description copied from interface:ISymbolTable
Pops a global scope previously pushed viapushGlobalScope( IScope )
orpushPrivateGlobalScope( IScope )
. You probably shouldn't call this method.- Specified by:
popGlobalScope
in interfaceISymbolTable
- See Also:
-
pushIsolatedScope
Description copied from interface:ISymbolTable
Push a scope that demarcates an activation record. The behavior is nearly identical to pushScope(), the [big] difference is that activation record scopes cannot access symbols from other activation record scopes. Use popScope() to pop a scope pushed via this method.- Specified by:
pushIsolatedScope
in interfaceISymbolTable
- Parameters:
activationCtx
- The context for the activation record.- Returns:
- The isolated scope (aka the activation record).
-
popScope
Description copied from interface:ISymbolTable
Pop a local scope context from the symbol table. See pushScope() for implementation suggestions.- Specified by:
popScope
in interfaceISymbolTable
- Returns:
- The popped scope.
-
popScope
- Specified by:
popScope
in interfaceISymbolTable
-
copy
Description copied from interface:ISymbolTable
Perform a semi-deep copy of this symbol table. Symbols need not be cloned.- Specified by:
copy
in interfaceISymbolTable
- Returns:
- A semi-deep copy of this symbol table.
-
getThisSymbolFromStackOrMap
Description copied from interface:ISymbolTable
Get the 'this' symbol from either the stack or the table.- Specified by:
getThisSymbolFromStackOrMap
in interfaceISymbolTable
-
defineCommonSymbols
public void defineCommonSymbols()Description copied from interface:ISymbolTable
Define symbols that are considered ubiquitous. There may be none.- Specified by:
defineCommonSymbols
in interfaceISymbolTable
-
isSymbolWithinScope
- Specified by:
isSymbolWithinScope
in interfaceISymbolTable
- Returns:
- true if the given symbol is within the given scope
-
peekIsolatedScope
- Specified by:
peekIsolatedScope
in interfaceISymbolTable
- Returns:
- the top-most isolated scope
-
getNextStackIndex
public int getNextStackIndex()For compile-time assignment of stack indexes.- Specified by:
getNextStackIndex
in interfaceIStackProvider
-
getNextStackIndexForScope
For compile-time assignment of stack indexes.- Specified by:
getNextStackIndexForScope
in interfaceIStackProvider
-
getNextStackIndexForScopeIndex
private int getNextStackIndexForScopeIndex(int csr) -
hasIsolatedScope
public boolean hasIsolatedScope()Description copied from interface:IStackProvider
For compile-time use. Returns true iff an isolated scope is visible.- Specified by:
hasIsolatedScope
in interfaceIStackProvider
-
getSymbol
-
getGlobalSymbol
-
getPrivateGlobalSymbol
-
addScope
-
createScope
-
removeGlobalScope
-
getIndexOfGlobalScope
-
getInsertionIndexOfGlobalScope
private int getInsertionIndexOfGlobalScope() -
getSymbols
-
getGlobalSymbols
-
getPrivateGlobalSymbols
-
peekScope
- Specified by:
peekScope
in interfaceISymbolTable
- Returns:
- the currently active scope
-
peekScope
- Specified by:
peekScope
in interfaceISymbolTable
-
ensureIsolatedScopeSizesCapacity
private void ensureIsolatedScopeSizesCapacity() -
toString
-