Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| 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

## javafe.tc
Class Env

    java.lang.Object
      javafe.tc.Env

Direct Known Subclasses:
  EnvForCU, EnvForEnclosedScope, EnvForGhostLocals, EnvForLocals, EnvForLocalType, EnvForTypeSig

public abstract class Env
extends java.lang.Object

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

### prefixSize

    public int prefixSize

### typeEnv

    public static ASTDecoration typeEnv

  decoration holding the type environment in which a type is resolved.

### whereDecoration

    protected static final ASTDecoration whereDecoration

  Decorates LocalVarDecl and FormalParaDecl nodes to point to the TypeSig of the type they are declared in.

  Set by the EnvForLocals constructor.

Constructor Detail

### Env

    public Env()

Method Detail

### isStaticContext

    public abstract boolean isStaticContext()

  Is there a current instance in scope?

  E.g., is "this" (or ".this") legal here?

  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 != is different; see canAccessInstance(-).

### getEnclosingClass

    public abstract TypeSig getEnclosingClass()

  Return the intermost class enclosing the code that is checked in this environment.

  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".

### getEnclosingInstance

    public abstract TypeSig getEnclosingInstance()

  If there is an enclosing instance in scope, then return the (exact) type of the innermost such instance.

  Note: this is considered a current instance, not an enclosing instance, even inside its methods.

### asStaticContext

    public abstract Env asStaticContext()

  Returns a new Env that acts the same as us, except that its current instance (if any) is not accessible.

  Note: this routine is somewhat inefficient and should be avoided unless an unknown environment needs to be coerced in this way.

### lookupSimpleTypeName

    public abstract TypeSig lookupSimpleTypeName(TypeSig caller,
                                                 Identifier id,
                                                 int loc)

  Attempt to lookup a simple TypeName in this environment to get the TypeSig it denotes. Returns null if no such type exists.

  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.

### locateFieldOrLocal

    public abstract ASTNode locateFieldOrLocal(Identifier id)

  Locate the lexically innermost field or local variable declaration with a given name.

  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.

### isDuplicate

    public boolean isDuplicate(Identifier id)

### locateMethod

    public abstract TypeSig locateMethod(Identifier id)

  Locate the lexically innermost method named 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.

### display

    public abstract void display()

  Display information about us to System.out. This function is intended only for debugging use.

### findTypeNamePrefix

    public 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.

  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.

### lookupTypeName

    public TypeSig lookupTypeName(TypeSig caller,
                                  Name n)

  Attempt to lookup a TypeName using this environment.

  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.

### processTypeNameAnnotations

    public TypeSig processTypeNameAnnotations(TypeName n,
                                              TypeSig sig)

  This processes the annotations on a type name

### resolveTypeName

    public TypeSig resolveTypeName(TypeSig caller,
                                   TypeName tn)

  Attempt to resolve a TypeName using this environment.

  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.

### resolveType

    public void resolveType(TypeSig caller,
                            Type t)

  Attempt to resolve a Type using this environment.

  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.

### disambiguateExprName

    public Expr disambiguateExprName(Name n)

  Attempt to disambiguate an Expr Name. Either returns the disambiguated Name as an Expr or null if it does not denote anything.

  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.)

### disambiguateTypeOrFieldName

    public java.lang.Object disambiguateTypeOrFieldName(Name n)

### disambiguateMethodName

    public MethodInvocation disambiguateMethodName(AmbiguousMethodInvocation inv)

  Attempt to disambiguate an AmbiguousMethodInvocation. Either returns the disambiguated method invocation as an Expr or reports a fatal error to ErrorSet if it does not denote anything.

  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.)

### getInnermostInstance

    public TypeSig getInnermostInstance()

  Returns the innermost current or enclosing instance, or null if none exists.

### canAccessInstance

    public boolean canAccessInstance(TypeSig C)

  Are C's instance variables accessible?

  If C is getEnclosingClass(), then this is equivalent to isStaticContext().

### lookupEnclosingInstance

    public Expr lookupEnclosingInstance(TypeSig T,
                                        int loc)

  Attempt to locate a current or enclosing instance that has type T.

  If such exist, return an inferred ".this" Expr for the innermost such one; otherwise, return null. The location fields of the Expr will be set to loc.

  Note: The returned instance may have be of a subtype of T.

### whereDeclared

    public static TypeSig whereDeclared(GenericVarDecl decl)

  What type is a GenericVarDecl declared in?

  Precondition: decl's type has been "parsed"; an Env containing decl has been constructed.

### getInferredThisExpr

    public final ThisExpr getInferredThisExpr(TypeSig C,
                                              int loc)

  Return an inferred ThisExpr for "[C.]this", using location loc.

  The "C." part is omitted if C is the type of this (e.g., getEnclosingClass()).

### getObjectDesignator

    public final 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.

  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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| 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

The ESC/Java2 Project Homepage