MLIR  16.0.0git
AsmParserImpl.h
Go to the documentation of this file.
1 //===- AsmParserImpl.h - MLIR AsmParserImpl Class ---------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_LIB_ASMPARSER_ASMPARSERIMPL_H
10 #define MLIR_LIB_ASMPARSER_ASMPARSERIMPL_H
11 
12 #include "Parser.h"
14 #include "mlir/IR/Builders.h"
16 #include "llvm/Support/Base64.h"
17 
18 namespace mlir {
19 namespace detail {
20 //===----------------------------------------------------------------------===//
21 // AsmParserImpl
22 //===----------------------------------------------------------------------===//
23 
24 /// This class provides the implementation of the generic parser methods within
25 /// AsmParser.
26 template <typename BaseT>
27 class AsmParserImpl : public BaseT {
28 public:
31  ~AsmParserImpl() override = default;
32 
33  /// Return the location of the original name token.
34  SMLoc getNameLoc() const override { return nameLoc; }
35 
36  //===--------------------------------------------------------------------===//
37  // Utilities
38  //===--------------------------------------------------------------------===//
39 
40  /// Return if any errors were emitted during parsing.
41  bool didEmitError() const { return emittedError; }
42 
43  /// Emit a diagnostic at the specified location and return failure.
44  InFlightDiagnostic emitError(SMLoc loc, const Twine &message) override {
45  emittedError = true;
46  return parser.emitError(loc, message);
47  }
48 
49  /// Return a builder which provides useful access to MLIRContext, global
50  /// objects like types and attributes.
51  Builder &getBuilder() const override { return parser.builder; }
52 
53  /// Get the location of the next token and store it into the argument. This
54  /// always succeeds.
55  SMLoc getCurrentLocation() override { return parser.getToken().getLoc(); }
56 
57  /// Re-encode the given source location as an MLIR location and return it.
58  Location getEncodedSourceLoc(SMLoc loc) override {
59  return parser.getEncodedSourceLocation(loc);
60  }
61 
62  //===--------------------------------------------------------------------===//
63  // Token Parsing
64  //===--------------------------------------------------------------------===//
65 
67 
68  /// Parse a `->` token.
69  ParseResult parseArrow() override {
70  return parser.parseToken(Token::arrow, "expected '->'");
71  }
72 
73  /// Parses a `->` if present.
75  return success(parser.consumeIf(Token::arrow));
76  }
77 
78  /// Parse a '{' token.
79  ParseResult parseLBrace() override {
80  return parser.parseToken(Token::l_brace, "expected '{'");
81  }
82 
83  /// Parse a '{' token if present
85  return success(parser.consumeIf(Token::l_brace));
86  }
87 
88  /// Parse a `}` token.
89  ParseResult parseRBrace() override {
90  return parser.parseToken(Token::r_brace, "expected '}'");
91  }
92 
93  /// Parse a `}` token if present
95  return success(parser.consumeIf(Token::r_brace));
96  }
97 
98  /// Parse a `:` token.
99  ParseResult parseColon() override {
100  return parser.parseToken(Token::colon, "expected ':'");
101  }
102 
103  /// Parse a `:` token if present.
105  return success(parser.consumeIf(Token::colon));
106  }
107 
108  /// Parse a `,` token.
109  ParseResult parseComma() override {
110  return parser.parseToken(Token::comma, "expected ','");
111  }
112 
113  /// Parse a `,` token if present.
115  return success(parser.consumeIf(Token::comma));
116  }
117 
118  /// Parses a `...`.
120  return parser.parseToken(Token::ellipsis, "expected '...'");
121  }
122 
123  /// Parses a `...` if present.
125  return success(parser.consumeIf(Token::ellipsis));
126  }
127 
128  /// Parse a `=` token.
129  ParseResult parseEqual() override {
130  return parser.parseToken(Token::equal, "expected '='");
131  }
132 
133  /// Parse a `=` token if present.
135  return success(parser.consumeIf(Token::equal));
136  }
137 
138  /// Parse a '<' token.
139  ParseResult parseLess() override {
140  return parser.parseToken(Token::less, "expected '<'");
141  }
142 
143  /// Parse a `<` token if present.
145  return success(parser.consumeIf(Token::less));
146  }
147 
148  /// Parse a '>' token.
150  return parser.parseToken(Token::greater, "expected '>'");
151  }
152 
153  /// Parse a `>` token if present.
155  return success(parser.consumeIf(Token::greater));
156  }
157 
158  /// Parse a `(` token.
160  return parser.parseToken(Token::l_paren, "expected '('");
161  }
162 
163  /// Parses a '(' if present.
165  return success(parser.consumeIf(Token::l_paren));
166  }
167 
168  /// Parse a `)` token.
170  return parser.parseToken(Token::r_paren, "expected ')'");
171  }
172 
173  /// Parses a ')' if present.
175  return success(parser.consumeIf(Token::r_paren));
176  }
177 
178  /// Parse a `[` token.
180  return parser.parseToken(Token::l_square, "expected '['");
181  }
182 
183  /// Parses a '[' if present.
185  return success(parser.consumeIf(Token::l_square));
186  }
187 
188  /// Parse a `]` token.
190  return parser.parseToken(Token::r_square, "expected ']'");
191  }
192 
193  /// Parses a ']' if present.
195  return success(parser.consumeIf(Token::r_square));
196  }
197 
198  /// Parses a '?' token.
200  return parser.parseToken(Token::question, "expected '?'");
201  }
202 
203  /// Parses a '?' if present.
205  return success(parser.consumeIf(Token::question));
206  }
207 
208  /// Parses a '*' token.
209  ParseResult parseStar() override {
210  return parser.parseToken(Token::star, "expected '*'");
211  }
212 
213  /// Parses a '*' if present.
215  return success(parser.consumeIf(Token::star));
216  }
217 
218  /// Parses a '+' token.
219  ParseResult parsePlus() override {
220  return parser.parseToken(Token::plus, "expected '+'");
221  }
222 
223  /// Parses a '+' token if present.
225  return success(parser.consumeIf(Token::plus));
226  }
227 
228  /// Parse a '|' token.
230  return parser.parseToken(Token::vertical_bar, "expected '|'");
231  }
232 
233  /// Parse a '|' token if present.
235  return success(parser.consumeIf(Token::vertical_bar));
236  }
237 
238  /// Parses a quoted string token if present.
239  ParseResult parseOptionalString(std::string *string) override {
240  if (!parser.getToken().is(Token::string))
241  return failure();
242 
243  if (string)
244  *string = parser.getToken().getStringValue();
246  return success();
247  }
248 
249  /// Parses a Base64 encoded string of bytes.
250  ParseResult parseBase64Bytes(std::vector<char> *bytes) override {
251  auto loc = getCurrentLocation();
252  if (!parser.getToken().is(Token::string))
253  return emitError(loc, "expected string");
254 
255  if (bytes) {
256  // decodeBase64 doesn't modify its input so we can use the token spelling
257  // and just slice off the quotes/whitespaces if there are any. Whitespace
258  // and quotes cannot appear as part of a (standard) base64 encoded string,
259  // so this is safe to do.
260  StringRef b64QuotedString = parser.getTokenSpelling();
261  StringRef b64String =
262  b64QuotedString.ltrim("\" \t\n\v\f\r").rtrim("\" \t\n\v\f\r");
263  if (auto err = llvm::decodeBase64(b64String, *bytes))
264  return emitError(loc, toString(std::move(err)));
265  }
266 
268  return success();
269  }
270 
271  /// Parse a floating point value from the stream.
272  ParseResult parseFloat(double &result) override {
273  bool isNegative = parser.consumeIf(Token::minus);
274  Token curTok = parser.getToken();
275  SMLoc loc = curTok.getLoc();
276 
277  // Check for a floating point value.
278  if (curTok.is(Token::floatliteral)) {
279  auto val = curTok.getFloatingPointValue();
280  if (!val)
281  return emitError(loc, "floating point value too large");
282  parser.consumeToken(Token::floatliteral);
283  result = isNegative ? -*val : *val;
284  return success();
285  }
286 
287  // Check for a hexadecimal float value.
288  if (curTok.is(Token::integer)) {
289  Optional<APFloat> apResult;
291  apResult, curTok, isNegative, APFloat::IEEEdouble(),
292  /*typeSizeInBits=*/64)))
293  return failure();
294 
295  parser.consumeToken(Token::integer);
296  result = apResult->convertToDouble();
297  return success();
298  }
299 
300  return emitError(loc, "expected floating point literal");
301  }
302 
303  /// Parse an optional integer value from the stream.
304  OptionalParseResult parseOptionalInteger(APInt &result) override {
305  return parser.parseOptionalInteger(result);
306  }
307 
308  /// Parse a list of comma-separated items with an optional delimiter. If a
309  /// delimiter is provided, then an empty list is allowed. If not, then at
310  /// least one element will be parsed.
312  function_ref<ParseResult()> parseElt,
313  StringRef contextMessage) override {
314  return parser.parseCommaSeparatedList(delimiter, parseElt, contextMessage);
315  }
316 
317  //===--------------------------------------------------------------------===//
318  // Keyword Parsing
319  //===--------------------------------------------------------------------===//
320 
321  ParseResult parseKeyword(StringRef keyword, const Twine &msg) override {
323  return parser.codeCompleteExpectedTokens(keyword);
324 
325  auto loc = getCurrentLocation();
326  if (parseOptionalKeyword(keyword))
327  return emitError(loc, "expected '") << keyword << "'" << msg;
328  return success();
329  }
331 
332  /// Parse the given keyword if present.
333  ParseResult parseOptionalKeyword(StringRef keyword) override {
335  return parser.codeCompleteOptionalTokens(keyword);
336 
337  // Check that the current token has the same spelling.
339  parser.getTokenSpelling() != keyword)
340  return failure();
342  return success();
343  }
344 
345  /// Parse a keyword, if present, into 'keyword'.
346  ParseResult parseOptionalKeyword(StringRef *keyword) override {
347  // Check that the current token is a keyword.
349  return failure();
350 
351  *keyword = parser.getTokenSpelling();
353  return success();
354  }
355 
356  /// Parse a keyword if it is one of the 'allowedKeywords'.
358  parseOptionalKeyword(StringRef *keyword,
359  ArrayRef<StringRef> allowedKeywords) override {
361  return parser.codeCompleteOptionalTokens(allowedKeywords);
362 
363  // Check that the current token is a keyword.
365  return failure();
366 
367  StringRef currentKeyword = parser.getTokenSpelling();
368  if (llvm::is_contained(allowedKeywords, currentKeyword)) {
369  *keyword = currentKeyword;
371  return success();
372  }
373 
374  return failure();
375  }
376 
377  /// Parse an optional keyword or string and set instance into 'result'.`
378  ParseResult parseOptionalKeywordOrString(std::string *result) override {
379  StringRef keyword;
380  if (succeeded(parseOptionalKeyword(&keyword))) {
381  *result = keyword.str();
382  return success();
383  }
384 
385  return parseOptionalString(result);
386  }
387 
388  //===--------------------------------------------------------------------===//
389  // Attribute Parsing
390  //===--------------------------------------------------------------------===//
391 
392  /// Parse an arbitrary attribute and return it in result.
393  ParseResult parseAttribute(Attribute &result, Type type) override {
394  result = parser.parseAttribute(type);
395  return success(static_cast<bool>(result));
396  }
397 
398  /// Parse a custom attribute with the provided callback, unless the next
399  /// token is `#`, in which case the generic parser is invoked.
401  Attribute &result, Type type,
403  override {
404  if (parser.getToken().isNot(Token::hash_identifier))
405  return parseAttribute(result, type);
406  result = parser.parseAttribute(type);
407  return success(static_cast<bool>(result));
408  }
409 
410  /// Parse a custom attribute with the provided callback, unless the next
411  /// token is `#`, in which case the generic parser is invoked.
413  Type &result,
414  function_ref<ParseResult(Type &result)> parseType) override {
415  if (parser.getToken().isNot(Token::exclamation_identifier))
416  return parseType(result);
417  result = parser.parseType();
418  return success(static_cast<bool>(result));
419  }
420 
422  Type type) override {
423  return parser.parseOptionalAttribute(result, type);
424  }
426  Type type) override {
427  return parser.parseOptionalAttribute(result, type);
428  }
430  Type type) override {
431  return parser.parseOptionalAttribute(result, type);
432  }
433 
434  /// Parse a named dictionary into 'result' if it is present.
436  if (parser.getToken().isNot(Token::l_brace))
437  return success();
438  return parser.parseAttributeDict(result);
439  }
440 
441  /// Parse a named dictionary into 'result' if the `attributes` keyword is
442  /// present.
444  if (failed(parseOptionalKeyword("attributes")))
445  return success();
446  return parser.parseAttributeDict(result);
447  }
448 
449  /// Parse an affine map instance into 'map'.
451  return parser.parseAffineMapReference(map);
452  }
453 
454  /// Parse an integer set instance into 'set'.
456  return parser.parseIntegerSetReference(set);
457  }
458 
459  //===--------------------------------------------------------------------===//
460  // Identifier Parsing
461  //===--------------------------------------------------------------------===//
462 
463  /// Parse an optional @-identifier and store it (without the '@' symbol) in a
464  /// string attribute named 'attrName'.
465  ParseResult parseOptionalSymbolName(StringAttr &result) override {
466  Token atToken = parser.getToken();
467  if (atToken.isNot(Token::at_identifier))
468  return failure();
469 
470  result = getBuilder().getStringAttr(atToken.getSymbolReference());
472 
473  // If we are populating the assembly parser state, record this as a symbol
474  // reference.
475  if (parser.getState().asmState) {
476  parser.getState().asmState->addUses(SymbolRefAttr::get(result),
477  atToken.getLocRange());
478  }
479  return success();
480  }
481 
482  //===--------------------------------------------------------------------===//
483  // Resource Parsing
484  //===--------------------------------------------------------------------===//
485 
486  /// Parse a handle to a resource within the assembly format.
488  parseResourceHandle(Dialect *dialect) override {
489  const auto *interface = dyn_cast<OpAsmDialectInterface>(dialect);
490  if (!interface) {
491  return parser.emitError() << "dialect '" << dialect->getNamespace()
492  << "' does not expect resource handles";
493  }
494  StringRef resourceName;
495  return parser.parseResourceHandle(interface, resourceName);
496  }
497 
498  //===--------------------------------------------------------------------===//
499  // Type Parsing
500  //===--------------------------------------------------------------------===//
501 
502  /// Parse a type.
503  ParseResult parseType(Type &result) override {
504  return failure(!(result = parser.parseType()));
505  }
506 
507  /// Parse an optional type.
509  return parser.parseOptionalType(result);
510  }
511 
512  /// Parse an arrow followed by a type list.
514  if (parseArrow() || parser.parseFunctionResultTypes(result))
515  return failure();
516  return success();
517  }
518 
519  /// Parse an optional arrow followed by a type list.
522  if (!parser.consumeIf(Token::arrow))
523  return success();
524  return parser.parseFunctionResultTypes(result);
525  }
526 
527  /// Parse a colon followed by a type.
528  ParseResult parseColonType(Type &result) override {
529  return failure(parser.parseToken(Token::colon, "expected ':'") ||
530  !(result = parser.parseType()));
531  }
532 
533  /// Parse a colon followed by a type list, which must have at least one type.
535  if (parser.parseToken(Token::colon, "expected ':'"))
536  return failure();
537  return parser.parseTypeListNoParens(result);
538  }
539 
540  /// Parse an optional colon followed by a type list, which if present must
541  /// have at least one type.
544  if (!parser.consumeIf(Token::colon))
545  return success();
546  return parser.parseTypeListNoParens(result);
547  }
548 
550  bool allowDynamic,
551  bool withTrailingX) override {
552  return parser.parseDimensionListRanked(dimensions, allowDynamic,
553  withTrailingX);
554  }
555 
557  return parser.parseXInDimensionList();
558  }
559 
560  //===--------------------------------------------------------------------===//
561  // Code Completion
562  //===--------------------------------------------------------------------===//
563 
564  /// Parse a keyword, or an empty string if the current location signals a code
565  /// completion.
566  ParseResult parseKeywordOrCompletion(StringRef *keyword) override {
567  Token tok = parser.getToken();
568  if (tok.isCodeCompletion() && tok.getSpelling().empty()) {
569  *keyword = "";
570  return success();
571  }
572  return parseKeyword(keyword);
573  }
574 
575  /// Signal the code completion of a set of expected tokens.
577  Token tok = parser.getToken();
578  if (tok.isCodeCompletion() && tok.getSpelling().empty())
579  (void)parser.codeCompleteExpectedTokens(tokens);
580  }
581 
582 protected:
583  /// The source location of the dialect symbol.
584  SMLoc nameLoc;
585 
586  /// The main parser.
588 
589  /// A flag that indicates if any errors were emitted during parsing.
590  bool emittedError = false;
591 };
592 } // namespace detail
593 } // namespace mlir
594 
595 #endif // MLIR_LIB_ASMPARSER_ASMPARSERIMPL_H
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition: AffineMap.h:42
void addUses(Value value, ArrayRef< SMLoc > locations)
Add a source uses of the given value.
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This class is a general helper class for creating context-global objects like types,...
Definition: Builders.h:49
StringAttr getStringAttr(const Twine &bytes)
Definition: Builders.cpp:243
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition: Dialect.h:41
StringRef getNamespace() const
Definition: Dialect.h:57
This class provides support for representing a failure result, or a valid value of type T.
Definition: LogicalResult.h:78
This class represents a diagnostic that is inflight and set to be reported.
Definition: Diagnostics.h:307
An integer set representing a conjunction of one or more affine equalities and inequalities.
Definition: IntegerSet.h:44
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition: Location.h:64
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
This class implements Optional functionality for ParseResult.
Definition: OpDefinition.h:37
This class represents success/failure for parsing-like operations that find it important to chain tog...
This represents a token in the MLIR syntax.
Definition: Token.h:20
SMRange getLocRange() const
Definition: Token.cpp:24
SMLoc getLoc() const
Definition: Token.cpp:18
bool is(Kind k) const
Definition: Token.h:38
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
Definition: Token.cpp:80
std::string getSymbolReference() const
Given a token containing a symbol reference, return the unescaped string value.
Definition: Token.cpp:147
bool isNot(Kind k) const
Definition: Token.h:50
bool isCodeCompletion() const
Returns true if the current token represents a code completion.
Definition: Token.h:62
StringRef getSpelling() const
Definition: Token.h:34
Optional< double > getFloatingPointValue() const
For a floatliteral token, return its value as a double.
Definition: Token.cpp:50
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
This class provides the implementation of the generic parser methods within AsmParser.
Definition: AsmParserImpl.h:27
ParseResult parseOptionalPlus() override
Parses a '+' token if present.
ParseResult parseOptionalLBrace() override
Parse a '{' token if present.
Definition: AsmParserImpl.h:84
ParseResult parseOptionalArrowTypeList(SmallVectorImpl< Type > &result) override
Parse an optional arrow followed by a type list.
ParseResult parseOptionalStar() override
Parses a '*' if present.
ParseResult parseColon() override
Parse a : token.
Definition: AsmParserImpl.h:99
ParseResult parseFloat(double &result) override
Parse a floating point value from the stream.
InFlightDiagnostic emitError(SMLoc loc, const Twine &message) override
Emit a diagnostic at the specified location and return failure.
Definition: AsmParserImpl.h:44
ParseResult parseOptionalGreater() override
Parse a > token if present.
ParseResult parseOptionalEllipsis() override
Parses a ... if present.
ParseResult parseColonType(Type &result) override
Parse a colon followed by a type.
ParseResult parseArrow() override
Parse a -> token.
Definition: AsmParserImpl.h:69
void codeCompleteExpectedTokens(ArrayRef< StringRef > tokens) override
Signal the code completion of a set of expected tokens.
ParseResult parseEllipsis() override
Parses a ....
ParseResult parseLParen() override
Parse a ( token.
ParseResult parseOptionalKeywordOrString(std::string *result) override
Parse an optional keyword or string and set instance into 'result'.`.
Location getEncodedSourceLoc(SMLoc loc) override
Re-encode the given source location as an MLIR location and return it.
Definition: AsmParserImpl.h:58
ParseResult parseOptionalAttrDict(NamedAttrList &result) override
Parse a named dictionary into 'result' if it is present.
SMLoc nameLoc
The source location of the dialect symbol.
ParseResult parseRParen() override
Parse a ) token.
ParseResult parseQuestion() override
Parses a '?' token.
OptionalParseResult parseOptionalAttribute(ArrayAttr &result, Type type) override
ParseResult parseCustomAttributeWithFallback(Attribute &result, Type type, function_ref< ParseResult(Attribute &result, Type type)> parseAttribute) override
Parse a custom attribute with the provided callback, unless the next token is #, in which case the ge...
OptionalParseResult parseOptionalType(Type &result) override
Parse an optional type.
SMLoc getNameLoc() const override
Return the location of the original name token.
Definition: AsmParserImpl.h:34
ParseResult parseOptionalQuestion() override
Parses a '?' if present.
ParseResult parseLBrace() override
Parse a '{' token.
Definition: AsmParserImpl.h:79
ParseResult parseOptionalComma() override
Parse a , token if present.
ParseResult parsePlus() override
Parses a '+' token.
ParseResult parseLess() override
Parse a '<' token.
ParseResult parseOptionalKeyword(StringRef *keyword, ArrayRef< StringRef > allowedKeywords) override
Parse a keyword if it is one of the 'allowedKeywords'.
ParseResult parseRBrace() override
Parse a } token.
Definition: AsmParserImpl.h:89
ParseResult parseOptionalRBrace() override
Parse a } token if present.
Definition: AsmParserImpl.h:94
ParseResult parseGreater() override
Parse a '>' token.
FailureOr< AsmDialectResourceHandle > parseResourceHandle(Dialect *dialect) override
Parse a handle to a resource within the assembly format.
ParseResult parseColonTypeList(SmallVectorImpl< Type > &result) override
Parse a colon followed by a type list, which must have at least one type.
ParseResult parseOptionalLess() override
Parse a < token if present.
OptionalParseResult parseOptionalAttribute(StringAttr &result, Type type) override
OptionalParseResult parseOptionalAttribute(Attribute &result, Type type) override
ParseResult parseAttribute(Attribute &result, Type type) override
Parse an arbitrary attribute and return it in result.
Parser & parser
The main parser.
ParseResult parseKeywordOrCompletion(StringRef *keyword) override
Parse a keyword, or an empty string if the current location signals a code completion.
AsmParserImpl(SMLoc nameLoc, Parser &parser)
Definition: AsmParserImpl.h:29
ParseResult parseOptionalKeyword(StringRef keyword) override
Parse the given keyword if present.
bool didEmitError() const
Return if any errors were emitted during parsing.
Definition: AsmParserImpl.h:41
ParseResult parseComma() override
Parse a , token.
OptionalParseResult parseOptionalInteger(APInt &result) override
Parse an optional integer value from the stream.
ParseResult parseRSquare() override
Parse a ] token.
Builder & getBuilder() const override
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
Definition: AsmParserImpl.h:51
ParseResult parseLSquare() override
Parse a [ token.
ParseResult parseBase64Bytes(std::vector< char > *bytes) override
Parses a Base64 encoded string of bytes.
ParseResult parseOptionalArrow() override
Parses a -> if present.
Definition: AsmParserImpl.h:74
~AsmParserImpl() override=default
ParseResult parseDimensionList(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic, bool withTrailingX) override
ParseResult parseEqual() override
Parse a = token.
ParseResult parseCustomTypeWithFallback(Type &result, function_ref< ParseResult(Type &result)> parseType) override
Parse a custom attribute with the provided callback, unless the next token is #, in which case the ge...
ParseResult parseOptionalColonTypeList(SmallVectorImpl< Type > &result) override
Parse an optional colon followed by a type list, which if present must have at least one type.
ParseResult parseOptionalVerticalBar() override
Parse a '|' token if present.
ParseResult parseOptionalAttrDictWithKeyword(NamedAttrList &result) override
Parse a named dictionary into 'result' if the attributes keyword is present.
ParseResult parseStar() override
Parses a '*' token.
ParseResult parseOptionalLParen() override
Parses a '(' if present.
ParseResult parseOptionalEqual() override
Parse a = token if present.
ParseResult parseOptionalLSquare() override
Parses a '[' if present.
ParseResult parseOptionalKeyword(StringRef *keyword) override
Parse a keyword, if present, into 'keyword'.
ParseResult parseAffineMap(AffineMap &map) override
Parse an affine map instance into 'map'.
ParseResult parseOptionalSymbolName(StringAttr &result) override
Parse an optional -identifier and store it (without the '@' symbol) in a string attribute named 'attr...
ParseResult parseVerticalBar() override
Parse a '|' token.
SMLoc getCurrentLocation() override
Get the location of the next token and store it into the argument.
Definition: AsmParserImpl.h:55
bool emittedError
A flag that indicates if any errors were emitted during parsing.
ParseResult printIntegerSet(IntegerSet &set) override
Parse an integer set instance into 'set'.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
ParseResult parseOptionalColon() override
Parse a : token if present.
ParseResult parseOptionalString(std::string *string) override
Parses a quoted string token if present.
ParseResult parseOptionalRParen() override
Parses a ')' if present.
ParseResult parseXInDimensionList() override
ParseResult parseKeyword(StringRef keyword, const Twine &msg) override
ParseResult parseType(Type &result) override
Parse a type.
ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElt, StringRef contextMessage) override
Parse a list of comma-separated items with an optional delimiter.
ParseResult parseOptionalRSquare() override
Parses a ']' if present.
ParseResult parseArrowTypeList(SmallVectorImpl< Type > &result) override
Parse an arrow followed by a type list.
This class implement support for parsing global entities like attributes and types.
Definition: Parser.h:25
ParseResult parseXInDimensionList()
Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element t...
Definition: TypeParser.cpp:575
OptionalParseResult parseOptionalType(Type &type)
Optionally parse a type.
Definition: TypeParser.cpp:23
ParseResult parseToken(Token::Kind expectedToken, const Twine &message)
Consume the specified token if present and return success.
Definition: Parser.cpp:232
Builder builder
Definition: Parser.h:29
ParseResult parseFloatFromIntegerLiteral(Optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics, size_t typeSizeInBits)
Parse a floating point value from an integer literal token.
Definition: Parser.cpp:277
Type parseType()
Parse an arbitrary type.
Definition: TypeParser.cpp:56
ParserState & getState() const
Definition: Parser.h:35
ParseResult parseAffineMapReference(AffineMap &map)
Location getEncodedSourceLocation(SMLoc loc)
Encode the specified source location information into an attribute for attachment to the IR.
Definition: Parser.h:92
InFlightDiagnostic emitError(const Twine &message={})
Emit an error and return failure.
Definition: Parser.cpp:157
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
StringRef getTokenSpelling() const
Definition: Parser.h:102
void consumeToken()
Advance the current lexer onto the next token.
Definition: Parser.h:114
ParseResult codeCompleteExpectedTokens(ArrayRef< StringRef > tokens)
Definition: Parser.cpp:418
ParseResult parseAttributeDict(NamedAttrList &attributes)
Parse an attribute dictionary.
ParseResult parseDimensionListRanked(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)
Parse a dimension list of a tensor or memref type.
Definition: TypeParser.cpp:510
ParseResult parseFunctionResultTypes(SmallVectorImpl< Type > &elements)
Parse a function result type.
Definition: TypeParser.cpp:67
ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
Parse a list of comma-separated items with an optional delimiter.
Definition: Parser.cpp:49
OptionalParseResult parseOptionalInteger(APInt &result)
Parse an optional integer value from the stream.
Definition: Parser.cpp:240
OptionalParseResult parseOptionalAttribute(Attribute &attribute, Type type={})
Parse an optional attribute with the provided type.
bool isCurrentTokenAKeyword() const
Returns true if the current token corresponds to a keyword.
Definition: Parser.h:148
ParseResult codeCompleteOptionalTokens(ArrayRef< StringRef > tokens)
Definition: Parser.cpp:422
ParseResult parseIntegerSetReference(IntegerSet &set)
ParseResult parseTypeListNoParens(SmallVectorImpl< Type > &elements)
Parse a list of types without an enclosing parenthesis.
Definition: TypeParser.cpp:83
const Token & getToken() const
Return the current token the parser is inspecting.
Definition: Parser.h:101
FailureOr< AsmDialectResourceHandle > parseResourceHandle(const OpAsmDialectInterface *dialect, StringRef &name)
Parse a handle to a dialect resource within the assembly format.
Definition: Parser.cpp:325
bool consumeIf(Token::Kind kind)
If the current token has the specified kind, consume it and return true.
Definition: Parser.h:106
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
StringRef toString(AsmResourceEntryKind kind)
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:68
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
AsmParserState * asmState
An optional pointer to a struct containing high level parser state to be populated during parsing.
Definition: ParserState.h:72