diff options
| author | River Riddle <riverriddle@google.com> | 2019-11-05 17:58:16 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-11-05 17:58:48 -0800 |
| commit | 8e0f4860cdc07b4c681c434792cede24f16961e3 (patch) | |
| tree | 0738f42b14d9f8cfce24ae9b5ffcde9a384d772c /mlir/lib/Parser/Parser.cpp | |
| parent | 500e858e6522c3b55c3f23e95689f146e09db43e (diff) | |
| download | bcm5719-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.cpp | 11 |
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 //===--------------------------------------------------------------------===// |

