[clang-tools-extra] r324742 - [clang-move] Don't dump macro symbols.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 9 07:57:30 PST 2018
Author: hokein
Date: Fri Feb 9 07:57:30 2018
New Revision: 324742
URL: http://llvm.org/viewvc/llvm-project?rev=324742&view=rev
Log:
[clang-move] Don't dump macro symbols.
Reviewers: ioeric
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43075
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=324742&r1=324741&r2=324742&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Fri Feb 9 07:57:30 2018
@@ -523,6 +523,7 @@ void ClangMoveTool::registerMatchers(ast
auto AllDeclsInHeader = namedDecl(
unless(ForwardClassDecls), unless(namespaceDecl()),
unless(usingDirectiveDecl()), // using namespace decl.
+ notInMacro(),
InOldHeader,
hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl()))),
hasDeclContext(decl(anyOf(namespaceDecl(), translationUnitDecl()))));
@@ -905,10 +906,9 @@ void ClangMoveTool::onEndOfTranslationUn
if (RemovedDecls.empty())
return;
- // Ignore symbols that are not supported (e.g. typedef and enum) when
- // checking if there is unremoved symbol in old header. This makes sure that
- // we always move old files to new files when all symbols produced from
- // dump_decls are moved.
+ // Ignore symbols that are not supported when checking if there is unremoved
+ // symbol in old header. This makes sure that we always move old files to new
+ // files when all symbols produced from dump_decls are moved.
auto IsSupportedKind = [](const clang::NamedDecl *Decl) {
switch (Decl->getKind()) {
case Decl::Kind::Function:
Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=324742&r1=324741&r2=324742&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Fri Feb 9 07:57:30 2018
@@ -391,6 +391,26 @@ TEST(ClangMove, DontMoveAll) {
}
}
+TEST(ClangMove, IgnoreMacroSymbolsAndMoveAll) {
+ const char TestCode[] = "#include \"foo.h\"";
+ std::vector<std::string> TestHeaders = {
+ "#define DEFINE_Foo int Foo = 1;\nDEFINE_Foo;\nclass Bar {};\n",
+ "#define DEFINE(x) int var_##x = 1;\nDEFINE(foo);\nclass Bar {};\n",
+ };
+ move::MoveDefinitionSpec Spec;
+ Spec.Names.push_back("Bar");
+ Spec.OldHeader = "foo.h";
+ Spec.OldCC = "foo.cc";
+ Spec.NewHeader = "new_foo.h";
+ Spec.NewCC = "new_foo.cc";
+
+ for (const auto& Header : TestHeaders) {
+ auto Results = runClangMoveOnCode(Spec, Header.c_str(), TestCode);
+ EXPECT_EQ("", Results[Spec.OldHeader]);
+ EXPECT_EQ(Header, Results[Spec.NewHeader]);
+ }
+}
+
TEST(ClangMove, MacroInFunction) {
const char TestHeader[] = "#define INT int\n"
"class A {\npublic:\n int f();\n};\n"
@@ -570,7 +590,9 @@ TEST(ClangMove, DumpDecls) {
"extern int kGlobalInt;\n"
"extern const char* const kGlobalStr;\n"
"} // namespace b\n"
- "} // namespace a\n";
+ "} // namespace a\n"
+ "#define DEFINE_FOO class Foo {};\n"
+ "DEFINE_FOO\n";
const char TestCode[] = "#include \"foo.h\"\n";
move::MoveDefinitionSpec Spec;
Spec.Names.push_back("B");
More information about the cfe-commits
mailing list