VDScriptAst.h revision db453c26f429ba8057ea92644ddd59279b9a918d
/** @file
*
* VBox HDD container test utility - scripting engine, AST related structures.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef _VDScriptAst_h__
#define _VDScriptAst_h__
/**
* AST node classes.
*/
typedef enum VDSCRIPTASTCLASS
{
/** Invalid. */
/** Function node. */
/** Function argument. */
/** Identifier node. */
/** Declaration node. */
/** Statement node. */
/** Expression node. */
/** @todo: Add if ... else, loops, ... */
/** 32bit blowup. */
VDSCRIPTASTCLASS_32BIT_HACK = 0x7fffffff
/** Pointer to an AST node class. */
typedef VDSCRIPTASTCLASS *PVDSCRIPTASTCLASS;
/**
* Core AST structure.
*/
typedef struct VDSCRIPTASTCORE
{
/** The node class, used for verification. */
/** List which might be used. */
/** Pointer to an AST core structure. */
typedef VDSCRIPTASTCORE *PVDSCRIPTASTCORE;
/** Pointer to an statement node - forward declaration. */
typedef struct VDSCRIPTASTSTMT *PVDSCRIPTASTSTMT;
/**
* AST identifier node.
*/
typedef struct VDSCRIPTASTIDE
{
/** Core structure. */
/** Number of characters in the identifier, excluding the zero terminator. */
unsigned cchIde;
/** Identifier, variable size. */
char aszIde[1];
/** Pointer to an identifer node. */
typedef VDSCRIPTASTIDE *PVDSCRIPTASTIDE;
/**
* AST declaration node.
*/
typedef struct VDSCRIPTASTDECL
{
/** Core structure. */
/** @todo */
/** Pointer to an declaration node. */
typedef VDSCRIPTASTDECL *PVDSCRIPTASTDECL;
/**
* AST expression node.
*/
typedef struct VDSCRIPTASTEXPR
{
/** Core structure. */
/** @todo */
unsigned uDummy;
/** Pointer to an expression node. */
typedef VDSCRIPTASTEXPR *PVDSCRIPTASTEXPR;
/**
* AST if node.
*/
typedef struct VDSCRIPTASTIF
{
/** Conditional expression. */
/** The true branch */
/** The else branch, can be NULL if no else branch. */
/** Pointer to an expression node. */
typedef VDSCRIPTASTIF *PVDSCRIPTASTIF;
/**
* AST switch node.
*/
typedef struct VDSCRIPTASTSWITCH
{
/** Conditional expression. */
/** The statement to follow. */
/** Pointer to an expression node. */
typedef VDSCRIPTASTSWITCH *PVDSCRIPTASTSWITCH;
/**
* AST while or do ... while node.
*/
typedef struct VDSCRIPTASTWHILE
{
/** Flag whether this is a do while loop. */
bool fDoWhile;
/** Conditional expression. */
/** The statement to follow. */
/** Pointer to an expression node. */
typedef VDSCRIPTASTWHILE *PVDSCRIPTASTWHILE;
/**
* AST for node.
*/
typedef struct VDSCRIPTASTFOR
{
/** Initializer expression. */
/** The exit condition. */
/** The for loop body. */
/** Pointer to an expression node. */
typedef VDSCRIPTASTFOR *PVDSCRIPTASTFOR;
/**
* Statement types.
*/
typedef enum VDSCRIPTSTMTTYPE
{
/** Invalid. */
/** Labeled statement. */
/** Compound statement. */
/** Expression statement. */
/** if statement. */
/** switch statement. */
/** while statement. */
/** for statement. */
/** continue statement. */
/** break statement. */
/** return statement. */
/** case statement. */
/** default statement. */
/** 32bit hack. */
VDSCRIPTSTMTTYPE_32BIT_HACK = 0x7fffffff
/** Pointer to a statement type. */
typedef VDSCRIPTSTMTTYPE *PVDSCRIPTSTMTTYPE;
/**
* AST statement node.
*/
typedef struct VDSCRIPTASTSTMT
{
/** Core structure. */
/** Statement type */
/** Statement type dependent data. */
union
{
/** Labeled statement (case, default). */
struct
{
/** Conditional expression, if NULL this is a statement for "default" */
/** Statement to execute. */
} Labeled;
/** Compound statement. */
struct
{
/** List of declarations - VDSCRIPTASTDECL. */
/** List of statements - VDSCRIPTASTSTMT. */
} Compound;
/** case statement. */
struct
{
/** Pointer to the expression. */
/** Pointer to the statement. */
} Case;
/** "if" statement. */
/** "switch" statement. */
/** "while" or "do ... while" loop. */
/** "for" loop. */
/** Pointer to another statement. */
/** Expression statement. */
};
/**
* AST node for one function argument.
*/
typedef struct VDSCRIPTASTFNARG
{
/** Core structure. */
/** Identifier describing the type of the argument. */
/** The name of the argument. */
/** Pointer to a AST function argument node. */
typedef VDSCRIPTASTFNARG *PVDSCRIPTASTFNARG;
/**
* AST node describing a function.
*/
typedef struct VDSCRIPTASTFN
{
/** Core structure. */
/** Identifier describing the return type. */
/** Name of the function. */
/** Number of arguments in the list. */
unsigned cArgs;
/** Argument list - VDSCRIPTASTFNARG. */
/** Compound statement node. */
/** Pointer to a function AST node. */
typedef VDSCRIPTASTFN *PVDSCRIPTASTFN;
/**
* Free the given AST node and all subsequent nodes pointed to
* by the given node.
*
* @returns nothing.
* @param pAstNode The AST node to free.
*/
/**
* Allocate a non variable in size AST node of the given class.
*
* @returns Pointer to the allocated node.
* NULL if out of memory.
* @param enmClass The class of the AST node.
*/
/**
* Allocate a IDE node which can hold the given number of characters.
*
* @returns Pointer to the allocated node.
* NULL if out of memory.
* @param cchIde Number of characters which can be stored in the node.
*/
#endif /* _VDScriptAst_h__ */