From d37c08ba93b7e3055412a3eafb7efcc4b6c6b3f7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 5 Nov 2003 14:14:23 +0000 Subject: *** empty log message *** --- sources/scala/List.scala | 14 +++++---- .../scala/tools/scaladoc/SymbolTablePrinter.java | 2 +- sources/scalac/ast/parser/Scanner.scala | 33 ++++++++++++++-------- sources/scalac/typechecker/Analyzer.java | 26 +++++++++++++---- 4 files changed, 51 insertions(+), 24 deletions(-) (limited to 'sources') diff --git a/sources/scala/List.scala b/sources/scala/List.scala index 9459184829..135a998000 100644 --- a/sources/scala/List.scala +++ b/sources/scala/List.scala @@ -71,12 +71,14 @@ object List { Pair(f :: fs, s :: ss) } - /** Converts an array into a list. - * @param arr the array to convert - * @returns a list that contains the same elements than arr - * in the same order + /** Converts an iterator to a list + * @param it the iterator to convert + * @returns a list that contains the elements returned by successive + * calls to it.next */ - def fromArray[a](arr: Array[a]): List[a] = fromArray(arr, 0, arr.length); + def fromIterator[a](it: Iterator[a]): List[a] = + if (it.hasNext) it.next :: fromIterator(it); + else Nil; /** Converts a range of an array into a list. * @param arr the array to convert @@ -112,7 +114,7 @@ object List { start = end; end = str.indexOf(separator, end); } - res.reverse + res.reverse } } diff --git a/sources/scala/tools/scaladoc/SymbolTablePrinter.java b/sources/scala/tools/scaladoc/SymbolTablePrinter.java index c5811f39a8..eef0016c11 100644 --- a/sources/scala/tools/scaladoc/SymbolTablePrinter.java +++ b/sources/scala/tools/scaladoc/SymbolTablePrinter.java @@ -490,8 +490,8 @@ public class SymbolTablePrinter extends scalac.symtab.SymbolTablePrinter { return this; case ConstantType(Type base, Object value): - print("("); printType(base, user); + print("("); print(value.toString()); print(")"); return this; diff --git a/sources/scalac/ast/parser/Scanner.scala b/sources/scalac/ast/parser/Scanner.scala index d7376395eb..5181812b9c 100644 --- a/sources/scalac/ast/parser/Scanner.scala +++ b/sources/scalac/ast/parser/Scanner.scala @@ -202,6 +202,13 @@ class Scanner(unit: Unit) extends TokenData { nextch(); getOperatorRest(index); return; + case `\\' => + nextch(); + if (ch == '"')//" + getStringLit(); + else + syntaxError(pos, "illegal character"); + return; case '/' => nextch(); if (!skipComment()) { @@ -222,17 +229,7 @@ class Scanner(unit: Unit) extends TokenData { getNumber(index, 10); return; case '\"' => //" scala-mode: need to understand literals - nextch(); - litlen = 0; - while (ch != '\"'/*"*/ && ch != CR && ch != LF && ch != SU) - getlitch(); - if (ch == '\"'/*"*/) { - token = STRINGLIT; - name = Name.fromSource(lit, 0, litlen); - nextch(); - } else { - syntaxError("unclosed character literal"); - } + getStringLit(); return; case '\'' => nextch(); @@ -446,6 +443,20 @@ class Scanner(unit: Unit) extends TokenData { } } + private def getStringLit(): unit = { + nextch(); + litlen = 0; + while (ch != '\"'/*"*/ && ch != CR && ch != LF && ch != SU) + getlitch(); + if (ch == '\"'/*"*/) { + token = STRINGLIT; + name = Name.fromSource(lit, 0, litlen); + nextch(); + } else { + syntaxError("unclosed character literal"); + } + } + /** returns true if argument corresponds to a keyword. * Used in dtd2scala tool. */ diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index 59a569ddba..e807c41994 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -1297,9 +1297,9 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { clazz.primaryConstructor()); // MZ: this is a hack, but I didn't know how to do it better if ((clazz.flags & (JAVA | CASE)) == (JAVA | CASE)) { - Symbol[] altconstr = clazz.allConstructors().alternativeSymbols(); - tree.type = tree.type.prefix().memberType( - altconstr[altconstr.length - 1]); + Symbol[] altconstr = clazz.allConstructors().alternativeSymbols(); + tree.type = tree.type.prefix().memberType( + altconstr[altconstr.length - 1]); } switch (tree.type) { case PolyType(Symbol[] tparams, Type restp): @@ -1397,10 +1397,24 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (value1 != null) return make.Literal(tree.pos, value1) .setType(Type.ConstantType(pt, value1)); + break; } - typeError(tree.pos, owntype, pt); - Type.explainTypes(owntype, pt); - tree.type = Type.ErrorType; + if ((mode & EXPRmode) != 0) { + Symbol coerceMeth = tree.type.lookup(Names.coerce); + if (coerceMeth != Symbol.NONE) { + Type coerceType = checkAccessible( + tree.pos, coerceMeth, tree.type.memberType(coerceMeth), + tree); + tree = make.Select(tree.pos, tree, Names.coerce) + .setSymbol(coerceMeth) + .setType(coerceType); + return adapt(tree, mode, pt); + } + } else if ((mode & CONSTRmode) == 0) { + typeError(tree.pos, owntype, pt); + Type.explainTypes(owntype, pt); + tree.type = Type.ErrorType; + } // for constructors, delay until after the `new'. } return tree; } -- cgit v1.2.3