Skip to content

Commit 539294f

Browse files
committed
Factor out NamedDefTrees from DefTrees
1 parent 7045ea8 commit 539294f

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Compiler {
4040
List(new YCheckPositions) :: // YCheck positions
4141
List(new Staging) :: // Check PCP, heal quoted types and expand macros
4242
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
43-
List(new semanticdb.ExtractSemanticDB) ::
43+
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files
4444
List(new PostTyper) :: // Additional checks and cleanups after type checking
4545
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
4646
List(new SetRootTree) :: // Set the `rootTreeOrProvider` on class symbols

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -332,28 +332,17 @@ object Trees {
332332
def namedType: NamedType = tpe.asInstanceOf[NamedType]
333333
}
334334

335-
/** Tree defines a new symbol and carries modifiers.
336-
* The position of a MemberDef contains only the defined identifier or pattern.
337-
* The envelope of a MemberDef contains the whole definition and has its point
338-
* on the opening keyword (or the next token after that if keyword is missing).
339-
*/
340-
abstract class MemberDef[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T] with DefTree[T] {
341-
type ThisTree[-T >: Untyped] <: MemberDef[T]
342-
343-
def rawComment: Option[Comment] = getAttachment(DocComment)
344-
345-
def setComment(comment: Option[Comment]): this.type = {
346-
comment.map(putAttachment(DocComment, _))
347-
this
348-
}
335+
abstract class NamedDefTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T] with DefTree[T] {
336+
type ThisTree[-T >: Untyped] <: NamedDefTree[T]
349337

350338
/** The position of the name defined by this definition.
351339
* This is a point position if the definition is synthetic, or a range position
352340
* if the definition comes from source.
353341
* It might also be that the definition does not have a position (for instance when synthesized by
354342
* a calling chain from `viewExists`), in that case the return position is NoSpan.
343+
* Overridden in Bind
355344
*/
356-
def nameSpan: Span =
345+
def nameSpan: Span =
357346
if (span.exists) {
358347
val point = span.point
359348
if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Span(point)
@@ -378,6 +367,22 @@ object Trees {
378367
else span
379368
}
380369

370+
/** Tree defines a new symbol and carries modifiers.
371+
* The position of a MemberDef contains only the defined identifier or pattern.
372+
* The envelope of a MemberDef contains the whole definition and has its point
373+
* on the opening keyword (or the next token after that if keyword is missing).
374+
*/
375+
abstract class MemberDef[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NamedDefTree[T] {
376+
type ThisTree[-T >: Untyped] <: MemberDef[T]
377+
378+
def rawComment: Option[Comment] = getAttachment(DocComment)
379+
380+
def setComment(comment: Option[Comment]): this.type = {
381+
comment.map(putAttachment(DocComment, _))
382+
this
383+
}
384+
}
385+
381386
/** A ValDef or DefDef tree */
382387
abstract class ValOrDefDef[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends MemberDef[T] with WithLazyField[Tree[T]] {
383388
type ThisTree[-T >: Untyped] <: ValOrDefDef[T]
@@ -704,10 +709,13 @@ object Trees {
704709

705710
/** name @ body */
706711
case class Bind[-T >: Untyped] private[ast] (name: Name, body: Tree[T])(implicit @constructorOnly src: SourceFile)
707-
extends NameTree[T] with DefTree[T] with PatternTree[T] {
712+
extends NamedDefTree[T] with PatternTree[T] {
708713
type ThisTree[-T >: Untyped] = Bind[T]
709714
override def isType: Boolean = name.isTypeName
710715
override def isTerm: Boolean = name.isTermName
716+
717+
override def nameSpan: Span =
718+
if span.exists then Span(span.start, span.start + name.toString.length) else span
711719
}
712720

713721
/** tree_1 | ... | tree_n */
@@ -940,6 +948,7 @@ object Trees {
940948
type NameTree = Trees.NameTree[T]
941949
type RefTree = Trees.RefTree[T]
942950
type DefTree = Trees.DefTree[T]
951+
type NamedDefTree = Trees.NamedDefTree[T]
943952
type MemberDef = Trees.MemberDef[T]
944953
type ValOrDefDef = Trees.ValOrDefDef[T]
945954
type LazyTree = Trees.LazyTree[T]

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Interactive {
6767

6868
/** Does this tree define a symbol ? */
6969
def isDefinition(tree: Tree): Boolean =
70-
tree.isInstanceOf[DefTree with NameTree]
70+
tree.isInstanceOf[NamedDefTree]
7171

7272
/** The type of the closest enclosing tree with a type containing position `pos`. */
7373
def enclosingType(trees: List[SourceTree], pos: SourcePosition)(implicit ctx: Context): Type = {

0 commit comments

Comments
 (0)