summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling/Syntax/TokensTest.cpp
diff options
context:
space:
mode:
authorJohan Vikstrom <jvikstrom@google.com>2019-08-20 13:34:01 +0000
committerJohan Vikstrom <jvikstrom@google.com>2019-08-20 13:34:01 +0000
commit6687fde07aeaea958d9f9b385949dbde769b20f7 (patch)
tree8433952735f0397550eda19de0449f19861e37f4 /clang/unittests/Tooling/Syntax/TokensTest.cpp
parentcec028fc14dda68c80e489b861adcf28944151f6 (diff)
downloadbcm5719-llvm-6687fde07aeaea958d9f9b385949dbde769b20f7.tar.gz
bcm5719-llvm-6687fde07aeaea958d9f9b385949dbde769b20f7.zip
[Syntax] Added function to get macro expansion tokens to TokenBuffer.
Summary: Returns the first token in every mapping where the token is an identifier. This API is required to be able to highlight macro expansions in clangd. Reviewers: hokein, ilya-biryukov Subscribers: kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66470 llvm-svn: 369385
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TokensTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/TokensTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/Syntax/TokensTest.cpp b/clang/unittests/Tooling/Syntax/TokensTest.cpp
index 78f0d2fdd87..6ffe2c43dd0 100644
--- a/clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -755,4 +755,27 @@ TEST_F(TokenBufferTest, TokensToFileRange) {
// We don't test assertion failures because death tests are slow.
}
+TEST_F(TokenBufferTest, macroExpansions) {
+ llvm::Annotations Code(R"cpp(
+ #define FOO B
+ #define FOO2 BA
+ #define CALL(X) int X
+ #define G CALL(FOO2)
+ int B;
+ $macro[[FOO]];
+ $macro[[CALL]](A);
+ $macro[[G]];
+ )cpp");
+ recordTokens(Code.code());
+ auto &SM = *SourceMgr;
+ auto Expansions = Buffer.macroExpansions(SM.getMainFileID());
+ std::vector<FileRange> ExpectedMacroRanges;
+ for (auto Range : Code.ranges("macro"))
+ ExpectedMacroRanges.push_back(
+ FileRange(SM.getMainFileID(), Range.Begin, Range.End));
+ std::vector<FileRange> ActualMacroRanges;
+ for (auto Expansion : Expansions)
+ ActualMacroRanges.push_back(Expansion->range(SM));
+ EXPECT_EQ(ExpectedMacroRanges, ActualMacroRanges);
+}
} // namespace
OpenPOWER on IntegriCloud