From cc8a8fa76acd6679db35c4f1a6b85820a1fcbae8 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Thu, 6 Jun 2019 15:58:47 -0700 Subject: [PATCH] Adding utility to parse optional colon-type-lists. PiperOrigin-RevId: 251945512 --- mlir/include/mlir/IR/OpImplementation.h | 5 +++++ mlir/lib/Parser/Parser.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 7fe039d..b84fe42 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -398,6 +398,11 @@ public: /// Parse a colon followed by a type list, which must have at least one type. virtual ParseResult parseColonTypeList(SmallVectorImpl &result) = 0; + /// Parse an optional colon followed by a type list, which if present must + /// have at least one type. + virtual ParseResult + parseOptionalColonTypeList(SmallVectorImpl &result) = 0; + /// Parse a keyword followed by a type. ParseResult parseKeywordType(const char *keyword, Type &result) { return failure(parseKeyword(keyword) || parseType(result)); diff --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp index 737d3da..67432d6 100644 --- a/mlir/lib/Parser/Parser.cpp +++ b/mlir/lib/Parser/Parser.cpp @@ -3333,6 +3333,15 @@ public: return parser.parseTypeListNoParens(result); } + /// Parse an optional colon followed by a type list, which if present must + /// have at least one type. + ParseResult + parseOptionalColonTypeList(SmallVectorImpl &result) override { + if (!parser.consumeIf(Token::colon)) + return success(); + return parser.parseTypeListNoParens(result); + } + private: /// A set of placeholder value definitions for parsed region arguments. SmallVector parsedRegionEntryArgumentPlaceholders; -- 2.7.4