mjc

org.multijava.mjc
Interface JCompilationUnitType

All Superinterfaces:
Comparable, CompilerPassEnterable
All Known Implementing Classes:
JCompilationUnit

public interface JCompilationUnitType
extends CompilerPassEnterable

This type represents a single Java compilation unit (typically a file in a file-based compiler like this) in the AST. The production for a compilation unit is the main entry point in Java parser grammar.


Method Summary
 void accept(MjcVisitor p)
          Accepts the specified visitor
 CSourceClass[] allTypeSignatures()
          Returns the CSourceClass objects representing the type signatures of the types declared in this compilatoin unit and as nested types.
 void cachePassParameters(Main compiler, Destination destination)
          Caches the arguments for the compiler passes.
 void checkInitializers(Main compiler)
          Checks the static initializers created during the checkInterface pass and performs some other checks that can be performed simply before full blown typechecking.
 void checkInterface(Main compiler)
          Checks the basic interfaces to make sure things generally look OK.
 boolean declaresGF(String qualifiedName)
          Returns true iff this compilation unit contains a declaration for a generic function with the given fully qualified name.
 boolean declaresType(String qualifiedName)
          Returns true iff this compilation unit contains a declaration for a type with the given fully qualified name.
 File file()
          Returns the file associated with this compilation unit.
 String fileNameIdent()
          Returns the Java identifier associated with the name of the file containing this compilation unit.
 MJGenericFunctionDecl[] gfDeclarations()
           
 JClassOrGFImportType[] importedClasses()
           
 JClassOrGFImportType[] importedGFs()
           
 JPackageImportType[] importedPackages()
           
 JClassOrGFImportType[] importedUnits()
          Returns an array of the class and generic function imports for this compilation unit.
 JPackageName packageName()
           
 String packageNameAsString()
           
 void preprocessDependencies(Main compiler)
          Performs preliminary processing on compilation units and types.
 void resolveSpecializers()
          Resolves value specializer expressions to the compile-time constants they represent.
 void resolveTopMethods()
          Finds the top method of every declared method.
 ArrayList tlMethods()
          Returns the AST subtrees for the augmenting method declarations.
 void translateMJ(Main compiler)
          Refactors this to include dispatchers for multimethods and other code necessary for running MultiJava code on a standard JVM.
 void typecheck(Main compiler)
          Typechecks this compilation unit.
 JTypeDeclarationType[] typeDeclarations()
           
 
Methods inherited from interface org.multijava.mjc.CompilerPassEnterable
checkInitializers, checkInterface, getTokenReference, preprocessDependencies, translateMJ, typecheck
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Method Detail

packageNameAsString

public String packageNameAsString()
Returns:
the package name of this compilation unit

file

public File file()
Returns the file associated with this compilation unit.


fileNameIdent

public String fileNameIdent()
Returns the Java identifier associated with the name of the file containing this compilation unit. For example, if the file is named "typecheck.java" then this method returns "typecheck".

Returns:
the Java identifier associated with the file containing this

packageName

public JPackageName packageName()

importedPackages

public JPackageImportType[] importedPackages()

importedClasses

public JClassOrGFImportType[] importedClasses()

typeDeclarations

public JTypeDeclarationType[] typeDeclarations()

gfDeclarations

public MJGenericFunctionDecl[] gfDeclarations()

allTypeSignatures

public CSourceClass[] allTypeSignatures()
Returns the CSourceClass objects representing the type signatures of the types declared in this compilatoin unit and as nested types.


declaresType

public boolean declaresType(String qualifiedName)
Returns true iff this compilation unit contains a declaration for a type with the given fully qualified name.

Parameters:
qualifiedName - a fully qualified name with parts separated by '/' not '.'

declaresGF

public boolean declaresGF(String qualifiedName)
Returns true iff this compilation unit contains a declaration for a generic function with the given fully qualified name.

Parameters:
qualifiedName - a fully qualified name with parts separated by '/' not '.'

tlMethods

public ArrayList tlMethods()
Returns the AST subtrees for the augmenting method declarations. Each element of the list is of type MJTopLevelMethodDeclaration


importedUnits

public JClassOrGFImportType[] importedUnits()
Returns an array of the class and generic function imports for this compilation unit. Typically code should use importedClasses or importedGFs instead. This method is available as a testing harness since the other two methods report empty results until after the preprocessDependencies pass.


importedGFs

public JClassOrGFImportType[] importedGFs()

preprocessDependencies

public void preprocessDependencies(Main compiler)
                                     throws PositionedError
Performs preliminary processing on compilation units and types. Processes type imports so external methods' receiver types can be analyzed and supertypes can be resolved. Groups external methods by name, corresponding to the anchor classes that will eventually be generated. Mutates the name space management in CTopLevel to record a CGenericFunctionCollection singleton for each anchor class.

Throws:
PositionedError

checkInterface

public void checkInterface(Main compiler)
                             throws PositionedError
Checks the basic interfaces to make sure things generally look OK. This pass gathers information about the type signatures of everything (imported generic functions, classes being compiled, methods, fields, etc...) needed for the later passes. This information is stored in a CCompilationUnit instance and instances of CMember that are bound to the AST. Also adds things like the default constructor and common initializer methods (which group all field initializers and initializer blocks) to the AST.

Throws:
PositionedError - an error with reference to the source file

checkInitializers

public void checkInitializers(Main compiler)
                                throws PositionedError
Checks the static initializers created during the checkInterface pass and performs some other checks that can be performed simply before full blown typechecking. Among these other checks are those for appropriateness of subclassing, such as inheritance circularities and "reimplementation" of interfaces.

Parameters:
compiler - the compiler that is calling (passed down through the AST via CContextType subtypes and used for error reporting)
Throws:
PositionedError - if check fails

resolveSpecializers

public void resolveSpecializers()
                                  throws PositionedError
Resolves value specializer expressions to the compile-time constants they represent. Must come after the checkInitializers phase.

Specified by:
resolveSpecializers in interface CompilerPassEnterable
Throws:
PositionedError

resolveTopMethods

public void resolveTopMethods()
                                throws PositionedError
Finds the top method of every declared method. Called after the resolveSpecializers pass. This cannot be done before then because the external generic function mappings are not complete until the end of the checkInterface pass and the constant value specializers are not known until after the resolveSpecializers pass. This must be done before the typecheck pass so that all specialized argument positions for generic functions are known for ambiguity checking.

Specified by:
resolveTopMethods in interface CompilerPassEnterable
Throws:
PositionedError

typecheck

public void typecheck(Main compiler)
                        throws PositionedError
Typechecks this compilation unit.

Parameters:
compiler - the compiler that is calling
Throws:
PositionedError - if a check fails that we cannot recover from

accept

public void accept(MjcVisitor p)
Accepts the specified visitor

Specified by:
accept in interface CompilerPassEnterable
Parameters:
p - the visitor

translateMJ

public void translateMJ(Main compiler)
Refactors this to include dispatchers for multimethods and other code necessary for running MultiJava code on a standard JVM.


cachePassParameters

public void cachePassParameters(Main compiler,
                                Destination destination)
Caches the arguments for the compiler passes.

 ensures arePassParametersCached;
 

See Also:
CompilerPassEnterable

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.