polyglot.types
Interface Context

All Superinterfaces:
java.lang.Cloneable, Copy, Resolver
All Known Subinterfaces:
CofferContext
All Known Implementing Classes:
CofferContext_c, Context_c

public interface Context
extends Resolver, Copy

A context represents a stack of scopes used for looking up types, methods, and variables. To push a new scope call one of the push* methods to return a new context. The old context may still be used and may be accessed directly through a call to pop(). While the stack of scopes is treated functionally, each individual scope is updated in place. Names added to the context are added in the current scope.


Method Summary
 void addMethod(MethodInstance mi)
          Add a method to the current scope.
 void addNamed(Named t)
          Add a named type object to the current scope.
 void addVariable(VarInstance vi)
          Add a variable to the current scope.
 ClassType currentClass()
          Return the innermost class in scope.
 ParsedClassType currentClassScope()
          Return the innermost class in scope.
 CodeInstance currentCode()
          Return the innermost method or constructor in scope.
 FieldInstance findField(java.lang.String name)
          Looks up a field in the current scope.
 ClassType findFieldScope(java.lang.String name)
          Finds the class which added a field to the scope.
 LocalInstance findLocal(java.lang.String name)
          Looks up a local variable in the current scope.
 MethodInstance findMethod(java.lang.String name, java.util.List formalTypes)
          Looks up a method in the current scope.
 ClassType findMethodScope(java.lang.String name)
          Finds the class which added a method to the scope.
 VarInstance findVariable(java.lang.String name)
          Looks up a local variable or field in the current scope.
 VarInstance findVariableSilent(java.lang.String name)
          Looks up a local variable or field in the current scope.
 ImportTable importTable()
          Get import table currently in scope.
 boolean inCode()
          Return whether innermost non-block scope is a code scope.
 boolean inStaticContext()
          Returns whether the current context is a static context.
 boolean isLocal(java.lang.String name)
          Returns whether the symbol is defined within the current method.
 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.
 Context pushBlock()
          Enter the scope of a block.
 Context pushClass(ParsedClassType scope, ClassType type)
          Enter the scope of a class.
 Context pushCode(CodeInstance f)
          Enter the scope of a method or constructor.
 Context pushSource(ImportTable it)
          Enter the scope of a source file.
 Context pushStatic()
          Enter a static scope.
 TypeSystem typeSystem()
          The type system.
 
Methods inherited from interface polyglot.types.Resolver
find
 
Methods inherited from interface polyglot.util.Copy
copy
 

Method Detail

typeSystem

TypeSystem typeSystem()
The type system.


addVariable

void addVariable(VarInstance vi)
Add a variable to the current scope.


addMethod

void addMethod(MethodInstance mi)
Add a method to the current scope.


addNamed

void addNamed(Named t)
Add a named type object to the current scope.


findMethod

MethodInstance findMethod(java.lang.String name,
                          java.util.List formalTypes)
                          throws SemanticException
Looks up a method in the current scope.

Parameters:
formalTypes - A list of Type.
Throws:
SemanticException
See Also:
Type

findVariable

VarInstance findVariable(java.lang.String name)
                         throws SemanticException
Looks up a local variable or field in the current scope.

Throws:
SemanticException

findVariableSilent

VarInstance findVariableSilent(java.lang.String name)
Looks up a local variable or field in the current scope.


findLocal

LocalInstance findLocal(java.lang.String name)
                        throws SemanticException
Looks up a local variable in the current scope.

Throws:
SemanticException

findField

FieldInstance findField(java.lang.String name)
                        throws SemanticException
Looks up a field in the current scope.

Throws:
SemanticException

findFieldScope

ClassType findFieldScope(java.lang.String name)
                         throws SemanticException
Finds the class which added a field to the scope. This is usually a subclass of findField(name).container().

Throws:
SemanticException

findMethodScope

ClassType findMethodScope(java.lang.String name)
                          throws SemanticException
Finds the class which added a method to the scope. This is usually a subclass of findMethod(name).container().

Throws:
SemanticException

importTable

ImportTable importTable()
Get import table currently in scope.


outerResolver

Resolver outerResolver()
Get the outer-most resolver for the source file currently in scope. This is usually just the import table.


pushSource

Context pushSource(ImportTable it)
Enter the scope of a source file.


pushClass

Context pushClass(ParsedClassType scope,
                  ClassType type)
Enter the scope of a class.


pushCode

Context pushCode(CodeInstance f)
Enter the scope of a method or constructor.


pushBlock

Context pushBlock()
Enter the scope of a block.


pushStatic

Context pushStatic()
Enter a static scope. In general, this is only used for explicit constructor calls; static methods, initializers of static fields and static initializers are generally handled by pushCode().


pop

Context pop()
Pop the context.


inCode

boolean inCode()
Return whether innermost non-block scope is a code scope.


isLocal

boolean isLocal(java.lang.String name)
Returns whether the symbol is defined within the current method.


inStaticContext

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)


currentClass

ClassType currentClass()
Return the innermost class in scope.


currentClassScope

ParsedClassType currentClassScope()
Return the innermost class in scope.


currentCode

CodeInstance currentCode()
Return the innermost method or constructor in scope.


package_

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