Skip to content

Commit 57d239e

Browse files
committed
[mlir] Breakdown diagnostic string literals
This commit breaks down diagnostic string literals so that the attribute name and enumurator names can be shared with the stringify utility function and the "expected ", " to be one of ", and ", " can be shared between different enum-related diagnostic. Differential Revision: https://reviews.llvm.org/D125938
1 parent deb62f5 commit 57d239e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

mlir/include/mlir/IR/EnumAttr.td

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ class IntEnumAttr<I intType, string name, string summary,
222222
stringToSymbolFnName # [{(enumKeyword);
223223
if (maybeEnum)
224224
return *maybeEnum;
225-
return {(::mlir::LogicalResult)$_parser.emitError(loc, "expected }] #
226-
cppType # [{ to be one of: }] #
227-
!interleave(!foreach(enum, enumerants, enum.str), ", ") # [{")};
225+
return {(::mlir::LogicalResult)($_parser.emitError(loc) << "expected " }] #
226+
[{<< "}] # cppType # [{" << " to be one of: " << }] #
227+
!interleave(!foreach(enum, enumerants, "\"" # enum.str # "\""),
228+
[{ << ", " << }]) # [{)};
228229
}()}];
229230
// Print the enum by calling `symbolToString`.
230231
let parameterPrinter = "$_printer << " # symbolToStringFnName # "($_self)";
@@ -294,10 +295,10 @@ class BitEnumAttr<I intType, string name, string summary,
294295
auto maybeEnum = }] # cppNamespace # "::" #
295296
stringToSymbolFnName # [{(enumKeyword);
296297
if (!maybeEnum) {
297-
return {(::mlir::LogicalResult)$_parser.emitError(loc, "expected }] #
298-
cppType # [{ to be one of: }] #
299-
!interleave(!foreach(enum, enumerants, enum.str),
300-
", ") # [{")};
298+
return {(::mlir::LogicalResult)($_parser.emitError(loc) << }] #
299+
[{"expected " << "}] # cppType # [{" << " to be one of: " << }] #
300+
!interleave(!foreach(enum, enumerants, "\"" # enum.str # "\""),
301+
[{ << ", " << }]) # [{)};
301302
}
302303
flags = flags | *maybeEnum;
303304
} while(::mlir::succeeded($_parser.}] # parseSeparatorFn # [{()));

0 commit comments

Comments
 (0)