summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Parser/Parser.cpp
diff options
context:
space:
mode:
authorRiver Riddle <riverriddle@google.com>2019-11-05 17:58:16 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-11-05 17:58:48 -0800
commit8e0f4860cdc07b4c681c434792cede24f16961e3 (patch)
tree0738f42b14d9f8cfce24ae9b5ffcde9a384d772c /mlir/lib/Parser/Parser.cpp
parent500e858e6522c3b55c3f23e95689f146e09db43e (diff)
downloadbcm5719-llvm-8e0f4860cdc07b4c681c434792cede24f16961e3.tar.gz
bcm5719-llvm-8e0f4860cdc07b4c681c434792cede24f16961e3.zip
Add (parse|print)OptionalAttrDictWithKeyword hooks to simplify parsing attribute dictionaries with regions.
Many operations with regions add an additional 'attributes' prefix when printing the attribute dictionary to differentiate it from the region body. This leads to duplicated logic for detecting when to actually print the attribute dictionary. PiperOrigin-RevId: 278747681
Diffstat (limited to 'mlir/lib/Parser/Parser.cpp')
-rw-r--r--mlir/lib/Parser/Parser.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index 3a45933db87..35c694b6a43 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -1533,7 +1533,7 @@ Attribute Parser::parseAttribute(Type type) {
///
ParseResult
Parser::parseAttributeDict(SmallVectorImpl<NamedAttribute> &attributes) {
- if (!consumeIf(Token::l_brace))
+ if (parseToken(Token::l_brace, "expected '{' in attribute dictionary"))
return failure();
auto parseElt = [&]() -> ParseResult {
@@ -3874,6 +3874,15 @@ public:
return parser.parseAttributeDict(result);
}
+ /// Parse a named dictionary into 'result' if the `attributes` keyword is
+ /// present.
+ ParseResult parseOptionalAttrDictWithKeyword(
+ SmallVectorImpl<NamedAttribute> &result) override {
+ if (failed(parseOptionalKeyword("attributes")))
+ return success();
+ return parser.parseAttributeDict(result);
+ }
+
//===--------------------------------------------------------------------===//
// Identifier Parsing
//===--------------------------------------------------------------------===//
OpenPOWER on IntegriCloud