forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope.C
105 lines (79 loc) · 2.6 KB
/
scope.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//------------------------------------------------------------------------------
// CLING - the C++ LLVM-based InterpreterG :)
//
// This file is dual-licensed: you can choose to license it under the University
// of Illinois Open Source License or the GNU Lesser General Public License. See
// LICENSE.TXT for details.
//------------------------------------------------------------------------------
// RUN: cat %s | %built_cling -fno-rtti 2>&1 | FileCheck %s
// Test findScope, which is essentially is a DeclContext.
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/LookupHelper.h"
#include "clang/AST/Decl.h"
#include "clang/AST/Type.h"
#include <cstdio>
using namespace std;
using namespace llvm;
using namespace cling;
.rawInput 1
class A {};
.rawInput 0
const LookupHelper& lookup = gCling->getLookupHelper();
LookupHelper::DiagSetting diags = LookupHelper::WithDiagnostics;
const clang::Decl* cl_A = lookup.findScope("A", diags);
printf("cl_A: 0x%lx\n", (unsigned long) cl_A);
//CHECK: cl_A: 0x{{[1-9a-f][0-9a-f]*$}}
cast<clang::NamedDecl>(cl_A)->getQualifiedNameAsString().c_str()
//CHECK-NEXT: ({{[^)]+}}) "A"
.rawInput 1
namespace N {
class A {};
}
.rawInput 0
const clang::Decl* cl_A_in_N = lookup.findScope("N::A", diags);
printf("cl_A_in_N: 0x%lx\n", (unsigned long) cl_A_in_N);
//CHECK: cl_A_in_N: 0x{{[1-9a-f][0-9a-f]*$}}
cast<clang::NamedDecl>(cl_A_in_N)->getQualifiedNameAsString().c_str()
//CHECK-NEXT: ({{[^)]+}}) "N::A"
.rawInput 1
namespace N {
namespace M {
namespace P {
class A {};
}
}
}
.rawInput 0
const clang::Decl* cl_A_in_NMP = lookup.findScope("N::M::P::A", diags);
cl_A_in_NMP
//CHECK: (const clang::Decl *) 0x{{[1-9a-f][0-9a-f]*$}}
cast<clang::NamedDecl>(cl_A_in_NMP)->getQualifiedNameAsString().c_str()
//CHECK-NEXT: ({{[^)]+}}) "N::M::P::A"
.rawInput 1
template <class T> class B { T b; };
.rawInput 0
const clang::Decl* cl_B_int = lookup.findScope("B<int>", diags);
printf("cl_B_int: 0x%lx\n", (unsigned long) cl_B_int);
//CHECK-NEXT: cl_B_int: 0x{{[1-9a-f][0-9a-f]*$}}
//
// Test optional returned type is as spelled by the user.
//
typedef int Int_t;
.rawInput 1
template <typename T> struct W { T member; };
.rawInput 0
const clang::Type* resType = 0;
lookup.findScope("W<Int_t>", diags, &resType);
//resType->dump();
clang::QualType(resType,0).getAsString().c_str()
//CHECK-NEXT: ({{[^)]+}}) "W<Int_t>"
.rawInput 1
namespace Functions {
void Next();
}
using namespace Functions;
namespace Next {}
.rawInput 0
const clang::Decl* cl_Next = lookup.findScope("Next", diags);
printf("cl_Next: 0x%lx\n", (unsigned long) cl_Next);
//CHECK-NEXT: cl_Next: 0x{{[1-9a-f][0-9a-f]*$}}