Adding utility to parse optional colon-type-lists.
authorBen Vanik <benvanik@google.com>
Thu, 6 Jun 2019 22:58:47 +0000 (15:58 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 9 Jun 2019 23:21:54 +0000 (16:21 -0700)
PiperOrigin-RevId: 251945512

mlir/include/mlir/IR/OpImplementation.h
mlir/lib/Parser/Parser.cpp

index 7fe039d..b84fe42 100644 (file)
@@ -398,6 +398,11 @@ public:
   /// Parse a colon followed by a type list, which must have at least one type.
   virtual ParseResult parseColonTypeList(SmallVectorImpl<Type> &result) = 0;
 
+  /// Parse an optional colon followed by a type list, which if present must
+  /// have at least one type.
+  virtual ParseResult
+  parseOptionalColonTypeList(SmallVectorImpl<Type> &result) = 0;
+
   /// Parse a keyword followed by a type.
   ParseResult parseKeywordType(const char *keyword, Type &result) {
     return failure(parseKeyword(keyword) || parseType(result));
index 737d3da..67432d6 100644 (file)
@@ -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<Type> &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<Value *, 2> parsedRegionEntryArgumentPlaceholders;