From: Bruno Ricci Date: Thu, 11 Jun 2020 16:36:28 +0000 (+0100) Subject: [clang] TextNodeDumper: Dump the trait spelling of {Type,ArrayType,Expression}TraitExpr X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d;p=platform%2Fupstream%2Fllvm.git [clang] TextNodeDumper: Dump the trait spelling of {Type,ArrayType,Expression}TraitExpr nodes using the new helper functions introduced in 78e636b3f2f0b0487130b31fade4f95ab179a18c. --- diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h index 4636c8e..b069bd0 100644 --- a/clang/include/clang/AST/TextNodeDumper.h +++ b/clang/include/clang/AST/TextNodeDumper.h @@ -259,6 +259,9 @@ public: 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 609a9d7..7007aa8 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 0000000..92931e2 --- /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 {{.*}} <> +// CHECK: |-FunctionDecl {{.*}} <{{.*}}ast-dump-traits.cpp:3:1, line:11:1> line:3:6 test_type_trait 'void ()' +// CHECK-NEXT: | `-CompoundStmt {{.*}} +// CHECK-NEXT: | |-DeclStmt {{.*}} +// CHECK-NEXT: | | `-EnumDecl {{.*}} col:8 referenced E +// CHECK-NEXT: | |-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} 'bool' __is_enum +// CHECK-NEXT: | |-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | | `-TypeTraitExpr {{.*}} 'bool' __is_same +// CHECK-NEXT: | `-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | `-TypeTraitExpr {{.*}} 'bool' __is_constructible +// CHECK-NEXT: |-FunctionDecl {{.*}} line:13:6 test_array_type_trait 'void ()' +// CHECK-NEXT: | `-CompoundStmt {{.*}} +// CHECK-NEXT: | `-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | `-ArrayTypeTraitExpr {{.*}} 'unsigned long' __array_rank +// CHECK-NEXT: |-FunctionDecl {{.*}} line:18:6 test_expression_trait 'void ()' +// CHECK-NEXT: | `-CompoundStmt {{.*}} +// CHECK-NEXT: | `-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | `-ExpressionTraitExpr {{.*}} 'bool' __is_lvalue_expr +// CHECK-NEXT: `-FunctionDecl {{.*}} line:23:6 test_unary_expr_or_type_trait 'void ()' +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: |-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' sizeof 'int' +// CHECK-NEXT: |-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' alignof 'int' +// CHECK-NEXT: `-CStyleCastExpr {{.*}} 'void' +// CHECK-NEXT: `-UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' __alignof 'int'