|
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
org.jmlspecs.checker.JmlFlowControlContext
This class is used during typechecking for control flow analysis that maintains local variable definite assignment (JLS2, 16), throwable, and reachability information (JLS2, 14.20).
| Field Summary | |
private static int |
DEFAULT_VAR_ESTIMATE
Default estimate of the number of local variable slots to reserve. |
| Fields inherited from class org.jmlspecs.checker.JmlContext |
cunit, delegee, parent |
| Fields inherited from class org.multijava.util.Utils |
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO |
| Constructor Summary | |
(package private) |
JmlFlowControlContext(CFlowControlContextType parent,
int varEstimate,
TokenReference where)
Construct a nested flow control context. |
protected |
JmlFlowControlContext(CFlowControlContextType parent,
CFlowControlContextType clone)
Used to clone this flow control context. |
(package private) |
JmlFlowControlContext(CFlowControlContextType parent,
TokenReference where)
Construct a nested flow control context. |
(package private) |
JmlFlowControlContext(CMethodContextType parent,
int varEstimate,
boolean isInExternalGF,
TokenReference where)
Construct an outer-most flow control context. |
(package private) |
JmlFlowControlContext(CMethodContextType parent,
int varEstimate,
TokenReference where)
Construct an outer-most flow control context. |
| Method Summary | |
void |
addFANonNull(Object expr)
Mark expr (or member) as NonNull in this context |
void |
addFANonNulls(Object[] exprs)
adds exprs (or members) as NonNull in this context |
void |
addFANull(Object expr)
|
void |
addFANulls(Object[] exprs)
|
void |
addLocalClass(CClass clazz)
Adds to this context a class declared via a type declaration statement. |
void |
addSyntheticThisParameter()
Records that a variable slot must be reserved for a synthetic this parameter. |
void |
addThisVariable()
Records that the Java keyword this is used in this
block. |
void |
addThrowable(CThrowableInfo throwable)
Registers that the given throwable can be thrown within this context. |
void |
addVariable(JLocalVariable var)
Adds a local variable to this block |
void |
adopt(CFlowControlContextType context)
|
void |
adoptNullityInfo(CContextType other)
|
void |
adoptParallelContexts(CFlowControlContextType[] contexts)
Adopts the information from the given contexts. |
void |
checkingComplete()
Registers that this context is no longer needed. |
CFlowControlContextType |
cloneContext()
Create a clone of this context to handle divergent paths in the control flow. |
CExpressionContextType |
createExpressionContext()
|
CFlowControlContextType |
createFinallyContext(CFlowControlContextType tryContext,
TokenReference where)
|
CFlowControlContextType |
createFlowControlContext(int params,
TokenReference where)
|
CFlowControlContextType |
createFlowControlContext(TokenReference where)
|
CLabeledContext |
createLabeledContext(JLabeledStatement self)
|
CLoopContext |
createLoopContext(JLoopStatement self)
|
CFlowControlContextType[] |
createParallelContexts(int count,
TokenReference where)
Creates a set of child contexts for typechecking parallel control flows. |
CSwitchBodyContext |
createSwitchBodyContext(JSwitchStatement stmt,
CType switchType)
|
CTryContext |
createTryContext(TokenReference where)
|
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. |
void |
dumpNonNulls(String msg)
|
CVariableInfoTable |
fieldInfo()
Returns the field info table |
protected CContextNullity |
getContextNullity()
|
Object[] |
getFANonNulls()
returns the JPhyla that are known to be non-null in this context. |
Object[] |
getFANulls()
|
CFlowControlContextType |
getFlowControlContext()
Returns the nearest control flow context (where control flow information is stored.) |
JLabeledStatement |
getLabeledStatement(String label)
Returns the statement with the specified label. |
JStatement |
getNearestBreakableStatement()
Returns the nearest breakable statement. |
JStatement |
getNearestContinuableStatement()
Returns the nearest continuable statement. |
TokenReference |
getTokenReference()
|
void |
initializeField(VariableDescriptor varDesc)
Marks the field with the given descriptor as definitely assigned to in this context. |
void |
initializeVariable(VariableDescriptor varDesc)
Marks the variable with the given descriptor as definitely assigned to in this context. |
boolean |
isFANonNull(Object expr)
Indicates whether expr (or member) is conditionally NonNull is this context. |
boolean |
isFieldDefinitelyAssigned(int pos)
Indicates whether the field in the given position is definitely assigned to in this context. |
boolean |
isFreshVariableName(JLocalVariable var)
Checks whether a local variable has a name that is fresh (i.e., no other local variable in scope has the same name). |
boolean |
isReachable()
Indicates whether the statements in this context are reachable up to most recent statement that was typechecked. |
boolean |
isVarDefinitelyAssigned(int pos)
Indicates whether the variable in the given position is definitely assigned to in this context. |
boolean |
isVarDefinitelyUnassigned(int pos)
Indicates whether the variable in the given position is definitely unassigned to in this context. |
int |
localsIndex()
|
int |
localsPosition()
Returns the number of stack positions required to store the local variables encountered thus far in this context. |
ArrayList |
localVars()
Returns the local variables list |
CClass |
lookupClass(String name)
Searches for a class with the given simple name according the procedure in JLS2 6.5.5. |
JLocalVariable |
lookupLocalVariable(String ident)
Returns the variable referred to by the given name in this context, recursing to surrounding contexts as appropriate. |
void |
merge(CFlowControlContextType context)
|
void |
mergeNullityInfo(CContextType other)
Merge the list of guarded nulls in this context with that of the given context. |
int |
numberOfLocalVars()
|
int |
parentIndex()
|
void |
removeAllFANullity()
|
void |
removeFANonNull(Object expr)
|
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 |
replaceVariableInfoUpTo(int pos,
CVariableInfoTable replacement)
Replaces the local variable info in positions 0 up to pos with the info in replacement. |
void |
setReachable(boolean reachable)
Mutates the reachability status of this context. |
CVariableInfoTable |
variableInfo()
Returns the variable info table |
| 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 final int DEFAULT_VAR_ESTIMATE
| Constructor Detail |
JmlFlowControlContext(CFlowControlContextType parent,
TokenReference where)
CCompilationUnitContextType.createFlowControlContext.
requires (* \caller instanceof CContextType *); ensures ((CFlowControlContext)delegee).nestedFlowControlContext;
parent - the parent context, it must be different
than null except if called by the top level #createFlowControlContext()
JmlFlowControlContext(CFlowControlContextType parent,
int varEstimate,
TokenReference where)
createFlowControlContext(int).
requires (* \caller instanceof CContextType *); ensures ((CFlowControlContext)delegee).nestedFlowControlContext;
parent - the parent context, it must be different than
nullvarEstimate - an estimate of the number of variable slots to
reserve #createFlowControlContext(int)
JmlFlowControlContext(CMethodContextType parent,
int varEstimate,
TokenReference where)
CMethodContextType.createFlowControlContext(int).
requires (* \caller instanceof CContextType *); ensures !((CFlowControlContext)delegee).nestedFlowControlContext;
parent - the parent context, it must be different than nullvarEstimate - an estimate of the number of variable slots to
reserve CMethodContextType#createFlowControlContext(int)
JmlFlowControlContext(CMethodContextType parent,
int varEstimate,
boolean isInExternalGF,
TokenReference where)
CMethodContextType.createFlowControlContext(int, boolean).
requires (* \caller instanceof CContextType *); ensures !((CFlowControlContext)delegee).nestedFlowControlContext;
parent - the parent context, it must be different than nullvarEstimate - an estimate of the number of variable slots to
reserveisInExternalGF - true if we are currently in a method of an
external generic functionCMethodContextType#createFlowControlContext(int)
protected JmlFlowControlContext(CFlowControlContextType parent,
CFlowControlContextType clone)
parent - the parent context, it must be different
than nullclone - the context whose state is to be adopted| Method Detail |
public void checkingComplete()
Registers that this context is no longer needed. Passes information collected by this context to the parent context.
Passes this context's field information to the surrounding context; passes local variable information to the surrounding context if that context is one which maintains local variable information.
Checks that local variables are used and issues warnings if not.
This should only be called on a linearly nested context! !FIXME!10/26 If we refactor the context creation code as planned (to lock the parent context) then this method is called to unlock the parent context when we exit a linearly nested context.
checkingComplete in interface CFlowControlContextTypepublic TokenReference getTokenReference()
getTokenReference in interface CFlowControlContextTypepublic CFlowControlContextType createFlowControlContext(TokenReference where)
createFlowControlContext in interface CFlowControlContextType
public CFlowControlContextType createFlowControlContext(int params,
TokenReference where)
createFlowControlContext in interface CFlowControlContextTypepublic CLabeledContext createLabeledContext(JLabeledStatement self)
createLabeledContext in interface CFlowControlContextTypepublic CLoopContext createLoopContext(JLoopStatement self)
createLoopContext in interface CFlowControlContextType
public CSwitchBodyContext createSwitchBodyContext(JSwitchStatement stmt,
CType switchType)
createSwitchBodyContext in interface CFlowControlContextTypepublic CTryContext createTryContext(TokenReference where)
createTryContext in interface CFlowControlContextType
public CFlowControlContextType createFinallyContext(CFlowControlContextType tryContext,
TokenReference where)
createFinallyContext in interface CFlowControlContextTypepublic CExpressionContextType createExpressionContext()
createExpressionContext in interface CFlowControlContextTypepublic CFlowControlContextType cloneContext()
cloneContext in interface CFlowControlContextType
public CFlowControlContextType[] createParallelContexts(int count,
TokenReference where)
adoptParallelContexts method of this.
also requires count > 0;
createParallelContexts in interface CFlowControlContextTypeadoptParallelContexts(CFlowControlContextType[])public void adoptParallelContexts(CFlowControlContextType[] contexts)
also requires contexts != null && contexts.length > 0;
adoptParallelContexts in interface CFlowControlContextTypepublic void merge(CFlowControlContextType context)
merge in interface CFlowControlContextTypepublic void adopt(CFlowControlContextType context)
adopt in interface CFlowControlContextTypepublic boolean isFreshVariableName(JLocalVariable var)
isFreshVariableName in interface CFlowControlContextTypevar - the variable
public void addVariable(JLocalVariable var)
throws UnpositionedError
addVariable in interface CFlowControlContextTypevar - the name of the variable
UnpositionedError - if the variable is a redeclarationpublic void addThisVariable()
this is used in this
block.
addThisVariable in interface CFlowControlContextTypepublic void addSyntheticThisParameter()
this parameter. Recall that this is
passed as a parameter for external methods.
addSyntheticThisParameter in interface CFlowControlContextTypepublic int localsPosition()
localsPosition in interface CFlowControlContextTypepublic int numberOfLocalVars()
numberOfLocalVars in interface CFlowControlContextTypepublic CVariableInfoTable variableInfo()
CFlowControlContextType
variableInfo in interface CFlowControlContextTypepublic CVariableInfoTable fieldInfo()
CFlowControlContextType
fieldInfo in interface CFlowControlContextTypepublic ArrayList localVars()
CFlowControlContextType
localVars in interface CFlowControlContextTypepublic int parentIndex()
parentIndex in interface CFlowControlContextTypepublic int localsIndex()
localsIndex in interface CFlowControlContextTypepublic final void setReachable(boolean reachable)
setReachable in interface CFlowControlContextTypereachable - indicates whether the statements in this context
are reachable after the current statement being
checked.public final boolean isReachable()
setReachable appropriately.)
isReachable in interface CFlowControlContextTypepublic JLabeledStatement getLabeledStatement(String label)
getLabeledStatement in interface CFlowControlContextTypepublic JStatement getNearestBreakableStatement()
getNearestBreakableStatement in interface CFlowControlContextTypepublic JStatement getNearestContinuableStatement()
getNearestContinuableStatement in interface CFlowControlContextTypepublic CFlowControlContextType getFlowControlContext()
getFlowControlContext in interface CFlowControlContextTypegetFlowControlContext in class JmlContextpublic void initializeVariable(VariableDescriptor varDesc)
initializeVariable in interface CFlowControlContextTypepublic boolean isVarDefinitelyAssigned(int pos)
isVarDefinitelyAssigned in interface CFlowControlContextTypepublic boolean isVarDefinitelyUnassigned(int pos)
isVarDefinitelyUnassigned in interface CFlowControlContextTypepos - stack position
public void replaceFieldInfoUpTo(int pos,
CVariableInfoTable replacement)
pos with the info in replacement.
replaceFieldInfoUpTo in interface CFlowControlContextTypereplaceFieldInfoUpTo in class JmlContext
public void replaceVariableInfoUpTo(int pos,
CVariableInfoTable replacement)
pos with the info in replacement.
replaceVariableInfoUpTo in interface CFlowControlContextTypepublic void initializeField(VariableDescriptor varDesc)
initializeField in interface CFlowControlContextTypeinitializeField in class JmlContextpublic boolean isFieldDefinitelyAssigned(int pos)
isFieldDefinitelyAssigned in interface CFlowControlContextTypeisFieldDefinitelyAssigned in class JmlContext
public void addLocalClass(CClass clazz)
throws UnpositionedError
addLocalClass in interface CFlowControlContextTypeclazz - the clazz to add
UnpositionedError - if duplicate class exists in this
lexical context protected CContextNullity getContextNullity()
getContextNullity in class JmlContextpublic boolean isFANonNull(Object expr)
isFANonNull in interface CContextTypeisFANonNull in class JmlContextpublic Object[] getFANonNulls()
getFANonNulls in interface CContextTypegetFANonNulls in class JmlContextpublic Object[] getFANulls()
getFANulls in interface CContextTypegetFANulls in class JmlContextpublic void addFANonNull(Object expr)
addFANonNull in interface CContextTypeaddFANonNull in class JmlContextpublic void addFANull(Object expr)
addFANull in interface CContextTypeaddFANull in class JmlContextpublic void removeFANonNull(Object expr)
removeFANonNull in interface CContextTyperemoveFANonNull in class JmlContextpublic void removeAllFANullity()
removeAllFANullity in interface CContextTyperemoveAllFANullity in class JmlContextpublic void addFANonNulls(Object[] exprs)
addFANonNulls in interface CContextTypeaddFANonNulls in class JmlContextpublic void addFANulls(Object[] exprs)
addFANulls in interface CContextTypeaddFANulls in class JmlContextpublic void mergeNullityInfo(CContextType other)
mergeNullityInfo in interface CContextTypemergeNullityInfo in class JmlContextpublic void adoptNullityInfo(CContextType other)
adoptNullityInfo in interface CContextTypeadoptNullityInfo in class JmlContextpublic void dumpNonNulls(String msg)
dumpNonNulls in interface CContextTypedumpNonNulls in class JmlContext
public CClass lookupClass(String name)
throws UnpositionedError
lookupClass in interface CFlowControlContextTypelookupClass in class JmlContextname - the class name, without qualifiers
UnpositionedError - if search fails public JLocalVariable lookupLocalVariable(String ident)
null
is returned.
lookupLocalVariable in interface CContextTypelookupLocalVariable in class JmlContextident - the name of the variable
public boolean declaredOutsideOfLoop(JLocalVariable var)
declaredOutsideOfLoop in interface CContextTypedeclaredOutsideOfLoop in class JmlContextpublic boolean declares(JLocalVariable var)
declares in interface CContextTypedeclares in class JmlContextpublic void addThrowable(CThrowableInfo throwable)
CFlowControlContextType
addThrowable in interface CFlowControlContextTypethrowable - the type of the new throwable
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||