From 7bea11942467109f1316db5d08de496b991205cc 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 | 2 ++ .../dotty/tools/dotc/core/tasty/AttributeUnpickler.scala | 2 ++ tasty/src/dotty/tools/tasty/TastyFormat.scala | 7 ++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala index af2b2e4759ff..26e89ee7b019 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala @@ -6,6 +6,7 @@ import dotty.tools.tasty.TastyBuffer import dotty.tools.tasty.TastyFormat.AttributesSection import java.nio.charset.StandardCharsets +import dotty.tools.tasty.TastyFormat object AttributePickler: @@ -19,6 +20,7 @@ object AttributePickler: val bytes = attribute.getBytes(StandardCharsets.UTF_8).nn val length = bytes.length assert("[a-zA-Z0-9]+".r.matches(attribute), "Malformed attribute. 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 7eb1ab7a0007..329e172cc45a 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 ||