mjc

org.multijava.mjc
Interface CFlowControlContextType

All Superinterfaces:
CContextType
All Known Implementing Classes:
CFinallyContext, CFlowControlContext

public interface CFlowControlContextType
extends CContextType

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


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.
 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)
           
 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.
 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 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
 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.
 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.
 CVariableInfoTable variableInfo()
          Returns the variable info table
 
Methods inherited from interface org.multijava.mjc.CContextType
addFANonNull, addFANonNulls, addFANull, addFANulls, adoptNullityInfo, arithmeticMode, catchUp, check, check, check, check, classToGenerate, createClassContext, createExtMethodContext, createInterfaceContext, declaredOutsideOfLoop, declares, dumpNonNulls, fail, fail, findNearestHost, getClassContext, getCMethod, getCompilationUnit, getCompiler, getFANonNulls, getFANulls, getMethodContext, getParentContext, isBeforeSuperConstructorCall, isFANonNull, isInConstructor, isInInitializer, isInLoop, isPure, isStatic, lookupField, lookupField, lookupLocalVariable, lookupMethod, lookupMethod, lookupMethodOrSet, lookupMethodOrSet, lookupOuterField, lookupOuterField, lookupOuterLocalVariable, lookupTypeVariable, mergeNullityInfo, modUtil, registerGFDecl, registerVisibleMethod, registerVisibleType, removeAllFANullity, removeFANonNull, reportTrouble, resolveMaybeExtMethodRef
 

Method Detail

checkingComplete

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.


getTokenReference

public TokenReference getTokenReference()

createFlowControlContext

public CFlowControlContextType createFlowControlContext(TokenReference where)

createFlowControlContext

public CFlowControlContextType createFlowControlContext(int params,
                                                        TokenReference where)

createLabeledContext

public CLabeledContext createLabeledContext(JLabeledStatement self)

createLoopContext

public CLoopContext createLoopContext(JLoopStatement self)

createSwitchBodyContext

public CSwitchBodyContext createSwitchBodyContext(JSwitchStatement stmt,
                                                  CType switchType)

createTryContext

public CTryContext createTryContext(TokenReference where)

createFinallyContext

public CFlowControlContextType createFinallyContext(CFlowControlContextType tryContext,
                                                    TokenReference where)

createExpressionContext

public CExpressionContextType createExpressionContext()

cloneContext

public CFlowControlContextType cloneContext()
Create a clone of this context to handle divergent paths in the control flow.


createParallelContexts

public CFlowControlContextType[] createParallelContexts(int count,
                                                        TokenReference where)
Creates a set of child contexts for typechecking parallel control flows. After using the contexts they should be passed to the adoptParallelContexts method of this.

 requires count > 0;
 

See Also:
adoptParallelContexts(CFlowControlContextType[])

adoptParallelContexts

public void adoptParallelContexts(CFlowControlContextType[] contexts)
Adopts the information from the given contexts.

 requires contexts != null && contexts.length > 0;
 


merge

public void merge(CFlowControlContextType context)

adopt

public void adopt(CFlowControlContextType context)

isFreshVariableName

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

Parameters:
var - the variable

addVariable

public void addVariable(JLocalVariable var)
                          throws UnpositionedError
Adds a local variable to this block

Parameters:
var - the name of the variable
Throws:
UnpositionedError - if the variable is a redeclaration

addThisVariable

public void addThisVariable()
Records that the Java keyword this is used in this block.


addSyntheticThisParameter

public void addSyntheticThisParameter()
Records that a variable slot must be reserved for a synthetic this parameter. Recall that this is passed as a parameter for external methods.


localsPosition

public int localsPosition()
Returns the number of stack positions required to store the local variables encountered thus far in this context.


numberOfLocalVars

public int numberOfLocalVars()

variableInfo

public CVariableInfoTable variableInfo()
Returns the variable info table


fieldInfo

public CVariableInfoTable fieldInfo()
Returns the field info table


localVars

public ArrayList localVars()
Returns the local variables list


parentIndex

public int parentIndex()

localsIndex

public int localsIndex()

setReachable

public void setReachable(boolean reachable)
Mutates the reachability status of this context.

Parameters:
reachable - indicates whether the statements in this context are reachable after the current statement being checked.

isReachable

public boolean isReachable()
Indicates whether the statements in this context are reachable up to most recent statement that was typechecked. (Assuming that statement's typechecking code calls setReachable appropriately.)

Returns:
if this context is still reachable

getLabeledStatement

public JLabeledStatement getLabeledStatement(String label)
Returns the statement with the specified label.


getNearestBreakableStatement

public JStatement getNearestBreakableStatement()
Returns the nearest breakable statement.


getNearestContinuableStatement

public JStatement getNearestContinuableStatement()
Returns the nearest continuable statement.


getFlowControlContext

public CFlowControlContextType getFlowControlContext()
Returns the nearest control flow context (where control flow information is stored.)

Specified by:
getFlowControlContext in interface CContextType
Returns:
the nearest parent of type CFlowControlContextType

initializeVariable

public void initializeVariable(VariableDescriptor varDesc)
Marks the variable with the given descriptor as definitely assigned to in this context.


isVarDefinitelyAssigned

public boolean isVarDefinitelyAssigned(int pos)
Indicates whether the variable in the given position is definitely assigned to in this context.


isVarDefinitelyUnassigned

public boolean isVarDefinitelyUnassigned(int i)
Indicates whether the variable in the given position is definitely unassigned to in this context

Parameters:
i - stack position
Returns:
true iff the variable is definitely unassigned

replaceFieldInfoUpTo

public void replaceFieldInfoUpTo(int pos,
                                 CVariableInfoTable replacement)
Replaces the local field info for fields in positions 0 up to pos with the info in replacement.

Specified by:
replaceFieldInfoUpTo in interface CContextType

replaceVariableInfoUpTo

public void replaceVariableInfoUpTo(int pos,
                                    CVariableInfoTable replacement)
Replaces the local variable info in positions 0 up to pos with the info in replacement.


initializeField

public void initializeField(VariableDescriptor varDesc)
Marks the field with the given descriptor as definitely assigned to in this context.

Specified by:
initializeField in interface CContextType

isFieldDefinitelyAssigned

public boolean isFieldDefinitelyAssigned(int pos)
Indicates whether the field in the given position is definitely assigned to in this context.

Specified by:
isFieldDefinitelyAssigned in interface CContextType

addLocalClass

public void addLocalClass(CClass clazz)
                            throws UnpositionedError
Adds to this context a class declared via a type declaration statement.

Parameters:
clazz - the clazz to add
Throws:
UnpositionedError - if duplicate class exists in this lexical context

lookupClass

public CClass lookupClass(String name)
                            throws UnpositionedError
Searches for a class with the given simple name according the procedure in JLS2 6.5.5. This method checks the first bullet point of that section: "If the simple type name occurs within the scope of a visible local class declaration with that name, then the simple type name denotes that local class type." If no match is found, then this method calls to the surrounding context to check the remaining bullet points.

Specified by:
lookupClass in interface CContextType
Parameters:
name - the class name, without qualifiers
Returns:
the class if found, null otherwise
Throws:
UnpositionedError - if search fails

addThrowable

public void addThrowable(CThrowableInfo throwable)
Registers that the given throwable can be thrown within this context. The implementation passes the throwable up through the nested contexts until a surrounding context is found that can handle throwables. For example, a CMethodContextType instance collects the throwables that are uncaught within a method body, while a CTryContext collects the throwables that are thrown within a try-block and are therefore subject to handling by associated catch-blocks.

Parameters:
throwable - the type of the new throwable

mjc

mjc is Copyright (C) 2000-2004 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. mjc is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.