summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Lex/LexerTest.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-01-20 16:52:43 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-01-20 16:52:43 +0000
commit85e7671b71a49beba14db59ebb87fc16b5a7fcb7 (patch)
tree2f8636bd9be40176283b484ce0fe9e40ea92633c /clang/unittests/Lex/LexerTest.cpp
parent528f56c93fc6a80f1827da2c4128c497d1dcbe37 (diff)
downloadbcm5719-llvm-85e7671b71a49beba14db59ebb87fc16b5a7fcb7.tar.gz
bcm5719-llvm-85e7671b71a49beba14db59ebb87fc16b5a7fcb7.zip
Enhance Lexer::makeFileCharRange to check for ranges inside a macro argument
expansion, in which case it returns a file range in the location where the argument was spelled. llvm-svn: 148551
Diffstat (limited to 'clang/unittests/Lex/LexerTest.cpp')
-rw-r--r--clang/unittests/Lex/LexerTest.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/clang/unittests/Lex/LexerTest.cpp b/clang/unittests/Lex/LexerTest.cpp
index c83a6ac8cf6..7d9e9e9cbc7 100644
--- a/clang/unittests/Lex/LexerTest.cpp
+++ b/clang/unittests/Lex/LexerTest.cpp
@@ -58,7 +58,8 @@ class VoidModuleLoader : public ModuleLoader {
TEST_F(LexerTest, LexAPI) {
const char *source =
"#define M(x) [x]\n"
- "M(foo)";
+ "#define N(x) x\n"
+ "M(foo) N([bar])";
MemoryBuffer *buf = MemoryBuffer::getMemBuffer(source);
SourceMgr.createMainFileIDForMemBuffer(buf);
@@ -82,10 +83,13 @@ TEST_F(LexerTest, LexAPI) {
}
// Make sure we got the tokens that we expected.
- ASSERT_EQ(3U, toks.size());
+ ASSERT_EQ(6U, toks.size());
ASSERT_EQ(tok::l_square, toks[0].getKind());
ASSERT_EQ(tok::identifier, toks[1].getKind());
ASSERT_EQ(tok::r_square, toks[2].getKind());
+ ASSERT_EQ(tok::l_square, toks[3].getKind());
+ ASSERT_EQ(tok::identifier, toks[4].getKind());
+ ASSERT_EQ(tok::r_square, toks[5].getKind());
SourceLocation lsqrLoc = toks[0].getLocation();
SourceLocation idLoc = toks[1].getLocation();
@@ -119,6 +123,34 @@ TEST_F(LexerTest, LexAPI) {
CharSourceRange::getTokenRange(SourceRange(lsqrLoc, rsqrLoc)),
SourceMgr, LangOpts);
EXPECT_EQ(text, "M(foo)");
+
+ SourceLocation macroLsqrLoc = toks[3].getLocation();
+ SourceLocation macroIdLoc = toks[4].getLocation();
+ SourceLocation macroRsqrLoc = toks[5].getLocation();
+ SourceLocation fileLsqrLoc = SourceMgr.getSpellingLoc(macroLsqrLoc);
+ SourceLocation fileIdLoc = SourceMgr.getSpellingLoc(macroIdLoc);
+ SourceLocation fileRsqrLoc = SourceMgr.getSpellingLoc(macroRsqrLoc);
+
+ range = Lexer::makeFileCharRange(SourceRange(macroLsqrLoc, macroIdLoc),
+ SourceMgr, LangOpts);
+ EXPECT_EQ(SourceRange(fileLsqrLoc, fileIdLoc.getLocWithOffset(3)),
+ range.getAsRange());
+
+ range = Lexer::makeFileCharRange(SourceRange(macroIdLoc, macroRsqrLoc),
+ SourceMgr, LangOpts);
+ EXPECT_EQ(SourceRange(fileIdLoc, fileRsqrLoc.getLocWithOffset(1)),
+ range.getAsRange());
+
+ macroPair = SourceMgr.getExpansionRange(macroLsqrLoc);
+ range = Lexer::makeFileCharRange(SourceRange(macroLsqrLoc, macroRsqrLoc),
+ SourceMgr, LangOpts);
+ EXPECT_EQ(SourceRange(macroPair.first, macroPair.second.getLocWithOffset(1)),
+ range.getAsRange());
+
+ text = Lexer::getSourceText(
+ CharSourceRange::getTokenRange(SourceRange(macroLsqrLoc, macroIdLoc)),
+ SourceMgr, LangOpts);
+ EXPECT_EQ(text, "[bar");
}
} // anonymous namespace
OpenPOWER on IntegriCloud