Package gw.lang.parser
Class StandardSymbolTable
- java.lang.Object
-
- gw.lang.parser.StandardSymbolTable
-
- All Implemented Interfaces:
IStackProvider,ISymbolTable
public class StandardSymbolTable extends java.lang.Object implements ISymbolTable
-
-
Field Summary
Fields Modifier and Type Field Description private int_iScopeCsrprivate int[]_scopeSizesThe sizes of the scopes are maintained in the array.private java.util.LinkedList_stackPrivateGlobalScopesprivate java.util.ArrayList_stackScopesstatic java.lang.reflect.MethodPRINT-
Fields inherited from interface gw.lang.parser.IStackProvider
START_POS, SUPER_POS, THIS_POS
-
-
Constructor Summary
Constructors Modifier Constructor Description StandardSymbolTable()StandardSymbolTable(boolean bDefineCommonSymbols)privateStandardSymbolTable(StandardSymbolTable source)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private IScopeaddScope(IScope scope)ISymbolTablecopy()Perform a semi-deep copy of this symbol table.private IScopecreateScope(IActivationContext activationCtx)voiddefineCommonSymbols()Define symbols that are considered ubiquitous.private voidensureIsolatedScopeSizesCapacity()private ISymbolgetGlobalSymbol(java.lang.CharSequence strName)private voidgetGlobalSymbols(java.util.Map symbols, int iPrivateGlobalIndex)private intgetIndexOfGlobalScope(IScope globalScope)private intgetInsertionIndexOfGlobalScope()intgetNextStackIndex()For compile-time assignment of stack indexes.intgetNextStackIndexForScope(IScope scope)For compile-time assignment of stack indexes.private intgetNextStackIndexForScopeIndex(int csr)intgetPrivateGlobalScopeCount()private ISymbolgetPrivateGlobalSymbol(java.lang.CharSequence strName)private voidgetPrivateGlobalSymbols(java.util.Map symbols, int iPrivateGlobalIndex)intgetScopeCount()ISymbolgetSymbol(java.lang.CharSequence name)private ISymbolgetSymbol(java.lang.CharSequence strName, int iStartIndex)java.util.MapgetSymbols()java.util.MapgetSymbols(int iStartIndex, int iPrivateGlobalIndex)private voidgetSymbols(java.util.Map symbols, int iStartIndex, int iPrivateGlobalIndex)ISymbolgetThisSymbolFromStackOrMap()Get the 'this' symbol from either the stack or the table.intgetTotalSymbolCount()booleanhasIsolatedScope()For compile-time use.private voidinit()booleanisSymbolWithinScope(ISymbol symToFind, IScope containingScope)IScopepeekIsolatedScope()IScopepeekScope()IScopepeekScope(int iPos)voidpopGlobalScope(IScope scope)Pops a global scope previously pushed viapushGlobalScope( IScope )orpushPrivateGlobalScope( IScope ).IScopepopScope()Pop a local scope context from the symbol table.IScopepopScope(IScope scope)IScopepushIsolatedScope(IActivationContext activationCtx)Push a scope that demarcates an activation record.voidpushPrivateGlobalScope(IScope scope)Push a global scope you specify onto the private global scope space.IScopepushScope()Push a local scope context onto the symbol table.IScopepushScope(IScope scope)Push a local scope context onto the symbol table.voidputSymbol(ISymbol symbol)Maps a name to a symbol in the table.private voidremoveGlobalScope(IScope globalScope)ISymbolremoveSymbol(java.lang.CharSequence name)Removes a previously mapped symbol.java.lang.StringtoString()
-
-
-
Field Detail
-
PRINT
public static final java.lang.reflect.Method PRINT
-
_stackScopes
private java.util.ArrayList _stackScopes
-
_stackPrivateGlobalScopes
private java.util.LinkedList _stackPrivateGlobalScopes
-
_scopeSizes
private int[] _scopeSizes
The 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 Detail
-
StandardSymbolTable
public StandardSymbolTable()
-
StandardSymbolTable
public StandardSymbolTable(boolean bDefineCommonSymbols)
- Parameters:
bDefineCommonSymbols-
-
StandardSymbolTable
private StandardSymbolTable(StandardSymbolTable source)
- Parameters:
source-
-
-
Method Detail
-
init
private void init()
-
getSymbol
public ISymbol getSymbol(java.lang.CharSequence name)
- Specified by:
getSymbolin interfaceISymbolTable- Returns:
- The symbol mapped to the specified name.
-
putSymbol
public void putSymbol(ISymbol symbol)
Description copied from interface:ISymbolTableMaps a name to a symbol in the table.- Specified by:
putSymbolin interfaceISymbolTable
-
removeSymbol
public ISymbol removeSymbol(java.lang.CharSequence name)
Description copied from interface:ISymbolTableRemoves a previously mapped symbol.- Specified by:
removeSymbolin interfaceISymbolTable- Parameters:
name- The name mapped to the symbol to remove.
-
getTotalSymbolCount
public int getTotalSymbolCount()
- Specified by:
getTotalSymbolCountin interfaceISymbolTable- Returns:
- the number of symbols exist in this table.
-
getSymbols
public java.util.Map getSymbols()
- Specified by:
getSymbolsin interfaceISymbolTable- Returns:
- A list of currently mapped ISymbols e.g., the values in a hash table based implementation.
-
getSymbols
public java.util.Map getSymbols(int iStartIndex, int iPrivateGlobalIndex)- Specified by:
getSymbolsin 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:
getScopeCountin 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:
ISymbolTable.getSymbols(int,int)
-
getPrivateGlobalScopeCount
public int getPrivateGlobalScopeCount()
- Specified by:
getPrivateGlobalScopeCountin 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:
ISymbolTable.getSymbols(int,int)
-
pushScope
public IScope pushScope()
Description copied from interface:ISymbolTablePush a local scope context onto the symbol table.- Specified by:
pushScopein interfaceISymbolTable- Returns:
- The pushed scope.
-
pushScope
public IScope pushScope(IScope scope)
Description copied from interface:ISymbolTablePush a local scope context onto the symbol table.- Specified by:
pushScopein interfaceISymbolTable- Parameters:
scope- the scope to push- Returns:
- The pushed scope.
-
pushPrivateGlobalScope
public void pushPrivateGlobalScope(IScope scope)
Description copied from interface:ISymbolTablePush 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:
pushPrivateGlobalScopein interfaceISymbolTable- See Also:
ISymbolTable.pushScope(),ISymbolTable.pushIsolatedScope(IActivationContext)
-
popGlobalScope
public void popGlobalScope(IScope scope)
Description copied from interface:ISymbolTablePops a global scope previously pushed viapushGlobalScope( IScope )orpushPrivateGlobalScope( IScope ). You probably shouldn't call this method.- Specified by:
popGlobalScopein interfaceISymbolTable- See Also:
ISymbolTable.pushPrivateGlobalScope(IScope),ISymbolTable.popScope()
-
pushIsolatedScope
public IScope pushIsolatedScope(IActivationContext activationCtx)
Description copied from interface:ISymbolTablePush 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:
pushIsolatedScopein interfaceISymbolTable- Parameters:
activationCtx- The context for the activation record.- Returns:
- The isolated scope (aka the activation record).
-
popScope
public IScope popScope()
Description copied from interface:ISymbolTablePop a local scope context from the symbol table. See pushScope() for implementation suggestions.- Specified by:
popScopein interfaceISymbolTable- Returns:
- The popped scope.
-
popScope
public IScope popScope(IScope scope)
- Specified by:
popScopein interfaceISymbolTable
-
copy
public ISymbolTable copy()
Description copied from interface:ISymbolTablePerform a semi-deep copy of this symbol table. Symbols need not be cloned.- Specified by:
copyin interfaceISymbolTable- Returns:
- A semi-deep copy of this symbol table.
-
getThisSymbolFromStackOrMap
public ISymbol getThisSymbolFromStackOrMap()
Description copied from interface:ISymbolTableGet the 'this' symbol from either the stack or the table.- Specified by:
getThisSymbolFromStackOrMapin interfaceISymbolTable
-
defineCommonSymbols
public void defineCommonSymbols()
Description copied from interface:ISymbolTableDefine symbols that are considered ubiquitous. There may be none.- Specified by:
defineCommonSymbolsin interfaceISymbolTable
-
isSymbolWithinScope
public boolean isSymbolWithinScope(ISymbol symToFind, IScope containingScope)
- Specified by:
isSymbolWithinScopein interfaceISymbolTable- Returns:
- true if the given symbol is within the given scope
-
peekIsolatedScope
public IScope peekIsolatedScope()
- Specified by:
peekIsolatedScopein interfaceISymbolTable- Returns:
- the top-most isolated scope
-
getNextStackIndex
public int getNextStackIndex()
For compile-time assignment of stack indexes.- Specified by:
getNextStackIndexin interfaceIStackProvider
-
getNextStackIndexForScope
public int getNextStackIndexForScope(IScope scope)
For compile-time assignment of stack indexes.- Specified by:
getNextStackIndexForScopein interfaceIStackProvider
-
getNextStackIndexForScopeIndex
private int getNextStackIndexForScopeIndex(int csr)
-
hasIsolatedScope
public boolean hasIsolatedScope()
Description copied from interface:IStackProviderFor compile-time use. Returns true iff an isolated scope is visible.- Specified by:
hasIsolatedScopein interfaceIStackProvider
-
getSymbol
private ISymbol getSymbol(java.lang.CharSequence strName, int iStartIndex)
-
getGlobalSymbol
private ISymbol getGlobalSymbol(java.lang.CharSequence strName)
-
getPrivateGlobalSymbol
private ISymbol getPrivateGlobalSymbol(java.lang.CharSequence strName)
-
createScope
private IScope createScope(IActivationContext activationCtx)
-
removeGlobalScope
private void removeGlobalScope(IScope globalScope)
-
getIndexOfGlobalScope
private int getIndexOfGlobalScope(IScope globalScope)
-
getInsertionIndexOfGlobalScope
private int getInsertionIndexOfGlobalScope()
-
getSymbols
private void getSymbols(java.util.Map symbols, int iStartIndex, int iPrivateGlobalIndex)
-
getGlobalSymbols
private void getGlobalSymbols(java.util.Map symbols, int iPrivateGlobalIndex)
-
getPrivateGlobalSymbols
private void getPrivateGlobalSymbols(java.util.Map symbols, int iPrivateGlobalIndex)
-
peekScope
public IScope peekScope()
- Specified by:
peekScopein interfaceISymbolTable- Returns:
- the currently active scope
-
peekScope
public IScope peekScope(int iPos)
- Specified by:
peekScopein interfaceISymbolTable
-
ensureIsolatedScopeSizesCapacity
private void ensureIsolatedScopeSizesCapacity()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-