1 | /** @file
|
---|
2 | * VBox HDD container test utility - scripting engine, AST related structures.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2013-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef VBOX_INCLUDED_SRC_testcase_VDScriptAst_h
|
---|
28 | #define VBOX_INCLUDED_SRC_testcase_VDScriptAst_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/list.h>
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Position information.
|
---|
37 | */
|
---|
38 | typedef struct VDSRCPOS
|
---|
39 | {
|
---|
40 | /** Line in the source. */
|
---|
41 | unsigned iLine;
|
---|
42 | /** Current start character .*/
|
---|
43 | unsigned iChStart;
|
---|
44 | /** Current end character. */
|
---|
45 | unsigned iChEnd;
|
---|
46 | } VDSRCPOS;
|
---|
47 | /** Pointer to a source position. */
|
---|
48 | typedef struct VDSRCPOS *PVDSRCPOS;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * AST node classes.
|
---|
52 | */
|
---|
53 | typedef enum VDSCRIPTASTCLASS
|
---|
54 | {
|
---|
55 | /** Invalid. */
|
---|
56 | VDSCRIPTASTCLASS_INVALID = 0,
|
---|
57 | /** Function node. */
|
---|
58 | VDSCRIPTASTCLASS_FUNCTION,
|
---|
59 | /** Function argument. */
|
---|
60 | VDSCRIPTASTCLASS_FUNCTIONARG,
|
---|
61 | /** Identifier node. */
|
---|
62 | VDSCRIPTASTCLASS_IDENTIFIER,
|
---|
63 | /** Declaration node. */
|
---|
64 | VDSCRIPTASTCLASS_DECLARATION,
|
---|
65 | /** Statement node. */
|
---|
66 | VDSCRIPTASTCLASS_STATEMENT,
|
---|
67 | /** Expression node. */
|
---|
68 | VDSCRIPTASTCLASS_EXPRESSION,
|
---|
69 | /** Type name node. */
|
---|
70 | VDSCRIPTASTCLASS_TYPENAME,
|
---|
71 | /** Type specifier node. */
|
---|
72 | VDSCRIPTASTCLASS_TYPESPECIFIER,
|
---|
73 | /** 32bit blowup. */
|
---|
74 | VDSCRIPTASTCLASS_32BIT_HACK = 0x7fffffff
|
---|
75 | } VDSCRIPTASTCLASS;
|
---|
76 | /** Pointer to an AST node class. */
|
---|
77 | typedef VDSCRIPTASTCLASS *PVDSCRIPTASTCLASS;
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Core AST structure.
|
---|
81 | */
|
---|
82 | typedef struct VDSCRIPTASTCORE
|
---|
83 | {
|
---|
84 | /** The node class, used for verification. */
|
---|
85 | VDSCRIPTASTCLASS enmClass;
|
---|
86 | /** List which might be used. */
|
---|
87 | RTLISTNODE ListNode;
|
---|
88 | /** Position in the source file of this node. */
|
---|
89 | VDSRCPOS Pos;
|
---|
90 | } VDSCRIPTASTCORE;
|
---|
91 | /** Pointer to an AST core structure. */
|
---|
92 | typedef VDSCRIPTASTCORE *PVDSCRIPTASTCORE;
|
---|
93 |
|
---|
94 | /** Pointer to an statement node - forward declaration. */
|
---|
95 | typedef struct VDSCRIPTASTSTMT *PVDSCRIPTASTSTMT;
|
---|
96 | /** Pointer to an expression node - forward declaration. */
|
---|
97 | typedef struct VDSCRIPTASTEXPR *PVDSCRIPTASTEXPR;
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * AST identifier node.
|
---|
101 | */
|
---|
102 | typedef struct VDSCRIPTASTIDE
|
---|
103 | {
|
---|
104 | /** Core structure. */
|
---|
105 | VDSCRIPTASTCORE Core;
|
---|
106 | /** Number of characters in the identifier, excluding the zero terminator. */
|
---|
107 | unsigned cchIde;
|
---|
108 | /** Identifier, variable size. */
|
---|
109 | char aszIde[1];
|
---|
110 | } VDSCRIPTASTIDE;
|
---|
111 | /** Pointer to an identifer node. */
|
---|
112 | typedef VDSCRIPTASTIDE *PVDSCRIPTASTIDE;
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Type specifier.
|
---|
116 | */
|
---|
117 | typedef enum VDSCRIPTASTTYPESPECIFIER
|
---|
118 | {
|
---|
119 | /** Invalid type specifier. */
|
---|
120 | VDSCRIPTASTTYPESPECIFIER_INVALID = 0,
|
---|
121 | /** Union type specifier. */
|
---|
122 | VDSCRIPTASTTYPESPECIFIER_UNION,
|
---|
123 | /** Struct type specifier. */
|
---|
124 | VDSCRIPTASTTYPESPECIFIER_STRUCT,
|
---|
125 | /** Identifier of a typedefed type. */
|
---|
126 | VDSCRIPTASTTYPESPECIFIER_IDE,
|
---|
127 | /** 32bit hack. */
|
---|
128 | VDSCRIPTASTTYPESPECIFIER_32BIT_HACK = 0x7fffffff
|
---|
129 | } VDSCRIPTASTTYPESPECIFIER;
|
---|
130 | /** Pointer to a typespecifier. */
|
---|
131 | typedef VDSCRIPTASTTYPESPECIFIER *PVDSCRIPTASTTYPESPECIFIER;
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * AST type specifier.
|
---|
135 | */
|
---|
136 | typedef struct VDSCRIPTASTTYPESPEC
|
---|
137 | {
|
---|
138 | /** Core structure. */
|
---|
139 | VDSCRIPTASTCORE Core;
|
---|
140 | /** Specifier type. */
|
---|
141 | VDSCRIPTASTTYPESPECIFIER enmType;
|
---|
142 | /** Type dependent data .*/
|
---|
143 | union
|
---|
144 | {
|
---|
145 | /** Pointer to an identifier for typedefed types. */
|
---|
146 | PVDSCRIPTASTIDE pIde;
|
---|
147 | /** struct or union specifier. */
|
---|
148 | struct
|
---|
149 | {
|
---|
150 | /** Pointer to the identifier, optional. */
|
---|
151 | PVDSCRIPTASTIDE pIde;
|
---|
152 | /** Declaration list - VDSCRIPTAST. */
|
---|
153 | RTLISTANCHOR ListDecl;
|
---|
154 | } StructUnion;
|
---|
155 | };
|
---|
156 | } VDSCRIPTASTTYPESPEC;
|
---|
157 | /** Pointer to an AST type specifier. */
|
---|
158 | typedef VDSCRIPTASTTYPESPEC *PVDSCRIPTASTTYPESPEC;
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Storage clase specifier.
|
---|
162 | */
|
---|
163 | typedef enum VDSCRIPTASTSTORAGECLASS
|
---|
164 | {
|
---|
165 | /** Invalid storage class sepcifier. */
|
---|
166 | VDSCRIPTASTSTORAGECLASS_INVALID = 0,
|
---|
167 | /** A typedef type. */
|
---|
168 | VDSCRIPTASTSTORAGECLASS_TYPEDEF,
|
---|
169 | /** An external declared object. */
|
---|
170 | VDSCRIPTASTSTORAGECLASS_EXTERN,
|
---|
171 | /** A static declared object. */
|
---|
172 | VDSCRIPTASTSTORAGECLASS_STATIC,
|
---|
173 | /** Auto object. */
|
---|
174 | VDSCRIPTASTSTORAGECLASS_AUTO,
|
---|
175 | /** Object should be stored in a register. */
|
---|
176 | VDSCRIPTASTSTORAGECLASS_REGISTER,
|
---|
177 | /** 32bit hack. */
|
---|
178 | VDSCRIPTASTSTORAGECLASS_32BIT_HACK = 0x7fffffff
|
---|
179 | } VDSCRIPTASTSTORAGECLASS;
|
---|
180 | /** Pointer to a storage class. */
|
---|
181 | typedef VDSCRIPTASTSTORAGECLASS *PVDSCRIPTASTSTORAGECLASS;
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Type qualifier.
|
---|
185 | */
|
---|
186 | typedef enum VDSCRIPTASTTYPEQUALIFIER
|
---|
187 | {
|
---|
188 | /** Invalid type qualifier. */
|
---|
189 | VDSCRIPTASTTYPEQUALIFIER_INVALID = 0,
|
---|
190 | /** Const type qualifier. */
|
---|
191 | VDSCRIPTASTTYPEQUALIFIER_CONST,
|
---|
192 | /** Restrict type qualifier. */
|
---|
193 | VDSCRIPTASTTYPEQUALIFIER_RESTRICT,
|
---|
194 | /** Volatile type qualifier. */
|
---|
195 | VDSCRIPTASTTYPEQUALIFIER_VOLATILE,
|
---|
196 | /** 32bit hack. */
|
---|
197 | VDSCRIPTASTTYPEQUALIFIER_32BIT_HACK = 0x7fffffff
|
---|
198 | } VDSCRIPTASTTYPEQUALIFIER;
|
---|
199 | /** Pointer to a type qualifier. */
|
---|
200 | typedef VDSCRIPTASTTYPEQUALIFIER *PVDSCRIPTASTTYPEQUALIFIER;
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * AST type name node.
|
---|
204 | */
|
---|
205 | typedef struct VDSCRIPTASTTYPENAME
|
---|
206 | {
|
---|
207 | /** Core structure. */
|
---|
208 | VDSCRIPTASTCORE Core;
|
---|
209 | } VDSCRIPTASTTYPENAME;
|
---|
210 | /** Pointer to a type name node. */
|
---|
211 | typedef VDSCRIPTASTTYPENAME *PVDSCRIPTASTTYPENAME;
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * AST declaration node.
|
---|
215 | */
|
---|
216 | typedef struct VDSCRIPTASTDECL
|
---|
217 | {
|
---|
218 | /** Core structure. */
|
---|
219 | VDSCRIPTASTCORE Core;
|
---|
220 | /** @todo */
|
---|
221 | } VDSCRIPTASTDECL;
|
---|
222 | /** Pointer to an declaration node. */
|
---|
223 | typedef VDSCRIPTASTDECL *PVDSCRIPTASTDECL;
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * Expression types.
|
---|
227 | */
|
---|
228 | typedef enum VDSCRIPTEXPRTYPE
|
---|
229 | {
|
---|
230 | /** Invalid. */
|
---|
231 | VDSCRIPTEXPRTYPE_INVALID = 0,
|
---|
232 | /** Numerical constant. */
|
---|
233 | VDSCRIPTEXPRTYPE_PRIMARY_NUMCONST,
|
---|
234 | /** String constant. */
|
---|
235 | VDSCRIPTEXPRTYPE_PRIMARY_STRINGCONST,
|
---|
236 | /** Boolean constant. */
|
---|
237 | VDSCRIPTEXPRTYPE_PRIMARY_BOOLEAN,
|
---|
238 | /** Identifier. */
|
---|
239 | VDSCRIPTEXPRTYPE_PRIMARY_IDENTIFIER,
|
---|
240 | /** List of assignment expressions as in a = b = c = ... . */
|
---|
241 | VDSCRIPTEXPRTYPE_ASSIGNMENT_LIST,
|
---|
242 | /** Postfix increment expression. */
|
---|
243 | VDSCRIPTEXPRTYPE_POSTFIX_INCREMENT,
|
---|
244 | /** Postfix decrement expression. */
|
---|
245 | VDSCRIPTEXPRTYPE_POSTFIX_DECREMENT,
|
---|
246 | /** Postfix function call expression. */
|
---|
247 | VDSCRIPTEXPRTYPE_POSTFIX_FNCALL,
|
---|
248 | /** Postfix dereference expression. */
|
---|
249 | VDSCRIPTEXPRTYPE_POSTFIX_DEREFERENCE,
|
---|
250 | /** Dot operator (@todo: Is there a better name for it?). */
|
---|
251 | VDSCRIPTEXPRTYPE_POSTFIX_DOT,
|
---|
252 | /** Unary increment expression. */
|
---|
253 | VDSCRIPTEXPRTYPE_UNARY_INCREMENT,
|
---|
254 | /** Unary decrement expression. */
|
---|
255 | VDSCRIPTEXPRTYPE_UNARY_DECREMENT,
|
---|
256 | /** Unary positive sign expression. */
|
---|
257 | VDSCRIPTEXPRTYPE_UNARY_POSSIGN,
|
---|
258 | /** Unary negtive sign expression. */
|
---|
259 | VDSCRIPTEXPRTYPE_UNARY_NEGSIGN,
|
---|
260 | /** Unary invert expression. */
|
---|
261 | VDSCRIPTEXPRTYPE_UNARY_INVERT,
|
---|
262 | /** Unary negate expression. */
|
---|
263 | VDSCRIPTEXPRTYPE_UNARY_NEGATE,
|
---|
264 | /** Unary reference expression. */
|
---|
265 | VDSCRIPTEXPRTYPE_UNARY_REFERENCE,
|
---|
266 | /** Unary dereference expression. */
|
---|
267 | VDSCRIPTEXPRTYPE_UNARY_DEREFERENCE,
|
---|
268 | /** Cast expression. */
|
---|
269 | VDSCRIPTEXPRTYPE_CAST,
|
---|
270 | /** Multiplicative expression. */
|
---|
271 | VDSCRIPTEXPRTYPE_MULTIPLICATION,
|
---|
272 | /** Division expression. */
|
---|
273 | VDSCRIPTEXPRTYPE_DIVISION,
|
---|
274 | /** Modulus expression. */
|
---|
275 | VDSCRIPTEXPRTYPE_MODULUS,
|
---|
276 | /** Addition expression. */
|
---|
277 | VDSCRIPTEXPRTYPE_ADDITION,
|
---|
278 | /** Subtraction expression. */
|
---|
279 | VDSCRIPTEXPRTYPE_SUBTRACTION,
|
---|
280 | /** Logical shift right. */
|
---|
281 | VDSCRIPTEXPRTYPE_LSR,
|
---|
282 | /** Logical shift left. */
|
---|
283 | VDSCRIPTEXPRTYPE_LSL,
|
---|
284 | /** Lower than expression */
|
---|
285 | VDSCRIPTEXPRTYPE_LOWER,
|
---|
286 | /** Higher than expression */
|
---|
287 | VDSCRIPTEXPRTYPE_HIGHER,
|
---|
288 | /** Lower or equal than expression */
|
---|
289 | VDSCRIPTEXPRTYPE_LOWEREQUAL,
|
---|
290 | /** Higher or equal than expression */
|
---|
291 | VDSCRIPTEXPRTYPE_HIGHEREQUAL,
|
---|
292 | /** Equals expression */
|
---|
293 | VDSCRIPTEXPRTYPE_EQUAL,
|
---|
294 | /** Not equal expression */
|
---|
295 | VDSCRIPTEXPRTYPE_NOTEQUAL,
|
---|
296 | /** Bitwise and expression */
|
---|
297 | VDSCRIPTEXPRTYPE_BITWISE_AND,
|
---|
298 | /** Bitwise xor expression */
|
---|
299 | VDSCRIPTEXPRTYPE_BITWISE_XOR,
|
---|
300 | /** Bitwise or expression */
|
---|
301 | VDSCRIPTEXPRTYPE_BITWISE_OR,
|
---|
302 | /** Logical and expression */
|
---|
303 | VDSCRIPTEXPRTYPE_LOGICAL_AND,
|
---|
304 | /** Logical or expression */
|
---|
305 | VDSCRIPTEXPRTYPE_LOGICAL_OR,
|
---|
306 | /** Assign expression */
|
---|
307 | VDSCRIPTEXPRTYPE_ASSIGN,
|
---|
308 | /** Multiplicative assign expression */
|
---|
309 | VDSCRIPTEXPRTYPE_ASSIGN_MULT,
|
---|
310 | /** Division assign expression */
|
---|
311 | VDSCRIPTEXPRTYPE_ASSIGN_DIV,
|
---|
312 | /** Modulus assign expression */
|
---|
313 | VDSCRIPTEXPRTYPE_ASSIGN_MOD,
|
---|
314 | /** Additive assign expression */
|
---|
315 | VDSCRIPTEXPRTYPE_ASSIGN_ADD,
|
---|
316 | /** Subtractive assign expression */
|
---|
317 | VDSCRIPTEXPRTYPE_ASSIGN_SUB,
|
---|
318 | /** Bitwise left shift assign expression */
|
---|
319 | VDSCRIPTEXPRTYPE_ASSIGN_LSL,
|
---|
320 | /** Bitwise right shift assign expression */
|
---|
321 | VDSCRIPTEXPRTYPE_ASSIGN_LSR,
|
---|
322 | /** Bitwise and assign expression */
|
---|
323 | VDSCRIPTEXPRTYPE_ASSIGN_AND,
|
---|
324 | /** Bitwise xor assign expression */
|
---|
325 | VDSCRIPTEXPRTYPE_ASSIGN_XOR,
|
---|
326 | /** Bitwise or assign expression */
|
---|
327 | VDSCRIPTEXPRTYPE_ASSIGN_OR,
|
---|
328 | /** 32bit hack. */
|
---|
329 | VDSCRIPTEXPRTYPE_32BIT_HACK = 0x7fffffff
|
---|
330 | } VDSCRIPTEXPRTYPE;
|
---|
331 | /** Pointer to an expression type. */
|
---|
332 | typedef VDSCRIPTEXPRTYPE *PVDSCRIPTEXPRTYPE;
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * AST expression node.
|
---|
336 | */
|
---|
337 | typedef struct VDSCRIPTASTEXPR
|
---|
338 | {
|
---|
339 | /** Core structure. */
|
---|
340 | VDSCRIPTASTCORE Core;
|
---|
341 | /** Expression type. */
|
---|
342 | VDSCRIPTEXPRTYPE enmType;
|
---|
343 | /** Expression type dependent data. */
|
---|
344 | union
|
---|
345 | {
|
---|
346 | /** Numerical constant. */
|
---|
347 | uint64_t u64;
|
---|
348 | /** Primary identifier. */
|
---|
349 | PVDSCRIPTASTIDE pIde;
|
---|
350 | /** String literal */
|
---|
351 | const char *pszStr;
|
---|
352 | /** Boolean constant. */
|
---|
353 | bool f;
|
---|
354 | /** List of expressions - VDSCRIPTASTEXPR. */
|
---|
355 | RTLISTANCHOR ListExpr;
|
---|
356 | /** Pointer to another expression. */
|
---|
357 | PVDSCRIPTASTEXPR pExpr;
|
---|
358 | /** Function call expression. */
|
---|
359 | struct
|
---|
360 | {
|
---|
361 | /** Other postfix expression used as the identifier for the function. */
|
---|
362 | PVDSCRIPTASTEXPR pFnIde;
|
---|
363 | /** Argument list if existing. */
|
---|
364 | RTLISTANCHOR ListArgs;
|
---|
365 | } FnCall;
|
---|
366 | /** Binary operation. */
|
---|
367 | struct
|
---|
368 | {
|
---|
369 | /** Left operator. */
|
---|
370 | PVDSCRIPTASTEXPR pLeftExpr;
|
---|
371 | /** Right operator. */
|
---|
372 | PVDSCRIPTASTEXPR pRightExpr;
|
---|
373 | } BinaryOp;
|
---|
374 | /** Dereference or dot operation. */
|
---|
375 | struct
|
---|
376 | {
|
---|
377 | /** The identifier to access. */
|
---|
378 | PVDSCRIPTASTIDE pIde;
|
---|
379 | /** Postfix expression coming after this. */
|
---|
380 | PVDSCRIPTASTEXPR pExpr;
|
---|
381 | } Deref;
|
---|
382 | /** Cast expression. */
|
---|
383 | struct
|
---|
384 | {
|
---|
385 | /** Type name. */
|
---|
386 | PVDSCRIPTASTTYPENAME pTypeName;
|
---|
387 | /** Following cast expression. */
|
---|
388 | PVDSCRIPTASTEXPR pExpr;
|
---|
389 | } Cast;
|
---|
390 | };
|
---|
391 | } VDSCRIPTASTEXPR;
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * AST if node.
|
---|
395 | */
|
---|
396 | typedef struct VDSCRIPTASTIF
|
---|
397 | {
|
---|
398 | /** Conditional expression. */
|
---|
399 | PVDSCRIPTASTEXPR pCond;
|
---|
400 | /** The true branch */
|
---|
401 | PVDSCRIPTASTSTMT pTrueStmt;
|
---|
402 | /** The else branch, can be NULL if no else branch. */
|
---|
403 | PVDSCRIPTASTSTMT pElseStmt;
|
---|
404 | } VDSCRIPTASTIF;
|
---|
405 | /** Pointer to an expression node. */
|
---|
406 | typedef VDSCRIPTASTIF *PVDSCRIPTASTIF;
|
---|
407 |
|
---|
408 | /**
|
---|
409 | * AST switch node.
|
---|
410 | */
|
---|
411 | typedef struct VDSCRIPTASTSWITCH
|
---|
412 | {
|
---|
413 | /** Conditional expression. */
|
---|
414 | PVDSCRIPTASTEXPR pCond;
|
---|
415 | /** The statement to follow. */
|
---|
416 | PVDSCRIPTASTSTMT pStmt;
|
---|
417 | } VDSCRIPTASTSWITCH;
|
---|
418 | /** Pointer to an expression node. */
|
---|
419 | typedef VDSCRIPTASTSWITCH *PVDSCRIPTASTSWITCH;
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * AST while or do ... while node.
|
---|
423 | */
|
---|
424 | typedef struct VDSCRIPTASTWHILE
|
---|
425 | {
|
---|
426 | /** Flag whether this is a do while loop. */
|
---|
427 | bool fDoWhile;
|
---|
428 | /** Conditional expression. */
|
---|
429 | PVDSCRIPTASTEXPR pCond;
|
---|
430 | /** The statement to follow. */
|
---|
431 | PVDSCRIPTASTSTMT pStmt;
|
---|
432 | } VDSCRIPTASTWHILE;
|
---|
433 | /** Pointer to an expression node. */
|
---|
434 | typedef VDSCRIPTASTWHILE *PVDSCRIPTASTWHILE;
|
---|
435 |
|
---|
436 | /**
|
---|
437 | * AST for node.
|
---|
438 | */
|
---|
439 | typedef struct VDSCRIPTASTFOR
|
---|
440 | {
|
---|
441 | /** Initializer expression. */
|
---|
442 | PVDSCRIPTASTEXPR pExprStart;
|
---|
443 | /** The exit condition. */
|
---|
444 | PVDSCRIPTASTEXPR pExprCond;
|
---|
445 | /** The third expression (normally used to increase/decrease loop variable). */
|
---|
446 | PVDSCRIPTASTEXPR pExpr3;
|
---|
447 | /** The for loop body. */
|
---|
448 | PVDSCRIPTASTSTMT pStmt;
|
---|
449 | } VDSCRIPTASTFOR;
|
---|
450 | /** Pointer to an expression node. */
|
---|
451 | typedef VDSCRIPTASTFOR *PVDSCRIPTASTFOR;
|
---|
452 |
|
---|
453 | /**
|
---|
454 | * Statement types.
|
---|
455 | */
|
---|
456 | typedef enum VDSCRIPTSTMTTYPE
|
---|
457 | {
|
---|
458 | /** Invalid. */
|
---|
459 | VDSCRIPTSTMTTYPE_INVALID = 0,
|
---|
460 | /** Compound statement. */
|
---|
461 | VDSCRIPTSTMTTYPE_COMPOUND,
|
---|
462 | /** Expression statement. */
|
---|
463 | VDSCRIPTSTMTTYPE_EXPRESSION,
|
---|
464 | /** if statement. */
|
---|
465 | VDSCRIPTSTMTTYPE_IF,
|
---|
466 | /** switch statement. */
|
---|
467 | VDSCRIPTSTMTTYPE_SWITCH,
|
---|
468 | /** while statement. */
|
---|
469 | VDSCRIPTSTMTTYPE_WHILE,
|
---|
470 | /** for statement. */
|
---|
471 | VDSCRIPTSTMTTYPE_FOR,
|
---|
472 | /** continue statement. */
|
---|
473 | VDSCRIPTSTMTTYPE_CONTINUE,
|
---|
474 | /** break statement. */
|
---|
475 | VDSCRIPTSTMTTYPE_BREAK,
|
---|
476 | /** return statement. */
|
---|
477 | VDSCRIPTSTMTTYPE_RETURN,
|
---|
478 | /** case statement. */
|
---|
479 | VDSCRIPTSTMTTYPE_CASE,
|
---|
480 | /** default statement. */
|
---|
481 | VDSCRIPTSTMTTYPE_DEFAULT,
|
---|
482 | /** 32bit hack. */
|
---|
483 | VDSCRIPTSTMTTYPE_32BIT_HACK = 0x7fffffff
|
---|
484 | } VDSCRIPTSTMTTYPE;
|
---|
485 | /** Pointer to a statement type. */
|
---|
486 | typedef VDSCRIPTSTMTTYPE *PVDSCRIPTSTMTTYPE;
|
---|
487 |
|
---|
488 | /**
|
---|
489 | * AST statement node.
|
---|
490 | */
|
---|
491 | typedef struct VDSCRIPTASTSTMT
|
---|
492 | {
|
---|
493 | /** Core structure. */
|
---|
494 | VDSCRIPTASTCORE Core;
|
---|
495 | /** Statement type */
|
---|
496 | VDSCRIPTSTMTTYPE enmStmtType;
|
---|
497 | /** Statement type dependent data. */
|
---|
498 | union
|
---|
499 | {
|
---|
500 | /** Compound statement. */
|
---|
501 | struct
|
---|
502 | {
|
---|
503 | /** List of declarations - VDSCRIPTASTDECL. */
|
---|
504 | RTLISTANCHOR ListDecls;
|
---|
505 | /** List of statements - VDSCRIPTASTSTMT. */
|
---|
506 | RTLISTANCHOR ListStmts;
|
---|
507 | } Compound;
|
---|
508 | /** case, default statement. */
|
---|
509 | struct
|
---|
510 | {
|
---|
511 | /** Pointer to the expression. */
|
---|
512 | PVDSCRIPTASTEXPR pExpr;
|
---|
513 | /** Pointer to the statement. */
|
---|
514 | PVDSCRIPTASTSTMT pStmt;
|
---|
515 | } Case;
|
---|
516 | /** "if" statement. */
|
---|
517 | VDSCRIPTASTIF If;
|
---|
518 | /** "switch" statement. */
|
---|
519 | VDSCRIPTASTSWITCH Switch;
|
---|
520 | /** "while" or "do ... while" loop. */
|
---|
521 | VDSCRIPTASTWHILE While;
|
---|
522 | /** "for" loop. */
|
---|
523 | VDSCRIPTASTFOR For;
|
---|
524 | /** Pointer to another statement. */
|
---|
525 | PVDSCRIPTASTSTMT pStmt;
|
---|
526 | /** Expression statement. */
|
---|
527 | PVDSCRIPTASTEXPR pExpr;
|
---|
528 | };
|
---|
529 | } VDSCRIPTASTSTMT;
|
---|
530 |
|
---|
531 | /**
|
---|
532 | * AST node for one function argument.
|
---|
533 | */
|
---|
534 | typedef struct VDSCRIPTASTFNARG
|
---|
535 | {
|
---|
536 | /** Core structure. */
|
---|
537 | VDSCRIPTASTCORE Core;
|
---|
538 | /** Identifier describing the type of the argument. */
|
---|
539 | PVDSCRIPTASTIDE pType;
|
---|
540 | /** The name of the argument. */
|
---|
541 | PVDSCRIPTASTIDE pArgIde;
|
---|
542 | } VDSCRIPTASTFNARG;
|
---|
543 | /** Pointer to a AST function argument node. */
|
---|
544 | typedef VDSCRIPTASTFNARG *PVDSCRIPTASTFNARG;
|
---|
545 |
|
---|
546 | /**
|
---|
547 | * AST node describing a function.
|
---|
548 | */
|
---|
549 | typedef struct VDSCRIPTASTFN
|
---|
550 | {
|
---|
551 | /** Core structure. */
|
---|
552 | VDSCRIPTASTCORE Core;
|
---|
553 | /** Identifier describing the return type. */
|
---|
554 | PVDSCRIPTASTIDE pRetType;
|
---|
555 | /** Name of the function. */
|
---|
556 | PVDSCRIPTASTIDE pFnIde;
|
---|
557 | /** Number of arguments in the list. */
|
---|
558 | unsigned cArgs;
|
---|
559 | /** Argument list - VDSCRIPTASTFNARG. */
|
---|
560 | RTLISTANCHOR ListArgs;
|
---|
561 | /** Compound statement node. */
|
---|
562 | PVDSCRIPTASTSTMT pCompoundStmts;
|
---|
563 | } VDSCRIPTASTFN;
|
---|
564 | /** Pointer to a function AST node. */
|
---|
565 | typedef VDSCRIPTASTFN *PVDSCRIPTASTFN;
|
---|
566 |
|
---|
567 | /**
|
---|
568 | * Free the given AST node and all subsequent nodes pointed to
|
---|
569 | * by the given node.
|
---|
570 | *
|
---|
571 | * @returns nothing.
|
---|
572 | * @param pAstNode The AST node to free.
|
---|
573 | */
|
---|
574 | DECLHIDDEN(void) vdScriptAstNodeFree(PVDSCRIPTASTCORE pAstNode);
|
---|
575 |
|
---|
576 | /**
|
---|
577 | * Allocate a non variable in size AST node of the given class.
|
---|
578 | *
|
---|
579 | * @returns Pointer to the allocated node.
|
---|
580 | * NULL if out of memory.
|
---|
581 | * @param enmClass The class of the AST node.
|
---|
582 | */
|
---|
583 | DECLHIDDEN(PVDSCRIPTASTCORE) vdScriptAstNodeAlloc(VDSCRIPTASTCLASS enmClass);
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * Allocate a IDE node which can hold the given number of characters.
|
---|
587 | *
|
---|
588 | * @returns Pointer to the allocated node.
|
---|
589 | * NULL if out of memory.
|
---|
590 | * @param cchIde Number of characters which can be stored in the node.
|
---|
591 | */
|
---|
592 | DECLHIDDEN(PVDSCRIPTASTIDE) vdScriptAstNodeIdeAlloc(size_t cchIde);
|
---|
593 |
|
---|
594 | #endif /* !VBOX_INCLUDED_SRC_testcase_VDScriptAst_h */
|
---|
595 |
|
---|