[clang] a9250c2 - [clang] TextNodeDumper: Dump the trait spelling of {Type,ArrayType,Expression}TraitExpr
Bruno Ricci via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 11 12:28:13 PDT 2020
Author: Bruno Ricci
Date: 2020-06-11T20:27:40+01:00
New Revision: a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d
URL: https://github.com/llvm/llvm-project/commit/a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d
DIFF: https://github.com/llvm/llvm-project/commit/a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d.diff
LOG: [clang] TextNodeDumper: Dump the trait spelling of {Type,ArrayType,Expression}TraitExpr
nodes using the new helper functions introduced
in 78e636b3f2f0b0487130b31fade4f95ab179a18c.
Added:
clang/test/AST/ast-dump-traits.cpp
Modified:
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h
index 4636c8ef65d3..b069bd09287a 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -259,6 +259,9 @@ class TextNodeDumper
void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
void VisitCXXNewExpr(const CXXNewExpr *Node);
void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
+ void VisitTypeTraitExpr(const TypeTraitExpr *Node);
+ void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node);
+ void VisitExpressionTraitExpr(const ExpressionTraitExpr *Node);
void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
void VisitExprWithCleanups(const ExprWithCleanups *Node);
void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 609a9d7ac2df..7007aa833f3f 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -949,6 +949,18 @@ void TextNodeDumper::VisitCXXDeleteExpr(const CXXDeleteExpr *Node) {
}
}
+void TextNodeDumper::VisitTypeTraitExpr(const TypeTraitExpr *Node) {
+ OS << " " << getTraitSpelling(Node->getTrait());
+}
+
+void TextNodeDumper::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node) {
+ OS << " " << getTraitSpelling(Node->getTrait());
+}
+
+void TextNodeDumper::VisitExpressionTraitExpr(const ExpressionTraitExpr *Node) {
+ OS << " " << getTraitSpelling(Node->getTrait());
+}
+
void TextNodeDumper::VisitMaterializeTemporaryExpr(
const MaterializeTemporaryExpr *Node) {
if (const ValueDecl *VD = Node->getExtendingDecl()) {
diff --git a/clang/test/AST/ast-dump-traits.cpp b/clang/test/AST/ast-dump-traits.cpp
new file mode 100644
index 000000000000..92931e2ac67a
--- /dev/null
+++ b/clang/test/AST/ast-dump-traits.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck -strict-whitespace %s
+
+void test_type_trait() {
+ // An unary type trait.
+ enum E {};
+ (void) __is_enum(E);
+ // A binary type trait.
+ (void) __is_same(int ,float);
+ // An n-ary type trait.
+ (void) __is_constructible(int, int, int, int);
+}
+
+void test_array_type_trait() {
+ // An array type trait.
+ (void) __array_rank(int[10][20]);
+}
+
+void test_expression_trait() {
+ // An expression trait.
+ (void) __is_lvalue_expr(1);
+}
+
+void test_unary_expr_or_type_trait() {
+ // Some UETTs.
+ (void) sizeof(int);
+ (void) alignof(int);
+ (void) __alignof(int);
+}
+// CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc>
+// CHECK: |-FunctionDecl {{.*}} <{{.*}}ast-dump-traits.cpp:3:1, line:11:1> line:3:6 test_type_trait 'void ()'
+// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:24, line:11:1>
+// CHECK-NEXT: | |-DeclStmt {{.*}} <line:5:3, col:12>
+// CHECK-NEXT: | | `-EnumDecl {{.*}} <col:3, col:11> col:8 referenced E
+// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:6:3, col:21> 'void' <ToVoid>
+// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:21> 'bool' __is_enum
+// CHECK-NEXT: | |-CStyleCastExpr {{.*}} <line:8:3, col:30> 'void' <ToVoid>
+// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} <col:10, col:30> 'bool' __is_same
+// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:10:3, col:47> 'void' <ToVoid>
+// CHECK-NEXT: | `-TypeTraitExpr {{.*}} <col:10, col:47> 'bool' __is_constructible
+// CHECK-NEXT: |-FunctionDecl {{.*}} <line:13:1, line:16:1> line:13:6 test_array_type_trait 'void ()'
+// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:16:1>
+// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:15:3, col:34> 'void' <ToVoid>
+// CHECK-NEXT: | `-ArrayTypeTraitExpr {{.*}} <col:10, col:34> 'unsigned long' __array_rank
+// CHECK-NEXT: |-FunctionDecl {{.*}} <line:18:1, line:21:1> line:18:6 test_expression_trait 'void ()'
+// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:21:1>
+// CHECK-NEXT: | `-CStyleCastExpr {{.*}} <line:20:3, col:28> 'void' <ToVoid>
+// CHECK-NEXT: | `-ExpressionTraitExpr {{.*}} <col:10, col:28> 'bool' __is_lvalue_expr
+// CHECK-NEXT: `-FunctionDecl {{.*}} <line:23:1, line:28:1> line:23:6 test_unary_expr_or_type_trait 'void ()'
+// CHECK-NEXT: `-CompoundStmt {{.*}} <col:38, line:28:1>
+// CHECK-NEXT: |-CStyleCastExpr {{.*}} <line:25:3, col:20> 'void' <ToVoid>
+// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}} <col:10, col:20> 'unsigned long' sizeof 'int'
+// CHECK-NEXT: |-CStyleCastExpr {{.*}} <line:26:3, col:21> 'void' <ToVoid>
+// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}} <col:10, col:21> 'unsigned long' alignof 'int'
+// CHECK-NEXT: `-CStyleCastExpr {{.*}} <line:27:3, col:23> 'void' <ToVoid>
+// CHECK-NEXT: `-UnaryExprOrTypeTraitExpr {{.*}} <col:10, col:23> 'unsigned long' __alignof 'int'
More information about the cfe-commits
mailing list