diff options
author | Matthias Zenger <mzenger@gmail.com> | 2004-02-11 13:26:10 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2004-02-11 13:26:10 +0000 |
commit | 990b79b76d437d1b98a19d956d3284c094540642 (patch) | |
tree | a84b899417603ebaf551864dbe7ecded61340b2f /sources | |
parent | 5cf09c3b1beba694440384d52d9d7a345f2fc579 (diff) | |
download | scala-990b79b76d437d1b98a19d956d3284c094540642.tar.gz scala-990b79b76d437d1b98a19d956d3284c094540642.tar.bz2 scala-990b79b76d437d1b98a19d956d3284c094540642.zip |
- Fixed some bugs
- Cleaned up code
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/scalap/Flags.scala | 144 | ||||
-rw-r--r-- | sources/scala/tools/scalap/JavaWriter.scala | 61 | ||||
-rw-r--r-- | sources/scala/tools/scalap/Main.scala | 50 | ||||
-rw-r--r-- | sources/scala/tools/scalap/ScalaWriter.scala | 288 |
4 files changed, 274 insertions, 269 deletions
diff --git a/sources/scala/tools/scalap/Flags.scala b/sources/scala/tools/scalap/Flags.scala index aafd795a67..df44d0e576 100644 --- a/sources/scala/tools/scalap/Flags.scala +++ b/sources/scala/tools/scalap/Flags.scala @@ -9,115 +9,71 @@ package scala.tools.scalap; +/** Encoding of modifiers for Scala definitions. + * + * @author Matthias Zenger + * @version 1.0, 10/02/2004 + */ object Flags { - final val DEFERRED = 0x00000001; - final val FINAL = 0x00000002; - final val PRIVATE = 0x00000004; - final val PROTECTED = 0x00000008; - - final val SEALED = 0x00000010; - final val OVERRIDE = 0x00000020; - final val CASE = 0x00000040; + final val DEFERRED = 0x00000001; // non-concrete definition + final val FINAL = 0x00000002; // final definition + final val PRIVATE = 0x00000004; // private definition + final val PROTECTED = 0x00000008; // protected definition + final val SEALED = 0x00000010; // sealed class + final val OVERRIDE = 0x00000020; // definition overrides other definition + final val CASE = 0x00000040; // case class final val ABSTRACT = 0x00000080; // abstract class final val DEF = 0x00000100; // a def parameter final val REPEATED = 0x00000200; // a repeated parameter - final val SYNTHETIC = 0x00000400; - final val DEPRECATED = 0x00000800; - - final val JAVA = 0x00001000; // symbol was defined by a Java class - final val OBJECT = 0x00002000; // symbol is module or class implementing a module - final val MUTABLE = 0x00004000; // symbol is a mutable variable. - final val PARAM = 0x00008000; // symbol is a (type) parameter to a method - - final val INITIALIZED = 0x00010000; // symbol's definition is complete - final val LOCKED = 0x00020000; // temporary flag to catch cyclic dependencies - final val ACCESSED = 0x00040000; // symbol was accessed at least once - final val SELECTOR = 0x00080000; // symbol was used as selector in Select - - final val PACKAGE = 0x00100000; // symbol is a java package. - final val LABEL = 0x00200000; // symbol is a label symbol - final val STATIC = 0x00400000; // "static" inner classes (i.e. after class norm.) - final val STABLE = 0x00800000; // functions that are assumed to be stable - // (typically, access methods for valdefs) - - final val CAPTURED = 0x01000000; // variables is accessed from nested function. - final val CASEACCESSOR = 0x02000000; // function is a case constructor - - final val ACCESSOR = 0x04000000; // function is an access function for a - // value or variable - final val BRIDGE = 0x08000000; // function is a bridge method. - - final val INTERFACE = 0x10000000; // symbol is a Java interface - final val TRAIT = 0x20000000; // symbol is a Trait - - final val COVAR = 0x40000000; // symbol is a covariant type variable - final val CONTRAVAR = 0x80000000; // symbol is a contravariant type variable - - // masks - final val SOURCEFLAGS = 0x00000077 - | DEF | REPEATED | OBJECT | MUTABLE - | PACKAGE | PARAM | TRAIT | COVAR - | CONTRAVAR; // these modifiers can be set in source programs - final val ACCESSFLAGS = PRIVATE | PROTECTED; - final val VARIANCES = COVAR | CONTRAVAR; - - def isDeferred(flags: Int): Boolean = (flags & DEFERRED) != 0; - - def isAbstract(flags: Int): Boolean = (flags & ABSTRACT) != 0; - - def isFinal(flags: Int): Boolean = (flags & FINAL) != 0; - - def isPrivate(flags: Int): Boolean = (flags & PRIVATE) != 0; - - def isProtected(flags: Int): Boolean = (flags & PROTECTED) != 0; - - def isSealed(flags: Int): Boolean = (flags & SEALED) != 0; - - def isOverride(flags: Int): Boolean = (flags & OVERRIDE) != 0; - - def isCase(flags: Int): Boolean = (flags & CASE) != 0; - - def isAccessor(flags: Int): Boolean = (flags & ACCESSOR) != 0; - - def isCaseAccessor(flags: Int): Boolean = (flags & CASEACCESSOR) != 0; - - def isInterface(flags: Int): Boolean = (flags & INTERFACE) != 0; - def isTrait(flags: Int): Boolean = (flags & TRAIT) != 0; + final val SYNTHETIC = 0x00000400; // a synthetic definition + final val DEPRECATED = 0x00000800; // a deprecated definition - def isObj(flags: Int): Boolean = (flags & OBJECT) != 0; + final val JAVA = 0x00001000; // defined by a Java class + final val OBJECT = 0x00002000; // a singleton object + final val MUTABLE = 0x00004000; // a mutable variable + final val PARAM = 0x00008000; // a (type) parameter of a method + final val PACKAGE = 0x00100000; // a java package - def isDef(flags: Int): Boolean = (flags & DEF) != 0; + final val CASEACCESSOR = 0x02000000; // a case constructor + final val ACCESSOR = 0x04000000; // an access function for a value/variable + final val BRIDGE = 0x08000000; // a bridge method. - def isObjClass(flags: Int): Boolean = (flags & OBJECT) != 0; + final val INTERFACE = 0x10000000; // a Java interface + final val TRAIT = 0x20000000; // a trait - def isStatic(flags: Int): Boolean = (flags & STATIC) != 0; + final val COVAR = 0x40000000; // a covariant type variable + final val CONTRAVAR = 0x80000000; // a contravariant type variable - def isJava(flags: Int): Boolean = (flags & JAVA) != 0; + final val TF_STAR = 4; // a repeated type + final val TF_DEF = 8; // a 'def' type - def isNoVal(flags: Int): Boolean = (flags & PACKAGE) != 0; + /** Check if a flag is present in the given flag set. + */ + def is(flag: Int, flagset: Int): Boolean = (flag & flagset) != 0; - def toString(flags: Int): String = { + /** Convert a set of modifiers into a readable string. + */ + def toString(flags: Int): String = { val buffer = new StringBuffer(); - var x: StringBuffer = buffer; - if (isPrivate(flags)) - x = buffer.append("private "); - if (isProtected(flags)) - x = buffer.append("protected "); - if (isAbstract(flags) && !isTrait(flags)) - x = buffer.append("abstract "); - if (isFinal(flags) && !isObj(flags)) - x = buffer.append("final "); - if (isSealed(flags)) - x = buffer.append("sealed "); - if (isCase(flags)) - x = buffer.append("case "); - if (isDef(flags)) - x = buffer.append("def "); - if (isOverride(flags)) - x = buffer.append("override "); + if (is(PRIVATE, flags)) + buffer.append("private "); + if (is(PROTECTED, flags)) + buffer.append("protected "); + if (is(ABSTRACT, flags) && !is(TRAIT, flags)) + buffer.append("abstract "); + if (is(FINAL, flags) && !is(OBJECT, flags)) + buffer.append("final "); + if (is(SEALED, flags)) + buffer.append("sealed "); + if (is(CASE, flags)) + buffer.append("case "); + if (is(DEF, flags)) + buffer.append("def "); + if (is(OVERRIDE, flags)) + buffer.append("override "); buffer.toString() } } diff --git a/sources/scala/tools/scalap/JavaWriter.scala b/sources/scala/tools/scalap/JavaWriter.scala index 670406383d..8c3a61db1c 100644 --- a/sources/scala/tools/scalap/JavaWriter.scala +++ b/sources/scala/tools/scalap/JavaWriter.scala @@ -83,7 +83,7 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer case cf.UTF8(str) => str; case cf.StringConst(m) => getName(m); case cf.ClassRef(m) => getName(m); - case x => Console.println("* " + x); "<error>" + case x => "<error>" } def getClassName(n: Int): String = nameToClass(getName(n)); @@ -101,12 +101,12 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer def isConstr(name: String) = (name == "<init>"); def printField(flags: Int, name: Int, tpe: Int, attribs: List[cf.Attribute]) = { - print(flagsToStr(false, flags))*; + print(flagsToStr(false, flags)); if ((flags & 0x0010) != 0) - print("val " + Names.decode(getName(name)))*; + print("val " + Names.decode(getName(name))); else - print("final var " + Names.decode(getName(name)))*; - print(": " + getType(tpe) + ";").newline*; + print("final var " + Names.decode(getName(name))); + print(": " + getType(tpe) + ";").newline; } def printMethod(flags: Int, name: Int, tpe: Int, attribs: List[cf.Attribute]) = { @@ -116,7 +116,6 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer case cf.Attribute(name, _) => getName(name) == "JacoMeta" } match { case Some(cf.Attribute(_, data)) => - Console.println(data.length); val mp = new MetaParser(getName( ((data(0) & 0xff) << 8) + (data(1) & 0xff)).trim()); mp.parse match { @@ -135,28 +134,48 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer } case None => if (getName(name) == "<init>") { - print("def this" + getType(tpe) + ";").newline*; + print("def this" + getType(tpe) + ";").newline; } else { - print("def " + Names.decode(getName(name)))*; - print(getType(tpe) + ";").newline*; + print("def " + Names.decode(getName(name))); + print(getType(tpe) + ";").newline; } } } - def printClass = { - val pck = getPackage(cf.classname); - if (pck.length() > 0) - println("package " + pck + ";"); - print(flagsToStr(true, cf.flags))*; + def printClassHeader = { if (isInterface(cf.flags)) { - print("trait " + getSimpleClassName(cf.classname))*; + print("trait " + getSimpleClassName(cf.classname)); } else { - print("class " + getSimpleClassName(cf.classname))*; + print("class " + getSimpleClassName(cf.classname)); if (cf.pool(cf.superclass) != null) - print(" extends " + getClassName(cf.superclass))*; + print(" extends " + getClassName(cf.superclass)); } cf.interfaces foreach { - n => print(" with " + getClassName(n))*; + n => print(" with " + getClassName(n)); + } + } + + def printClass = { + val pck = getPackage(cf.classname); + if (pck.length() > 0) + println("package " + pck + ";"); + print(flagsToStr(true, cf.flags)); + cf.attribs find { + case cf.Attribute(name, _) => getName(name) == "JacoMeta" + } match { + case None => + printClassHeader; + case Some(cf.Attribute(_, data)) => + val mp = new MetaParser(getName( + ((data(0) & 0xff) << 8) + (data(1) & 0xff)).trim()); + mp.parse match { + case None => printClassHeader; + case Some(str) => + if (isInterface(cf.flags)) + print("trait " + getSimpleClassName(cf.classname) + str); + else + print("class " + getSimpleClassName(cf.classname) + str); + } } var statics: List[cf.Member] = Nil; print(" {").indent.newline; @@ -174,9 +193,9 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer else printMethod(flags, name, tpe, attribs) } - undent.print("}").newline*; + undent.print("}").newline; if (!statics.isEmpty) { - print("object " + getSimpleClassName(cf.classname) + " {")*; + print("object " + getSimpleClassName(cf.classname) + " {"); indent.newline; statics foreach { case cf.Member(true, flags, name, tpe, attribs) => @@ -185,7 +204,7 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer if (getName(name) != "<clinit>") printMethod(flags, name, tpe, attribs) } - undent.print("}").newline* + undent.print("}").newline } } } diff --git a/sources/scala/tools/scalap/Main.scala b/sources/scala/tools/scalap/Main.scala index 203a9d427f..5ca1f8e06b 100644 --- a/sources/scala/tools/scalap/Main.scala +++ b/sources/scala/tools/scalap/Main.scala @@ -9,15 +9,25 @@ package scala.tools.scalap; import java.io._; -import scala.collection._; +/** The main object used to execute scalap on the command-line. + * + * @author Matthias Zenger + * @version 1.0, 10/02/2004 + */ object Main { - val VERSION = "1.0a"; + /** The version number. + */ + val VERSION = "1.0.1"; + /** Verbose program run? + */ var verbose = false; + /** Prints usage information for scalap. + */ def usage: Unit = { Console.println("usage: scalap {<option>} <name>"); Console.println("where <option> is"); @@ -29,32 +39,50 @@ object Main { Console.println(" -cp <pathlist> specify where to find user class files"); } + /** Executes scalap with the given arguments and classpath for the + * class denoted by 'classname'. + */ def process(args: Arguments, path: ClassPath)(classname: String): Unit = { + // find the classfile val file = path.openClass(Names.encode( - if (classname == "scala.AnyRef") "java.lang.Object" else classname)); + if (classname == "scala.AnyRef") "java.lang.Object" + else classname)); + // if the classfile exists... if (file.exists) { if (verbose) Console.println(Console.BOLD + "FILENAME" + Console.RESET + " = " + file.getPath); + // construct a reader for the classfile content val reader = new ByteArrayReader(file.content); + // parse the classfile val clazz = new Classfile(reader); + // check if there is a Scala signature attribute val attrib = clazz.attribs.find(a => a.toString() == "ScalaSignature"); attrib match { + // if the attribute is found, we have to extract the scope + // from the attribute case Some(a) => + // parse the Scala attribute val info = new ScalaAttribute(a.reader); val symtab = new EntityTable(info); + // construct a new output stream writer val out = new OutputStreamWriter(System.out); val writer = new ScalaWriter(args, out); + // output all elements of the scope symtab.root.elements foreach ( sym => { writer.printSymbol(sym); writer.println*; }); out.flush(); + // It must be a Java class case None => + // construct a new output stream writer val out = new OutputStreamWriter(System.out); val writer = new JavaWriter(clazz, out); + // print the class writer.printClass; out.flush(); } + // if the class corresponds to the artificial class scala.Any... } else if (classname == "scala.Any") { Console.println("package scala;"); Console.println("class Any {"); @@ -68,17 +96,26 @@ object Main { Console.println(" final def asInstanceOf[T]: T;"); Console.println(" def match[S, T](f: S => T): T;"); Console.println("}"); + // explain that scala.All cannot be printed... } else if (classname == "scala.All") { - Console.println("Type scala.All is artificial; it is a subtype of all types."); + Console.println("Type scala.All is artificial; " + + "it is a subtype of all types."); + // explain that scala.AllRef cannot be printed... } else if (classname == "scala.AllRef") { - Console.println("Type scala.AllRef is artificial; it is a subtype of all subtypes of scala.AnyRef."); + Console.println("Type scala.AllRef is artificial; it is a " + + "subtype of all subtypes of scala.AnyRef."); + // at this point we are sure that the classfile is not available... } else Console.println("class/object not found."); } + /** The main method of this object. + */ def main(args: Array[String]) = { + // print usage information if there is no command-line argument if (args.length == 0) usage; + // otherwise parse the arguments... else { val arguments = Arguments.Parser('-') .withOption("-private") @@ -93,6 +130,7 @@ object Main { if (arguments contains "-help") usage; verbose = arguments contains "-verbose"; + // construct a custom class path val path = arguments.getArgument("-classpath") match { case None => arguments.getArgument("-cp") match { case None => new ClassPath @@ -100,9 +138,11 @@ object Main { } case Some(path) => new ClassPath { override val classPath = path } } + // print the classpath if output is verbose if (verbose) Console.println(Console.BOLD + "CLASSPATH" + Console.RESET + " = " + path); + // process all given classes arguments.getOthers.foreach(process(arguments, path)); } } diff --git a/sources/scala/tools/scalap/ScalaWriter.scala b/sources/scala/tools/scalap/ScalaWriter.scala index 58009682e9..4a7b14ddb3 100644 --- a/sources/scala/tools/scalap/ScalaWriter.scala +++ b/sources/scala/tools/scalap/ScalaWriter.scala @@ -8,39 +8,104 @@ package scala.tools.scalap; -import java.io._; -import scala.collection.mutable._; +import java.io.Writer; +import scala.collection.mutable.Buffer; class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) { - def printFlags(flags: Int): Unit = { - val buffer = new StringBuffer(); - var x: StringBuffer = buffer; - if (Flags.isPrivate(flags)) - x = buffer.append("private "); - if (Flags.isProtected(flags)) - x = buffer.append("protected "); - if (Flags.isAbstract(flags) && !Flags.isTrait(flags)) - x = buffer.append("abstract "); - if (Flags.isFinal(flags) && !Flags.isObj(flags)) - x = buffer.append("final "); - if (Flags.isSealed(flags)) - x = buffer.append("sealed "); - if (Flags.isCase(flags)) - x = buffer.append("case "); - if (Flags.isDef(flags)) - x = buffer.append("def "); - if (Flags.isOverride(flags)) - x = buffer.append("override "); - print(buffer.toString())* + def printSymbol(sym: Symbol): Unit = sym match { + case NoSymbol => + print("<nosymbol>") + case s: TypeSymbol => + printFlags(s); + print("type "); + printTVar(s); + case s: AliasSymbol => + printFlags(s); + print("type " + s.name + " = "); + printType(s.tpe); + case s: ClassSymbol => + printFlags(s); + if (Flags.is(Flags.DEFERRED, s.flags)) + print("/*deferred*/ "); + if (Flags.is(Flags.OBJECT, s.flags)) + print("object " + s.name); + else if (Flags.is(Flags.TRAIT, s.flags)) + print("trait " + s.name); + else + print("class " + s.name); + printConstr(s.constr); + print(" extends "); + printType(s.tpe); + case s: ValSymbol => + s.tpe match { + case PolyType(tpe, Nil) => + printFlags(s); + print("def " + s.name + ": "); + printType(tpe); + case PolyType(_, _) => + printFlags(s); + print("def " + s.name); + printType(s.tpe); + case MethodType(_, _) => + printFlags(s); + print("def " + s.name); + printType(s.tpe); + case _ => + printFlags(s); + print("val " + s.name + ": "); + printType(s.tpe); + } + case s: ExternalSymbol => + print("<externalsymbol: " + s.fullname + ">") + } + + def printConstr(sym: Symbol): Unit = sym match { + case s: ValSymbol => + s.tpe match { + case PolyType(MethodType(argtpes, _), tvars) => + print("["); + if (!tvars.isEmpty) { + printTVar(tvars.head); + tvars.tail foreach { sym => + print(", "); + printTVar(sym); + } + } + print("]"); + printTypes(argtpes, "(", ", ", ")"); + case MethodType(argtpes, _) => + printTypes(argtpes, "(", ", ", ")"); + case _ => + } + } + + def printScope(scope: Buffer[Symbol]): Unit = { + var first = true; + scope.elements foreach ( + sym => { sym match { + case s: ValSymbol if + (s.tpe.isInstanceOf[OverloadedType] || + (Flags.is(Flags.CASEACCESSOR, s.flags) && + !s.tpe.isInstanceOf[PolyType])) => + case _ => + if (!ignoreDef(sym)) { + if (first) print(" {").indent else print(";"); + first = false; + newline; + printSymbol(sym); + } + }}); + if (!first) + newline.undent.print("}") } def printType(tpe: Type): Unit = { printType0(tpe); tpe match { - case ThisType(_) => print(".type")* - case SingletonType(_, _) => print(".type")* + case ThisType(_) => print(".type") + case SingletonType(_, _) => print(".type") case _ => } } @@ -50,28 +115,19 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) { printTypes0(tpes, begin, infix, end); } - def printTypes0(tpes: List[Type], begin: String, infix: String, end: String): Unit = { - print(begin)*; - if (!tpes.isEmpty) { - printType(tpes.head); - tpes.tail foreach (t => { print(infix)*; printType(t) }); - } - print(end)*; - } - def printType0(tpe: Type): Unit = tpe match { case NoType => case ThisType(sym) => sym match { - case x: ExternalSymbol => print(sym.fullname)* - case NoSymbol => print("this")* - case _ => print(sym.fullname).print(".this")* + case x: ExternalSymbol => print(sym.fullname) + case NoSymbol => print("this") + case _ => print(sym.fullname).print(".this") } case SingletonType(tpe, sym) => printPrefix(tpe); - print(sym.name)* + print(sym.name) case TypeRef(tpe, sym, args) => printPrefix(tpe); - print(sym.name)*; + print(sym.name); printTypes(args, "[", ", ", "]"); case CompoundType(clazz, components) => printTypes(components, "", " with ", ""); @@ -86,15 +142,15 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) { tpe0 = restpe; } } - print(":").newspace*; + print(":").newspace; printType(tpe0); case PolyType(tpe, tvars) => - print("[")*; + print("["); if (!tvars.isEmpty) { printTVar(tvars.head); - tvars.tail foreach (sym => {print(", ")*; printTVar(sym);}); + tvars.tail foreach (sym => {print(", "); printTVar(sym);}); } - print("]")*; + print("]"); printType(tpe); case OverloadedType(_, tpes) => printTypes(tpes, "", " <and> ", ""); @@ -102,16 +158,25 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) { printType(base); print("(" + num + ")"); case TypeFlag(TypeRef(_, _, List(tpe0)), flags) => - if ((flags & 8) != 0) - print("def ")*; + if (Flags.is(Flags.TF_DEF, flags)) + print("def "); printType(tpe0); - if ((flags & 4) != 0) - print("*")*; + if (Flags.is(Flags.TF_STAR, flags)) + print("*"); case TypeFlag(tpe0, flags) => - if ((flags & 8) != 0) - print("def ")*; + if (Flags.is(Flags.TF_DEF, flags)) + print("def "); printType(tpe0); - case _ => print("<unknown type>")*; + case _ => print("<unknown type>"); + } + + def printTypes0(tpes: List[Type], begin: String, infix: String, end: String): Unit = { + print(begin); + if (!tpes.isEmpty) { + printType(tpes.head); + tpes.tail foreach (t => { print(infix); printType(t) }); + } + print(end); } def printPrefix(tpe: Type): Unit = tpe match { @@ -121,28 +186,38 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) { if ((sym.name.length() != 0) && ("<root>" != sym.name)) { printType0(tpe); - print(".")* + print(".") + } + case SingletonType(_, sym) => + if ((sym.name.length() != 0) && + ("<root>" != sym.name)) { + printType0(tpe); + print(".") } case TypeRef(_, _, _) => printType0(tpe); - print("#")* + print("#") case _ => + Console.println(tpe.getClass()); printType0(tpe); - print(".")* + print(".") } def printTVar(tvar: Symbol): Unit = tvar match { - case sym: TypeSymbol => print(sym.name); - if (!isExternalType(sym.tpe, "Any")) { - print(" <: ")*; - printType(sym.tpe); - } - if (!isExternalType(sym.lower, "All")) { - print(" >: ")*; - printType(sym.lower); - } + case sym: TypeSymbol => + print(sym.name); + if (!isExternalType(sym.tpe, "Any")) { + print(" <: ")*; + printType(sym.tpe); + } + if (!isExternalType(sym.lower, "All")) { + print(" >: ")*; + printType(sym.lower); + } } + def printFlags(sym: Symbol) = print(Flags.toString(sym.flags)); + def isExternalType(tpe: Type, name: String): Boolean = tpe match { case TypeRef(SingletonType(ThisType(root), pck), sym, Nil) => (root.name.length() == 0) && @@ -151,94 +226,9 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) { case _ => false } - def printSymbol(sym: Symbol): Unit = sym match { - case NoSymbol => - print("<nosymbol>")* - case s: TypeSymbol => - print(Flags.toString(s.flags))*; - print("type ")*; - printTVar(s); - case s: AliasSymbol => - print(Flags.toString(s.flags))*; - print("type " + s.name + " = ")*; - printType(s.tpe); - case s: ClassSymbol => - print(Flags.toString(s.flags))*; - if (Flags.isDeferred(s.flags)) - print("/*deferred*/ ")*; - if (Flags.isObj(s.flags)) - print("object " + s.name); - else if (Flags.isTrait(s.flags)) - print("trait " + s.name)*; - else - print("class " + s.name)*; - printConstr(s.constr); - print(" extends "); - printType(s.tpe); - case s: ValSymbol => - s.tpe match { - case PolyType(tpe, Nil) => - print(Flags.toString(s.flags))*; - print("def " + s.name + ": ")*; - printType(tpe); - case PolyType(_, _) => - print(Flags.toString(s.flags))*; - print("def " + s.name)*; - printType(s.tpe); - case MethodType(_, _) => - print(Flags.toString(s.flags))*; - print("def " + s.name)*; - printType(s.tpe); - case _ => - print(Flags.toString(s.flags))*; - print("val " + s.name + ": ")*; - printType(s.tpe); - } - case s: ExternalSymbol => - print("<externalsymbol: " + s.fullname + ">")* - } - - def printConstr(sym: Symbol): Unit = sym match { - case s: ValSymbol => - s.tpe match { - case PolyType(MethodType(argtpes, _), tvars) => - print("[")*; - if (!tvars.isEmpty) { - printTVar(tvars.head); - tvars.tail foreach (sym => {print(", ")*; printTVar(sym);}); - } - print("]")*; - printTypes(argtpes, "(", ", ", ")"); - case MethodType(argtpes, _) => - printTypes(argtpes, "(", ", ", ")"); - case _ => - } - } - - def ignoreDef(s: Symbol) = { - (Flags.isPrivate(s.flags) && + def ignoreDef(s: Symbol) = + (Flags.is(Flags.PRIVATE, s.flags) && !((args != null) && (args contains "-private"))) || (s.name == "<init>") || - Flags.isCaseAccessor(s.flags) - } - - def printScope(scope: Buffer[Symbol]): Unit = { - var first = true; - scope.elements foreach ( - sym => { sym match { - case s: ValSymbol if - (s.tpe.isInstanceOf[OverloadedType] || - (Flags.isCaseAccessor(s.flags) && - !s.tpe.isInstanceOf[PolyType])) => - case _ => - if (!ignoreDef(sym)) { - if (first) print(" {").indent* else print(";")*; - first = false; - newline*; - printSymbol(sym); - } - }}); - if (!first) - newline.undent.print("}")* - } + Flags.is(Flags.CASEACCESSOR, s.flags); } |