scalap changed to treat named parameters and package objects

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@18149 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
ilyas 2009-06-29 16:09:59 +00:00
parent 498f9c76f1
commit eb21570b03
34 changed files with 241 additions and 1228 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -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>

View File

@ -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)

View File

@ -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'.
*/

View File

@ -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,13 +81,13 @@ 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 ")
if (symbol.isAbstract) symbol match {
case c@(_: ClassSymbol | _: ObjectSymbol) if !c.isTrait => print("abstract ")
case _ => ()
case _ => ()
}
if (symbol.isCase && !symbol.isMethod) print("case ")
}
@ -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 ", "")

View File

@ -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

View File

@ -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
}

View File

@ -1,11 +0,0 @@
case class CaseClass[A >: scala.Nothing <: scala.Seq[scala.Int]](a : A, s : scala.Predef.String) extends java.lang.Object with scala.ScalaObject with scala.Product {
val i : A = { /* compiled code */ }
val s : scala.Predef.String = { /* compiled code */ }
def foo : scala.Int = { /* compiled code */ }
override def hashCode() : scala.Int = { /* compiled code */ }
override def toString() : scala.Predef.String = { /* compiled code */ }
override def equals(a : scala.Any) : scala.Boolean = { /* compiled code */ }
override def productPrefix : java.lang.String = { /* compiled code */ }
override def productArity : scala.Int = { /* compiled code */ }
override def productElement(i : scala.Int) : scala.Any = { /* compiled code */ }
}

View File

@ -1 +0,0 @@
class CbnParam(s: => String)

View File

@ -1,4 +0,0 @@
class ParamNames extends java.lang.Object with scala.ScalaObject {
def this() = { /* compiled code */ }
def foo(s : => scala.Seq[scala.Int], s : => scala.Seq[scala.Any]) : scala.Unit = { /* compiled code */ }
}

View File

@ -1,3 +1,3 @@
case class CaseClass[A <: Seq[Int]](i: A, s: String) {
def foo = 239
def foo = 239
}

View File

@ -0,0 +1,14 @@
case class CaseClass[A >: scala.Nothing <: scala.Seq[scala.Int]] extends java.lang.Object with scala.ScalaObject with scala.Product {
val i : A = { /* compiled code */ }
val s : scala.Predef.String = { /* compiled code */ }
def foo : scala.Int = { /* compiled code */ }
def copy[A >: scala.Nothing <: scala.Seq[scala.Int]]() : CaseClass[A] = { /* compiled code */ }
def copy$default$1[A >: scala.Nothing <: scala.Seq[scala.Int]] : A = { /* compiled code */ }
def copy$default$2[A >: scala.Nothing <: scala.Seq[scala.Int]] : scala.Predef.String = { /* compiled code */ }
override def hashCode() : scala.Int = { /* compiled code */ }
override def toString() : scala.Predef.String = { /* compiled code */ }
override def equals(x$1 : scala.Any) : scala.Boolean = { /* compiled code */ }
override def productPrefix : java.lang.String = { /* compiled code */ }
override def productArity : scala.Int = { /* compiled code */ }
override def productElement(x$1 : scala.Int) : scala.Any = { /* compiled code */ }
}

View File

@ -1,3 +1,3 @@
case object CaseObject {
def bar = 239
def bar = 239
}

View File

@ -1,8 +1,8 @@
final case object CaseObject extends java.lang.Object with scala.ScalaObject with scala.Product {
case object CaseObject extends java.lang.Object with scala.ScalaObject with scala.Product {
def bar : scala.Int = { /* compiled code */ }
final override def toString() : java.lang.String = { /* compiled code */ }
override def productPrefix : java.lang.String = { /* compiled code */ }
override def productArity : scala.Int = { /* compiled code */ }
override def productElement(i : scala.Int) : scala.Any = { /* compiled code */ }
override def productElement(x$1 : scala.Int) : scala.Any = { /* compiled code */ }
protected def readResolve() : java.lang.Object = { /* compiled code */ }
}

View File

@ -0,0 +1 @@
class CbnParam(s: => String)

View File

@ -0,0 +1,4 @@
package object PackageObject {
type A = String
def foo(i: Int) = 239
}

View File

@ -0,0 +1,5 @@
package object PackageObject extends java.lang.Object with scala.ScalaObject {
def this() = { /* compiled code */ }
type A = scala.Predef.String
def foo(i : scala.Int) : scala.Int = { /* compiled code */ }
}

View File

@ -1,4 +1,4 @@
class ParamClauses extends java.lang.Object with scala.ScalaObject {
def this() = { /* compiled code */ }
def foo(i : scala.Int)(s : scala.Predef.String)(d : scala.Double) : scala.Int = { /* compiled code */ }
def foo(i : scala.Int)(s : scala.Predef.String)(t : scala.Double) : scala.Int = { /* compiled code */ }
}

View File

@ -0,0 +1,4 @@
class ParamNames extends java.lang.Object with scala.ScalaObject {
def this() = { /* compiled code */ }
def foo(s : => scala.Seq[scala.Int], s2 : => scala.Seq[scala.Any]) : scala.Unit = { /* compiled code */ }
}

View File

@ -1,3 +1,3 @@
class SequenceParam extends java.lang.Object with scala.ScalaObject {
def this(s : scala.Predef.String, s : scala.Int*) = { /* compiled code */ }
def this(s : scala.Predef.String, i : scala.Int*) = { /* compiled code */ }
}

View File

@ -2,7 +2,7 @@ trait TraitObject extends java.lang.Object with scala.ScalaObject {
def $init$() : scala.Unit = { /* compiled code */ }
def foo : scala.Int = { /* compiled code */ }
}
final object TraitObject extends java.lang.Object with scala.ScalaObject {
object TraitObject extends java.lang.Object with scala.ScalaObject {
def this() = { /* compiled code */ }
def bar : scala.Int = { /* compiled code */ }
}