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 | export interface Syn {
|
27 | readonly tag: string;
|
28 | readonly range?: [number, number];
|
29 | readonly loc?: SourceLocation;
|
30 | }
|
31 | export interface Position {
|
32 | readonly line: number;
|
33 | readonly column: number;
|
34 | }
|
35 | export interface SourceLocation {
|
36 | readonly start: Position;
|
37 | readonly end: Position;
|
38 | readonly source?: string | null;
|
39 | }
|
40 | export interface Identifier extends Syn {
|
41 | readonly tag: "Identifier";
|
42 | readonly name: string;
|
43 | }
|
44 | export declare type Type = IntType | BoolType | StringType | CharType | VoidType | PointerType | ArrayType | StructType | Identifier;
|
45 | export interface IntType extends Syn {
|
46 | readonly tag: "IntType";
|
47 | }
|
48 | export interface BoolType extends Syn {
|
49 | readonly tag: "BoolType";
|
50 | }
|
51 | export interface StringType extends Syn {
|
52 | readonly tag: "StringType";
|
53 | }
|
54 | export interface CharType extends Syn {
|
55 | readonly tag: "CharType";
|
56 | }
|
57 | export interface VoidType extends Syn {
|
58 | readonly tag: "VoidType";
|
59 | }
|
60 | export interface PointerType extends Syn {
|
61 | readonly tag: "PointerType";
|
62 | readonly argument: Type;
|
63 | }
|
64 | export interface ArrayType extends Syn {
|
65 | readonly tag: "ArrayType";
|
66 | readonly argument: Type;
|
67 | }
|
68 | export interface StructType extends Syn {
|
69 | readonly tag: "StructType";
|
70 | readonly id: Identifier;
|
71 | }
|
72 | export declare type Expression = Identifier | IntLiteral | StringLiteral | CharLiteral | BoolLiteral | NullLiteral | ArrayMemberExpression | StructMemberExpression | CallExpression | IndirectCallExpression | CastExpression | UnaryExpression | BinaryExpression | LogicalExpression | ConditionalExpression | AllocExpression | AllocArrayExpression | ResultExpression | LengthExpression | HasTagExpression;
|
73 | export interface IntLiteral extends Syn {
|
74 | readonly tag: "IntLiteral";
|
75 | readonly value: number;
|
76 | readonly raw: string;
|
77 | }
|
78 | export interface StringLiteral extends Syn {
|
79 | readonly tag: "StringLiteral";
|
80 | readonly value: string;
|
81 | readonly raw: string;
|
82 | }
|
83 | export interface CharLiteral extends Syn {
|
84 | readonly tag: "CharLiteral";
|
85 | readonly value: string;
|
86 | readonly raw: string;
|
87 | }
|
88 | export interface BoolLiteral extends Syn {
|
89 | readonly tag: "BoolLiteral";
|
90 | readonly value: boolean;
|
91 | }
|
92 | export interface NullLiteral extends Syn {
|
93 | readonly tag: "NullLiteral";
|
94 | }
|
95 |
|
96 |
|
97 |
|
98 | export interface ArrayMemberExpression extends Syn {
|
99 | readonly tag: "ArrayMemberExpression";
|
100 | readonly object: Expression;
|
101 | readonly index: Expression;
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | export interface StructMemberExpression extends Syn {
|
109 | readonly tag: "StructMemberExpression";
|
110 | readonly deref: boolean;
|
111 | readonly object: Expression;
|
112 | readonly field: Identifier;
|
113 | }
|
114 |
|
115 |
|
116 |
|
117 | export interface CallExpression extends Syn {
|
118 | readonly tag: "CallExpression";
|
119 | readonly callee: Identifier;
|
120 | readonly arguments: Expression[];
|
121 | }
|
122 |
|
123 |
|
124 |
|
125 | export interface IndirectCallExpression extends Syn {
|
126 | readonly tag: "IndirectCallExpression";
|
127 | readonly callee: Expression;
|
128 | readonly arguments: Expression[];
|
129 | }
|
130 |
|
131 |
|
132 |
|
133 | export interface CastExpression extends Syn {
|
134 | readonly tag: "CastExpression";
|
135 | readonly kind: Type;
|
136 | readonly argument: Expression;
|
137 | }
|
138 |
|
139 |
|
140 |
|
141 | export interface UnaryExpression extends Syn {
|
142 | readonly tag: "UnaryExpression";
|
143 | readonly operator: "&" | "!" | "~" | "-" | "*";
|
144 | readonly argument: Expression;
|
145 | }
|
146 |
|
147 |
|
148 |
|
149 | export interface BinaryExpression extends Syn {
|
150 | readonly tag: "BinaryExpression";
|
151 | readonly operator: "*" | "/" | "%" | "+" | "-" | "<<" | ">>" | "<" | "<=" | ">=" | ">" | "==" | "!=" | "&" | "^" | "|";
|
152 | readonly left: Expression;
|
153 | readonly right: Expression;
|
154 | }
|
155 |
|
156 |
|
157 |
|
158 | export interface LogicalExpression extends Syn {
|
159 | readonly tag: "LogicalExpression";
|
160 | readonly operator: "||" | "&&";
|
161 | readonly left: Expression;
|
162 | readonly right: Expression;
|
163 | }
|
164 |
|
165 |
|
166 |
|
167 | export interface ConditionalExpression extends Syn {
|
168 | readonly tag: "ConditionalExpression";
|
169 | readonly test: Expression;
|
170 | readonly consequent: Expression;
|
171 | readonly alternate: Expression;
|
172 | }
|
173 |
|
174 |
|
175 |
|
176 | export interface AllocExpression extends Syn {
|
177 | readonly tag: "AllocExpression";
|
178 | readonly kind: Type;
|
179 | }
|
180 |
|
181 |
|
182 |
|
183 | export interface AllocArrayExpression extends Syn {
|
184 | readonly tag: "AllocArrayExpression";
|
185 | readonly kind: Type;
|
186 | readonly size: Expression;
|
187 | }
|
188 |
|
189 |
|
190 |
|
191 | export interface ResultExpression extends Syn {
|
192 | readonly tag: "ResultExpression";
|
193 | }
|
194 |
|
195 |
|
196 |
|
197 | export interface LengthExpression extends Syn {
|
198 | readonly tag: "LengthExpression";
|
199 | readonly argument: Expression;
|
200 | }
|
201 |
|
202 |
|
203 |
|
204 | export interface HasTagExpression extends Syn {
|
205 | readonly tag: "HasTagExpression";
|
206 | readonly kind: Type;
|
207 | readonly argument: Expression;
|
208 | }
|
209 |
|
210 |
|
211 |
|
212 | export declare type LValue = Identifier | StructMemberLValue | DereferenceLValue | ArrayMemberLValue;
|
213 | export interface StructMemberLValue extends StructMemberExpression {
|
214 | readonly object: LValue;
|
215 | }
|
216 | export interface DereferenceLValue extends UnaryExpression {
|
217 | readonly operator: "*";
|
218 | readonly argument: LValue;
|
219 | }
|
220 | export interface ArrayMemberLValue extends ArrayMemberExpression {
|
221 | readonly object: LValue;
|
222 | }
|
223 | export declare type SimpleStatement = AssignmentStatement | UpdateStatement | ExpressionStatement;
|
224 | export declare type Statement = SimpleStatement | VariableDeclaration | IfStatement | WhileStatement | ForStatement | ReturnStatement | BlockStatement | AssertStatement | ErrorStatement | BreakStatement | ContinueStatement;
|
225 | export interface AssignmentStatement extends Syn {
|
226 | readonly tag: "AssignmentStatement";
|
227 | readonly operator: "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "<<=" | ">>=" | "&=" | "^=" | "|=";
|
228 | readonly left: LValue;
|
229 | readonly right: Expression;
|
230 | }
|
231 | export interface UpdateStatement extends Syn {
|
232 | readonly tag: "UpdateStatement";
|
233 | readonly operator: "++" | "--";
|
234 | readonly argument: Expression;
|
235 | }
|
236 | export interface ExpressionStatement extends Syn {
|
237 | readonly tag: "ExpressionStatement";
|
238 | readonly expression: Expression;
|
239 | }
|
240 | export interface VariableDeclaration extends Syn {
|
241 | readonly tag: "VariableDeclaration";
|
242 | readonly kind: Type;
|
243 | readonly id: Identifier;
|
244 | readonly init: Expression | null;
|
245 | }
|
246 | export interface IfStatement extends Syn {
|
247 | readonly tag: "IfStatement";
|
248 | readonly test: Expression;
|
249 | readonly consequent: Statement;
|
250 | readonly alternate?: Statement;
|
251 | }
|
252 | export interface WhileStatement extends Syn {
|
253 | readonly tag: "WhileStatement";
|
254 | readonly invariants: Expression[];
|
255 | readonly test: Expression;
|
256 | readonly body: Statement;
|
257 | }
|
258 | export interface ForStatement extends Syn {
|
259 | readonly tag: "ForStatement";
|
260 | readonly invariants: Expression[];
|
261 | readonly init: SimpleStatement | VariableDeclaration | null;
|
262 | readonly test: Expression;
|
263 | readonly update: SimpleStatement | null;
|
264 | readonly body: Statement;
|
265 | }
|
266 | export interface ReturnStatement extends Syn {
|
267 | readonly tag: "ReturnStatement";
|
268 | readonly argument: Expression | null;
|
269 | }
|
270 | export interface BlockStatement extends Syn {
|
271 | readonly tag: "BlockStatement";
|
272 | readonly body: Statement[];
|
273 | }
|
274 | export interface AssertStatement extends Syn {
|
275 | readonly tag: "AssertStatement";
|
276 | readonly contract: boolean;
|
277 | readonly test: Expression;
|
278 | }
|
279 | export interface ErrorStatement extends Syn {
|
280 | readonly tag: "ErrorStatement";
|
281 | readonly argument: Expression;
|
282 | }
|
283 | export interface BreakStatement extends Syn {
|
284 | readonly tag: "BreakStatement";
|
285 | }
|
286 | export interface ContinueStatement extends Syn {
|
287 | readonly tag: "ContinueStatement";
|
288 | }
|
289 | export declare type Declaration = StructDeclaration | FunctionDeclaration | TypeDefinition | FunctionTypeDefinition | Pragma;
|
290 | export interface StructDeclaration {
|
291 | readonly tag: "StructDeclaration";
|
292 | readonly id: Identifier;
|
293 | readonly definitions: VariableDeclarationOnly[];
|
294 | }
|
295 | export interface VariableDeclarationOnly extends Syn {
|
296 | readonly kind: Type;
|
297 | readonly id: Identifier;
|
298 | }
|
299 | export interface FunctionDeclaration {
|
300 | readonly tag: "FunctionDeclaration";
|
301 | readonly returns: Type;
|
302 | readonly id: Identifier;
|
303 | readonly params: VariableDeclarationOnly[];
|
304 | readonly preconditions: Expression[];
|
305 | readonly postconditions: Expression[];
|
306 | readonly body: null | BlockStatement;
|
307 | }
|
308 | export interface TypeDefinition {
|
309 | readonly tag: "TypeDefinition";
|
310 | readonly definition: VariableDeclarationOnly;
|
311 | }
|
312 | export interface FunctionTypeDefinition {
|
313 | readonly tag: "FunctionTypeDefinition";
|
314 | readonly definition: FunctionDeclaration;
|
315 | }
|
316 | export interface Pragma {
|
317 | readonly tag: "Pragma";
|
318 | readonly pragma: string;
|
319 | readonly contents: string;
|
320 | }
|