VirtualBox

source: vbox/trunk/src/VBox/Storage/testcase/VDScriptAst.h

Last change on this file was 106061, checked in by vboxsync, 3 weeks ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
1/** @file
2 * VBox HDD container test utility - scripting engine, AST related structures.
3 */
4
5/*
6 * Copyright (C) 2013-2024 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 */
38typedef 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. */
48typedef struct VDSRCPOS *PVDSRCPOS;
49
50/**
51 * AST node classes.
52 */
53typedef 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. */
77typedef VDSCRIPTASTCLASS *PVDSCRIPTASTCLASS;
78
79/**
80 * Core AST structure.
81 */
82typedef 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. */
92typedef VDSCRIPTASTCORE *PVDSCRIPTASTCORE;
93
94/** Pointer to an statement node - forward declaration. */
95typedef struct VDSCRIPTASTSTMT *PVDSCRIPTASTSTMT;
96/** Pointer to an expression node - forward declaration. */
97typedef struct VDSCRIPTASTEXPR *PVDSCRIPTASTEXPR;
98
99/**
100 * AST identifier node.
101 */
102typedef 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. */
112typedef VDSCRIPTASTIDE *PVDSCRIPTASTIDE;
113
114/**
115 * Type specifier.
116 */
117typedef 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. */
131typedef VDSCRIPTASTTYPESPECIFIER *PVDSCRIPTASTTYPESPECIFIER;
132
133/**
134 * AST type specifier.
135 */
136typedef 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. */
158typedef VDSCRIPTASTTYPESPEC *PVDSCRIPTASTTYPESPEC;
159
160/**
161 * Storage clase specifier.
162 */
163typedef 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. */
181typedef VDSCRIPTASTSTORAGECLASS *PVDSCRIPTASTSTORAGECLASS;
182
183/**
184 * Type qualifier.
185 */
186typedef 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. */
200typedef VDSCRIPTASTTYPEQUALIFIER *PVDSCRIPTASTTYPEQUALIFIER;
201
202/**
203 * AST type name node.
204 */
205typedef struct VDSCRIPTASTTYPENAME
206{
207 /** Core structure. */
208 VDSCRIPTASTCORE Core;
209} VDSCRIPTASTTYPENAME;
210/** Pointer to a type name node. */
211typedef VDSCRIPTASTTYPENAME *PVDSCRIPTASTTYPENAME;
212
213/**
214 * AST declaration node.
215 */
216typedef struct VDSCRIPTASTDECL
217{
218 /** Core structure. */
219 VDSCRIPTASTCORE Core;
220 /** @todo */
221} VDSCRIPTASTDECL;
222/** Pointer to an declaration node. */
223typedef VDSCRIPTASTDECL *PVDSCRIPTASTDECL;
224
225/**
226 * Expression types.
227 */
228typedef 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. */
332typedef VDSCRIPTEXPRTYPE *PVDSCRIPTEXPRTYPE;
333
334/**
335 * AST expression node.
336 */
337typedef 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 */
396typedef 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. */
406typedef VDSCRIPTASTIF *PVDSCRIPTASTIF;
407
408/**
409 * AST switch node.
410 */
411typedef 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. */
419typedef VDSCRIPTASTSWITCH *PVDSCRIPTASTSWITCH;
420
421/**
422 * AST while or do ... while node.
423 */
424typedef 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. */
434typedef VDSCRIPTASTWHILE *PVDSCRIPTASTWHILE;
435
436/**
437 * AST for node.
438 */
439typedef 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. */
451typedef VDSCRIPTASTFOR *PVDSCRIPTASTFOR;
452
453/**
454 * Statement types.
455 */
456typedef 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. */
486typedef VDSCRIPTSTMTTYPE *PVDSCRIPTSTMTTYPE;
487
488/**
489 * AST statement node.
490 */
491typedef 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 */
534typedef 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. */
544typedef VDSCRIPTASTFNARG *PVDSCRIPTASTFNARG;
545
546/**
547 * AST node describing a function.
548 */
549typedef 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. */
565typedef VDSCRIPTASTFN *PVDSCRIPTASTFN;
566
567/**
568 * Free the given AST node and all subsequent nodes pointed to
569 * by the given node.
570 *
571 * @param pAstNode The AST node to free.
572 */
573DECLHIDDEN(void) vdScriptAstNodeFree(PVDSCRIPTASTCORE pAstNode);
574
575/**
576 * Allocate a non variable in size AST node of the given class.
577 *
578 * @returns Pointer to the allocated node.
579 * NULL if out of memory.
580 * @param enmClass The class of the AST node.
581 */
582DECLHIDDEN(PVDSCRIPTASTCORE) vdScriptAstNodeAlloc(VDSCRIPTASTCLASS enmClass);
583
584/**
585 * Allocate a IDE node which can hold the given number of characters.
586 *
587 * @returns Pointer to the allocated node.
588 * NULL if out of memory.
589 * @param cchIde Number of characters which can be stored in the node.
590 */
591DECLHIDDEN(PVDSCRIPTASTIDE) vdScriptAstNodeIdeAlloc(size_t cchIde);
592
593#endif /* !VBOX_INCLUDED_SRC_testcase_VDScriptAst_h */
594
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette