polyglot.ext.jl.types
Class Context_c

java.lang.Object
  extended by polyglot.ext.jl.types.Context_c
All Implemented Interfaces:
java.lang.Cloneable, Context, Resolver, Copy
Direct Known Subclasses:
CofferContext_c

public class Context_c
extends java.lang.Object
implements Context

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

outer

protected Context outer

ts

protected TypeSystem ts

BLOCK

public static final Context_c.Kind BLOCK

CLASS

public static final Context_c.Kind CLASS

CODE

public static final Context_c.Kind CODE

OUTER

public static final Context_c.Kind OUTER

SOURCE

public static final Context_c.Kind SOURCE

it

protected ImportTable it
The import table for the file


kind

protected Context_c.Kind kind

type

protected ClassType type

scope

protected ParsedClassType scope

code

protected CodeInstance code

types

protected java.util.Map types

vars

protected java.util.Map vars

inCode

protected boolean inCode

staticContext

protected boolean staticContext
Is the context static?

Constructor Detail

Context_c

public Context_c(TypeSystem ts)
Method Detail

isBlock

public boolean isBlock()

isClass

public boolean isClass()

isCode

public boolean isCode()

isOuter

public boolean isOuter()

isSource

public boolean isSource()

typeSystem

public TypeSystem typeSystem()
Description copied from interface: Context
The type system.

Specified by:
typeSystem in interface Context

copy

public java.lang.Object copy()
Specified by:
copy in interface Copy

push

protected Context_c push()

outerResolver

public Resolver outerResolver()
Description copied from interface: Context
Get the outer-most resolver for the source file currently in scope. This is usually just the import table.

Specified by:
outerResolver in interface Context

importTable

public ImportTable importTable()
Description copied from interface: Context
Get import table currently in scope.

Specified by:
importTable in interface Context

package_

public Package package_()
The current package, or null if not in a package.

Specified by:
package_ in interface Context

isLocal

public boolean isLocal(java.lang.String name)
Returns whether the particular symbol is defined locally. If it isn't in this scope, we ask the parent scope, but don't traverse to enclosing classes.

Specified by:
isLocal in interface Context

findMethod

public MethodInstance findMethod(java.lang.String name,
                                 java.util.List argTypes)
                          throws SemanticException
Looks up a method with name "name" and arguments compatible with "argTypes".

Specified by:
findMethod in interface Context
argTypes - A list of Type.
Throws:
SemanticException
See Also:
Type

findLocal

public LocalInstance findLocal(java.lang.String name)
                        throws SemanticException
Gets a local of a particular name.

Specified by:
findLocal in interface Context
Throws:
SemanticException

findFieldScope

public ClassType findFieldScope(java.lang.String name)
                         throws SemanticException
Finds the class which added a field to the scope.

Specified by:
findFieldScope in interface Context
Throws:
SemanticException

findMethodScope

public ClassType findMethodScope(java.lang.String name)
                          throws SemanticException
Finds the class which added a method to the scope.

Specified by:
findMethodScope in interface Context
Throws:
SemanticException

findField

public FieldInstance findField(java.lang.String name)
                        throws SemanticException
Gets a field of a particular name.

Specified by:
findField in interface Context
Throws:
SemanticException

findVariable

public VarInstance findVariable(java.lang.String name)
                         throws SemanticException
Gets a local or field of a particular name.

Specified by:
findVariable in interface Context
Throws:
SemanticException

findVariableSilent

public VarInstance findVariableSilent(java.lang.String name)
Gets a local or field of a particular name.

Specified by:
findVariableSilent in interface Context

mapsToString

protected java.lang.String mapsToString()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

pop

public Context pop()
Description copied from interface: Context
Pop the context.

Specified by:
pop in interface Context

find

public Named find(java.lang.String name)
           throws SemanticException
Finds the definition of a particular type.

Specified by:
find in interface Resolver
Throws:
SemanticException

pushSource

public Context pushSource(ImportTable it)
Push a source file scope.

Specified by:
pushSource in interface Context

pushClass

public Context pushClass(ParsedClassType classScope,
                         ClassType type)
Pushes on a class scoping.

Specified by:
pushClass in interface Context
Parameters:
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.
Returns:
A new context with a new scope and which maps the short name of type to type.

pushBlock

public Context pushBlock()
pushes an additional block-scoping level.

Specified by:
pushBlock in interface Context

pushStatic

public Context pushStatic()
pushes an additional static scoping level.

Specified by:
pushStatic in interface Context

pushCode

public Context pushCode(CodeInstance ci)
enters a method

Specified by:
pushCode in interface Context

currentCode

public CodeInstance currentCode()
Gets the current method

Specified by:
currentCode in interface Context

inCode

public boolean inCode()
Return true if in a method's scope and not in a local class within the innermost method.

Specified by:
inCode in interface Context

inStaticContext

public boolean inStaticContext()
Returns whether the current context is a static context. A statement of expression occurs in a static context if and only if the inner-most method, constructor, instance initializer, static initializer, field initializer, or explicit constructor statement enclosing the statement or expressions is a static method, static initializer, the variable initializer of a static variable, or an explicity constructor invocation statment. (Java Language Spec, 2nd Edition, 8.1.2)

Specified by:
inStaticContext in interface Context

currentClass

public ClassType currentClass()
Gets current class

Specified by:
currentClass in interface Context

currentClassScope

public ParsedClassType currentClassScope()
Gets current class

Specified by:
currentClassScope in interface Context

addVariable

public void addVariable(VarInstance vi)
Adds a symbol to the current scoping level.

Specified by:
addVariable in interface Context

addMethod

public void addMethod(MethodInstance mi)
Deprecated. 

Adds a method to the current scoping level. Actually, this does nothing now.

Specified by:
addMethod in interface Context

addNamed

public void addNamed(Named t)
Adds a named type object to the current scoping level.

Specified by:
addNamed in interface Context

findInThisScope

public Named findInThisScope(java.lang.String name)

addNamedToThisScope

public void addNamedToThisScope(Named type)

findMethodContainerInThisScope

public ClassType findMethodContainerInThisScope(java.lang.String name)

findVariableInThisScope

public VarInstance findVariableInThisScope(java.lang.String name)

addVariableToThisScope

public void addVariableToThisScope(VarInstance var)