VirtualBox

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

Last change on this file since 77807 was 76578, checked in by vboxsync, 6 years ago

Storage: scm --guard-relative-to-dir {parent}

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