summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcremet <cremet@epfl.ch>2004-03-08 18:44:45 +0000
committercremet <cremet@epfl.ch>2004-03-08 18:44:45 +0000
commitfce53bc99b7d378beb7fa0ca91ef7ee9dd633e72 (patch)
treef70bac934eafd04b2aecaf9fbb0a14566aacb9a8
parenta4737b5704f2f38a3a9971c0bfbec41d2e1b69d3 (diff)
downloadscala-fce53bc99b7d378beb7fa0ca91ef7ee9dd633e72.tar.gz
scala-fce53bc99b7d378beb7fa0ca91ef7ee9dd633e72.tar.bz2
scala-fce53bc99b7d378beb7fa0ca91ef7ee9dd633e72.zip
- Added a node DocDef for documentation comments.
- Fixed a bug that made an error when stopping the compiler after phase "analyze".
-rw-r--r--sources/scala/tools/scalac/ast/parser/Parser.scala20
-rw-r--r--sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala5
-rw-r--r--sources/scala/tools/scalac/typechecker/Analyzer.scala15
-rw-r--r--sources/scala/tools/scalac/typechecker/DeSugarize.scala53
-rw-r--r--sources/scala/tools/scaladoc/Location.java4
-rw-r--r--sources/scala/tools/scaladoc/ScalaSearch.java12
-rw-r--r--sources/scalac/Global.java4
-rw-r--r--sources/scalac/symtab/Symbol.java4
8 files changed, 59 insertions, 58 deletions
diff --git a/sources/scala/tools/scalac/ast/parser/Parser.scala b/sources/scala/tools/scalac/ast/parser/Parser.scala
index d0c3169b36..3c214803ef 100644
--- a/sources/scala/tools/scalac/ast/parser/Parser.scala
+++ b/sources/scala/tools/scalac/ast/parser/Parser.scala
@@ -157,10 +157,6 @@ class Parser(unit: Unit) {
/////// COMMENT COLLECTION ///////////////////////////////////////////////////
- /** keep the comments associated with a given tree
- */
- protected val mapTreeComment: Map = unit.global.mapTreeComment;
-
/** stack of comments
*/
protected val commentStack = new Stack();
@@ -180,12 +176,16 @@ class Parser(unit: Unit) {
/** pop a comment from the stack and associate it with the given tree
*/
- protected def popComment(tree: Tree): Tree = {
- if (local == 0)
- if (!commentStack.empty())
- mapTreeComment.put(tree, commentStack.pop().asInstanceOf[String]);
- tree
- }
+ protected def popComment(tree: Tree): Tree =
+ if ((local == 0) && !commentStack.empty()) {
+ val comment = commentStack.pop().asInstanceOf[String];
+ if (comment != null)
+ make.DocDef(tree.pos, comment, tree)
+ else
+ tree
+ }
+ else
+ tree;
/////// TREE CONSTRUCTION ////////////////////////////////////////////////////
diff --git a/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala b/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala
index 618c74da9f..75312d5f2e 100644
--- a/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala
+++ b/sources/scala/tools/scalac/ast/printer/TextTreePrinter.scala
@@ -227,6 +227,11 @@ class TextTreePrinter(writer: PrintWriter) with TreePrinter {
case Tree.Empty =>
print(TXT_EMPTY);
+ case Tree$DocDef(comment, definition) =>
+ print(comment);
+ printNewLine();
+ print(definition);
+
case Tree$ClassDef(mods, name, tparams, vparams, tpe, impl) =>
printModifiers(mods);
print(if ((mods & Modifiers.INTERFACE) != 0) KW_INTERFACE else KW_CLASS);
diff --git a/sources/scala/tools/scalac/typechecker/Analyzer.scala b/sources/scala/tools/scalac/typechecker/Analyzer.scala
index 420e2d25df..0558360c1f 100644
--- a/sources/scala/tools/scalac/typechecker/Analyzer.scala
+++ b/sources/scala/tools/scalac/typechecker/Analyzer.scala
@@ -776,11 +776,6 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer(
}
tree.setSymbol(sym);
- // set the comment associated with a symbol
- val comment: String = global.mapTreeComment.get(tree).asInstanceOf[String];
- if (comment != null)
- global.mapSymbolComment.put(sym, new Pair(comment, unit));
-
sym
}
@@ -822,7 +817,9 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer(
}
case Tree$DocDef(comment, definition) =>
- outerEnterSym(definition)
+ val sym = outerEnterSym(definition);
+ global.mapSymbolComment.put(sym, new Pair(comment, unit));
+ sym
case Tree$ClassDef(mods, name, tparams, vparams, _, templ) =>
val clazz: ClassSymbol = ClassSymbol.define(
@@ -1977,12 +1974,6 @@ class Analyzer(global: scalac_Global, descr: AnalyzerPhase) extends Transformer(
tree.setType(Type.NoType)
case Tree$DocDef(comment, definition) =>
- val defined = definition match {
- case Tree$PackageDef(pkg, _) => pkg.symbol()
- case _ => definition.symbol()
- }
- assert(defined != null, tree);
- global.mapSymbolComment.put(defined, new Pair(comment, unit));
transform(definition)
case Tree$PackageDef(pkg, templ @ Tree$Template(parents, body)) =>
diff --git a/sources/scala/tools/scalac/typechecker/DeSugarize.scala b/sources/scala/tools/scalac/typechecker/DeSugarize.scala
index 7ed101309d..7df53c18c6 100644
--- a/sources/scala/tools/scalac/typechecker/DeSugarize.scala
+++ b/sources/scala/tools/scalac/typechecker/DeSugarize.scala
@@ -234,15 +234,23 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
make.Apply(tree.pos, update, args1);
}
- /** make a set of trees share the same documentation comment as a
- * given tree (used for pattern and val definitions)
+ /** Remove the DocDef shell, if any.
*/
- def shareComment(trees: Array[Tree], tree: Tree): Array[Tree] = {
- val comment: String = global.mapTreeComment.get(tree).asInstanceOf[String];
- if (comment != null)
- for (val i <- Iterator.range(0, trees.length))
- global.mapTreeComment.put(trees(i), comment);
- trees;
+ def unboxDocDef(tree: Tree): Tree = tree match {
+ case Tree$DocDef(_, definition) => definition
+ case _ => tree
+ }
+
+ /** If "tree" is a DocDef, add its comment to "trees".
+ */
+ def boxDocDef(trees: Array[Tree], tree: Tree): Array[Tree] = {
+ tree match {
+ case Tree$DocDef(comment, _) =>
+ for (val i <- Iterator.range(0, trees.length))
+ trees(i) = make.DocDef(tree.pos, comment, trees(i))
+ case _ =>
+ }
+ trees
}
/** expand pattern definitions and variable definitions in templates.
@@ -251,7 +259,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
var change: boolean = false;
var i = 0;
while (i < stats.length && !change) {
- stats(i) match {
+ unboxDocDef(stats(i)) match {
case Tree$PatDef(_, _, _) =>
change = true;
case Tree$ValDef(_, _, _, _) =>
@@ -263,12 +271,13 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
if (change) {
val ts: TreeList = new TreeList();
for (val i <- Iterator.range(0, stats.length)) {
- stats(i) match {
+ val stat = unboxDocDef(stats(i));
+ stat match {
case Tree$PatDef(_, _, _) =>
- ts.append(Statements(this.PatDef(stats(i)), isLocal));
+ ts.append(boxDocDef(Statements(this.PatDef(stat), isLocal), stats(i)));
case Tree$ValDef(_, _, _, _) =>
if (isLocal) ts.append(stats(i))
- else ts.append(this.ValDef(stats(i)));
+ else ts.append(boxDocDef(this.ValDef(stat), stats(i)));
case _ =>
ts.append(stats(i));
}
@@ -300,15 +309,11 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
def PatDef(tree: Tree): Array[Tree] = tree match {
case Tree$PatDef(mods, Tree$Ident(name), rhs) =>
// val x = e ==> val x = e
- shareComment(
- NewArray.Tree(make.ValDef(tree.pos, mods, name, Tree.Empty, rhs)),
- tree);
+ NewArray.Tree(make.ValDef(tree.pos, mods, name, Tree.Empty, rhs))
case Tree$PatDef(mods, Tree$Typed(Tree$Ident(name), tpe), rhs) =>
// val x: T = e ==> val x: T = e
- shareComment(
- NewArray.Tree(make.ValDef(tree.pos, mods, name, tpe, rhs)),
- tree);
+ NewArray.Tree(make.ValDef(tree.pos, mods, name, tpe, rhs))
case Tree$PatDef(mods, pat, rhs) =>
val pos: int = tree.pos;
@@ -340,7 +345,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
// val x_1 = e.match (case p => x_1)
val valdef: Tree = make.ValDef(pos, mods, vars(0), Tree.Empty, match);
print(pat, "patdef", valdef);
- shareComment(NewArray.Tree(valdef), tree);
+ NewArray.Tree(valdef)
} else {
// t$
val vble: Name = getvar();
@@ -355,7 +360,7 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
make.Select(pos, make.Ident(pos, vble), tupleSelectorName(i + 1)));
}
print(pat, "patdef", new Tree$Block(res, gen.mkUnitLit(pos)));//debug
- shareComment(res, tree);
+ res
}
}
@@ -375,9 +380,9 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
else make.Ident(tree.pos, valname));
if ((mods1 & MUTABLE) == 0) {
if ((mods1 & DEFERRED) != 0)
- shareComment(NewArray.Tree(getter), tree);
+ NewArray.Tree(getter)
else
- shareComment(NewArray.Tree(valdef1, getter), tree);
+ NewArray.Tree(valdef1, getter)
} else {
val setter: Tree = make.DefDef(
tree.pos, mods1, setterName(name),
@@ -394,9 +399,9 @@ class DeSugarize(make: TreeFactory, copy: TreeCopier, gen: TreeGen, infer: scala
make.Ident(tree.pos, valname),
make.Ident(tree.pos, parameterName(0))));
if ((mods1 & DEFERRED) != 0)
- shareComment(NewArray.Tree(getter, setter), tree);
+ NewArray.Tree(getter, setter)
else
- shareComment(NewArray.Tree(valdef1, getter, setter), tree);
+ NewArray.Tree(valdef1, getter, setter)
}
}
diff --git a/sources/scala/tools/scaladoc/Location.java b/sources/scala/tools/scaladoc/Location.java
index 69ba4af8d9..c97e4d9ea7 100644
--- a/sources/scala/tools/scaladoc/Location.java
+++ b/sources/scala/tools/scaladoc/Location.java
@@ -24,8 +24,8 @@ public class Location {
static public final String ROOT_NAME = "root-page";
static public final String HTML_SUFFIX = ".html";
- //static public final String CLASS_SUFFIX = "-class";
- static public final String CLASS_SUFFIX = "(class)";
+ static public final String CLASS_SUFFIX = "-class";
+ //static public final String CLASS_SUFFIX = "(class)";
/////////////////// UNIQUE URL //////////////////////
diff --git a/sources/scala/tools/scaladoc/ScalaSearch.java b/sources/scala/tools/scaladoc/ScalaSearch.java
index 38b927b296..46450dc41f 100644
--- a/sources/scala/tools/scaladoc/ScalaSearch.java
+++ b/sources/scala/tools/scaladoc/ScalaSearch.java
@@ -570,11 +570,13 @@ public class DocSyms {
}
);
// add all super packages.
- Symbol owner = pack.owner();
- while (!owner.isRoot()) {
- syms.add(owner.module());
- owner = owner.owner();
- }
+ if (!pack.isRoot()) {
+ Symbol owner = pack.owner();
+ while (!owner.isRoot()) {
+ syms.add(owner.module());
+ owner = owner.owner();
+ }
+ }
}
}
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java
index 5a02a5a435..bf95540e99 100644
--- a/sources/scalac/Global.java
+++ b/sources/scalac/Global.java
@@ -96,10 +96,6 @@ public abstract class Global {
public final PrintWriter writer;
public final TreePrinter treePrinter;
- /** documentation comments of trees
- */
- public final Map/*<Tree, String>*/ mapTreeComment = new HashMap();
-
/** documentation comments of symbols
*/
public final Map/*<Symbol, String>*/ mapSymbolComment = new HashMap();
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 6dbe109d21..03966f10b1 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -1859,7 +1859,9 @@ public class ClassSymbol extends TypeSymbol {
public Type thisType() {
Global global = Global.instance;
- if (global.currentPhase.id > global.PHASE.ERASURE.id()) return type();
+ if (global.currentPhase.id > global.PHASE.ERASURE.id())
+ if (!global.PHASE.ERASURE.hasSkipFlag())
+ return type();
return thistp;
}