diff options
author | michelou <michelou@epfl.ch> | 2006-10-05 17:20:12 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2006-10-05 17:20:12 +0000 |
commit | c23c5ee74c0d020cebb3dbb9afd8284508bed1a1 (patch) | |
tree | c528eff31c374746c0b441d42bdb9437d0983f61 /src | |
parent | 9c0102e5689bebb56e3ec1308123875102c68d25 (diff) | |
download | scala-c23c5ee74c0d020cebb3dbb9afd8284508bed1a1.tar.gz scala-c23c5ee74c0d020cebb3dbb9afd8284508bed1a1.tar.bz2 scala-c23c5ee74c0d020cebb3dbb9afd8284508bed1a1.zip |
fixed method toString in class symtab.ConstantType
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/DocGenerator.scala | 75 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Constants.scala | 60 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Types.scala | 12 |
3 files changed, 95 insertions, 52 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/DocGenerator.scala b/src/compiler/scala/tools/nsc/doc/DocGenerator.scala index 2364111cb5..4ee929d24b 100644 --- a/src/compiler/scala/tools/nsc/doc/DocGenerator.scala +++ b/src/compiler/scala/tools/nsc/doc/DocGenerator.scala @@ -81,6 +81,11 @@ abstract class DocGenerator extends Models { Text(tree.symbol.toString()) } + /** + * @param tpe ... + * @param target ... + * @return ... + */ def urlFor(tpe: Type, target: String): NodeSeq = try { if (tpe.symbol hasFlag Flags.JAVA) <a class={tpe.toString().replace('.', '_')} href="" @@ -96,22 +101,22 @@ abstract class DocGenerator extends Models { } def urlFor0(sym: Symbol, orig: Symbol): String = { - (if (sym == NoSymbol) { - "XXX"; - } else if (sym.owner.isPackageClass) sym.fullNameString('/'); - else urlFor0(sym.owner, orig) + "." + Utility.escape(sym.nameString)) + (sym match { - case msym: ModuleSymbol => - if (msym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE - else NAME_SUFFIX_OBJECT - case csym: ClassSymbol => - if (csym.isModuleClass) { - if (csym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE + (if (sym == NoSymbol) "XXX" + else if (sym.owner.isPackageClass) sym.fullNameString('/') + else urlFor0(sym.owner, orig) + "." + Utility.escape(sym.nameString)) + + (sym match { + case msym: ModuleSymbol => + if (msym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE else NAME_SUFFIX_OBJECT - } - else "" - case _ => - //System.err.println("XXX: class or object " + orig + " not found in " + sym) - "XXXXX" + case csym: ClassSymbol => + if (csym.isModuleClass) { + if (csym hasFlag Flags.PACKAGE) NAME_SUFFIX_PACKAGE + else NAME_SUFFIX_OBJECT + } + else "" + case _ => + //System.err.println("XXX: class or object " + orig + " not found in " + sym) + "XXXXX" }) } @@ -261,6 +266,10 @@ abstract class DocGenerator extends Models { br(res.concat(Text("]"))) } + /** + * @param mmbr ... + * @return ... + */ def fullHeader(mmbr: HasTree): NodeSeq = <span>{ { if (!mmbr.isInstanceOf[ImplMod]) { <a name = {Utility.escape(mmbr.tree.symbol.nameString)}></a>; @@ -296,7 +305,7 @@ abstract class DocGenerator extends Models { <tr><td colspan="2" class="title">{Text(labelFor(kind))} Summary</td></tr> { { for (val mmbr <- map(kind).toList) yield - shortHeader(mmbr); + shortHeader(mmbr) } } </table>; br(x); @@ -334,6 +343,10 @@ abstract class DocGenerator extends Models { } else NodeSeq.Empty + /** + * @param mmbr ... + * @return ... + */ def shortHeader(mmbr: HasTree): NodeSeq = { <tr> <td valign="top" class="modifiers"> @@ -367,7 +380,7 @@ abstract class DocGenerator extends Models { def ifT(tree: Tree, nodes: NodeSeq, before: Boolean) = if (tree != EmptyTree && - tree.tpe.symbol != definitions.AnyClass && + tree.tpe.symbol != definitions.AnyClass && tree.tpe.symbol != definitions.AllClass) { if (before) nodes.concat(forTree(tree)) else { @@ -382,12 +395,12 @@ abstract class DocGenerator extends Models { def forTree(tree: Tree): NodeSeq = tree match { case vdef: ValDef => - Text(vdef.symbol.name.toString()).concat(Text(" : ")).concat(forTree(vdef.tpt)); + Text(vdef.symbol.name.toString()).concat(Text(": ")).concat(forTree(vdef.tpt)) case sel: Select => forTree(sel.qualifier).concat(Text(sel.symbol.nameString)) case tree: AbsTypeDef => ifT(tree.lo, Text(" <: "), false). - concat(Text(tree.symbol.nameString)).concat(ifT(tree.hi, Text(" <: "), true)); + concat(Text(tree.symbol.nameString)).concat(ifT(tree.hi, Text(" <: "), true)) case tpt: TypeTree => urlFor(tpt.tpe, contentFrame) case id: Ident => @@ -398,6 +411,10 @@ abstract class DocGenerator extends Models { Text("XX=" + tree.getClass() + " " + tree.toString()) } + /** + * @param trees ... + * @return ... + */ def forTrees(trees: List[Tree]): NodeSeq = if (trees.isEmpty) NodeSeq.Empty else { @@ -406,14 +423,14 @@ abstract class DocGenerator extends Models { else Text(", ")).concat(forTrees(trees.tail)) } - def surround(open: String, close: String, node: NodeSeq): NodeSeq = + private def surround(open: String, close: String, node: NodeSeq): NodeSeq = Text(open).concat(node).concat(Text(close)) /** * @param ht ... * @return ... */ - def typesFor(ht: HasTree): NodeSeq = { + private def typesFor(ht: HasTree): NodeSeq = { val tparams = ht.tree match { case cdef: ClassDef => cdef.tparams case ddef: DefDef => ddef.tparams @@ -424,21 +441,29 @@ abstract class DocGenerator extends Models { else surround("[", "]", forTrees(tparams)) } - def argsFor(ht: HasTree): NodeSeq = ht.tree match { + /** + * @param ht ... + * @return ... + */ + private def argsFor(ht: HasTree): NodeSeq = ht.tree match { case ddef: DefDef => if (!ddef.vparamss.isEmpty && (!ddef.vparamss.tail.isEmpty || !ddef.vparamss.head.isEmpty)) { val nodes = for (val vparams <- ddef.vparamss) yield surround("(", ")", forTrees(vparams)); - nodes.flatMap(x => x.toList); + nodes.flatMap(x => x.toList) } else NodeSeq.Empty case _ => NodeSeq.Empty } - def resultFor(ht: HasTree): NodeSeq = ht.tree match { + /** + * @param ht ... + * @return ... + */ + private def resultFor(ht: HasTree): NodeSeq = ht.tree match { case vdef: ValOrDefDef => if (!vdef.symbol.nameString.equals("this")) - Text(" : ").concat(forTree(vdef.tpt)) + Text(": ").concat(forTree(vdef.tpt)) else NodeSeq.Empty case _ => diff --git a/src/compiler/scala/tools/nsc/symtab/Constants.scala b/src/compiler/scala/tools/nsc/symtab/Constants.scala index cdca0502da..f86f68cf7a 100644 --- a/src/compiler/scala/tools/nsc/symtab/Constants.scala +++ b/src/compiler/scala/tools/nsc/symtab/Constants.scala @@ -1,32 +1,32 @@ -/* NSC -- new scala compiler - * Copyright 2005 LAMP/EPFL +/* NSC -- new Scala compiler + * Copyright 2005-2006 LAMP/EPFL * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.symtab; +package scala.tools.nsc.symtab -import classfile.PickleFormat._; +import classfile.PickleFormat._ trait Constants requires SymbolTable { - import definitions._; + import definitions._ final val NoTag = LITERAL - LITERAL - final val UnitTag = LITERALunit - LITERAL; - final val BooleanTag = LITERALboolean - LITERAL; - final val ByteTag = LITERALbyte - LITERAL; - final val ShortTag = LITERALshort - LITERAL; - final val CharTag = LITERALchar - LITERAL; - final val IntTag = LITERALint - LITERAL; - final val LongTag = LITERALlong - LITERAL; - final val FloatTag = LITERALfloat - LITERAL; - final val DoubleTag = LITERALdouble - LITERAL; - final val StringTag = LITERALstring - LITERAL; - final val NullTag = LITERALnull - LITERAL; - final val ClassTag = LITERALclass - LITERAL; - final val EnumTag = ClassTag + 1; - final val ArrayTag = EnumTag + 1; + final val UnitTag = LITERALunit - LITERAL + final val BooleanTag = LITERALboolean - LITERAL + final val ByteTag = LITERALbyte - LITERAL + final val ShortTag = LITERALshort - LITERAL + final val CharTag = LITERALchar - LITERAL + final val IntTag = LITERALint - LITERAL + final val LongTag = LITERALlong - LITERAL + final val FloatTag = LITERALfloat - LITERAL + final val DoubleTag = LITERALdouble - LITERAL + final val StringTag = LITERALstring - LITERAL + final val NullTag = LITERALnull - LITERAL + final val ClassTag = LITERALclass - LITERAL + final val EnumTag = ClassTag + 1 + final val ArrayTag = EnumTag + 1 def isNumeric(tag: int) = ByteTag <= tag && tag <= DoubleTag @@ -47,7 +47,7 @@ trait Constants requires SymbolTable { else if (value.isInstanceOf[Symbol]) EnumTag else if (value.isInstanceOf[Array[Constant]]) ArrayTag else if (value == null) NullTag - else throw new Error("bad constant value: " + value); + else throw new Error("bad constant value: " + value) def tpe: Type = tag match { case UnitTag => UnitClass.tpe @@ -65,7 +65,11 @@ trait Constants requires SymbolTable { case EnumTag => symbolValue.owner.linkedClassOfClass.tpe } - /** We need the equals method to take account of tags as well as values */ + /** We need the equals method to take account of tags as well as values. + * + * @param other ... + * @return ... + */ override def equals(other: Any): boolean = other match { case that: Constant => this.value == that.value && this.tag == that.tag case _ => false @@ -152,9 +156,13 @@ trait Constants requires SymbolTable { case _ => throw new Error("value " + value + " is not a double") } - /** Convert constant value to conform to given type */ + /** Convert constant value to conform to given type. + * + * @param pt ... + * @return ... + */ def convertTo(pt: Type): Constant = { - val target = pt.symbol; + val target = pt.symbol if (target == tpe.symbol) this else if (target == ByteClass && ByteTag <= tag && tag <= IntTag && @@ -182,17 +190,17 @@ trait Constants requires SymbolTable { def stringValue: String = if (value == null) "null" else if (tag == ClassTag) signature(typeValue) - else value.toString(); + else value.toString() def typeValue: Type = value.asInstanceOf[Type] def symbolValue: Symbol = value.asInstanceOf[Symbol] def arrayValue: Array[Constant] = - throw new Error("value " + value + " is not an array"); + throw new Error("value " + value + " is not an array") override def hashCode(): int = - if (value == null) 0 else value.hashCode() * 41 + 17; + if (value == null) 0 else value.hashCode() * 41 + 17 } class ArrayConstant(override val arrayValue: Array[Constant], diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 8eaf84a0b4..a3d466db56 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -838,7 +838,17 @@ trait Types requires SymbolTable { override def symbol: Symbol = value.tpe.symbol override def singleDeref: Type = value.tpe override def deconst: Type = value.tpe - override def toString(): String = value.tpe.toString() + "(" + value.stringValue + ")" + private def escape(text: String): String = { + val buf = new StringBuffer + for (val c <- Iterator.fromString(text)) + if (Character.isISOControl(c)) + buf.append("\\0" + Integer.toOctalString(c.asInstanceOf[Int])) + else + buf.append(c) + buf.toString + } + override def toString(): String = + value.tpe.toString() + "(\"" + escape(value.stringValue) + "\")" // override def isNullable: boolean = value.value == null // override def isNonNull: boolean = value.value != null } |