diff options
author | mihaylov <mihaylov@epfl.ch> | 2004-05-31 13:06:17 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2004-05-31 13:06:17 +0000 |
commit | 3d3273ecaeeb9bb0e428ddaa3e393526db9111f2 (patch) | |
tree | 755a9227217bafb55c81b6c8c249ba099cc5c17c /sources/scalac/symtab/classfile/PackageParser.java | |
parent | b1a561d119bca6f046fec81f493992bb9c45e40f (diff) | |
download | scala-3d3273ecaeeb9bb0e428ddaa3e393526db9111f2.tar.gz scala-3d3273ecaeeb9bb0e428ddaa3e393526db9111f2.tar.bz2 scala-3d3273ecaeeb9bb0e428ddaa3e393526db9111f2.zip |
- When using the MSIL backend import classes fr...
- When using the MSIL backend import classes from .NET assemblies rather
than .class files
Diffstat (limited to 'sources/scalac/symtab/classfile/PackageParser.java')
-rw-r--r-- | sources/scalac/symtab/classfile/PackageParser.java | 77 |
1 files changed, 66 insertions, 11 deletions
diff --git a/sources/scalac/symtab/classfile/PackageParser.java b/sources/scalac/symtab/classfile/PackageParser.java index 07d196312c..b8a1636eb0 100644 --- a/sources/scalac/symtab/classfile/PackageParser.java +++ b/sources/scalac/symtab/classfile/PackageParser.java @@ -10,6 +10,7 @@ package scalac.symtab.classfile; import java.util.Iterator; import java.util.HashMap; +import java.util.Set; import scala.tools.util.AbstractFile; import scala.tools.util.Position; @@ -23,6 +24,8 @@ import scalac.symtab.Type; import scalac.util.Name; import scalac.util.Debug; +import scalac.symtab.SymbolNameWriter; + /** * This class implements a package member loader. It can be used to * complete package class symbols. @@ -35,6 +38,11 @@ public class PackageParser extends SymbolLoader { /** The directory to read */ private final AbstractFile directory; + /** Are we targeting the MSIL? */ + private boolean forMSIL; + + private SymbolNameWriter snw = new SymbolNameWriter(); + //######################################################################## // Public Constructors @@ -42,6 +50,7 @@ public class PackageParser extends SymbolLoader { public PackageParser(Global global, AbstractFile directory) { super(global); this.directory = directory; + this.forMSIL = global.target == global.TARGET_MSIL; } //######################################################################## @@ -76,6 +85,14 @@ public class PackageParser extends SymbolLoader { } } + HashMap types = null; + Set namespaces = null; + ch.epfl.lamp.compiler.msil.Type type = null; + if (forMSIL) { + types = clrParser().getTypes(peckage); + namespaces = clrParser().getNamespaces(peckage); + } + // create JVM and source members Scope members = new Scope(); for (Iterator i = sources.entrySet().iterator(); i.hasNext(); ) { @@ -83,10 +100,19 @@ public class PackageParser extends SymbolLoader { String name = (String)entry.getKey(); AbstractFile sfile = (AbstractFile)entry.getValue(); AbstractFile cfile = (AbstractFile)classes.remove(name); - if (global.separate && cfile != null) { + if (forMSIL) { + type = (ch.epfl.lamp.compiler.msil.Type)types.remove(name); + if (global.separate && forMSIL && type != null) { +// if (type.Assembly.getFile().lastModified() +// > sfile.lastModified()) { + types.put(name, type); + continue; +// } + } + } else if (global.separate && cfile != null) { if (cfile.lastModified() > sfile.lastModified()) { - classes.put(name, cfile); - continue; + classes.put(name, cfile); + continue; } } packages.remove(name); @@ -94,31 +120,60 @@ public class PackageParser extends SymbolLoader { SymbolLoader loader = new SourceCompleter(global, sfile); peckage.newLoadedClass(0, classname, loader, members); } + + if (forMSIL) { + for (Iterator i = types.keySet().iterator(); i.hasNext(); ) { + classes.remove(i.next()); + } + } + for (Iterator i = classes.entrySet().iterator(); i.hasNext(); ) { HashMap.Entry entry = (HashMap.Entry)i.next(); String name = (String)entry.getKey(); - AbstractFile cfile = (AbstractFile)entry.getValue(); - packages.remove(name); - Name classname = Name.fromString(name).toTypeName(); - SymbolLoader loader = new ClassParser(global, cfile); - peckage.newLoadedClass(JAVA, classname, loader, members); + //assert !types.containsKey(name) : types.get(name); + if (!forMSIL || clrParser().shouldLoadClassfile(peckage, name)) { + AbstractFile cfile = (AbstractFile)entry.getValue(); + packages.remove(name); + Name classname = Name.fromString(name).toTypeName(); + SymbolLoader loader = new ClassParser(global, cfile); + peckage.newLoadedClass(JAVA, classname, loader, members); + } } + + if (forMSIL) { + // import the CLR types contained in the package (namespace) + for (Iterator i = types.values().iterator(); i.hasNext(); ) { + type = (ch.epfl.lamp.compiler.msil.Type)i.next(); + clrParser().importType(type, peckage, members); + } + } + for (Iterator i = packages.entrySet().iterator(); i.hasNext(); ) { HashMap.Entry entry = (HashMap.Entry)i.next(); String name = (String)entry.getKey(); AbstractFile dfile = (AbstractFile)entry.getValue(); SymbolLoader loader = new PackageParser(global, dfile); peckage.newLoadedPackage(Name.fromString(name), loader, members); + if (forMSIL) + namespaces.remove(name); } - // collect and create CLR members - if (global.target == global.TARGET_MSIL) - CLRPackageParser.instance(global).importCLRTypes(peckage, members); + if (forMSIL) { + // import the CLR namespaces contained in the package (namespace) + for (Iterator i = namespaces.iterator(); i.hasNext(); ) { + String namespace = (String)i.next(); + clrParser().importNamespace(namespace, peckage, members); + } + } // initialize package peckage.setInfo(Type.compoundType(Type.EMPTY_ARRAY, members, peckage)); return "directory path '" + directory + "'"; } + private CLRPackageParser clrParser() { + return CLRPackageParser.instance(global); + } + //######################################################################## } |