Skip to content

Commit 51095d0

Browse files
committed
Give attribute a semantic kind
1 parent e947f3e commit 51095d0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/core/tasty/AttributePickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.dotc.core.tasty
33
import dotty.tools.dotc.ast.{tpd, untpd}
44

55
import dotty.tools.tasty.TastyBuffer
6-
import dotty.tools.tasty.TastyFormat.AttributesSection
6+
import dotty.tools.tasty.TastyFormat, TastyFormat.AttributesSection
77

88
import java.nio.charset.StandardCharsets
99

@@ -19,6 +19,7 @@ object AttributePickler:
1919
val bytes = attribute.getBytes(StandardCharsets.UTF_8).nn
2020
val length = bytes.length
2121
assert("[a-zA-Z0-9]+".r.matches(attribute), s"Malformed attribute: $attribute\n. Attribute must match [a-zA-Z0-9]+")
22+
buf.writeNat(TastyFormat.FLAGattr)
2223
buf.writeNat(length)
2324
buf.writeBytes(bytes, length)
2425
end pickleAttributes

compiler/src/dotty/tools/dotc/core/tasty/AttributeUnpickler.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class AttributeUnpickler(reader: TastyReader):
1313
private[tasty] lazy val attributes: List[String] = {
1414
val attributesBuilder = List.newBuilder[String]
1515
while (!isAtEnd) {
16+
val kind = readNat()
17+
assert(kind == TastyFormat.FLAGattr, "Malformed attribute kind")
1618
val length = readNat()
1719
val bytes = readBytes(length)
1820
val attribute = new String(bytes, StandardCharsets.UTF_8)

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Standard Section: "Comments" Comment*
270270
271271
Standard Section: "Attributes" Attribute*
272272
```none
273-
Attribute = UTF8 // attributes match the regex [a-zA-Z0-9]+
273+
Attribute = FLAGattr UTF8 // attributes match the regex [a-zA-Z0-9]+
274274
```
275275
276276
**************************************************************************************/
@@ -606,6 +606,11 @@ object TastyFormat {
606606
final val firstNatASTTreeTag = IDENT
607607
final val firstLengthTreeTag = PACKAGE
608608

609+
610+
// Attribute tags
611+
612+
final val FLAGattr = 1
613+
609614
/** Useful for debugging */
610615
def isLegalTag(tag: Int): Boolean =
611616
firstSimpleTreeTag <= tag && tag <= SPLITCLAUSE ||

0 commit comments

Comments
 (0)