-
Notifications
You must be signed in to change notification settings - Fork 0
/
cc_grammar.proto
477 lines (409 loc) · 11 KB
/
cc_grammar.proto
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
// WSO-Vasker: Golang C++ AST Parser Tools
// Copyright (c) 2021 Warriorstar Orion <[email protected]>
// SPDX-License-Identifier: MIT
syntax = "proto2";
package cc_transformer;
option go_package = "snowfrost.garden/vasker/cc_grammar";
option java_package = "garden.snowfrost.vasker";
option java_outer_classname = "Cc";
message Project {
optional string prefix = 1;
repeated DeclarationFile declaration_files = 3;
repeated DefinitionFile definition_files = 2;
}
message FileMetadata {
optional string filename = 1;
optional uint32 file_id = 2;
optional string source_path = 3;
}
message Preamble { repeated string headers = 1; }
message DefinitionFile {
optional FileMetadata file_metadata = 1;
optional Preamble preamble = 2;
optional string base_include = 3;
repeated NamespacedDefinition namespaced_definitions = 4;
}
message Identifier {
optional string namespace = 1;
optional string id = 2;
}
enum AccessSpecifier {
PRIVATE = 0;
PUBLIC = 1;
PROTECTED = 2;
}
message BaseSpecifier {
optional AccessSpecifier access_specifier = 1;
optional Identifier class_or_decltype = 2;
optional bool virtual = 3;
}
message MemberInitializer {
optional Identifier member = 1;
repeated Expression expressions = 2;
}
message Constructor {
optional Identifier class_name = 1;
repeated FunctionArgument arguments = 2;
repeated MemberInitializer member_initializers = 3;
optional BlockDefinition block_definition = 4;
}
message Destructor {
optional Identifier class_name = 1;
optional BlockDefinition block_definition = 2;
}
message CopyAssignmentOperator {}
message MoveAssignmentOperator {}
message UsingDeclaration { optional Identifier identifier = 1; }
message MemberDeclarator {
optional Initializer initializer = 1;
oneof Value { Identifier declared_name = 2; }
optional CppType declared_type = 3;
optional bool class = 4;
optional bool friend = 5;
}
message MemberSpecification {
oneof Value {
MemberDeclarator member_declarator = 1;
Constructor constructor = 2;
Destructor destructor = 3;
CopyAssignmentOperator copy_assignment_operator = 4;
MoveAssignmentOperator move_assignment_operator = 5;
FunctionDeclaration function_declaration = 6;
FunctionDefinition function_definition = 7;
AccessSpecifier access_specifier = 8;
UsingDeclaration using_declaration = 9;
// static_assert declarations
// member template declarations
// alias declarations
// deduction guides
}
}
message ClassDeclaration {
optional string name = 1;
repeated BaseSpecifier base_specifiers = 2;
repeated MemberSpecification member_specifiers = 3;
}
message ClassDefinition {
optional string name = 1;
repeated FunctionDefinition function_definitions = 2;
}
message NamespacedDeclaration {
optional string namespace = 1;
repeated ClassForwardDeclaration class_forward_declarations = 2;
repeated ClassDeclaration class_declarations = 3;
repeated FunctionDeclaration function_declarations = 4;
}
message NamespacedDefinition {
optional string namespace = 1;
repeated ClassDefinition class_definitions = 2;
repeated FunctionDefinition function_definitions = 3;
repeated Constructor constructors = 4;
}
message DeclarationFile {
optional FileMetadata file_metadata = 1;
optional Preamble preamble = 2;
optional string include_guard = 3;
repeated NamespacedDeclaration namespaced_declarations = 4;
}
message ClassForwardDeclaration {
optional string namespace = 1;
optional string class_name = 2;
}
message NamespaceDeclaration { optional string declaration = 1; }
message IfStatement {
optional Expression condition = 1;
optional Statement statement_true = 2;
optional Statement statement_false = 3;
}
message CompoundStatement { repeated Statement statements = 1; }
message SimpleTypeSpecifier {
oneof Value { Identifier declared_name = 1; }
}
message TypeSpecifier {
oneof Value { SimpleTypeSpecifier simple_type_specifier = 1; }
}
message FunctionSpecifier {
enum FunctionSpecifierKeyword {
INLINE = 1;
VIRTUAL = 2;
EXPLICIT = 3;
}
optional FunctionSpecifierKeyword keyword = 1;
}
message DeclarationSpecifier {
oneof Value {
FunctionSpecifier function_specifier = 1;
// type-specifier-seq
TypeSpecifier type_specifier = 2;
}
optional bool virtual = 3;
}
message Declarator {
optional Initializer initializer = 1;
oneof Value {
// unqualified-id or qualified-id
Identifier declared_name = 2;
}
}
message CopyInitializer { optional Expression other = 1; }
message Initializer {
oneof Value { CopyInitializer copy_initializer = 1; }
}
message SimpleDeclaration {
// attr since C++11
// decl-specific-seq
repeated DeclarationSpecifier specifiers = 1;
// init-declarator-list
repeated Declarator declarators = 2;
}
message BlockDeclaration {
oneof Value { SimpleDeclaration simple_declaration = 1; }
}
message Declaration {
oneof value { BlockDeclaration block_declaration = 1; }
}
message DoWhile {
optional Expression condition = 1;
optional BlockDefinition block_definition = 2;
}
message While {
optional Expression condition = 1;
optional BlockDefinition block_definition = 2;
}
message CoYield { optional Expression expression = 1; }
message CoReturn { optional Expression expression = 1; }
message Statement {
oneof value {
Expression expression_statement = 1;
CompoundStatement compound_statement = 2;
IfStatement if_statement = 3;
Declaration declaration_statement = 4;
DoWhile do_while = 5;
RangeBasedFor range_based_for = 6;
ForLoop for_loop = 7;
ReturnStatement return_statement = 8;
While while = 9;
CoReturn co_return = 10;
}
}
message ConditionalOperator {
optional Expression predicate = 1;
optional Expression first = 2;
optional Expression second = 3;
}
message Expression {
oneof value {
AssignmentExpression assignment_expression = 1;
UnaryExpression unary_expression = 2;
ArithmeticExpression arithmetic_expression = 3;
LogicalExpression logical_expression = 4;
ComparisonExpression comparison_expression = 5;
MemberAccessExpression member_access_expression = 6;
FunctionCallExpression function_call_expression = 7;
Literal literal_expression = 8;
Identifier identifier_expression = 9;
LambdaExpression lambda_expression = 10;
CoYield co_yield = 11;
ConditionalOperator conditional_operator = 12;
}
}
message LambdaCapture {
enum LambdaCaptureType {
UNKNOWN = 1;
SIMPLE = 2;
}
optional Identifier identifier = 1;
optional Initializer initializer = 2;
optional LambdaCaptureType capture_type = 3;
}
message LambdaExpression {
enum LambdaCaptureDefault {
UNKNOWN = 1;
NONE = 2;
BY_REFERENCE = 3;
BY_COPY = 4;
}
optional LambdaCaptureDefault capture_default = 1;
repeated LambdaCapture capture = 2;
repeated FunctionArgument arguments = 3;
optional CppType trailing_return_type = 4;
optional BlockDefinition body = 5;
}
message ForLoop {
oneof init {
Statement init_statement = 1;
Expression init_expression = 2;
}
oneof condition {
Expression cond_expression = 3;
// TODO: Declaration with brace-or-equals identifier
}
// iteration-expression is not a statement according
// to the grammar, but permitting a statement allows
// a tiny amount of wiggle room when transforming ASTs
// in other languages which may allow a statement.
optional Statement iter_expr = 4;
optional Statement body = 5;
}
message InitializerList { repeated Expression args = 1; }
message FunctionCallExpression {
optional Expression name = 1;
repeated ExpressionArg arguments = 2;
message ExpressionArg {
oneof Value {
Expression expression = 1;
InitializerList initializer_list = 2;
}
}
}
message BlockDefinition { repeated Statement statements = 1; }
message FunctionDefinition {
optional FunctionDeclaration declaration = 1;
optional BlockDefinition block_definition = 2;
}
message VirtSpecifier {
enum Keyword {
OVERRIDE = 1;
FINAL = 2;
OVERRIDE_FINAL = 3;
FINAL_OVERRIDE = 4;
}
optional Keyword keyword = 1;
}
message FunctionDeclaration {
optional string name = 1;
optional CppType return_type = 2;
repeated FunctionArgument arguments = 3;
optional VirtSpecifier virt_specifier = 4;
optional Identifier member_of = 5;
}
message CppType {
enum PType {
UNKNOWN = 0;
NONE = 1;
RAW_POINTER = 2;
REFERENCE = 3;
UNIQUE_PTR = 4;
SHARED_PTR = 5;
}
optional PType p_type = 1;
optional string name = 2;
}
message FunctionArgument {
optional CppType cpp_type = 1;
optional string name = 2;
}
message AssignmentExpression {
enum Operator {
SIMPLE = 0;
ADDITION = 1;
SUBTRACTION = 2;
MULTIPLICATION = 3;
DIVISION = 4;
MODULO = 5;
BITWISE_AND = 6;
BITWISE_OR = 7;
BITWISE_XOR = 8;
BITWISE_LSHIFT = 9;
BITWISE_RSHIFT = 10;
}
optional Operator operator = 1;
optional Expression lhs = 2;
optional Expression rhs = 3;
}
message UnaryExpression {
enum Operator {
UNARY_PLUS = 1;
UNARY_MINUS = 2;
BITWISE_NOT = 3;
PRE_INCREMENT = 4;
PRE_DECREMENT = 5;
POST_INCREMENT = 6;
POST_DECREMENT = 7;
LOGICAL_NOT = 8;
POINTER_INDIRECTION = 9;
ADDRESS_OF = 10;
}
optional Operator operator = 1;
optional Expression operand = 2;
}
message LogicalExpression {
enum Operator {
LOGICAL_AND = 1;
LOGICAL_OR = 2;
}
optional Operator operator = 1;
optional Expression lhs = 2;
optional Expression rhs = 3;
}
message ComparisonExpression {
enum Operator {
EQUAL_TO = 1;
NOT_EQUAL_TO = 2;
LESS_THAN = 3;
GREATER_THAN = 4;
LESS_THAN_OR_EQUAL_TO = 5;
GREATER_THAN_OR_EQUAL_TO = 6;
}
optional Operator operator = 1;
optional Expression lhs = 2;
optional Expression rhs = 3;
}
message MemberAccessExpression {
enum Operator {
SUBSCRIPT = 1;
MEMBER_OF_OBJECT = 2;
MEMBER_OF_POINTER = 3;
POINTER_TO_OBJECT_MEMBER = 4;
POINTER_TO_POINTER_MEMBER = 5;
}
optional Operator operator = 1;
optional Expression lhs = 2;
optional Expression rhs = 3;
}
message ArithmeticExpression {
enum Operator {
ADDITION = 1;
SUBTRACTION = 2;
MULTIPLICATION = 3;
DIVISION = 4;
MODULO = 5;
BITWISE_AND = 6;
BITWISE_OR = 7;
BITWISE_XOR = 8;
BITWISE_LSHIFT = 9;
BITWISE_RSHIFT = 10;
}
optional Operator operator = 1;
optional Expression lhs = 2;
optional Expression rhs = 3;
}
message Literal {
oneof Value {
int64 integer_literal = 1;
int64 character_literal = 2;
float float_literal = 3;
string string_literal = 4;
bool boolean_literal = 5;
}
}
message RangeBasedFor {
optional Declaration declaration = 1;
optional Expression range_expression = 2;
optional BlockDefinition loop_definition = 3;
}
message ReturnStatement {
oneof Value {
Expression expression = 1;
// TODO: braced-init-list
}
}
message SwitchStatement {
optional Expression condition = 1;
repeated SwitchCase cases = 2;
optional Statement default_body = 3;
}
message SwitchCase {
optional Expression const_expression = 1;
optional Statement body = 2;
}