|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpolyglot.ext.jl.types.Context_c
public class Context_c
This class maintains a context for looking up named variables, types, and methods. It's implemented as a stack of Context objects. Each Context points to an outer context. To enter a new scope, call one of the pushXXX methods. To leave a scope, just follow the outer() pointer. NodeVisitors handle leaving scope automatically. Each context object contains maps from names to variable, type, and method objects declared in that scope.
Nested Class Summary | |
---|---|
static class |
Context_c.Kind
|
Field Summary | |
---|---|
static Context_c.Kind |
BLOCK
|
static Context_c.Kind |
CLASS
|
protected CodeInstance |
code
|
static Context_c.Kind |
CODE
|
protected boolean |
inCode
|
protected ImportTable |
it
The import table for the file |
protected Context_c.Kind |
kind
|
protected Context |
outer
|
static Context_c.Kind |
OUTER
|
protected ParsedClassType |
scope
|
static Context_c.Kind |
SOURCE
|
protected boolean |
staticContext
Is the context static? |
protected TypeSystem |
ts
|
protected ClassType |
type
|
protected java.util.Map |
types
|
protected java.util.Map |
vars
|
Constructor Summary | |
---|---|
Context_c(TypeSystem ts)
|
Method Summary | |
---|---|
void |
addMethod(MethodInstance mi)
Deprecated. |
void |
addNamed(Named t)
Adds a named type object to the current scoping level. |
void |
addNamedToThisScope(Named type)
|
void |
addVariable(VarInstance vi)
Adds a symbol to the current scoping level. |
void |
addVariableToThisScope(VarInstance var)
|
java.lang.Object |
copy()
|
ClassType |
currentClass()
Gets current class |
ParsedClassType |
currentClassScope()
Gets current class |
CodeInstance |
currentCode()
Gets the current method |
Named |
find(java.lang.String name)
Finds the definition of a particular type. |
FieldInstance |
findField(java.lang.String name)
Gets a field of a particular name. |
ClassType |
findFieldScope(java.lang.String name)
Finds the class which added a field to the scope. |
Named |
findInThisScope(java.lang.String name)
|
LocalInstance |
findLocal(java.lang.String name)
Gets a local of a particular name. |
MethodInstance |
findMethod(java.lang.String name,
java.util.List argTypes)
Looks up a method with name "name" and arguments compatible with "argTypes". |
ClassType |
findMethodContainerInThisScope(java.lang.String name)
|
ClassType |
findMethodScope(java.lang.String name)
Finds the class which added a method to the scope. |
VarInstance |
findVariable(java.lang.String name)
Gets a local or field of a particular name. |
VarInstance |
findVariableInThisScope(java.lang.String name)
|
VarInstance |
findVariableSilent(java.lang.String name)
Gets a local or field of a particular name. |
ImportTable |
importTable()
Get import table currently in scope. |
boolean |
inCode()
Return true if in a method's scope and not in a local class within the innermost method. |
boolean |
inStaticContext()
Returns whether the current context is a static context. |
boolean |
isBlock()
|
boolean |
isClass()
|
boolean |
isCode()
|
boolean |
isLocal(java.lang.String name)
Returns whether the particular symbol is defined locally. |
boolean |
isOuter()
|
boolean |
isSource()
|
protected java.lang.String |
mapsToString()
|
Resolver |
outerResolver()
Get the outer-most resolver for the source file currently in scope. |
Package |
package_()
The current package, or null if not in a package. |
Context |
pop()
Pop the context. |
protected Context_c |
push()
|
Context |
pushBlock()
pushes an additional block-scoping level. |
Context |
pushClass(ParsedClassType classScope,
ClassType type)
Pushes on a class scoping. |
Context |
pushCode(CodeInstance ci)
enters a method |
Context |
pushSource(ImportTable it)
Push a source file scope. |
Context |
pushStatic()
pushes an additional static scoping level. |
java.lang.String |
toString()
|
TypeSystem |
typeSystem()
The type system. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Context outer
protected TypeSystem ts
public static final Context_c.Kind BLOCK
public static final Context_c.Kind CLASS
public static final Context_c.Kind CODE
public static final Context_c.Kind OUTER
public static final Context_c.Kind SOURCE
protected ImportTable it
protected Context_c.Kind kind
protected ClassType type
protected ParsedClassType scope
protected CodeInstance code
protected java.util.Map types
protected java.util.Map vars
protected boolean inCode
protected boolean staticContext
Constructor Detail |
---|
public Context_c(TypeSystem ts)
Method Detail |
---|
public boolean isBlock()
public boolean isClass()
public boolean isCode()
public boolean isOuter()
public boolean isSource()
public TypeSystem typeSystem()
Context
typeSystem
in interface Context
public java.lang.Object copy()
copy
in interface Copy
protected Context_c push()
public Resolver outerResolver()
Context
outerResolver
in interface Context
public ImportTable importTable()
Context
importTable
in interface Context
public Package package_()
package_
in interface Context
public boolean isLocal(java.lang.String name)
isLocal
in interface Context
public MethodInstance findMethod(java.lang.String name, java.util.List argTypes) throws SemanticException
findMethod
in interface Context
argTypes
- A list of Type
.
SemanticException
Type
public LocalInstance findLocal(java.lang.String name) throws SemanticException
findLocal
in interface Context
SemanticException
public ClassType findFieldScope(java.lang.String name) throws SemanticException
findFieldScope
in interface Context
SemanticException
public ClassType findMethodScope(java.lang.String name) throws SemanticException
findMethodScope
in interface Context
SemanticException
public FieldInstance findField(java.lang.String name) throws SemanticException
findField
in interface Context
SemanticException
public VarInstance findVariable(java.lang.String name) throws SemanticException
findVariable
in interface Context
SemanticException
public VarInstance findVariableSilent(java.lang.String name)
findVariableSilent
in interface Context
protected java.lang.String mapsToString()
public java.lang.String toString()
toString
in class java.lang.Object
public Context pop()
Context
pop
in interface Context
public Named find(java.lang.String name) throws SemanticException
find
in interface Resolver
SemanticException
public Context pushSource(ImportTable it)
pushSource
in interface Context
public Context pushClass(ParsedClassType classScope, ClassType type)
pushClass
in interface Context
classScope
- The class whose scope is being entered. This is
the object associated with the class declaration and is returned by
currentClassScope. This is a mutable class type since for some
passes (e.g., addMembers), the object returned by currentClassScope
is modified.type
- The type to be returned by currentClass(). For JL, this
type is the same as classScope. For other languages, it may differ
since currentClassScope might not represent a type.
public Context pushBlock()
pushBlock
in interface Context
public Context pushStatic()
pushStatic
in interface Context
public Context pushCode(CodeInstance ci)
pushCode
in interface Context
public CodeInstance currentCode()
currentCode
in interface Context
public boolean inCode()
inCode
in interface Context
public boolean inStaticContext()
inStaticContext
in interface Context
public ClassType currentClass()
currentClass
in interface Context
public ParsedClassType currentClassScope()
currentClassScope
in interface Context
public void addVariable(VarInstance vi)
addVariable
in interface Context
public void addMethod(MethodInstance mi)
addMethod
in interface Context
public void addNamed(Named t)
addNamed
in interface Context
public Named findInThisScope(java.lang.String name)
public void addNamedToThisScope(Named type)
public ClassType findMethodContainerInThisScope(java.lang.String name)
public VarInstance findVariableInThisScope(java.lang.String name)
public void addVariableToThisScope(VarInstance var)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |