27#ifndef LLVM_CLANG_TOOLING_SYNTAX_TOKENS_H
28#define LLVM_CLANG_TOOLING_SYNTAX_TOKENS_H
35#include "llvm/ADT/ArrayRef.h"
36#include "llvm/ADT/DenseMap.h"
37#include "llvm/ADT/StringRef.h"
38#include "llvm/Support/Compiler.h"
39#include "llvm/Support/raw_ostream.h"
66 unsigned length()
const {
return End - Begin; }
70 return Begin <= Offset && Offset < End;
74 return Begin <= Offset && Offset <= End;
85 return std::tie(L.File, L.Begin, L.End) == std::tie(R.File, R.Begin, R.End);
98llvm::raw_ostream &
operator<<(llvm::raw_ostream &OS,
const FileRange &R);
116 unsigned length()
const {
return Length; }
138 std::string
str()
const;
191 return ExpandedTokens;
231 std::optional<llvm::ArrayRef<syntax::Token>>
280 std::optional<Expansion>
284 std::vector<Expansion>
325 unsigned BeginSpelled = 0;
326 unsigned EndSpelled = 0;
329 unsigned BeginExpanded = 0;
330 unsigned EndExpanded = 0;
333 std::string str()
const;
342 std::vector<syntax::Token> SpelledTokens;
344 std::vector<Mapping> Mappings;
346 unsigned BeginExpanded = 0;
347 unsigned EndExpanded = 0;
354 std::pair<const syntax::Token *, const Mapping *>
355 spelledForExpandedToken(
const syntax::Token *Expanded)
const;
359 static const Mapping *
360 mappingStartingBeforeSpelled(
const MarkedFile &F,
364 Expansion makeExpansion(
const MarkedFile &,
const Mapping &)
const;
372 std::vector<syntax::Token> ExpandedTokens;
374 llvm::DenseMap<SourceLocation, unsigned> ExpandedTokIndex;
375 llvm::DenseMap<FileID, MarkedFile> Files;
411std::vector<syntax::Token>
447 using PPExpansions = llvm::DenseMap<SourceLocation, SourceLocation>;
449 class CollectPPExpansions;
451 std::vector<syntax::Token> Expanded;
453 PPExpansions Expansions;
455 CollectPPExpansions *Collector;
Defines the clang::LangOptions interface.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines the clang::TokenKind enum and support functions.
Represents a character-granular source range.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Token - This structure provides full information about a lexed token.
A list of tokens obtained by preprocessing a text buffer and operations to map between the expanded a...
TokenBuffer(const SourceManager &SourceMgr)
const syntax::Token * spelledTokenContaining(SourceLocation Loc) const
Returns the spelled Token containing the Loc, if there are no such tokens returns nullptr.
const SourceManager & sourceManager() const
void indexExpandedTokens()
Builds a cache to make future calls to expandedToken(SourceRange) faster.
llvm::SmallVector< llvm::ArrayRef< syntax::Token >, 1 > expandedForSpelled(llvm::ArrayRef< syntax::Token > Spelled) const
Find the subranges of expanded tokens, corresponding to Spelled.
TokenBuffer & operator=(const TokenBuffer &)=delete
TokenBuffer(TokenBuffer &&)=default
llvm::ArrayRef< syntax::Token > expandedTokens() const
All tokens produced by the preprocessor after all macro replacements, directives, etc.
std::string dumpForTests() const
std::optional< llvm::ArrayRef< syntax::Token > > spelledForExpanded(llvm::ArrayRef< syntax::Token > Expanded) const
Returns the subrange of spelled tokens corresponding to AST node spanning Expanded.
TokenBuffer & operator=(TokenBuffer &&)=default
TokenBuffer(const TokenBuffer &)=delete
std::vector< Expansion > expansionsOverlapping(llvm::ArrayRef< syntax::Token > Spelled) const
Returns all expansions (partially) expanded from the specified tokens.
std::optional< Expansion > expansionStartingAt(const syntax::Token *Spelled) const
If Spelled starts a mapping (e.g.
llvm::ArrayRef< syntax::Token > spelledTokens(FileID FID) const
Lexed tokens of a file before preprocessing.
std::vector< const syntax::Token * > macroExpansions(FileID FID) const
Get all tokens that expand a macro in FID.
Collects tokens for the main file while running the frontend action.
TokenBuffer consume() &&
Finalizes token collection.
A token coming directly from a file or from a macro invocation.
std::string str() const
For debugging purposes.
llvm::StringRef text(const SourceManager &SM) const
Get the substring covered by the token.
tok::TokenKind kind() const
SourceLocation endLocation() const
Location right after the last character of a token.
FileRange range(const SourceManager &SM) const
Gets a range of this token.
std::string dumpForTests(const SourceManager &SM) const
SourceLocation location() const
Location of the first character of a token.
const syntax::Token * spelledIdentifierTouching(SourceLocation Loc, llvm::ArrayRef< syntax::Token > Tokens)
The identifier token that overlaps or touches a spelling location Loc.
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.
raw_ostream & operator<<(raw_ostream &OS, NodeKind K)
For debugging purposes.
llvm::ArrayRef< syntax::Token > spelledTokensTouching(SourceLocation Loc, const syntax::TokenBuffer &Tokens)
The spelled tokens that overlap or touch a spelling location Loc.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
A half-open character range inside a particular file, the start offset is included and the end offset...
CharSourceRange toCharRange(const SourceManager &SM) const
Convert to the clang range.
bool contains(unsigned Offset) const
Check if Offset is inside the range.
friend bool operator==(const FileRange &L, const FileRange &R)
friend bool operator!=(const FileRange &L, const FileRange &R)
unsigned beginOffset() const
Start is a start offset (inclusive) in the corresponding file.
llvm::StringRef text(const SourceManager &SM) const
Gets the substring that this FileRange refers to.
bool touches(unsigned Offset) const
Check Offset is inside the range or equal to its endpoint.
unsigned endOffset() const
End offset (exclusive) in the corresponding file.
An expansion produced by the preprocessor, includes macro expansions and preprocessor directives.
llvm::ArrayRef< syntax::Token > Expanded
llvm::ArrayRef< syntax::Token > Spelled