MLIR: lib/AsmParser/Token.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9 #ifndef MLIR_LIB_PARSER_TOKEN_H
10 #define MLIR_LIB_PARSER_TOKEN_H
11
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/SMLoc.h"
15 #include
16
17 namespace mlir {
18
19
21 public:
23 #define TOK_MARKER(NAME) NAME,
24 #define TOK_IDENTIFIER(NAME) NAME,
25 #define TOK_LITERAL(NAME) NAME,
26 #define TOK_PUNCTUATION(NAME, SPELLING) NAME,
27 #define TOK_KEYWORD(SPELLING) kw_##SPELLING,
28 #include "TokenKinds.def"
29 };
30
32
33
34 StringRef getSpelling() const { return spelling; }
35
36
38 bool is(Kind k) const { return kind == k; }
39
41
42
43 template <typename... T>
45 if (is(k1))
46 return true;
47 return isAny(k2, k3, others...);
48 }
49
50 bool isNot(Kind k) const { return kind != k; }
51
52
53 template <typename... T>
55 return (k1, k2, others...);
56 }
57
58
60
61
63
64
65
67
68
69
72 }
73
74
75
76
77
79
80
81
85 }
86
87
88
90
91
93
94
95
96
98
99
100
101
103
104
105
107
108
109
110
111
113
114
115
117
118
119 SMLoc getLoc() const;
122
123
124
125
127
128 private:
129
131
132
133
134 StringRef spelling;
135 };
136
137 }
138
139 #endif
union mlir::linalg::@1203::ArityGroupAndKind::Kind kind
This represents a token in the MLIR syntax.
bool isCodeCompletionFor(Kind kind) const
Returns true if the current token represents a code completion for the "normal" token type.
SMRange getLocRange() const
bool isKeyword() const
Return true if this is one of the keyword token kinds (e.g. kw_if).
static StringRef getTokenSpelling(Kind kind)
Given a punctuation or keyword token kind, return the spelling of the token as a string.
bool isAny(Kind k1, Kind k2, Kind k3, T... others) const
Return true if this token is one of the specified kinds.
bool isNot(Kind k1, Kind k2, T... others) const
Return true if this token isn't one of the specified kinds.
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
std::string getSymbolReference() const
Given a token containing a symbol reference, return the unescaped string value.
std::optional< unsigned > getUnsignedIntegerValue() const
For an integer token, return its value as an unsigned.
std::optional< uint64_t > getUInt64IntegerValue() const
std::optional< double > getFloatingPointValue() const
For a floatliteral token, return its value as a double.
Token(Kind kind, StringRef spelling)
bool isAny(Kind k1, Kind k2) const
std::optional< unsigned > getHashIdentifierNumber() const
Given a hash_identifier token like #123, try to parse the number out of the identifier,...
bool isCodeCompletion() const
Returns true if the current token represents a code completion.
StringRef getSpelling() const
std::optional< bool > getIntTypeSignedness() const
For an inttype token, return its signedness semantics: std::nullopt means no signedness semantics; tr...
bool isOrIsCodeCompletionFor(Kind kind) const
Returns true if the current token is the given type, or represents a code completion for that type.
std::optional< unsigned > getIntTypeBitwidth() const
For an inttype token, return its bitwidth.
std::optional< std::string > getHexStringValue() const
Given a token containing a hex string literal, return its value or std::nullopt if the token does not...
Include the generated interface declarations.