• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "stub.h" // this bad path is made valid by a `-I include` clang arg
2 
3 #pragma once
4 
5 #define TESTMACRO
6 
7 #define TESTMACRO_INTEGER 42
8 #define TESTMACRO_STRING "Hello Preprocessor!"
9 #define TESTMACRO_STRING_EXPANDED TESTMACRO_STRING
10 #define TESTMACRO_CUSTOMINTKIND_PATH 123
11 
12 // The following two macros are parsed the same by cexpr, but are semantically
13 // different.
14 #define TESTMACRO_NONFUNCTIONAL (TESTMACRO_INTEGER)
15 #define TESTMACRO_FUNCTIONAL_EMPTY(TESTMACRO_INTEGER)
16 #define TESTMACRO_FUNCTIONAL_NONEMPTY(TESTMACRO_INTEGER)-TESTMACRO_INTEGER
17 #define TESTMACRO_FUNCTIONAL_TOKENIZED(  a, b   ,c,d,e   ) a/b c    d ## e
18 #define TESTMACRO_FUNCTIONAL_SPLIT(  a, \
19         b) b,\
20         a
21 //#define TESTMACRO_INVALID("string") // A conforming preprocessor rejects this
22 #define TESTMACRO_STRING_EXPR ("string")
23 #define TESTMACRO_STRING_FUNC_NON_UTF8(x) (x "��") /* invalid UTF-8 on purpose */
24 
25 enum {
26   MY_ANNOYING_MACRO =
27 #define MY_ANNOYING_MACRO 1
28     MY_ANNOYING_MACRO,
29 };
30 
31 class Test {
32   int m_int;
33   double m_double;
34 public:
35   static const char* name();
36   Test(int foo);
37   Test(double foo);
38 
39   static const int COUNTDOWN[];
40   static const int* COUNTDOWN_PTR;
41   static const int* countdown();
42 };
43 
44 class ITest {
45   virtual void foo() = 0;
46 };
47 
48 class VirtualDestructor {
49 public:
50   static unsigned sDestructorCount;
51   virtual ~VirtualDestructor() = 0;
52 };
53 
54 class InheritsFromVirtualDestructor final : public VirtualDestructor {
55 public:
56   static unsigned sDestructorCount;
57   InheritsFromVirtualDestructor();
58   ~InheritsFromVirtualDestructor() final;
59 };
60 
61 namespace testing {
62 
63 typedef Test TypeAlias;
64 
65 } // namespace testing
66 
67 typedef testing::TypeAlias TypeAlias;
68 
69 namespace bitfields {
70 
71 struct First {
72     unsigned char three_bits_byte_one : 3;
73     // This starts a new byte, leaving 5 bits unused.
74     unsigned char :0;
75 
76     unsigned char six_bits_byte_two : 6;
77     unsigned char two_bits_byte_two : 2;
78 
79     /// Returns true if the bitfields match the arguments, false otherwise.
80     bool assert(unsigned char first,
81                 unsigned char second,
82                 unsigned char third);
83 };
84 
85 struct Second {
86     int thirty_one_bits : 31;
87     bool one_bit : 1;
88 
89     /// Returns true if the bitfields match the arguments, false otherwise.
90     bool assert(int first,
91                 bool second);
92 };
93 
94 enum ItemKind {
95     ITEM_KIND_UNO = 0,
96     ITEM_KIND_DOS,
97     ITEM_KIND_TRES,
98 };
99 
100 struct Third {
101     int flags : 28;
102     bool is_whatever : 1;
103     ItemKind kind : 3;
104 
105     /// Returns true if the bitfields match the arguments, false otherwise.
106     bool assert(int first, bool second, ItemKind third);
107 };
108 
109 enum MyEnum {
110     ONE = 0,
111     TWO,
112     THREE,
113     FOUR,
114 };
115 
116 struct Fourth {
117     MyEnum tag: 2;
118     unsigned long ptr: 48;
119 
120     /// Returns true if the bitfields match the arguments, false otherwise.
121     bool assert(MyEnum tag, unsigned long ptr);
122 };
123 
124 struct Date2 {
125     unsigned short nWeekDay  : 3;    // 0..7   (3 bits)
126     unsigned short nMonthDay : 6;    // 0..31  (6 bits)
127     unsigned short nMonth    : 5;    // 0..12  (5 bits)
128     unsigned short nYear     : 8;    // 0..100 (8 bits)
129     unsigned char byte : 8;
130 
131     bool assert(unsigned short nWeekDay,
132                 unsigned short nMonthDay,
133                 unsigned short nMonth,
134                 unsigned short nYear,
135                 unsigned short byte);
136 };
137 
138 
139 struct Fifth {
140     unsigned short nWeekDay  : 3;    // 0..7   (3 bits)
141     unsigned short nMonthDay : 6;    // 0..31  (6 bits)
142     unsigned short nMonth    : 5;    // 0..12  (5 bits)
143     unsigned short nYear     : 8;    // 0..100 (8 bits)
144     unsigned char byte;
145 
146     /// Returns true if the bitfields match the arguments, false otherwise.
147     bool assert(unsigned short nWeekDay,
148                 unsigned short nMonthDay,
149                 unsigned short nMonth,
150                 unsigned short nYear,
151                 unsigned char byte);
152 };
153 
154 struct Sixth {
155     unsigned char byte;
156     unsigned char nWeekDay  : 3;
157     unsigned char nMonth    : 5;
158     unsigned char nMonthDay : 6;
159 
160     /// Returns true if the bitfields match the arguments, false otherwise.
161     bool assert(unsigned char byte,
162                 unsigned char nWeekDay,
163                 unsigned char nMonth,
164                 unsigned char nMonthDay);
165 };
166 
167 struct Seventh {
168     bool first_one_bit : 1;
169     unsigned int second_thirty_bits : 30;
170     unsigned short third_two_bits : 2;
171     unsigned int fourth_thirty_bits : 30;
172     unsigned short fifth_two_bits : 2;
173     bool sixth_one_bit : 1;
174     unsigned int seventh_thirty_bits : 30;
175 
176     /// Returns true if the bitfields match the arguments, false otherwise.
177     bool assert(bool first,
178                 int second,
179                 unsigned short third,
180                 unsigned int fourth,
181                 unsigned short fifth,
182                 bool sixth,
183                 int seventh);
184 };
185 
186 } // namespace bitfields
187 
188 struct AutoRestoreBool {
189   bool* m_ptr;
190   bool m_value;
191 
192   AutoRestoreBool(bool*);
193   ~AutoRestoreBool();
194 };
195 
196 struct WithWChar {
197   wchar_t foo[30];
198 };
199 
200 // The names of the following items are unprefixed by the parse callbacks.
201 const int MY_PREFIXED_CONST_VALUE = 3;
202 
203 int my_prefixed_function_name();
204 
205 struct my_prefixed_bar {
206     int foo;
207 };
208 
209 struct my_prefixed_foo {
210    my_prefixed_bar member;
211 };
212 
213 enum my_prefixed_enum_to_be_constified {
214   ONE = 1,
215   TWO,
216   THREE,
217 };
218 
219 struct my_prefixed_baz {
220   char foo[30];
221 };
222 
223 template<typename T>
224 struct my_prefixed_templated_foo {
225   T member;
226 };
227 
228 my_prefixed_templated_foo<my_prefixed_baz> TEMPLATED_CONST_VALUE;
229 
230 void my_prefixed_function_to_remove();
231 
232 typedef union {
233   double v[4];
234 } Coord;
235 
236 Coord coord(double x, double y, double z, double t);
237 
238 // Used to test custom derives on enum. See `test_custom_derive`.
239 enum MyOrderedEnum {
240   MICRON,
241   METER,
242   LIGHTYEAR,
243 };
244