Skip to content

Commit

Permalink
Give attribute a semantic kind
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 26, 2023
1 parent e947f3e commit 51095d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion tasty/src/dotty/tools/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]+
```
**************************************************************************************/
Expand Down Expand Up @@ -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 ||
Expand Down

0 comments on commit 51095d0

Please sign in to comment.