Index: include/clang/Tooling/ASTDiff/ASTDiff.h =================================================================== --- include/clang/Tooling/ASTDiff/ASTDiff.h +++ include/clang/Tooling/ASTDiff/ASTDiff.h @@ -98,12 +98,6 @@ NodeRef getNode(NodeId Id) const; - /// Serialize the node attributes to a string representation. This should - /// uniquely distinguish nodes of the same kind. Note that this function - /// just - /// returns a representation of the node value, not considering descendants. - std::string getNodeValue(NodeRef Node) const; - class Impl; std::unique_ptr TreeImpl; }; Index: lib/Tooling/ASTDiff/ASTDiff.cpp =================================================================== --- lib/Tooling/ASTDiff/ASTDiff.cpp +++ lib/Tooling/ASTDiff/ASTDiff.cpp @@ -152,14 +152,6 @@ Node &getMutableNode(NodeId Id) { return Nodes[Id]; } Node &getMutableNode(NodeRef N) { return getMutableNode(N.getId()); } - std::string getRelativeName(const NamedDecl *ND, - const DeclContext *Context) const; - std::string getRelativeName(const NamedDecl *ND) const; - - std::string getNodeValue(NodeRef Node) const; - std::string getDeclValue(const Decl *D) const; - std::string getStmtValue(const Stmt *S) const; - private: void initTree(); void setLeftMostDescendants(); @@ -349,123 +341,6 @@ N.getId() <= SubtreeRoot.RightMostDescendant; } -// Returns the qualified name of ND. If it is subordinate to Context, -// then the prefix of the latter is removed from the returned value. -std::string -SyntaxTree::Impl::getRelativeName(const NamedDecl *ND, - const DeclContext *Context) const { - std::string Val = ND->getQualifiedNameAsString(); - std::string ContextPrefix; - if (!Context) - return Val; - if (auto *Namespace = dyn_cast(Context)) - ContextPrefix = Namespace->getQualifiedNameAsString(); - else if (auto *Record = dyn_cast(Context)) - ContextPrefix = Record->getQualifiedNameAsString(); - else if (AST.getLangOpts().CPlusPlus11) - if (auto *Tag = dyn_cast(Context)) - ContextPrefix = Tag->getQualifiedNameAsString(); - // 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)) - Val = Val.substr(ContextPrefix.size() + 1); - return Val; -} - -std::string SyntaxTree::Impl::getRelativeName(const NamedDecl *ND) const { - return getRelativeName(ND, ND->getDeclContext()); -} - -static const DeclContext *getEnclosingDeclContext(ASTUnit &AST, const Stmt *S) { - while (S) { - const auto &Parents = AST.getASTContext().getParents(*S); - if (Parents.empty()) - return nullptr; - const auto &P = Parents[0]; - if (const auto *D = P.get()) - return D->getDeclContext(); - S = P.get(); - } - return nullptr; -} - -static std::string getInitializerValue(const CXXCtorInitializer *Init, - const PrintingPolicy &TypePP) { - if (Init->isAnyMemberInitializer()) - return Init->getAnyMember()->getName(); - if (Init->isBaseInitializer()) - return QualType(Init->getBaseClass(), 0).getAsString(TypePP); - if (Init->isDelegatingInitializer()) - return Init->getTypeSourceInfo()->getType().getAsString(TypePP); - llvm_unreachable("Unknown initializer type"); -} - -std::string SyntaxTree::Impl::getNodeValue(NodeRef N) const { - assert(&N.Tree == this); - const DynTypedNode &DTN = N.ASTNode; - if (N.isMacro()) { - return Lexer::getSourceText(N.getSourceRange(), AST.getSourceManager(), - AST.getLangOpts()); - } - if (auto *S = DTN.get()) - return getStmtValue(S); - if (auto *D = DTN.get()) - return getDeclValue(D); - if (auto *Init = DTN.get()) - return getInitializerValue(Init, TypePP); - llvm_unreachable("Fatal: unhandled AST node.\n"); -} - -std::string SyntaxTree::Impl::getDeclValue(const Decl *D) const { - std::string Value; - if (auto *V = dyn_cast(D)) - return getRelativeName(V) + "(" + V->getType().getAsString(TypePP) + ")"; - if (auto *N = dyn_cast(D)) - Value += getRelativeName(N) + ";"; - if (auto *T = dyn_cast(D)) - return Value + T->getUnderlyingType().getAsString(TypePP) + ";"; - if (auto *T = dyn_cast(D)) - if (T->getTypeForDecl()) - Value += - T->getTypeForDecl()->getCanonicalTypeInternal().getAsString(TypePP) + - ";"; - if (auto *U = dyn_cast(D)) - return U->getNominatedNamespace()->getName(); - if (auto *A = dyn_cast(D)) { - CharSourceRange Range(A->getSourceRange(), false); - return Lexer::getSourceText(Range, AST.getSourceManager(), - AST.getLangOpts()); - } - return Value; -} - -std::string SyntaxTree::Impl::getStmtValue(const Stmt *S) const { - if (auto *U = dyn_cast(S)) - return UnaryOperator::getOpcodeStr(U->getOpcode()); - if (auto *B = dyn_cast(S)) - return B->getOpcodeStr(); - if (auto *M = dyn_cast(S)) - return getRelativeName(M->getMemberDecl()); - if (auto *I = dyn_cast(S)) { - SmallString<256> Str; - I->getValue().toString(Str, /*Radix=*/10, /*Signed=*/false); - return Str.str(); - } - if (auto *F = dyn_cast(S)) { - SmallString<256> Str; - F->getValue().toString(Str); - return Str.str(); - } - if (auto *D = dyn_cast(S)) - return getRelativeName(D->getDecl(), getEnclosingDeclContext(AST, S)); - if (auto *String = dyn_cast(S)) - return String->getString(); - if (auto *B = dyn_cast(S)) - return B->getValue() ? "true" : "false"; - return ""; -} - static HashType hashNode(NodeRef N) { llvm::MD5 Hash; SourceManager &SM = N.getTree().getSourceManager(); @@ -534,9 +409,6 @@ NodeId getPostorderOffset() const { return Tree.PostorderIds[getIdInRoot(SNodeId(1))]; } - std::string getNodeValue(SNodeId Id) const { - return Tree.getNodeValue(getNode(Id)); - } private: /// Returns the number of leafs in the subtree. @@ -1284,9 +1156,5 @@ } SyntaxTree::PreorderIterator SyntaxTree::end() const { return TreeImpl->end(); } -std::string SyntaxTree::getNodeValue(NodeRef N) const { - return TreeImpl->getNodeValue(N); -} - } // end namespace diff } // end namespace clang Index: test/Tooling/clang-diff-ast.cpp =================================================================== --- test/Tooling/clang-diff-ast.cpp +++ test/Tooling/clang-diff-ast.cpp @@ -2,93 +2,94 @@ // CHECK: {{^}}TranslationUnitDecl(0) -// CHECK: {{^}} NamespaceDecl: test;( +// CHECK: {{^}} NamespaceDecl(1) namespace test { -// CHECK: {{^}} FunctionDecl: :f( -// CHECK: CompoundStmt( +// CHECK: {{^}} FunctionDecl(2) +// CHECK: CompoundStmt(3) void f() { - // CHECK: VarDecl: i(int)( - // CHECK: IntegerLiteral: 1 + // CHECK: DeclStmt(4) + // CHECK: VarDecl(5) + // CHECK: IntegerLiteral(6) auto i = 1; - // CHECK: FloatingLiteral: 1.5( + // CHECK: FloatingLiteral(9) auto r = 1.5; - // CHECK: CXXBoolLiteralExpr: true( + // CHECK: CXXBoolLiteralExpr(12) auto b = true; - // CHECK: CallExpr( + // CHECK: CallExpr(13) // CHECK-NOT: ImplicitCastExpr - // CHECK: DeclRefExpr: :f( + // CHECK: DeclRefExpr(14) f(); - // CHECK: UnaryOperator: ++( + // CHECK: UnaryOperator(15) ++i; - // CHECK: BinaryOperator: =( + // CHECK: BinaryOperator(17) i = i; } } // end namespace test -// CHECK: UsingDirectiveDecl: test( +// CHECK: UsingDirectiveDecl(20) using namespace test; -// CHECK: TypedefDecl: nat;unsigned int;( +// CHECK: TypedefDecl(21) typedef unsigned nat; -// CHECK: TypeAliasDecl: real;double;( +// CHECK: TypeAliasDecl(22) using real = double; class Base { }; -// CHECK: CXXRecordDecl: X;X;( +// CHECK: CXXRecordDecl(23) class X : Base { int m; - // CHECK: CXXMethodDecl: :foo(const char *(int) - // CHECK: ParmVarDecl: i(int)( + // CHECK: CXXMethodDecl(26) + // CHECK: ParmVarDecl(27) const char *foo(int i) { if (i == 0) - // CHECK: StringLiteral: foo( + // CHECK: StringLiteral(34) return "foo"; // CHECK-NOT: ImplicitCastExpr return 0; } - // CHECK: AccessSpecDecl: public( + // CHECK: AccessSpecDecl(37) public: int not_initialized; - // CHECK: CXXConstructorDecl: :X(void (char, int){{( __attribute__\(\(thiscall\)\))?}})( - // CHECK-NEXT: ParmVarDecl: s(char) - // CHECK-NEXT: ParmVarDecl: (int) - // CHECK-NEXT: CXXCtorInitializer: Base - // CHECK-NEXT: CXXConstructExpr - // CHECK-NEXT: CXXCtorInitializer: m - // CHECK-NEXT: IntegerLiteral: 0 + // CHECK: CXXConstructorDecl(39) + // CHECK-NEXT: ParmVarDecl(40) + // CHECK-NEXT: ParmVarDecl(41) + // CHECK-NEXT: CXXCtorInitializer(42) + // CHECK-NEXT: CXXConstructExpr(43) + // CHECK-NEXT: CXXCtorInitializer(44) + // CHECK-NEXT: IntegerLiteral(45) X(char s, int) : Base(), m(0) { - // CHECK-NEXT: CompoundStmt - // CHECK: MemberExpr: :m( + // CHECK-NEXT: CompoundStmt(46) + // CHECK: MemberExpr(49) int x = m; } - // CHECK: CXXConstructorDecl: :X(void (char){{( __attribute__\(\(thiscall\)\))?}})( - // CHECK: CXXCtorInitializer: X + // CHECK: CXXConstructorDecl(51) + // CHECK: CXXCtorInitializer(53) X(char s) : X(s, 4) {} }; #define M (void)1 #define F(a, b) (void)a, b void macros() { - // CHECK: Macro: M( + // CHECK: Macro(60) M; // two expressions, therefore it occurs twice - // CHECK-NEXT: Macro: F(1, 2)( - // CHECK-NEXT: Macro: F(1, 2)( + // CHECK-NEXT: Macro(61) + // CHECK-NEXT: Macro(62) F(1, 2); } #ifndef GUARD #define GUARD -// CHECK-NEXT: NamespaceDecl +// CHECK-NEXT: NamespaceDecl(63) namespace world { // nodes from other files are excluded, there should be no output here #include "clang-diff-ast.cpp" } -// CHECK-NEXT: FunctionDecl: sentinel +// CHECK-NEXT: FunctionDecl(64) void sentinel(); #endif Index: test/Tooling/clang-diff-basic.cpp =================================================================== --- test/Tooling/clang-diff-basic.cpp +++ test/Tooling/clang-diff-basic.cpp @@ -1,31 +1,31 @@ // RUN: clang-diff -dump-matches %S/Inputs/clang-diff-basic-src.cpp %s -- | FileCheck %s -// CHECK: Match TranslationUnitDecl{{.*}} to TranslationUnitDecl -// CHECK: Match NamespaceDecl: src{{.*}} to NamespaceDecl: dst +// CHECK: Match TranslationUnitDecl(0) to TranslationUnitDecl(0) +// CHECK: Match NamespaceDecl(1) to NamespaceDecl(1) namespace dst { -// CHECK-NOT: Match NamespaceDecl: src{{.*}} to NamespaceDecl: inner +// CHECK-NOT: Match NamespaceDecl(1) to NamespaceDecl(2) namespace inner { void foo() { - // CHECK: Match IntegerLiteral: 321{{.*}} to IntegerLiteral: 322 + // CHECK: Match IntegerLiteral(6) to IntegerLiteral(7) int x = 322; } } -// CHECK: Match DeclRefExpr: :foo{{.*}} to DeclRefExpr: :inner::foo +// CHECK: Match DeclRefExpr(10) to DeclRefExpr(11) void main() { inner::foo(); } -// CHECK: Match StringLiteral: foo{{.*}} to StringLiteral: foo +// CHECK: Match StringLiteral(13) to StringLiteral(13) const char *b = "f" "o" "o"; // unsigned is canonicalized to unsigned int -// CHECK: Match TypedefDecl: :nat;unsigned int;{{.*}} to TypedefDecl: :nat;unsigned int; +// CHECK: Match TypedefDecl(14) to TypedefDecl(14) typedef unsigned nat; -// CHECK: Match VarDecl: :p(int){{.*}} to VarDecl: :prod(double) -// CHECK: Update VarDecl: :p(int){{.*}} to :prod(double) -// CHECK: Match BinaryOperator: *{{.*}} to BinaryOperator: * +// CHECK: Match VarDecl(15) +// CHECK: Update VarDecl(15) +// CHECK: Match BinaryOperator(17) double prod = 1 * 2 * 10; -// CHECK: Update DeclRefExpr +// CHECK: Update DeclRefExpr(25) int squared = prod * prod; class X { @@ -42,14 +42,14 @@ }; } -// CHECK: Move CompoundStmt{{.*}} into CompoundStmt +// CHECK: Move CompoundStmt(48) into CompoundStmt(47) void m() { { int x = 0 + 0 + 0; } } -// CHECK: Update and Move IntegerLiteral: 7{{.*}} into BinaryOperator: +({{.*}}) at 1 +// CHECK: Update and Move IntegerLiteral(59) into BinaryOperator(57) at 1 int um = 1 + 7; namespace { // match with parents of different type -// CHECK: Match FunctionDecl: f1{{.*}} to FunctionDecl: (anonymous namespace)::f1 +// CHECK: Match FunctionDecl(70) to FunctionDecl(69) void f1() {{ (void) __func__;;; }} } @@ -60,13 +60,13 @@ #define F(a, b) return a + b; int f2() { - // CHECK: Match Macro: M1{{.*}} to Macro: M1 + // CHECK: Match Macro(72) to Macro(71) M1; - // CHECK: Update Macro: M1{{.*}} to M2 + // CHECK: Update Macro(73) M2; - // CHECK: Match Macro: F(1, 1)(74) + // CHECK: Match Macro(74) F(1, /*b=*/1); } -// CHECK: Delete AccessSpecDecl: public -// CHECK: Delete CXXMethodDecl +// CHECK: Delete AccessSpecDecl(39) +// CHECK: Delete CXXMethodDecl(42) Index: test/Tooling/clang-diff-bottomup.cpp =================================================================== --- test/Tooling/clang-diff-bottomup.cpp +++ test/Tooling/clang-diff-bottomup.cpp @@ -16,7 +16,7 @@ void f1() { // CompoundStmt: 3 matched descendants, subtree sizes 4 and 5 // Jaccard similarity = 3 / (4 + 5 - 3) = 3 / 6 >= 0.5 -// CHECK: Match FunctionDecl: f1(void ())(1) to FunctionDecl: f1(void ())(1) +// CHECK: Match FunctionDecl(1) to FunctionDecl(1) // CHECK: Match CompoundStmt(2) to CompoundStmt(2) // CHECK: Match CompoundStmt(4) to CompoundStmt(3) // CHECK: Match CompoundStmt(5) to CompoundStmt(4) Index: test/Tooling/clang-diff-heuristics.cpp =================================================================== --- test/Tooling/clang-diff-heuristics.cpp +++ test/Tooling/clang-diff-heuristics.cpp @@ -13,12 +13,12 @@ #else // same parents, same value -// CHECK: Match FunctionDecl: f1(void ())(1) to FunctionDecl: f1(void ())(1) +// CHECK: Match FunctionDecl(1) to FunctionDecl(1) // CHECK: Match CompoundStmt void f1() {} // same parents, same identifier -// CHECK: Match FunctionDecl: f2(void (int))(4) to FunctionDecl: f2(void ())(3) +// CHECK: Match FunctionDecl(4) to FunctionDecl(3) // CHECK: Match CompoundStmt void f2() {} Index: test/Tooling/clang-diff-html.test =================================================================== --- test/Tooling/clang-diff-html.test +++ test/Tooling/clang-diff-html.test @@ -5,31 +5,26 @@ match, update CHECK: namespace src { +CHECK-NEXT: [[L]] -> [[R]]' class='u'>namespace src { match, move CHECK: void foo() +CHECK-NEXT: [[L]] -> [[R]]' class='m'>void foo() match CHECK: void main() +CHECK-NEXT: [[L]] -> [[R]]'>void main() deletion CHECK: 4 +CHECK-NEXT: [[L]] -> -1' class='d'>4 update + move -CHECK: 2' class='u m'>2 +CHECK: class='u m'>2 insertion CHECK: "Bar" +CHECK-NEXT: -1 -> [[R]]' class='i'>"Bar" comments -CHECK: // CHECK: Delete AccessSpecDecl: public +CHECK: // CHECK: Delete AccessSpecDecl Index: test/Tooling/clang-diff-json.cpp =================================================================== --- test/Tooling/clang-diff-json.cpp +++ test/Tooling/clang-diff-json.cpp @@ -19,9 +19,5 @@ // CHECK-NEXT: "type": "CharacterLiteral" // CHECK-NEXT: } // CHECK: ] -// CHECK: "type": "VarDecl", +// CHECK: "type": "VarDecl" char nl = '\n'; - -// CHECK: "value": "abc \n\t\u0000\u001f" -char s[] = "abc \n\t\0\x1f"; - Index: test/Tooling/clang-diff-topdown.cpp =================================================================== --- test/Tooling/clang-diff-topdown.cpp +++ test/Tooling/clang-diff-topdown.cpp @@ -58,9 +58,9 @@ namespace dst { int x; - // CHECK: Match DeclRefExpr: :x(17) to DeclRefExpr: :x(22) + // CHECK: Match DeclRefExpr(17) to DeclRefExpr(22) int x1 = x + 1; - // CHECK: Match DeclRefExpr: x(21) to DeclRefExpr: x(26) + // CHECK: Match DeclRefExpr(21) to DeclRefExpr(26) int x2 = ::x + 1; } Index: tools/clang-diff/ClangDiff.cpp =================================================================== --- tools/clang-diff/ClangDiff.cpp +++ tools/clang-diff/ClangDiff.cpp @@ -299,13 +299,7 @@ << "tid='" << OtherTag << TargetId << "' "; OS << "title='"; printHtml(OS, Node.getTypeLabel()); - OS << "\n" << LeftId << " -> " << RightId; - std::string Value = Tree.getNodeValue(Node); - if (!Value.empty()) { - OS << "\n"; - printHtml(OS, Value); - } - OS << "'"; + OS << "\n" << LeftId << " -> " << RightId << "'"; if (Node.Change != diff::NoChange) OS << " class='" << getChangeKindAbbr(Node.Change) << "'"; OS << ">"; @@ -356,12 +350,6 @@ auto Offsets = Node.getSourceRangeOffsets(); OS << R"(,"begin":)" << Offsets.first; OS << R"(,"end":)" << Offsets.second; - std::string Value = Tree.getNodeValue(Node); - if (!Value.empty()) { - OS << R"(,"value":")"; - printJsonString(OS, Value); - OS << '"'; - } } static void printNodeAsJson(raw_ostream &OS, diff::SyntaxTree &Tree, @@ -395,9 +383,6 @@ static void printNode(raw_ostream &OS, diff::SyntaxTree &Tree, diff::NodeRef Node) { OS << Node.getTypeLabel(); - std::string Value = Tree.getNodeValue(Node); - if (!Value.empty()) - OS << ": " << Value; OS << "(" << Node.getId() << ")"; } @@ -422,7 +407,7 @@ case diff::Update: OS << "Update "; printNode(OS, SrcTree, *Src); - OS << " to " << DstTree.getNodeValue(Dst) << "\n"; + OS << "\n"; break; case diff::Insert: case diff::Move: