3d475f690d5d82606d31b3689815152e68da442bvboxsync/** @file
3d475f690d5d82606d31b3689815152e68da442bvboxsync *
3d475f690d5d82606d31b3689815152e68da442bvboxsync * VBox HDD container test utility - scripting engine, internal script structures.
3d475f690d5d82606d31b3689815152e68da442bvboxsync */
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync/*
3d475f690d5d82606d31b3689815152e68da442bvboxsync * Copyright (C) 2013 Oracle Corporation
3d475f690d5d82606d31b3689815152e68da442bvboxsync *
3d475f690d5d82606d31b3689815152e68da442bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3d475f690d5d82606d31b3689815152e68da442bvboxsync * available from http://www.virtualbox.org. This file is free software;
3d475f690d5d82606d31b3689815152e68da442bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3d475f690d5d82606d31b3689815152e68da442bvboxsync * General Public License (GPL) as published by the Free Software
3d475f690d5d82606d31b3689815152e68da442bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3d475f690d5d82606d31b3689815152e68da442bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3d475f690d5d82606d31b3689815152e68da442bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3d475f690d5d82606d31b3689815152e68da442bvboxsync */
3d475f690d5d82606d31b3689815152e68da442bvboxsync#ifndef _VDScriptInternal_h__
3d475f690d5d82606d31b3689815152e68da442bvboxsync#define _VDScriptInternal_h__
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync#include <iprt/list.h>
3d475f690d5d82606d31b3689815152e68da442bvboxsync#include <iprt/string.h>
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync#include "VDScript.h"
3d475f690d5d82606d31b3689815152e68da442bvboxsync
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync/**
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync * Script function which can be called.
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsynctypedef struct VDSCRIPTFN
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync{
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** String space core. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync RTSTRSPACECORE Core;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Flag whether function is defined in the source or was
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync * registered from the outside. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync bool fExternal;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Flag dependent data. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync union
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync {
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Data for functions defined in the source. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync struct
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync {
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Pointer to the AST defining the function. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync PVDSCRIPTASTFN pAstFn;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync } Internal;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Data for external defined functions. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync struct
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync {
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Callback function. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync PFNVDSCRIPTCALLBACK pfnCallback;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Opaque user data. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync void *pvUser;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync } External;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync } Type;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Return type of the function. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync VDSCRIPTTYPE enmTypeRetn;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Number of arguments the function takes. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync unsigned cArgs;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync /** Variable sized array of argument types. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync VDSCRIPTTYPE aenmArgTypes[1];
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync} VDSCRIPTFN;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync/** Pointer to a script function registration structure. */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsynctypedef VDSCRIPTFN *PVDSCRIPTFN;
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync/** Pointer to a tokenize state. */
3d475f690d5d82606d31b3689815152e68da442bvboxsynctypedef struct VDTOKENIZER *PVDTOKENIZER;
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync/**
3d475f690d5d82606d31b3689815152e68da442bvboxsync * Script context.
3d475f690d5d82606d31b3689815152e68da442bvboxsync */
3d475f690d5d82606d31b3689815152e68da442bvboxsynctypedef struct VDSCRIPTCTXINT
3d475f690d5d82606d31b3689815152e68da442bvboxsync{
3d475f690d5d82606d31b3689815152e68da442bvboxsync /** String space of external registered and source defined functions. */
3d475f690d5d82606d31b3689815152e68da442bvboxsync RTSTRSPACE hStrSpaceFn;
3d475f690d5d82606d31b3689815152e68da442bvboxsync /** List of ASTs for functions - VDSCRIPTASTFN. */
3d475f690d5d82606d31b3689815152e68da442bvboxsync RTLISTANCHOR ListAst;
3d475f690d5d82606d31b3689815152e68da442bvboxsync /** Pointer to the current tokenizer state. */
3d475f690d5d82606d31b3689815152e68da442bvboxsync PVDTOKENIZER pTokenizer;
3d475f690d5d82606d31b3689815152e68da442bvboxsync} VDSCRIPTCTXINT;
3d475f690d5d82606d31b3689815152e68da442bvboxsync/** Pointer to a script context. */
3d475f690d5d82606d31b3689815152e68da442bvboxsynctypedef VDSCRIPTCTXINT *PVDSCRIPTCTXINT;
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync/**
3d475f690d5d82606d31b3689815152e68da442bvboxsync * Check the context for type correctness.
3d475f690d5d82606d31b3689815152e68da442bvboxsync *
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @returns VBox status code.
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @param pThis The script context.
3d475f690d5d82606d31b3689815152e68da442bvboxsync */
3d475f690d5d82606d31b3689815152e68da442bvboxsyncDECLHIDDEN(int) vdScriptCtxCheck(PVDSCRIPTCTXINT pThis);
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync/**
fb7c7050d4e425a33a74936d12390d522666aa6cvboxsync * Interprete a given function AST. The executed functions
fb7c7050d4e425a33a74936d12390d522666aa6cvboxsync * must be type correct, otherwise the behavior is undefined
fb7c7050d4e425a33a74936d12390d522666aa6cvboxsync * (Will assert in debug builds).
3d475f690d5d82606d31b3689815152e68da442bvboxsync *
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @returns VBox status code.
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @param pThis The script context.
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync * @param pszFn The function name to interprete.
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @param paArgs Arguments to pass to the function.
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @param cArgs Number of arguments.
3d475f690d5d82606d31b3689815152e68da442bvboxsync * @param pRet Where to store the return value on success.
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync *
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsync * @note: The AST is not modified in any way during the interpretation process.
3d475f690d5d82606d31b3689815152e68da442bvboxsync */
9e0b97c99123f5eb89a851ce0182f7e438000c0dvboxsyncDECLHIDDEN(int) vdScriptCtxInterprete(PVDSCRIPTCTXINT pThis, const char *pszFn,
3d475f690d5d82606d31b3689815152e68da442bvboxsync PVDSCRIPTARG paArgs, unsigned cArgs,
3d475f690d5d82606d31b3689815152e68da442bvboxsync PVDSCRIPTARG pRet);
3d475f690d5d82606d31b3689815152e68da442bvboxsync
3d475f690d5d82606d31b3689815152e68da442bvboxsync#endif /* _VDScriptInternal_h__ */