MLIR  20.0.0git
ParserState.h
Go to the documentation of this file.
1 //===- ParserState.h - MLIR ParserState -------------------------*- 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_PARSERSTATE_H
10 #define MLIR_LIB_ASMPARSER_PARSERSTATE_H
11 
12 #include "Lexer.h"
13 #include "mlir/IR/Attributes.h"
15 #include "llvm/ADT/SetVector.h"
16 #include "llvm/ADT/StringMap.h"
17 
18 namespace mlir {
19 class OpAsmDialectInterface;
20 
21 namespace detail {
22 
23 //===----------------------------------------------------------------------===//
24 // SymbolState
25 //===----------------------------------------------------------------------===//
26 
27 /// This class contains record of any parsed top-level symbols.
28 struct SymbolState {
29  /// A map from attribute alias identifier to Attribute.
30  llvm::StringMap<Attribute> attributeAliasDefinitions;
31 
32  /// A map from type alias identifier to Type.
33  llvm::StringMap<Type> typeAliasDefinitions;
34 
35  /// A map of dialect resource keys to the resolved resource name and handle
36  /// to use during parsing.
38  llvm::StringMap<std::pair<std::string, AsmDialectResourceHandle>>>
40 
41  /// A map from unique integer identifier to DistinctAttr.
43 };
44 
45 //===----------------------------------------------------------------------===//
46 // ParserState
47 //===----------------------------------------------------------------------===//
48 
49 /// This class refers to all of the state maintained globally by the parser,
50 /// such as the current lexer position etc.
51 struct ParserState {
52  ParserState(const llvm::SourceMgr &sourceMgr, const ParserConfig &config,
55  : config(config),
57  curToken(lex.lexToken()), lastToken(Token::error, ""), symbols(symbols),
59  ParserState(const ParserState &) = delete;
60  void operator=(const ParserState &) = delete;
61 
62  /// The configuration used to setup the parser.
64 
65  /// The lexer for the source file we're parsing.
67 
68  /// This is the next token that hasn't been consumed yet.
70 
71  /// This is the last token that has been consumed.
73 
74  /// The current state for symbol parsing.
76 
77  /// Stack of potentially cyclic mutable attributes or type currently being
78  /// parsed.
80 
81  /// An optional pointer to a struct containing high level parser state to be
82  /// populated during parsing.
84 
85  /// An optional code completion context.
87 
88  // Contains the stack of default dialect to use when parsing regions.
89  // A new dialect get pushed to the stack before parsing regions nested
90  // under an operation implementing `OpAsmOpInterface`, and
91  // popped when done. At the top-level we start with "builtin" as the
92  // default, so that the top-level `module` operation parses as-is.
94 };
95 
96 } // namespace detail
97 } // namespace mlir
98 
99 #endif // MLIR_LIB_ASMPARSER_PARSERSTATE_H
static MLIRContext * getContext(OpFoldResult val)
This class provides an abstract interface into the parser for hooking in code completion events.
Definition: CodeComplete.h:24
This class represents state from a parsed MLIR textual format string.
This class breaks up the current file into a token stream.
Definition: Lexer.h:23
This class represents a configuration for the MLIR assembly parser.
Definition: AsmState.h:467
This represents a token in the MLIR syntax.
Definition: Token.h:20
Include the generated interface declarations.
This class refers to all of the state maintained globally by the parser, such as the current lexer po...
Definition: ParserState.h:51
SetVector< const void * > cyclicParsingStack
Stack of potentially cyclic mutable attributes or type currently being parsed.
Definition: ParserState.h:79
SymbolState & symbols
The current state for symbol parsing.
Definition: ParserState.h:75
const ParserConfig & config
The configuration used to setup the parser.
Definition: ParserState.h:63
Lexer lex
The lexer for the source file we're parsing.
Definition: ParserState.h:66
Token curToken
This is the next token that hasn't been consumed yet.
Definition: ParserState.h:69
Token lastToken
This is the last token that has been consumed.
Definition: ParserState.h:72
AsmParserCodeCompleteContext * codeCompleteContext
An optional code completion context.
Definition: ParserState.h:86
AsmParserState * asmState
An optional pointer to a struct containing high level parser state to be populated during parsing.
Definition: ParserState.h:83
SmallVector< StringRef > defaultDialectStack
Definition: ParserState.h:93
void operator=(const ParserState &)=delete
ParserState(const ParserState &)=delete
ParserState(const llvm::SourceMgr &sourceMgr, const ParserConfig &config, SymbolState &symbols, AsmParserState *asmState, AsmParserCodeCompleteContext *codeCompleteContext)
Definition: ParserState.h:52
This class contains record of any parsed top-level symbols.
Definition: ParserState.h:28
llvm::StringMap< Attribute > attributeAliasDefinitions
A map from attribute alias identifier to Attribute.
Definition: ParserState.h:30
DenseMap< const OpAsmDialectInterface *, llvm::StringMap< std::pair< std::string, AsmDialectResourceHandle > > > dialectResources
A map of dialect resource keys to the resolved resource name and handle to use during parsing.
Definition: ParserState.h:39
DenseMap< uint64_t, DistinctAttr > distinctAttributes
A map from unique integer identifier to DistinctAttr.
Definition: ParserState.h:42
llvm::StringMap< Type > typeAliasDefinitions
A map from type alias identifier to Type.
Definition: ParserState.h:33