summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-02 16:46:23 +0000
committerPaul Phillips <paulp@improving.org>2010-02-02 16:46:23 +0000
commitc8203f123f44057233cca331ceb2b823a1b67e6f (patch)
tree76cb436f9465f08bb8431a13199e45fbffa88608
parenta469bd96379a755c222ccb97d3eba610b020471c (diff)
downloadscala-c8203f123f44057233cca331ceb2b823a1b67e6f.tar.gz
scala-c8203f123f44057233cca331ceb2b823a1b67e6f.tar.bz2
scala-c8203f123f44057233cca331ceb2b823a1b67e6f.zip
Hid some AST nodes from the prying eyes of refl...
Hid some AST nodes from the prying eyes of reflectors. Now Parens, AssignOrNamedArg, and DocDef are known only to scalac. Also some cosmetic arranging in the new reflect.generic package, because there's never a better time than when the code is still warm from the compiler. Review by odersky.
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala31
-rwxr-xr-xsrc/library/scala/reflect/generic/Symbols.scala50
-rwxr-xr-xsrc/library/scala/reflect/generic/Trees.scala69
3 files changed, 71 insertions, 79 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 1e7e453da5..79e1a0777b 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -171,7 +171,6 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
override def setPos(pos: Position) = { assert(false); this }
}
-
def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef =
atPos(sym.pos) {
assert(sym != NoSymbol)
@@ -329,7 +328,22 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
def TypeTree(tp: Type): TypeTree = TypeTree() setType tp
- type AbsDocComment = DocComment
+ /** Documented definition, eliminated by analyzer */
+ case class DocDef(comment: DocComment, definition: Tree)
+ extends Tree {
+ override def symbol: Symbol = definition.symbol
+ override def symbol_=(sym: Symbol) { definition.symbol = sym }
+ // sean: seems to be important to the IDE
+ override def isDef = definition.isDef
+ }
+
+ /** Either an assignment or a named argument. Only appears in argument lists,
+ * eliminated by typecheck (doTypedApply)
+ */
+ case class AssignOrNamedArg(lhs: Tree, rhs: Tree)
+ extends TermTree
+
+ case class Parens(args: List[Tree]) extends Tree // only used during parsing
// ----- auxiliary objects and methods ------------------------------
@@ -851,6 +865,19 @@ trait Trees extends reflect.generic.Trees { self: SymbolTable =>
}
class Traverser extends super.Traverser {
+ /** Compiler specific tree types are handled here: the remainder are in
+ * the library's abstract tree traverser.
+ */
+ override def traverse(tree: Tree): Unit = tree match {
+ case AssignOrNamedArg(lhs, rhs) =>
+ traverse(lhs); traverse(rhs)
+ case DocDef(comment, definition) =>
+ traverse(definition)
+ case Parens(ts) =>
+ traverseTrees(ts)
+ case _ => super.traverse(tree)
+ }
+
/** The abstract traverser is not aware of Tree.isTerm, so we override this one.
*/
override def traverseStats(stats: List[Tree], exprOwner: Symbol) {
diff --git a/src/library/scala/reflect/generic/Symbols.scala b/src/library/scala/reflect/generic/Symbols.scala
index 4f6e4402b9..b503d14d4b 100755
--- a/src/library/scala/reflect/generic/Symbols.scala
+++ b/src/library/scala/reflect/generic/Symbols.scala
@@ -39,11 +39,7 @@ trait Symbols { self: Universe =>
else owner.enclClass.fullName(separator) + separator + encodedName
}
- private def stripLocalSuffix(s: String) =
- if (s endsWith nme.LOCAL_SUFFIX_STRING)
- s.substring(0, s.length - nme.LOCAL_SUFFIX_STRING.length)
- else
- s
+ private def stripLocalSuffix(s: String) = s stripSuffix nme.LOCAL_SUFFIX_STRING
/** The encoded full path name of this symbol, where outer names and inner names
* are separated by periods.
@@ -123,37 +119,37 @@ trait Symbols { self: Universe =>
final def isProtected = hasFlag(PROTECTED)
/** Is this symbol a sealed class? */
- final def isSealed = isClass && (hasFlag(SEALED) || definitions.isValueClass(this))
- final def isOverride = hasFlag(OVERRIDE)
- final def isCase = hasFlag(CASE)
+ def isTrait: Boolean = isClass && hasFlag(TRAIT) // refined later for virtual classes.
+ final def hasDefault = isParameter && hasFlag(DEFAULTPARAM)
final def isAbstractClass = isClass && hasFlag(ABSTRACT)
final def isAbstractOverride = isTerm && hasFlag(ABSTRACT) && hasFlag(OVERRIDE)
+ final def isBridge = hasFlag(BRIDGE)
+ final def isCase = hasFlag(CASE)
+ final def isCaseAccessor = hasFlag(CASEACCESSOR)
+ final def isContravariant = isType && hasFlag(CONTRAVARIANT)
+ final def isCovariant = isType && hasFlag(COVARIANT)
final def isDeferred = hasFlag(DEFERRED) && !isClass
+ final def isExistentiallyBound = isType && hasFlag(EXISTENTIAL)
+ final def isGetterOrSetter = hasFlag(ACCESSOR)
+ final def isInterface = hasFlag(INTERFACE)
+ final def isJavaDefined = hasFlag(JAVA)
+ final def isLazy = hasFlag(LAZY)
final def isMethod = isTerm && hasFlag(METHOD)
- final def isSourceMethod = isTerm && (flags & (METHOD | STABLE)) == METHOD // exclude all accessors!!!
final def isModule = isTerm && hasFlag(MODULE)
final def isModuleClass = isClass && hasFlag(MODULE)
- final def isInterface = hasFlag(INTERFACE)
final def isMutable = hasFlag(MUTABLE)
- final def isParameter = hasFlag(PARAM)
+ final def isOverloaded = hasFlag(OVERLOADED)
+ final def isOverride = hasFlag(OVERRIDE)
final def isPackage = isModule && hasFlag(PACKAGE)
final def isPackageClass = isClass && hasFlag(PACKAGE)
- final def isCovariant = isType && hasFlag(COVARIANT)
- final def isContravariant = isType && hasFlag(CONTRAVARIANT)
- final def isJavaDefined = hasFlag(JAVA)
- final def isSynthetic = hasFlag(SYNTHETIC)
- def isTrait: Boolean = isClass && hasFlag(TRAIT) // refined later for virtual classes.
- final def hasDefault = isParameter && hasFlag(DEFAULTPARAM)
- final def isBridge = hasFlag(BRIDGE)
- final def isGetterOrSetter = hasFlag(ACCESSOR)
- final def isSuperAccessor = hasFlag(SUPERACCESSOR)
final def isParamAccessor = hasFlag(PARAMACCESSOR)
- final def isCaseAccessor = hasFlag(CASEACCESSOR)
- final def isLazy = hasFlag(LAZY)
- final def isExistentiallyBound = isType && hasFlag(EXISTENTIAL)
- final def isTypeParameter = isType && isParameter && !isSkolem
+ final def isParameter = hasFlag(PARAM)
final def isRefinementClass = isClass && name == mkTypeName(nme.REFINE_CLASS_NAME)
- final def isOverloaded = hasFlag(OVERLOADED)
+ final def isSealed = isClass && (hasFlag(SEALED) || definitions.isValueClass(this))
+ final def isSourceMethod = isTerm && (flags & (METHOD | STABLE)) == METHOD // exclude all accessors!!!
+ final def isSuperAccessor = hasFlag(SUPERACCESSOR)
+ final def isSynthetic = hasFlag(SYNTHETIC)
+ final def isTypeParameter = isType && isParameter && !isSkolem
/** Is this symbol an implementation class for a mixin? */
final def isImplClass = isClass && hasFlag(IMPLCLASS)
@@ -174,7 +170,7 @@ trait Symbols { self: Universe =>
*/
def isEffectiveRoot = isRoot || isEmptyPackageClass
- // creators
+ // creators
def newValue(name: Name, pos: Position = NoPosition): Symbol
def newAbstractType(name: Name, pos: Position = NoPosition): Symbol
@@ -184,7 +180,7 @@ trait Symbols { self: Universe =>
def newMethod(name: Name, pos: Position = NoPosition): Symbol
def newModule(name: Name, clazz: Symbol, pos: Position = NoPosition): Symbol
- // access to related symbols
+ // access to related symbols
/** The next enclosing class */
def enclClass: Symbol = if (isClass) this else owner.enclClass
diff --git a/src/library/scala/reflect/generic/Trees.scala b/src/library/scala/reflect/generic/Trees.scala
index 8f639d388d..02f4f6eb35 100755
--- a/src/library/scala/reflect/generic/Trees.scala
+++ b/src/library/scala/reflect/generic/Trees.scala
@@ -22,23 +22,24 @@ trait Trees { self: Universe =>
* use the AnnotationInfo's (Symbol.annotations) in later phases.
*/
case class Modifiers(flags: Long, privateWithin: Name, annotations: List[Tree], positions: Map[Long, Position]) {
- def isCovariant = hasFlag(COVARIANT ) // marked with `+'
+ def isAbstract = hasFlag(ABSTRACT )
+ def isAccessor = hasFlag(ACCESSOR )
+ def isArgument = hasFlag(PARAM )
+ def isCase = hasFlag(CASE )
def isContravariant = hasFlag(CONTRAVARIANT) // marked with `-'
- def isPrivate = hasFlag(PRIVATE )
- def isProtected = hasFlag(PROTECTED)
- def isVariable = hasFlag(MUTABLE )
- def isArgument = hasFlag(PARAM )
- def isAccessor = hasFlag(ACCESSOR )
- def isOverride = hasFlag(OVERRIDE )
- def isAbstract = hasFlag(ABSTRACT )
- def isDeferred = hasFlag(DEFERRED )
- def isCase = hasFlag(CASE )
- def isLazy = hasFlag(LAZY )
- def isSealed = hasFlag(SEALED )
- def isFinal = hasFlag(FINAL )
- def isTrait = hasFlag(TRAIT )
- def isImplicit = hasFlag(IMPLICIT )
- def isPublic = !isPrivate && !isProtected
+ def isCovariant = hasFlag(COVARIANT ) // marked with `+'
+ def isDeferred = hasFlag(DEFERRED )
+ def isFinal = hasFlag(FINAL )
+ def isImplicit = hasFlag(IMPLICIT )
+ def isLazy = hasFlag(LAZY )
+ def isOverride = hasFlag(OVERRIDE )
+ def isPrivate = hasFlag(PRIVATE )
+ def isProtected = hasFlag(PROTECTED)
+ def isPublic = !isPrivate && !isProtected
+ def isSealed = hasFlag(SEALED )
+ def isTrait = hasFlag(TRAIT )
+ def isVariable = hasFlag(MUTABLE )
+
def hasFlag(flag: Long) = (flag & flags) != 0L
def & (flag: Long): Modifiers = {
val flags1 = flags & flag
@@ -57,9 +58,9 @@ trait Trees { self: Universe =>
}
def withAnnotations(annots: List[Tree]) =
if (annots.isEmpty) this
- else Modifiers(flags, privateWithin, annotations ::: annots, positions)
+ else copy(annotations = annotations ::: annots)
def withPosition(flag: Long, position: Position) =
- Modifiers(flags, privateWithin, annotations, positions + (flag -> position))
+ copy(positions = positions + (flag -> position))
}
def Modifiers(flags: Long, privateWithin: Name): Modifiers = Modifiers(flags, privateWithin, List(), new Map.EmptyMap)
@@ -69,7 +70,6 @@ trait Trees { self: Universe =>
abstract class Tree extends Product {
val id = nodeCount
-// assert(id != 1223)
nodeCount += 1
private[this] var rawpos: Position = NoPosition
@@ -489,8 +489,6 @@ trait Trees { self: Universe =>
traverse(expr)
case Annotated(annot, arg) =>
traverse(annot); traverse(arg)
- case DocDef(comment, definition) =>
- traverse(definition)
case Template(parents, self, body) =>
traverseTrees(parents)
if (!self.isEmpty) traverse(self)
@@ -515,8 +513,6 @@ trait Trees { self: Universe =>
}
case Assign(lhs, rhs) =>
traverse(lhs); traverse(rhs)
- case AssignOrNamedArg(lhs, rhs) =>
- traverse(lhs); traverse(rhs)
case If(cond, thenp, elsep) =>
traverse(cond); traverse(thenp); traverse(elsep)
case Match(selector, cases) =>
@@ -563,8 +559,6 @@ trait Trees { self: Universe =>
traverse(tpt); traverseTrees(whereClauses)
case SelectFromArray(qualifier, selector, erasure) =>
traverse(qualifier)
- case Parens(ts) =>
- traverseTrees(ts)
}
def traverseTrees(trees: List[Tree]) {
@@ -635,31 +629,6 @@ trait Trees { self: Universe =>
case class SelectFromArray(qualifier: Tree, name: Name, erasure: Type)
extends TermTree with RefTree { }
- /** Some shorter-lived tree types which we need to expose at this
- * level in order to have an abstract Tree traverser.
- */
-
- /** This one isn't even in ast.Trees, so it's 100% abstract. */
- type AbsDocComment
-
- /** Documented definition, eliminated by analyzer */
- case class DocDef(comment: AbsDocComment, definition: Tree)
- extends Tree {
- override def symbol: Symbol = definition.symbol
- override def symbol_=(sym: Symbol) { definition.symbol = sym }
- // sean: seems to be important to the IDE
- override def isDef = definition.isDef
- }
-
- /** Either an assignment or a named argument. Only appears in argument lists,
- * eliminated by typecheck (doTypedApply)
- */
- case class AssignOrNamedArg(lhs: Tree, rhs: Tree)
- extends TermTree
-
- case class Parens(args: List[Tree]) extends Tree // only used during parsing
-
-
/* A standard pattern match
case EmptyTree =>
case PackageDef(pid, stats) =>