From 51095d0b69c30e59c891705d3139e4e0392786b9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 25 Oct 2023 17:26:43 +0200 Subject: [PATCH] Give attribute a semantic kind --- .../src/dotty/tools/dotc/core/tasty/AttributePickler.scala | 3 ++- .../dotty/tools/dotc/core/tasty/AttributeUnpickler.scala | 2 ++ tasty/src/dotty/tools/tasty/TastyFormat.scala | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala index 869081e7b9bc..d91e2fb82d37 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala @@ -3,7 +3,7 @@ package dotty.tools.dotc.core.tasty import dotty.tools.dotc.ast.{tpd, untpd} import dotty.tools.tasty.TastyBuffer -import dotty.tools.tasty.TastyFormat.AttributesSection +import dotty.tools.tasty.TastyFormat, TastyFormat.AttributesSection import java.nio.charset.StandardCharsets @@ -19,6 +19,7 @@ object AttributePickler: val bytes = attribute.getBytes(StandardCharsets.UTF_8).nn val length = bytes.length assert("[a-zA-Z0-9]+".r.matches(attribute), s"Malformed attribute: $attribute\n. Attribute must match [a-zA-Z0-9]+") + buf.writeNat(TastyFormat.FLAGattr) buf.writeNat(length) buf.writeBytes(bytes, length) end pickleAttributes diff --git a/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala index 85d2e64e9593..1dc3792c3807 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala @@ -13,6 +13,8 @@ class AttributeUnpickler(reader: TastyReader): private[tasty] lazy val attributes: List[String] = { val attributesBuilder = List.newBuilder[String] while (!isAtEnd) { + val kind = readNat() + assert(kind == TastyFormat.FLAGattr, "Malformed attribute kind") val length = readNat() val bytes = readBytes(length) val attribute = new String(bytes, StandardCharsets.UTF_8) diff --git a/tasty/src/dotty/tools/tasty/TastyFormat.scala b/tasty/src/dotty/tools/tasty/TastyFormat.scala index 887109d16cf0..34734d5093b8 100644 --- a/tasty/src/dotty/tools/tasty/TastyFormat.scala +++ b/tasty/src/dotty/tools/tasty/TastyFormat.scala @@ -270,7 +270,7 @@ Standard Section: "Comments" Comment* Standard Section: "Attributes" Attribute* ```none - Attribute = UTF8 // attributes match the regex [a-zA-Z0-9]+ + Attribute = FLAGattr UTF8 // attributes match the regex [a-zA-Z0-9]+ ``` **************************************************************************************/ @@ -606,6 +606,11 @@ object TastyFormat { final val firstNatASTTreeTag = IDENT final val firstLengthTreeTag = PACKAGE + + // Attribute tags + + final val FLAGattr = 1 + /** Useful for debugging */ def isLegalTag(tag: Int): Boolean = firstSimpleTreeTag <= tag && tag <= SPLITCLAUSE ||