summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilyas <ilyas@epfl.ch>2009-01-22 18:43:57 +0000
committerilyas <ilyas@epfl.ch>2009-01-22 18:43:57 +0000
commit59d2220360399bf57859713f636a29e307172b2f (patch)
treefceac28eb095c6337a14cb68009a9ad8fc4d275b /src
parentd7839e8a6dc23049f9b0cc979c5e2ba54ce07a5a (diff)
downloadscala-59d2220360399bf57859713f636a29e307172b2f.tar.gz
scala-59d2220360399bf57859713f636a29e307172b2f.tar.bz2
scala-59d2220360399bf57859713f636a29e307172b2f.zip
scalap modified for correct case classes printing
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scalax/rules/scalasig/ScalaSigPrinter.scala58
-rw-r--r--src/compiler/scalax/rules/scalasig/Type.scala4
2 files changed, 54 insertions, 8 deletions
diff --git a/src/compiler/scalax/rules/scalasig/ScalaSigPrinter.scala b/src/compiler/scalax/rules/scalasig/ScalaSigPrinter.scala
index 9dbdbfd25a..f85c8884a5 100644
--- a/src/compiler/scalax/rules/scalasig/ScalaSigPrinter.scala
+++ b/src/compiler/scalax/rules/scalasig/ScalaSigPrinter.scala
@@ -1,13 +1,15 @@
package scalax.rules.scalasig
import _root_.scala.Symbol
+import java.io.{PrintStream, ByteArrayOutputStream}
import util.StringUtil
-import java.io.PrintStream
import java.util.regex.Pattern
class ScalaSigPrinter(stream: PrintStream) {
import stream._
+ val CONSTRUCTOR_NAME = "<init>"
+
case class TypeFlags(printRep: Boolean)
def printSymbol(symbol: Symbol) {printSymbol(0, symbol)}
@@ -17,8 +19,14 @@ class ScalaSigPrinter(stream: PrintStream) {
def indent() {for (i <- 1 to level) print(" ")}
symbol match {
- case o: ObjectSymbol => indent; printObject(level, o)
- case c: ClassSymbol if !refinementClass(c) && !c.isModule => indent; printClass(level, c)
+ case o: ObjectSymbol => indent; {
+ if (!isCaseClassObject(o)) {
+ printObject(level, o)
+ }
+ }
+ case c: ClassSymbol if !refinementClass(c) && !c.isModule => indent; {
+ printClass(level, c)
+ }
case m: MethodSymbol => printMethod(level, m, indent)
case a: AliasSymbol => indent; printAlias(level, a)
case t: TypeSymbol => ()
@@ -27,6 +35,20 @@ class ScalaSigPrinter(stream: PrintStream) {
}
}
+ def isCaseClassObject(o: ObjectSymbol): Boolean = {
+ val TypeRefType(prefix, classSymbol: ClassSymbol, typeArgs) = o.infoType
+ o.isFinal && (classSymbol.children.find(_.isCase) match {
+ case Some(_) => true
+ case None => false
+ })
+ }
+
+ def underCaseClass(m: MethodSymbol) = m.parent match {
+ case Some(c: ClassSymbol) => c.isCase
+ case _ => false
+ }
+
+
def printChildren(level: Int, symbol: Symbol) {
for (child <- symbol.children) printSymbol(level + 1, child)
}
@@ -55,9 +77,15 @@ class ScalaSigPrinter(stream: PrintStream) {
def printClass(level: Int, c: ClassSymbol) {
printModifiers(c)
+ val defaultConstructor = if (c.isCase) getPrinterByConstructor(c) else ""
if (c.isTrait) print("trait ") else print("class ")
print(processName(c.name))
- printType(c)
+ val it = c.infoType
+ val classType = it match {
+ case PolyType(typeRef, symbols) => PolyTypeWithCons(typeRef, symbols, defaultConstructor)
+ case _ => it
+ }
+ printType(classType)
print(" {")
//Print class selftype
c.selfType match {
@@ -69,6 +97,22 @@ class ScalaSigPrinter(stream: PrintStream) {
printWithIndent(level, "}\n")
}
+ def getPrinterByConstructor(c: ClassSymbol) = {
+ c.children.find{
+ case m : MethodSymbol if m.name == CONSTRUCTOR_NAME => true
+ case _ => false
+ } match {
+ case Some(m: MethodSymbol) => {
+ val baos = new ByteArrayOutputStream
+ val stream = new PrintStream(baos)
+ val printer = new ScalaSigPrinter(stream)
+ printer.printMethodType(m.infoType, false)
+ baos.toString
+ }
+ case None => ""
+ }
+ }
+
def printObject(level: Int, o: ObjectSymbol) {
printModifiers(o)
print("object ")
@@ -118,6 +162,7 @@ class ScalaSigPrinter(stream: PrintStream) {
def printMethod(level: Int, m: MethodSymbol, indent : () => Unit): Unit = {
val n = m.name
+ if (underCaseClass(m) && n == CONSTRUCTOR_NAME) return
if (m.isAccessor && n.endsWith("_$eq")) return
indent()
printModifiers(m)
@@ -129,7 +174,7 @@ class ScalaSigPrinter(stream: PrintStream) {
print("def ")
}
n match {
- case "<init>" => {
+ case CONSTRUCTOR_NAME => {
print("this")
printMethodType(m.infoType, false)
print(" = { /* compiled code */ }")
@@ -138,7 +183,7 @@ class ScalaSigPrinter(stream: PrintStream) {
val nn = processName(name)
print(nn)
printMethodType(m.infoType, true)
- if (!m.isAbstract) { // Print body for non-abstract metods
+ if (!m.isDeferred) { // Print body only for non-abstract metods
print(" = { /* compiled code */ }")
}
}
@@ -229,6 +274,7 @@ class ScalaSigPrinter(stream: PrintStream) {
case MethodType(resultType, _) => toString(resultType, sep)
case PolyType(typeRef, symbols) => typeParamString(symbols) + toString(typeRef, sep)
+ case PolyTypeWithCons(typeRef, symbols, cons) => typeParamString(symbols) + cons + toString(typeRef, sep)
case AnnotatedType(typeRef, attribTreeRefs) => toString(typeRef, sep)
case AnnotatedWithSelfType(typeRef, symbol, attribTreeRefs) => toString(typeRef, sep)
//case DeBruijnIndexType(typeLevel, typeIndex) =>
diff --git a/src/compiler/scalax/rules/scalasig/Type.scala b/src/compiler/scalax/rules/scalasig/Type.scala
index 1fcb306ef7..0298f4a0c0 100644
--- a/src/compiler/scalax/rules/scalasig/Type.scala
+++ b/src/compiler/scalax/rules/scalasig/Type.scala
@@ -14,9 +14,9 @@ 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 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 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
-case class ExistentialType(typeRef : Type, symbols : Seq[Symbol]) extends Type
-
+case class ExistentialType(typeRef : Type, symbols : Seq[Symbol]) extends Type \ No newline at end of file