]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / namespace / main.cpp
1 //===-- main.cpp ------------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include <cstdarg>
11 #include <cstdlib>
12 #include "ns.h"
13
14 namespace {
15     typedef unsigned int my_uint_t;
16     int i; // Find the line number for anonymous namespace variable i.
17
18     int myanonfunc (int a)
19     {
20         return a + a;
21     }
22
23     int
24     variadic_sum (int arg_count...)
25     {
26         int sum = 0;
27         std::va_list args;
28         va_start(args, arg_count);
29
30         for (int i = 0; i < arg_count; i++)
31             sum += va_arg(args, int);
32
33         va_end(args);
34         return sum;
35     }
36 }
37
38 namespace A {
39     typedef unsigned int uint_t;
40     namespace B {
41         typedef unsigned int uint_t;
42         int j; // Find the line number for named namespace variable j.
43         int myfunc (int a);
44         int myfunc2(int a)
45         {
46              return a + 2;
47         }
48         float myfunc (float f)
49         {
50             return f - 2.0;
51         }
52     }
53 }
54
55 namespace Y
56 {
57     typedef unsigned int uint_t;
58     using A::B::j;
59     int foo;
60 }
61
62 using A::B::j;          // using declaration
63
64 namespace Foo = A::B;   // namespace alias
65
66 using Foo::myfunc;      // using declaration
67
68 using namespace Foo;    // using directive
69
70 namespace A {
71     namespace B {
72         using namespace Y;
73         int k;
74     }
75 }
76
77 namespace ns1 {
78     int value = 100;
79 }
80
81 namespace ns2 {
82     int value = 200;
83 }
84
85 void test_namespace_scopes() {
86     do {
87         using namespace ns1;
88         printf("ns1::value = %d\n", value); // Evaluate ns1::value
89     } while(0);
90     
91     do {
92         using namespace ns2;
93         printf("ns2::value = %d\n", value); // Evaluate ns2::value
94     } while(0);
95 }
96
97 int Foo::myfunc(int a)
98 {
99     test_namespace_scopes();    
100
101     ::my_uint_t anon_uint = 0;
102     A::uint_t a_uint = 1;
103     B::uint_t b_uint = 2;
104     Y::uint_t y_uint = 3;
105     i = 3;
106     j = 4;
107     printf("::i=%d\n", ::i);
108     printf("A::B::j=%d\n", A::B::j);
109     printf("variadic_sum=%d\n", variadic_sum(3, 1, 2, 3));
110     myanonfunc(3);
111     return myfunc2(3) + j + i + a + 2 + anon_uint + a_uint + b_uint + y_uint; // Set break point at this line.
112 }
113
114 int
115 main (int argc, char const *argv[])
116 {
117     test_lookup_at_global_scope();
118     test_lookup_at_file_scope();
119     A::test_lookup_at_ns_scope();
120     A::B::test_lookup_at_nested_ns_scope();
121     A::B::test_lookup_at_nested_ns_scope_after_using();
122     test_lookup_before_using_directive();
123     test_lookup_after_using_directive();
124     return Foo::myfunc(12);
125 }