MLIR  17.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/StringMap.h"
16 
17 namespace mlir {
18 class OpAsmDialectInterface;
19 
20 namespace detail {
21 
22 //===----------------------------------------------------------------------===//
23 // SymbolState
24 //===----------------------------------------------------------------------===//
25 
26 /// This class contains record of any parsed top-level symbols.
27 struct SymbolState {
28  /// A map from attribute alias identifier to Attribute.
29  llvm::StringMap<Attribute> attributeAliasDefinitions;
30 
31  /// A map from type alias identifier to Type.
32  llvm::StringMap<Type> typeAliasDefinitions;
33 
34  /// A map of dialect resource keys to the resolved resource name and handle
35  /// to use during parsing.
37  llvm::StringMap<std::pair<std::string, AsmDialectResourceHandle>>>
39 };
40 
41 //===----------------------------------------------------------------------===//
42 // ParserState
43 //===----------------------------------------------------------------------===//
44 
45 /// This class refers to all of the state maintained globally by the parser,
46 /// such as the current lexer position etc.
47 struct ParserState {
48  ParserState(const llvm::SourceMgr &sourceMgr, const ParserConfig &config,
51  : config(config),
52  lex(sourceMgr, config.getContext(), codeCompleteContext),
53  curToken(lex.lexToken()), symbols(symbols), asmState(asmState),
55  ParserState(const ParserState &) = delete;
56  void operator=(const ParserState &) = delete;
57 
58  /// The configuration used to setup the parser.
60 
61  /// The lexer for the source file we're parsing.
63 
64  /// This is the next token that hasn't been consumed yet.
66 
67  /// The current state for symbol parsing.
69 
70  /// An optional pointer to a struct containing high level parser state to be
71  /// populated during parsing.
73 
74  /// An optional code completion context.
76 
77  // Contains the stack of default dialect to use when parsing regions.
78  // A new dialect get pushed to the stack before parsing regions nested
79  // under an operation implementing `OpAsmOpInterface`, and
80  // popped when done. At the top-level we start with "builtin" as the
81  // default, so that the top-level `module` operation parses as-is.
83 };
84 
85 } // namespace detail
86 } // namespace mlir
87 
88 #endif // MLIR_LIB_ASMPARSER_PARSERSTATE_H
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:458
This represents a token in the MLIR syntax.
Definition: Token.h:20
This header declares functions that assit transformations in the MemRef dialect.
This class refers to all of the state maintained globally by the parser, such as the current lexer po...
Definition: ParserState.h:47
SymbolState & symbols
The current state for symbol parsing.
Definition: ParserState.h:68
const ParserConfig & config
The configuration used to setup the parser.
Definition: ParserState.h:59
Lexer lex
The lexer for the source file we're parsing.
Definition: ParserState.h:62
Token curToken
This is the next token that hasn't been consumed yet.
Definition: ParserState.h:65
AsmParserCodeCompleteContext * codeCompleteContext
An optional code completion context.
Definition: ParserState.h:75
AsmParserState * asmState
An optional pointer to a struct containing high level parser state to be populated during parsing.
Definition: ParserState.h:72
SmallVector< StringRef > defaultDialectStack
Definition: ParserState.h:82
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:48
This class contains record of any parsed top-level symbols.
Definition: ParserState.h:27
llvm::StringMap< Attribute > attributeAliasDefinitions
A map from attribute alias identifier to Attribute.
Definition: ParserState.h:29
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:38
llvm::StringMap< Type > typeAliasDefinitions
A map from type alias identifier to Type.
Definition: ParserState.h:32