[clang] 6d0f834 - [clang][AST] TextNodeDumper: dump the operator spelling for overloaded operators.
Bruno Ricci via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 9 07:40:04 PDT 2020
Author: Bruno Ricci
Date: 2020-06-09T15:18:14+01:00
New Revision: 6d0f8345ac195990aea3776722f6de6e2957e6c2
URL: https://github.com/llvm/llvm-project/commit/6d0f8345ac195990aea3776722f6de6e2957e6c2
DIFF: https://github.com/llvm/llvm-project/commit/6d0f8345ac195990aea3776722f6de6e2957e6c2.diff
LOG: [clang][AST] TextNodeDumper: dump the operator spelling for overloaded operators.
This mirrors what is done for built-in operators.
Added:
clang/test/AST/ast-dump-overloaded-operators.cpp
Modified:
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
clang/test/Import/call-expr/test.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h
index 0fb4baf0ca4d..4636c8ef65d3 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -231,6 +231,7 @@ class TextNodeDumper
void VisitCaseStmt(const CaseStmt *Node);
void VisitConstantExpr(const ConstantExpr *Node);
void VisitCallExpr(const CallExpr *Node);
+ void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node);
void VisitCastExpr(const CastExpr *Node);
void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
void VisitDeclRefExpr(const DeclRefExpr *Node);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 72f0ba37e3e7..84f9738ade8d 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -715,6 +715,14 @@ void TextNodeDumper::VisitCallExpr(const CallExpr *Node) {
OS << " adl";
}
+void TextNodeDumper::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node) {
+ const char *OperatorSpelling = clang::getOperatorSpelling(Node->getOperator());
+ if (OperatorSpelling)
+ OS << " '" << OperatorSpelling << "'";
+
+ VisitCallExpr(Node);
+}
+
void TextNodeDumper::VisitCastExpr(const CastExpr *Node) {
OS << " <";
{
diff --git a/clang/test/AST/ast-dump-overloaded-operators.cpp b/clang/test/AST/ast-dump-overloaded-operators.cpp
new file mode 100644
index 000000000000..cd4e14be9f1a
--- /dev/null
+++ b/clang/test/AST/ast-dump-overloaded-operators.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck -strict-whitespace %s
+
+enum E {};
+void operator+(E,E);
+void operator,(E,E);
+
+void test() {
+ E e;
+ e + e;
+ e , e;
+}
+// CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc>
+// CHECK: `-FunctionDecl {{.*}} <line:7:1, line:11:1> line:7:6 test 'void ()'
+// CHECK-NEXT: `-CompoundStmt {{.*}} <col:13, line:11:1>
+// CHECK-NEXT: |-DeclStmt {{.*}} <line:8:3, col:6>
+// CHECK-NEXT: | `-VarDecl {{.*}} <col:3, col:5> col:5 used e 'E'
+// CHECK-NEXT: |-CXXOperatorCallExpr {{.*}} <line:9:3, col:7> 'void' '+'
+// CHECK-NEXT: | |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(E, E)' <FunctionToPointerDecay>
+// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:5> 'void (E, E)' lvalue Function {{.*}} 'operator+' 'void (E, E)'
+// CHECK-NEXT: | |-ImplicitCastExpr {{.*}} <col:3> 'E' <LValueToRValue>
+// CHECK-NEXT: | | `-DeclRefExpr {{.*}} <col:3> 'E' lvalue Var {{.*}} 'e' 'E'
+// CHECK-NEXT: | `-ImplicitCastExpr {{.*}} <col:7> 'E' <LValueToRValue>
+// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:7> 'E' lvalue Var {{.*}} 'e' 'E'
+// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}} <line:10:3, col:7> 'void' ','
+// CHECK-NEXT: |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(E, E)' <FunctionToPointerDecay>
+// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:5> 'void (E, E)' lvalue Function {{.*}} 'operator,' 'void (E, E)'
+// CHECK-NEXT: |-ImplicitCastExpr {{.*}} <col:3> 'E' <LValueToRValue>
+// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:3> 'E' lvalue Var {{.*}} 'e' 'E'
+// CHECK-NEXT: `-ImplicitCastExpr {{.*}} <col:7> 'E' <LValueToRValue>
+// CHECK-NEXT: `-DeclRefExpr {{.*}} <col:7> 'E' lvalue Var {{.*}} 'e' 'E'
diff --git a/clang/test/Import/call-expr/test.cpp b/clang/test/Import/call-expr/test.cpp
index 86c1b50c47d6..e2836a2bb9de 100644
--- a/clang/test/Import/call-expr/test.cpp
+++ b/clang/test/Import/call-expr/test.cpp
@@ -5,4 +5,4 @@ void expr() {
// CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^>]*}}> line:{{.*}}:{{[^ ]*}} used f 'void ()'
// CHECK: -CallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' adl
-// CHECK: -CXXOperatorCallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' adl
+// CHECK: -CXXOperatorCallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' '+' adl
More information about the cfe-commits
mailing list