3838#include " absl/strings/str_format.h"
3939#include " absl/types/span.h"
4040#include " absl/types/variant.h"
41+ #include " xls/common/attribute_data.h" // IWYU pragma: keep
4142#include " xls/common/status/status_macros.h"
4243#include " xls/dslx/channel_direction.h"
4344#include " xls/dslx/frontend/ast_node.h" // IWYU pragma: export
@@ -321,47 +322,18 @@ enum class TypeAnnotationKind : uint8_t {
321322 kTypeVariable
322323};
323324
324- enum class AttributeKind : uint8_t {
325- kCfg ,
326- kDerive ,
327- kDslxFormatDisable ,
328- kExternVerilog ,
329- kSvType ,
330- kTest ,
331- kTestProc ,
332- kQuickcheck ,
333- kChannelStrictness
334- };
335-
336- std::string AttributeKindToString (AttributeKind kind);
337-
338325// One of the `#[foo]`-like nodes preceding some entity.
339326class Attribute : public AstNode {
340327 public:
341- using StringKeyValueArgument = std::pair<std::string, std::string>;
342- using IntKeyValueArgument = std::pair<std::string, int64_t >;
343-
344- // Represents a quoted string argument as opposed to a bare identifier-like
345- // string.
346- struct StringLiteralArgument {
347- std::string text;
348- };
349-
350- // Note that a std::string argument is the simplest kind and looks like an
351- // unquoted identifier, like `test` in `#[cfg(test)]`.
352- using Argument = std::variant<std::string, StringLiteralArgument,
353- StringKeyValueArgument, IntKeyValueArgument>;
354-
355328 Attribute (Module* owner, Span span, std::optional<Span> arg_span,
356- AttributeKind kind, std::vector<Argument> args )
329+ AttributeData attribute_data )
357330 : AstNode(owner),
358331 span_ (span),
359332 arg_span_(arg_span),
360- kind_(kind),
361- args_(std::move(args)) {}
333+ attribute_data_(std::move(attribute_data)) {}
362334
363335 AstNodeKind kind () const override { return AstNodeKind::kAttribute ; }
364- AttributeKind attribute_kind () const { return kind_ ; }
336+ AttributeKind attribute_kind () const { return attribute_data_. kind () ; }
365337
366338 std::optional<Span> GetSpan () const override { return span_; }
367339 std::optional<Span> GetArgSpan () const { return arg_span_; }
@@ -371,7 +343,10 @@ class Attribute : public AstNode {
371343 }
372344
373345 std::string_view GetNodeTypeName () const override { return " Attribute" ; }
374- const std::vector<Argument>& args () const { return args_; }
346+ const AttributeData& attribute_data () const { return attribute_data_; }
347+ const std::vector<AttributeData::Argument>& args () const {
348+ return attribute_data_.args ();
349+ }
375350
376351 std::vector<AstNode*> GetChildren (bool want_types) const override {
377352 return {};
@@ -382,8 +357,7 @@ class Attribute : public AstNode {
382357 private:
383358 const Span span_;
384359 const std::optional<Span> arg_span_;
385- const AttributeKind kind_;
386- const std::vector<Argument> args_;
360+ const AttributeData attribute_data_;
387361};
388362
389363// Abstract base class for type annotations.
0 commit comments