[PATCH] D37004: [clang-diff] Fix the html output for CXXOperatorCallExpr
Johannes Altmanninger via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 22 02:17:10 PDT 2017
johannes created this revision.
Herald added subscribers: mgorny, klimek.
The operator is always the first child of such an expression.
If it is an infix operator, we want to print the LHS first.
https://reviews.llvm.org/D37004
Files:
test/Tooling/clang-diff-ast.cpp
tools/clang-diff/CMakeLists.txt
tools/clang-diff/ClangDiff.cpp
Index: tools/clang-diff/ClangDiff.cpp
===================================================================
--- tools/clang-diff/ClangDiff.cpp
+++ tools/clang-diff/ClangDiff.cpp
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/AST/ExprCXX.h"
#include "clang/Tooling/ASTDiff/ASTDiff.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
@@ -310,8 +311,17 @@
OS << " class='" << getChangeKindAbbr(Node.Change) << "'";
OS << ">";
- for (diff::NodeId Child : Node.Children)
- Offset = printHtmlForNode(OS, Diff, Tree, IsLeft, Child, Offset);
+ const auto &Children = Node.Children;
+ auto *OpCall = Node.ASTNode.get<CXXOperatorCallExpr>();
+ if (OpCall && OpCall->isInfixBinaryOp()) {
+ assert(Children.size() == 3 &&
+ "A Binary operator is supposed to have two arguments.");
+ for (int I : {1, 0, 2})
+ Offset = printHtmlForNode(OS, Diff, Tree, IsLeft, Children[I], Offset);
+ } else {
+ for (diff::NodeId Child : Children)
+ Offset = printHtmlForNode(OS, Diff, Tree, IsLeft, Child, Offset);
+ }
for (; Offset < End; ++Offset)
printHtml(OS, Code[Offset]);
Index: tools/clang-diff/CMakeLists.txt
===================================================================
--- tools/clang-diff/CMakeLists.txt
+++ tools/clang-diff/CMakeLists.txt
@@ -7,6 +7,7 @@
)
target_link_libraries(clang-diff
+ clangAST
clangBasic
clangFrontend
clangTooling
Index: test/Tooling/clang-diff-ast.cpp
===================================================================
--- test/Tooling/clang-diff-ast.cpp
+++ test/Tooling/clang-diff-ast.cpp
@@ -39,7 +39,7 @@
};
// CHECK: CXXRecordDecl: X;X;(
-class X : Base {
+struct X : Base {
int m;
// CHECK: CXXMethodDecl: :foo(const char *(int)
// CHECK: ParmVarDecl: i(int)(
@@ -105,3 +105,23 @@
// CHECK-NEXT: TemplateName
// CHECK-NEXT: TemplateArgument
class I : C<int> {};
+
+struct str {
+ str& operator+(const str&);
+} s1, s2, s3;
+
+// CHECK: CXXOperatorCallExpr
+// CHECK-NEXT: DeclRefExpr: str::operator+
+// CHECK-NEXT: CXXOperatorCallExpr
+// CHECK-NEXT: DeclRefExpr: str::operator+
+// CHECK-NEXT: DeclRefExpr: s1
+// CHECK-NEXT: DeclRefExpr: s2
+// CHECK-NEXT: DeclRefExpr: s3
+str x = s1 + s2 + s3;
+
+// CHECK: BinaryOperator: +
+// CHECK-NEXT: BinaryOperator: +
+// CHECK-NEXT: IntegerLiteral: 1
+// CHECK-NEXT: IntegerLiteral: 2
+// CHECK-NEXT: IntegerLiteral: 3
+int op = 1 + 2 + 3;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37004.112136.patch
Type: text/x-patch
Size: 2511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170822/4cd749f2/attachment.bin>
More information about the cfe-commits
mailing list