java.lang.Object
com.port80.eclipse.csharp.llk.ast.ScopeStack
- All Implemented Interfaces:
- ILLKScope, IScopeStack
- public class ScopeStack
- extends java.lang.Object
- implements IScopeStack
Scope stack is used by the parser to keep track of the current
lexical scopes and performs symbol lookups.
. Scope stack from bottom to top:
RootContext scope
CompilationUnit scope
TopLevelClass scope
class/block/method...etc. scopes
...
. When a variable is encountered in the statement, its type is
determined by searching the scopes from the top of the scope stack
downwards until it found the variable declaration/definition. If
a scope belongs to an IType (parent!=null), IType would
search the super-class and/or super-interfaces.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NAME
private static final java.lang.String NAME
- See Also:
- Constant Field Values
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
main
protected com.port80.eclipse.csharp.llk.parser.ILLKMain main
top
protected ILLKScope top
classLevel
protected int classLevel
- Current top of stack object.
stack
protected java.util.List stack
- Number of IType on stack.
ScopeStack
public ScopeStack(com.port80.eclipse.csharp.llk.parser.ILLKMain main)
push
public void push(java.lang.Object o)
- Specified by:
push in interface IScopeStack
pop
public ILLKScope pop()
- Specified by:
pop in interface IScopeStack
empty
public boolean empty()
- Specified by:
empty in interface IScopeStack
peek
public ILLKScope peek()
- Specified by:
peek in interface IScopeStack
size
public int size()
- Specified by:
size in interface IScopeStack
get
public ILLKScope get(int i)
- Specified by:
get in interface IScopeStack
getRootContext
public com.port80.eclipse.csharp.llk.parser.ASTRootContext getRootContext()
- Specified by:
getRootContext in interface IScopeStack
getCompilationUnit
public com.port80.eclipse.csharp.llk.parser.ASTCompilationUnit getCompilationUnit()
- Specified by:
getCompilationUnit in interface IScopeStack
isClassScope
public boolean isClassScope()
- Specified by:
isClassScope in interface IScopeStack
getClassLevel
public int getClassLevel()
- Specified by:
getClassLevel in interface IScopeStack
getCurrentClass
public Type getCurrentClass()
- Specified by:
getCurrentClass in interface IScopeStack
getTopLevelClass
public Type getTopLevelClass()
- Specified by:
getTopLevelClass in interface IScopeStack
getName
public java.lang.String getName()
- Specified by:
getName in interface ILLKScope
keySet
public java.util.Set keySet()
- Specified by:
keySet in interface ILLKScope
putSymbol
public ISymbol putSymbol(ISymbol sym)
- Specified by:
putSymbol in interface ILLKScope
putType
public ISymbol putType(java.lang.String key,
ISymbol sym)
- Specified by:
putType in interface ILLKScope
putVar
public ISymbol putVar(java.lang.String key,
ISymbol sym)
- Specified by:
putVar in interface ILLKScope
putMethod
public ISymbol putMethod(java.lang.String key,
ISymbol sym)
- Specified by:
putMethod in interface ILLKScope
putSymbolList
public void putSymbolList(java.util.List aList)
- Specified by:
putSymbolList in interface ILLKScope
getVar
public ISymbol getVar(java.lang.String varname)
- Specified by:
getVar in interface ILLKScope
getMethod
public ISymbol getMethod(java.lang.String sig)
- Specified by:
getMethod in interface ILLKScope
getType
public ISymbol getType(java.lang.String typename)
- Lookup a type symbol.
. Accept both simple type name and qualified type name. To lookup a qualified
type name, the first prefix in the qualified name is lookup as a simple name.
Follow suffices are then lookup its prefix's scope. If the first prefix is
not found, try again with the second prefix is concatenated to the first.
If none of the prefix are found, return error (null).
. Looking up a simple type name is rather complicated because it involve search
through the scope stack, the package and the import list.
. If a class symbol is not declared in this compilation unit, search
the oneTypeImportList, then the package scope, then onDemandImportList
- Specified by:
getType in interface ILLKScope
dumpScope
public void dumpScope(java.lang.String indent)
- Specified by:
dumpScope in interface ILLKScope
getSimpleType
public ISymbol getSimpleType(java.lang.String typename)
- Specified by:
getSimpleType in interface IScopeStack
importType
public ISymbol importType(java.lang.String typename)
findClass
public Type findClass(java.lang.String canonical_name)
- Find a class with specified canonical name in this compilation unit.
Load one from the system if not found.
- Specified by:
findClass in interface IScopeStack
findClass
public Type findClass(java.lang.Class c)
- Find the class definition (IType) for a Class. Create one if
not yet exist.
loadClass
public Type loadClass(java.lang.Class c)
loadClass
public Type loadClass(java.lang.String name)
- Specified by:
loadClass in interface IScopeStack