|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.multijava.util.Utils
org.multijava.mjc.CContext
org.multijava.mjc.CFlowControlContext
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 | |
protected CFlowControlContextType |
cachedParent
This is an alias of the inherited parent field but stored as a subtype to avoid casts. |
private static int |
DEFAULT_VAR_ESTIMATE
Default estimate of the number of local variable slots to reserve. |
protected CVariableInfoTable |
fieldInfo
The definite assignment state of the fields in this context. |
private HashMap |
innerClasses
A map from identifiers to class signatures for the classes declared via type declaration statements in this context. |
protected boolean |
isReachable
|
private int |
localsIndex
The total number of local variables declared in this context. |
private int |
localsPosition
The number of stack positions required to store the local variables encountered thus far in this and surrounding contexts. |
private ArrayList |
localVars
A list of the local variables declared in this context. |
protected CMethodContextType |
methodContext
This is an alias of the inherited parent field but stored as a subtype to avoid casts. |
private int |
parentIndex
The total number of local variables declared in the surrounding contexts before the beginning of this context. |
protected CVariableInfoTable |
variableInfo
The definite assignment state of the variables in this context. |
private TokenReference |
where
A source code position for the start of this context. |
| Fields inherited from class org.multijava.mjc.CContext |
contextNullity, cunit, parent |
| Fields inherited from class org.multijava.util.Utils |
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO |
| Constructor Summary | |
CFlowControlContext(CFlowControlContextType parent,
int varEstimate,
TokenReference where)
Construct a nested flow control context. |
|
CFlowControlContext(CFlowControlContextType parent,
CFlowControlContextType clone)
Used to clone this flow control context in subclasses. |
|
CFlowControlContext(CFlowControlContextType parent,
TokenReference where)
Construct a nested flow control context. |
|
CFlowControlContext(CMethodContextType parent,
int varEstimate,
boolean isInExternalGF,
TokenReference where)
Construct an outer-most flow control context. |
|
CFlowControlContext(CMethodContextType parent,
int varEstimate,
TokenReference where)
|
|
| Method Summary | |
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 |
adoptParallelContexts(CFlowControlContextType[] contexts)
Adopts the information from the given contexts. |
CFlowControlContextType |
cachedParent()
|
protected void |
checkAssignmentToFinals()
For each variable (and field), if it is definitely assigned in this context, is not definitely assigned in the parent context, and is final, then report error. |
void |
checkingComplete()
Registers that this context is no longer needed. |
protected void |
checkLocalVarUsage()
Checks that all declare local variables have been used now that they are going out of scope. |
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. |
private CVariableState |
fieldAt(int pos)
|
protected int |
fieldCount()
Returns the number of fields in the enclosing class. |
String |
fieldIdent(int pos)
|
CVariableInfoTable |
fieldInfo()
Returns the field info table |
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. |
private void |
initializeLocalVars(int varEstimate)
Initializes local vars based on the value of varEstimate. |
void |
initializeVariable(VariableDescriptor varDesc)
Marks the variable with the given descriptor as definitely assigned to in this context. |
boolean |
isFieldDefinitelyAssigned(int pos)
Indicates whether the field in the given position is definitely assigned to in this context. |
boolean |
isFieldFinal(int pos)
|
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 i)
Indicates whether the variable in the given position is definitely unassigned to in this context |
boolean |
isVarFinal(int pos)
|
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. |
private CClass |
lookupLocalClass(String ident)
Looks for a class with the given name declared via a type declaration statement in this context. |
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)
|
int |
numberOfLocalVars()
|
int |
parentIndex()
|
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. |
String |
toString()
|
private CVariableState |
varAt(int pos)
|
CVariableInfoTable |
variableInfo()
Returns the variable info table |
String |
varIdent(int pos)
|
| 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, wait, wait, wait |
| Field Detail |
protected final CFlowControlContextType cachedParent
protected final CMethodContextType methodContext
protected boolean isReachable
protected CVariableInfoTable variableInfo
protected CVariableInfoTable fieldInfo
private HashMap innerClasses
private ArrayList localVars
private invariant localVars != null ==> (\forall Object o; localVars.contains(o); o instanceof JLocalVariable );
private final int parentIndex
private int localsIndex
private int localsPosition
private static final int DEFAULT_VAR_ESTIMATE
private final TokenReference where
| Constructor Detail |
public CFlowControlContext(CFlowControlContextType parent,
TokenReference where)
CCompilationUnitContextType.createFlowControlContext.
requires (* \caller instanceof CContextType *); ensures nestedFlowControlContext;
where - a source-code location for the start of this contextparent - the parent context, it must be different than null except if
called by the top levelcreateFlowControlContext(org.multijava.util.compiler.TokenReference)
public CFlowControlContext(CFlowControlContextType parent,
int varEstimate,
TokenReference where)
createFlowControlContext(int).
requires (* \caller instanceof CContextType *); ensures nestedFlowControlContext;
parent - the parent context, it must be different than nullvarEstimate - an estimate of the number of variable slots to reservewhere - a source-code location for the start of this contextcreateFlowControlContext(int, org.multijava.util.compiler.TokenReference)
public CFlowControlContext(CMethodContextType parent,
int varEstimate,
boolean isInExternalGF,
TokenReference where)
CMethodContextType.createFlowControlContext(int).
requires (* \caller instanceof CContextType *); ensures !nestedFlowControlContext;
parent - the parent context, it must be different than nullvarEstimate - an estimate of the number of variable slots to
reserveisInExternalGF - true if this context is in a method that is part of an
external generic functionCMethodContextType.createFlowControlContext(int, boolean,
org.multijava.util.compiler.TokenReference)
public CFlowControlContext(CMethodContextType parent,
int varEstimate,
TokenReference where)
public CFlowControlContext(CFlowControlContextType parent,
CFlowControlContextType clone)
requires (* \caller instanceof CContextType *); ensures nestedFlowControlContext;
clone - the context whose state is to be adoptedparent - the parent context, it must be different than null| Method Detail |
public String toString()
toString in class Objectprivate void initializeLocalVars(int varEstimate)
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 CFlowControlContextTypeprotected void checkLocalVarUsage()
public 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 final void merge(CFlowControlContextType context)
merge in interface CFlowControlContextTypepublic final 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 CFlowControlContextTypeprotected void checkAssignmentToFinals()
public 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 CContextpublic void initializeVariable(VariableDescriptor varDesc)
initializeVariable in interface CFlowControlContextTypepublic boolean isVarDefinitelyAssigned(int pos)
isVarDefinitelyAssigned in interface CFlowControlContextTypepublic boolean isVarDefinitelyUnassigned(int i)
CFlowControlContextType
isVarDefinitelyUnassigned in interface CFlowControlContextTypei - stack position
public boolean isVarFinal(int pos)
public String varIdent(int pos)
private CVariableState varAt(int pos)
public void replaceFieldInfoUpTo(int pos,
CVariableInfoTable replacement)
pos with the info in replacement.
replaceFieldInfoUpTo in interface CFlowControlContextTypereplaceFieldInfoUpTo in class CContext
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 CContextpublic boolean isFieldDefinitelyAssigned(int pos)
isFieldDefinitelyAssigned in interface CFlowControlContextTypeisFieldDefinitelyAssigned in class CContextpublic boolean isFieldFinal(int pos)
public String fieldIdent(int pos)
private CVariableState fieldAt(int pos)
protected int fieldCount()
public void addLocalClass(CClass clazz)
throws UnpositionedError
addLocalClass in interface CFlowControlContextTypeclazz - the clazz to add
UnpositionedError - if duplicate class exists in this lexical context
public CClass lookupClass(String name)
throws UnpositionedError
lookupClass in interface CFlowControlContextTypelookupClass in class CContextname - the class name, without qualifiers
UnpositionedError - if search failsprivate CClass lookupLocalClass(String ident)
ident - the name of the class
public JLocalVariable lookupLocalVariable(String ident)
null is returned.
lookupLocalVariable in interface CContextTypelookupLocalVariable in class CContextident - the name of the variable
public boolean declaredOutsideOfLoop(JLocalVariable var)
declaredOutsideOfLoop in interface CContextTypedeclaredOutsideOfLoop in class CContextpublic boolean declares(JLocalVariable var)
declares in interface CContextTypedeclares in class CContextpublic void addThrowable(CThrowableInfo throwable)
addThrowable in interface CFlowControlContextTypethrowable - the type of the new throwablepublic CFlowControlContextType cachedParent()
|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||