diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/javac')
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaParsers.scala | 183 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaScanners.scala | 286 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/javac/JavaTokens.scala | 6 |
3 files changed, 182 insertions, 293 deletions
diff --git a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala index 8aa9b81a72..f1b1d1a9a7 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaParsers.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaParsers.scala @@ -35,7 +35,6 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { abstract class JavaParser extends ParserCommon { val in: JavaScanner - protected def posToReport: Int = in.currentPos def freshName(prefix : String): Name protected implicit def i2p(offset : Int) : Position private implicit def p2i(pos : Position): Int = if (pos.isDefined) pos.point else -1 @@ -75,7 +74,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { nbraces += 1 case _ => } - in.nextToken + in.nextToken() } } @@ -94,11 +93,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { if (skipIt) skip() } - def warning(msg: String) : Unit = warning(in.currentPos, msg) - def errorTypeTree = TypeTree().setType(ErrorType) setPos in.currentPos - def errorTermTree = Literal(Constant(null)) setPos in.currentPos - def errorPatternTree = blankExpr setPos in.currentPos // --------- tree building ----------------------------- @@ -130,7 +125,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def makeSyntheticParam(count: Int, tpt: Tree): ValDef = makeParam(nme.syntheticParamName(count), tpt) def makeParam(name: String, tpt: Tree): ValDef = - makeParam(newTypeName(name), tpt) + makeParam(name: TermName, tpt) def makeParam(name: TermName, tpt: Tree): ValDef = ValDef(Modifiers(Flags.JAVA | Flags.PARAM), name, tpt, EmptyTree) @@ -153,7 +148,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { nbraces += 1 case _ => } - in.nextToken + in.nextToken() in.token match { case RPAREN => nparens -= 1 @@ -168,7 +163,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { while (!(tokens contains in.token) && in.token != EOF) { if (in.token == LBRACE) { skipAhead(); accept(RBRACE) } else if (in.token == LPAREN) { skipAhead(); accept(RPAREN) } - else in.nextToken + else in.nextToken() } } @@ -178,18 +173,14 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def accept(token: Int): Int = { val pos = in.currentPos if (in.token != token) { - val posToReport = - //if (in.currentPos.line(unit.source).get(0) > in.lastPos.line(unit.source).get(0)) - // in.lastPos - //else - in.currentPos + val posToReport = in.currentPos val msg = JavaScannerConfiguration.token2string(token) + " expected but " + JavaScannerConfiguration.token2string(in.token) + " found." - syntaxError(posToReport, msg, true) + syntaxError(posToReport, msg, skipIt = true) } - if (in.token == token) in.nextToken + if (in.token == token) in.nextToken() pos } @@ -209,7 +200,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def ident(): Name = if (in.token == IDENTIFIER) { val name = in.name - in.nextToken + in.nextToken() name } else { accept(IDENTIFIER) @@ -219,7 +210,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def repsep[T <: Tree](p: () => T, sep: Int): List[T] = { val buf = ListBuffer[T](p()) while (in.token == sep) { - in.nextToken + in.nextToken() buf += p() } buf.toList @@ -233,7 +224,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { case AppliedTypeTree(_, _) | ExistentialTypeTree(_, _) | SelectFromTypeTree(_, _) => tree case _ => - syntaxError(tree.pos, "identifier expected", false) + syntaxError(tree.pos, "identifier expected", skipIt = false) errorTypeTree } } @@ -243,7 +234,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def qualId(): RefTree = { var t: RefTree = atPos(in.currentPos) { Ident(ident()) } while (in.token == DOT) { - in.nextToken + in.nextToken() t = atPos(in.currentPos) { Select(t, ident()) } } t @@ -252,7 +243,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def optArrayBrackets(tpt: Tree): Tree = if (in.token == LBRACKET) { val tpt1 = atPos(in.pos) { arrayOf(tpt) } - in.nextToken + in.nextToken() accept(RBRACKET) optArrayBrackets(tpt1) } else tpt @@ -260,21 +251,21 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def basicType(): Tree = atPos(in.pos) { in.token match { - case BYTE => in.nextToken; TypeTree(ByteClass.tpe) - case SHORT => in.nextToken; TypeTree(ShortClass.tpe) - case CHAR => in.nextToken; TypeTree(CharClass.tpe) - case INT => in.nextToken; TypeTree(IntClass.tpe) - case LONG => in.nextToken; TypeTree(LongClass.tpe) - case FLOAT => in.nextToken; TypeTree(FloatClass.tpe) - case DOUBLE => in.nextToken; TypeTree(DoubleClass.tpe) - case BOOLEAN => in.nextToken; TypeTree(BooleanClass.tpe) - case _ => syntaxError("illegal start of type", true); errorTypeTree + case BYTE => in.nextToken(); TypeTree(ByteClass.tpe) + case SHORT => in.nextToken(); TypeTree(ShortClass.tpe) + case CHAR => in.nextToken(); TypeTree(CharClass.tpe) + case INT => in.nextToken(); TypeTree(IntClass.tpe) + case LONG => in.nextToken(); TypeTree(LongClass.tpe) + case FLOAT => in.nextToken(); TypeTree(FloatClass.tpe) + case DOUBLE => in.nextToken(); TypeTree(DoubleClass.tpe) + case BOOLEAN => in.nextToken(); TypeTree(BooleanClass.tpe) + case _ => syntaxError("illegal start of type", skipIt = true); errorTypeTree } } def typ(): Tree = optArrayBrackets { - if (in.token == FINAL) in.nextToken + if (in.token == FINAL) in.nextToken() if (in.token == IDENTIFIER) { var t = typeArgs(atPos(in.currentPos)(Ident(ident()))) // typeSelect generates Select nodes is the lhs is an Ident or Select, @@ -287,7 +278,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { case _ => SelectFromTypeTree(t, name.toTypeName) } while (in.token == DOT) { - in.nextToken + in.nextToken() t = typeArgs(atPos(in.currentPos)(typeSelect(t, ident()))) } convertToTypeId(t) @@ -301,14 +292,14 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def typeArg(): Tree = if (in.token == QMARK) { val pos = in.currentPos - in.nextToken + in.nextToken() var lo: Tree = TypeTree(NothingClass.tpe) var hi: Tree = TypeTree(AnyClass.tpe) if (in.token == EXTENDS) { - in.nextToken + in.nextToken() hi = typ() } else if (in.token == SUPER) { - in.nextToken + in.nextToken() lo = typ() } val tdef = atPos(pos) { @@ -324,7 +315,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { typ() } if (in.token == LT) { - in.nextToken + in.nextToken() val t1 = convertToTypeId(t) val args = repsep(typeArg, COMMA) acceptClosingAngle() @@ -339,7 +330,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def annotations(): List[Tree] = { //var annots = new ListBuffer[Tree] while (in.token == AT) { - in.nextToken + in.nextToken() annotation() } List() // don't pass on annotations for now @@ -348,46 +339,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { /** Annotation ::= TypeName [`(` AnnotationArgument {`,` AnnotationArgument} `)`] */ def annotation() { - val pos = in.currentPos - var t = qualId() + qualId() if (in.token == LPAREN) { skipAhead(); accept(RPAREN) } else if (in.token == LBRACE) { skipAhead(); accept(RBRACE) } } -/* - def annotationArg() = { - val pos = in.token - if (in.token == IDENTIFIER && in.lookaheadToken == ASSIGN) { - val name = ident() - accept(ASSIGN) - atPos(pos) { - ValDef(Modifiers(Flags.JAVA), name, TypeTree(), elementValue()) - } - } else { - elementValue() - } - } - - def elementValue(): Tree = - if (in.token == AT) annotation() - else if (in.token == LBRACE) elementValueArrayInitializer() - else expression1() - - def elementValueArrayInitializer() = { - accept(LBRACE) - val buf = new ListBuffer[Tree] - def loop() = - if (in.token != RBRACE) { - buf += elementValue() - if (in.token == COMMA) { - in.nextToken - loop() - } - } - loop() - accept(RBRACE) - buf.toList - } - */ def modifiers(inInterface: Boolean): Modifiers = { var flags: Long = Flags.JAVA @@ -399,38 +354,38 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { while (true) { in.token match { case AT if (in.lookaheadToken != INTERFACE) => - in.nextToken + in.nextToken() annotation() case PUBLIC => isPackageAccess = false - in.nextToken + in.nextToken() case PROTECTED => flags |= Flags.PROTECTED - in.nextToken + in.nextToken() case PRIVATE => isPackageAccess = false flags |= Flags.PRIVATE - in.nextToken + in.nextToken() case STATIC => flags |= Flags.STATIC - in.nextToken + in.nextToken() case ABSTRACT => flags |= Flags.ABSTRACT - in.nextToken + in.nextToken() case FINAL => flags |= Flags.FINAL - in.nextToken + in.nextToken() case NATIVE => addAnnot(NativeAttr) - in.nextToken + in.nextToken() case TRANSIENT => addAnnot(TransientAttr) - in.nextToken + in.nextToken() case VOLATILE => addAnnot(VolatileAttr) - in.nextToken + in.nextToken() case SYNCHRONIZED | STRICTFP => - in.nextToken + in.nextToken() case _ => val privateWithin: TypeName = if (isPackageAccess && !inInterface) thisPackageName @@ -444,7 +399,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def typeParams(): List[TypeDef] = if (in.token == LT) { - in.nextToken + in.nextToken() val tparams = repsep(typeParam, COMMA) acceptClosingAngle() tparams @@ -455,7 +410,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val name = identForType() val hi = if (in.token == EXTENDS) { - in.nextToken + in.nextToken() bound() } else { scalaDot(tpnme.Any) @@ -468,7 +423,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { atPos(in.currentPos) { val buf = ListBuffer[Tree](typ()) while (in.token == AMP) { - in.nextToken + in.nextToken() buf += typ() } val ts = buf.toList @@ -484,21 +439,21 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { } def formalParam(): ValDef = { - if (in.token == FINAL) in.nextToken + if (in.token == FINAL) in.nextToken() annotations() var t = typ() if (in.token == DOTDOTDOT) { - in.nextToken + in.nextToken() t = atPos(t.pos) { AppliedTypeTree(scalaDot(tpnme.JAVA_REPEATED_PARAM_CLASS_NAME), List(t)) } } - varDecl(in.currentPos, Modifiers(Flags.JAVA | Flags.PARAM), t, ident()) + varDecl(in.currentPos, Modifiers(Flags.JAVA | Flags.PARAM), t, ident().toTermName) } def optThrows() { if (in.token == THROWS) { - in.nextToken + in.nextToken() repsep(typ, COMMA) } } @@ -517,7 +472,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val isVoid = in.token == VOID var rtpt = if (isVoid) { - in.nextToken + in.nextToken() TypeTree(UnitClass.tpe) setPos in.pos } else typ() var pos = in.currentPos @@ -551,7 +506,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { if (parentToken == AT && in.token == DEFAULT) { val annot = atPos(pos) { - New(Select(scalaDot(nme.runtime), tpnme.AnnotationDefaultATTR), ListOfNil) + New(Select(scalaDot(nme.runtime), tpnme.AnnotationDefaultATTR), Nil) } mods1 = mods1 withAnnotations List(annot) skipTo(SEMI) @@ -587,18 +542,18 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { * these potential definitions are real or not. */ def fieldDecls(pos: Position, mods: Modifiers, tpt: Tree, name: Name): List[Tree] = { - val buf = ListBuffer[Tree](varDecl(pos, mods, tpt, name)) + val buf = ListBuffer[Tree](varDecl(pos, mods, tpt, name.toTermName)) val maybe = new ListBuffer[Tree] // potential variable definitions. while (in.token == COMMA) { - in.nextToken + in.nextToken() if (in.token == IDENTIFIER) { // if there's an ident after the comma ... val name = ident() if (in.token == ASSIGN || in.token == SEMI) { // ... followed by a `=` or `;`, we know it's a real variable definition buf ++= maybe - buf += varDecl(in.currentPos, mods, tpt.duplicate, name) + buf += varDecl(in.currentPos, mods, tpt.duplicate, name.toTermName) maybe.clear() } else if (in.token == COMMA) { // ... if there's a comma after the ident, it could be a real vardef or not. - maybe += varDecl(in.currentPos, mods, tpt.duplicate, name) + maybe += varDecl(in.currentPos, mods, tpt.duplicate, name.toTermName) } else { // ... if there's something else we were still in the initializer of the // previous var def; skip to next comma or semicolon. skipTo(COMMA, SEMI) @@ -671,25 +626,25 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def collectIdents() : Int = { if (in.token == ASTERISK) { val starOffset = in.pos - in.nextToken + in.nextToken() buf += nme.WILDCARD starOffset } else { val nameOffset = in.pos buf += ident() if (in.token == DOT) { - in.nextToken + in.nextToken() collectIdents() } else nameOffset } } - if (in.token == STATIC) in.nextToken + if (in.token == STATIC) in.nextToken() else buf += nme.ROOTPKG val lastnameOffset = collectIdents() accept(SEMI) val names = buf.toList if (names.length < 2) { - syntaxError(pos, "illegal import", false) + syntaxError(pos, "illegal import", skipIt = false) List() } else { val qual = ((Ident(names.head): Tree) /: names.tail.init) (Select(_, _)) @@ -704,7 +659,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { def interfacesOpt() = if (in.token == IMPLEMENTS) { - in.nextToken + in.nextToken() repsep(typ, COMMA) } else { List() @@ -717,7 +672,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val tparams = typeParams() val superclass = if (in.token == EXTENDS) { - in.nextToken + in.nextToken() typ() } else { javaLangObject() @@ -736,10 +691,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val tparams = typeParams() val parents = if (in.token == EXTENDS) { - in.nextToken + in.nextToken() repsep(typ, COMMA) } else { - List(javaLangObject) + List(javaLangObject()) } val (statics, body) = typeBody(INTERFACE, name) addCompanionObject(statics, atPos(pos) { @@ -766,7 +721,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { skipAhead() // skip init block, we just assume we have seen only static accept(RBRACE) } else if (in.token == SEMI) { - in.nextToken + in.nextToken() } else { if (in.token == ENUM || definesInterface(in.token)) mods |= Flags.STATIC val decls = memberDecl(mods, parentToken) @@ -818,7 +773,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { if (in.token != RBRACE && in.token != SEMI && in.token != EOF) { buf += enumConst(enumType) if (in.token == COMMA) { - in.nextToken + in.nextToken() parseEnumConsts() } } @@ -827,7 +782,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { val consts = buf.toList val (statics, body) = if (in.token == SEMI) { - in.nextToken + in.nextToken() typeBodyDecls(ENUM, name) } else { (List(), List()) @@ -869,7 +824,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { // The STABLE flag is to signal to namer that this was read from a // java enum, and so should be given a Constant type (thereby making // it usable in annotations.) - ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name, enumType, blankExpr) + ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name.toTermName, enumType, blankExpr) } } @@ -878,13 +833,13 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { case INTERFACE => interfaceDecl(mods) case AT => annotationDecl(mods) case CLASS => classDecl(mods) - case _ => in.nextToken; syntaxError("illegal start of type declaration", true); List(errorTypeTree) + case _ => in.nextToken(); syntaxError("illegal start of type declaration", skipIt = true); List(errorTypeTree) } /** CompilationUnit ::= [package QualId semi] TopStatSeq */ def compilationUnit(): Tree = { - var pos = in.currentPos; + var pos = in.currentPos val pkg: RefTree = if (in.token == AT || in.token == PACKAGE) { annotations() @@ -904,9 +859,9 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners { while (in.token == IMPORT) buf ++= importDecl() while (in.token != EOF && in.token != RBRACE) { - while (in.token == SEMI) in.nextToken + while (in.token == SEMI) in.nextToken() if (in.token != EOF) - buf ++= typeDecl(modifiers(false)) + buf ++= typeDecl(modifiers(inInterface = false)) } accept(EOF) atPos(pos) { diff --git a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala index e230585a8b..f9b1e57e66 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaScanners.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaScanners.scala @@ -10,7 +10,7 @@ import scala.tools.nsc.util.JavaCharArrayReader import scala.reflect.internal.util._ import scala.reflect.internal.Chars._ import JavaTokens._ -import scala.annotation.switch +import scala.annotation.{ switch, tailrec } import scala.language.implicitConversions // Todo merge these better with Scanners @@ -57,23 +57,14 @@ trait JavaScanners extends ast.parser.ScannersCommon { /** ... */ abstract class AbstractJavaScanner extends AbstractJavaTokenData { - implicit def p2g(pos: Position): ScanPosition implicit def g2p(pos: ScanPosition): Position - /** the last error position - */ - var errpos: ScanPosition - var lastPos: ScanPosition - def skipToken: ScanPosition def nextToken(): Unit def next: AbstractJavaTokenData def intVal(negated: Boolean): Long def floatVal(negated: Boolean): Double - def intVal: Long = intVal(false) - def floatVal: Double = floatVal(false) - //def token2string(token : Int) : String = configuration.token2string(token) - /** return recent scala doc, if any */ - def flushDoc: DocComment + def intVal: Long = intVal(negated = false) + def floatVal: Double = floatVal(negated = false) def currentPos: Position } @@ -227,17 +218,9 @@ trait JavaScanners extends ast.parser.ScannersCommon { abstract class JavaScanner extends AbstractJavaScanner with JavaTokenData with Cloneable with ScannerCommon { override def intVal = super.intVal// todo: needed? override def floatVal = super.floatVal - override var errpos: Int = NoPos def currentPos: Position = g2p(pos - 1) - var in: JavaCharArrayReader = _ - def dup: JavaScanner = { - val dup = clone().asInstanceOf[JavaScanner] - dup.in = in.dup - dup - } - /** character buffer for literals */ val cbuf = new StringBuilder() @@ -252,22 +235,6 @@ trait JavaScanners extends ast.parser.ScannersCommon { cbuf.setLength(0) } - /** buffer for the documentation comment - */ - var docBuffer: StringBuilder = null - - def flushDoc: DocComment = { - val ret = if (docBuffer != null) DocComment(docBuffer.toString, NoPosition) else null - docBuffer = null - ret - } - - /** add the given character to the documentation buffer - */ - protected def putDocChar(c: Char) { - if (docBuffer ne null) docBuffer.append(c) - } - private class JavaTokenData0 extends JavaTokenData /** we need one token lookahead @@ -277,13 +244,6 @@ trait JavaScanners extends ast.parser.ScannersCommon { // Get next token ------------------------------------------------------------ - /** read next token and return last position - */ - def skipToken: Int = { - val p = pos; nextToken - p - 1 - } - def nextToken() { if (next.token == EMPTY) { fetchToken() @@ -296,7 +256,7 @@ trait JavaScanners extends ast.parser.ScannersCommon { def lookaheadToken: Int = { prev copyFrom this - nextToken + nextToken() val t = token next copyFrom this this copyFrom prev @@ -308,11 +268,10 @@ trait JavaScanners extends ast.parser.ScannersCommon { private def fetchToken() { if (token == EOF) return lastPos = in.cpos - 1 - //var index = bp while (true) { in.ch match { case ' ' | '\t' | CR | LF | FF => - in.next + in.next() case _ => pos = in.cpos (in.ch: @switch) match { @@ -329,47 +288,47 @@ trait JavaScanners extends ast.parser.ScannersCommon { 'u' | 'v' | 'w' | 'x' | 'y' | 'z' => putChar(in.ch) - in.next - getIdentRest + in.next() + getIdentRest() return case '0' => putChar(in.ch) - in.next + in.next() if (in.ch == 'x' || in.ch == 'X') { - in.next + in.next() base = 16 } else { base = 8 } - getNumber + getNumber() return case '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => base = 10 - getNumber + getNumber() return case '\"' => - in.next + in.next() while (in.ch != '\"' && (in.isUnicode || in.ch != CR && in.ch != LF && in.ch != SU)) { getlitch() } if (in.ch == '\"') { token = STRINGLIT setName() - in.next + in.next() } else { syntaxError("unclosed string literal") } return case '\'' => - in.next + in.next() getlitch() if (in.ch == '\'') { - in.next + in.next() token = CHARLIT setName() } else { @@ -379,31 +338,31 @@ trait JavaScanners extends ast.parser.ScannersCommon { case '=' => token = ASSIGN - in.next + in.next() if (in.ch == '=') { token = EQEQ - in.next + in.next() } return case '>' => token = GT - in.next + in.next() if (in.ch == '=') { token = GTEQ - in.next + in.next() } else if (in.ch == '>') { token = GTGT - in.next + in.next() if (in.ch == '=') { token = GTGTEQ - in.next + in.next() } else if (in.ch == '>') { token = GTGTGT - in.next + in.next() if (in.ch == '=') { token = GTGTGTEQ - in.next + in.next() } } } @@ -411,145 +370,145 @@ trait JavaScanners extends ast.parser.ScannersCommon { case '<' => token = LT - in.next + in.next() if (in.ch == '=') { token = LTEQ - in.next + in.next() } else if (in.ch == '<') { token = LTLT - in.next + in.next() if (in.ch == '=') { token = LTLTEQ - in.next + in.next() } } return case '!' => token = BANG - in.next + in.next() if (in.ch == '=') { token = BANGEQ - in.next + in.next() } return case '~' => token = TILDE - in.next + in.next() return case '?' => token = QMARK - in.next + in.next() return case ':' => token = COLON - in.next + in.next() return case '@' => token = AT - in.next + in.next() return case '&' => token = AMP - in.next + in.next() if (in.ch == '&') { token = AMPAMP - in.next + in.next() } else if (in.ch == '=') { token = AMPEQ - in.next + in.next() } return case '|' => token = BAR - in.next + in.next() if (in.ch == '|') { token = BARBAR - in.next + in.next() } else if (in.ch == '=') { token = BAREQ - in.next + in.next() } return case '+' => token = PLUS - in.next + in.next() if (in.ch == '+') { token = PLUSPLUS - in.next + in.next() } else if (in.ch == '=') { token = PLUSEQ - in.next + in.next() } return case '-' => token = MINUS - in.next + in.next() if (in.ch == '-') { token = MINUSMINUS - in.next + in.next() } else if (in.ch == '=') { token = MINUSEQ - in.next + in.next() } return case '*' => token = ASTERISK - in.next + in.next() if (in.ch == '=') { token = ASTERISKEQ - in.next + in.next() } return case '/' => - in.next + in.next() if (!skipComment()) { token = SLASH - in.next + in.next() if (in.ch == '=') { token = SLASHEQ - in.next + in.next() } return } case '^' => token = HAT - in.next + in.next() if (in.ch == '=') { token = HATEQ - in.next + in.next() } return case '%' => token = PERCENT - in.next + in.next() if (in.ch == '=') { token = PERCENTEQ - in.next + in.next() } return case '.' => token = DOT - in.next + in.next() if ('0' <= in.ch && in.ch <= '9') { - putChar('.'); getFraction + putChar('.'); getFraction() } else if (in.ch == '.') { - in.next + in.next() if (in.ch == '.') { - in.next + in.next() token = DOTDOTDOT } else syntaxError("`.' character expected") } @@ -557,60 +516,60 @@ trait JavaScanners extends ast.parser.ScannersCommon { case ';' => token = SEMI - in.next + in.next() return case ',' => token = COMMA - in.next + in.next() return case '(' => token = LPAREN - in.next + in.next() return case '{' => token = LBRACE - in.next + in.next() return case ')' => token = RPAREN - in.next + in.next() return case '}' => token = RBRACE - in.next + in.next() return case '[' => token = LBRACKET - in.next + in.next() return case ']' => token = RBRACKET - in.next + in.next() return case SU => if (!in.hasNext) token = EOF else { syntaxError("illegal character") - in.next + in.next() } return case _ => if (Character.isUnicodeIdentifierStart(in.ch)) { putChar(in.ch) - in.next - getIdentRest + in.next() + getIdentRest() } else { syntaxError("illegal character: "+in.ch.toInt) - in.next + in.next() } return } @@ -618,33 +577,20 @@ trait JavaScanners extends ast.parser.ScannersCommon { } } - private def skipComment(): Boolean = { - if (in.ch == '/') { - do { - in.next - } while ((in.ch != CR) && (in.ch != LF) && (in.ch != SU)) - true - } else if (in.ch == '*') { - docBuffer = null - in.next - val scalaDoc = ("/**", "*/") - if (in.ch == '*' && forScaladoc) - docBuffer = new StringBuilder(scalaDoc._1) - do { - do { - if (in.ch != '*' && in.ch != SU) { - in.next; putDocChar(in.ch) - } - } while (in.ch != '*' && in.ch != SU) - while (in.ch == '*') { - in.next; putDocChar(in.ch) - } - } while (in.ch != '/' && in.ch != SU) - if (in.ch == '/') in.next - else incompleteInputError("unclosed comment") - true - } else { - false + protected def skipComment(): Boolean = { + @tailrec def skipLineComment(): Unit = in.ch match { + case CR | LF | SU => + case _ => in.next; skipLineComment() + } + @tailrec def skipJavaComment(): Unit = in.ch match { + case SU => incompleteInputError("unclosed comment") + case '*' => in.next; if (in.ch == '/') in.next else skipJavaComment() + case _ => in.next; skipJavaComment() + } + in.ch match { + case '/' => in.next ; skipLineComment() ; true + case '*' => in.next ; skipJavaComment() ; true + case _ => false } } @@ -668,12 +614,12 @@ trait JavaScanners extends ast.parser.ScannersCommon { '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => putChar(in.ch) - in.next + in.next() case '_' => putChar(in.ch) - in.next - getIdentRest + in.next() + getIdentRest() return case SU => setName() @@ -682,7 +628,7 @@ trait JavaScanners extends ast.parser.ScannersCommon { case _ => if (Character.isUnicodeIdentifierPart(in.ch)) { putChar(in.ch) - in.next + in.next() } else { setName() token = JavaScannerConfiguration.name2token(name) @@ -698,17 +644,17 @@ trait JavaScanners extends ast.parser.ScannersCommon { */ protected def getlitch() = if (in.ch == '\\') { - in.next + in.next() if ('0' <= in.ch && in.ch <= '7') { val leadch: Char = in.ch var oct: Int = digit2int(in.ch, 8) - in.next + in.next() if ('0' <= in.ch && in.ch <= '7') { oct = oct * 8 + digit2int(in.ch, 8) - in.next + in.next() if (leadch <= '3' && '0' <= in.ch && in.ch <= '7') { oct = oct * 8 + digit2int(in.ch, 8) - in.next + in.next() } } putChar(oct.asInstanceOf[Char]) @@ -726,11 +672,11 @@ trait JavaScanners extends ast.parser.ScannersCommon { syntaxError(in.cpos - 1, "invalid escape character") putChar(in.ch) } - in.next + in.next() } } else { putChar(in.ch) - in.next + in.next() } /** read fractional part and exponent of floating point number @@ -740,35 +686,35 @@ trait JavaScanners extends ast.parser.ScannersCommon { token = DOUBLELIT while ('0' <= in.ch && in.ch <= '9') { putChar(in.ch) - in.next + in.next() } if (in.ch == 'e' || in.ch == 'E') { val lookahead = in.copy - lookahead.next + lookahead.next() if (lookahead.ch == '+' || lookahead.ch == '-') { - lookahead.next + lookahead.next() } if ('0' <= lookahead.ch && lookahead.ch <= '9') { putChar(in.ch) - in.next + in.next() if (in.ch == '+' || in.ch == '-') { putChar(in.ch) - in.next + in.next() } while ('0' <= in.ch && in.ch <= '9') { putChar(in.ch) - in.next + in.next() } } token = DOUBLELIT } if (in.ch == 'd' || in.ch == 'D') { putChar(in.ch) - in.next + in.next() token = DOUBLELIT } else if (in.ch == 'f' || in.ch == 'F') { putChar(in.ch) - in.next + in.next() token = FLOATLIT } setName() @@ -828,23 +774,23 @@ trait JavaScanners extends ast.parser.ScannersCommon { protected def getNumber() { while (digit2int(in.ch, if (base < 10) 10 else base) >= 0) { putChar(in.ch) - in.next + in.next() } token = INTLIT if (base <= 10 && in.ch == '.') { val lookahead = in.copy - lookahead.next + lookahead.next() lookahead.ch match { case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'd' | 'D' | 'e' | 'E' | 'f' | 'F' => putChar(in.ch) - in.next - return getFraction + in.next() + return getFraction() case _ => if (!isIdentifierStart(lookahead.ch)) { putChar(in.ch) - in.next - return getFraction + in.next() + return getFraction() } } } @@ -852,11 +798,11 @@ trait JavaScanners extends ast.parser.ScannersCommon { (in.ch == 'e' || in.ch == 'E' || in.ch == 'f' || in.ch == 'F' || in.ch == 'd' || in.ch == 'D')) { - return getFraction + return getFraction() } setName() if (in.ch == 'l' || in.ch == 'L') { - in.next + in.next() token = LONGLIT } } @@ -868,7 +814,6 @@ trait JavaScanners extends ast.parser.ScannersCommon { def syntaxError(pos: Int, msg: String) { error(pos, msg) token = ERROR - errpos = pos } /** generate an error at the current token position @@ -879,7 +824,6 @@ trait JavaScanners extends ast.parser.ScannersCommon { def incompleteInputError(msg: String) { incompleteInputError(pos, msg) token = EOF - errpos = pos } override def toString() = token match { @@ -908,21 +852,17 @@ trait JavaScanners extends ast.parser.ScannersCommon { /** INIT: read lookahead character and token. */ def init() { - in.next - nextToken + in.next() + nextToken() } } - /** ... - */ class JavaUnitScanner(unit: CompilationUnit) extends JavaScanner { in = new JavaCharArrayReader(unit.source.content, !settings.nouescape.value, syntaxError) - init - def warning(pos: Int, msg: String) = unit.warning(pos, msg) + init() def error (pos: Int, msg: String) = unit. error(pos, msg) def incompleteInputError(pos: Int, msg: String) = unit.incompleteInputError(pos, msg) def deprecationWarning(pos: Int, msg: String) = unit.deprecationWarning(pos, msg) - implicit def p2g(pos: Position): Int = if (pos.isDefined) pos.point else -1 implicit def g2p(pos: Int): Position = new OffsetPosition(unit.source, pos) } } diff --git a/src/compiler/scala/tools/nsc/javac/JavaTokens.scala b/src/compiler/scala/tools/nsc/javac/JavaTokens.scala index a562de291d..953a3c6d82 100644 --- a/src/compiler/scala/tools/nsc/javac/JavaTokens.scala +++ b/src/compiler/scala/tools/nsc/javac/JavaTokens.scala @@ -68,9 +68,6 @@ object JavaTokens extends ast.parser.Tokens { final val VOLATILE = 68 final val WHILE = 69 - def isKeyword(code : Int) = - code >= ABSTRACT && code <= WHILE - /** special symbols */ final val COMMA = 70 final val SEMI = 71 @@ -115,9 +112,6 @@ object JavaTokens extends ast.parser.Tokens { final val GTGTEQ = 113 final val GTGTGTEQ = 114 - def isSymbol(code : Int) = - code >= COMMA && code <= GTGTGTEQ - /** parenthesis */ final val LPAREN = 115 final val RPAREN = 116 |