From fc0af274210727cbe4f3f3709d3685b0aca50bcb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 5 Dec 2005 19:36:27 +0000 Subject: *** empty log message *** --- sources/scala/tools/nsc/Global.scala | 16 +++++--- sources/scala/tools/nsc/ast/parser/Parsers.scala | 2 +- sources/scala/tools/nsc/backend/jvm/GenJVM.scala | 44 +++++++++++----------- sources/scala/tools/nsc/symtab/Flags.scala | 2 +- sources/scala/tools/nsc/symtab/StdNames.scala | 2 +- sources/scala/tools/nsc/symtab/SymbolLoaders.scala | 13 +++++-- sources/scala/tools/nsc/symtab/Symbols.scala | 2 - .../nsc/symtab/classfile/ClassfileParser.scala | 8 +++- .../tools/nsc/symtab/classfile/PickleFormat.scala | 3 ++ .../scala/tools/nsc/symtab/classfile/Pickler.scala | 2 + .../tools/nsc/symtab/classfile/UnPickler.scala | 11 ++++++ .../tools/nsc/typechecker/SyntheticMethods.scala | 8 ++-- sources/scala/tools/nsc/typechecker/Typers.scala | 3 -- 13 files changed, 72 insertions(+), 44 deletions(-) (limited to 'sources') diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala index 8be805b45b..dc709117de 100755 --- a/sources/scala/tools/nsc/Global.scala +++ b/sources/scala/tools/nsc/Global.scala @@ -359,13 +359,19 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable if (settings.Xshowicode.value) writeICode(); if (reporter.errors == 0) { +/* for (val Pair(sym, pickled) <- symData.elements.toList) { sym setPos Position.NOPOS; - if (symData contains sym) { - symData -= sym; - symData -= sym.linkedSym; - writeSymblFile(sym, pickled) - } +// if (symData contains sym) { +// symData -= sym; +// symData -= sym.linkedSym; +// writeSymblFile(sym, pickled) +// } +// } +*/ + for (val Pair(sym, file) <- symSource.elements) { + sym setPos Position.NOPOS; + if (sym.isTerm) sym.moduleClass setPos Position.NOPOS; resetPackageClass(sym.owner); } } else { diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala index 68025a25ab..ae4f271684 100755 --- a/sources/scala/tools/nsc/ast/parser/Parsers.scala +++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala @@ -1563,7 +1563,7 @@ import Tokens._; } else argss += List(); if (name != nme.ScalaObject.toTypeName) parents += scalaScalaObjectConstr; - if (name.isTypeName && (mods & Flags.CASE) != 0) parents += caseClassConstr; + if (/*name.isTypeName && */(mods & Flags.CASE) != 0) parents += caseClassConstr; val ps = parents.toList; var body = if (in.token == LBRACE) { diff --git a/sources/scala/tools/nsc/backend/jvm/GenJVM.scala b/sources/scala/tools/nsc/backend/jvm/GenJVM.scala index 6be4eb02fe..d998884ae8 100644 --- a/sources/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/sources/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -63,6 +63,27 @@ abstract class GenJVM extends SubComponent { val fjbgContext = new FJBGContext(); + def emitClass(jclass: JClass, sym: Symbol): Unit = { + def addScalaAttr(sym: Symbol): Unit = currentRun.symData.get(sym) match { + case Some(pickle) => + val scalaAttr = fjbgContext.JOtherAttribute(jclass, + jclass, + nme.ScalaSignatureATTR.toString(), + pickle.bytes, + pickle.writeIndex); + jclass.addAttribute(scalaAttr); + currentRun.symData -= sym; + currentRun.symData -= sym.linkedSym; + //System.out.println("Generated ScalaSig Attr for " + sym);//debug + case _ => + log("Could not find pickle information for " + sym); + } + if (!jclass.getName().endsWith("$")) + addScalaAttr(if (isTopLevelModule(sym)) sym.sourceModule else sym); + val outfile = getFile(jclass, ".class"); + jclass.writeTo(outfile); + informProgress("wrote " + outfile); + } def genClass(c: IClass): Unit = { log("Generating class " + c.symbol + " flags: " + Flags.flagsToString(c.symbol.flags)); @@ -99,28 +120,13 @@ abstract class GenJVM extends SubComponent { clasz.fields foreach genField; clasz.methods foreach genMethod; - addScalaAttribute(c.symbol); - jclass.writeTo(getFile(jclass, ".class")); + emitClass(jclass, c.symbol) } def isTopLevelModule(sym: Symbol): Boolean = { sym.isModuleClass && !sym.isImplClass && !sym.hasFlag(Flags.LIFTED) /* && !atPhase(currentRun.erasurePhase)(sym.isNestedClass) */ } - def addScalaAttribute(sym: Symbol): Unit = { - currentRun.symData.get(sym) match { - case Some(pickle) => - val scalaAttr = fjbgContext.JOtherAttribute(jclass, - jclass, - nme.ScalaSignatureATTR.toString(), - pickle.bytes, - pickle.writeIndex); - jclass.addAttribute(scalaAttr); - case _ => - log("Could not find pickle information for " + sym); - } - } - def genField(f: IField): Unit = { log("Adding field: " + f.symbol.fullNameString); jclass.addNewField(javaFlags(f.symbol), @@ -222,8 +228,7 @@ abstract class GenJVM extends SubComponent { mirrorCode.emitINVOKEVIRTUAL(moduleName, mirrorMethod.getName(), mirrorMethod.getType().asInstanceOf[JMethodType]); mirrorCode.emitRETURN(mirrorMethod.getReturnType()); } - - mirrorClass.writeTo(getFile(mirrorClass, ".class")); + emitClass(mirrorClass, clasz.symbol); } @@ -922,7 +927,6 @@ abstract class GenJVM extends SubComponent { settings.outdir.value + File.separatorChar + path + suffix } - private def genLocalVariableTable: Unit = { val vars: Array[JLocalVariable] = jmethod.getLocalVariables(); @@ -954,7 +958,5 @@ abstract class GenJVM extends SubComponent { lvTab.array()); jcode.addAttribute(attr); } - } - } diff --git a/sources/scala/tools/nsc/symtab/Flags.scala b/sources/scala/tools/nsc/symtab/Flags.scala index f0ed9318a4..c21dacda72 100644 --- a/sources/scala/tools/nsc/symtab/Flags.scala +++ b/sources/scala/tools/nsc/symtab/Flags.scala @@ -114,7 +114,7 @@ object Flags { final val PickledFlags = 0xFFFFFFFF; /** Module flags inherited by their module-class */ - final val ModuleToClassFlags = AccessFlags | PACKAGE; + final val ModuleToClassFlags = AccessFlags | PACKAGE | CASE; def flags2mods(flags: long): int = flags.asInstanceOf[int]; diff --git a/sources/scala/tools/nsc/symtab/StdNames.scala b/sources/scala/tools/nsc/symtab/StdNames.scala index c20843843a..1ecfa8bec8 100755 --- a/sources/scala/tools/nsc/symtab/StdNames.scala +++ b/sources/scala/tools/nsc/symtab/StdNames.scala @@ -315,7 +315,7 @@ import scala.tools.nsc.util.NameTransformer; val LocalVariableTableATTR = newTermName("LocalVariableTable"); val InnerClassesATTR = newTermName("InnerClasses"); val JacoMetaATTR = newTermName("JacoMeta"); - val ScalaSignatureATTR = newTermName("ScalaSignature"); + val ScalaSignatureATTR = newTermName("ScalaSig"); val JavaInterfaceATTR = newTermName("JacoInterface"); // '_' is temporary diff --git a/sources/scala/tools/nsc/symtab/SymbolLoaders.scala b/sources/scala/tools/nsc/symtab/SymbolLoaders.scala index 045c311d58..09b1f4b9f7 100755 --- a/sources/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/sources/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -112,11 +112,13 @@ abstract class SymbolLoaders { val filename = file.getName(); if (file.isDirectory()) { if (filename != "META_INF" && !packages.isDefinedAt(filename)) packages(filename) = file; +/* } else if (filename.endsWith(".symbl")) { val name = filename.substring(0, filename.length() - 6); if (isValid(name) && (!classes.isDefinedAt(name) || classes(name).getName().endsWith(".class"))) classes(name) = file; +*/ } else if (filename.endsWith(".class")) { val name = filename.substring(0, filename.length() - 6); if (isValid(name) && !classes.isDefinedAt(name)) @@ -138,8 +140,9 @@ abstract class SymbolLoaders { case Some(sfile) if (sfile.lastModified() > cfile.lastModified()) => {} case _ => val loader = - if (cfile.getName().endsWith(".symbl")) new SymblfileLoader(cfile) - else new ClassfileLoader(cfile); +/* if (cfile.getName().endsWith(".symbl")) new SymblfileLoader(cfile) + else */ + new ClassfileLoader(cfile); enterClassAndModule(name, loader) } } @@ -155,20 +158,22 @@ abstract class SymbolLoaders { val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global; } +/* private object symblfileParser extends SymblfileParser { val global: SymbolLoaders.this.global.type = SymbolLoaders.this.global; } +*/ class ClassfileLoader(file: AbstractFile) extends SymbolLoader(file) { protected def doComplete(root: Symbol): unit = classfileParser.parse(file, root); protected def kindString: String = "class file"; } - +/* class SymblfileLoader(file: AbstractFile) extends SymbolLoader(file) { protected def doComplete(root: Symbol): unit = symblfileParser.parse(file, root); protected def kindString: String = "symbl file"; } - +*/ class SourcefileLoader(file: AbstractFile) extends SymbolLoader(file) { protected def doComplete(root: Symbol): unit = global.currentRun.compileLate(file); protected def kindString: String = "source file"; diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 0966f9a034..fe423d0fa8 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -55,8 +55,6 @@ import Flags._; else -1; } - - var attributes: List[AttrInfo] = List(); // Creators ------------------------------------------------------------------- diff --git a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index d1c7ae62ab..f64627428c 100755 --- a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -42,6 +42,10 @@ abstract class ClassfileParser { val global: ClassfileParser.this.global.type = ClassfileParser.this.global } + private object unpickler extends UnPickler { + val global: ClassfileParser.this.global.type = ClassfileParser.this.global + } + def parse(file: AbstractFile, root: Symbol): unit = { assert(!busy); busy = true; @@ -326,8 +330,8 @@ abstract class ClassfileParser { case nme.InnerClassesATTR => parseInnerClasses() case nme.ScalaSignatureATTR => - //unpickle.parse(in.nextBytes(attrLen), clazz, statics.sourceModule); - //this.isScala = true; + unpickler.unpickle(in.buf, in.bp, clazz, staticModule); + this.isScala = true; case nme.JacoMetaATTR => val meta = pool.getName(in.nextChar()).toString().trim(); metaParser.parse(meta, sym, symtype); diff --git a/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala b/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala index 30967e2e9f..220b4bc6b5 100755 --- a/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala +++ b/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala @@ -52,6 +52,9 @@ object PickleFormat { * * len is remaining length after `len'. */ + val MajorVersion = 2; + val MinorVersion = 0; + final val TERMname = 1; final val TYPEname = 2; final val NONEsym = 3; diff --git a/sources/scala/tools/nsc/symtab/classfile/Pickler.scala b/sources/scala/tools/nsc/symtab/classfile/Pickler.scala index 3e7df0a315..6eb2196d53 100755 --- a/sources/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/sources/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -232,6 +232,8 @@ abstract class Pickler extends SubComponent { /** Write byte array */ def finish = { assert(writeIndex == 0); + writeNat(MajorVersion); + writeNat(MinorVersion); writeNat(ep); if (settings.debug.value) log("" + ep + " entries");//debug for (val i <- Iterator.range(0, ep)) writeEntry(entries(i)) diff --git a/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala b/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala index 091e8024a8..89adee33ef 100755 --- a/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/sources/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -28,6 +28,7 @@ abstract class UnPickler { private class UnPickle(bytes: Array[byte], offset: int, classRoot: Symbol, moduleRoot: Symbol) extends PickleBuffer(bytes, offset, -1) { if (settings.debug.value) global.log("unpickle " + classRoot + " and " + moduleRoot); + checkVersion(); private val index = createIndex; private val entries = new Array[AnyRef](index.length); private val symScopes = new HashMap[Symbol, Scope]; @@ -37,6 +38,16 @@ abstract class UnPickler { if (settings.debug.value) global.log("unpickled " + classRoot + ":" + classRoot.rawInfo + ", " + moduleRoot + ":" + moduleRoot.rawInfo);//debug + private def checkVersion() = { + val major = readNat(); + val minor = readNat(); + if (major != MajorVersion || minor > MinorVersion) + throw new TypeError("Scala signature " + classRoot.name + + " has wrong version\n expected: " + + MajorVersion + "." + MinorVersion + + "\n found: " + major + "." + minor) + } + /** The scope associated with given symbol */ private def symScope(sym: Symbol) = symScopes.get(sym) match { case None => val s = new Scope(); symScopes(sym) = s; s diff --git a/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala b/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala index fec30d66b0..38c680b4f6 100755 --- a/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -102,13 +102,13 @@ import util.ListBuffer; if (!hasImplementation(nme.readResolve)) ts += readResolveMethod; } } else { - if (!hasImplementation(nme.caseElement)) ts += caseElementMethod; - if (!hasImplementation(nme.caseArity)) ts += caseArityMethod; - if (!hasImplementation(nme.caseName)) ts += caseNameMethod; - if (!hasImplementation(nme.equals_)) ts += forwardingMethod(nme.equals_); if (!hasImplementation(nme.hashCode_)) ts += forwardingMethod(nme.hashCode_); if (!hasImplementation(nme.toString_)) ts += forwardingMethod(nme.toString_); + if (!hasImplementation(nme.equals_)) ts += forwardingMethod(nme.equals_); } + if (!hasImplementation(nme.caseElement)) ts += caseElementMethod; + if (!hasImplementation(nme.caseArity)) ts += caseArityMethod; + if (!hasImplementation(nme.caseName)) ts += caseNameMethod; } val synthetics = ts.toList; copy.Template( diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index 9a6d6dab4b..a161349a34 100755 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -515,9 +515,6 @@ import collection.mutable.HashMap; val impl2 = addSyntheticMethods(impl1, clazz); val ret = copy.ClassDef(cdef, cdef.mods, cdef.name, tparams1, tpt1, impl2) setType NoType; - //for (val p <- impl2.parents) - // System.err.println("AFTER: " + p + " " + p.pos); - // Thread.dumpStack(); ret; } -- cgit v1.2.3