Skip to content

Commit d478634

Browse files
committedFeb 9, 2018
[clang-move] Don't dump macro symbols.
Reviewers: ioeric Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43075 llvm-svn: 324742
1 parent 38d8013 commit d478634

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed
 

‎clang-tools-extra/clang-move/ClangMove.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
523523
auto AllDeclsInHeader = namedDecl(
524524
unless(ForwardClassDecls), unless(namespaceDecl()),
525525
unless(usingDirectiveDecl()), // using namespace decl.
526+
notInMacro(),
526527
InOldHeader,
527528
hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))),
528529
hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl()))));
@@ -905,10 +906,9 @@ void ClangMoveTool::onEndOfTranslationUnit() {
905906

906907
if (RemovedDecls.empty())
907908
return;
908-
// Ignore symbols that are not supported (e.g. typedef and enum) when
909-
// checking if there is unremoved symbol in old header. This makes sure that
910-
// we always move old files to new files when all symbols produced from
911-
// dump_decls are moved.
909+
// Ignore symbols that are not supported when checking if there is unremoved
910+
// symbol in old header. This makes sure that we always move old files to new
911+
// files when all symbols produced from dump_decls are moved.
912912
auto IsSupportedKind = [](const clang::NamedDecl *Decl) {
913913
switch (Decl->getKind()) {
914914
case Decl::Kind::Function:

‎clang-tools-extra/unittests/clang-move/ClangMoveTests.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,26 @@ TEST(ClangMove, DontMoveAll) {
391391
}
392392
}
393393

394+
TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) {
395+
const char TestCode[] = "#include \"foo.h\"";
396+
std::vector<std::string> TestHeaders = {
397+
"#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n",
398+
"#define DEFINE(x) int var_##x = 1;\nDEFINE(foo);\nclass Bar {};\n",
399+
};
400+
move::MoveDefinitionSpec Spec;
401+
Spec.Names.push_back("Bar");
402+
Spec.OldHeader = "foo.h";
403+
Spec.OldCC = "foo.cc";
404+
Spec.NewHeader = "new_foo.h";
405+
Spec.NewCC = "new_foo.cc";
406+
407+
for (const auto& Header : TestHeaders) {
408+
auto Results = runClangMoveOnCode(Spec, Header.c_str(), TestCode);
409+
EXPECT_EQ("", Results[Spec.OldHeader]);
410+
EXPECT_EQ(Header, Results[Spec.NewHeader]);
411+
}
412+
}
413+
394414
TEST(ClangMove, MacroInFunction) {
395415
const char TestHeader[] = "#define INT int\n"
396416
"class A {\npublic:\n int f();\n};\n"
@@ -570,7 +590,9 @@ TEST(ClangMove, DumpDecls) {
570590
"extern int kGlobalInt;\n"
571591
"extern const char* const kGlobalStr;\n"
572592
"} // namespace b\n"
573-
"} // namespace a\n";
593+
"} // namespace a\n"
594+
"#define DEFINE_FOO class Foo {};\n"
595+
"DEFINE_FOO\n";
574596
const char TestCode[] = "#include \"foo.h\"\n";
575597
move::MoveDefinitionSpec Spec;
576598
Spec.Names.push_back("B");

0 commit comments

Comments
 (0)
Please sign in to comment.