|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavafe.tc.Env
Env's are the environments used during typechecking to keep track of what types, local variables, fields, and current/enclosing instances are in scope.
Field Summary | |
int |
prefixSize
|
static ASTDecoration |
typeEnv
decoration holding the type environment in which a type is resolved. |
protected static ASTDecoration |
whereDecoration
Decorates LocalVarDecl and FormalParaDecl nodes to point to the TypeSig of the type they are declared in. |
Constructor Summary | |
Env()
|
Method Summary | |
abstract Env |
asStaticContext()
Returns a new Env that acts the same as us, except that its current instance (if any) is not accessible. |
boolean |
canAccessInstance(TypeSig C)
Are C's instance variables accessible? |
Expr |
disambiguateExprName(Name n)
Attempt to disambiguate an Expr Name. |
MethodInvocation |
disambiguateMethodName(AmbiguousMethodInvocation inv)
Attempt to disambiguate an AmbiguousMethodInvocation. |
java.lang.Object |
disambiguateTypeOrFieldName(Name n)
|
abstract void |
display()
Display information about us to System.out. |
TypeSig |
findTypeNamePrefix(TypeSig caller,
Name n,
boolean ignoreFields)
Attempts to find the canonical prefix of a given name that denotes a TypeName in this environment. |
abstract TypeSig |
getEnclosingClass()
Return the intermost class enclosing the code that is checked in this environment. |
abstract TypeSig |
getEnclosingInstance()
If there is an enclosing instance in scope, then return the (exact) type of the innermost such instance. |
ThisExpr |
getInferredThisExpr(TypeSig C,
int loc)
Return an inferred ThisExpr for "[C.]this", using location loc. |
TypeSig |
getInnermostInstance()
Returns the innermost current or enclosing instance, or null if none exists. |
ObjectDesignator |
getObjectDesignator(TypeSig C,
int loc)
Return an inferred ObjectDesignator for use in a reference to a possibly-instance member of class C from here. |
boolean |
isDuplicate(Identifier id)
|
abstract boolean |
isStaticContext()
Is there a current instance in scope? |
abstract ASTNode |
locateFieldOrLocal(Identifier id)
Locate the lexically innermost field or local variable declaration with a given name. |
abstract TypeSig |
locateMethod(Identifier id)
Locate the lexically innermost method named id. |
Expr |
lookupEnclosingInstance(TypeSig T,
int loc)
Attempt to locate a current or enclosing instance that has type T. |
abstract TypeSig |
lookupSimpleTypeName(TypeSig caller,
Identifier id,
int loc)
Attempt to lookup a simple TypeName in this environment to get the TypeSig it denotes. |
TypeSig |
lookupTypeName(TypeSig caller,
Name n)
Attempt to lookup a TypeName using this environment. |
TypeSig |
processTypeNameAnnotations(TypeName n,
TypeSig sig)
This processes the annotations on a type name |
void |
resolveType(TypeSig caller,
Type t)
Attempt to resolve a Type using this environment. |
TypeSig |
resolveTypeName(TypeSig caller,
TypeName tn)
Attempt to resolve a TypeName using this environment. |
static TypeSig |
whereDeclared(GenericVarDecl decl)
What type is a GenericVarDecl declared in? |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public int prefixSize
public static ASTDecoration typeEnv
protected static final ASTDecoration whereDecoration
Set by the EnvForLocals constructor.
Constructor Detail |
public Env()
Method Detail |
public abstract boolean isStaticContext()
E.g., is "this" (or "
This is also refered to as "are we in a static context?". The
legality of super also depends on this result.
The legality of C.this, C !=
public abstract TypeSig getEnclosingClass()
May return null if there is no enclosing class (aka, for environments for CompilationUnits).
If isStaticContext() returns true, then this is the type of "this".
public abstract TypeSig getEnclosingInstance()
Note: this is considered a current instance, not an enclosing instance, even inside its methods.
public abstract Env asStaticContext()
Note: this routine is somewhat inefficient and should be avoided unless an unknown environment needs to be coerced in this way.
public abstract TypeSig lookupSimpleTypeName(TypeSig caller, Identifier id, int loc)
This routine does not check that the resulting type (if any) is actually accessible, if caller is null.
If id is ambiguous, then if loc != Location.NULL then a fatal error is reported at that location via ErrorSet else one of its possible meanings is returned.
public abstract ASTNode locateFieldOrLocal(Identifier id)
Let d be the lexically innermost field or local variable declaration (including formals) of id (if any such declaration exists). Then this routine returns:
d (a LocalVarDecl or FormalParaDecl) if d is a local variable declaration the class C that lexically encloses us and contains the (inherited) field d if d is a field declaration null if d does not exist Note: inherited fields are considered to lexically enclose the code of their subclasses. We give the class containing the field instead of the field itself to postpone dealing with multiple fields named id visible in the same class.
In the field case, id disambiguates to C[.this].id.
This routine does not check that a resulting field is actually accessible.
public boolean isDuplicate(Identifier id)
public abstract TypeSig locateMethod(Identifier id)
Returns the TypeSig for the innermost lexically enclosing type that has a method named id or null if no such type exists.
Note: inherited methods are considered to lexically enclose the code of their subclasses.
id disambiguates to C[.this].id.
This routine does not check that a resulting method is actually accessible.
public abstract void display()
public TypeSig findTypeNamePrefix(TypeSig caller, Name n, boolean ignoreFields)
A canonical prefix is composed of a base type name (either the leftmost identifer or a fully-quantified outside type name (P.I) depending), extended by some number of type member accesses (.C1.C2...). If ignoreFields is not set, then we stop extending the base type name as soon as we encounter an access that can refer to a field. If it is set, then we stop extending only when we reach the end of the name or an access that cannot refer to a type member.
If we encounter an ambiguous prefix, we report a fatal error at loc via ErrorSet.
Otherwise, we return the TypeSig that the found prefix denotes (null if the prefix is of length 0) and sets prefixSize to the prefix's size.
This routine does not check that the resulting type (if any) is actually accessible, unless caller is not null.
public TypeSig lookupTypeName(TypeSig caller, Name n)
If it encounters an ambiguous prefix, a fatal error is reported via ErrorSet.
Otherwise, returns the TypeSig that n denotes or null if n does not denote a type.
This routine does not check that the resulting type (if any) is actually accessible, unless caller is not null.
public TypeSig processTypeNameAnnotations(TypeName n, TypeSig sig)
public TypeSig resolveTypeName(TypeSig caller, TypeName tn)
If an error occurs (including no such type), reports it to ErrorSet via a fatal error.
Otherwise, returns the TypeSig that n denotes. This TypeSig may also later be obtained by using TypeSig.getSig on n.
This routine does not check that the resulting type (if any) is actually accessible, unless caller is not null.
public void resolveType(TypeSig caller, Type t)
If an error occurs, reports it to ErrorSet via a fatal error.
This routine does not check that (immediate) types (if any) are actually accessible, if caller is null.
public Expr disambiguateExprName(Name n)
If non-null, the result will always be a field access of some kind. If a prefix of n is ambiguous because of multiple import-on-demand declarations, a fatal error will result. Nothing is reported if n does not name anything.
If n is a reference to a field f in lexically enclosing class C, then the result will be of the form "[C.]this.n" if C's instance fields are accessible and "C.n" otherwise.
(At this point we haven't decided which field f refers to so we don't know if it is an instance field or not.)
public java.lang.Object disambiguateTypeOrFieldName(Name n)
public MethodInvocation disambiguateMethodName(AmbiguousMethodInvocation inv)
The result will always be a method invocation.
If a prefix of n is ambiguous because of multiple import-on-demand declarations, a fatal error will result. If n is a reference to a method m in lexically enclosing class C, then the result will be of the form "[C.]this.m" if C's instance methods are accessible and "C.m" otherwise.
(At this point we haven't decided which method m refers to so we don't know if it is an instance method or not.)
public TypeSig getInnermostInstance()
public boolean canAccessInstance(TypeSig C)
If C is getEnclosingClass(), then this is equivalent to isStaticContext().
public Expr lookupEnclosingInstance(TypeSig T, int loc)
If such exist, return an inferred "
Note: The returned instance may have be of a subtype of T.
public static TypeSig whereDeclared(GenericVarDecl decl)
Precondition: decl's type has been "parsed"; an Env containing decl has been constructed.
public final ThisExpr getInferredThisExpr(TypeSig C, int loc)
The "C." part is omitted if C is the type of this (e.g., getEnclosingClass()).
public final ObjectDesignator getObjectDesignator(TypeSig C, int loc)
If C's instance variables are not accessible from this point (see canAccessInstance(-)), then returns "C.".
Otherwise returns an inferred "[C.]this.". (cf. getInferredThisExpr(-)) loc is used as the location for the this. and C. parts.
|
ESC/Java2 © 2003,2004,2005 David Cok and Joseph Kiniry © 2005 UCD Dublin © 2003,2004 Radboud University Nijmegen © 1999,2000 Compaq Computer Corporation © 1997,1998,1999 Digital Equipment Corporation All Rights Reserved |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |