forked from OSchip/llvm-project
[clang-move] Don't dump macro symbols.
Reviewers: ioeric Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D43075 llvm-svn: 324742
This commit is contained in:
parent
38d8013458
commit
d478634777
|
@ -523,6 +523,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
|
|||
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::onEndOfTranslationUnit() {
|
|||
|
||||
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:
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue