|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.multijava.util.Utils
org.jmlspecs.checker.JmlContext
Descendents of this class represent local contexts during checking passes (checkInterface, checkInitializers, typecheck). The context classes follow the control flow and maintain information about variables (initialized, used, allocated) and exceptions (thrown, caught). They also verify that a context is still reachable. The contexts are used for name resolution (JLS2, 6 and 14.4), checking for unreachable statements (JLS2 14.20), checking for definite assignment (JLS2, 16), and for checking for proper subclassing and overriding (JLS2, 8).
The contexts are hierarchical. To wit, a compilation unit context is created and passed to the method that checks a class. This method creates a class context by passing the compilation unit context to the CClassContext constructor. When checking methods of the class the CClassContext instance is passed to the CMethodContext constructor. These context classes are stored in fields of the AST nodes.
During typechecking the context hierarchy is mutated in a way that mimics the actual run-time control flow. For example, variable declarations cause the context to be mutated to record the variable's name and type. Assignment to a variable causes the context to be mutated to record that the variable is definitely assigned. Reference a variable's value triggers a check that the variable has been definitely assigned.
| Field Summary | |
protected CCompilationUnitContextType |
cunit
|
protected CContext |
delegee
|
protected CContextType |
parent
The parent context. |
private static int |
specScopeCounter
number of nested spec scopes |
| Fields inherited from class org.multijava.util.Utils |
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO |
| Fields inherited from interface org.multijava.mjc.Constants |
ACC_PURE, AMID_JAVA_MATH, AMID_MAX, AMID_SAFE_MATH, CMP_VERSION, JAV_ASSERTION_ERROR, JAV_CLASS, JAV_CLASSLOADER, JAV_CLASSNOTFOUND_EXCEPTION, JAV_CLONE, JAV_CLONEABLE, JAV_CONSTRUCTOR, JAV_ERROR, JAV_EXCEPTION, JAV_INIT, JAV_LENGTH, JAV_NAME_SEPARATOR, JAV_NOCLASSDEFFOUND_ERROR, JAV_OBJECT, JAV_OUTER_THIS, JAV_RMJ_RUNTIME_EXCEPTION, JAV_RUNTIME, JAV_RUNTIME_EXCEPTION, JAV_SERIALIZABLE, JAV_STATIC_INIT, JAV_STRING, JAV_STRINGBUFFER, JAV_SUPER, JAV_THIS, JAV_THROWABLE, MJ_ANCHOR, OPE_BAND, OPE_BNOT, OPE_BOR, OPE_BSR, OPE_BXOR, OPE_EQ, OPE_GE, OPE_GT, OPE_LAND, OPE_LE, OPE_LNOT, OPE_LOR, OPE_LT, OPE_MINUS, OPE_NE, OPE_PERCENT, OPE_PLUS, OPE_POSTDEC, OPE_POSTINC, OPE_PREDEC, OPE_PREINC, OPE_SIMPLE, OPE_SL, OPE_SLASH, OPE_SR, OPE_STAR, TID_ARRAY, TID_BOOLEAN, TID_BYTE, TID_CHAR, TID_CLASS, TID_DOUBLE, TID_FLOAT, TID_INT, TID_LONG, TID_MAX, TID_SHORT, TID_VOID, UNIV_ARRAY_TMP, UNIV_TMP |
| Constructor Summary | |
(package private) |
JmlContext()
Constructs a new context. |
protected |
JmlContext(CContextType parent)
Construct a block context, it supports local variable allocation throw statement and return statement |
| Method Summary | |
MJMathMode |
arithmeticMode()
Indicates the integral arithmetic mode that should be used. |
void |
catchUp(JTypeDeclarationType decl)
Calls back to the compiler for this context and requests that the compiler catch-up decl to the same pass as the currently active task. |
boolean |
check(boolean expr,
MessageDescription mess)
Verifies an expression and if false signals an error. |
boolean |
check(boolean expr,
MessageDescription mess,
Object param1)
Verifies an expression and if false signals an error. |
boolean |
check(boolean expr,
MessageDescription mess,
Object param1,
Object param2)
Verifies an expression and if false signals an error. |
boolean |
check(boolean expr,
MessageDescription mess,
Object[] params)
|
void |
classToGenerate(CSourceClass clazz)
Adds a source class to be generated |
CClassContextType |
createClassContext(CClass self)
Creates a class context with this context as its parent. |
static CFlowControlContextType |
createDummyContext(JmlSourceClass self)
|
CExtMethodContext |
createExtMethodContext(CSourceClass host,
CClass owner)
Create a new child of this context representing the context in which an external method declaration is typechecked. |
CInterfaceContextType |
createInterfaceContext(CClass self)
Creates an interface context with this context as its parent. |
boolean |
declaredOutsideOfLoop(JLocalVariable var)
Indicates whether this context is enclosed in a loop and the given variable is declared outside the inner-most loop context. |
boolean |
declares(JLocalVariable var)
Returns true if the given local variable is declared exactly in this context, i.e., it is not declared in an outer context. |
static void |
enterSpecScope()
Enters a new JML specification scope. |
static void |
exitSpecScope()
Exits the current JML specification scope. |
void |
fail(MessageDescription mess,
Object params)
|
void |
fail(MessageDescription mess,
Object param1,
Object param2)
Generates an UnpositionedError with a given message. |
void |
fail(MessageDescription mess,
Object[] params)
Generates an UnpositionedError with a given message. |
CMemberHost |
findNearestHost()
Returns the signature of the nearest lexically enclosing context that can host member declarations (i.e., a CClass or a CCompilationUnit). |
CClassContextType |
getClassContext()
Returns the class context for this context. |
CMethod |
getCMethod()
Returns the signature of the method declaration in which this context is enclosed, or null if this context is not enclosed in a method declaration. |
CCompilationUnitContextType |
getCompilationUnit()
Returns the compilation unit context for this context. |
Main |
getCompiler()
Gets the compiler for this context |
CFlowControlContextType |
getFlowControlContext()
Returns the nearest control flow context (where control flow information is stored.) |
CClass |
getHostClass()
Returns the signature of the class declaration in which this context is enclosed, or null if this context is not enclosed in a class declaration. |
CMethodContextType |
getMethodContext()
Returns the method context for this context. |
CContextType |
getParentContext()
Returns the parent context for this context |
void |
initializeField(VariableDescriptor varDesc)
Marks the field with the given descriptor as definitely assigned to in this context. |
static boolean |
inSpecScope()
Returns true if currently in JML specification scope. |
boolean |
isBeforeSuperConstructorCall()
Indicates whether this context is enclosed in a constructor and occurs before the constructor has invoked the superclass constructor. |
boolean |
isFieldDefinitelyAssigned(int pos)
Indicates whether the field in the given position is definitely assigned to in this context. |
boolean |
isInConstructor()
Indicates whether this context is enclosed in a constructor. |
boolean |
isInInitializer()
Indicates whether this context is enclosed in an instance or static initializer. |
boolean |
isInLoop()
Indicates whether this context is enclosed in a loop. |
boolean |
isPure()
Indicates whether this context is "pure". |
boolean |
isStatic()
Indicates whether this context is "static". |
CClass |
lookupClass(String name)
Searches for a class with the given simple name according the procedure in JLS2 6.5.5. |
CFieldAccessor |
lookupField(String ident)
searches for a field with the given identifier |
CFieldAccessor |
lookupField(String ident,
CExpressionContextType context)
searches for a field with the given identifier |
JLocalVariable |
lookupLocalVariable(String ident)
searches for a local variable with the given identifier |
CMethod |
lookupMethod(String name,
CType[] params)
Searches for the most specific method in the current context that is applicable to the given identifier and argument type tuple. |
CMethod |
lookupMethod(String name,
CType[] params,
CClassContextType context)
Searches for the most specific method in the current context that is applicable to the given identifier and argument type tuple. |
CMethodSet |
lookupMethodOrSet(String name,
CType[] params)
Searches for the most specific method(s) in the current context that is applicable to the given identifier and argument type tuple. |
CMethodSet |
lookupMethodOrSet(String name,
CType[] params,
CClassContextType context)
Searches for the most specific method(s) in the current context that is applicable to the given identifier and argument type tuple. |
CFieldAccessor |
lookupOuterField(String ident)
Searches for a field of the given name in the context surrounding the current lexical contour. |
CFieldAccessor |
lookupOuterField(String ident,
CExpressionContextType context)
Searches for a field of the given name in the context surrounding the current lexical contour. |
JExpression |
lookupOuterLocalVariable(TokenReference ref,
String ident)
Finds a local variable with the given name that appears outside the current lexical contour. |
CTypeVariable |
lookupTypeVariable(String ident)
search for type variable that are accessible |
ModifierUtility |
modUtil()
Returns the modifier utility for this. |
void |
registerGFDecl(String methodIdent,
CGenericFunctionCollection coll)
Registers the declaration of an external generic function in this context. |
void |
registerVisibleMethod(CMethod method)
Registers with the surrounding context that a declaration of the given method occurs in this context. |
void |
registerVisibleType(CType type)
Registers with the surrounding context that a reference to the given type occurs in this context. |
void |
replaceFieldInfoUpTo(int pos,
CVariableInfoTable replacement)
Replaces the local field info for fields in positions 0 up to pos with the info in replacement. |
void |
reportTrouble(Exception trouble)
Reports the given error and the "swallows" it, allowing compilation to continue. |
void |
resolveMaybeExtMethodRef(String ident)
Searches for any imported external generic functions. |
| Methods inherited from class org.multijava.util.Utils |
assertTrue, assertTrue, combineArrays, escapeString, escapeString, fail, fail, getFilePath, hasFlag, hasOtherFlags, parsePathParts, relativePathTo, splitQualifiedName, splitQualifiedName, stripJavaModifiers, stripNonJavaModifiers, stripPrivateModifier, unescapeString, vectorToArray, vectorToIntArray |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static int specScopeCounter
protected CContextType parent
invariant parent != null ==> parent instanceof JmlContext;
protected CCompilationUnitContextType cunit
protected CContext delegee
| Constructor Detail |
JmlContext()
protected JmlContext(CContextType parent)
parent - the parent context, it must be different
than null except if called by the top level| Method Detail |
public CClass lookupClass(String name)
throws UnpositionedError
lookupClass in interface CContextTypename - the class name, without qualifiers
UnpositionedError - if search fails
public CTypeVariable lookupTypeVariable(String ident)
throws UnpositionedError
CContextType
lookupTypeVariable in interface CContextTypeUnpositionedError
public CMethod lookupMethod(String name,
CType[] params)
throws UnpositionedError
lookupMethod in interface CContextTypename - method nameparams - method parameter types
UnpositionedError - if the result is ambiguous
public CMethod lookupMethod(String name,
CType[] params,
CClassContextType context)
throws UnpositionedError
lookupMethod in interface CContextTypename - method nameparams - method parameter typescontext - the context of the class containing
the method call
UnpositionedError - if the result is ambiguous
public CMethodSet lookupMethodOrSet(String name,
CType[] params)
throws UnpositionedError
lookupMethodOrSet in interface CContextTypename - method nameparams - method parameter types
UnpositionedError - if the result is ambiguous
public CMethodSet lookupMethodOrSet(String name,
CType[] params,
CClassContextType context)
throws UnpositionedError
lookupMethodOrSet in interface CContextTypename - method nameparams - method parameter typescontext - the context of the class containing
the method call
UnpositionedError - if the result is ambiguous
public CFieldAccessor lookupField(String ident)
throws UnpositionedError
lookupField in interface CContextTypeUnpositionedError - this error will be positioned soon
public CFieldAccessor lookupField(String ident,
CExpressionContextType context)
throws UnpositionedError
lookupField in interface CContextTypeUnpositionedError - this error will be positioned soonpublic JLocalVariable lookupLocalVariable(String ident)
lookupLocalVariable in interface CContextTypeident - the name of the local variable
public JExpression lookupOuterLocalVariable(TokenReference ref,
String ident)
lookupOuterLocalVariable in interface CContextTyperef - a token reference used to build a new
JOuterLocalVariableExpressionident - the name of the outer variable
public CFieldAccessor lookupOuterField(String ident)
throws UnpositionedError
lookupOuterField in interface CContextTypeident - the name of the field
UnpositionedError - this error will be positioned soon
public CFieldAccessor lookupOuterField(String ident,
CExpressionContextType context)
throws UnpositionedError
lookupOuterField in interface CContextTypeident - the name of the fieldcontext - the context of the field access
UnpositionedError - this error will be positioned soon
public void replaceFieldInfoUpTo(int pos,
CVariableInfoTable replacement)
pos with the info in replacement.
replaceFieldInfoUpTo in interface CContextTypepublic void initializeField(VariableDescriptor varDesc)
initializeField in interface CContextTypepublic boolean isFieldDefinitelyAssigned(int pos)
isFieldDefinitelyAssigned in interface CContextTypepublic CContextType getParentContext()
getParentContext in interface CContextTypepublic CCompilationUnitContextType getCompilationUnit()
getCompilationUnit in interface CContextTypepublic CClassContextType getClassContext()
getClassContext in interface CContextTypepublic CMethodContextType getMethodContext()
getMethodContext in interface CContextTypepublic CFlowControlContextType getFlowControlContext()
getFlowControlContext in interface CContextTypepublic CMethod getCMethod()
getCMethod in interface CContextTypepublic CClass getHostClass()
public CMemberHost findNearestHost()
CClass or a CCompilationUnit). Used
for access checks, this is slightly different than
getHostClass(). The later method returns an
anchor class signature for external methods, which is useful in
code generation and in typechecking external method bodies. On
the other hand, this method returns a
CCompilationUnit for external methods, which is
useful in checking access between two differently named generic
functions declared in the same compilation unit. !FIXME! It
may be possible to eliminate this method and just use
getHostClass now that private external methods are
duplciated in every anchor.
findNearestHost in interface CContextTypeCMemberHost public CClassContextType createClassContext(CClass self)
createClassContext in interface CContextTypeself - the corresponding classpublic CInterfaceContextType createInterfaceContext(CClass self)
createInterfaceContext in interface CContextTypeself - the corresponding interface signature
public CExtMethodContext createExtMethodContext(CSourceClass host,
CClass owner)
createExtMethodContext in interface CContextTypehost - the host classowner - the receiver classpublic void classToGenerate(CSourceClass clazz)
classToGenerate in interface CContextTypeclazz - the class to be generatedpublic void resolveMaybeExtMethodRef(String ident)
resolveMaybeExtMethodRef in interface CContextTypeident - the name of the generic function to search for
public void registerGFDecl(String methodIdent,
CGenericFunctionCollection coll)
registerGFDecl in interface CContextTypepublic void registerVisibleMethod(CMethod method)
registerVisibleMethod in interface CContextTypepublic void registerVisibleType(CType type)
registerVisibleType in interface CContextTypepublic void reportTrouble(Exception trouble)
reportTrouble in interface CContextTypetrouble - the error
public void fail(MessageDescription mess,
Object param1,
Object param2)
throws UnpositionedError
fail in interface CContextTypemess - the error messageparam1 - the first message parameterparam2 - the second message parameter
UnpositionedError - the error exception
public void fail(MessageDescription mess,
Object params)
throws UnpositionedError
UnpositionedError
public void fail(MessageDescription mess,
Object[] params)
throws UnpositionedError
fail in interface CContextTypemess - the error messageparams - the message parameters
UnpositionedError - the error exception
public boolean check(boolean expr,
MessageDescription mess)
throws UnpositionedError
check in interface CContextTypeexpr - condition to verifymess - the message to be displayed
UnpositionedError - this error will be positioned soon
public boolean check(boolean expr,
MessageDescription mess,
Object[] params)
throws UnpositionedError
check in interface CContextTypeUnpositionedError
public boolean check(boolean expr,
MessageDescription mess,
Object param1)
throws UnpositionedError
check in interface CContextTypeexpr - condition to verifymess - the message to be displayedparam1 - the first parameter
UnpositionedError - this error will be positioned soon
public boolean check(boolean expr,
MessageDescription mess,
Object param1,
Object param2)
throws UnpositionedError
check in interface CContextTypeexpr - condition to verifymess - the message to be displayedparam1 - the first parameterparam2 - the second parameter
UnpositionedError - this error will be positioned soonpublic Main getCompiler()
getCompiler in interface CContextTypepublic final ModifierUtility modUtil()
modUtil in interface CContextTypepublic boolean isInLoop()
isInLoop in interface CContextTypepublic boolean declaredOutsideOfLoop(JLocalVariable var)
declaredOutsideOfLoop in interface CContextTypepublic boolean declares(JLocalVariable var)
declares in interface CContextTypepublic boolean isInInitializer()
isInInitializer in interface CContextTypepublic boolean isInConstructor()
isInConstructor in interface CContextTypepublic boolean isBeforeSuperConstructorCall()
isBeforeSuperConstructorCall in interface CContextTypepublic boolean isStatic()
isStatic in interface CContextTypepublic boolean isPure()
isPure in interface CContextTypepublic void catchUp(JTypeDeclarationType decl)
catchUp in interface CContextTypepublic MJMathMode arithmeticMode()
arithmeticMode in interface CContextTypepublic static CFlowControlContextType createDummyContext(JmlSourceClass self)
public static void enterSpecScope()
exitSpecScope(),
inSpecScope()public static void exitSpecScope()
enterSpecScope(),
inSpecScope()public static boolean inSpecScope()
true if currently in JML specification scope.
enterSpecScope(),
exitSpecScope()
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||