Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Created August 15, 2009 15:18
Show Gist options
  • Save stepancheg/168375 to your computer and use it in GitHub Desktop.
Save stepancheg/168375 to your computer and use it in GitHub Desktop.
PackageLoader.doComplete diff
Index: Global.scala
===================================================================
--- Global.scala (revision 18483)
+++ Global.scala (working copy)
@@ -848,6 +848,7 @@
}
}
for ((sym, file) <- symSource.iterator) resetPackageClass(sym.owner)
+ Junk.printStats()
informTime("total", startTime)
if (!dependencyAnalysis.off) {
Index: symtab/SymbolLoaders.scala
===================================================================
--- symtab/SymbolLoaders.scala (revision 18483)
+++ symtab/SymbolLoaders.scala (working copy)
@@ -52,7 +52,9 @@
try {
val start = currentTime
val currentphase = phase
+ Junk.now("complete")
doComplete(root)
+ Junk.pop()
phase = currentphase
def source = kindString + " " + sourceString
informTime("loaded " + source, start)
@@ -101,6 +103,7 @@
var root: Symbol = _
def enterPackage(name: String, completer: SymbolLoader) {
+ Junk.now("enterPackage")
val preExisting = root.info.decls.lookup(newTermName(name))
if (preExisting != NoSymbol)
throw new TypeError(
@@ -110,9 +113,10 @@
pkg.moduleClass.setInfo(completer)
pkg.setInfo(pkg.moduleClass.tpe)
root.info.decls.enter(pkg)
+ Junk.pop()
}
// @return - the symbol of the class
- def enterClassAndModule(name: String, completer: SymbolLoader): Symbol = {
+ def enterClassAndModule(name: String, completer: SymbolLoader): Symbol = Junk.enter("enterClassAndModule") {
val owner = if (root.isRoot) definitions.EmptyPackageClass else root
val className = newTermName(name)
assert(owner.info.decls.lookup(name) == NoSymbol, owner.fullNameString + "." + name)
@@ -135,57 +139,42 @@
}
lazy val scope = newPackageScope(computeDepends(this))
protected def doComplete(root: Symbol) {
+ Junk.now("PackageLoader.doComplete")
assert(root.isPackageClass, root)
this.root = root
root.setInfo(new PackageClassInfoType(scope, root, this))
refresh()
+ Junk.pop()
}
def refresh() {
/** Is the given name a valid input file base name? */
def isValid(name: String): Boolean =
name.length() > 0 && (!name.endsWith("$class") || settings.XO.value)
- val classes = new HashMap[String, global.classPath0.Context]
+ //val classes = new HashMap[String, global.classPath0.Context]
val packages = new HashMap[String, global.classPath0.Context]
- def recordClass(file: AbstractFile, extension: String, classOK: global.classPath0.Context => Boolean) {
- if (!file.isDirectory && file.name.endsWith(extension)) {
- val name = file.name.substring(0, file.name.length - extension.length)
- if (isValid(name) && !classes.isDefinedAt(name)) {
- val clazz = directory.find(name, false)
- if ((clazz ne null) && classOK(clazz)) classes(name) = clazz
- }
+ for ((name, sources, context) <- directory.children) {
+ if (context ne null) {
+ packages(name) = context
+ } else if ((sources ne null) && isValid(name)) {
+ val entry = sources.entries.first
+ val isSourceFile = sources.isSourceFile
+ if (!isSourceFile) {
+ //if (entry.location.name.endsWith(".class")) {
+ if (!global.forMSIL) {
+ val loader = new ClassfileLoader(sources.classFile, sources.sourceFile, sources.sourcePath)
+ enterClassAndModule(name, loader)
+ }
+ } else {
+ if (checkSource(name, sources.sourceFile) && entry.source.compile) {
+ val loader = new SourcefileLoader(sources.sourceFile)
+ enterClassAndModule(name, loader)
+ }
+ }
}
}
-
- for (dir <- directory.entries) if ((dir.location ne null) && dir.location.isDirectory) {
- for (file <- dir.location) {
- if (file.isDirectory && directory.validPackage(file.name) && !packages.isDefinedAt(file.name))
- packages(file.name) = directory.find(file.name, true);
- else if (!global.forMSIL)
- recordClass(file, ".class", source => true)
- }
- }
- for (dir <- directory.entries) if (dir.source ne null) {
- for (file <- dir.source.location) {
- if (file.isDirectory && directory.validPackage(file.name) && !packages.isDefinedAt(file.name))
- packages(file.name) = directory.find(file.name, true)
- else if (dir.source.compile)
- recordClass(file, ".scala", source => checkSource(file.name, source.sourceFile))
- }
- }
-
- // do classes first
- for ((name, file) <- classes.iterator) {
- val loader = if (!file.isSourceFile) {
- new ClassfileLoader(file.classFile, file.sourceFile, file.sourcePath)
- } else {
- assert(file.sourceFile ne null)
- new SourcefileLoader(file.sourceFile)
- }
- enterClassAndModule(name, loader)
- }
-
+
// packages second
for ((name, file) <- packages.iterator)
enterPackage(name, newPackageLoader(file))
@@ -287,8 +276,10 @@
override def sourcePath = sourcePath0 /* could be null */
}
protected def doComplete(root: Symbol) {
+ val name = sourceString
completeClassfile(root, this) {
- classfileParser.parse(classFile, root)
+ val r = classfileParser.parse(classFile, root)
+ r
}
root match {
case clazz: ClassSymbol =>
Index: io/ZipArchive.scala
===================================================================
--- io/ZipArchive.scala (revision 18483)
+++ io/ZipArchive.scala (working copy)
@@ -113,6 +113,7 @@
/** Loads the archive and creates the root directory. */
private def load() {
+ Junk.now("ZipArchive.load")
this.root = new DirEntry(this, "<root>", "/")
// A path to DirEntry map
val dirs: Map[String, DirEntry] = new HashMap()
@@ -140,6 +141,7 @@
parent.entries.update(name, new FileEntry(parent, name, path, entry))
}
}
+ Junk.pop()
}
/**
Index: util/ClassPath.scala
===================================================================
--- util/ClassPath.scala (revision 18483)
+++ util/ClassPath.scala (working copy)
@@ -13,6 +13,7 @@
import java.util.StringTokenizer
import scala.collection.mutable.ArrayBuffer
+import scala.collection.mutable.HashMap
import scala.tools.nsc.io.AbstractFile
/** <p>
@@ -144,6 +145,93 @@
null
} else ret
} else null
+
+ // (name, file context, package context)*
+ def children: Iterator[(String, Context, Context)] = if (isPackage) {
+ class Temp(var dirs: List[Entry], var sourceFiles: List[Entry], var classFiles: List[Entry]) {
+ def this() = this(Nil, Nil, Nil)
+ }
+ val map = new HashMap[String, Temp]
+ for (entry <- entries) {
+ if ((entry.location ne null) && entry.location.isDirectory) {
+ for (file <- entry.location) {
+ val fileName = file.name
+ if (file.isDirectory) {
+ if (validPackage(name)) {
+ val name = fileName
+ val source1 =
+ if (entry.source ne null) entry.source.location.lookupName(name, true)
+ else null
+ val temp = map.getOrElseUpdate(name, new Temp)
+ temp.dirs ::=
+ new Entry(file) {
+ override def source =
+ if (source1 eq null) null
+ else new Source(source1, entry.source.compile)
+ }
+ }
+ } else if (fileName.endsWith(".class")) {
+ val name = fileName.substring(0, fileName.length - ".class".length)
+ val source1 =
+ if (entry.source eq null) null
+ else {
+ val source2 = entry.source.location.lookupName(name + ".scala", false)
+ if (source2 eq null) entry.source.location
+ else source2
+ }
+ val temp = map.getOrElseUpdate(name, new Temp)
+ //temp.regFiles ++= List(file)
+ temp.classFiles ::=
+ new Entry(file) {
+ override def source =
+ if (source1 eq null) null
+ else new Source(source1, entry.source.compile)
+ }
+ }
+ }
+ }
+ if ((entry.source ne null) && (entry.source.location != entry.location)) {
+ for (file <- entry.source.location)
+ if (file.isDirectory) {
+ val name = file.name
+ if (validPackage(name)) {
+ val clazz =
+ if (entry.location ne null) entry.location.lookupName(name, true)
+ else null
+ val temp = map.getOrElseUpdate(name, new Temp)
+ if (validPackage(file.name))
+ //temp.dirs ++= List(file)
+ temp.dirs ::=
+ new Entry(clazz) {
+ override def source =
+ new Source(file, entry.source.compile)
+ }
+ }
+ } else if (file.name.endsWith(".scala")) {
+ val name = file.name.substring(0, file.name.length - ".scala".length)
+ val temp = map.getOrElseUpdate(name, new Temp)
+ temp.sourceFiles ::=
+ new Entry(null) {
+ override def source =
+ new Source(file, entry.source.compile)
+ }
+ }
+ }
+ }
+ map.iterator.map { case (name, temp) =>
+ (name,
+ if (!temp.classFiles.isEmpty)
+ new Context(temp.classFiles.last :: Nil)
+ else if (!temp.sourceFiles.isEmpty)
+ new Context(temp.sourceFiles.last :: Nil)
+ else null
+ ,
+ if (!temp.dirs.isEmpty)
+ new Context(temp.dirs.reverse)
+ else null
+ )
+ }
+ } else Iterator.empty
def isPackage: Boolean =
if (entries.isEmpty) false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment