From f4f4e7138732bec78765b4a470f7aea3468fe8ba Mon Sep 17 00:00:00 2001 From: michelou Date: Wed, 4 Oct 2006 15:20:29 +0000 Subject: removed Scala attributes '_mixin_' and '_trait_' --- .../scala/tools/nsc/ast/parser/Parsers.scala | 184 ++++++++++----------- .../scala/tools/nsc/backend/ScalaPrimitives.scala | 23 ++- .../tools/nsc/backend/WorklistAlgorithm.scala | 4 +- .../scala/tools/nsc/doc/DocGenerator.scala | 3 +- src/library/scala/_mixin_.scala | 18 -- src/library/scala/_trait_.scala | 18 -- 6 files changed, 111 insertions(+), 139 deletions(-) delete mode 100644 src/library/scala/_mixin_.scala delete mode 100644 src/library/scala/_trait_.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 30ba3a7c98..ba4bcfc3fb 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -6,8 +6,7 @@ package scala.tools.nsc.ast.parser -import scala.tools.nsc.util.Position -import util.ListBuffer +import scala.tools.nsc.util.{ListBuffer, Position} import symtab.Flags import Tokens._ @@ -51,9 +50,9 @@ import Tokens._ trait Parsers requires SyntaxAnalyzer { import global._ - import RequiresIntsAsPositions._; + import RequiresIntsAsPositions._ private val glob: global.type = global - import global.posAssigner.atPos; + import global.posAssigner.atPos class Parser(unit: global.CompilationUnit) { @@ -84,7 +83,7 @@ trait Parsers requires SyntaxAnalyzer { /////// ERROR HANDLING ////////////////////////////////////////////////////// private def skip(): unit = { - //System.out.println(" " + in.token2string(in.token));//DEBUG + //System.out.println(" " + in.token2string(in.token))//DEBUG var nparens = 0 var nbraces = 0 while (true) { @@ -149,7 +148,8 @@ trait Parsers requires SyntaxAnalyzer { /** StatementSeparator = NewLine | `;' * NewLine = `\n' // where allowed */ - def acceptStatSep(): unit = if (in.token == NEWLINE) in.nextToken() else accept(SEMI) + def acceptStatSep(): unit = + if (in.token == NEWLINE) in.nextToken() else accept(SEMI) def errorTypeTree = TypeTree().setType(ErrorType).setPos(in.currentPos) def errorTermTree = Literal(Constant(null)).setPos(in.currentPos) @@ -1063,15 +1063,15 @@ trait Parsers requires SyntaxAnalyzer { val pos = in.currentPos val t = pattern1(seqOK) if (isIdent && in.name == BAR) { - val ts = new ListBuffer[Tree] + t; + val ts = new ListBuffer[Tree] + t while (isIdent && in.name == BAR) { - in.nextToken(); ts += pattern1(seqOK); + in.nextToken(); ts += pattern1(seqOK) } atPos(pos) { makeAlternative(ts.toList) } } else t } - def pattern(): Tree = pattern(false); + def pattern(): Tree = pattern(false) /** Pattern1 ::= varid `:' Type1 * | `_' `:' Type1 @@ -1135,9 +1135,9 @@ trait Parsers requires SyntaxAnalyzer { } while (isIdent && in.name != BAR) { top = reduceStack( - false, base, top, precedence(in.name), treeInfo.isLeftAssoc(in.name)); - opstack = OpInfo(top, in.name, in.currentPos) :: opstack; - ident(); + false, base, top, precedence(in.name), treeInfo.isLeftAssoc(in.name)) + opstack = OpInfo(top, in.name, in.currentPos) :: opstack + ident() top = simplePattern(seqOK) } reduceStack(false, base, top, 0, true) @@ -1189,14 +1189,14 @@ trait Parsers requires SyntaxAnalyzer { accept(RPAREN) p case XMLSTART => - val r = xmlp.xLiteralPattern; + val r = xmlp.xLiteralPattern //Console.println("successfully parsed xml pattern "+r); DEBUG r case _ => if (settings.migrate.value && in.token == MATCH || in.token == REQUIRES || in.token == IMPLICIT) syntaxErrorMigrate(""+in+" is now a reserved word; cannot be used as identifier"); - syntaxError("illegal start of simple pattern", true); + syntaxError("illegal start of simple pattern", true) errorPatternTree } @@ -1286,23 +1286,23 @@ trait Parsers requires SyntaxAnalyzer { var caseParam = ofCaseClass def param(): ValDef = { atPos(in.currentPos) { - val attrs = attributeClauses(); - var mods = Modifiers(Flags.PARAM); + val attrs = attributeClauses() + var mods = Modifiers(Flags.PARAM) if (owner.isTypeName) { - mods = modifiers() | Flags.PARAMACCESSOR; + mods = modifiers() | Flags.PARAMACCESSOR if (in.token == VAL) { in.nextToken() } else if (in.token == VAR) { - mods = mods | Flags.MUTABLE; + mods = mods | Flags.MUTABLE in.nextToken() } else { if (mods.flags != Flags.PARAMACCESSOR) accept(VAL); - if (!(caseParam)) mods = mods | Flags.PRIVATE | Flags.LOCAL; + if (!(caseParam)) mods = mods | Flags.PRIVATE | Flags.LOCAL } - if (caseParam) mods = mods | Flags.CASEACCESSOR; + if (caseParam) mods = mods | Flags.CASEACCESSOR } - val name = ident(); - accept(COLON); + val name = ident() + accept(COLON) val bynamemod = if (in.token == ARROW) { if (owner.isTypeName && !mods.hasFlag(Flags.LOCAL)) @@ -1316,12 +1316,12 @@ trait Parsers requires SyntaxAnalyzer { } } def paramClause(): List[ValDef] = { - val params = new ListBuffer[ValDef]; + val params = new ListBuffer[ValDef] if (in.token != RPAREN) { if (in.token == IMPLICIT) { if (!implicitViews.isEmpty) syntaxError("cannot have both view bounds `<%' and implicit parameters", false); - in.nextToken(); + in.nextToken() implicitmod = Flags.IMPLICIT } params += param(); @@ -1331,17 +1331,17 @@ trait Parsers requires SyntaxAnalyzer { } params.toList } - val vds = new ListBuffer[List[ValDef]]; - val pos = in.currentPos; - newLineOptWhenFollowedBy(LPAREN); + val vds = new ListBuffer[List[ValDef]] + val pos = in.currentPos + newLineOptWhenFollowedBy(LPAREN) while (implicitmod == 0 && in.token == LPAREN) { - in.nextToken(); - vds += paramClause(); - accept(RPAREN); - caseParam = false; - newLineOptWhenFollowedBy(LPAREN); + in.nextToken() + vds += paramClause() + accept(RPAREN) + caseParam = false + newLineOptWhenFollowedBy(LPAREN) } - val result = vds.toList; + val result = vds.toList if (owner == nme.CONSTRUCTOR && (result.isEmpty || (!result.head.isEmpty && result.head.head.mods.hasFlag(Flags.IMPLICIT)))) @@ -1378,17 +1378,17 @@ trait Parsers requires SyntaxAnalyzer { */ def typeParamClauseOpt(owner: Name, implicitViews: ListBuffer[Tree]): List[AbsTypeDef] = { def typeParam(): AbsTypeDef = { - var mods = Modifiers(Flags.PARAM); + var mods = Modifiers(Flags.PARAM) if (owner.isTypeName && isIdent) { if (in.name == PLUS) { - in.nextToken(); - mods = mods | Flags.COVARIANT; + in.nextToken() + mods = mods | Flags.COVARIANT } else if (in.name == MINUS) { - in.nextToken(); - mods = mods | Flags.CONTRAVARIANT; + in.nextToken() + mods = mods | Flags.CONTRAVARIANT } } - val pname = ident(); + val pname = ident() val param = atPos(in.currentPos) { typeBounds(mods, pname) } if (in.token == VIEWBOUND && (implicitViews != null)) implicitViews += atPos(in.skipToken()) { @@ -1427,10 +1427,10 @@ trait Parsers requires SyntaxAnalyzer { /** Import ::= import ImportExpr {`,' ImportExpr} */ def importClause(): List[Tree] = { - accept(IMPORT); - val ts = new ListBuffer[Tree] + importExpr(); + accept(IMPORT) + val ts = new ListBuffer[Tree] + importExpr() while (in.token == COMMA) { - in.nextToken(); ts += importExpr(); + in.nextToken(); ts += importExpr() } ts.toList } @@ -1439,8 +1439,8 @@ trait Parsers requires SyntaxAnalyzer { */ def importExpr(): Tree = atPos(in.currentPos) { - var t: Tree = null; - var pos = 0; + var t: Tree = null + var pos = 0 if (in.token == THIS) { t = atPos(in.currentPos) { This(nme.EMPTY.toTypeName) } t = atPos(accept(DOT)) { selector(t) } @@ -1454,12 +1454,12 @@ trait Parsers requires SyntaxAnalyzer { t = atPos(accept(DOT)) { selector(t) } pos = accept(DOT); } else { - t = i; + t = i } } def loop: Tree = if (in.token == USCORE) { - in.nextToken(); + in.nextToken() Import(t, List(Pair(nme.WILDCARD, null))) } else if (in.token == LBRACE) { Import(t, importSelectors()) @@ -1467,10 +1467,10 @@ trait Parsers requires SyntaxAnalyzer { val name = ident(); if (in.token == DOT) { t = atPos(pos) { Select(t, name) } - pos = accept(DOT); + pos = accept(DOT) loop } else { - Import(t, List(Pair(name, name))); + Import(t, List(Pair(name, name))) } } loop @@ -1479,14 +1479,14 @@ trait Parsers requires SyntaxAnalyzer { /** ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}' */ def importSelectors(): List[Pair[Name, Name]] = { - val names = new ListBuffer[Pair[Name, Name]]; - accept(LBRACE); - var isLast = importSelector(names); + val names = new ListBuffer[Pair[Name, Name]] + accept(LBRACE) + var isLast = importSelector(names) while (!isLast && in.token == COMMA) { - in.nextToken(); - isLast = importSelector(names); + in.nextToken() + isLast = importSelector(names) } - accept(RBRACE); + accept(RBRACE) names.toList } @@ -1496,7 +1496,7 @@ trait Parsers requires SyntaxAnalyzer { if (in.token == USCORE) { in.nextToken(); names += Pair(nme.WILDCARD, null); true } else { - val name = ident(); + val name = ident() names += Pair( name, if (in.token == ARROW) { @@ -1518,7 +1518,7 @@ trait Parsers requires SyntaxAnalyzer { * | def FunDcl * | type [NewLine] TypeDcl */ - def defOrDcl(mods: Modifiers): List[Tree] = { + def defOrDcl(mods: Modifiers): List[Tree] = in.token match { case VAL => patDefOrDcl(mods) @@ -1533,7 +1533,6 @@ trait Parsers requires SyntaxAnalyzer { case _ => List(tmplDef(mods)) } - } /** PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr * ValDcl ::= Id {`,' Id} `:' Type @@ -1582,17 +1581,17 @@ trait Parsers requires SyntaxAnalyzer { do { lhs += Pair(in.skipToken(), ident()) } while (in.token == COMMA); - val tp = typedOpt(); + val tp = typedOpt() val rhs = if (tp.isEmpty || in.token == EQUALS) { accept(EQUALS); if (!tp.isEmpty && in.token == USCORE) { - in.nextToken(); + in.nextToken() EmptyTree } else { expr() } } else { - newmods = newmods | Flags.DEFERRED; + newmods = newmods | Flags.DEFERRED EmptyTree } for (val Pair(pos, name) <- lhs.toList) yield @@ -1608,22 +1607,22 @@ trait Parsers requires SyntaxAnalyzer { def funDefOrDcl(mods: Modifiers): Tree = atPos(in.skipToken()) { if (in.token == THIS) { - in.nextToken(); - val vparamss = paramClauses(nme.CONSTRUCTOR, List(), false); + in.nextToken() + val vparamss = paramClauses(nme.CONSTRUCTOR, List(), false) val rhs = if (in.token == LBRACE) constrBlock() else { accept(EQUALS); constrExpr() } DefDef(mods, nme.CONSTRUCTOR, List(), vparamss, TypeTree(), rhs) } else { - var newmods = mods; - val name = ident(); - val implicitViews = new ListBuffer[Tree]; - val tparams = typeParamClauseOpt(name, implicitViews); - val vparamss = paramClauses(name, implicitViews.toList, false); - var restype = typedOpt(); + var newmods = mods + val name = ident() + val implicitViews = new ListBuffer[Tree] + val tparams = typeParamClauseOpt(name, implicitViews) + val vparamss = paramClauses(name, implicitViews.toList, false) + var restype = typedOpt() val rhs = if (in.token == SEMI || in.token == NEWLINE || in.token == RBRACE) { if (restype.isEmpty) restype = scalaUnitConstr - newmods = newmods | Flags.DEFERRED; + newmods = newmods | Flags.DEFERRED EmptyTree } else if (restype.isEmpty && in.token == LBRACE) { restype = scalaUnitConstr @@ -1750,14 +1749,14 @@ trait Parsers requires SyntaxAnalyzer { val argss = new ListBuffer[List[Tree]]; if (in.token == EXTENDS) { in.nextToken(); - val parent = simpleType(); + val parent = simpleType() // System.err.println("classTempl: " + parent); - parents += parent; + parents += parent if (in.token == LPAREN) do { argss += argumentExprs() } while (in.token == LPAREN) else argss += List(); while (in.token == WITH) { - in.nextToken(); + in.nextToken() parents += simpleType() } } else { @@ -1833,13 +1832,13 @@ trait Parsers requires SyntaxAnalyzer { in.token == CASEOBJECT || in.token == LBRACKET || isModifier) { - val attrs = attributeClauses(); + val attrs = attributeClauses() (stats ++ - joinAttributes(attrs, joinComment(List(tmplDef(modifiers() | mixinAttribute(attrs)))))) + joinAttributes(attrs, joinComment(List(tmplDef(modifiers()/*| mixinAttribute(attrs)*/))))) } else if (in.token != SEMI && in.token != NEWLINE) { syntaxError("illegal start of class or object definition", true) } - if (in.token != RBRACE && in.token != EOF) acceptStatSep(); + if (in.token != RBRACE && in.token != EOF) acceptStatSep() } stats.toList } @@ -1852,20 +1851,20 @@ trait Parsers requires SyntaxAnalyzer { * | */ def templateStatSeq(): List[Tree] = { - val stats = new ListBuffer[Tree]; + val stats = new ListBuffer[Tree] while (in.token != RBRACE && in.token != EOF) { if (in.token == IMPORT) { stats ++= importClause() } else if (isExprIntro) { stats += expr() } else if (isDefIntro || isModifier || in.token == LBRACKET) { - val attrs = attributeClauses(); + val attrs = attributeClauses() (stats ++ - joinAttributes(attrs, joinComment(defOrDcl(modifiers() | mixinAttribute(attrs))))) + joinAttributes(attrs, joinComment(defOrDcl(modifiers()/*| mixinAttribute(attrs)*/)))) } else if (in.token != SEMI && in.token != NEWLINE) { - syntaxError("illegal start of definition", true); + syntaxError("illegal start of definition", true) } - if (in.token != RBRACE && in.token != EOF) acceptStatSep(); + if (in.token != RBRACE && in.token != EOF) acceptStatSep() } stats.toList } @@ -1898,8 +1897,8 @@ trait Parsers requires SyntaxAnalyzer { accept(EQUALS) atPos(pos) { Assign(aname, liftingScope(prefixExpr())) } } - val pos = in.currentPos; - var t: Tree = convertToTypeId(stableId()); + val pos = in.currentPos + var t: Tree = convertToTypeId(stableId()) if (in.token == LBRACKET) t = atPos(in.currentPos)(AppliedTypeTree(t, typeArgs())); val args = if (in.token == LPAREN) argumentExprs() else List(); @@ -1907,7 +1906,7 @@ trait Parsers requires SyntaxAnalyzer { in.nextToken() val nvps = new ListBuffer[Tree] + nameValuePair() while (in.token == COMMA) { - in.nextToken(); + in.nextToken() nvps += nameValuePair() } accept(RBRACE); @@ -1916,7 +1915,7 @@ trait Parsers requires SyntaxAnalyzer { val constr = atPos(pos) { New(t, List(args)) } glob.Attribute(constr, nameValuePairs) setPos pos } - +/* //DEPRECATED def mixinAttribute(attrs: List[Tree]) = { def isMixinAttribute(attr: Tree) = attr match { case Apply(Select(New(Ident(name)), constr), List()) @@ -1927,7 +1926,7 @@ trait Parsers requires SyntaxAnalyzer { } if (attrs exists isMixinAttribute) Flags.TRAIT else 0 } - +*/ def joinAttributes(attrs: List[Attribute], defs: List[Tree]): List[Tree] = { def setAttr(defn: Tree): Unit = defn match { case DocDef(_, def0) => setAttr(def0) @@ -1977,20 +1976,19 @@ trait Parsers requires SyntaxAnalyzer { } while ((in.token != RBRACE) && (in.token != EOF) && (in.token != CASE)) { if (in.token == IMPORT) { - stats ++= importClause(); - acceptStatSep(); + stats ++= importClause() + acceptStatSep() } else if (isExprIntro) { - stats += blockStatExpr(); - if (in.token != RBRACE && in.token != CASE) acceptStatSep(); + stats += blockStatExpr() + if (in.token != RBRACE && in.token != CASE) acceptStatSep() } else if (isDefIntro) { localDef(NoMods) } else if (isLocalModifier) { localDef(localModifiers()) } else if (in.token == SEMI || in.token == NEWLINE) { - in.nextToken(); - } else { - syntaxError("illegal start of statement", true); - } + in.nextToken() + } else + syntaxError("illegal start of statement", true) } stats.toList } diff --git a/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala b/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala index 058dc0f4e1..c544aa8337 100644 --- a/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala +++ b/src/compiler/scala/tools/nsc/backend/ScalaPrimitives.scala @@ -18,13 +18,22 @@ import scala.collection.mutable.{Map, HashMap} * different value types, but with the same meaning (like plus, minus, * etc.). They will all be mapped to the same int. * - * Note: The three equal methods have the following semantics: - * - "==" checks for null, and if non-null, calls java.lang.Object.equals - * (class: Any; modifier: final). Primitive: EQ - * - "eq" usual reference comparison - * (class: AnyRef; modifier: final). Primitive: ID - * - "equals" user-defined equality (Java semantics) - * (class: Object; modifier: none). Primitive: EQUALS + *

Note: The three equal methods have the following semantics:

+ *
    + *
  • + * "==" checks for null, and if non-null, calls + * java.lang.Object.equals
    + * (class: Any; modifier: final). Primitive: EQ + *
  • + *
  • + * "eq" usual reference comparison
    + * (class: AnyRef; modifier: final). Primitive: ID + *
  • + *
  • + * "equals" user-defined equality (Java semantics)
    + * (class: Object; modifier: none). Primitive: EQUALS + *
  • + *
* * Inspired from the scalac compiler. */ diff --git a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala index 4dc52f02de..1b30e513eb 100644 --- a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala +++ b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala @@ -22,7 +22,7 @@ import scala.collection.mutable.MutableList * * @author Martin Odersky * @version 1.0 - * @see scala.tools.nsc.backend.icode.Linearizers + * @see scala.tools.nsc.backend.icode.Linearizers */ trait WorklistAlgorithm { type Elem @@ -34,6 +34,8 @@ trait WorklistAlgorithm { * Run the iterative algorithm until the worklist * remains empty. The initializer is run once before * the loop starts and should initialize the worklist. + * + * @param initWorklist ... */ def run(initWorklist: => Unit) = { initWorklist diff --git a/src/compiler/scala/tools/nsc/doc/DocGenerator.scala b/src/compiler/scala/tools/nsc/doc/DocGenerator.scala index a087b10b58..8153e5f293 100644 --- a/src/compiler/scala/tools/nsc/doc/DocGenerator.scala +++ b/src/compiler/scala/tools/nsc/doc/DocGenerator.scala @@ -696,8 +696,7 @@ abstract class DocGenerator extends Models { val mat2 = pat2.matcher(s) if (mat2.matches) { attr = Triple(mat2.group(1), mat2.group(2), new StringBuffer(mat2.group(3))) - if (isShort) - attributes += attr + attributes += attr } else if (attr != null) attr._3.append(s + LINE_SEPARATOR) else diff --git a/src/library/scala/_mixin_.scala b/src/library/scala/_mixin_.scala deleted file mode 100644 index 5d80167992..0000000000 --- a/src/library/scala/_mixin_.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2005, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -*/ - -// $Id:_trait_.scala 5359 2005-12-16 16:33:49 +0100 (Fri, 16 Dec 2005) dubochet $ - -package scala; - -/** Temporary class. - * When this appears in the attribute list of an abstract class, the class - * is assumed to be a mixin. Used to ensure that code that compiles under - * (old) scalac can also compile under nsc. - */ -class _mixin_ extends Attribute {} diff --git a/src/library/scala/_trait_.scala b/src/library/scala/_trait_.scala deleted file mode 100644 index 087508da64..0000000000 --- a/src/library/scala/_trait_.scala +++ /dev/null @@ -1,18 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2005, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -*/ - -// $Id:_trait_.scala 5359 2005-12-16 16:33:49 +0100 (Fri, 16 Dec 2005) dubochet $ - -package scala; - -/** Temporary class. - * When this appears in the attribute list of an abstract class, the class - * is assumed to be a trait. Used to ensure that code that compiles under - * (old) scalac can also compile under nsc. - */ -class _trait_ extends Attribute {} -- cgit v1.2.3