ESC/Java2
© 2003,2004,2005,2006 David Cok and Joseph Kiniry
© 2005,2006 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.tc
Class FlowInsensitiveChecks

java.lang.Object
  extended byjavafe.tc.FlowInsensitiveChecks
Direct Known Subclasses:
FlowInsensitiveChecks

public class FlowInsensitiveChecks
extends java.lang.Object

Does disambiguation and flow insensitive checks on a type declaration.


Field Summary
protected  TypeSigVec allowedExceptions
           
private static ASTDecoration branchDecoration
          Decorates BranchStmt nodes to point to labelled Stmt objects.
static boolean dontAddImplicitConstructorInvocations
          Controls whether or not implicit super-calls in constructors are made explicit.
protected  StmtVec enclosingLabels
           
(package private)  boolean impl_peerInStaticCautionThrown
           
(package private)  boolean inCtor
           
(package private)  boolean inPure
           
static FlowInsensitiveChecks inst
           
(package private)  boolean inStatic
           
protected  boolean leftToRight
           
(package private)  boolean readonlyStdForPureCtor
           
protected  Type returnType
           
protected  EnvForTypeSig rootIEnv
           
protected  EnvForTypeSig rootSEnv
           
protected  TypeSig sig
           
private static ASTDecoration typeDecoration
          Decorates VarInit nodes to point to Type objects.
(package private)  int universeElementReturnType
           
(package private)  int universeReturnType
           
protected  boolean useUniverses
           
 
Constructor Summary
protected FlowInsensitiveChecks()
           
 
Method Summary
protected  boolean assignmentConvertable(Expr e, Type t)
          Checks if Exp e can be assigned to Type t.
protected  Expr checkAmbiguousMethodInvocationExpr(Env env, AmbiguousMethodInvocation ami)
          Disambiguates an ambiguous method invocation and then typechecks it.
protected  Expr checkAmbiguousVariableAccessExpr(Env env, AmbiguousVariableAccess av)
          Disambiguates an ambiguous variable access and then typechecks (e.g., x).
protected  ArrayRefExpr checkArrayRefExpr(Env env, ArrayRefExpr r)
          Typechecks an array reference expression (e.g., a[3]).
protected  Expr checkAssignmentExpr(Env env, BinaryExpr be)
          Typecheck assignment-like expressions (e.g., a += 2).
protected  Expr checkBinaryExpr(Env env, BinaryExpr be)
          Typecheck simple binary expressions (e.g., x + y).
protected  Type checkBinaryExpr(int op, Expr left, Expr right, int loc)
           
protected  Expr checkBitnotExpr(Env env, UnaryExpr ue)
          Typecheck bitwise negation (e.g., ~x).
protected  Expr checkBooleanLitExpr(Expr x)
          Typechecks booleans.
protected  CastExpr checkCastExpr(Env env, CastExpr ce)
          Typecheck a (dynamic) cast.
protected  Expr checkCharLitExpr(Expr x)
          Typechecks characters.
protected  Env checkClassDeclStmt(Env e, ClassDeclStmt s)
           
protected  Expr checkClassLiteralExpr(Env env, ClassLiteral cl)
          Typechecks a class literal (e.g., X which might appear as the rhs of instanceof).
protected  Expr checkCondExpr(Env env, CondExpr ce)
          Typechecks a conditional expression (e..g, a == 0 ?
protected  Expr checkDesignator(Env env, Expr e)
           
protected  Expr checkDoubleLitExpr(Expr x)
          Typechecks doubles (e.g., 2.9).
protected  Expr checkExpr(Env env, Expr x)
          Typechecks expressions.
protected  Expr checkExpr(Env env, Expr expr, Type t)
          Typechecks expressions.
protected  Type[] checkExprVec(Env env, ExprVec ev)
           
protected  FieldAccess checkFieldAccessExpr(Env env, FieldAccess fa)
          Typechecks a field access (e.g., this.x).
 void checkFieldDecl(FieldDecl fd)
          Moves fd into implementation checked state.
protected  Expr checkFloatLitExpr(Expr x)
          Typechecks floats (e.g., 2.9F).
protected  void checkForLoopAfterInit(Env se, ForStmt f)
           
protected  Expr checkIncDecExpr(Env env, UnaryExpr ue)
          Typecheck unary increment and decrement operators (e.g., ++x).
protected  VarInit checkInit(Env env, VarInit x, Type expectedResult)
           
protected  Expr checkInstanceOfExpr(Env env, InstanceOfExpr ie)
          Typechecks a dynamic type probe (e.g., x instanceof X).
(package private) static boolean checkIntegralType(Expr e)
           
protected  Expr checkIntLitExpr(Expr x)
          Typechecks integers (e.g., 29).
protected  Expr checkLongLitExpr(Expr x)
          Typechecks long literal expressions (e.g., 29L).
protected  MethodInvocation checkMethodInvocationExpr(Env env, MethodInvocation mi)
          Typecheck method invocation.
protected  Env checkModifierPragma(ModifierPragma p, ASTNode ctxt, Env env)
          Hook to do additional processing on Modifiers.
protected  Env checkModifierPragmaVec(ModifierPragmaVec v, ASTNode ctxt, Env env)
          Hook to do additional processing on ModifierVecs.
protected  Expr checkNewArrayExpr(Env env, NewArrayExpr na)
          Typecheck a new array construction (e.g., new int[100]).
protected  NewInstanceExpr checkNewInstanceExpr(Env env, NewInstanceExpr ne)
          Typecheck a class instantiation (e.g., new C()).
protected  void checkNoRepInStaticContext(ASTNode n)
           
protected  Expr checkNotExpr(Env env, UnaryExpr ue)
          Typecheck boolean not (e.g., !
protected  Expr checkNullLitExpr(Expr x)
          Typechecks null.
(package private) static boolean checkNumericType(Expr e)
           
protected  Type checkObjectDesignator(Env env, ObjectDesignator od)
           
protected  Expr checkParenExpr(Env env, ParenExpr pe)
          Typechecks paranthesis.
protected  Expr checkSignExpr(Env env, UnaryExpr ue)
          Typecheck sign (e.g.
protected  Env checkStmt(Env e, Stmt s)
          Typecheck a statement in a given environment then return the environment in effect for statements that follow the given statement.
protected  Env checkStmtPragma(Env e, StmtPragma s)
           
protected  Env checkStmtVec(Env env, StmtVec v)
           
protected  Expr checkStringLitExpr(Expr x)
          Typechecks strings.
protected  Env checkSwitchStmt(Env e, SwitchStmt s)
           
protected  Expr checkThisExpr(Env env, ThisExpr e)
          Typechecks this expression.
(package private) static void checkType(Expr expr, Type t)
           
 void checkTypeDeclaration(TypeSig s)
          Moves s into implementation checked state.
protected  void checkTypeDeclElem(TypeDeclElem e)
           
protected  void checkTypeDeclElemPragma(TypeDeclElemPragma e)
           
protected  Env checkTypeModifierPragma(TypeModifierPragma p, ASTNode ctxt, Env env)
           
protected  Env checkTypeModifierPragmaVec(TypeModifierPragmaVec v, ASTNode ctxt, Env env)
           
protected  Env checkTypeModifiers(Env env, Type t)
          This may be called more than once on a Type t.
static void checkUniverseAssignability(ASTNode l, ASTNode r)
          Tests if universe modifiers of r can be assigned to l.
static void checkUniverseCastability(ASTNode l, ASTNode r)
          Tests if the cast of the universe modifiers l r is ever possible.
protected  void checkUniverseForField(GenericVarDecl gvd)
           
protected  Env checkVarDeclStmt(Env e, LocalVarDecl s)
           
protected  Expr checkVariableAccessExpr(VariableAccess lva)
          Typecheck variable access.
static void copyUniverses(ASTNode dest, ASTNode source)
           
static void determineUniverseForArrayRefExpr(ArrayRefExpr r)
           
static void determineUniverseForFieldAccess(FieldAccess fa)
           
 void determineUniverseForMethodInvocation(MethodInvocation mi)
           
(package private) static Stmt getBranchLabel(BranchStmt s)
          Retrieves the Stmt target of a BranchStmt.
static Type getType(VarInit i)
          Retrieves the Type of a VarInit.
protected static Type getTypeOrNull(VarInit i)
          Retrieves the Type of a VarInit.
private static void initTypeDecoration()
           
static FlowInsensitiveChecks inst()
           
protected  boolean isPure(RoutineDecl rd)
           
(package private) static boolean isVariable(Expr e)
           
static int leastUpperUniverseBound(int l, int r)
           
protected  EnvForTypeSig makeEnvForTypeSig(TypeSig s, boolean staticContext)
          Factory method so subclasses can override.
protected static void reportLookupException(LookupException e, java.lang.String s, java.lang.String t, int loc)
           
private static void setBranchLabel(BranchStmt s, Stmt l)
           
static VarInit setType(VarInit i, Type t)
           
private  Type tryCondExprMatch(Expr leftExpr, Expr rightExpr)
          Return the type of a E1 : L ?
static boolean universeIsSubtypeOf(int sub, int sup)
          Tests if the universe modifier sub is a subtype of the universe modifier sup.
protected static int universeTypeCombiner(ASTNode left, ASTNode right)
           
protected static int universeTypeCombiner(int l, int r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inst

public static FlowInsensitiveChecks inst

dontAddImplicitConstructorInvocations

public static boolean dontAddImplicitConstructorInvocations
Controls whether or not implicit super-calls in constructors are made explicit. By default they are.


useUniverses

protected boolean useUniverses

readonlyStdForPureCtor

boolean readonlyStdForPureCtor

inPure

boolean inPure

inCtor

boolean inCtor

inStatic

boolean inStatic

universeReturnType

int universeReturnType

universeElementReturnType

int universeElementReturnType

sig

protected TypeSig sig

rootIEnv

protected EnvForTypeSig rootIEnv

rootSEnv

protected EnvForTypeSig rootSEnv

leftToRight

protected boolean leftToRight

returnType

protected Type returnType

allowedExceptions

protected TypeSigVec allowedExceptions

enclosingLabels

protected StmtVec enclosingLabels

typeDecoration

private static ASTDecoration typeDecoration
Decorates VarInit nodes to point to Type objects.


branchDecoration

private static ASTDecoration branchDecoration
Decorates BranchStmt nodes to point to labelled Stmt objects.


impl_peerInStaticCautionThrown

boolean impl_peerInStaticCautionThrown
Constructor Detail

FlowInsensitiveChecks

protected FlowInsensitiveChecks()
Method Detail

inst

public static FlowInsensitiveChecks inst()

makeEnvForTypeSig

protected EnvForTypeSig makeEnvForTypeSig(TypeSig s,
                                          boolean staticContext)
Factory method so subclasses can override.


checkTypeDeclaration

public void checkTypeDeclaration(TypeSig s)
Moves s into implementation checked state.


checkFieldDecl

public void checkFieldDecl(FieldDecl fd)
Moves fd into implementation checked state.


checkUniverseAssignability

public static void checkUniverseAssignability(ASTNode l,
                                              ASTNode r)
Tests if universe modifiers of r can be assigned to l.


checkUniverseCastability

public static void checkUniverseCastability(ASTNode l,
                                            ASTNode r)
Tests if the cast of the universe modifiers l r is ever possible.


universeIsSubtypeOf

public static boolean universeIsSubtypeOf(int sub,
                                          int sup)
Tests if the universe modifier sub is a subtype of the universe modifier sup.


checkTypeDeclElem

protected void checkTypeDeclElem(TypeDeclElem e)

checkVarDeclStmt

protected Env checkVarDeclStmt(Env e,
                               LocalVarDecl s)

checkClassDeclStmt

protected Env checkClassDeclStmt(Env e,
                                 ClassDeclStmt s)

checkSwitchStmt

protected Env checkSwitchStmt(Env e,
                              SwitchStmt s)

checkStmt

protected Env checkStmt(Env e,
                        Stmt s)
Typecheck a statement in a given environment then return the environment in effect for statements that follow the given statement.

(The returned environment will be the same as the one passed in unless the statement is a declaration.)


checkForLoopAfterInit

protected void checkForLoopAfterInit(Env se,
                                     ForStmt f)

checkStmtVec

protected Env checkStmtVec(Env env,
                           StmtVec v)

checkExprVec

protected Type[] checkExprVec(Env env,
                              ExprVec ev)

checkInit

protected VarInit checkInit(Env env,
                            VarInit x,
                            Type expectedResult)

checkDesignator

protected Expr checkDesignator(Env env,
                               Expr e)

checkExpr

protected Expr checkExpr(Env env,
                         Expr expr,
                         Type t)
Typechecks expressions.

Parameters:
env - The current environment.
expr - The expression to be checked.
t - The expected type.
Returns:
The checked expression.

checkExpr

protected Expr checkExpr(Env env,
                         Expr x)
Typechecks expressions. Work is delegated to specialized methods. This way the clients that inherit from this class have a finer grained control by overriding methods.

Parameters:
env - The current environment.
x - The expression to typecheck.
Returns:
The checked expression. It has the type set.

checkVariableAccessExpr

protected Expr checkVariableAccessExpr(VariableAccess lva)
Typecheck variable access.

Parameters:
lva - The variable access.
Returns:
The variable access.

checkMethodInvocationExpr

protected MethodInvocation checkMethodInvocationExpr(Env env,
                                                     MethodInvocation mi)
Typecheck method invocation.

Parameters:
env - The current environment.
mi - The method invocation.
Returns:
The checked method invocation.

checkAmbiguousMethodInvocationExpr

protected Expr checkAmbiguousMethodInvocationExpr(Env env,
                                                  AmbiguousMethodInvocation ami)
Disambiguates an ambiguous method invocation and then typechecks it.

Parameters:
env - The current environment.
ami - The ambiguous method invocation.
Returns:
The checked ambiguous invocation.

checkFieldAccessExpr

protected FieldAccess checkFieldAccessExpr(Env env,
                                           FieldAccess fa)
Typechecks a field access (e.g., this.x).

Parameters:
env - The current environment.
fa - The field access.
Returns:
The checked field access.

checkAmbiguousVariableAccessExpr

protected Expr checkAmbiguousVariableAccessExpr(Env env,
                                                AmbiguousVariableAccess av)
Disambiguates an ambiguous variable access and then typechecks (e.g., x).

Parameters:
env - The current environment.
av - The variable access.
Returns:
The disambiguated and checked variable access.

checkParenExpr

protected Expr checkParenExpr(Env env,
                              ParenExpr pe)
Typechecks paranthesis.

Parameters:
env - The current environment.
pe - The paranthesis expression.
Returns:
The checked paranthesis expression.

checkNotExpr

protected Expr checkNotExpr(Env env,
                            UnaryExpr ue)
Typecheck boolean not (e.g., !x). The argument must be boolean and the result is a boolean.

Parameters:
env - The current environment.
ue - The unary expression containing the boolean not operation.
Returns:
The typechecked not expression.

checkIncDecExpr

protected Expr checkIncDecExpr(Env env,
                               UnaryExpr ue)
Typecheck unary increment and decrement operators (e.g., ++x).

Parameters:
env - The current environment.
ue - The unary expression representing the inc(dec)rement.
Returns:
The checked expression.

checkBitnotExpr

protected Expr checkBitnotExpr(Env env,
                               UnaryExpr ue)
Typecheck bitwise negation (e.g., ~x). The argument must be a primitive numeric type; the result has the same type as the argument.

Parameters:
env - The current environment.
ue - The unary expression representing bitwise negation.
Returns:
The checked expression.

checkSignExpr

protected Expr checkSignExpr(Env env,
                             UnaryExpr ue)
Typecheck sign (e.g. +x or -x). The argument must be a primitive numeric type; the result has the same type as the argument.

Parameters:
env - The current environment;
ue - The unary expression representing the sign.
Returns:
The checked expression.

checkAssignmentExpr

protected Expr checkAssignmentExpr(Env env,
                                   BinaryExpr be)
Typecheck assignment-like expressions (e.g., a += 2).

Parameters:
env - The current environment.
be - The binary expression representing the assignment.
Returns:
The checked expression.

checkBinaryExpr

protected Expr checkBinaryExpr(Env env,
                               BinaryExpr be)
Typecheck simple binary expressions (e.g., x + y).

Parameters:
env - The current environment.
be - The simple binary expression.
Returns:
The checked expression.

checkClassLiteralExpr

protected Expr checkClassLiteralExpr(Env env,
                                     ClassLiteral cl)
Typechecks a class literal (e.g., X which might appear as the rhs of instanceof).

Parameters:
env - The current environment.
cl - The class literal to check.
Returns:
The checked expression.

checkCastExpr

protected CastExpr checkCastExpr(Env env,
                                 CastExpr ce)
Typecheck a (dynamic) cast.

Parameters:
env - The current environment.
ce - The cast to be checked.
Returns:
The checked expression.

checkInstanceOfExpr

protected Expr checkInstanceOfExpr(Env env,
                                   InstanceOfExpr ie)
Typechecks a dynamic type probe (e.g., x instanceof X).

Parameters:
env - The current environment.
ie - The instance of expression.
Returns:
The checked expression.

checkCondExpr

protected Expr checkCondExpr(Env env,
                             CondExpr ce)
Typechecks a conditional expression (e..g, a == 0 ? x : 0).

Parameters:
env - The current environment.
ce - The expression to check.
Returns:
The checked expression.

checkNewArrayExpr

protected Expr checkNewArrayExpr(Env env,
                                 NewArrayExpr na)
Typecheck a new array construction (e.g., new int[100]).

Parameters:
env - The current environment.
na - The expression to check.
Returns:
The checked expression.

checkNewInstanceExpr

protected NewInstanceExpr checkNewInstanceExpr(Env env,
                                               NewInstanceExpr ne)
Typecheck a class instantiation (e.g., new C()).

Parameters:
env - The current environment.
ne - The instantiotion to check.
Returns:
The checked instantiation.

checkArrayRefExpr

protected ArrayRefExpr checkArrayRefExpr(Env env,
                                         ArrayRefExpr r)
Typechecks an array reference expression (e.g., a[3]).

Parameters:
env - The current environment.
r - The expression to check.
Returns:
The checked expression.

checkNullLitExpr

protected Expr checkNullLitExpr(Expr x)
Typechecks null.

Parameters:
x - The null expression.
Returns:
The null expression.

checkLongLitExpr

protected Expr checkLongLitExpr(Expr x)
Typechecks long literal expressions (e.g., 29L).

Parameters:
x - The literal.
Returns:
The literal.

checkIntLitExpr

protected Expr checkIntLitExpr(Expr x)
Typechecks integers (e.g., 29).

Parameters:
x - The literal.
Returns:
The literal.

checkDoubleLitExpr

protected Expr checkDoubleLitExpr(Expr x)
Typechecks doubles (e.g., 2.9).

Parameters:
x - The literal.
Returns:
The literal.

checkFloatLitExpr

protected Expr checkFloatLitExpr(Expr x)
Typechecks floats (e.g., 2.9F).

Parameters:
x - The literal.
Returns:
The literal.

checkBooleanLitExpr

protected Expr checkBooleanLitExpr(Expr x)
Typechecks booleans.

Parameters:
x - The literal.
Returns:
The literal.

checkCharLitExpr

protected Expr checkCharLitExpr(Expr x)
Typechecks characters.

Parameters:
x - The literal.
Returns:
The literal.

checkStringLitExpr

protected Expr checkStringLitExpr(Expr x)
Typechecks strings.

Parameters:
x - The expression to be checked.
Returns:
The checked expression.

checkThisExpr

protected Expr checkThisExpr(Env env,
                             ThisExpr e)
Typechecks this expression.

Parameters:
env - The current environment.
e - The expression to check.
Returns:
The checked expression (which was mutated).

checkObjectDesignator

protected Type checkObjectDesignator(Env env,
                                     ObjectDesignator od)

tryCondExprMatch

private Type tryCondExprMatch(Expr leftExpr,
                              Expr rightExpr)
Return the type of a E1 : L ? R expression given the typechecked Expr's for L and R, as per JLS 15.24.

Returns:
null if the given combination is illegal.

checkBinaryExpr

protected Type checkBinaryExpr(int op,
                               Expr left,
                               Expr right,
                               int loc)

checkIntegralType

static boolean checkIntegralType(Expr e)

checkNumericType

static boolean checkNumericType(Expr e)

isVariable

static boolean isVariable(Expr e)

initTypeDecoration

private static void initTypeDecoration()

setType

public static VarInit setType(VarInit i,
                              Type t)

getTypeOrNull

protected static Type getTypeOrNull(VarInit i)
Retrieves the Type of a VarInit. This type is associated with an expression by the typechecking pass. If the expression does not have an associated type, then null is returned.


getType

public static Type getType(VarInit i)
Retrieves the Type of a VarInit. This type is associated with an expression by the typechecking pass. If the expression does not have an associated type, then Assert.fail is called.


setBranchLabel

private static void setBranchLabel(BranchStmt s,
                                   Stmt l)

getBranchLabel

static Stmt getBranchLabel(BranchStmt s)
Retrieves the Stmt target of a BranchStmt. This Stmt may be mentioned either explicitly (as in break label;), or implicitly (as in break;) by the BranchStmt. The correct Stmt target is associated with the BranchStmt by the typechecking pass. This type is associated with an expression by the typechecking pass. If the BranchStmt does not have an associated Stmt target, then Assert.fail is called.


checkType

static void checkType(Expr expr,
                      Type t)

reportLookupException

protected static void reportLookupException(LookupException e,
                                            java.lang.String s,
                                            java.lang.String t,
                                            int loc)

assignmentConvertable

protected boolean assignmentConvertable(Expr e,
                                        Type t)
Checks if Exp e can be assigned to Type t. This method is here instead of in Types, because it needs to mess with constants.


checkTypeDeclElemPragma

protected void checkTypeDeclElemPragma(TypeDeclElemPragma e)

checkModifierPragmaVec

protected Env checkModifierPragmaVec(ModifierPragmaVec v,
                                     ASTNode ctxt,
                                     Env env)
Hook to do additional processing on ModifierVecs. The ASTNode is the parent of the ModifierPragma, and env is the current environment.


checkModifierPragma

protected Env checkModifierPragma(ModifierPragma p,
                                  ASTNode ctxt,
                                  Env env)
Hook to do additional processing on Modifiers. The ASTNode is the parent of the ModifierPragma, and env is the current environment.

Returns:
true if pragma should be deleted

checkStmtPragma

protected Env checkStmtPragma(Env e,
                              StmtPragma s)

checkTypeModifierPragmaVec

protected Env checkTypeModifierPragmaVec(TypeModifierPragmaVec v,
                                         ASTNode ctxt,
                                         Env env)

checkTypeModifierPragma

protected Env checkTypeModifierPragma(TypeModifierPragma p,
                                      ASTNode ctxt,
                                      Env env)

checkTypeModifiers

protected Env checkTypeModifiers(Env env,
                                 Type t)
This may be called more than once on a Type t.


isPure

protected boolean isPure(RoutineDecl rd)

universeTypeCombiner

protected static int universeTypeCombiner(int l,
                                          int r)

universeTypeCombiner

protected static int universeTypeCombiner(ASTNode left,
                                          ASTNode right)

checkNoRepInStaticContext

protected void checkNoRepInStaticContext(ASTNode n)

checkUniverseForField

protected void checkUniverseForField(GenericVarDecl gvd)

copyUniverses

public static void copyUniverses(ASTNode dest,
                                 ASTNode source)

leastUpperUniverseBound

public static int leastUpperUniverseBound(int l,
                                          int r)

determineUniverseForFieldAccess

public static void determineUniverseForFieldAccess(FieldAccess fa)

determineUniverseForMethodInvocation

public void determineUniverseForMethodInvocation(MethodInvocation mi)

determineUniverseForArrayRefExpr

public static void determineUniverseForArrayRefExpr(ArrayRefExpr r)

ESC/Java2
© 2003,2004,2005,2006 David Cok and Joseph Kiniry
© 2005,2006 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage