[clang][AST] TextNodeDumper: dump the operator spelling for overloaded operators.

This mirrors what is done for built-in operators.
This commit is contained in:
Bruno Ricci 2020-06-09 15:03:22 +01:00
parent 21d747184a
commit 6d0f8345ac
No known key found for this signature in database
GPG Key ID: D58C906B2F684D92
4 changed files with 40 additions and 1 deletions

View File

@ -231,6 +231,7 @@ public:
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);

View File

@ -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 << " <";
{

View File

@ -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'

View File

@ -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