diff options
author | Rafael Stahl <r.stahl@tum.de> | 2018-07-04 13:34:05 +0000 |
---|---|---|
committer | Rafael Stahl <r.stahl@tum.de> | 2018-07-04 13:34:05 +0000 |
commit | 29f37fbb8b3dc877f7ea77a6c065d4fa9b9dba16 (patch) | |
tree | abaee3b5823cdbb6b750e38c54099f95cffb0009 /clang/unittests/AST/ASTImporterTest.cpp | |
parent | da4a966e1c3c0315512e1dfe5cd486722bcc0fbf (diff) | |
download | bcm5719-llvm-29f37fbb8b3dc877f7ea77a6c065d4fa9b9dba16.tar.gz bcm5719-llvm-29f37fbb8b3dc877f7ea77a6c065d4fa9b9dba16.zip |
[ASTImporter] import macro source locations
Summary: Implement full import of macro expansion info with spelling and expansion locations.
Reviewers: a.sidorin, klimek, martong, balazske, xazax.hun
Reviewed By: martong
Subscribers: thakis, xazax.hun, balazske, rnkovacs, cfe-commits
Differential Revision: https://reviews.llvm.org/D47698
llvm-svn: 336269
Diffstat (limited to 'clang/unittests/AST/ASTImporterTest.cpp')
-rw-r--r-- | clang/unittests/AST/ASTImporterTest.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index b1e6e42b5a4..dfcb6c18939 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -1577,6 +1577,66 @@ TEST_P(ASTImporterTestBase, ToTU, cxxRecordDecl(unless(isImplicit())))); } +static void CompareSourceLocs(FullSourceLoc Loc1, FullSourceLoc Loc2) { + EXPECT_EQ(Loc1.getExpansionLineNumber(), Loc2.getExpansionLineNumber()); + EXPECT_EQ(Loc1.getExpansionColumnNumber(), Loc2.getExpansionColumnNumber()); + EXPECT_EQ(Loc1.getSpellingLineNumber(), Loc2.getSpellingLineNumber()); + EXPECT_EQ(Loc1.getSpellingColumnNumber(), Loc2.getSpellingColumnNumber()); +} +static void CompareSourceRanges(SourceRange Range1, SourceRange Range2, + SourceManager &SM1, SourceManager &SM2) { + CompareSourceLocs(FullSourceLoc{ Range1.getBegin(), SM1 }, + FullSourceLoc{ Range2.getBegin(), SM2 }); + CompareSourceLocs(FullSourceLoc{ Range1.getEnd(), SM1 }, + FullSourceLoc{ Range2.getEnd(), SM2 }); +} +TEST_P(ASTImporterTestBase, ImportSourceLocs) { + Decl *FromTU = getTuDecl( + R"( + #define MFOO(arg) arg = arg + 1 + + void foo() { + int a = 5; + MFOO(a); + } + )", + Lang_CXX); + auto FromD = FirstDeclMatcher<FunctionDecl>().match(FromTU, functionDecl()); + auto ToD = Import(FromD, Lang_CXX); + + auto ToLHS = LastDeclMatcher<DeclRefExpr>().match(ToD, declRefExpr()); + auto FromLHS = LastDeclMatcher<DeclRefExpr>().match(FromTU, declRefExpr()); + auto ToRHS = LastDeclMatcher<IntegerLiteral>().match(ToD, integerLiteral()); + auto FromRHS = + LastDeclMatcher<IntegerLiteral>().match(FromTU, integerLiteral()); + + SourceManager &ToSM = ToAST->getASTContext().getSourceManager(); + SourceManager &FromSM = FromD->getASTContext().getSourceManager(); + CompareSourceRanges(ToD->getSourceRange(), FromD->getSourceRange(), ToSM, + FromSM); + CompareSourceRanges(ToLHS->getSourceRange(), FromLHS->getSourceRange(), ToSM, + FromSM); + CompareSourceRanges(ToRHS->getSourceRange(), FromRHS->getSourceRange(), ToSM, + FromSM); +} + +TEST_P(ASTImporterTestBase, DISABLED_ImportNestedMacro) { + Decl *FromTU = getTuDecl( + R"( + #define FUNC_INT void declToImport + #define FUNC FUNC_INT + FUNC(int a); + )", + Lang_CXX); + auto FromD = FirstDeclMatcher<FunctionDecl>().match(FromTU, functionDecl()); + auto ToD = Import(FromD, Lang_CXX); + + SourceManager &ToSM = ToAST->getASTContext().getSourceManager(); + SourceManager &FromSM = FromD->getASTContext().getSourceManager(); + CompareSourceRanges(ToD->getSourceRange(), FromD->getSourceRange(), ToSM, + FromSM); +} + TEST_P( ASTImporterTestBase, ImportDefinitionOfClassTemplateSpecIfThereIsAnExistingFwdDeclAndDefinition) |