|
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.util.compiler.Phylum
org.multijava.mjc.JPhylum
org.multijava.mjc.JCompilationUnit
This class 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.
| Field Summary | |
private Hashtable |
allLoadedClasses
Maps from identifiers (of type String) to class
type singletons (of type CClassType). |
private Main |
cachedCompiler
|
private static Iterator |
EMPTY_ITERATOR
|
private CCompilationUnit |
export
Provides name space management, e.g., resolving references to external types. |
private String |
fileIdent
|
private MJGenericFunctionDecl[] |
gfDeclarations
Stores references to the collections of non-private generic functions declared in this compilation unit. |
private JClassOrGFImportType[] |
importedClasses
|
private JClassOrGFImportType[] |
importedGFs
|
private JPackageImportType[] |
importedPackages
|
private ArrayList |
importedUnits
|
private CGFCollectionMap |
inScopeGenFuncMap
Maps from identifiers to sets of external generic function collections that are in scope for this compilation unit. |
private JPackageName |
packageName
|
private static HashSet |
PRIMITIVE_TYPES_SET
|
private MJGenericFunctionDecl[] |
privateGFDeclarations
Stores references to the collections of private generic functions declared in this compilation unit. |
private ArrayList |
tlMethods
AST subtrees for the augmenting method declarations. |
private JTypeDeclarationType[] |
typeDeclarations
|
private static Comparator |
VGF_COMPARATOR
Compares two CMethod objects based on identifiers and parameter types, but only comparing these alphabetically. |
| Fields inherited from class org.multijava.mjc.JPhylum |
EMPTY |
| Fields inherited from class org.multijava.util.compiler.Phylum |
|
| Fields inherited from class org.multijava.util.Utils |
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO |
| Constructor Summary | |
JCompilationUnit(TokenReference where,
JPackageName packageName,
CCompilationUnit export,
JPackageImportType[] importedPackages,
ArrayList importedUnits,
JTypeDeclarationType[] typeDeclarations,
ArrayList tlMethods)
Constructs a CompilationUnit with the specified top level context |
|
| 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. |
private CMethod[] |
calcVisibleGenericFunctions()
Finds the top methods of every generic function visible in this compilation unit. |
void |
checkInitializers()
Invokes the checkInitializers method of the implementing class using previously cached arguments. |
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()
Invokes the checkInterface method of the implementing class using previously cached arguments. |
void |
checkInterface(Main compiler)
Checks the basic interfaces to make sure things generally look OK. |
private void |
clonePrivateAnchorsAndAddTo(Main compiler,
JTypeDeclarationType parent,
boolean genInterface)
Clones every private generic function anchor and adds each as a child of the given parent node. |
int |
compareTo(Object o)
Compares this to a given object. |
CCompilationUnitContextType |
createCompilationUnitContext(Main compiler,
CCompilationUnit cunit)
|
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 top-level 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()
|
private void |
groupByAnchor(Main compiler,
CCompilationUnitContextType context)
Groups top-level methods into collections (of type MJGenericFunctionDecl) that correspond to the
anchor classes. |
JClassOrGFImportType[] |
importedClasses()
|
JClassOrGFImportType[] |
importedGFs()
|
JPackageImportType[] |
importedPackages()
|
JClassOrGFImportType[] |
importedUnits()
Returns an array of the class and generic function imports for this compilation unit. |
ArrayList |
importedUnitsAsArrayList()
|
private void |
makeAndStoreAnchorDecl(ArrayList anchorMates,
String id,
boolean priv,
ArrayList anchors,
ArrayList privateAnchors)
Utility method generates a MJGenericFunctionDecl
anchor for the given methods and stores it in the appropriate
anchor collection. |
private static Iterator |
makeIterator(ArrayList[] l_f)
Generates an iterator for looping through the cartesian cross-product of the sets of types. |
private String |
matchPackageName(String qualifiedName)
If qualifiedName begins with the package name of this compilation unit, then returns the remainder of qualifiedName; otherwise returns null. |
JPackageName |
packageName()
|
String |
packageNameAsString()
|
void |
preprocessDependencies()
Performs preliminary processing on compilation units and types. |
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 |
resolveSpecializers(Main compiler)
Resolves value specializer expressions to the compile-time constants they represent. |
void |
resolveTopMethods()
Finds the top method of every declared method. |
private void |
separateImports()
Separates the import statements into those for classes and those for generic functions. |
void |
setImportedPackages(JPackageImportType[] packages)
|
void |
setPackage(JPackageName n)
|
ArrayList |
tlMethods()
Returns the AST subtrees for the augmenting method declarations. |
void |
translateMJ()
Invokes the translateMJ method of the implementing class using previously cached arguments. |
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()
Invokes the typecheck method of the implementing class using previously cached arguments. |
void |
typecheck(Main compiler)
Typechecks this compilation unit. |
JTypeDeclarationType[] |
typeDeclarations()
|
| Methods inherited from class org.multijava.mjc.JPhylum |
check, check, check, check, fail, fail, fail, warn, warn, warn, warn |
| Methods inherited from class org.multijava.util.compiler.Phylum |
getTokenReference, setTokenReference |
| 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, toString, wait, wait, wait |
| Methods inherited from interface org.multijava.mjc.CompilerPassEnterable |
getTokenReference |
| Field Detail |
private Main cachedCompiler
private JPackageName packageName
private JClassOrGFImportType[] importedClasses
private JClassOrGFImportType[] importedGFs
private ArrayList importedUnits
private JPackageImportType[] importedPackages
private JTypeDeclarationType[] typeDeclarations
private String fileIdent
private ArrayList tlMethods
private MJGenericFunctionDecl[] privateGFDeclarations
private MJGenericFunctionDecl[] gfDeclarations
private Hashtable allLoadedClasses
String) to class
type singletons (of type CClassType). Aliased in
CCompilationUnit.
CClassType,
CCompilationUnit,
CCompilationUnit.loadedClassesprivate CGFCollectionMap inScopeGenFuncMap
CCompilationUnit.loadedGFCollectionsprivate final CCompilationUnit export
private static HashSet PRIMITIVE_TYPES_SET
private static final Iterator EMPTY_ITERATOR
private static final Comparator VGF_COMPARATOR
| Constructor Detail |
public JCompilationUnit(TokenReference where,
JPackageName packageName,
CCompilationUnit export,
JPackageImportType[] importedPackages,
ArrayList importedUnits,
JTypeDeclarationType[] typeDeclarations,
ArrayList tlMethods)
where - the position of this tokenpackageName - the package to which this c.u. belongsimportedPackages - the packages imported by this c.u.importedUnits - the classes and external members imported by
this compilation unittypeDeclarations - the classes and interfaces declared
in this c.u.tlMethods - the MultiJava top-level declarations
in this c.u.| Method Detail |
private void separateImports()
throws PositionedError
PositionedErrorpublic String packageNameAsString()
packageNameAsString in interface JCompilationUnitTypepublic File file()
file in interface JCompilationUnitTypepublic String fileNameIdent()
fileNameIdent in interface JCompilationUnitTypepublic JPackageName packageName()
packageName in interface JCompilationUnitTypepublic void setPackage(JPackageName n)
public JPackageImportType[] importedPackages()
importedPackages in interface JCompilationUnitTypepublic void setImportedPackages(JPackageImportType[] packages)
public JClassOrGFImportType[] importedClasses()
importedClasses in interface JCompilationUnitTypepublic JTypeDeclarationType[] typeDeclarations()
typeDeclarations in interface JCompilationUnitTypepublic MJGenericFunctionDecl[] gfDeclarations()
gfDeclarations in interface JCompilationUnitTypepublic CSourceClass[] allTypeSignatures()
allTypeSignatures in interface JCompilationUnitTypepublic boolean declaresType(String qualifiedName)
declaresType in interface JCompilationUnitTypequalifiedName - a fully qualified name with parts
separated by '/' not '.'public boolean declaresGF(String qualifiedName)
declaresGF in interface JCompilationUnitTypequalifiedName - a fully qualified name with parts
separated by '/' not '.'private String matchPackageName(String qualifiedName)
public ArrayList tlMethods()
tlMethods in interface JCompilationUnitTypepublic JClassOrGFImportType[] importedUnits()
importedUnits in interface JCompilationUnitTypepublic ArrayList importedUnitsAsArrayList()
public JClassOrGFImportType[] importedGFs()
importedGFs in interface JCompilationUnitType
public CCompilationUnitContextType createCompilationUnitContext(Main compiler,
CCompilationUnit cunit)
public void preprocessDependencies(Main compiler)
throws PositionedError
preprocessDependencies in interface JCompilationUnitTypePositionedError
private void groupByAnchor(Main compiler,
CCompilationUnitContextType context)
throws PositionedError
MJGenericFunctionDecl) that correspond to the
anchor classes.
PositionedErrorMJGenericFunctionDecl
private void makeAndStoreAnchorDecl(ArrayList anchorMates,
String id,
boolean priv,
ArrayList anchors,
ArrayList privateAnchors)
MJGenericFunctionDecl
anchor for the given methods and stores it in the appropriate
anchor collection.
anchorMates - the method declarationsid - the shared identifier of the methodspriv - indicates that all the methods are privateanchors - non-private anchors declared in thisprivateAnchors - private anchors declared in this
private void clonePrivateAnchorsAndAddTo(Main compiler,
JTypeDeclarationType parent,
boolean genInterface)
parent - the AST node to add the private generic
function anchor AST togenInterface - if true then generate the interface for the
cloned anchors
public void checkInterface(Main compiler)
throws PositionedError
checkInterface in interface JCompilationUnitTypePositionedError - an error with reference
to the source file
public void checkInitializers(Main compiler)
throws PositionedError
checkInitializers in interface JCompilationUnitTypecompiler - the compiler that is calling (passed down
through the AST via CContextType subtypes
and used for error reporting)
PositionedError - if check fails
public void resolveSpecializers(Main compiler)
throws PositionedError
compiler - the compiler that is calling (passed down
through the AST via CContextType subtypes
and used for error reporting)
PositionedError
public void resolveTopMethods()
throws PositionedError
resolveTopMethods in interface JCompilationUnitTypePositionedError
public void typecheck(Main compiler)
throws PositionedError
typecheck in interface JCompilationUnitTypecompiler - the compiler that is calling
PositionedError - if a check fails that we cannot
recover from
private CMethod[] calcVisibleGenericFunctions()
throws PositionedError
export.visibleMethods(). Also calculates which arguments
of the generic function are specialized on in this compilation.
The visible generic functions are stored in
visibleGenericFunctions. Each top method stores
a bit set indicating which arguments are specialized for its generic
function.
PositionedError - if a top method cannot be found private static Iterator makeIterator(ArrayList[] l_f)
l_f - each element should be a set of CTypes
public void accept(MjcVisitor p)
accept in interface JCompilationUnitTypep - the visitorpublic void translateMJ(Main compiler)
translateMJ in interface JCompilationUnitType
public int compareTo(Object o)
throws ClassCastException
also ensures (* \result == lexically ordered according to the file name without the suffix *); also requires o != null && !(o instanceof JCompilationUnit); signals_only ClassCastException;
compareTo in interface Comparableo - an Object value to compare to this
ClassCastException - if o is incomparable to this
public void cachePassParameters(Main compiler,
Destination destination)
also ensures arePassParametersCached;
cachePassParameters in interface JCompilationUnitTypeCompilerPassEnterable
public void preprocessDependencies()
throws PositionedError
preprocessDependencies in interface CompilerPassEnterablePositionedError
public void checkInterface()
throws PositionedError
CompilerPassEnterablerequires arePassParametersCached;
checkInterface in interface CompilerPassEnterablePositionedError
public void checkInitializers()
throws PositionedError
CompilerPassEnterablerequires arePassParametersCached;
checkInitializers in interface CompilerPassEnterablePositionedError
public void resolveSpecializers()
throws PositionedError
JCompilationUnitType
resolveSpecializers in interface JCompilationUnitTypePositionedError
public void typecheck()
throws PositionedError
CompilerPassEnterablerequires arePassParametersCached;
typecheck in interface CompilerPassEnterablePositionedErrorpublic void translateMJ()
CompilerPassEnterablerequires arePassParametersCached;
translateMJ in interface CompilerPassEnterable
|
mjc | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||