johannes created this revision.
Herald added a subscriber: klimek.
This makes Node::getIdentifier return a valid value for special
NamedDecl nodes that do not have a name, such as ctors, dtors
and unnamed classes / namespaces.
https://reviews.llvm.org/D36688
Files:
lib/Tooling/ASTDiff/ASTDiff.cpp
test/Tooling/clang-diff-heuristics.cpp
Index: test/Tooling/clang-diff-heuristics.cpp
===
--- test/Tooling/clang-diff-heuristics.cpp
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -10,6 +10,8 @@
void f2(int) {;}
+class C3 { C3(); };
+
#else
// same parents, same value
@@ -22,4 +24,8 @@
// CHECK: Match CompoundStmt
void f2() {}
+// same parents, same identifier
+// CHECK: Match CXXConstructorDecl: :C3(void ())(9) to CXXConstructorDecl:
:C3(void (int))(6)
+class C3 { C3(int); };
+
#endif
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -384,8 +384,7 @@
// Strip the qualifier, if Val refers to somthing in the current scope.
// But leave one leading ':' in place, so that we know that this is a
// relative path.
- if (!ContextPrefix.empty() &&
- StringRef(Val).startswith(ContextPrefix))
+ if (!ContextPrefix.empty() && StringRef(Val).startswith(ContextPrefix))
Val = Val.substr(ContextPrefix.size() + 1);
return Val;
}
@@ -715,14 +714,18 @@
if (auto *ND = ASTNode.get()) {
if (ND->getDeclName().isIdentifier())
return ND->getQualifiedNameAsString();
+else
+ return std::string();
}
return llvm::None;
}
llvm::Optional Node::getIdentifier() const {
if (auto *ND = ASTNode.get()) {
if (ND->getDeclName().isIdentifier())
return ND->getName();
+else
+ return StringRef();
}
return llvm::None;
}
Index: test/Tooling/clang-diff-heuristics.cpp
===
--- test/Tooling/clang-diff-heuristics.cpp
+++ test/Tooling/clang-diff-heuristics.cpp
@@ -10,6 +10,8 @@
void f2(int) {;}
+class C3 { C3(); };
+
#else
// same parents, same value
@@ -22,4 +24,8 @@
// CHECK: Match CompoundStmt
void f2() {}
+// same parents, same identifier
+// CHECK: Match CXXConstructorDecl: :C3(void ())(9) to CXXConstructorDecl: :C3(void (int))(6)
+class C3 { C3(int); };
+
#endif
Index: lib/Tooling/ASTDiff/ASTDiff.cpp
===
--- lib/Tooling/ASTDiff/ASTDiff.cpp
+++ lib/Tooling/ASTDiff/ASTDiff.cpp
@@ -384,8 +384,7 @@
// Strip the qualifier, if Val refers to somthing in the current scope.
// But leave one leading ':' in place, so that we know that this is a
// relative path.
- if (!ContextPrefix.empty() &&
- StringRef(Val).startswith(ContextPrefix))
+ if (!ContextPrefix.empty() && StringRef(Val).startswith(ContextPrefix))
Val = Val.substr(ContextPrefix.size() + 1);
return Val;
}
@@ -715,14 +714,18 @@
if (auto *ND = ASTNode.get()) {
if (ND->getDeclName().isIdentifier())
return ND->getQualifiedNameAsString();
+else
+ return std::string();
}
return llvm::None;
}
llvm::Optional Node::getIdentifier() const {
if (auto *ND = ASTNode.get()) {
if (ND->getDeclName().isIdentifier())
return ND->getName();
+else
+ return StringRef();
}
return llvm::None;
}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits