summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-08-15 16:27:10 +0000
committerMartin Odersky <odersky@gmail.com>2008-08-15 16:27:10 +0000
commit20a3e4ee457e61d3f695b794260b5a1e1e0156e9 (patch)
tree4a202ce58be5e09fa27881462d30dffba7fcf47c /src
parentd82034554088b25d30ae9dcdae5146b5351e7fc5 (diff)
downloadscala-20a3e4ee457e61d3f695b794260b5a1e1e0156e9.tar.gz
scala-20a3e4ee457e61d3f695b794260b5a1e1e0156e9.tar.bz2
scala-20a3e4ee457e61d3f695b794260b5a1e1e0156e9.zip
Buffer gets vararg +, += methods; small fixes.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala39
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala22
-rw-r--r--src/compiler/scala/tools/nsc/matching/TransMatcher.scala8
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Flags.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala1
-rw-r--r--src/library/scala/collection/mutable/Buffer.scala22
8 files changed, 81 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index fec56256fc..6031a3b643 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -76,7 +76,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
object analysis extends {
val global: Global.this.type = Global.this
- } with TypeFlowAnalysis
+ } with TypeFlowAnalysis
object copyPropagation extends {
val global: Global.this.type = Global.this
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index 32d7573a6a..5a12ed2f00 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -499,6 +499,8 @@ trait Trees {
*/
case class Import(expr: Tree, selectors: List[(Name, Name)])
extends SymTree
+ // The symbol of an Import is an import symbol @see Symbol.newImport
+ // It's used primarily as a marker to check thta the import has been typechecked.
/** Annotation application (constructor arguments + name-value pairs) */
case class Annotation(constr: Tree, elements: List[Tree])
@@ -515,13 +517,23 @@ trait Trees {
override def isType = definition.isType
}
- /** Instantiation template
+ /** Instantiation template of a class or trait
*
* @param parents
* @param body
*/
case class Template(parents: List[Tree], self: ValDef, body: List[Tree])
extends SymTree {
+ // the symbol of a template is a local dummy. @see Symbol.newLocalDummy
+ // the owner of the local dummy is the enclosing trait or class.
+ // the local dummy is itself the owner of any local blocks
+ // For example:
+ //
+ // class C {
+ // def foo // owner is C
+ // {
+ // def bar // owner is local dummy
+ // }
// System.err.println("TEMPLATE: " + parents)
}
@@ -621,6 +633,8 @@ trait Trees {
/** Anonymous function, eliminated by analyzer */
case class Function(vparams: List[ValDef], body: Tree)
extends TermTree with SymTree
+ // The symbol of a Function is a synthetic value of name nme.ANON_FUN_NAME
+ // It is the owner of the function's parameters.
/** Assignment */
case class Assign(lhs: Tree, rhs: Tree)
@@ -652,6 +666,7 @@ trait Trees {
/** Return expression */
case class Return(expr: Tree)
extends TermTree with SymTree
+ // The symbol of a Return node is the enclosing method.
case class Try(block: Tree, catches: List[CaseDef], finalizer: Tree)
extends TermTree
@@ -671,6 +686,8 @@ trait Trees {
}
/** Factory method for object creation <code>&lt;new tpt(args_1)...(args_n)&gt;</code>.
+ * A New(t, as) is expanded to:
+ * (new t).<init>(as)
*
* @param tpt ...
* @param argss ...
@@ -686,6 +703,8 @@ trait Trees {
case class Typed(expr: Tree, tpt: Tree)
extends TermTree
+ // Martin to Sean: Should GenericApply/TypeApply/Apply not be SymTree's? After all,
+ // ApplyDynamic is a SymTree.
abstract class GenericApply extends TermTree {
val fun: Tree
val args: List[Tree]
@@ -713,20 +732,25 @@ trait Trees {
*/
case class ApplyDynamic(qual: Tree, args: List[Tree])
extends TermTree with SymTree
+ // The symbol of an ApplyDynamic is the function symbol of `qual', or NoSymbol, if there is none.
/** Super reference */
case class Super(qual: Name, mix: Name)
extends TermTree with SymTree
+ // The symbol of a Super is the class _from_ which the super reference is made.
+ // For instance in C.super(...), it would be C.
def Super(sym: Symbol, mix: Name): Tree = Super(sym.name, mix) setSymbol sym
/** Self reference */
case class This(qual: Name)
extends TermTree with SymTree
+ // The symbol of a This is the class to which the this refers.
+ // For instance in C.this, it would be C.
def This(sym: Symbol): Tree = This(sym.name) setSymbol sym
- /** Designator */
+ /** Designator <qualifier> . <selector> */
case class Select(qualifier: Tree, selector: Name)
extends SymTree {
override def isTerm = selector.isTermName
@@ -736,7 +760,7 @@ trait Trees {
def Select(qualifier: Tree, sym: Symbol): Select =
Select(qualifier, sym.name) setSymbol sym
- /** Identifier */
+ /** Identifier <name> */
case class Ident(name: Name)
extends SymTree {
override def isTerm = name.isTermName
@@ -788,15 +812,15 @@ trait Trees {
case class SingletonTypeTree(ref: Tree)
extends TypTree
- /** Type selection, eliminated by RefCheck */
+ /** Type selection <qualifier> # <selector>, eliminated by RefCheck */
case class SelectFromTypeTree(qualifier: Tree, selector: Name)
extends TypTree with SymTree
- /** Intersection type, eliminated by RefCheck */
+ /** Intersection type <parent1> with ... with <parentN> { <decls> }, eliminated by RefCheck */
case class CompoundTypeTree(templ: Template)
extends TypTree
- /** Applied type, eliminated by RefCheck */
+ /** Applied type <tpt> [ <args> ], eliminated by RefCheck */
case class AppliedTypeTree(tpt: Tree, args: List[Tree])
extends TypTree {
override def symbol: Symbol = tpt.symbol
@@ -813,6 +837,7 @@ trait Trees {
def underlying : AnyRef
override def equalsStructure0(that: Tree)(f : (Tree,Tree) => Boolean): Boolean = this eq that
}
+
/* A standard pattern match
case EmptyTree =>
case PackageDef(name, stats) =>
@@ -1603,7 +1628,7 @@ trait Trees {
}
object posAssigner extends Traverser {
- var pos: Position = _
+ private var pos: Position = _
override def traverse(t: Tree) {
if (t != EmptyTree && t.pos == NoPosition) {
t.setPos(pos)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 6fd2c94c1a..ed68e42341 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -1992,7 +1992,6 @@ trait Parsers extends NewScanners with MarkupParsers {
/** VarDef ::= PatDef
* | Id {`,' Id} `:' Type `=' `_'
* VarDcl ::= Id {`,' Id} `:' Type
- */
def varDefOrDcl(mods: Modifiers): List[Tree] = {
var newmods = mods | Flags.MUTABLE
val lhs = new ListBuffer[(Int, Name)]
@@ -2021,6 +2020,7 @@ trait Parsers extends NewScanners with MarkupParsers {
} else ValDef(newmods, name, tp.duplicate, rhs.duplicate)
}
}
+ */
/** FunDef ::= FunSig `:' Type `=' Expr
* | FunSig [nl] `{' Block `}'
@@ -2029,7 +2029,7 @@ trait Parsers extends NewScanners with MarkupParsers {
* FunSig ::= id [FunTypeParamClause] ParamClauses
*/
def funDefOrDcl(mods: Modifiers): Tree = {
- var pos = inSkipToken
+ var pos = inSkipToken // position of `def'
if (inToken == THIS) {
atPos(inCurrentPos) {
inNextToken
@@ -2045,6 +2045,8 @@ trait Parsers extends NewScanners with MarkupParsers {
val name = ident()
if (name != nme.ERROR) pos = namePos
atPos(pos) {
+ // implicitViewBuf is for view bounded type parameters of the form
+ // [T <% B]; it contains the equivalent implicit parameter, i.e. (implicit p: T => B)
val implicitViewBuf = new ListBuffer[Tree]
val tparams = typeParamClauseOpt(name, implicitViewBuf)
val vparamss = paramClauses(name, implicitViewBuf.toList, false)
@@ -2325,6 +2327,7 @@ trait Parsers extends NewScanners with MarkupParsers {
/** Packaging ::= package QualId [nl] `{' TopStatSeq `}'
*/
def packaging(): Tree = {
+
val pkgPos = accept(PACKAGE)
val pkg = qualId()
val pos = if (pkg.pos != NoPosition) pkg.pos else i2p(pkgPos)
@@ -2436,7 +2439,20 @@ trait Parsers extends NewScanners with MarkupParsers {
stats.toList
}
- /** overridable IDE hook for local definitions of blockStatSeq */
+ /** overridable IDE hook for local definitions of blockStatSeq
+ * Here's an idea how to fill in start and end positions.
+ def localDef : List[Tree] = {
+ atEndPos {
+ atStartPos(inCurrentPos) {
+ val annots = annotations(true)
+ val mods = localModifiers() withAnnotations annots
+ if (!(mods hasFlag ~(Flags.IMPLICIT | Flags.LAZY))) defOrDcl(mods)
+ else List(tmplDef(mods))
+ }
+ } (inCurrentPos)
+ }
+ */
+
def localDef : List[Tree] = {
val annots = annotations(true)
val mods = localModifiers() withAnnotations annots
diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
index a84de60527..941d669438 100644
--- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
+++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala
@@ -182,7 +182,7 @@ trait TransMatcher { self: transform.ExplicitOuter with PatternNodes with Parall
}
implicit val rep = new RepFactory(handleOuter)
-// try {
+ try {
val tmps = new ListBuffer[Symbol]
val vds = new ListBuffer[Tree]
var root:Symbol = newVar(selector.pos, selector.tpe)
@@ -238,9 +238,9 @@ trait TransMatcher { self: transform.ExplicitOuter with PatternNodes with Parall
dfatree = rep.cleanup(dfatree)
resetTrav.traverse(dfatree)
dfatree
-// } catch {
-// case e => e.printStackTrace(); throw new FatalError(e.getMessage())
-// }
+ } catch {
+ case ex: FatalError => ex.printStackTrace(); throw ex
+ }
}
}
diff --git a/src/compiler/scala/tools/nsc/symtab/Flags.scala b/src/compiler/scala/tools/nsc/symtab/Flags.scala
index 41371570f8..4d4bb4c70f 100644
--- a/src/compiler/scala/tools/nsc/symtab/Flags.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Flags.scala
@@ -24,7 +24,7 @@ object Flags extends Enumeration {
final val DEFERRED = 0x00000100 // was `abstract' for members
final val METHOD = 0x00000200 // a method
final val MODULE = 0x00000400 // symbol is module or class implementing a module
- final val INTERFACE = 0x00000800 // symbol is an interface
+ final val INTERFACE = 0x00000800 // symbol is an interface (i.e. a trait which defines only abstract methods)
final val MUTABLE = 0x00001000 // symbol is a mutable variable.
final val PARAM = 0x00002000 // symbol is a (value or type) parameter to a method
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 20290acfb8..6dfc4b9002 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -426,8 +426,8 @@ trait Types {
}
*/
case tp =>
-// if (sym.name.toString == "c") print(this + ".memberType(" + sym +":" + sym.tpe +")" + sym.ownerChain);//debug
val res = tp.asSeenFrom(this, sym.owner)
+// if (sym.name.toString == "emitSWITCH") println(this + ".memberType(" + sym +":" + sym.tpe +")" + sym.ownerChain + " = " + res);//debug
res
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 61a8533abd..e03451acc9 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -583,6 +583,7 @@ trait Contexts { self: Analyzer =>
/** The prefix expression */
def qual: Tree = tree.symbol.info match {
case ImportType(expr) => expr
+ case ErrorType => tree
case _ => throw new FatalError("symbol " + tree.symbol + " has bad type: " + tree.symbol.info);//debug
}
diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala
index 9d35ab0bed..cbe594bca1 100644
--- a/src/library/scala/collection/mutable/Buffer.scala
+++ b/src/library/scala/collection/mutable/Buffer.scala
@@ -35,6 +35,18 @@ trait Buffer[A] extends AnyRef
*/
def +=(elem: A): Unit
+ /** Append a two or more elements to this buffer.
+ *
+ * @param elem1 the first element to append.
+ * @param elem2 the second element to append.
+ * @param elems the remaining elements to append.
+ */
+ def +=(elem1: A, elem2: A, elems: A*): Unit = {
+ this += elem1
+ this += elem2
+ this ++= elems
+ }
+
/** Append a single element to this buffer and return
* the identity of the buffer.
*
@@ -42,6 +54,16 @@ trait Buffer[A] extends AnyRef
*/
def +(elem: A): Buffer[A] = { this += elem; this }
+ /** Append two or more elements to this buffer and return
+ * the identity of the buffer.
+ *
+ * @param elem1 the first element to append.
+ * @param elem2 the second element to append.
+ * @param elems the remaining elements to append.
+ */
+ def +(elem1: A, elem2: A, elems: A*): Buffer[A] =
+ this + elem1 + elem2 ++ elems
+
/** Prepend a single element to this buffer and return
* the identity of the buffer.
*