mjc

org.multijava.mjc
Interface CClassContextType

All Superinterfaces:
CContextType
All Known Subinterfaces:
CInterfaceContextType
All Known Implementing Classes:
CClassContext, CInterfaceContext

public interface CClassContextType
extends CContextType

This class represents the context for a class during checking passes (checkInterface, checkInitializers, typecheck).

See Also:
CContextType

Method Summary
 void addInitializer()
          Add an initializer to this context
 void checkingComplete(JTypeDeclarationType decl, CVariableInfoTable staticC, CVariableInfoTable instanceC, CVariableInfoTable[] constructorsC)
          Verifies that all final fields are initialized and all abstract methods are appropriately implemented.
 CConstructorContextType createConstructorContext(CMethod self)
           
 CInitializerContextType createInitializerContext(CMethod self)
           
 CMethodContextType createMethodContext(CMethod self)
           
 CVariableInfoTable fieldInfo()
          Returns the fieldInfo table.
 CVariableInfoTable fieldInfoTable()
          Returns the current field information for the most recently checked member of this context.
 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()
          getClassContext
 CClass getHostClass()
          Returns the CClass representing the signature of the class containing this context.
 CClass getOwnerClass()
          Returns the CClass representing the signature of the class that is the logical owner of this context.
 boolean hasInitializer()
          Returns true if this class need initializers
 void initializeField(VariableDescriptor varDesc)
          Marks the field 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.
 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, CExpressionContextType context)
          lookupField
 CMethod lookupMethod(String ident, CType[] params, CClassContextType context)
          Searches for the most specific method when no receiver is explicit at the call site.
 CMethodSet lookupMethodOrSet(String ident, CType[] params, CClassContextType context)
          Searches for the most specific method(s) when no receiver is explicit at the call site.
 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 the type variable that are accessible
 void markAllFieldsAsInitialized()
           
 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 resolveMaybeExtMethodRef(String ident)
          Searches for any imported or private external generic functions.
 void setFieldInfoTable(CVariableInfoTable fieldInfo)
          Sets the field information for this to match that given by fieldInfo.
 
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, getCMethod, getCompilationUnit, getCompiler, getFANonNulls, getFANulls, getFlowControlContext, getMethodContext, getParentContext, isBeforeSuperConstructorCall, isFANonNull, isInConstructor, isInInitializer, isInLoop, isPure, isStatic, lookupField, lookupLocalVariable, lookupMethod, lookupMethodOrSet, lookupOuterField, mergeNullityInfo, modUtil, registerGFDecl, registerVisibleMethod, removeAllFANullity, removeFANonNull, reportTrouble
 

Method Detail

checkingComplete

public void checkingComplete(JTypeDeclarationType decl,
                             CVariableInfoTable staticC,
                             CVariableInfoTable instanceC,
                             CVariableInfoTable[] constructorsC)
                               throws UnpositionedError
Verifies that all final fields are initialized and all abstract methods are appropriately implemented.

Throws:
UnpositionedError - if any checks fail

createMethodContext

public CMethodContextType createMethodContext(CMethod self)

createConstructorContext

public CConstructorContextType createConstructorContext(CMethod self)

createInitializerContext

public CInitializerContextType createInitializerContext(CMethod self)

addInitializer

public void addInitializer()
Add an initializer to this context


hasInitializer

public boolean hasInitializer()
Returns true if this class need initializers


fieldInfo

public CVariableInfoTable fieldInfo()
Returns the fieldInfo table.

Returns:
an field into table.

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

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

fieldInfoTable

public CVariableInfoTable fieldInfoTable()
Returns the current field information for the most recently checked member of this context. It then clears the field info stored in this object. The pattern of use is to pass this context into a typecheck method. That method mutates this context to include the variable information extracted from the statement being checked. Upon return from the typecheck the caller calls fieldInfoTable to extract the information. This is kludgey and one wonders why the typecheck methods doesn't just return the CVariableInfoTable instance. !FIXME!


setFieldInfoTable

public void setFieldInfoTable(CVariableInfoTable fieldInfo)
Sets the field information for this to match that given by fieldInfo. Called before typechecking constructors with the argument equal to the field assignment information after checking initializers.


markAllFieldsAsInitialized

public void markAllFieldsAsInitialized()

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 implements the second and third bullet points of the procedure. That is "Otherwise, if the simple type name occurs within the scope of exactly one visible member type, then the simple type name denotes that member type;" and "Otherwise, if the simple type name occurs within the scope of more than one visible member type, then the name is ambiguous as a type name; a compile-time error occurs." If the class is not found according to these constraints, then the surrounding context is called to check the remaining bullets.

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

lookupTypeVariable

public CTypeVariable lookupTypeVariable(String ident)
                                          throws UnpositionedError
search for the type variable that are accessible

Specified by:
lookupTypeVariable in interface CContextType
Throws:
UnpositionedError

lookupMethod

public CMethod lookupMethod(String ident,
                            CType[] params,
                            CClassContextType context)
                              throws UnpositionedError
Searches for the most specific method when no receiver is explicit at the call site.

Specified by:
lookupMethod in interface CContextType
Parameters:
ident - method name
params - method parameters
context - the context of the class containing the method call
Returns:
the method or null if not found
Throws:
UnpositionedError - this error will be positioned soon

lookupMethodOrSet

public CMethodSet lookupMethodOrSet(String ident,
                                    CType[] params,
                                    CClassContextType context)
                                      throws UnpositionedError
Searches for the most specific method(s) when no receiver is explicit at the call site.

Specified by:
lookupMethodOrSet in interface CContextType
Parameters:
ident - method name
params - method parameters
context - the context of the class containing the method call
Returns:
the method or null if not found
Throws:
UnpositionedError - this error will be positioned soon

lookupOuterField

public CFieldAccessor lookupOuterField(String ident,
                                       CExpressionContextType context)
                                         throws UnpositionedError
Searches for a field of the given name in the context surrounding the current lexical contour.

Specified by:
lookupOuterField in interface CContextType
Parameters:
ident - the name of the field
context - the context of the field access
Returns:
a variable from a field in the surrounding context, or null if none is found
Throws:
UnpositionedError - this error will be positioned soon

lookupField

public CFieldAccessor lookupField(String ident,
                                  CExpressionContextType context)
                                    throws UnpositionedError
lookupField

Specified by:
lookupField in interface CContextType
Parameters:
ident - the name of the field
context - the context of the field access
Returns:
a variable from an ident in current context
Throws:
UnpositionedError - this error will be positioned soon

lookupOuterLocalVariable

public JExpression lookupOuterLocalVariable(TokenReference ref,
                                            String ident)
Finds a local variable with the given name that appears outside the current lexical contour.

Specified by:
lookupOuterLocalVariable in interface CContextType
Parameters:
ref - a token reference used to build a new JOuterLocalVariableExpression
ident - the name of the outer variable
Returns:
a variable from an ident in the surrounding context, or null if not found

getClassContext

public CClassContextType getClassContext()
getClassContext

Specified by:
getClassContext in interface CContextType
Returns:
the near parent of type CClassContextType

getHostClass

public CClass getHostClass()
Returns the CClass representing the signature of the class containing this context.

Returns:
the CClass representing the signature of the class

getOwnerClass

public CClass getOwnerClass()
Returns the CClass representing the signature of the class that is the logical owner of this context. Useful for external methods where the host is the generic function anchor but the owner is the method's receiver.

Returns:
the CClass representing the signature of the class
See Also:
getHostClass(), org.multijava.mjc.CExtMethodContext#getHostClass()

findNearestHost

public CMemberHost findNearestHost()
Returns the signature of the nearest lexically enclosing context that can host member declarations (i.e., a 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 duplicated in every anchor.

Specified by:
findNearestHost in interface CContextType
Returns:
the nearest parent that can be coerced to a CMemberHost, i.e., this.self

resolveMaybeExtMethodRef

public void resolveMaybeExtMethodRef(String ident)
Searches for any imported or private external generic functions.

Specified by:
resolveMaybeExtMethodRef in interface CContextType
Parameters:
ident - the name of the generic function to search for

registerVisibleType

public void registerVisibleType(CType type)
Registers with the surrounding context that a reference to the given type occurs in this context.

Specified by:
registerVisibleType in interface CContextType

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.