|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
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.
| 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 |
adoptNullityInfo(CContextType other)
|
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. |
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. |
void |
dumpNonNulls(String msg)
|
void |
fail(MessageDescription mess,
Object param1,
Object param2)
Generates an UnpositionedError with a given message. |
void |
fail(MessageDescription mess,
Object[] params)
|
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 |
Object[] |
getFANonNulls()
returns the JPhyla that are known to be non-null in this context. |
Object[] |
getFANulls()
|
CFlowControlContextType |
getFlowControlContext()
Returns the nearest expression context. |
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. |
boolean |
isBeforeSuperConstructorCall()
Indicates whether this context is enclosed in a constructor and occurs before the constructor has invoked the superclass constructor. |
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 |
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 |
void |
mergeNullityInfo(CContextType other)
Merge the list of nulls in this context with that of the given context. |
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 |
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 |
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. |
| Method Detail |
public CClass lookupClass(String name)
throws UnpositionedError
name - the class name, without qualifiers
UnpositionedError - if search fails
public CTypeVariable lookupTypeVariable(String Ident)
throws UnpositionedError
UnpositionedError
public CMethod lookupMethod(String name,
CType[] params)
throws UnpositionedError
name - method nameparams - method parameter types
UnpositionedError - if the result is ambiguous
public CMethod lookupMethod(String name,
CType[] params,
CClassContextType context)
throws UnpositionedError
name - 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
name - method nameparams - method parameter types
UnpositionedError - if the result is ambiguous
public CMethodSet lookupMethodOrSet(String name,
CType[] params,
CClassContextType context)
throws UnpositionedError
name - 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
UnpositionedError - this error will be positioned soon
public CFieldAccessor lookupField(String ident,
CExpressionContextType context)
throws UnpositionedError
UnpositionedError - this error will be positioned soonpublic JLocalVariable lookupLocalVariable(String ident)
ident - the name of the local variable
public JExpression lookupOuterLocalVariable(TokenReference ref,
String ident)
ref - a token reference used to build a new
JOuterLocalVariableExpressionident - the name of the outer variable
public CFieldAccessor lookupOuterField(String ident)
throws UnpositionedError
ident - the name of the field
UnpositionedError - this error will be positioned soon
public CFieldAccessor lookupOuterField(String ident,
CExpressionContextType context)
throws UnpositionedError
ident - 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.
public void initializeField(VariableDescriptor varDesc)
public boolean isFieldDefinitelyAssigned(int pos)
public CContextType getParentContext()
public CCompilationUnitContextType getCompilationUnit()
public CClassContextType getClassContext()
public CMethodContextType getMethodContext()
public CFlowControlContextType getFlowControlContext()
public CMethod getCMethod()
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.
CMemberHost public CClassContextType createClassContext(CClass self)
self - the corresponding classpublic CInterfaceContextType createInterfaceContext(CClass self)
self - the corresponding interface signature
public CExtMethodContext createExtMethodContext(CSourceClass host,
CClass owner)
host - the host classowner - the receiver classpublic void classToGenerate(CSourceClass clazz)
clazz - the class to be generatedpublic void resolveMaybeExtMethodRef(String ident)
ident - the name of the generic function to search for
public void registerGFDecl(String methodIdent,
CGenericFunctionCollection coll)
public void registerVisibleMethod(CMethod method)
public void registerVisibleType(CType type)
public void reportTrouble(Exception trouble)
trouble - the error
public void fail(MessageDescription mess,
Object param1,
Object param2)
throws UnpositionedError
mess - 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 boolean check(boolean expr,
MessageDescription mess)
throws UnpositionedError
expr - 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
UnpositionedError
public boolean check(boolean expr,
MessageDescription mess,
Object param1)
throws UnpositionedError
expr - 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
expr - condition to verifymess - the message to be displayedparam1 - the first parameterparam2 - the second parameter
UnpositionedError - this error will be positioned soonpublic Main getCompiler()
public ModifierUtility modUtil()
public boolean isInLoop()
public boolean declaredOutsideOfLoop(JLocalVariable var)
public boolean declares(JLocalVariable var)
public boolean isInInitializer()
public boolean isInConstructor()
public boolean isBeforeSuperConstructorCall()
public boolean isStatic()
public boolean isPure()
public void catchUp(JTypeDeclarationType decl)
public MJMathMode arithmeticMode()
public boolean isFANonNull(Object expr)
public Object[] getFANonNulls()
public Object[] getFANulls()
public void addFANonNull(Object expr)
public void addFANull(Object expr)
public void removeFANonNull(Object expr)
public void removeAllFANullity()
public void addFANonNulls(Object[] exprs)
public void addFANulls(Object[] exprs)
public void mergeNullityInfo(CContextType other)
public void adoptNullityInfo(CContextType other)
public void dumpNonNulls(String msg)
|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||