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 25, 2023
1 parent 9bbb1a7 commit 7bea119
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
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 7bea119

Please sign in to comment.