diff options
author | Martin Odersky <odersky@gmail.com> | 2007-02-09 19:09:06 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-02-09 19:09:06 +0000 |
commit | c470f8cca0fc646ba2f950302b9a2dfc515bff74 (patch) | |
tree | c43c9dcc044e7e1f111b1e7dbf5eefd1ef909364 /src/compiler | |
parent | 9674b0e81d31ef6c7380ceb7a85c453cd4294b94 (diff) | |
download | scala-c470f8cca0fc646ba2f950302b9a2dfc515bff74.tar.gz scala-c470f8cca0fc646ba2f950302b9a2dfc515bff74.tar.bz2 scala-c470f8cca0fc646ba2f950302b9a2dfc515bff74.zip |
renamed attributes to annotations; added @syntax.
Diffstat (limited to 'src/compiler')
12 files changed, 134 insertions, 127 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala index 830194c5c1..9179533e43 100644 --- a/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala +++ b/src/compiler/scala/tools/nsc/ast/TreeBrowsers.scala @@ -353,8 +353,8 @@ abstract class TreeBrowsers { case TypeTree() => Pair("TypeTree", EMPTY) - case Attributed(constr, elements, arg) => - Pair("AttributedTypeTree", EMPTY) + case Annotated(constr, elements, arg) => + Pair("Annotated", EMPTY) case AttributedTypeTree(attribs, tpt) => Pair("AttributedTypeTree", EMPTY) @@ -500,7 +500,7 @@ abstract class TreeBrowsers { case TypeTree() => Nil - case Attributed(constr, elements, arg) => + case Annotated(constr, elements, arg) => constr :: elements ::: List(arg) case SingletonTypeTree(ref) => diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala index 5c63d2c524..55b4bb0e2c 100644 --- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala +++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala @@ -65,7 +65,7 @@ abstract class TreePrinters { def printParam(tree: Tree): unit = tree match { case ValDef(mods, name, tp, rhs) => - printAttributes(tree) + printAnnotations(tree) print(symName(tree, name)); printOpt(": ", tp) case AbsTypeDef(mods, name, lo, hi) => print(symName(tree, name)) @@ -104,7 +104,7 @@ abstract class TreePrinters { if (s.length() != 0) print(s + " ") } - def printAttributes(tree: Tree): unit = { + def printAnnotations(tree: Tree): unit = { val attrs = tree.symbol.attributes if (!attrs.isEmpty) print(attrs mkString ("[", ", ", "]")) else { @@ -122,23 +122,23 @@ abstract class TreePrinters { print("<empty>") case ClassDef(mods, name, tparams, tp, impl) => - printAttributes(tree) + printAnnotations(tree) printModifiers(tree, mods) print((if (mods hasFlag TRAIT) "trait " else "class ") + symName(tree, name)) printTypeParams(tparams) printOpt(" requires ", tp); print(" extends "); print(impl) case PackageDef(packaged, stats) => - printAttributes(tree) + printAnnotations(tree) print("package "); print(packaged); printColumn(stats, " {", ";", "}") case ModuleDef(mods, name, impl) => - printAttributes(tree) + printAnnotations(tree) printModifiers(tree, mods); print("object " + symName(tree, name)) print(" extends "); print(impl) case ValDef(mods, name, tp, rhs) => - printAttributes(tree) + printAnnotations(tree) printModifiers(tree, mods) print(if (mods.hasFlag(MUTABLE)) "var " else "val ") print(symName(tree, name)) @@ -149,7 +149,7 @@ abstract class TreePrinters { } case DefDef(mods, name, tparams, vparamss, tp, rhs) => - printAttributes(tree) + printAnnotations(tree) printModifiers(tree, mods) print("def " + symName(tree, name)) printTypeParams(tparams); vparamss foreach printValueParams @@ -159,7 +159,7 @@ abstract class TreePrinters { printModifiers(tree, mods); print("type "); printParam(tree) case AliasTypeDef(mods, name, tparams, rhs) => - printAttributes(tree) + printAnnotations(tree) printModifiers(tree, mods); print("type " + symName(tree, name)) printTypeParams(tparams); printOpt(" = ", rhs) @@ -176,7 +176,7 @@ abstract class TreePrinters { case DocDef(comment, definition) => print(comment); println; print(definition) - case Attribute(Apply(Select(New(tpt), nme.CONSTRUCTOR), args), elements) => + case Annotation(Apply(Select(New(tpt), nme.CONSTRUCTOR), args), elements) => print(tpt) if (!args.isEmpty) printRow(args, "(", ",", ")") @@ -294,7 +294,7 @@ abstract class TreePrinters { print(" ") print(tree) - case Attributed(Apply(Select(New(tpt), nme.CONSTRUCTOR), args), elements, tree) => + case Annotated(Apply(Select(New(tpt), nme.CONSTRUCTOR), args), elements, tree) => def printAttr() { print("@"); print(tpt) if (!args.isEmpty) diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 25cfaf6cf4..a7843c9fad 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -17,7 +17,7 @@ trait Trees requires Global { //statistics var nodeCount = 0 - case class Modifiers(flags: int, privateWithin: Name, attributes: List[Attribute]) { + case class Modifiers(flags: int, privateWithin: Name, attributes: List[Annotation]) { def isCovariant = hasFlag(COVARIANT ) def isContravariant = hasFlag(CONTRAVARIANT) def isPrivate = hasFlag(PRIVATE ) @@ -50,7 +50,7 @@ trait Trees requires Global { if (flags1 == flags) this else Modifiers(flags1, privateWithin, attributes) } - def withAttributes(attrs: List[Attribute]) = + def withAnnotations(attrs: List[Annotation]) = if (attrs.isEmpty) this else Modifiers(flags, privateWithin, attributes ::: attrs) } @@ -410,8 +410,8 @@ trait Trees requires Global { case class Import(expr: Tree, selectors: List[{Name, Name}]) extends SymTree - /** Attribute application (constructor arguments + name-value pairs) */ - case class Attribute(constr: Tree, elements: List[Tree]) + /** Annotation application (constructor arguments + name-value pairs) */ + case class Annotation(constr: Tree, elements: List[Tree]) extends TermTree /** Documented definition, eliminated by analyzer */ @@ -442,7 +442,7 @@ trait Trees requires Global { /** Add constructor to template */ var vparamss1 = vparamss map (.map (vd => { - val ret = ValDef(Modifiers(vd.mods.flags & IMPLICIT | PARAM) withAttributes vd.mods.attributes, + val ret = ValDef(Modifiers(vd.mods.flags & IMPLICIT | PARAM) withAnnotations vd.mods.attributes, vd.name, vd.tpt.duplicate, EmptyTree).setPos(vd.pos) if (false/*inIDE*/ && vd.symbol != NoSymbol) ret.symbol = vd.symbol @@ -659,7 +659,7 @@ trait Trees requires Global { // def TypeTree(tp: Type, tree : Tree): TypeTree = TypeTree(tree) setType tp /** A tree that has anP attribute attached to it */ - case class Attributed(constr: Tree, elements: List[Tree], arg: Tree) extends Tree { + case class Annotated(constr: Tree, elements: List[Tree], arg: Tree) extends Tree { override def isType = arg.isType } @@ -703,7 +703,7 @@ trait Trees requires Global { case AliasTypeDef(mods, name, tparams, rhs) => (eliminated by erasure) case LabelDef(name, params, rhs) => case Import(expr, selectors) => (eliminated by typecheck) - case Attribute(constr, elements) => (eliminated by typecheck) + case Annotation(constr, elements) => (eliminated by typecheck) case DocDef(comment, definition) => (eliminated by typecheck) case Template(parents, body) => case Block(stats, expr) => @@ -731,7 +731,7 @@ trait Trees requires Global { case Ident(name) => case Literal(value) => case TypeTree() => (introduced by refcheck) - case Attributed(constr, elements, arg) => (eliminated by typer) + case Annotated(constr, elements, arg) => (eliminated by typer) case AttributedTypeTree(attribs, tpt) => (eliminated by uncurry) case SingletonTypeTree(ref) => (eliminated by uncurry) case SelectFromTypeTree(qualifier, selector) => (eliminated by uncurry) @@ -750,7 +750,7 @@ trait Trees requires Global { def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree): AliasTypeDef def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree): LabelDef def Import(tree: Tree, expr: Tree, selectors: List[{Name, Name}]): Import - def Attribute(tree: Tree, constr: Tree, elements: List[Tree]): Attribute + def Annotation(tree: Tree, constr: Tree, elements: List[Tree]): Annotation def DocDef(tree: Tree, comment: String, definition: Tree): DocDef def Template(tree: Tree, parents: List[Tree], body: List[Tree]): Template def Block(tree: Tree, stats: List[Tree], expr: Tree): Block @@ -778,7 +778,7 @@ trait Trees requires Global { def Ident(tree: Tree, name: Name): Ident def Literal(tree: Tree, value: Constant): Literal def TypeTree(tree: Tree): TypeTree - def Attributed(tree: Tree, constr: Tree, elements: List[Tree], arg: Tree): Attributed + def Annotated(tree: Tree, constr: Tree, elements: List[Tree], arg: Tree): Annotated def AttributedTypeTree(tree: Tree, attribs: List[Tree], tpt: Tree): AttributedTypeTree def SingletonTypeTree(tree: Tree, ref: Tree): SingletonTypeTree def SelectFromTypeTree(tree: Tree, qualifier: Tree, selector: Name): SelectFromTypeTree @@ -806,8 +806,8 @@ trait Trees requires Global { new LabelDef(name, params, rhs).copyAttrs(tree) def Import(tree: Tree, expr: Tree, selectors: List[{Name, Name}]) = new Import(expr, selectors).copyAttrs(tree) - def Attribute(tree: Tree, constr: Tree, elements: List[Tree]) = - new Attribute(constr, elements) + def Annotation(tree: Tree, constr: Tree, elements: List[Tree]) = + new Annotation(constr, elements) def DocDef(tree: Tree, comment: String, definition: Tree) = new DocDef(comment, definition).copyAttrs(tree) def Template(tree: Tree, parents: List[Tree], body: List[Tree]) = @@ -862,8 +862,8 @@ trait Trees requires Global { new Literal(value).copyAttrs(tree) def TypeTree(tree: Tree) = new TypeTree().copyAttrs(tree) - def Attributed(tree: Tree, constr: Tree, elements: List[Tree], arg: Tree) = - new Attributed(constr, elements, arg) + def Annotated(tree: Tree, constr: Tree, elements: List[Tree], arg: Tree) = + new Annotated(constr, elements, arg) def AttributedTypeTree(tree: Tree, attribs: List[Tree], tpt: Tree) = new AttributedTypeTree(attribs, tpt) def SingletonTypeTree(tree: Tree, ref: Tree) = @@ -926,10 +926,10 @@ trait Trees requires Global { if (expr0 == expr) && (selectors0 == selectors) => t case _ => copy.Import(tree, expr, selectors) } - def Attribute(tree: Tree, constr: Tree, elements: List[Tree]) = tree match { - case t @ Attribute(constr0, elements0) + def Annotation(tree: Tree, constr: Tree, elements: List[Tree]) = tree match { + case t @ Annotation(constr0, elements0) if (constr0 == constr) && (elements0 == elements) => t - case _ => copy.Attribute(tree, constr, elements) + case _ => copy.Annotation(tree, constr, elements) } def DocDef(tree: Tree, comment: String, definition: Tree) = tree match { case t @ DocDef(comment0, definition0) @@ -1065,10 +1065,10 @@ trait Trees requires Global { case t @ TypeTree() => t case _ => copy.TypeTree(tree) } - def Attributed(tree: Tree, constr: Tree, elements: List[Tree], arg: Tree) = tree match { - case t @ Attributed(constr0, elements0, arg0) + def Annotated(tree: Tree, constr: Tree, elements: List[Tree], arg: Tree) = tree match { + case t @ Annotated(constr0, elements0, arg0) if (constr0==constr) && (elements0==elements) && (arg0==arg) => t - case _ => copy.Attributed(tree, constr, elements, arg) + case _ => copy.Annotated(tree, constr, elements, arg) } def AttributedTypeTree(tree: Tree, attribs: List[Tree], tpt: Tree) = tree match { case t @ AttributedTypeTree(attribs0, tpt0) @@ -1145,8 +1145,8 @@ trait Trees requires Global { copy.LabelDef(tree, name, transformIdents(params), transform(rhs)) //bq: Martin, once, atOwner(...) works, also change `LamdaLifter.proxy' case Import(expr, selectors) => copy.Import(tree, transform(expr), selectors) - case Attribute(constr, elements) => - copy.Attribute(tree, transform(constr), transformTrees(elements)) + case Annotation(constr, elements) => + copy.Annotation(tree, transform(constr), transformTrees(elements)) case DocDef(comment, definition) => copy.DocDef(tree, comment, transform(definition)) case Template(parents, body) => @@ -1203,8 +1203,8 @@ trait Trees requires Global { copy.Literal(tree, value) case TypeTree() => copy.TypeTree(tree) - case Attributed(constr, elements, arg) => - copy.Attributed(tree, transform(constr), transformTrees(elements), transform(arg)) + case Annotated(constr, elements, arg) => + copy.Annotated(tree, transform(constr), transformTrees(elements), transform(arg)) case AttributedTypeTree(attribs, tpt) => copy.AttributedTypeTree(tree, transformTrees(attribs), transform(tpt)) case SingletonTypeTree(ref) => @@ -1285,9 +1285,9 @@ trait Trees requires Global { traverseTrees(params); traverse(rhs) case Import(expr, selectors) => traverse(expr) - case Attribute(constr, elements) => + case Annotation(constr, elements) => traverse(constr); traverseTrees(elements) - case Attributed(constr: Tree, elements: List[Tree], arg: Tree) => + case Annotated(constr: Tree, elements: List[Tree], arg: Tree) => traverse(constr); traverseTrees(elements); traverse(arg) case DocDef(comment, definition) => traverse(definition) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index fd0c5269bb..c61edbce53 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -648,14 +648,13 @@ trait Parsers requires SyntaxAnalyzer { } } - /** SimpleType ::= {`@' Attribute} SimpleType1 + /** SimpleType ::= Annotations SimpleType1 * SimpleType1 ::= SimpleType1 TypeArgs * | SimpleType1 `#' Id * | StableId * | Path `.' type * | `(' Type `)' * | `{' [Type `,' [Types [`,']]] `}' - * | TypeAttributes SimpleType (if -Xplugtypes) * SimpleTypePattern ::= SimpleTypePattern1 [TypePatternArgs] * SimpleTypePattern1 ::= SimpleTypePattern1 "#" Id * | StableId @@ -663,7 +662,8 @@ trait Parsers requires SyntaxAnalyzer { * | `{' [ArgTypePattern `,' [ArgTypePatterns [`,']]] `}' */ def simpleType(isPattern: boolean): Tree = { - val attribs = typeAttributes() + val annots = if (settings.Xplugtypes.value) typeAttributes() + else annotations() val pos = in.currentPos var t: Tree = if (in.token == LPAREN && !isPattern) { @@ -705,8 +705,8 @@ trait Parsers requires SyntaxAnalyzer { } else done=true } - if (settings.Xplugtypes.value) t.withAttributes(attribs) - else (t /: attribs) (makeAttributed) + if (settings.Xplugtypes.value) t.withAttributes(annots) + else (t /: annots) (makeAnnotated) } /** TypeArgs ::= `[' ArgTypes `]' @@ -932,7 +932,7 @@ trait Parsers requires SyntaxAnalyzer { } } else if (in.token == COLON) { val pos = in.skipToken() - val attribs = typeAttributes() + val annots = annotations() if ((mode & IsArgument) != 0 && in.token == USCORE) { val pos1 = in.skipToken() if (isIdent && in.name == nme.STAR) { @@ -945,15 +945,15 @@ trait Parsers requires SyntaxAnalyzer { } else { syntaxErrorOrIncomplete("`*' expected", true) } - } else if (attribs.isEmpty || isTypeIntro) { + } else if (annots.isEmpty || isTypeIntro) { t = atPos(pos) { val tpt = if ((mode & IsInBlock) != 0) compoundType(false) else typ() // this does not correspond to syntax, but is necessary to // accept closures. We might restrict closures to be between {...} only! - Typed(t, (tpt /: attribs) (makeAttributed)) + Typed(t, (tpt /: annots) (makeAnnotated)) } } else { - t = (t /: attribs) (makeAttributed) + t = (t /: annots) (makeAnnotated) } } else if (in.token == MATCH) { t = atPos(in.skipToken()) { @@ -1499,17 +1499,17 @@ trait Parsers requires SyntaxAnalyzer { /** ParamClauses ::= {[NewLine] `(' [Param {`,' Param}] ')'} * [[NewLine] `(' implicit Param {`,' Param} `)'] - * Param ::= Id [`:' ParamType] + * Param ::= Annotations Id [`:' ParamType] * ClassParamClauses ::= {[NewLine] `(' [ClassParam {`' ClassParam}] ')'} * [[NewLine] `(' implicit ClassParam {`,' ClassParam} `)'] - * ClassParam ::= [[modifiers] (val | var)] Param + * ClassParam ::= Annotations [[modifiers] (val | var)] Param */ def paramClauses(owner: Name, implicitViews: List[Tree], ofCaseClass: boolean): List[List[ValDef]] = { var implicitmod = 0 var caseParam = ofCaseClass def param(): ValDef = { atPos(in.currentPos) { - val attrs = attributeClauses() + val annots = annotations() var mods = Modifiers(Flags.PARAM) if (owner.isTypeName) { mods = modifiers() | Flags.PARAMACCESSOR @@ -1541,7 +1541,7 @@ trait Parsers requires SyntaxAnalyzer { } paramType() } - ValDef((mods | implicitmod | bynamemod) withAttributes attrs, name, tpt, EmptyTree) + ValDef((mods | implicitmod | bynamemod) withAnnotations annots, name, tpt, EmptyTree) } } def paramClause(): List[ValDef] = { @@ -1948,12 +1948,13 @@ trait Parsers requires SyntaxAnalyzer { val tparams = typeParamClauseOpt(name, implicitViewBuf) implicitClassViews = implicitViewBuf.toList //if (mods.hasFlag(Flags.CASE) && in.token != LPAREN) accept(LPAREN) + val constrAnnots = annotations() val {constrMods, vparamss} = if (mods.hasFlag(Flags.TRAIT)) {NoMods, List()} else {accessModifierOpt(), paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE))} val thistpe = requiresTypeOpt() - val template = classTemplate(mods, name, constrMods, vparamss) + val template = classTemplate(mods, name, constrMods withAnnotations constrAnnots, vparamss) val mods1 = if (mods.hasFlag(Flags.TRAIT) && (template.body forall treeInfo.isInterfaceMember)) mods | Flags.INTERFACE @@ -2056,7 +2057,7 @@ trait Parsers requires SyntaxAnalyzer { } /** TopStatSeq ::= [TopStat {StatementSeparator TopStat}] - * TopStat ::= AttributeClauses Modifiers TmplDef + * TopStat ::= Annotations Modifiers TmplDef * | Packaging * | Import * | @@ -2075,8 +2076,9 @@ trait Parsers requires SyntaxAnalyzer { in.token == CASEOBJECT || in.token == LBRACKET || isModifier) { - val attrs = attributeClauses() - stats ++ joinComment(List(tmplDef(modifiers() withAttributes attrs))) + val annots = annotations() + newLineOpt() + stats ++ joinComment(List(tmplDef(modifiers() withAnnotations annots))) } else if (in.token != SEMI && in.token != NEWLINE) { syntaxErrorOrIncomplete("expected class or object definition", true) } @@ -2087,8 +2089,8 @@ trait Parsers requires SyntaxAnalyzer { /** TemplateStatSeq ::= TemplateStat {StatementSeparator TemplateStat} * TemplateStat ::= Import - * | AttributeClauses Modifiers Def - * | AttributeClauses Modifiers Dcl + * | Annotations Modifiers Def + * | Annotations Modifiers Dcl * | Expr * | */ @@ -2100,8 +2102,9 @@ trait Parsers requires SyntaxAnalyzer { } else if (isExprIntro) { stats += expr() } else if (isDefIntro || isModifier || in.token == LBRACKET) { - val attrs = attributeClauses() - stats ++ joinComment(defOrDcl(modifiers() withAttributes attrs)) + val annots = annotations() + newLineOpt() + stats ++ joinComment(defOrDcl(modifiers() withAnnotations annots)) } else if (in.token != SEMI && in.token != NEWLINE) { syntaxErrorOrIncomplete("illegal start of definition", true) } @@ -2110,27 +2113,52 @@ trait Parsers requires SyntaxAnalyzer { stats.toList } - /** AttributeClauses ::= {AttributeClause} - * AttributeClause ::= `[' Attribute {`,' Attribute} `]' [NewLine] + /** Annotations ::= {Annotation} + * Annotation ::= `[' AnnotationExpr {`,' AnnotationExpr} `]' [NewLine] + * | `@' AnnotationExpr [NewLine] */ - def attributeClauses(): List[Attribute] = { - var attrs = new ListBuffer[Attribute] - while (in.token == LBRACKET) { - in.nextToken() - attrs += attribute() - while (in.token == COMMA) { + def annotations(): List[Annotation] = { + var annots = new ListBuffer[Annotation] + if (in.token == LBRACKET) { + while (in.token == LBRACKET) { in.nextToken() - attrs += attribute() + annots += annotation() + while (in.token == COMMA) { + in.nextToken() + annots += annotation() + } + accept(RBRACKET) + newLineOpt() + } + } else { + while (in.token == AT) { + in.nextToken() + annots += annotation() + newLineOpt() } - accept(RBRACKET) - newLineOpt() } - attrs.toList + annots.toList } - /** Attribute ::= StableId [TypeArgs] [`(' [Exprs] `)'] [`{' {NameValuePair} `}'] + /** TypeAttributes ::= {`[' Exprs `]'} + * + * Type attributes may be arbitrary expressions. */ - def attribute(): Attribute = { + def typeAttributes(): List[Tree] = { + val exps = new ListBuffer[Tree] + if (settings.Xplugtypes.value) { + while(in.token == LBRACKET) { + accept(LBRACKET) + exps ++= argExprs + accept(RBRACKET) + } + } + exps.toList + } + + /** Annotation ::= StableId [TypeArgs] [`(' [Exprs] `)'] [`{' {NameValuePair} `}'] + */ + def annotation(): Annotation = { def nameValuePair(): Tree = { accept(VAL) var pos = in.currentPos @@ -2154,28 +2182,7 @@ trait Parsers requires SyntaxAnalyzer { nvps.toList } else List() val constr = atPos(pos) { New(t, List(args)) } - glob.Attribute(constr, nameValuePairs) setPos pos - } - - /** TypeAttributes ::= (`[' Exprs `]') * - * - * Type attributes may be arbitrary expressions. - */ - def typeAttributes(): List[Tree] = { - val exps = new ListBuffer[Tree] - if (settings.Xplugtypes.value) { - while(in.token == LBRACKET) { - accept(LBRACKET) - exps ++= argExprs - accept(RBRACKET) - } - } else { - while (in.token == AT) { - val pos = in.skipToken() - exps += attribute() - } - } - exps.toList + Annotation(constr, nameValuePairs) setPos pos } /** RefineStatSeq ::= RefineStat {StatementSeparator RefineStat} diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index 4ee8350cdb..e09b18dfd8 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -103,8 +103,8 @@ abstract class TreeBuilder { case _ => AppliedTypeTree(scalaDot(newTypeName("Tuple" + trees.length)), trees) } - def makeAttributed(t: Tree, attr: Tree): Tree = attr match { - case Attribute(constr, elements) => Attributed(constr, elements, t) setPos attr.pos + def makeAnnotated(t: Tree, attr: Tree): Tree = attr match { + case Annotation(constr, elements) => Annotated(constr, elements, t) setPos attr.pos } /** If tree is a variable pattern, return Some("its name and type"). @@ -365,7 +365,7 @@ abstract class TreeBuilder { makeVisitor(cases, checkExhaustive, "x$") private def makeUnsealed(expr: Tree): Tree = - Attributed(New(scalaDot(definitions.UnsealedClass.name), List(List())), List(), expr) + Annotated(New(scalaDot(definitions.UnsealedClass.name), List(List())), List(), expr) /** Create visitor <x => x match cases> */ def makeVisitor(cases: List[CaseDef], checkExhaustive: boolean, prefix: String): Tree = { diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index d1491ff335..c43e9069a9 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -279,7 +279,7 @@ abstract class GenJVM extends SubComponent { buf.putShort(0xbaba.toShort) for (val AttrInfo(typ, consts, nvPairs) <- attributes; - typ.symbol isNonBottomSubClass definitions.ClassfileAttributeClass) { + typ.symbol isNonBottomSubClass definitions.ClassfileAnnotationClass) { nattr = nattr + 1 val jtype = javaType(typ) buf.putShort(cpool.addUtf8(jtype.getSignature()).toShort) @@ -313,7 +313,7 @@ abstract class GenJVM extends SubComponent { def addParamAnnotations(pattrss: List[List[AttrInfo]]): Unit = { val attributes = for (val attrs <- pattrss) yield for (val attr @ AttrInfo(tpe, _, _) <- attrs; - tpe.symbol isNonBottomSubClass definitions.ClassfileAttributeClass) yield attr; + tpe.symbol isNonBottomSubClass definitions.ClassfileAnnotationClass) yield attr; if (attributes.forall(.isEmpty)) return; val buf: ByteBuffer = ByteBuffer.allocate(2048) @@ -1345,7 +1345,7 @@ abstract class GenJVM extends SubComponent { def needsInterfaceCall(sym: Symbol): Boolean = sym.hasFlag(Flags.INTERFACE) || (sym.hasFlag(Flags.JAVA) && - sym.isNonBottomSubClass(definitions.ClassfileAttributeClass)) + sym.isNonBottomSubClass(definitions.ClassfileAnnotationClass)) def javaType(t: TypeKind): JType = t match { diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala index 9d2abb6aec..52934c95fc 100644 --- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala +++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala @@ -477,7 +477,7 @@ class SemanticTokens(val compiler: Global) { case tree : DocDef => build(tree.definition); case tree: Import => build(tree.expr) case tree: AppliedTypeTree => ; - case tree: Attributed => ; + case tree: Annotated => ; case tree: AttributedTypeTree => ; case tree: SingletonTypeTree => ; case tree: Super => ; diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index c6fcbee6c7..01d6437426 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -65,9 +65,9 @@ trait Definitions requires SymbolTable { // the scala reference classes var ScalaObjectClass: Symbol = _ def ScalaObjectClass_tag = getMember(ScalaObjectClass, nme.tag) - var AttributeClass: Symbol = _ - var ClassfileAttributeClass: Symbol = _ - var StaticAttributeClass: Symbol = _ + var AnnotationClass: Symbol = _ + var ClassfileAnnotationClass: Symbol = _ + var StaticAnnotationClass: Symbol = _ //var ChannelClass: Symbol = _ // def Channel_send = getMember(ChannelClass, nme.send) // def Channel_receive = getMember(ChannelClass, nme.receive) @@ -750,9 +750,9 @@ trait Definitions requires SymbolTable { // the scala reference classes ScalaObjectClass = getClass("scala.ScalaObject") - AttributeClass = getClass("scala.Attribute") - ClassfileAttributeClass = getClass("scala.ClassfileAttribute") - StaticAttributeClass = getClass("scala.StaticAttribute") + AnnotationClass = getClass("scala.Annotation") + ClassfileAnnotationClass = getClass("scala.ClassfileAnnotation") + StaticAnnotationClass = getClass("scala.StaticAnnotation") //ChannelClass = getClass("scala.distributed.Channel") //RemoteRefClass = getClass("scala.distributed.RemoteRef") if (!forCLDC && ! forMSIL) { @@ -894,7 +894,7 @@ trait Definitions requires SymbolTable { AnnotationDefaultAttr = newClass(RootClass, nme.AnnotationDefaultATTR, - List(AttributeClass.typeConstructor)) + List(AnnotationClass.typeConstructor)) SerializableAttr = getClass("scala.serializable") BeanPropertyAttr = if (forCLDC || forMSIL) null else getClass("scala.reflect.BeanProperty") DeprecatedAttr = getClass("scala.deprecated") diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index d995c0d082..8c0833e3bf 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -355,17 +355,17 @@ abstract class ClassfileParser { def parseClass(): unit = { val jflags = in.nextChar - val isAttribute = (jflags & JAVA_ACC_ANNOTATION) != 0 + val isAnnotation = (jflags & JAVA_ACC_ANNOTATION) != 0 var sflags = transFlags(jflags) if ((sflags & DEFERRED) != 0) sflags = sflags & ~DEFERRED | ABSTRACT val c = pool.getClassSymbol(in.nextChar) if (c != clazz) throw new IOException("class file '" + in.file + "' contains wrong " + c) - val superType = if (isAttribute) { in.nextChar; definitions.AttributeClass.tpe } + val superType = if (isAnnotation) { in.nextChar; definitions.AnnotationClass.tpe } else pool.getSuperClass(in.nextChar).tpe val ifaceCount = in.nextChar var ifaces = for (val i <- List.range(0, ifaceCount)) yield pool.getSuperClass(in.nextChar).tpe - if (isAttribute) ifaces = definitions.ClassfileAttributeClass.tpe :: ifaces + if (isAnnotation) ifaces = definitions.ClassfileAnnotationClass.tpe :: ifaces val parents = superType :: ifaces instanceDefs = newScope @@ -405,7 +405,7 @@ abstract class ClassfileParser { // If the annotation has an attribute with name 'value' // add a constructor for it - if (isAttribute) { + if (isAnnotation) { val value = instanceDefs.lookup(nme.value) if (value != NoSymbol) { instanceDefs.enter( diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index faa15d9c92..68c504eb30 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -112,8 +112,8 @@ abstract class Pickler extends SubComponent { putChildren(sym, sym.children) for (val attr <- sym.attributes.reverse) { - if (attr.atp.symbol isNonBottomSubClass definitions.StaticAttributeClass) - putAttribute(sym, attr) + if (attr.atp.symbol isNonBottomSubClass definitions.StaticAnnotationClass) + putAnnotation(sym, attr) } } else if (sym != NoSymbol) { putEntry(if (sym.isModuleClass) sym.name.toTermName else sym.name) @@ -173,7 +173,7 @@ abstract class Pickler extends SubComponent { children foreach putSymbol } - private def putAttribute(sym: Symbol, attr: AttrInfo): unit = { + private def putAnnotation(sym: Symbol, attr: AttrInfo): unit = { assert(putEntry{sym, attr}) putType(attr.atp) for (val c <- attr.args) putConstant(c) diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index e3b4fbd33e..162bc87d43 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -667,8 +667,8 @@ trait Namers requires Analyzer { case arg => error(arg.pos, "attribute argument needs to be a constant; found: "+arg) } val attrInfos = - for (val t @ Attribute(constr, elements) <- defn.mods.attributes) yield { - typer.typed(constr, EXPRmode | CONSTmode, AttributeClass.tpe) match { + for (val t @ Annotation(constr, elements) <- defn.mods.attributes) yield { + typer.typed(constr, EXPRmode | CONSTmode, AnnotationClass.tpe) match { case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) => val constrArgs = args map getConstant val attrScope = tpt.tpe.decls. diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 18c9adda86..b546d4b8d6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -880,7 +880,7 @@ trait Typers requires Analyzer { else typed(atPos(vdef.pos)(Select(This(value.owner), value)), EXPRmode, value.tpe)) result.tpt.asInstanceOf[TypeTree] setOriginal tpt /* setPos tpt.pos */ checkNoEscaping.privates(getter, result.tpt) - copy.DefDef(result, result.mods withAttributes vdef.mods.attributes, result.name, + copy.DefDef(result, result.mods withAnnotations vdef.mods.attributes, result.name, result.tparams, result.vparamss, result.tpt, result.rhs) } def setterDef: DefDef = { @@ -892,7 +892,7 @@ trait Typers requires Analyzer { else typed(Assign(Select(This(value.owner), value), Ident(vparamss.head.head))))) - copy.DefDef(result, result.mods withAttributes vdef.mods.attributes, result.name, + copy.DefDef(result, result.mods withAnnotations vdef.mods.attributes, result.name, result.tparams, result.vparamss, result.tpt, result.rhs) } val gs = if (mods hasFlag MUTABLE) List(getterDef, setterDef) @@ -902,8 +902,8 @@ trait Typers requires Analyzer { case DocDef(comment, defn) => addGetterSetter(defn) map (stat => DocDef(comment, stat)) - case Attributed(constr, elements, defn) => - addGetterSetter(defn) map (stat => Attributed(constr, elements, stat)) + case Annotated(constr, elements, defn) => + addGetterSetter(defn) map (stat => Annotated(constr, elements, stat)) case _ => List(stat) @@ -1536,7 +1536,7 @@ trait Typers requires Analyzer { } } - def typedAttribute(constr: Tree, elements: List[Tree]): AttrInfo = { + def typedAnnotation(constr: Tree, elements: List[Tree]): AttrInfo = { var attrError: Boolean = false; def error(pos: PositionType, msg: String): Null = { context.error(pos, msg) @@ -1548,7 +1548,7 @@ trait Typers requires Analyzer { case arg => error(arg.pos, "attribute argument needs to be a constant; found: "+arg) } val attrInfo = - typed(constr, EXPRmode | CONSTmode, AttributeClass.tpe) match { + typed(constr, EXPRmode | CONSTmode, AnnotationClass.tpe) match { case Apply(Select(New(tpt), nme.CONSTRUCTOR), args) => val constrArgs = args map getConstant val attrScope = tpt.tpe.decls @@ -1947,8 +1947,8 @@ trait Typers requires Analyzer { if (comments ne null) comments(defn.symbol) = comment ret - case Attributed(constr, elements, arg) => - val attrInfo = typedAttribute(constr, elements) + case Annotated(constr, elements, arg) => + val attrInfo = typedAnnotation(constr, elements) val arg1 = typed(arg, mode, pt) def attrType = TypeTree(arg1.tpe.withAttribute(attrInfo)) setOriginal tree |