}
};
+/// Parse an Optional attribute.
+template <typename AttributeT>
+struct FieldParser<
+ std::optional<AttributeT>,
+ std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
+ std::optional<AttributeT>>> {
+ static FailureOr<std::optional<AttributeT>> parse(AsmParser &parser) {
+ AttributeT attr;
+ OptionalParseResult result = parser.parseOptionalAttribute(attr);
+ if (result.has_value()) {
+ if (succeeded(*result))
+ return {std::optional<AttributeT>(attr)};
+ return failure();
+ }
+ return {std::nullopt};
+ }
+};
+
/// Parse an Optional integer.
template <typename IntT>
struct FieldParser<
}
def TestTypeOptionalParam : Test_Type<"TestTypeOptionalParam"> {
- let parameters = (ins OptionalParameter<"mlir::Optional<int>">:$a, "int":$b);
+ let parameters = (ins
+ OptionalParameter<"mlir::Optional<int>">:$a,
+ "int":$b,
+ DefaultValuedParameter<"std::optional<::mlir::Attribute>",
+ "std::nullopt">:$c
+ );
let mnemonic = "optional_param";
- let assemblyFormat = "`<` $a `,` $b `>`";
+ let assemblyFormat = "`<` $a `,` $b ( `,` $c^)? `>`";
}
def TestTypeOptionalParams : Test_Type<"TestTypeOptionalParams"> {
// CHECK: !test.struct_capture_all<v0 = 0, v1 = 1, v2 = 2, v3 = 3>
// CHECK: !test.optional_param<, 6>
// CHECK: !test.optional_param<5, 6>
+// CHECK: !test.optional_param<5, 6, "foo">
+// CHECK: !test.optional_param<5, 6, {foo = "bar"}>
// CHECK: !test.optional_params<"a">
// CHECK: !test.optional_params<5, "a">
// CHECK: !test.optional_struct<b = "a">
!test.struct_capture_all<v3 = 3, v1 = 1, v2 = 2, v0 = 0>,
!test.optional_param<, 6>,
!test.optional_param<5, 6>,
+ !test.optional_param<5, 6, "foo">,
+ !test.optional_param<5, 6, {foo = "bar"}>,
!test.optional_params<"a">,
!test.optional_params<5, "a">,
!test.optional_struct<b = "a">,