summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLex Spoon <lex@lexspoon.org>2007-08-06 20:49:38 +0000
committerLex Spoon <lex@lexspoon.org>2007-08-06 20:49:38 +0000
commita00c8f75f17206b0a6f055d5db168415054aeb34 (patch)
tree369070030389a9cf433aaf7b0db6b825d6d433e0 /src
parente114becbc9f1de72b6dabc8c3c84d352187a61bb (diff)
downloadscala-a00c8f75f17206b0a6f055d5db168415054aeb34.tar.gz
scala-a00c8f75f17206b0a6f055d5db168415054aeb34.tar.bz2
scala-a00c8f75f17206b0a6f055d5db168415054aeb34.zip
- annotations can follow a type in addition to ...
- annotations can follow a type in addition to preceding it - annotations are traversed by tree Traverser's - the internal representation of declaration annotations is now type checkable
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala14
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala14
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala6
3 files changed, 19 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index d6d1033916..3681307413 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -755,7 +755,7 @@ trait Trees {
// used for tailcalls and like
case Import(expr, selectors) => (eliminated by typecheck)
// import expr.{selectors}
- case Annotation(constr, elements) => (eliminated by typecheck)
+ case Annotation(constr, elements) =>
// @constr(elements) where constr = tp(args), elements = { val x1 = c1, ..., val xn = cn }
case DocDef(comment, definition) => (eliminated by typecheck)
// /** comment */ definition
@@ -1338,7 +1338,7 @@ trait Trees {
class Traverser {
protected var currentOwner: Symbol = definitions.RootClass
- def traverse(tree: Tree): Unit = tree match {
+ def traverse(tree: Tree): Unit = tree match {
case EmptyTree =>
;
case PackageDef(name, stats) =>
@@ -1347,23 +1347,23 @@ trait Trees {
}
case ClassDef(mods, name, tparams, impl) =>
atOwner(tree.symbol) {
- traverseTrees(tparams); traverse(impl)
+ traverseTrees(mods.annotations); traverseTrees(tparams); traverse(impl)
}
case ModuleDef(mods, name, impl) =>
atOwner(tree.symbol.moduleClass) {
- traverse(impl)
+ traverseTrees(mods.annotations); traverse(impl)
}
case ValDef(mods, name, tpt, rhs) =>
atOwner(tree.symbol) {
- traverse(tpt); traverse(rhs)
+ traverseTrees(mods.annotations); traverse(tpt); traverse(rhs)
}
case DefDef(mods, name, tparams, vparamss, tpt, rhs) =>
atOwner(tree.symbol) {
- traverseTrees(tparams); traverseTreess(vparamss); traverse(tpt); traverse(rhs)
+ traverseTrees(mods.annotations); traverseTrees(tparams); traverseTreess(vparamss); traverse(tpt); traverse(rhs)
}
case TypeDef(mods, name, tparams, rhs) =>
atOwner(tree.symbol) {
- traverseTrees(tparams); traverse(rhs)
+ traverseTrees(mods.annotations); traverseTrees(tparams); traverse(rhs)
}
case LabelDef(name, params, rhs) =>
traverseTrees(params); traverse(rhs)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index eb176dca42..5c2ff33243 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -763,7 +763,7 @@ trait Parsers {
}
}
- /** AnnotType ::= Annotations SimpleType
+ /** AnnotType ::= Annotations SimpleType Annotations
* SimpleType ::= SimpleType TypeArgs
* | SimpleType `#' Id
* | StableId
@@ -772,7 +772,7 @@ trait Parsers {
* | WildcardType
*/
def annotType(isPattern: Boolean): Tree = {
- val annots = annotations()
+ val annots1 = annotations() // Q: deprecate annotations here?
val pos = inCurrentPos
val t: Tree = annotTypeRest(pos, isPattern,
@@ -790,6 +790,9 @@ trait Parsers {
case _ => convertToTypeId(r)
}
})
+
+ val annots2 = annotations()
+ val annots = annots1 ::: annots2
(t /: annots) (makeAnnotated)
}
@@ -1609,11 +1612,12 @@ trait Parsers {
*/
def annotation(): Annotation = {
def nameValuePair(): Tree = {
- accept(VAL)
var pos = inCurrentPos
- val aname = atPos(pos) { Ident(ident()) }
+ accept(VAL)
+ val aname = ident()
accept(EQUALS)
- atPos(pos) { Assign(aname, stripParens(prefixExpr())) }
+ val rhs = stripParens(prefixExpr())
+ atPos(pos) { ValDef(NoMods, aname, TypeTree(), rhs) }
}
val pos = inCurrentPos
var t: Tree = convertToTypeId(stableId())
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 5979cd3add..96238bd76e 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1728,12 +1728,12 @@ trait Typers { self: Analyzer =>
names.retain(sym => sym.name != nme.value)
}
val nvPairs = annot.elements map {
- case Assign(ntree @ Ident(name), rhs) => {
+ case vd @ ValDef(_, name, _, rhs) => {
val sym = attrScope.lookup(name);
if (sym == NoSymbol) {
- error(ntree.pos, "unknown attribute element name: " + name)
+ error(vd.pos, "unknown attribute element name: " + name)
} else if (!names.contains(sym)) {
- error(ntree.pos, "duplicate value for element " + name)
+ error(vd.pos, "duplicate value for element " + name)
} else {
names -= sym
val annArg =