27 #ifndef LLVM_CLANG_TOOLING_SYNTAX_TOKENS_H 28 #define LLVM_CLANG_TOOLING_SYNTAX_TOKENS_H 36 #include "llvm/ADT/ArrayRef.h" 37 #include "llvm/ADT/Optional.h" 38 #include "llvm/ADT/StringRef.h" 39 #include "llvm/Support/Compiler.h" 40 #include "llvm/Support/raw_ostream.h" 67 unsigned length()
const {
return End - Begin; }
71 return Begin <= Offset && Offset < End;
75 return Begin <= Offset && Offset <= End;
86 return std::tie(L.File, L.Begin, L.End) == std::tie(R.File, R.Begin, R.End);
117 unsigned length()
const {
return Length; }
139 std::string str()
const;
187 return ExpandedTokens;
256 std::vector<const syntax::Token *> macroExpansions(
FileID FID)
const;
260 std::string dumpForTests()
const;
274 unsigned BeginSpelled = 0;
275 unsigned EndSpelled = 0;
278 unsigned BeginExpanded = 0;
279 unsigned EndExpanded = 0;
282 std::string str()
const;
291 std::vector<syntax::Token> SpelledTokens;
293 std::vector<Mapping> Mappings;
295 unsigned BeginExpanded = 0;
296 unsigned EndExpanded = 0;
303 std::pair<const syntax::Token *, const Mapping *>
304 spelledForExpandedToken(
const syntax::Token *Expanded)
const;
309 std::vector<syntax::Token> ExpandedTokens;
310 llvm::DenseMap<FileID, MarkedFile> Files;
373 class CollectPPExpansions;
375 std::vector<syntax::Token> Expanded;
377 PPExpansions Expansions;
379 CollectPPExpansions *Collector;
llvm::StringRef text(const SourceManager &SM) const
Gets the substring that this FileRange refers to.
const SourceManager & sourceManager() const
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
friend bool operator==(const FileRange &L, const FileRange &R)
Defines the clang::FileManager interface and associated types.
llvm::ArrayRef< syntax::Token > spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens)
The spelled tokens that overlap or touch a spelling location Loc.
Defines the SourceManager interface.
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, NodeKind K)
For debugging purposes.
A token coming directly from a file or from a macro invocation.
FileRange(FileID File, unsigned BeginOffset, unsigned EndOffset)
EXPECTS: File.isValid() && Begin <= End.
llvm::ArrayRef< syntax::Token > expandedTokens() const
All tokens produced by the preprocessor after all macro replacements, directives, etc...
Token - This structure provides full information about a lexed token.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
llvm::ArrayRef< syntax::Token > Spelled
SourceLocation location() const
Location of the first character of a token.
CharSourceRange toCharRange(const SourceManager &SM) const
Convert to the clang range.
bool touches(unsigned Offset) const
Check Offset is inside the range or equal to its endpoint.
SourceLocation endLocation() const
Location right after the last character of a token.
TokenBuffer(const SourceManager &SourceMgr)
bool contains(unsigned Offset) const
Check if Offset is inside the range.
Defines the clang::LangOptions interface.
Represents a character-granular source range.
const syntax::Token * spelledIdentifierTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens)
The identifier token that overlaps or touches a spelling location Loc.
Encodes a location in the source.
tok::TokenKind kind() const
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
unsigned beginOffset() const
Start is a start offset (inclusive) in the corresponding file.
Dataflow Directional Tag Classes.
A half-open character range inside a particular file, the start offset is included and the end offset...
Collects tokens for the main file while running the frontend action.
std::vector< syntax::Token > tokenize(FileID FID, const SourceManager &SM, const LangOptions &LO)
Lex the text buffer, corresponding to FID, in raw mode and record the resulting spelled tokens...
Defines the clang::TokenKind enum and support functions.
Defines the clang::SourceLocation class and associated facilities.
An expansion produced by the preprocessor, includes macro expansions and preprocessor directives...
friend bool operator!=(const FileRange &L, const FileRange &R)
A list of tokens obtained by preprocessing a text buffer and operations to map between the expanded a...
A trivial tuple used to represent a source range.
llvm::ArrayRef< syntax::Token > Expanded
unsigned endOffset() const
End offset (exclusive) in the corresponding file.
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.