9 #ifndef LIB_TOOLS_PDLL_PARSER_LEXER_H_
10 #define LIB_TOOLS_PDLL_PARSER_LEXER_H_
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/SMLoc.h"
22 class CodeCompleteContext;
25 class DiagnosticEngine;
99 Token(
Kind kind, StringRef spelling) : kind(kind), spelling(spelling) {}
128 template <
typename... T>
130 return is(k1) ||
isAny(k2, k3, others...);
135 template <
typename... T>
137 return !
isAny(k1, k2, others...);
141 bool is(
Kind k)
const {
return kind == k; }
144 SMLoc
getStartLoc()
const {
return SMLoc::getFromPointer(spelling.data()); }
147 return SMLoc::getFromPointer(spelling.data() + spelling.size());
180 LogicalResult
pushInclude(StringRef filename, SMRange includeLoc);
197 return Token(kind, StringRef(tokStart, curPtr - tokStart));
205 Token lexDirective(
const char *tokStart);
206 Token lexIdentifier(
const char *tokStart);
207 Token lexNumber(
const char *tokStart);
208 Token lexString(
const char *tokStart,
bool isStringBlock);
210 llvm::SourceMgr &srcMgr;
220 bool addedHandlerToDiagEngine;
223 const char *codeCompletionLocation;
This class provides an abstract interface into the parser for hooking in code completion events.
Token emitError(SMRange loc, const Twine &msg)
Emit an error to the lexer with the given location and message.
Token emitError(const char *loc, const Twine &msg)
Token emitErrorAndNote(SMRange loc, const Twine &msg, SMRange noteLoc, const Twine ¬e)
Token lexToken()
Lex the next token and return it.
llvm::SourceMgr & getSourceMgr()
Return a reference to the source manager used by the lexer.
ast::DiagnosticEngine & getDiagEngine()
Return a reference to the diagnostic engine used by the lexer.
void resetPointer(const char *newPointer)
Change the position of the lexer cursor.
LogicalResult pushInclude(StringRef filename, SMRange includeLoc)
Push an include of the given file.
Lexer(llvm::SourceMgr &mgr, ast::DiagnosticEngine &diagEngine, CodeCompleteContext *codeCompleteContext)
bool isNot(Kind k) const
Return if the token does not have the given kind.
bool isNot(Kind k1, Kind k2, T... others) const
bool is(Kind k) const
Return if the token has the given kind.
StringRef getSpelling() const
Return the bytes that make up this token.
SMRange getLoc() const
Return a location for the range of this token.
Token(Kind kind, StringRef spelling)
bool isString() const
Returns true if the current token is a string literal.
bool isDependentKeyword() const
Returns true if the current token is a keyword in a dependent context, and in any other situation (e....
@ code_complete_string
Token signifying a code completion location within a string.
@ code_complete
Token signifying a code completion location.
@ KW_DEPENDENT_BEGIN
Dependent keywords, i.e.
@ less
Paired punctuation.
@ kw_Attr
General keywords.
SMLoc getEndLoc() const
Return a location at the end of this token.
SMLoc getStartLoc() const
Return a location for the start of this token.
bool isAny(Kind k1, Kind k2, Kind k3, T... others) const
bool isAny(Kind k1, Kind k2) const
Return true if this token is one of the specified kinds.
bool isKeyword() const
Returns true if the current token is a keyword.
Kind getKind() const
Return the kind of this token.
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
This class manages the construction and emission of PDLL diagnostics.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.