-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblocks-and-statements.ts
More file actions
368 lines (312 loc) · 8.01 KB
/
Copy pathblocks-and-statements.ts
File metadata and controls
368 lines (312 loc) · 8.01 KB
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
import { BaseNode } from "./ast";
import { Identifier, UnannType } from "./classes";
export interface Block extends BaseNode {
kind: "Block";
blockStatements: Array<BlockStatement>;
}
export type BlockStatement =
| LocalVariableDeclarationStatement
| Statement
| ExplicitConstructorInvocation;
export interface ExplicitConstructorInvocation extends BaseNode {
kind: "ExplicitConstructorInvocation";
thisOrSuper: "this" | "super";
argumentList: ArgumentList;
}
export interface LocalVariableDeclarationStatement extends BaseNode {
kind: "LocalVariableDeclarationStatement";
localVariableType: LocalVariableType;
variableDeclaratorList: Array<VariableDeclarator>;
}
export type Statement =
| Block
| StatementWithoutTrailingSubstatement
| IfStatement
| WhileStatement
| ForStatement
| EmptyStatement
| SwitchStatement;
export interface EmptyStatement extends BaseNode {
kind: "EmptyStatement";
}
export interface IfStatement extends BaseNode {
kind: "IfStatement";
condition: Expression;
consequent: Statement;
alternate?: Statement;
}
export interface WhileStatement extends BaseNode {
kind: "WhileStatement";
condition: Expression;
body: Statement;
}
export interface DoStatement extends BaseNode {
kind: "DoStatement";
condition: Expression;
body: Statement;
}
export type ForStatement = BasicForStatement | EnhancedForStatement;
export interface BasicForStatement extends BaseNode {
kind: "BasicForStatement";
forInit: Array<ExpressionStatement> | LocalVariableDeclarationStatement;
condition?: Expression;
forUpdate: Array<ExpressionStatement>;
body: Statement;
}
export interface EnhancedForStatement extends BaseNode {
kind: "EnhancedForStatement";
}
export interface SwitchStatement extends BaseNode {
kind: "SwitchStatement";
expression: Expression; // The expression to evaluate for the switch
cases: Array<SwitchCase>;
}
export interface SwitchCase extends BaseNode {
kind: "SwitchCase";
labels: Array<CaseLabel | DefaultLabel>; // Labels for case blocks
statements?: Array<BlockStatement>; // Statements to execute for the case
}
export type CaseLabel = CaseLiteralLabel | CaseExpressionLabel;
export interface CaseLiteralLabel extends BaseNode {
kind: "CaseLabel";
expression: Literal; // Literal values: byte, short, int, char, or String
}
export interface CaseExpressionLabel extends BaseNode {
kind: "CaseLabel";
expression: Expression; // For future extension if needed
}
export interface DefaultLabel extends BaseNode {
kind: "DefaultLabel"; // Represents the default case
}
export type StatementWithoutTrailingSubstatement =
| Block
| ExpressionStatement
| DoStatement
| ReturnStatement
| BreakStatement
| ContinueStatement
| ThrowStatement
| TryStatement;
export interface ThrowStatement extends BaseNode {
kind: "ThrowStatement";
expression: Expression;
}
export interface CatchClause extends BaseNode {
kind: "CatchClause";
catchFormalParameter: CatchFormalParameter;
block: Block;
}
export interface Catches extends BaseNode {
kind: "Catches";
catchClauses: Array<CatchClause>;
}
export interface CatchFormalParameter extends BaseNode {
kind: "CatchFormalParameter";
catchType: CatchType;
variableDeclaratorId: Identifier;
}
export interface CatchType extends BaseNode {
kind: "CatchType";
unannClassType: UnannType;
}
export interface Finally extends BaseNode {
kind: "Finally";
block: Block;
}
export interface TryStatement extends BaseNode {
kind: "TryStatement";
block: Block;
catches?: Catches;
finally?: Finally;
}
export interface ExpressionStatement extends BaseNode {
kind: "ExpressionStatement";
stmtExp: StatementExpression;
}
export type StatementExpression = MethodInvocation | Assignment | UnaryExpression;
export interface MethodInvocation extends BaseNode {
kind: "MethodInvocation";
identifier: Identifier;
argumentList: ArgumentList;
}
export type ArgumentList = Array<Expression>;
export type LocalVariableType = UnannType;
export interface VariableDeclarator {
kind: "VariableDeclarator";
variableDeclaratorId: VariableDeclaratorId;
dims?: string;
variableInitializer?: VariableInitializer;
}
export type VariableDeclaratorId = Identifier;
export type VariableInitializer = Expression | ArrayInitializer;
export type ArrayInitializer = Array<VariableInitializer>;
export interface ArrayAccess extends BaseNode {
kind: "ArrayAccess";
primary: Primary;
expression: Expression;
}
export interface ReturnStatement extends BaseNode {
kind: "ReturnStatement";
exp: Expression;
}
export type Expression =
| Primary
| BinaryExpression
| UnaryExpression
| TernaryExpression
| Void;
export interface Void extends BaseNode {
kind: "Void";
}
export type Primary =
| Literal
| ExpressionName
| Assignment
| MethodInvocation
| ArrayAccess
| ClassInstanceCreationExpression;
export interface ClassInstanceCreationExpression extends BaseNode {
kind: "ClassInstanceCreationExpression";
identifier: Identifier;
argumentList: ArgumentList;
}
export interface Literal extends BaseNode {
kind: "Literal";
literalType:
| IntegerLiteral
| FloatingPointLiteral
| BooleanLiteral
| CharacterLiteral
| TextBlockLiteral
| StringLiteral
| NullLiteral;
}
export type IntegerLiteral =
| DecimalIntegerLiteral
| HexIntegerLiteral
| OctalIntegerLiteral
| BinaryIntegerLiteral;
export interface DecimalIntegerLiteral {
kind: "DecimalIntegerLiteral";
value: string;
}
export interface HexIntegerLiteral {
kind: "HexIntegerLiteral";
value: string;
}
export interface OctalIntegerLiteral {
kind: "OctalIntegerLiteral";
value: string;
}
export interface BinaryIntegerLiteral {
kind: "BinaryIntegerLiteral";
value: string;
}
export type FloatingPointLiteral =
| DecimalFloatingPointLiteral
| HexadecimalFloatingPointLiteral;
export interface DecimalFloatingPointLiteral {
kind: "DecimalFloatingPointLiteral";
value: string;
}
export interface HexadecimalFloatingPointLiteral {
kind: "HexadecimalFloatingPointLiteral";
value: string;
}
export interface BooleanLiteral {
kind: "BooleanLiteral";
value: "true" | "false";
}
export interface CharacterLiteral {
kind: "CharacterLiteral";
value: string;
}
export type TextBlockLiteral = StringLiteral;
export interface StringLiteral {
kind: "StringLiteral";
value: string;
}
export interface NullLiteral {
kind: "NullLiteral";
value: "null";
}
export type BinaryOperator =
| "+"
| "-"
| "*"
| "/"
| "%"
| "|"
| "&"
| "^"
| "<<"
| ">>"
| ">>>"
| "=="
| "!="
| "<"
| "<="
| ">"
| ">="
| "&&"
| "||";
export interface BinaryExpression extends BaseNode {
kind: "BinaryExpression";
operator: BinaryOperator;
left: Expression;
right: Expression;
}
export interface ExpressionName extends BaseNode {
kind: "ExpressionName";
name: string;
}
export interface Assignment extends BaseNode {
kind: "Assignment";
left: LeftHandSide;
operator:
| "="
| "+="
| "-="
| "*="
| "/="
| "%="
| "|="
| "&="
| "^="
| "<<="
| ">>="
| ">>>=";
right: Expression;
}
export type LeftHandSide = ExpressionName | ArrayAccess;
export type UnaryExpression = PrefixExpression | PostfixExpression | CastExpression;
export interface CastExpression extends BaseNode {
kind: "CastExpression";
castType: Identifier;
expression: Expression;
isPrimitiveCast: boolean;
}
export interface PrefixExpression extends BaseNode {
kind: "PrefixExpression";
operator: "-" | "+" | "++" | "--" | "!" | "~";
expression: Expression;
}
export interface PostfixExpression extends BaseNode {
kind: "PostfixExpression";
operator: "++" | "--";
expression: Expression;
}
export interface BreakStatement extends BaseNode {
kind: "BreakStatement";
identifier?: Identifier;
}
export interface ContinueStatement extends BaseNode {
kind: "ContinueStatement";
identifier?: Identifier;
}
export interface TernaryExpression extends BaseNode {
kind: "TernaryExpression";
condition: Expression;
consequent: Expression;
alternate: Expression;
}