VDScriptAst.h revision c299849be8ae3544715e8806e1433cae67d93e2e
/** @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__
/**
* Position information.
*/
typedef struct VDSRCPOS
{
/** Line in the source. */
unsigned iLine;
/** Current start character .*/
unsigned iChStart;
/** Current end character. */
unsigned iChEnd;
} VDSRCPOS;
/** Pointer to a source position. */
/**
* AST node classes.
*/
typedef enum VDSCRIPTASTCLASS
{
/** Invalid. */
/** Function node. */
/** Function argument. */
/** Identifier node. */
/** Declaration node. */
/** Statement node. */
/** Expression node. */
/** Type name node. */
/** Type specifier node. */
/** 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. */
/** Position in the source file of this node. */
/** Pointer to an AST core structure. */
typedef VDSCRIPTASTCORE *PVDSCRIPTASTCORE;
/** Pointer to an statement node - forward declaration. */
typedef struct VDSCRIPTASTSTMT *PVDSCRIPTASTSTMT;
/** Pointer to an expression node - forward declaration. */
typedef struct VDSCRIPTASTEXPR *PVDSCRIPTASTEXPR;
/**
* 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;
/**
* Type specifier.
*/
typedef enum VDSCRIPTASTTYPESPECIFIER
{
/** Invalid type specifier. */
/** Union type specifier. */
/** Struct type specifier. */
/** Identifier of a typedefed type. */
/** 32bit hack. */
VDSCRIPTASTTYPESPECIFIER_32BIT_HACK = 0x7fffffff
/** Pointer to a typespecifier. */
/**
* AST type specifier.
*/
typedef struct VDSCRIPTASTTYPESPEC
{
/** Core structure. */
/** Specifier type. */
/** Type dependent data .*/
union
{
/** Pointer to an identifier for typedefed types. */
/** struct or union specifier. */
struct
{
/** Pointer to the identifier, optional. */
/** Declaration list - VDSCRIPTAST. */
} StructUnion;
};
/** Pointer to an AST type specifier. */
typedef VDSCRIPTASTTYPESPEC *PVDSCRIPTASTTYPESPEC;
/**
* Storage clase specifier.
*/
typedef enum VDSCRIPTASTSTORAGECLASS
{
/** Invalid storage class sepcifier. */
/** A typedef type. */
/** An external declared object. */
/** A static declared object. */
/** Auto object. */
/** Object should be stored in a register. */
/** 32bit hack. */
VDSCRIPTASTSTORAGECLASS_32BIT_HACK = 0x7fffffff
/** Pointer to a storage class. */
/**
* Type qualifier.
*/
typedef enum VDSCRIPTASTTYPEQUALIFIER
{
/** Invalid type qualifier. */
/** Const type qualifier. */
/** Restrict type qualifier. */
/** Volatile type qualifier. */
/** 32bit hack. */
VDSCRIPTASTTYPEQUALIFIER_32BIT_HACK = 0x7fffffff
/** Pointer to a type qualifier. */
/**
* AST type name node.
*/
typedef struct VDSCRIPTASTTYPENAME
{
/** Core structure. */
/** Pointer to a type name node. */
typedef VDSCRIPTASTTYPENAME *PVDSCRIPTASTTYPENAME;
/**
* AST declaration node.
*/
typedef struct VDSCRIPTASTDECL
{
/** Core structure. */
/** @todo */
/** Pointer to an declaration node. */
typedef VDSCRIPTASTDECL *PVDSCRIPTASTDECL;
/**
* Expression types.
*/
typedef enum VDSCRIPTEXPRTYPE
{
/** Invalid. */
/** Numerical constant. */
/** String constant. */
/** Boolean constant. */
/** Identifier. */
/** List of assignment expressions as in a = b = c = ... . */
/** Postfix increment expression. */
/** Postfix decrement expression. */
/** Postfix function call expression. */
/** Postfix dereference expression. */
/** Dot operator (@todo: Is there a better name for it?). */
/** Unary increment expression. */
/** Unary decrement expression. */
/** Unary positive sign expression. */
/** Unary negtive sign expression. */
/** Unary invert expression. */
/** Unary negate expression. */
/** Unary reference expression. */
/** Unary dereference expression. */
/** Cast expression. */
/** Multiplicative expression. */
/** Division expression. */
/** Modulus expression. */
/** Addition expression. */
/** Subtraction expression. */
/** Logical shift right. */
/** Logical shift left. */
/** Lower than expression */
/** Higher than expression */
/** Lower or equal than expression */
/** Higher or equal than expression */
/** Equals expression */
/** Not equal expression */
/** Bitwise and expression */
/** Bitwise xor expression */
/** Bitwise or expression */
/** Logical and expression */
/** Logical or expression */
/** Assign expression */
/** Multiplicative assign expression */
/** Division assign expression */
/** Modulus assign expression */
/** Additive assign expression */
/** Subtractive assign expression */
/** Bitwise left shift assign expression */
/** Bitwise right shift assign expression */
/** Bitwise and assign expression */
/** Bitwise xor assign expression */
/** Bitwise or assign expression */
/** 32bit hack. */
VDSCRIPTEXPRTYPE_32BIT_HACK = 0x7fffffff
/** Pointer to an expression type. */
typedef VDSCRIPTEXPRTYPE *PVDSCRIPTEXPRTYPE;
/**
* AST expression node.
*/
typedef struct VDSCRIPTASTEXPR
{
/** Core structure. */
/** Expression type. */
/** Expression type dependent data. */
union
{
/** Numerical constant. */
/** Primary identifier. */
/** String literal */
const char *pszStr;
/** Boolean constant. */
bool f;
/** List of expressions - VDSCRIPTASTEXPR. */
/** Pointer to another expression. */
/** Function call expression. */
struct
{
/** Other postfix expression used as the identifier for the function. */
/** Argument list if existing. */
} FnCall;
/** Binary operation. */
struct
{
/** Left operator. */
/** Right operator. */
} BinaryOp;
/** Dereference or dot operation. */
struct
{
/** The identifier to access. */
/** Postfix expression coming after this. */
} Deref;
/** Cast expression. */
struct
{
/** Type name. */
/** Following cast expression. */
} Cast;
};
/**
* 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. */
/** 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
{
/** Compound statement. */
struct
{
/** List of declarations - VDSCRIPTASTDECL. */
/** List of statements - VDSCRIPTASTSTMT. */
} Compound;
/** case, default 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__ */