VirtualBox

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

Last change on this file since 49439 was 44941, checked in by vboxsync, 12 years ago

Storage/testcase: More scripting language work

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1/** @file
2 *
3 * VBox HDD container test utility - scripting engine, AST related structures.
4 */
5
6/*
7 * Copyright (C) 2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17#ifndef _VDScriptAst_h__
18#define _VDScriptAst_h__
19
20#include <iprt/list.h>
21
22/**
23 * Position information.
24 */
25typedef struct VDSRCPOS
26{
27 /** Line in the source. */
28 unsigned iLine;
29 /** Current start character .*/
30 unsigned iChStart;
31 /** Current end character. */
32 unsigned iChEnd;
33} VDSRCPOS;
34/** Pointer to a source position. */
35typedef struct VDSRCPOS *PVDSRCPOS;
36
37/**
38 * AST node classes.
39 */
40typedef enum VDSCRIPTASTCLASS
41{
42 /** Invalid. */
43 VDSCRIPTASTCLASS_INVALID = 0,
44 /** Function node. */
45 VDSCRIPTASTCLASS_FUNCTION,
46 /** Function argument. */
47 VDSCRIPTASTCLASS_FUNCTIONARG,
48 /** Identifier node. */
49 VDSCRIPTASTCLASS_IDENTIFIER,
50 /** Declaration node. */
51 VDSCRIPTASTCLASS_DECLARATION,
52 /** Statement node. */
53 VDSCRIPTASTCLASS_STATEMENT,
54 /** Expression node. */
55 VDSCRIPTASTCLASS_EXPRESSION,
56 /** 32bit blowup. */
57 VDSCRIPTASTCLASS_32BIT_HACK = 0x7fffffff
58} VDSCRIPTASTCLASS;
59/** Pointer to an AST node class. */
60typedef VDSCRIPTASTCLASS *PVDSCRIPTASTCLASS;
61
62/**
63 * Core AST structure.
64 */
65typedef struct VDSCRIPTASTCORE
66{
67 /** The node class, used for verification. */
68 VDSCRIPTASTCLASS enmClass;
69 /** List which might be used. */
70 RTLISTNODE ListNode;
71 /** Position in the source file of this node. */
72 VDSRCPOS Pos;
73} VDSCRIPTASTCORE;
74/** Pointer to an AST core structure. */
75typedef VDSCRIPTASTCORE *PVDSCRIPTASTCORE;
76
77/** Pointer to an statement node - forward declaration. */
78typedef struct VDSCRIPTASTSTMT *PVDSCRIPTASTSTMT;
79/** Pointer to an expression node - forward declaration. */
80typedef struct VDSCRIPTASTEXPR *PVDSCRIPTASTEXPR;
81
82/**
83 * AST identifier node.
84 */
85typedef struct VDSCRIPTASTIDE
86{
87 /** Core structure. */
88 VDSCRIPTASTCORE Core;
89 /** Number of characters in the identifier, excluding the zero terminator. */
90 unsigned cchIde;
91 /** Identifier, variable size. */
92 char aszIde[1];
93} VDSCRIPTASTIDE;
94/** Pointer to an identifer node. */
95typedef VDSCRIPTASTIDE *PVDSCRIPTASTIDE;
96
97/**
98 * AST declaration node.
99 */
100typedef struct VDSCRIPTASTDECL
101{
102 /** Core structure. */
103 VDSCRIPTASTCORE Core;
104 /** @todo */
105} VDSCRIPTASTDECL;
106/** Pointer to an declaration node. */
107typedef VDSCRIPTASTDECL *PVDSCRIPTASTDECL;
108
109/**
110 * Expression types.
111 */
112typedef enum VDSCRIPTEXPRTYPE
113{
114 /** Invalid. */
115 VDSCRIPTEXPRTYPE_INVALID = 0,
116 /** Numerical constant. */
117 VDSCRIPTEXPRTYPE_PRIMARY_NUMCONST,
118 /** String constant. */
119 VDSCRIPTEXPRTYPE_PRIMARY_STRINGCONST,
120 /** Boolean constant. */
121 VDSCRIPTEXPRTYPE_PRIMARY_BOOLEAN,
122 /** Identifier. */
123 VDSCRIPTEXPRTYPE_PRIMARY_IDENTIFIER,
124 /** List of assignment expressions as in a = b = c = ... . */
125 VDSCRIPTEXPRTYPE_ASSIGNMENT_LIST,
126 /** Postfix increment expression. */
127 VDSCRIPTEXPRTYPE_POSTFIX_INCREMENT,
128 /** Postfix decrement expression. */
129 VDSCRIPTEXPRTYPE_POSTFIX_DECREMENT,
130 /** Postfix function call expression. */
131 VDSCRIPTEXPRTYPE_POSTFIX_FNCALL,
132 /** Unary increment expression. */
133 VDSCRIPTEXPRTYPE_UNARY_INCREMENT,
134 /** Unary decrement expression. */
135 VDSCRIPTEXPRTYPE_UNARY_DECREMENT,
136 /** Unary positive sign expression. */
137 VDSCRIPTEXPRTYPE_UNARY_POSSIGN,
138 /** Unary negtive sign expression. */
139 VDSCRIPTEXPRTYPE_UNARY_NEGSIGN,
140 /** Unary invert expression. */
141 VDSCRIPTEXPRTYPE_UNARY_INVERT,
142 /** Unary negate expression. */
143 VDSCRIPTEXPRTYPE_UNARY_NEGATE,
144 /** Multiplicative expression. */
145 VDSCRIPTEXPRTYPE_MULTIPLICATION,
146 /** Division expression. */
147 VDSCRIPTEXPRTYPE_DIVISION,
148 /** Modulus expression. */
149 VDSCRIPTEXPRTYPE_MODULUS,
150 /** Addition expression. */
151 VDSCRIPTEXPRTYPE_ADDITION,
152 /** Subtraction expression. */
153 VDSCRIPTEXPRTYPE_SUBTRACTION,
154 /** Logical shift right. */
155 VDSCRIPTEXPRTYPE_LSR,
156 /** Logical shift left. */
157 VDSCRIPTEXPRTYPE_LSL,
158 /** Lower than expression */
159 VDSCRIPTEXPRTYPE_LOWER,
160 /** Higher than expression */
161 VDSCRIPTEXPRTYPE_HIGHER,
162 /** Lower or equal than expression */
163 VDSCRIPTEXPRTYPE_LOWEREQUAL,
164 /** Higher or equal than expression */
165 VDSCRIPTEXPRTYPE_HIGHEREQUAL,
166 /** Equals expression */
167 VDSCRIPTEXPRTYPE_EQUAL,
168 /** Not equal expression */
169 VDSCRIPTEXPRTYPE_NOTEQUAL,
170 /** Bitwise and expression */
171 VDSCRIPTEXPRTYPE_BITWISE_AND,
172 /** Bitwise xor expression */
173 VDSCRIPTEXPRTYPE_BITWISE_XOR,
174 /** Bitwise or expression */
175 VDSCRIPTEXPRTYPE_BITWISE_OR,
176 /** Logical and expression */
177 VDSCRIPTEXPRTYPE_LOGICAL_AND,
178 /** Logical or expression */
179 VDSCRIPTEXPRTYPE_LOGICAL_OR,
180 /** Assign expression */
181 VDSCRIPTEXPRTYPE_ASSIGN,
182 /** Multiplicative assign expression */
183 VDSCRIPTEXPRTYPE_ASSIGN_MULT,
184 /** Division assign expression */
185 VDSCRIPTEXPRTYPE_ASSIGN_DIV,
186 /** Modulus assign expression */
187 VDSCRIPTEXPRTYPE_ASSIGN_MOD,
188 /** Additive assign expression */
189 VDSCRIPTEXPRTYPE_ASSIGN_ADD,
190 /** Subtractive assign expression */
191 VDSCRIPTEXPRTYPE_ASSIGN_SUB,
192 /** Bitwise left shift assign expression */
193 VDSCRIPTEXPRTYPE_ASSIGN_LSL,
194 /** Bitwise right shift assign expression */
195 VDSCRIPTEXPRTYPE_ASSIGN_LSR,
196 /** Bitwise and assign expression */
197 VDSCRIPTEXPRTYPE_ASSIGN_AND,
198 /** Bitwise xor assign expression */
199 VDSCRIPTEXPRTYPE_ASSIGN_XOR,
200 /** Bitwise or assign expression */
201 VDSCRIPTEXPRTYPE_ASSIGN_OR,
202 /** 32bit hack. */
203 VDSCRIPTEXPRTYPE_32BIT_HACK = 0x7fffffff
204} VDSCRIPTEXPRTYPE;
205/** Pointer to an expression type. */
206typedef VDSCRIPTEXPRTYPE *PVDSCRIPTEXPRTYPE;
207
208/**
209 * AST expression node.
210 */
211typedef struct VDSCRIPTASTEXPR
212{
213 /** Core structure. */
214 VDSCRIPTASTCORE Core;
215 /** Expression type. */
216 VDSCRIPTEXPRTYPE enmType;
217 /** Expression type dependent data. */
218 union
219 {
220 /** Numerical constant. */
221 uint64_t u64;
222 /** Primary identifier. */
223 PVDSCRIPTASTIDE pIde;
224 /** String literal */
225 const char *pszStr;
226 /** Boolean constant. */
227 bool f;
228 /** List of expressions - VDSCRIPTASTEXPR. */
229 RTLISTANCHOR ListExpr;
230 /** Pointer to another expression. */
231 PVDSCRIPTASTEXPR pExpr;
232 /** Function call expression. */
233 struct
234 {
235 /** Other postfix expression used as the identifier for the function. */
236 PVDSCRIPTASTEXPR pFnIde;
237 /** Argument list if existing. */
238 RTLISTANCHOR ListArgs;
239 } FnCall;
240 /** Binary operation. */
241 struct
242 {
243 /** Left operator. */
244 PVDSCRIPTASTEXPR pLeftExpr;
245 /** Right operator. */
246 PVDSCRIPTASTEXPR pRightExpr;
247 } BinaryOp;
248 };
249} VDSCRIPTASTEXPR;
250
251/**
252 * AST if node.
253 */
254typedef struct VDSCRIPTASTIF
255{
256 /** Conditional expression. */
257 PVDSCRIPTASTEXPR pCond;
258 /** The true branch */
259 PVDSCRIPTASTSTMT pTrueStmt;
260 /** The else branch, can be NULL if no else branch. */
261 PVDSCRIPTASTSTMT pElseStmt;
262} VDSCRIPTASTIF;
263/** Pointer to an expression node. */
264typedef VDSCRIPTASTIF *PVDSCRIPTASTIF;
265
266/**
267 * AST switch node.
268 */
269typedef struct VDSCRIPTASTSWITCH
270{
271 /** Conditional expression. */
272 PVDSCRIPTASTEXPR pCond;
273 /** The statement to follow. */
274 PVDSCRIPTASTSTMT pStmt;
275} VDSCRIPTASTSWITCH;
276/** Pointer to an expression node. */
277typedef VDSCRIPTASTSWITCH *PVDSCRIPTASTSWITCH;
278
279/**
280 * AST while or do ... while node.
281 */
282typedef struct VDSCRIPTASTWHILE
283{
284 /** Flag whether this is a do while loop. */
285 bool fDoWhile;
286 /** Conditional expression. */
287 PVDSCRIPTASTEXPR pCond;
288 /** The statement to follow. */
289 PVDSCRIPTASTSTMT pStmt;
290} VDSCRIPTASTWHILE;
291/** Pointer to an expression node. */
292typedef VDSCRIPTASTWHILE *PVDSCRIPTASTWHILE;
293
294/**
295 * AST for node.
296 */
297typedef struct VDSCRIPTASTFOR
298{
299 /** Initializer expression. */
300 PVDSCRIPTASTEXPR pExprStart;
301 /** The exit condition. */
302 PVDSCRIPTASTEXPR pExprCond;
303 /** The third expression (normally used to increase/decrease loop variable). */
304 PVDSCRIPTASTEXPR pExpr3;
305 /** The for loop body. */
306 PVDSCRIPTASTSTMT pStmt;
307} VDSCRIPTASTFOR;
308/** Pointer to an expression node. */
309typedef VDSCRIPTASTFOR *PVDSCRIPTASTFOR;
310
311/**
312 * Statement types.
313 */
314typedef enum VDSCRIPTSTMTTYPE
315{
316 /** Invalid. */
317 VDSCRIPTSTMTTYPE_INVALID = 0,
318 /** Compound statement. */
319 VDSCRIPTSTMTTYPE_COMPOUND,
320 /** Expression statement. */
321 VDSCRIPTSTMTTYPE_EXPRESSION,
322 /** if statement. */
323 VDSCRIPTSTMTTYPE_IF,
324 /** switch statement. */
325 VDSCRIPTSTMTTYPE_SWITCH,
326 /** while statement. */
327 VDSCRIPTSTMTTYPE_WHILE,
328 /** for statement. */
329 VDSCRIPTSTMTTYPE_FOR,
330 /** continue statement. */
331 VDSCRIPTSTMTTYPE_CONTINUE,
332 /** break statement. */
333 VDSCRIPTSTMTTYPE_BREAK,
334 /** return statement. */
335 VDSCRIPTSTMTTYPE_RETURN,
336 /** case statement. */
337 VDSCRIPTSTMTTYPE_CASE,
338 /** default statement. */
339 VDSCRIPTSTMTTYPE_DEFAULT,
340 /** 32bit hack. */
341 VDSCRIPTSTMTTYPE_32BIT_HACK = 0x7fffffff
342} VDSCRIPTSTMTTYPE;
343/** Pointer to a statement type. */
344typedef VDSCRIPTSTMTTYPE *PVDSCRIPTSTMTTYPE;
345
346/**
347 * AST statement node.
348 */
349typedef struct VDSCRIPTASTSTMT
350{
351 /** Core structure. */
352 VDSCRIPTASTCORE Core;
353 /** Statement type */
354 VDSCRIPTSTMTTYPE enmStmtType;
355 /** Statement type dependent data. */
356 union
357 {
358 /** Compound statement. */
359 struct
360 {
361 /** List of declarations - VDSCRIPTASTDECL. */
362 RTLISTANCHOR ListDecls;
363 /** List of statements - VDSCRIPTASTSTMT. */
364 RTLISTANCHOR ListStmts;
365 } Compound;
366 /** case, default statement. */
367 struct
368 {
369 /** Pointer to the expression. */
370 PVDSCRIPTASTEXPR pExpr;
371 /** Pointer to the statement. */
372 PVDSCRIPTASTSTMT pStmt;
373 } Case;
374 /** "if" statement. */
375 VDSCRIPTASTIF If;
376 /** "switch" statement. */
377 VDSCRIPTASTSWITCH Switch;
378 /** "while" or "do ... while" loop. */
379 VDSCRIPTASTWHILE While;
380 /** "for" loop. */
381 VDSCRIPTASTFOR For;
382 /** Pointer to another statement. */
383 PVDSCRIPTASTSTMT pStmt;
384 /** Expression statement. */
385 PVDSCRIPTASTEXPR pExpr;
386 };
387} VDSCRIPTASTSTMT;
388
389/**
390 * AST node for one function argument.
391 */
392typedef struct VDSCRIPTASTFNARG
393{
394 /** Core structure. */
395 VDSCRIPTASTCORE Core;
396 /** Identifier describing the type of the argument. */
397 PVDSCRIPTASTIDE pType;
398 /** The name of the argument. */
399 PVDSCRIPTASTIDE pArgIde;
400} VDSCRIPTASTFNARG;
401/** Pointer to a AST function argument node. */
402typedef VDSCRIPTASTFNARG *PVDSCRIPTASTFNARG;
403
404/**
405 * AST node describing a function.
406 */
407typedef struct VDSCRIPTASTFN
408{
409 /** Core structure. */
410 VDSCRIPTASTCORE Core;
411 /** Identifier describing the return type. */
412 PVDSCRIPTASTIDE pRetType;
413 /** Name of the function. */
414 PVDSCRIPTASTIDE pFnIde;
415 /** Number of arguments in the list. */
416 unsigned cArgs;
417 /** Argument list - VDSCRIPTASTFNARG. */
418 RTLISTANCHOR ListArgs;
419 /** Compound statement node. */
420 PVDSCRIPTASTSTMT pCompoundStmts;
421} VDSCRIPTASTFN;
422/** Pointer to a function AST node. */
423typedef VDSCRIPTASTFN *PVDSCRIPTASTFN;
424
425/**
426 * Free the given AST node and all subsequent nodes pointed to
427 * by the given node.
428 *
429 * @returns nothing.
430 * @param pAstNode The AST node to free.
431 */
432DECLHIDDEN(void) vdScriptAstNodeFree(PVDSCRIPTASTCORE pAstNode);
433
434/**
435 * Allocate a non variable in size AST node of the given class.
436 *
437 * @returns Pointer to the allocated node.
438 * NULL if out of memory.
439 * @param enmClass The class of the AST node.
440 */
441DECLHIDDEN(PVDSCRIPTASTCORE) vdScriptAstNodeAlloc(VDSCRIPTASTCLASS enmClass);
442
443/**
444 * Allocate a IDE node which can hold the given number of characters.
445 *
446 * @returns Pointer to the allocated node.
447 * NULL if out of memory.
448 * @param cchIde Number of characters which can be stored in the node.
449 */
450DECLHIDDEN(PVDSCRIPTASTIDE) vdScriptAstNodeIdeAlloc(unsigned cchIde);
451
452#endif /* _VDScriptAst_h__ */
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