forked from lvzixun/Clang-Complete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clang.py
499 lines (359 loc) · 11.7 KB
/
clang.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# the type from clang-c/Index.h
from ctypes import Structure, POINTER, c_char_p, c_void_p, c_uint, c_bool, c_ulong, c_int
from .enum import Enum
class CXUnsavedFile(Structure):
_fields_ = [("name", c_char_p), ("contents", c_char_p), ('length', c_ulong)]
class CXCompletionChunkKind(Enum):
Optional = 0
TypedText = 1
Text = 2
Placeholder = 3
Informative = 4
CurrentParameter = 5
LeftParen = 6
RightParen = 7
LeftBracket = 8
RightBracket = 9
LeftBrace = 10
RightBrace = 11
LeftAngle = 12
RightAngle = 13
Comma = 14
ResultType = 15
Colon = 16
SemiColon = 17
Equal = 18
HorizontalSpace = 19
VerticalSpace = 20
class CXCursorKind(Enum):
UNEXPOSED_DECL = 1
# A C or C++ struct.
STRUCT_DECL = 2
# A C or C++ union.
UNION_DECL = 3
# A C++ class.
CLASS_DECL = 4
# An enumeration.
ENUM_DECL = 5
# A field (in C or non-static data member (in C++ in a struct, union, or C++
# class.
FIELD_DECL = 6
# An enumerator constant.
ENUM_CONSTANT_DECL = 7
# A function.
FUNCTION_DECL = 8
# A variable.
VAR_DECL = 9
# A function or method parameter.
PARM_DECL = 10
# An Objective-C @interface.
OBJC_INTERFACE_DECL = 11
# An Objective-C @interface for a category.
OBJC_CATEGORY_DECL = 12
# An Objective-C @protocol declaration.
OBJC_PROTOCOL_DECL = 13
# An Objective-C @property declaration.
OBJC_PROPERTY_DECL = 14
# An Objective-C instance variable.
OBJC_IVAR_DECL = 15
# An Objective-C instance method.
OBJC_INSTANCE_METHOD_DECL = 16
# An Objective-C class method.
OBJC_CLASS_METHOD_DECL = 17
# An Objective-C @implementation.
OBJC_IMPLEMENTATION_DECL = 18
# An Objective-C @implementation for a category.
OBJC_CATEGORY_IMPL_DECL = 19
# A typedef.
TYPEDEF_DECL = 20
# A C++ class method.
CXX_METHOD = 21
# A C++ namespace.
NAMESPACE = 22
# A linkage specification, e.g. 'extern "C"'.
LINKAGE_SPEC = 23
# A C++ constructor.
CONSTRUCTOR = 24
# A C++ destructor.
DESTRUCTOR = 25
# A C++ conversion function.
CONVERSION_FUNCTION = 26
# A C++ template type parameter
TEMPLATE_TYPE_PARAMETER = 27
# A C++ non-type template paramater.
TEMPLATE_NON_TYPE_PARAMETER = 28
# A C++ template template parameter.
TEMPLATE_TEMPLATE_PARAMTER = 29
# A C++ function template.
FUNCTION_TEMPLATE = 30
# A C++ class template.
CLASS_TEMPLATE = 31
# A C++ class template partial specialization.
CLASS_TEMPLATE_PARTIAL_SPECIALIZATION = 32
# A C++ namespace alias declaration.
NAMESPACE_ALIAS = 33
# A C++ using directive
USING_DIRECTIVE = 34
# A C++ using declaration
USING_DECLARATION = 35
# A Type alias decl.
TYPE_ALIAS_DECL = 36
# A Objective-C synthesize decl
OBJC_SYNTHESIZE_DECL = 37
# A Objective-C dynamic decl
OBJC_DYNAMIC_DECL = 38
# A C++ access specifier decl.
CXX_ACCESS_SPEC_DECL = 39
###
# Reference Kinds
OBJC_SUPER_CLASS_REF = 40
OBJC_PROTOCOL_REF = 41
OBJC_CLASS_REF = 42
# A reference to a type declaration.
#
# A type reference occurs anywhere where a type is named but not
# declared. For example, given:
# typedef unsigned size_type;
# size_type size;
#
# The typedef is a declaration of size_type (CXCursor_TypedefDecl ,
# while the type of the variable "size" is referenced. The cursor
# referenced by the type of size is the typedef for size_type.
TYPE_REF = 43
CXX_BASE_SPECIFIER = 44
# A reference to a class template, function template, template
# template parameter, or class template partial specialization.
TEMPLATE_REF = 45
# A reference to a namespace or namepsace alias.
NAMESPACE_REF = 46
# A reference to a member of a struct, union, or class that occurs in
# some non-expression context, e.g., a designated initializer.
MEMBER_REF = 47
# A reference to a labeled statement.
LABEL_REF = 48
# A reference toa a set of overloaded functions or function templates
# that has not yet been resolved to a specific function or function template.
OVERLOADED_DECL_REF = 49
###
# Invalid/Error Kinds
INVALID_FILE = 70
NO_DECL_FOUND = 71
NOT_IMPLEMENTED = 72
INVALID_CODE = 73
###
# Expression Kinds
# An expression whose specific kind is not exposed via this interface.
#
# Unexposed expressions have the same operations as any other kind of
# expression; one can extract their location information, spelling, children,
# etc. However, the specific kind of the expression is not reported.
UNEXPOSED_EXPR = 100
# An expression that refers to some value declaration, such as a function,
# varible, or enumerator.
DECL_REF_EXPR = 101
# An expression that refers to a member of a struct, union, class, Objective-C
# class, etc.
MEMBER_REF_EXPR = 102
# An expression that calls a function.
CALL_EXPR = 103
# An expression that sends a message to an Objective-C object or class.
OBJC_MESSAGE_EXPR = 104
# An expression that represents a block literal.
BLOCK_EXPR = 105
# An integer literal.
INTEGER_LITERAL = 106
# A floating point number literal.
FLOATING_LITERAL = 107
# An imaginary number literal.
IMAGINARY_LITERAL = 108
# A string literal.
STRING_LITERAL = 109
# A character literal.
CHARACTER_LITERAL = 110
# A parenthesized expression, e.g. "(1 ".
#
# This AST node is only formed if full location information is requested.
PAREN_EXPR = 111
# This represents the unary-expression's (except sizeof and
# alignof .
UNARY_OPERATOR = 112
# [C99 6.5.2.1] Array Subscripting.
ARRAY_SUBSCRIPT_EXPR = 113
# A builtin binary operation expression such as "x + y" or
# "x <= y".
BINARY_OPERATOR = 114
# Compound assignment such as "+=".
COMPOUND_ASSIGNMENT_OPERATOR = 115
# The ?: ternary operator.
CONDITONAL_OPERATOR = 116
# An explicit cast in C (C99 6.5.4 or a C-style cast in C++
# (C++ [expr.cast] , which uses the syntax (Type expr.
#
# For example: (int f.
CSTYLE_CAST_EXPR = 117
# [C99 6.5.2.5]
COMPOUND_LITERAL_EXPR = 118
# Describes an C or C++ initializer list.
INIT_LIST_EXPR = 119
# The GNU address of label extension, representing &&label.
ADDR_LABEL_EXPR = 120
# This is the GNU Statement Expression extension: ({int X=4; X;}
StmtExpr = 121
# Represents a C1X generic selection.
GENERIC_SELECTION_EXPR = 122
# Implements the GNU __null extension, which is a name for a null
# pointer constant that has integral type (e.g., int or long and is the same
# size and alignment as a pointer.
#
# The __null extension is typically only used by system headers, which define
# NULL as __null in C++ rather than using 0 (which is an integer that may not
# match the size of a pointer .
GNU_NULL_EXPR = 123
# C++'s static_cast<> expression.
CXX_STATIC_CAST_EXPR = 124
# C++'s dynamic_cast<> expression.
CXX_DYNAMIC_CAST_EXPR = 125
# C++'s reinterpret_cast<> expression.
CXX_REINTERPRET_CAST_EXPR = 126
# C++'s const_cast<> expression.
CXX_CONST_CAST_EXPR = 127
# Represents an explicit C++ type conversion that uses "functional"
# notion (C++ [expr.type.conv] .
#
# Example:
# \code
# x = int(0.5 ;
# \endcode
CXX_FUNCTIONAL_CAST_EXPR = 128
# A C++ typeid expression (C++ [expr.typeid] .
CXX_TYPEID_EXPR = 129
# [C++ 2.13.5] C++ Boolean Literal.
CXX_BOOL_LITERAL_EXPR = 130
# [C++0x 2.14.7] C++ Pointer Literal.
CXX_NULL_PTR_LITERAL_EXPR = 131
# Represents the "this" expression in C++
CXX_THIS_EXPR = 132
# [C++ 15] C++ Throw Expression.
#
# This handles 'throw' and 'throw' assignment-expression. When
# assignment-expression isn't present, Op will be null.
CXX_THROW_EXPR = 133
# A new expression for memory allocation and constructor calls, e.g:
# "new CXXNewExpr(foo ".
CXX_NEW_EXPR = 134
# A delete expression for memory deallocation and destructor calls,
# e.g. "delete[] pArray".
CXX_DELETE_EXPR = 135
# Represents a unary expression.
CXX_UNARY_EXPR = 136
# ObjCStringLiteral, used for Objective-C string literals i.e. "foo".
OBJC_STRING_LITERAL = 137
# ObjCEncodeExpr, used for in Objective-C.
OBJC_ENCODE_EXPR = 138
# ObjCSelectorExpr used for in Objective-C.
OBJC_SELECTOR_EXPR = 139
# Objective-C's protocol expression.
OBJC_PROTOCOL_EXPR = 140
# An Objective-C "bridged" cast expression, which casts between
# Objective-C pointers and C pointers, transferring ownership in the process.
#
# \code
# NSString *str = (__bridge_transfer NSString * CFCreateString( ;
# \endcode
OBJC_BRIDGE_CAST_EXPR = 141
# Represents a C++0x pack expansion that produces a sequence of
# expressions.
#
# A pack expansion expression contains a pattern (which itself is an
# expression followed by an ellipsis. For example:
PACK_EXPANSION_EXPR = 142
# Represents an expression that computes the length of a parameter
# pack.
SIZE_OF_PACK_EXPR = 143
# A statement whose specific kind is not exposed via this interface.
#
# Unexposed statements have the same operations as any other kind of statement;
# one can extract their location information, spelling, children, etc. However,
# the specific kind of the statement is not reported.
UNEXPOSED_STMT = 200
# A labelled statement in a function.
LABEL_STMT = 201
# A compound statement
COMPOUND_STMT = 202
# A case statement.
CASE_STMT = 203
# A default statement.
DEFAULT_STMT = 204
# An if statement.
IF_STMT = 205
# A switch statement.
SWITCH_STMT = 206
# A while statement.
WHILE_STMT = 207
# A do statement.
DO_STMT = 208
# A for statement.
FOR_STMT = 209
# A goto statement.
GOTO_STMT = 210
# An indirect goto statement.
INDIRECT_GOTO_STMT = 211
# A continue statement.
CONTINUE_STMT = 212
# A break statement.
BREAK_STMT = 213
# A return statement.
RETURN_STMT = 214
# A GNU-style inline assembler statement.
ASM_STMT = 215
# Objective-C's overall @try-@catch-@finally statement.
OBJC_AT_TRY_STMT = 216
# Objective-C's @catch statement.
OBJC_AT_CATCH_STMT = 217
# Objective-C's @finally statement.
OBJC_AT_FINALLY_STMT = 218
# Objective-C's @throw statement.
OBJC_AT_THROW_STMT = 219
# Objective-C's @synchronized statement.
OBJC_AT_SYNCHRONIZED_STMT = 220
# Objective-C's autorealease pool statement.
OBJC_AUTORELEASE_POOL_STMT = 221
# Objective-C's for collection statement.
OBJC_FOR_COLLECTION_STMT = 222
# C++'s catch statement.
CXX_CATCH_STMT = 223
# C++'s try statement.
CXX_TRY_STMT = 224
# C++'s for (* : * statement.
CXX_FOR_RANGE_STMT = 225
# Windows Structured Exception Handling's try statement.
SEH_TRY_STMT = 226
# Windows Structured Exception Handling's except statement.
SEH_EXCEPT_STMT = 227
# Windows Structured Exception Handling's finally statement.
SEH_FINALLY_STMT = 228
# The null statement.
NULL_STMT = 230
# Adaptor class for mixing declarations with statements and expressions.
DECL_STMT = 231
###
# Other Kinds
# Cursor that represents the translation unit itself.
#
# The translation unit cursor exists primarily to act as the root cursor for
# traversing the contents of a translation unit.
TRANSLATION_UNIT = 300
###
# Attributes
# An attribute whoe specific kind is note exposed via this interface
UNEXPOSED_ATTR = 400
IB_ACTION_ATTR = 401
IB_OUTLET_ATTR = 402
IB_OUTLET_COLLECTION_ATTR = 403
###
# Preprocessing
PREPROCESSING_DIRECTIVE = 500
MACRO_DEFINITION = 501
MACRO_INSTANTIATION = 502
INCLUSION_DIRECTIVE = 503
# __all__ = ["CXUnsavedFile", "CXCompletionChunkKind", "CXCursorKind"]