diff options
author | paltherr <paltherr@epfl.ch> | 2003-05-09 15:28:18 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2003-05-09 15:28:18 +0000 |
commit | 52874b143e7599d268df80e220eac4964c20b201 (patch) | |
tree | 0bf1d8474c2d7433fb4b99f9fde1e461a9a8ca69 /sources/scalac | |
parent | bbb471bf1afb636ff554ddb0ba4c2bc04bab53b2 (diff) | |
download | scala-52874b143e7599d268df80e220eac4964c20b201.tar.gz scala-52874b143e7599d268df80e220eac4964c20b201.tar.bz2 scala-52874b143e7599d268df80e220eac4964c20b201.zip |
- Removed code that is now in class SymbolTable...
- Removed code that is now in class SymbolTablePrinter Changed some
- toString methods to use SymbolTablePrinter
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/Global.java | 4 | ||||
-rw-r--r-- | sources/scalac/symtab/Scope.java | 18 | ||||
-rw-r--r-- | sources/scalac/symtab/Symbol.java | 86 | ||||
-rw-r--r-- | sources/scalac/symtab/Type.java | 130 |
4 files changed, 6 insertions, 232 deletions
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java index 9ba64c6c47..626d9f517f 100644 --- a/sources/scalac/Global.java +++ b/sources/scalac/Global.java @@ -430,11 +430,11 @@ public class Global { } private String show(Symbol symbol) { - return symbol.defString(); + return new SymbolTablePrinter(" ").printSignature(symbol).toString(); } private String show(Type type) { - return type.toString(); + return new SymbolTablePrinter(" ").printType(type).toString(); } /* diff --git a/sources/scalac/symtab/Scope.java b/sources/scalac/symtab/Scope.java index 7874e4303d..6c707f43c4 100644 --- a/sources/scalac/symtab/Scope.java +++ b/sources/scalac/symtab/Scope.java @@ -301,23 +301,7 @@ public class Scope { } public String toString() { - StringBuffer str = new StringBuffer("{"); - SymbolIterator it = iterator(); - while (it.hasNext()) { - str.append("\n " + it.next().defString()); - } - str.append("}"); - return str.toString(); - } - - public String simpleToString() { - StringBuffer str = new StringBuffer("{"); - SymbolIterator it = iterator(); - while (it.hasNext()) { - str.append("\n " + it.next().name); - } - str.append("}"); - return str.toString(); + return new SymbolTablePrinter().printScope(this).toString(); } public static Scope EMPTY = new Scope(); diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index 1d248a4920..181edac352 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -733,24 +733,11 @@ public abstract class Symbol implements Modifiers, Kinds { return NameTransformer.decode(fullName()).toString(); } - public String idString() { - if (Global.instance.uniqid && - (kind == TYPE || Global.instance.debug)) - return "#" + Global.instance.uniqueID.id(this); - else return ""; - } - /** String representation, including symbol's kind * e.g., "class Foo", "function Bar". */ public String toString() { - if (isRoot()) return "<root package>"; - String kstr = kindString(); - String str; - if (isAnonymousClass()) str = "<template>"; - else if (kstr.length() == 0) str = fullNameString(); - else str = kstr + " " + fullNameString(); - return str + idString(); + return new SymbolTablePrinter().printSymbol(this).toString(); } /** String representation of location. @@ -765,22 +752,7 @@ public abstract class Symbol implements Modifiers, Kinds { /** String representation of definition. */ public String defString() { - StringBuffer buffer = new StringBuffer(); - if (!isParameter()) buffer.append(defKeyword()).append(' '); - String name = nameString(); - if (!Global.instance.debug) { - int index = name.indexOf('$'); - if (index > 0) name = name.substring(0, index); - } - buffer.append(name).append(idString()).append(innerString()); - if (rawInfoAt(Global.instance.POST_ANALYZER_PHASE_ID) - instanceof Type.LazyType) - buffer.append("?"); - else if (isInitializedMethod()) - buffer.append(info().defString()); - else - buffer.append(info()); - return buffer.toString(); + return new SymbolTablePrinter().printSignature(this).toString(); } public static String[] defString(Symbol[] defs) { @@ -790,60 +762,6 @@ public abstract class Symbol implements Modifiers, Kinds { return strs; } - private String innerString() { - switch (kind) { - case Kinds.ERROR: return ": "; - case Kinds.NONE : return ": "; - case Kinds.ALIAS: return " = "; - case Kinds.CLASS: return " extends "; - case Kinds.TYPE : return " <: "; - case Kinds.VAL : return isModule() ? "extends" : - isInitializedMethod() ? "" : ": "; - default : throw Debug.abort("illegal case: " + kind); - } - } - - /** String representation of kind */ - public String kindString() { - switch (kind) { - case CLASS: - if ((flags & TRAIT) != 0) - return "trait"; - else if ((flags & MODUL) != 0 && Global.instance.debug) - return "object class"; - else - return "class"; - case TYPE: - case ALIAS: - return "type"; - case VAL: - if (isVariable()) return "variable"; - else if (isModule()) return "object"; - else if (isConstructor()) return "constructor"; - else if (isInitializedMethod() && - (Global.instance.debug || (flags & STABLE) == 0) ) - return "method"; - else return "value"; - default: return ""; - } - } - - /** Definition keyword of kind - */ - public String defKeyword() { - switch (kind) { - case CLASS: if ((flags & TRAIT) != 0) return "trait"; else return "class"; - case TYPE: - case ALIAS: return "type"; - case VAL: - if (isVariable()) return "var"; - else if (isModule()) return "object"; - else if (isInitializedMethod()) return "def"; - else return "val"; - default: return ""; - } - } - // Overloading and Overriding ------------------------------------------- /** Add another overloaded alternative to this symbol. diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index f98be55b21..f201027d75 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -2069,90 +2069,7 @@ public class Type implements Modifiers, Kinds, TypeTags { // Object Interface ----------------------------------------------------------------- public String toString() { - switch (this) { - case ErrorType: - return "<error>"; - case AnyType: - return "<any type>"; - case NoType: - return "<notype>"; - case ThisType(Symbol sym): - if (sym.isRoot()) return "<root>.this.type"; - else if (this == localThisType) return "<local>.this.type"; - else if (sym.isAnonymousClass()) return "this.type"; - else { - Type this1 = (Global.instance.debug) ? this : expandModuleThis(); - if (this1 == this) return sym.nameString() + ".this.type"; - else return this1.toString(); - } - case TypeRef(Type pre, Symbol sym, Type[] args): - if (sym.isRoot()) return "<root>"; - if (!Global.instance.debug) { - if (isFunctionType()) { - Type[] params = new Type[args.length - 1]; - System.arraycopy(args, 0, params, 0, params.length); - return ArrayApply.toString(params, "(", ",", ") => ") + - args[params.length]; - } else if (sym.isAnonymousClass()) { - return "<template: " + - ArrayApply.toString( - pre.memberInfo(sym).parents(), "", "", " with ") + - "{...}>"; - } - } - Type pre1 = (Global.instance.debug) ? pre : pre.expandModuleThis(); - String result = pre1.prefixString() + sym.nameString() + sym.idString(); - if (args.length != 0) - result = result + ArrayApply.toString(args, "[", ",", "]"); - return result; - case SingleType(Type pre, Symbol sym): - if ((sym.flags & SYNTHETIC) != 0 && !Global.instance.debug) - return widen().toString(); - if (sym.isRoot()) return "<root>.type"; - Type pre1 = (Global.instance.debug) ? pre : pre.expandModuleThis(); - return pre1.prefixString() + sym.nameString() + sym.idString() + ".type"; - case CompoundType(Type[] parts, Scope members): - validate();//debug - if (!Global.instance.debug && isFunctionType()) - return parts[1].toString(); - StringBuffer buf = new StringBuffer(); - if (parts.length > 0) { - buf.append(parts[0].toString()); - int i = 1; - while (i < parts.length) { - buf.append(" with "); - buf.append(parts[i].toString()); - i++; - } - } - boolean first = true; - for (Scope.SymbolIterator it = members.iterator(); it.hasNext(); ) { - Symbol sym = it.next(); - buf.append(first ? " with {" : ", "); - first = false; - buf.append(sym.defString()); - } - if (!first) buf.append("}"); - return buf.toString(); - case MethodType(Symbol[] vparams, Type result): - return ArrayApply.toString(paramTypeString(vparams), "(", ",", ")") + result; - case PolyType(Symbol[] tparams, Type result): - return ArrayApply.toString(Symbol.defString(tparams), "[", ",", "]") + - result; - case OverloadedType(Symbol[] alts, Type[] alttypes): - return ArrayApply.toString(alttypes, "", " <and> ", ""); - case TypeVar(Type origin, Constraint constr): - if (constr.inst != NoType) return constr.inst.toString(); - else return origin + "?"; - case UnboxedType(int kind): - return unboxedName(kind).toString(); - case UnboxedArrayType(Type elemtp): - return elemtp.toString() + "[]"; - case LazyType(): - return "<lazy type " + getClass() + ">"; - default: - return "<unknown type " + getClass() + ">"; - } + return new SymbolTablePrinter().printType(this).toString(); } public String toLongString() { @@ -2161,51 +2078,6 @@ public class Type implements Modifiers, Kinds, TypeTags { else return str; } - // used by Symbol.defString - String defString() { - StringBuffer buffer = new StringBuffer(); - switch (this) { - case MethodType(Symbol[] vparams, Type result): - buffer.append( - ArrayApply.toString(paramTypeString(vparams), "(", ",", ")")); - return buffer.append(result.defString()).toString(); - case PolyType(Symbol[] tparams, Type result): - if (tparams.length != 0) buffer.append( - ArrayApply.toString(Symbol.defString(tparams), "[", ",", "]")); - return buffer.append(result.defString()).toString(); - default: - return buffer.append(": ").append(this).toString(); - } - } - - private String prefixString() { - if ((symbol().kind == NONE || symbol().isRoot()) && !Global.instance.debug) { - return ""; - } else { - String spre = toString(); - if (spre.length() == 0) - return ""; - else if (spre.endsWith(".type")) - return spre.substring(0, spre.length() - 4); - else - return spre + "#"; - } - } - - private String[] paramTypeString(Symbol[] vparams) { - String[] ss = new String[vparams.length]; - for (int i = 0; i < ss.length; i++) { - Type tp = vparams[i].type(); - if ((vparams[i].flags & REPEATED) != 0 && - tp.symbol() == Global.instance.definitions.SEQ_CLASS && - tp.typeArgs().length == 1) - ss[i] = tp.typeArgs()[0].toString() + "*"; - else - ss[i] = tp.toString(); - } - return ss; - } - public int hashCode() { switch (this) { case ErrorType: |