diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:09 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:09 +0000 |
commit | 519fc96c475680de2cc49e7811dbbfadb912cbcc (patch) | |
tree | 310ca684459b7e9ae13c9a3b9abf308b3a634afe /lib/Tooling/Syntax/Tokens.cpp | |
parent | 2298981669bf3bd63335a4be179bc0f96823a8f4 (diff) |
Notes
Diffstat (limited to 'lib/Tooling/Syntax/Tokens.cpp')
-rw-r--r-- | lib/Tooling/Syntax/Tokens.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Tooling/Syntax/Tokens.cpp b/lib/Tooling/Syntax/Tokens.cpp index d82dc1f35c944..a2c3bc137d6ba 100644 --- a/lib/Tooling/Syntax/Tokens.cpp +++ b/lib/Tooling/Syntax/Tokens.cpp @@ -232,6 +232,21 @@ TokenBuffer::expansionStartingAt(const syntax::Token *Spelled) const { return E; } +std::vector<const syntax::Token *> +TokenBuffer::macroExpansions(FileID FID) const { + auto FileIt = Files.find(FID); + assert(FileIt != Files.end() && "file not tracked by token buffer"); + auto &File = FileIt->second; + std::vector<const syntax::Token *> Expansions; + auto &Spelled = File.SpelledTokens; + for (auto Mapping : File.Mappings) { + const syntax::Token *Token = &Spelled[Mapping.BeginSpelled]; + if (Token->kind() == tok::TokenKind::identifier) + Expansions.push_back(Token); + } + return Expansions; +} + std::vector<syntax::Token> syntax::tokenize(FileID FID, const SourceManager &SM, const LangOptions &LO) { std::vector<syntax::Token> Tokens; @@ -321,7 +336,7 @@ TokenCollector::TokenCollector(Preprocessor &PP) : PP(PP) { }); // And locations of macro calls, to properly recover boundaries of those in // case of empty expansions. - auto CB = llvm::make_unique<CollectPPExpansions>(*this); + auto CB = std::make_unique<CollectPPExpansions>(*this); this->Collector = CB.get(); PP.addPPCallbacks(std::move(CB)); } |