diff options
author | ilyas <ilyas@epfl.ch> | 2009-06-29 16:09:59 +0000 |
---|---|---|
committer | ilyas <ilyas@epfl.ch> | 2009-06-29 16:09:59 +0000 |
commit | e659affbea5daf934f2f078fd8b872930bbaa09c (patch) | |
tree | 8bc757562f2ab5ddcca47b2663821993cdcc92dd /src | |
parent | 91643c355b853e9bdfb70a5afab426a3537bfc1d (diff) | |
download | scala-e659affbea5daf934f2f078fd8b872930bbaa09c.tar.gz scala-e659affbea5daf934f2f078fd8b872930bbaa09c.tar.bz2 scala-e659affbea5daf934f2f078fd8b872930bbaa09c.zip |
scalap changed to treat named parameters and pa...
scalap changed to treat named parameters and package objects
Diffstat (limited to 'src')
7 files changed, 193 insertions, 123 deletions
diff --git a/src/partest/scala/tools/partest/nest/Worker.scala b/src/partest/scala/tools/partest/nest/Worker.scala index 967374e6ee..0ecd9986f3 100644 --- a/src/partest/scala/tools/partest/nest/Worker.scala +++ b/src/partest/scala/tools/partest/nest/Worker.scala @@ -754,12 +754,12 @@ class Worker(val fileManager: FileManager) extends Actor { case "scalap" => { - def decompileFile(clazz: Class[_]) = { + def decompileFile(clazz: Class[_], packObj: Boolean) = { val byteCode = ByteCode.forClass(clazz) val classFile = ClassFileParser.parse(byteCode) val Some(sig) = classFile.attribute("ScalaSig").map(_.byteCode).map(ScalaSigAttributeParsers.parse) import scala.tools.scalap.Main._ - parseScalaSignature(sig) + parseScalaSignature(sig, packObj) } runInContext(file, kind, (logFile: File, outDir: File) => { @@ -781,12 +781,13 @@ class Worker(val fileManager: FileManager) extends Actor { } else { // 3. Decompile file and compare results - val className = sourceDirName.capitalize + val isPackageObject = sourceDir.getName.startsWith("package") + val className = sourceDirName.capitalize + (if (!isPackageObject) "" else ".package") val url = outDir.toURI.toURL val loader = new URLClassLoader(Array(url), getClass.getClassLoader) val clazz = loader.loadClass(className) - val result = decompileFile(clazz) + val result = decompileFile(clazz, isPackageObject) try { val fstream = new FileWriter(logFile); diff --git a/src/scala-lang.iml b/src/scala-lang.iml deleted file mode 100644 index d860a9ce0f..0000000000 --- a/src/scala-lang.iml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module relativePaths="true" type="JAVA_MODULE" version="4"> - <component name="FacetManager"> - <facet type="Scala" name="Scala"> - <configuration /> - </facet> - </component> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$/../META-INF" /> - <content url="file://$MODULE_DIR$/../docs" /> - <content url="file://$MODULE_DIR$/../lib" /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/actors" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/compiler" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/dbc" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/library" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/manual" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/partest" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/scalap" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/swing" isTestSource="false" /> - <excludeFolder url="file://$MODULE_DIR$/android-library" /> - <excludeFolder url="file://$MODULE_DIR$/dotnet-library" /> - <excludeFolder url="file://$MODULE_DIR$/mono" /> - </content> - <content url="file://$MODULE_DIR$/../test" /> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - <orderEntry type="library" name="ant" level="project" /> - <orderEntry type="library" name="lib1" level="project" /> - <orderEntry type="library" name="testlib" level="project" /> - </component> -</module> - diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala index 71b93835e6..54fe21d4e6 100644 --- a/src/scalap/scala/tools/scalap/Main.scala +++ b/src/scalap/scala/tools/scalap/Main.scala @@ -61,16 +61,28 @@ object Main { out.flush() } - def parseScalaSignature(scalaSig: ScalaSig) = { + def isPackageObjectFile(s: String) = s != null && (s.endsWith(File.separator + "package") || s == "package") + + def parseScalaSignature(scalaSig: ScalaSig, isPackageObject: Boolean) = { val baos = new ByteArrayOutputStream val stream = new PrintStream(baos) val syms = scalaSig.topLevelClasses ::: scalaSig.topLevelObjects syms.first.parent match { //Partial match case Some(p) if (p.name != "<empty>") => { - stream.print("package "); - stream.print(p.path); - stream.print("\n") + val path = p.path + if (!isPackageObject) { + stream.print("package "); + stream.print(path); + stream.print("\n") + } else { + val i = path.lastIndexOf(".") + if (i > 0) { + stream.print("package "); + stream.print(path.substring(0, i)) + stream.print("\n") + } + } } case _ => } @@ -83,11 +95,11 @@ object Main { } - def decompileScala(bytes: Array[Byte]) = { + def decompileScala(bytes: Array[Byte], isPackageObject: Boolean) = { val byteCode = ByteCode(bytes) val classFile = ClassFileParser.parse(byteCode) classFile.attribute(SCALA_SIG).map(_.byteCode).map(ScalaSigAttributeParsers.parse) match { - case Some(scalaSig) => Console.println(parseScalaSignature(scalaSig)) + case Some(scalaSig) => Console.println(parseScalaSignature(scalaSig, isPackageObject)) case None => //Do nothing } } @@ -112,7 +124,7 @@ object Main { } val bytes = cfile.toByteArray if (isScalaFile(bytes)) { - decompileScala(bytes) + decompileScala(bytes, isPackageObjectFile(filename)) } else { // construct a reader for the classfile content val reader = new ByteArrayReader(cfile.toByteArray) diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala index c660bdd7c3..ad29ac0701 100644 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala +++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala @@ -138,14 +138,64 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { val symbolInfo = nameRef ~ symbolRef ~ nat ~ (symbolRef?) ~ ref ~ get ^~~~~~^ SymbolInfo - def symbolEntry(key : Int) = (key -~ none | (key + 64) -~ nat) -~ symbolInfo + def symHeader(key: Int) = (key -~ none | (key + 64) -~ nat) + + def symbolEntry(key : Int) = symHeader(key) -~ symbolInfo + + /*************************************************** + * Symbol table attribute format: + * Symtab = nentries_Nat {Entry} + * Entry = 1 TERMNAME len_Nat NameInfo + * | 2 TYPENAME len_Nat NameInfo + * | 3 NONEsym len_Nat + * | 4 TYPEsym len_Nat SymbolInfo + * | 5 ALIASsym len_Nat SymbolInfo + * | 6 CLASSsym len_Nat SymbolInfo [thistype_Ref] + * | 7 MODULEsym len_Nat SymbolInfo + * | 8 VALsym len_Nat [defaultGetter_Ref] SymbolInfo [alias_Ref] + * | 9 EXTref len_Nat name_Ref [owner_Ref] + * | 10 EXTMODCLASSref len_Nat name_Ref [owner_Ref] + * | 11 NOtpe len_Nat + * | 12 NOPREFIXtpe len_Nat + * | 13 THIStpe len_Nat sym_Ref + * | 14 SINGLEtpe len_Nat type_Ref sym_Ref + * | 15 CONSTANTtpe len_Nat type_Ref constant_Ref + * | 16 TYPEREFtpe len_Nat type_Ref sym_Ref {targ_Ref} + * | 17 TYPEBOUNDStpe len_Nat tpe_Ref tpe_Ref + * | 18 REFINEDtpe len_Nat classsym_Ref {tpe_Ref} + * | 19 CLASSINFOtpe len_Nat classsym_Ref {tpe_Ref} + * | 20 METHODtpe len_Nat tpe_Ref {sym_Ref} + * | 21 POLYTtpe len_Nat tpe_Ref {sym_Ref} + * | 22 IMPLICITMETHODtpe len_Nat tpe_Ref {tpe_Ref} + * | 52 SUPERtpe len_Nat tpe_Ref tpe_Ref + * | 24 LITERALunit len_Nat + * | 25 LITERALboolean len_Nat value_Long + * | 26 LITERALbyte len_Nat value_Long + * | 27 LITERALshort len_Nat value_Long + * | 28 LITERALchar len_Nat value_Long + * | 29 LITERALint len_Nat value_Long + * | 30 LITERALlong len_Nat value_Long + * | 31 LITERALfloat len_Nat value_Long + * | 32 LITERALdouble len_Nat value_Long + * | 33 LITERALstring len_Nat name_Ref + * | 34 LITERALnull len_Nat + * | 35 LITERALclass len_Nat tpe_Ref + * | 36 LITERALenum len_Nat sym_Ref + * | 40 SYMANNOT len_Nat sym_Ref AnnotInfoBody + * | 41 CHILDREN len_Nat sym_Ref {sym_Ref} + * | 42 ANNOTATEDtpe len_Nat [sym_Ref] tpe_Ref {annotinfo_Ref} + * | 43 ANNOTINFO len_Nat AnnotInfoBody + * | 44 ANNOTARGARRAY len_Nat {constAnnotArg_Ref} + * | 47 DEBRUIJNINDEXtpe len_Nat level_Nat index_Nat + * | 48 EXISTENTIALtpe len_Nat type_Ref {symbol_Ref} + */ val noSymbol = 3 -^ NoSymbol val typeSymbol = symbolEntry(4) ^^ TypeSymbol as "typeSymbol" val aliasSymbol = symbolEntry(5) ^^ AliasSymbol as "alias" val classSymbol = symbolEntry(6) ~ (ref?) ^~^ ClassSymbol as "class" val objectSymbol = symbolEntry(7) ^^ ObjectSymbol as "object" - val methodSymbol = symbolEntry(8) ~ (ref?) ^~^ MethodSymbol as "method" + val methodSymbol = symHeader(8) -~ /*(ref?) -~*/ symbolInfo ~ (ref?) ^~^ MethodSymbol as "method" val extRef = 9 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extRef" val extModClassRef = 10 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extModClassRef" @@ -174,9 +224,9 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { 17 -~ typeRef ~ typeRef ^~^ TypeBoundsType, 18 -~ classSymRef ~ (typeRef*) ^~^ RefinedType, 19 -~ symbolRef ~ (typeRef*) ^~^ ClassInfoType, - 20 -~ typeRef ~ (typeRef*) ^~^ MethodType, + 20 -~ typeRef ~ (symbolRef*) ^~^ MethodType, 21 -~ typeRef ~ (refTo(typeSymbol)*) ^~^ PolyType, - 22 -~ typeRef ~ (typeRef*) ^~^ ImplicitMethodType, + 22 -~ typeRef ~ (symbolRef*) ^~^ ImplicitMethodType, 42 -~ typeRef ~ (attribTreeRef*) ^~^ AnnotatedType, 51 -~ typeRef ~ symbolRef ~ (attribTreeRef*) ^~~^ AnnotatedWithSelfType, 47 -~ typeLevel ~ typeIndex ^~^ DeBruijnIndexType, @@ -215,55 +265,59 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { case class AnnotInfo(refs : Seq[Int]) // attarg_Ref {constant_Ref attarg_Ref} - /* | 49 TREE len_Nat 1 EMPTYtree - * | 49 TREE len_Nat 2 PACKAGEtree type_Ref sym_Ref mods_Ref name_Ref {tree_Ref} - * | 49 TREE len_Nat 3 CLASStree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 4 MODULEtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref - * | 49 TREE len_Nat 5 VALDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 6 DEFDEFtree type_Ref sym_Ref mods_Ref name_Ref numtparams_Nat {tree_Ref} numparamss_Nat {numparams_Nat {tree_Ref}} tree_Ref tree_Ref - * | 49 TREE len_Nat 7 TYPEDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 8 LABELtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 9 IMPORTtree type_Ref sym_Ref tree_Ref {name_Ref name_Ref} - * | 49 TREE len_Nat 10 ANNOTATIONtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 11 DOCDEFtree type_Ref sym_Ref string_Ref tree_Ref - * | 49 TREE len_Nat 12 TEMPLATEtree type_Ref sym_Ref numparents_Nat {tree_Ref} tree_Ref {tree_Ref} - * | 49 TREE len_Nat 13 BLOCKtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 14 CASEtree type_Ref tree_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 15 SEQUENCEtree type_Ref {tree_Ref} - * | 49 TREE len_Nat 16 ALTERNATIVEtree type_Ref {tree_Ref} - * | 49 TREE len_Nat 17 STARtree type_Ref {tree_Ref} - * | 49 TREE len_Nat 18 BINDtree type_Ref sym_Ref name_Ref tree_Ref - * | 49 TREE len_Nat 19 UNAPPLYtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 20 ARRAYVALUEtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 21 FUNCTIONtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 22 ASSIGNtree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 23 IFtree type_Ref tree_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 24 MATCHtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 25 RETURNtree type_Ref sym_Ref tree_Ref - * | 49 TREE len_Nat 26 TREtree type_Ref tree_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 27 THROWtree type_Ref tree_Ref - * | 49 TREE len_Nat 28 NEWtree type_Ref tree_Ref - * | 49 TREE len_Nat 29 TYPEDtree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 30 TYPEAPPLYtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 31 APPLYtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 32 APPLYDYNAMICtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 33 SUPERtree type_Ref sym_Ref tree_Ref name_Ref - * | 49 TREE len_Nat 34 THIStree type_Ref sym_Ref name_Ref - * | 49 TREE len_Nat 35 SELECTtree type_Ref sym_Ref tree_Ref name_Ref - * | 49 TREE len_Nat 36 IDENTtree type_Ref sym_Ref name_Ref - * | 49 TREE len_Nat 37 LITERALtree type_Ref constant_Ref - * | 49 TREE len_Nat 38 TYPEtree type_Ref - * | 49 TREE len_Nat 39 ANNOTATEDtree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 40 SINGLETONTYPEtree type_Ref tree_Ref - * | 49 TREE len_Nat 41 SELECTFROMTYPEtree type_Ref tree_Ref name_Ref - * | 49 TREE len_Nat 42 COMPOUNDTYPEtree type_Ref tree_Ref - * | 49 TREE len_Nat 43 APPLIEDTYPEtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 44 TYPEBOUNDStree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 45 EXISTENTIALTYPEtree type_Ref tree_Ref {tree_Ref} - * | 50 MODIFIERS len_Nat flags_Long privateWithin_Ref {Annotation_Ref} - - * Attarg = Refltree | Constant - * - * len is remaining length after `len'. - */ - + /*************************************************** + * | 49 TREE len_Nat 1 EMPTYtree + * | 49 TREE len_Nat 2 PACKAGEtree type_Ref sym_Ref mods_Ref name_Ref {tree_Ref} + * | 49 TREE len_Nat 3 CLASStree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 4 MODULEtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref + * | 49 TREE len_Nat 5 VALDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 6 DEFDEFtree type_Ref sym_Ref mods_Ref name_Ref numtparams_Nat {tree_Ref} numparamss_Nat {numparams_Nat {tree_Ref}} tree_Ref tree_Ref + * | 49 TREE len_Nat 7 TYPEDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 8 LABELtree type_Ref sym_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 9 IMPORTtree type_Ref sym_Ref tree_Ref {name_Ref name_Ref} + * | 49 TREE len_Nat 11 DOCDEFtree type_Ref sym_Ref string_Ref tree_Ref + * | 49 TREE len_Nat 12 TEMPLATEtree type_Ref sym_Ref numparents_Nat {tree_Ref} tree_Ref {tree_Ref} + * | 49 TREE len_Nat 13 BLOCKtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 14 CASEtree type_Ref tree_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 15 SEQUENCEtree type_Ref {tree_Ref} + * | 49 TREE len_Nat 16 ALTERNATIVEtree type_Ref {tree_Ref} + * | 49 TREE len_Nat 17 STARtree type_Ref {tree_Ref} + * | 49 TREE len_Nat 18 BINDtree type_Ref sym_Ref name_Ref tree_Ref + * | 49 TREE len_Nat 19 UNAPPLYtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 20 ARRAYVALUEtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 21 FUNCTIONtree type_Ref sym_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 22 ASSIGNtree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 23 IFtree type_Ref tree_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 24 MATCHtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 25 RETURNtree type_Ref sym_Ref tree_Ref + * | 49 TREE len_Nat 26 TREtree type_Ref tree_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 27 THROWtree type_Ref tree_Ref + * | 49 TREE len_Nat 28 NEWtree type_Ref tree_Ref + * | 49 TREE len_Nat 29 TYPEDtree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 30 TYPEAPPLYtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 31 APPLYtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 32 APPLYDYNAMICtree type_Ref sym_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 33 SUPERtree type_Ref sym_Ref tree_Ref name_Ref + * | 49 TREE len_Nat 34 THIStree type_Ref sym_Ref name_Ref + * | 49 TREE len_Nat 35 SELECTtree type_Ref sym_Ref tree_Ref name_Ref + * | 49 TREE len_Nat 36 IDENTtree type_Ref sym_Ref name_Ref + * | 49 TREE len_Nat 37 LITERALtree type_Ref constant_Ref + * | 49 TREE len_Nat 38 TYPEtree type_Ref + * | 49 TREE len_Nat 39 ANNOTATEDtree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 40 SINGLETONTYPEtree type_Ref tree_Ref + * | 49 TREE len_Nat 41 SELECTFROMTYPEtree type_Ref tree_Ref name_Ref + * | 49 TREE len_Nat 42 COMPOUNDTYPEtree type_Ref tree_Ref + * | 49 TREE len_Nat 43 APPLIEDTYPEtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 44 TYPEBOUNDStree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 45 EXISTENTIALTYPEtree type_Ref tree_Ref {tree_Ref} + * | 50 MODIFIERS len_Nat flags_Long privateWithin_Ref + * SymbolInfo = name_Ref owner_Ref flags_LongNat [privateWithin_Ref] info_Ref + * NameInfo = <character sequence of length len_Nat in Utf8 format> + * NumInfo = <len_Nat-byte signed number in big endian format> + * Ref = Nat + * AnnotInfoBody = info_Ref {annotArg_Ref} {name_Ref constAnnotArg_Ref} + * AnnotArg = Tree | Constant + * ConstAnnotArg = Constant | AnnotInfo | AnnotArgArray + * + * len is remaining length after `len'. + */
\ No newline at end of file diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala index dd711e41db..f3e395ae75 100644 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala +++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala @@ -32,7 +32,12 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { case o: ObjectSymbol => if (!isCaseClassObject(o)) { indent - printObject(level, o) + if (o.name == "package") { + // print package object + printPackageObject(level, o) + } else { + printObject(level, o) + } } case c: ClassSymbol if !refinementClass(c) && !c.isModule => indent @@ -76,7 +81,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { def printModifiers(symbol: Symbol) { if (symbol.isSealed) print("sealed ") if (symbol.isImplicit) print("implicit ") - if (symbol.isFinal) print("final ") + if (symbol.isFinal && !symbol.isInstanceOf[ObjectSymbol]) print("final ") if (symbol.isPrivate) print("private ") else if (symbol.isProtected) print("protected ") if (symbol.isOverride) print("override ") @@ -120,13 +125,27 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { val baos = new ByteArrayOutputStream val stream = new PrintStream(baos) val printer = new ScalaSigPrinter(stream, printPrivates) - printer.printMethodType(m.infoType, false) +// printer.printMethodType(m.infoType, false) baos.toString case None => "" } } + def printPackageObject(level: Int, o: ObjectSymbol) { + printModifiers(o) + print("package ") + print("object ") + val poName = o.symbolInfo.owner.name + print(processName(poName)) + val TypeRefType(prefix, classSymbol: ClassSymbol, typeArgs) = o.infoType + printType(classSymbol) + print(" {\n") + printChildren(level, classSymbol) + printWithIndent(level, "}\n") + + } + def printObject(level: Int, o: ObjectSymbol) { printModifiers(o) print("object ") @@ -148,33 +167,49 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { if (res.length > 1) StringUtil.decapitalize(res.substring(0, 1)) else res.toLowerCase }) - def printMethodType(t: Type, printResult: Boolean): Unit = { - def _pmt(mt: Type {def resultType: Type; def paramTypes: Seq[Type]}) = { - print(genParamNames(mt).zip(mt.paramTypes.toList.map(toString(_)(TypeFlags(true)))).map(p => p._1 + " : " + p._2).mkString( - "(" + (mt match {case ImplicitMethodType(_, _) => "implicit "; case _ => ""}) + def printMethodType(t: Type, printResult: Boolean)(implicit cont : => Unit): Unit = { + + def _pmt(mt: Type {def resultType: Type; def paramSymbols: Seq[Symbol]}) = { + + val paramEntries = mt.paramSymbols.map({ + case ms: MethodSymbol => ms.name + " : " + toString(ms.infoType)(TypeFlags(true)) + case _ => "^___^" + }) + + // Printe parameter clauses + print(paramEntries.mkString( + "(" + (mt match {case _ : ImplicitMethodType => "implicit "; case _ => ""}) , ", ", ")")) + + // Print result type mt.resultType match { - case mt: MethodType => printMethodType(mt, printResult) - case imt: ImplicitMethodType => printMethodType(imt, printResult) + case mt: MethodType => printMethodType(mt, printResult)({}) + case imt: ImplicitMethodType => printMethodType(imt, printResult)({}) case x => if (printResult) { print(" : "); printType(x) } } } + t match { - case mt@MethodType(resType, paramTypes) => _pmt(mt) - case mt@ImplicitMethodType(resType, paramTypes) => _pmt(mt) + case mt@MethodType(resType, paramSymbols) => _pmt(mt) + case mt@ImplicitMethodType(resType, paramSymbols) => _pmt(mt) case pt@PolyType(mt, typeParams) => { print(typeParamString(typeParams)) - printMethodType(mt, printResult) + printMethodType(mt, printResult)({}) } //todo consider another method types case x => print(" : "); printType(x) } + + // Print rest of the symbol output + cont } def printMethod(level: Int, m: MethodSymbol, indent: () => Unit) { + def cont = print(" = { /* compiled code */ }") + val n = m.name if (underCaseClass(m) && n == CONSTRUCTOR_NAME) return if (m.isAccessor && n.endsWith("_$eq")) return @@ -190,18 +225,15 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { n match { case CONSTRUCTOR_NAME => print("this") - printMethodType(m.infoType, false) - print(" = { /* compiled code */ }") + printMethodType(m.infoType, false)(cont) case name => val nn = processName(name) print(nn) - printMethodType(m.infoType, true) - if (!m.isDeferred) { // Print body only for non-abstract metods - print(" = { /* compiled code */ }") - } + printMethodType(m.infoType, true)( + {if (!m.isDeferred) print(" = { /* compiled code */ }" /* Print body only for non-abstract metods */ )} + ) } print("\n") - printChildren(level, m) } def printAlias(level: Int, a: AliasSymbol) { @@ -276,7 +308,10 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { case _ => "scala.Seq" + typeArgString(typeArgs) } case "scala.<byname>" => "=> " + toString(typeArgs.first) - case _ => StringUtil.trimStart(processName(symbol.path) + typeArgString(typeArgs), "<empty>.") + case _ => { + val path = StringUtil.cutSubstring(symbol.path)(".package") //remove package object reference + StringUtil.trimStart(processName(path) + typeArgString(typeArgs), "<empty>.") + } }) case TypeBoundsType(lower, upper) => " >: " + toString(lower) + " <: " + toString(upper) case RefinedType(classSym, typeRefs) => sep + typeRefs.map(toString).mkString("", " with ", "") diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala index c812a94af7..f6986b28b7 100644 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala +++ b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala @@ -12,10 +12,10 @@ case class TypeRefType(prefix : Type, symbol : Symbol, typeArgs : Seq[Type]) ext case class TypeBoundsType(lower : Type, upper : Type) extends Type case class RefinedType(classSym : Symbol, typeRefs : List[Type]) extends Type case class ClassInfoType(symbol : Symbol, typeRefs : Seq[Type]) extends Type -case class MethodType(resultType : Type, paramTypes : Seq[Type]) extends Type +case class MethodType(resultType : Type, paramSymbols : Seq[Symbol]) extends Type case class PolyType(typeRef : Type, symbols : Seq[TypeSymbol]) extends Type case class PolyTypeWithCons(typeRef : Type, symbols : Seq[TypeSymbol], cons: String) extends Type -case class ImplicitMethodType(resultType : Type, paramTypes : Seq[Type]) extends Type +case class ImplicitMethodType(resultType : Type, paramSymbols : Seq[Symbol]) extends Type case class AnnotatedType(typeRef : Type, attribTreeRefs : List[Int]) extends Type case class AnnotatedWithSelfType(typeRef : Type, symbol : Symbol, attribTreeRefs : List[Int]) extends Type case class DeBruijnIndexType(typeLevel : Int, typeIndex : Int) extends Type diff --git a/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala b/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala index d48597fd9a..7986763b7b 100644 --- a/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala +++ b/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala @@ -12,4 +12,6 @@ object StringUtil { def decapitalize(s: String) = Introspector.decapitalize(s) + def cutSubstring(dom: String)(s: String) = if (dom != null && s != null) dom.replace(s, "") else dom + }
\ No newline at end of file |