From 41ffd1b8e70e0e4c2017aca9145878cb456ae7dd Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sat, 21 Nov 2020 13:58:11 +0100 Subject: [PATCH] Make standard section names part of TastyFormat --- .../src/dotty/tools/dotc/core/tasty/CommentPickler.scala | 3 ++- .../src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala | 7 ++++--- .../src/dotty/tools/dotc/core/tasty/PositionPickler.scala | 4 ++-- .../src/dotty/tools/dotc/core/tasty/TastyClassName.scala | 3 ++- .../src/dotty/tools/dotc/core/tasty/TastyPrinter.scala | 7 ++++--- .../src/dotty/tools/dotc/core/tasty/TreePickler.scala | 5 ++--- tasty/src/dotty/tools/tasty/TastyFormat.scala | 8 ++++++-- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala index 62978d8b64d3..068def1abdbd 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/CommentPickler.scala @@ -6,12 +6,13 @@ import dotty.tools.dotc.core.Contexts._ import dotty.tools.tasty.TastyBuffer import TastyBuffer.{Addr, NoAddr} +import dotty.tools.tasty.TastyFormat.CommentsSection import java.nio.charset.StandardCharsets class CommentPickler(pickler: TastyPickler, addrOfTree: tpd.Tree => Addr, docString: untpd.MemberDef => Option[Comment]): private val buf = new TastyBuffer(5000) - pickler.newSection("Comments", buf) + pickler.newSection(CommentsSection, buf) def pickleComment(root: tpd.Tree): Unit = traverse(root) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala index a62236edbddf..ffcab8dc7a90 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/DottyUnpickler.scala @@ -11,6 +11,7 @@ import Names.SimpleName import TreeUnpickler.UnpickleMode import dotty.tools.tasty.TastyReader +import dotty.tools.tasty.TastyFormat.{ASTsSection, PositionsSection, CommentsSection} object DottyUnpickler { @@ -18,17 +19,17 @@ object DottyUnpickler { class BadSignature(msg: String) extends RuntimeException(msg) class TreeSectionUnpickler(posUnpickler: Option[PositionUnpickler], commentUnpickler: Option[CommentUnpickler]) - extends SectionUnpickler[TreeUnpickler](TreePickler.sectionName) { + extends SectionUnpickler[TreeUnpickler](ASTsSection) { def unpickle(reader: TastyReader, nameAtRef: NameTable): TreeUnpickler = new TreeUnpickler(reader, nameAtRef, posUnpickler, commentUnpickler) } - class PositionsSectionUnpickler extends SectionUnpickler[PositionUnpickler]("Positions") { + class PositionsSectionUnpickler extends SectionUnpickler[PositionUnpickler](PositionsSection) { def unpickle(reader: TastyReader, nameAtRef: NameTable): PositionUnpickler = new PositionUnpickler(reader, nameAtRef) } - class CommentsSectionUnpickler extends SectionUnpickler[CommentUnpickler]("Comments") { + class CommentsSectionUnpickler extends SectionUnpickler[CommentUnpickler](CommentsSection) { def unpickle(reader: TastyReader, nameAtRef: NameTable): CommentUnpickler = new CommentUnpickler(reader) } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala index 2212c1842e0a..d7aace27140c 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala @@ -3,7 +3,7 @@ package dotc package core package tasty -import dotty.tools.tasty.TastyFormat.SOURCE +import dotty.tools.tasty.TastyFormat.{SOURCE, PositionsSection} import dotty.tools.tasty.TastyBuffer import TastyBuffer._ @@ -23,7 +23,7 @@ class PositionPickler( import ast.tpd._ val buf: TastyBuffer = new TastyBuffer(5000) - pickler.newSection("Positions", buf) + pickler.newSection(PositionsSection, buf) private val pickledIndices = new mutable.BitSet diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala index c4283bb43473..0a05cd8edc4a 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyClassName.scala @@ -11,6 +11,7 @@ import StdNames.nme import TastyUnpickler._ import util.Spans.offsetToInt import printing.Highlighting._ +import dotty.tools.tasty.TastyFormat.ASTsSection /** Reads the package and class name of the class contained in this TASTy */ class TastyClassName(bytes: Array[Byte]) { @@ -21,7 +22,7 @@ class TastyClassName(bytes: Array[Byte]) { /** Returns a tuple with the package and class names */ def readName(): Option[(TermName, TermName)] = unpickle(new TreeSectionUnpickler) - class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](TreePickler.sectionName) { + class TreeSectionUnpickler extends SectionUnpickler[(TermName, TermName)](ASTsSection) { import dotty.tools.tasty.TastyFormat._ def unpickle(reader: TastyReader, tastyName: NameTable): (TermName, TermName) = { import reader._ diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala index 9d8d6654a138..074cdd8fca78 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala @@ -10,6 +10,7 @@ import Names.Name import TastyUnpickler._ import util.Spans.offsetToInt import printing.Highlighting._ +import dotty.tools.tasty.TastyFormat.{ASTsSection, PositionsSection, CommentsSection} object TastyPrinter: def show(bytes: Array[Byte])(using Context): String = @@ -57,7 +58,7 @@ class TastyPrinter(bytes: Array[Byte]) { sb.result } - class TreeSectionUnpickler extends SectionUnpickler[String](TreePickler.sectionName) { + class TreeSectionUnpickler extends SectionUnpickler[String](ASTsSection) { import dotty.tools.tasty.TastyFormat._ private val sb: StringBuilder = new StringBuilder @@ -133,7 +134,7 @@ class TastyPrinter(bytes: Array[Byte]) { } } - class PositionSectionUnpickler extends SectionUnpickler[String]("Positions") { + class PositionSectionUnpickler extends SectionUnpickler[String](PositionsSection) { private val sb: StringBuilder = new StringBuilder @@ -150,7 +151,7 @@ class TastyPrinter(bytes: Array[Byte]) { } } - class CommentSectionUnpickler extends SectionUnpickler[String]("Comments") { + class CommentSectionUnpickler extends SectionUnpickler[String](CommentsSection) { private val sb: StringBuilder = new StringBuilder diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 0451e67c00ee..1dbb3068720e 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -20,11 +20,10 @@ import printing.Texts._ import util.SourceFile import annotation.constructorOnly import collection.mutable +import dotty.tools.tasty.TastyFormat.ASTsSection object TreePickler { - val sectionName = "ASTs" - case class Hole(isTermHole: Boolean, idx: Int, args: List[tpd.Tree])(implicit @constructorOnly src: SourceFile) extends tpd.Tree { override def isTerm: Boolean = isTermHole override def isType: Boolean = !isTermHole @@ -36,7 +35,7 @@ object TreePickler { class TreePickler(pickler: TastyPickler) { val buf: TreeBuffer = new TreeBuffer - pickler.newSection(TreePickler.sectionName, buf) + pickler.newSection(ASTsSection, buf) import TreePickler._ import buf._ import pickler.nameBuffer.nameIndex diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index fc3c4dc2d3a9..02ec1a207097 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -226,7 +226,7 @@ Note: Tree tags are grouped into 5 categories that determine what follows, and t Category 4 (tags 110-127): tag Nat AST Category 5 (tags 128-255): tag Length -Standard Section: "Positions" Assoc* +Standard-Section: "Positions" Assoc* Assoc = Header offset_Delta? offset_Delta? point_Delta? | SOURCE nameref_Int @@ -244,7 +244,7 @@ Standard Section: "Positions" Assoc* All elements of a position section are serialized as Ints -Standard Section: "Comments" Comment* +Standard-Section: "Comments" Comment* Comment = Length Bytes LongInt // Raw comment's bytes encoded as UTF-8, followed by the comment's coordinates. @@ -257,6 +257,10 @@ object TastyFormat { val MajorVersion: Int = 25 val MinorVersion: Int = 0 + final val ASTsSection = "ASTs" + final val PositionsSection = "Positions" + final val CommentsSection = "Comments" + /** Tags used to serialize names, should update [[nameTagToString]] if a new constant is added */ class NameTags { final val UTF8 = 1 // A simple name in UTF8 encoding.