Clang Project

clang_source_code/test/Tooling/clang-diff-ast.cpp
1// RUN: clang-diff -ast-dump %s -- -std=c++11 | FileCheck %s
2
3
4// CHECK: {{^}}TranslationUnitDecl(0)
5// CHECK: {{^}} NamespaceDecl: test;(
6namespace test {
7
8// CHECK: {{^}} FunctionDecl: :f(
9// CHECK: CompoundStmt(
10void f() {
11  // CHECK: VarDecl: i(int)(
12  // CHECK: IntegerLiteral: 1
13  auto i = 1;
14  // CHECK: FloatingLiteral: 1.5(
15  auto r = 1.5;
16  // CHECK: CXXBoolLiteralExpr: true(
17  auto b = true;
18  // CHECK: CallExpr(
19  // CHECK-NOT: ImplicitCastExpr
20  // CHECK: DeclRefExpr: :f(
21  f();
22  // CHECK: UnaryOperator: ++(
23  ++i;
24  // CHECK: BinaryOperator: =(
25  i = i;
26}
27
28} // end namespace test
29
30// CHECK: UsingDirectiveDecl: test(
31using namespace test;
32
33// CHECK: TypedefDecl: nat;unsigned int;(
34typedef unsigned nat;
35// CHECK: TypeAliasDecl: real;double;(
36using real = double;
37
38class Base {
39};
40
41// CHECK: CXXRecordDecl: X;X;(
42class X : Base {
43  int m;
44  // CHECK: CXXMethodDecl: :foo(const char *(int)
45  // CHECK: ParmVarDecl: i(int)(
46  const char *foo(int i) {
47    if (i == 0)
48      // CHECK: StringLiteral: foo(
49      return "foo";
50    // CHECK-NOT: ImplicitCastExpr
51    return 0;
52  }
53
54  // CHECK: AccessSpecDecl: public(
55public:
56  int not_initialized;
57  // CHECK: CXXConstructorDecl: :X(void (char, int){{( __attribute__\(\(thiscall\)\))?}})(
58  // CHECK-NEXT: ParmVarDecl: s(char)
59  // CHECK-NEXT: ParmVarDecl: (int)
60  // CHECK-NEXT: CXXCtorInitializer: Base
61  // CHECK-NEXT: CXXConstructExpr
62  // CHECK-NEXT: CXXCtorInitializer: m
63  // CHECK-NEXT: IntegerLiteral: 0
64  X(char s, int) : Base(), m(0) {
65    // CHECK-NEXT: CompoundStmt
66    // CHECK: MemberExpr: :m(
67    int x = m;
68  }
69  // CHECK: CXXConstructorDecl: :X(void (char){{( __attribute__\(\(thiscall\)\))?}})(
70  // CHECK: CXXCtorInitializer: X
71  X(char s) : X(s, 4) {}
72};
73
74#define M (void)1
75#define MA(a, b) (void)a, b
76// CHECK: FunctionDecl
77// CHECK-NEXT: CompoundStmt
78void macros() {
79  M;
80  MA(1, 2);
81}
82
83#ifndef GUARD
84#define GUARD
85// CHECK-NEXT: NamespaceDecl
86namespace world {
87// nodes from other files are excluded, there should be no output here
88#include "clang-diff-ast.cpp"
89}
90// CHECK-NEXT: FunctionDecl: sentinel
91void sentinel();
92#endif
93