aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Tooling/Syntax/Tokens.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Tooling/Syntax/Tokens.cpp')
-rw-r--r--lib/Tooling/Syntax/Tokens.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/Tooling/Syntax/Tokens.cpp b/lib/Tooling/Syntax/Tokens.cpp
index d82dc1f35c94..a2c3bc137d6b 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));
}