diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-01-19 15:59:14 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-01-19 15:59:14 +0000 |
commit | 11b652d41d0d97380ab321a1dba48ecb044f9de8 (patch) | |
tree | 94aa7ff36d083794630aa801f3166d96c80993bb /unittests/Lex/LexerTest.cpp | |
parent | 69bda4c027671df7163619f215209529eb236620 (diff) | |
download | clang-11b652d41d0d97380ab321a1dba48ecb044f9de8.tar.gz clang-11b652d41d0d97380ab321a1dba48ecb044f9de8.tar.bz2 clang-11b652d41d0d97380ab321a1dba48ecb044f9de8.tar.xz |
Introduce Lexer::makeFileCharRange() that accepts a token source range
and returns a character range with file locations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148480 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Lex/LexerTest.cpp')
-rw-r--r-- | unittests/Lex/LexerTest.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp index e63f31a705..05478eef9f 100644 --- a/unittests/Lex/LexerTest.cpp +++ b/unittests/Lex/LexerTest.cpp @@ -90,14 +90,30 @@ TEST_F(LexerTest, LexAPI) { SourceLocation lsqrLoc = toks[0].getLocation(); SourceLocation idLoc = toks[1].getLocation(); SourceLocation rsqrLoc = toks[2].getLocation(); - + std::pair<SourceLocation,SourceLocation> + macroPair = SourceMgr.getExpansionRange(lsqrLoc); + SourceRange macroRange = SourceRange(macroPair.first, macroPair.second); + SourceLocation Loc; EXPECT_TRUE(Lexer::isAtStartOfMacroExpansion(lsqrLoc, SourceMgr, LangOpts, &Loc)); - EXPECT_EQ(SourceMgr.getExpansionLoc(lsqrLoc), Loc); + EXPECT_EQ(Loc, macroRange.getBegin()); EXPECT_FALSE(Lexer::isAtStartOfMacroExpansion(idLoc, SourceMgr, LangOpts)); EXPECT_FALSE(Lexer::isAtEndOfMacroExpansion(idLoc, SourceMgr, LangOpts)); EXPECT_TRUE(Lexer::isAtEndOfMacroExpansion(rsqrLoc, SourceMgr, LangOpts, &Loc)); - EXPECT_EQ(SourceMgr.getExpansionRange(rsqrLoc).second, Loc); + EXPECT_EQ(Loc, macroRange.getEnd()); + + CharSourceRange range = Lexer::makeFileCharRange(SourceRange(lsqrLoc, idLoc), + SourceMgr, LangOpts); + EXPECT_TRUE(range.isInvalid()); + range = Lexer::makeFileCharRange(SourceRange(idLoc, rsqrLoc), + SourceMgr, LangOpts); + EXPECT_TRUE(range.isInvalid()); + range = Lexer::makeFileCharRange(SourceRange(lsqrLoc, rsqrLoc), + SourceMgr, LangOpts); + EXPECT_TRUE(!range.isTokenRange()); + EXPECT_EQ(range.getAsRange(), + SourceRange(macroRange.getBegin(), + macroRange.getEnd().getLocWithOffset(1))); } } // anonymous namespace |