MLIR 24.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#include <optional>
18
19namespace mlir {
20namespace detail {
21//===----------------------------------------------------------------------===//
22// AsmParserImpl
23//===----------------------------------------------------------------------===//
24
25/// This class provides the implementation of the generic parser methods within
26/// AsmParser.
27template <typename BaseT>
28class AsmParserImpl : public BaseT {
29public:
32 ~AsmParserImpl() override = default;
33
34 /// Return the location of the original name token.
35 SMLoc getNameLoc() const override { return nameLoc; }
36
37 //===--------------------------------------------------------------------===//
38 // Utilities
39 //===--------------------------------------------------------------------===//
40
41 /// Return if any errors were emitted during parsing.
42 bool didEmitError() const { return emittedError; }
43
44 /// Emit a diagnostic at the specified location and return failure.
45 InFlightDiagnostic emitError(SMLoc loc, const Twine &message) override {
46 emittedError = true;
47 return parser.emitError(loc, message);
48 }
49
50 /// Return a builder which provides useful access to MLIRContext, global
51 /// objects like types and attributes.
52 Builder &getBuilder() const override { return parser.builder; }
53
54 /// Get the location of the next token and store it into the argument. This
55 /// always succeeds.
56 SMLoc getCurrentLocation() override { return parser.getToken().getLoc(); }
57
58 /// Re-encode the given source location as an MLIR location and return it.
59 Location getEncodedSourceLoc(SMLoc loc) override {
60 return parser.getEncodedSourceLocation(loc);
61 }
62
63 //===--------------------------------------------------------------------===//
64 // Token Parsing
65 //===--------------------------------------------------------------------===//
66
68
69 /// Parse a `->` token.
70 ParseResult parseArrow() override {
71 return parser.parseToken(Token::arrow, "expected '->'");
72 }
73
74 /// Parses a `->` if present.
75 ParseResult parseOptionalArrow() override {
76 return success(parser.consumeIf(Token::arrow));
77 }
78
79 /// Parse a '{' token.
80 ParseResult parseLBrace() override {
81 return parser.parseToken(Token::l_brace, "expected '{'");
82 }
83
84 /// Parse a '{' token if present
85 ParseResult parseOptionalLBrace() override {
86 return success(parser.consumeIf(Token::l_brace));
87 }
88
89 /// Parse a `}` token.
90 ParseResult parseRBrace() override {
91 return parser.parseToken(Token::r_brace, "expected '}'");
92 }
93
94 /// Parse a `}` token if present
95 ParseResult parseOptionalRBrace() override {
96 return success(parser.consumeIf(Token::r_brace));
97 }
98
99 /// Parse a `:` token.
100 ParseResult parseColon() override {
101 return parser.parseToken(Token::colon, "expected ':'");
102 }
103
104 /// Parse a `:` token if present.
105 ParseResult parseOptionalColon() override {
106 return success(parser.consumeIf(Token::colon));
107 }
108
109 /// Parse a `,` token.
110 ParseResult parseComma() override {
111 return parser.parseToken(Token::comma, "expected ','");
112 }
113
114 /// Parse a `,` token if present.
115 ParseResult parseOptionalComma() override {
116 return success(parser.consumeIf(Token::comma));
117 }
118
119 /// Parses a `...`.
120 ParseResult parseEllipsis() override {
121 return parser.parseToken(Token::ellipsis, "expected '...'");
122 }
123
124 /// Parses a `...` if present.
125 ParseResult parseOptionalEllipsis() override {
126 return success(parser.consumeIf(Token::ellipsis));
127 }
128
129 /// Parse a `=` token.
130 ParseResult parseEqual() override {
131 return parser.parseToken(Token::equal, "expected '='");
132 }
133
134 /// Parse a `=` token if present.
135 ParseResult parseOptionalEqual() override {
136 return success(parser.consumeIf(Token::equal));
137 }
138
139 /// Parse a '<' token.
140 ParseResult parseLess() override {
141 return parser.parseToken(Token::less, "expected '<'");
142 }
143
144 /// Parse a `<` token if present.
145 ParseResult parseOptionalLess() override {
146 return success(parser.consumeIf(Token::less));
147 }
148
149 /// Parse a '>' token.
150 ParseResult parseGreater() override {
151 return parser.parseToken(Token::greater, "expected '>'");
152 }
153
154 /// Parse a `>` token if present.
155 ParseResult parseOptionalGreater() override {
156 return success(parser.consumeIf(Token::greater));
157 }
158
159 /// Parse a `(` token.
160 ParseResult parseLParen() override {
161 return parser.parseToken(Token::l_paren, "expected '('");
162 }
163
164 /// Parses a '(' if present.
165 ParseResult parseOptionalLParen() override {
166 return success(parser.consumeIf(Token::l_paren));
167 }
168
169 /// Parse a `)` token.
170 ParseResult parseRParen() override {
171 return parser.parseToken(Token::r_paren, "expected ')'");
172 }
173
174 /// Parses a ')' if present.
175 ParseResult parseOptionalRParen() override {
176 return success(parser.consumeIf(Token::r_paren));
177 }
178
179 /// Parse a `[` token.
180 ParseResult parseLSquare() override {
181 return parser.parseToken(Token::l_square, "expected '['");
182 }
183
184 /// Parses a '[' if present.
185 ParseResult parseOptionalLSquare() override {
186 return success(parser.consumeIf(Token::l_square));
187 }
188
189 /// Parse a `]` token.
190 ParseResult parseRSquare() override {
191 return parser.parseToken(Token::r_square, "expected ']'");
192 }
193
194 /// Parses a ']' if present.
195 ParseResult parseOptionalRSquare() override {
196 return success(parser.consumeIf(Token::r_square));
197 }
198
199 /// Parses a '?' token.
200 ParseResult parseQuestion() override {
201 return parser.parseToken(Token::question, "expected '?'");
202 }
203
204 /// Parses a '?' if present.
205 ParseResult parseOptionalQuestion() override {
206 return success(parser.consumeIf(Token::question));
207 }
208
209 /// Parses a '/' token.
210 ParseResult parseSlash() override {
211 return parser.parseToken(Token::slash, "expected '/'");
212 }
213
214 /// Parses a '/' if present.
215 ParseResult parseOptionalSlash() override {
216 return success(parser.consumeIf(Token::slash));
217 }
218
219 /// Parses a '*' token.
220 ParseResult parseStar() override {
221 return parser.parseToken(Token::star, "expected '*'");
222 }
223
224 /// Parses a '*' if present.
225 ParseResult parseOptionalStar() override {
226 return success(parser.consumeIf(Token::star));
227 }
228
229 /// Parses a '+' token.
230 ParseResult parsePlus() override {
231 return parser.parseToken(Token::plus, "expected '+'");
232 }
233
234 /// Parses a '+' token if present.
235 ParseResult parseOptionalPlus() override {
236 return success(parser.consumeIf(Token::plus));
237 }
238
239 /// Parses a '-' token.
240 ParseResult parseMinus() override {
241 return parser.parseToken(Token::minus, "expected '-'");
242 }
243
244 /// Parses a '-' token if present.
245 ParseResult parseOptionalMinus() override {
246 return success(parser.consumeIf(Token::minus));
247 }
248
249 /// Parse a '|' token.
250 ParseResult parseVerticalBar() override {
251 return parser.parseToken(Token::vertical_bar, "expected '|'");
252 }
253
254 /// Parse a '|' token if present.
255 ParseResult parseOptionalVerticalBar() override {
256 return success(parser.consumeIf(Token::vertical_bar));
257 }
258
259 /// Parses a quoted string token if present.
260 ParseResult parseOptionalString(std::string *string) override {
261 return parser.parseOptionalString(string);
262 }
263
264 /// Parses a Base64 encoded string of bytes.
265 ParseResult parseBase64Bytes(std::vector<char> *bytes) override {
266 auto loc = getCurrentLocation();
267 if (!parser.getToken().is(Token::string))
268 return emitError(loc, "expected string");
269
270 if (bytes) {
271 // decodeBase64 doesn't modify its input so we can use the token spelling
272 // and just slice off the quotes/whitespaces if there are any. Whitespace
273 // and quotes cannot appear as part of a (standard) base64 encoded string,
274 // so this is safe to do.
275 StringRef b64QuotedString = parser.getTokenSpelling();
276 StringRef b64String =
277 b64QuotedString.ltrim("\" \t\n\v\f\r").rtrim("\" \t\n\v\f\r");
278 if (auto err = llvm::decodeBase64(b64String, *bytes))
279 return emitError(loc, toString(std::move(err)));
280 }
281
282 parser.consumeToken();
283 return success();
284 }
285
286 /// Parse a floating point value with given semantics from the stream. The
287 /// literal is parsed directly using the requested semantics, avoiding range
288 /// or precision loss from an intermediate double conversion.
289 ParseResult parseFloat(const llvm::fltSemantics &semantics,
290 APFloat &result) override {
291 bool isNegative = parser.consumeIf(Token::minus);
292 Token curTok = parser.getToken();
293 std::optional<APFloat> apResult;
294 if (failed(parser.parseFloatFromLiteral(apResult, curTok, isNegative,
295 semantics)))
296 return failure();
297 parser.consumeToken();
298 result = *apResult;
299 return success();
300 }
301
302 /// Parse a floating point value from the stream.
303 ParseResult parseFloat(double &result) override {
304 llvm::APFloat apResult(0.0);
305 if (parseFloat(APFloat::IEEEdouble(), apResult))
306 return failure();
307
308 result = apResult.convertToDouble();
309 return success();
310 }
311
312 /// Parse an optional integer value from the stream.
314 return parser.parseOptionalInteger(result);
315 }
316
317 /// Parse an optional integer value from the stream.
319 return parser.parseOptionalDecimalInteger(result);
320 }
321
322 /// Parse a list of comma-separated items with an optional delimiter. If a
323 /// delimiter is provided, then an empty list is allowed. If not, then at
324 /// least one element will be parsed.
325 ParseResult parseCommaSeparatedList(Delimiter delimiter,
326 function_ref<ParseResult()> parseElt,
327 StringRef contextMessage) override {
328 return parser.parseCommaSeparatedList(delimiter, parseElt, contextMessage);
329 }
330
331 //===--------------------------------------------------------------------===//
332 // Keyword Parsing
333 //===--------------------------------------------------------------------===//
334
335 ParseResult parseKeyword(StringRef keyword, const Twine &msg) override {
336 if (parser.getToken().isCodeCompletion())
337 return parser.codeCompleteExpectedTokens(keyword);
338
339 auto loc = getCurrentLocation();
340 if (parseOptionalKeyword(keyword))
341 return emitError(loc, "expected '") << keyword << "'" << msg;
342 return success();
343 }
345
346 /// Parse the given keyword if present.
347 ParseResult parseOptionalKeyword(StringRef keyword) override {
348 if (parser.getToken().isCodeCompletion())
349 return parser.codeCompleteOptionalTokens(keyword);
350
351 // Check that the current token has the same spelling.
352 if (!parser.isCurrentTokenAKeyword() ||
353 parser.getTokenSpelling() != keyword)
354 return failure();
355 parser.consumeToken();
356 return success();
357 }
358
359 /// Parse a keyword, if present, into 'keyword'.
360 ParseResult parseOptionalKeyword(StringRef *keyword) override {
361 return parser.parseOptionalKeyword(keyword);
362 }
363
364 /// Parse a keyword if it is one of the 'allowedKeywords'.
365 ParseResult
366 parseOptionalKeyword(StringRef *keyword,
367 ArrayRef<StringRef> allowedKeywords) override {
368 if (parser.getToken().isCodeCompletion())
369 return parser.codeCompleteOptionalTokens(allowedKeywords);
370
371 // Check that the current token is a keyword.
372 if (!parser.isCurrentTokenAKeyword())
373 return failure();
374
375 StringRef currentKeyword = parser.getTokenSpelling();
376 if (llvm::is_contained(allowedKeywords, currentKeyword)) {
377 *keyword = currentKeyword;
378 parser.consumeToken();
379 return success();
380 }
381
382 return failure();
383 }
384
385 /// Parse a string if it is one of the 'allowedKeywords'.
386 ParseResult
388 ArrayRef<StringRef> allowedKeywords) override {
389 // Check that the current token is a keyword.
390 if (!parser.getToken().is(Token::string))
391 return failure();
392
393 std::string string{};
394 string = parser.getToken().getStringValue();
395
396 if (llvm::is_contained(allowedKeywords, string)) {
397 parser.consumeToken();
398 if (result)
399 *result = std::move(string);
400 return success();
401 }
402
403 return failure();
404 }
405
406 /// Parse an optional keyword or string and set instance into 'result'.`
407 ParseResult parseOptionalKeywordOrString(std::string *result) override {
408 return parser.parseOptionalKeywordOrString(result);
409 }
410
411 ParseResult
413 ArrayRef<StringRef> allowedValues) override {
414 StringRef keyword;
415 if (succeeded(parseOptionalKeyword(&keyword, allowedValues))) {
416 *result = keyword.str();
417 return success();
418 }
419
420 return parseOptionalString(result, allowedValues);
421 }
422
423 //===--------------------------------------------------------------------===//
424 // Attribute Parsing
425 //===--------------------------------------------------------------------===//
426
427 /// Parse an arbitrary attribute and return it in result.
428 ParseResult parseAttribute(Attribute &result, Type type) override {
429 result = parser.parseAttribute(type);
430 return success(static_cast<bool>(result));
431 }
432
433 /// Parse a custom attribute with the provided callback, unless the next
434 /// token is `#`, in which case the generic parser is invoked.
436 Attribute &result, Type type,
437 function_ref<ParseResult(Attribute &result, Type type)> parseAttribute)
438 override {
439 if (parser.getToken().isNot(Token::hash_identifier))
440 return parseAttribute(result, type);
441 result = parser.parseAttribute(type);
442 return success(static_cast<bool>(result));
443 }
444
445 /// Parse a custom attribute with the provided callback, unless the next
446 /// token is `#`, in which case the generic parser is invoked.
448 Type &result,
449 function_ref<ParseResult(Type &result)> parseType) override {
450 if (parser.getToken().isNot(Token::exclamation_identifier))
451 return parseType(result);
452 result = parser.parseType();
453 return success(static_cast<bool>(result));
454 }
455
457 Type type) override {
458 return parser.parseOptionalAttribute(result, type);
459 }
461 Type type) override {
462 return parser.parseOptionalAttribute(result, type);
463 }
465 Type type) override {
466 return parser.parseOptionalAttribute(result, type);
467 }
469 Type type) override {
470 return parser.parseOptionalAttribute(result, type);
471 }
472
473 /// Parse a named dictionary into 'result' if it is present.
475 if (parser.getToken().isNot(Token::l_brace))
476 return success();
477 return parser.parseAttributeDict(result);
478 }
479
480 /// Parse a named dictionary into 'result' if the `attributes` keyword is
481 /// present.
483 if (failed(parseOptionalKeyword("attributes")))
484 return success();
485 return parser.parseAttributeDict(result);
486 }
487
488 /// Parse an affine map instance into 'map'.
489 ParseResult parseAffineMap(AffineMap &map) override {
490 return parser.parseAffineMapReference(map);
491 }
492
493 /// Parse an affine expr instance into 'expr' using the already computed
494 /// mapping from symbols to affine expressions in 'symbolSet'.
495 ParseResult
496 parseAffineExpr(ArrayRef<std::pair<StringRef, AffineExpr>> symbolSet,
497 AffineExpr &expr) override {
498 return parser.parseAffineExprReference(symbolSet, expr);
499 }
500
501 /// Parse an integer set instance into 'set'.
502 ParseResult parseIntegerSet(IntegerSet &set) override {
503 return parser.parseIntegerSetReference(set);
504 }
505
506 //===--------------------------------------------------------------------===//
507 // Identifier Parsing
508 //===--------------------------------------------------------------------===//
509
510 /// Parse an optional @-identifier and store it (without the '@' symbol) in a
511 /// string attribute named 'attrName'.
512 ParseResult parseOptionalSymbolName(StringAttr &result) override {
513 Token atToken = parser.getToken();
514 if (atToken.isNot(Token::at_identifier))
515 return failure();
516
518 parser.consumeToken();
519
520 // If we are populating the assembly parser state, record this as a symbol
521 // reference.
522 if (parser.getState().asmState) {
523 parser.getState().asmState->addUses(SymbolRefAttr::get(result),
524 atToken.getLocRange());
525 }
526 return success();
527 }
528
529 //===--------------------------------------------------------------------===//
530 // Resource Parsing
531 //===--------------------------------------------------------------------===//
532
533 /// Parse a handle to a resource within the assembly format.
534 FailureOr<AsmDialectResourceHandle>
535 parseResourceHandle(Dialect *dialect) override {
536 const auto *interface = dyn_cast<OpAsmDialectInterface>(dialect);
537 if (!interface) {
538 return parser.emitError() << "dialect '" << dialect->getNamespace()
539 << "' does not expect resource handles";
540 }
541 std::string resourceName;
542 return parser.parseResourceHandle(interface, resourceName);
543 }
544
545 //===--------------------------------------------------------------------===//
546 // Type Parsing
547 //===--------------------------------------------------------------------===//
548
549 /// Parse a type.
550 ParseResult parseType(Type &result) override {
551 return failure(!(result = parser.parseType()));
552 }
553
554 /// Parse an optional type.
556 return parser.parseOptionalType(result);
557 }
558
559 /// Parse an arrow followed by a type list.
561 if (parseArrow() || parser.parseFunctionResultTypes(result))
562 return failure();
563 return success();
564 }
565
566 /// Parse an optional arrow followed by a type list.
567 ParseResult
569 if (!parser.consumeIf(Token::arrow))
570 return success();
571 return parser.parseFunctionResultTypes(result);
572 }
573
574 /// Parse a colon followed by a type.
575 ParseResult parseColonType(Type &result) override {
576 return failure(parser.parseToken(Token::colon, "expected ':'") ||
577 !(result = parser.parseType()));
578 }
579
580 /// Parse a colon followed by a type list, which must have at least one type.
582 if (parser.parseToken(Token::colon, "expected ':'"))
583 return failure();
584 return parser.parseTypeListNoParens(result);
585 }
586
587 /// Parse an optional colon followed by a type list, which if present must
588 /// have at least one type.
589 ParseResult
591 if (!parser.consumeIf(Token::colon))
592 return success();
593 return parser.parseTypeListNoParens(result);
594 }
595
597 bool allowDynamic,
598 bool withTrailingX) override {
599 return parser.parseDimensionListRanked(dimensions, allowDynamic,
600 withTrailingX);
601 }
602
603 ParseResult parseXInDimensionList() override {
604 return parser.parseXInDimensionList();
605 }
606
607 LogicalResult pushCyclicParsing(const void *opaquePointer) override {
608 return success(parser.getState().cyclicParsingStack.insert(opaquePointer));
609 }
610
611 void popCyclicParsing() override {
612 parser.getState().cyclicParsingStack.pop_back();
613 }
614
615 //===--------------------------------------------------------------------===//
616 // Code Completion
617 //===--------------------------------------------------------------------===//
618
619 /// Parse a keyword, or an empty string if the current location signals a code
620 /// completion.
621 ParseResult parseKeywordOrCompletion(StringRef *keyword) override {
622 Token tok = parser.getToken();
623 if (tok.isCodeCompletion() && tok.getSpelling().empty()) {
624 *keyword = "";
625 return success();
626 }
627 return parseKeyword(keyword);
628 }
629
630 /// Signal the code completion of a set of expected tokens.
632 Token tok = parser.getToken();
633 if (tok.isCodeCompletion() && tok.getSpelling().empty())
634 (void)parser.codeCompleteExpectedTokens(tokens);
635 }
636
637protected:
638 /// The source location of the dialect symbol.
639 SMLoc nameLoc;
640
641 /// The main parser.
643
644 /// A flag that indicates if any errors were emitted during parsing.
645 bool emittedError = false;
646};
647} // namespace detail
648} // namespace mlir
649
650#endif // MLIR_LIB_ASMPARSER_ASMPARSERIMPL_H
return success()
ArrayAttr()
Base type for affine expression.
Definition AffineExpr.h:68
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Definition AffineMap.h:46
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:51
StringAttr getStringAttr(const Twine &bytes)
Definition Builders.cpp:271
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition Dialect.h:38
StringRef getNamespace() const
Definition Dialect.h:54
This class represents a diagnostic that is inflight and set to be reported.
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:76
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
This class implements Optional functionality for ParseResult.
This represents a token in the MLIR syntax.
Definition Token.h:20
SMRange getLocRange() const
Definition Token.cpp:30
std::string getSymbolReference() const
Given a token containing a symbol reference, return the unescaped string value.
Definition Token.cpp:144
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
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
ParseResult parseOptionalPlus() override
Parses a '+' token if present.
ParseResult parseOptionalLBrace() override
Parse a '{' token if present.
ParseResult parseOptionalArrowTypeList(SmallVectorImpl< Type > &result) override
Parse an optional arrow followed by a type list.
ParseResult parseOptionalStar() override
Parses a '*' if present.
ParseResult parseOptionalMinus() override
Parses a '-' token if present.
ParseResult parseColon() override
Parse a : token.
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.
ParseResult parseMinus() override
Parses a '-' token.
ParseResult parseOptionalKeywordOrString(std::string *result, ArrayRef< StringRef > allowedValues) override
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.
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 parseOptionalSlash() override
Parses a '/' if present.
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.
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.
ParseResult parseIntegerSet(IntegerSet &set) override
Parse an integer set instance into 'set'.
ParseResult parseFloat(const llvm::fltSemantics &semantics, APFloat &result) override
Parse a floating point value with given semantics from the stream.
Builder & getBuilder() const override
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
SMLoc getNameLoc() const override
Return the location of the original name token.
ParseResult parseOptionalQuestion() override
Parses a '?' if present.
ParseResult parseLBrace() override
Parse a '{' token.
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 parseOptionalString(std::string *result, ArrayRef< StringRef > allowedKeywords) override
Parse a string if it is one of the 'allowedKeywords'.
OptionalParseResult parseOptionalDecimalInteger(APInt &result) override
Parse an optional integer value from the stream.
ParseResult parseRBrace() override
Parse a } token.
ParseResult parseOptionalRBrace() override
Parse a } token if present.
ParseResult parseGreater() override
Parse a '>' token.
ParseResult parseColonTypeList(SmallVectorImpl< Type > &result) override
Parse a colon followed by a type list, which must have at least one type.
ParseResult parseSlash() override
Parses a '/' token.
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.
LogicalResult pushCyclicParsing(const void *opaquePointer) override
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)
ParseResult parseAffineExpr(ArrayRef< std::pair< StringRef, AffineExpr > > symbolSet, AffineExpr &expr) override
Parse an affine expr instance into 'expr' using the already computed mapping from symbols to affine e...
ParseResult parseOptionalKeyword(StringRef keyword) override
Parse the given keyword if present.
FailureOr< AsmDialectResourceHandle > parseResourceHandle(Dialect *dialect) override
Parse a handle to a resource within the assembly format.
bool didEmitError() const
Return if any errors were emitted during parsing.
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.
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.
~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.
AsmParser::Delimiter Delimiter
ParseResult parseOptionalEqual() override
Parse a = token if present.
void popCyclicParsing() override
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.
OptionalParseResult parseOptionalAttribute(SymbolRefAttr &result, Type type) override
SMLoc getCurrentLocation() override
Get the location of the next token and store it into the argument.
bool emittedError
A flag that indicates if any errors were emitted during parsing.
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:27
AttrTypeReplacer.
Include the generated interface declarations.
StringRef toString(AsmResourceEntryKind kind)
llvm::function_ref< Fn > function_ref
Definition LLVM.h:147