VirtualBox

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

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

Storage/testcase: Updates for VDScript, parser not quite working yet

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