VDScriptAst.cpp revision 8bce22f6f04047918df71d70b614262e1d08dc61
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync/** @file
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync *
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * VBox HDD container test utility - scripting engine AST node related functions.
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync */
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync/*
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync * Copyright (C) 2013 Oracle Corporation
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync *
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * available from http://www.virtualbox.org. This file is free software;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * General Public License (GPL) as published by the Free Software
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync */
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync#define LOGGROUP LOGGROUP_DEFAULT
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync#include <iprt/list.h>
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync#include <iprt/mem.h>
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync#include <iprt/assert.h>
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync#include <VBox/log.h>
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync#include "VDScriptAst.h"
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync/**
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * Put all child nodes of the given expression AST node onto the given to free list.
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync *
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * @returns nothing.
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * @param pList The free list to append everything to.
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync * @param pAstNode The expression node to free.
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync */
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsyncstatic void vdScriptAStNodeExpressionPutOnFreeList(PRTLISTANCHOR pList, PVDSCRIPTASTCORE pAstNode)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync{
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync AssertMsgReturnVoid(pAstNode->enmClass == VDSCRIPTASTCLASS_EXPRESSION,
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync ("Given AST node is not a statement\n"));
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync PVDSCRIPTASTEXPR pExpr = (PVDSCRIPTASTEXPR)pAstNode;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync switch (pExpr->enmType)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_PRIMARY_NUMCONST:
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync case VDSCRIPTEXPRTYPE_PRIMARY_STRINGCONST:
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync case VDSCRIPTEXPRTYPE_PRIMARY_IDENTIFIER:
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync case VDSCRIPTEXPRTYPE_ASSIGNMENT_LIST:
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync case VDSCRIPTEXPRTYPE_POSTFIX_INCREMENT:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_POSTFIX_DECREMENT:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_POSTFIX_FNCALL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_UNARY_INCREMENT:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_UNARY_DECREMENT:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_UNARY_POSSIGN:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_UNARY_NEGSIGN:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_UNARY_INVERT:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_UNARY_NEGATE:
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync case VDSCRIPTEXPRTYPE_MULTIPLICATION:
15aa5bd4323e2951c8b51648033af4104b2ba8f9vboxsync case VDSCRIPTEXPRTYPE_DIVISION:
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync case VDSCRIPTEXPRTYPE_MODULUS:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ADDITION:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_SUBTRACTION:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_LSR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_LSL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_LOWER:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_HIGHER:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_LOWEREQUAL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_HIGHEREQUAL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_EQUAL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_NOTEQUAL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_BITWISE_AND:
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync case VDSCRIPTEXPRTYPE_BITWISE_XOR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_BITWISE_OR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_LOGICAL_AND:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_LOGICAL_OR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_MULT:
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_DIV:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_MOD:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_ADD:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_SUB:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_LSL:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_LSR:
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_AND:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_XOR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_ASSIGN_OR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTEXPRTYPE_INVALID:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync default:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync AssertMsgFailedReturnVoid(("Invalid AST node expression type %d\n",
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync pExpr->enmType));
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync}
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync/**
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync * Free a given statement AST node and put everything on the given to free list.
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync *
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync * @returns nothing.
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync * @param pList The free list to append everything to.
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync * @param pAstNode The statement node to free.
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync */
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsyncstatic void vdScriptAstNodeStatmentPutOnFreeList(PRTLISTANCHOR pList, PVDSCRIPTASTCORE pAstNode)
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync{
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync AssertMsgReturnVoid(pAstNode->enmClass == VDSCRIPTASTCLASS_STATEMENT,
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync ("Given AST node is not a statement\n"));
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync PVDSCRIPTASTSTMT pStmt = (PVDSCRIPTASTSTMT)pAstNode;
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync switch (pStmt->enmStmtType)
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync {
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync case VDSCRIPTSTMTTYPE_COMPOUND:
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync {
99dfe084aaa87733b2e26f5f9a86054d0461ff60vboxsync /* Put all declarations on the to free list. */
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync while (!RTListIsEmpty(&pStmt->Compound.ListDecls))
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync PVDSCRIPTASTCORE pNode = RTListGetFirst(&pStmt->Compound.ListDecls, VDSCRIPTASTCORE, ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListNodeRemove(&pNode->ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pNode->ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync /* Put all statements on the to free list. */
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync while (!RTListIsEmpty(&pStmt->Compound.ListStmts))
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync PVDSCRIPTASTCORE pNode = RTListGetFirst(&pStmt->Compound.ListDecls, VDSCRIPTASTCORE, ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListNodeRemove(&pNode->ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pNode->ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_EXPRESSION:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->pExpr->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_IF:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->If.pCond->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->If.pTrueStmt->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync if (pStmt->If.pElseStmt)
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync RTListAppend(pList, &pStmt->If.pElseStmt->Core.ListNode);
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync break;
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync }
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync case VDSCRIPTSTMTTYPE_SWITCH:
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync {
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync RTListAppend(pList, &pStmt->Switch.pCond->Core.ListNode);
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync RTListAppend(pList, &pStmt->Switch.pStmt->Core.ListNode);
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync break;
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync }
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync case VDSCRIPTSTMTTYPE_WHILE:
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync {
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync RTListAppend(pList, &pStmt->While.pCond->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->While.pStmt->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_FOR:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->For.pExprStart->Core.ListNode);
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync RTListAppend(pList, &pStmt->For.pExprCond->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->For.pExpr3->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->For.pStmt->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_RETURN:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync if (pStmt->pExpr)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->pExpr->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_CASE:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->Case.pExpr->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->Case.pStmt->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_DEFAULT:
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(pList, &pStmt->Case.pStmt->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_CONTINUE:
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync case VDSCRIPTSTMTTYPE_BREAK:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync break;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTSTMTTYPE_INVALID:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync default:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync AssertMsgFailedReturnVoid(("Invalid AST node statement type %d\n",
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync pStmt->enmStmtType));
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync }
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync}
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsyncDECLHIDDEN(void) vdScriptAstNodeFree(PVDSCRIPTASTCORE pAstNode)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync{
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync RTLISTANCHOR ListFree;
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync
c5245f029ba21b3152e4ba59394838bb5c09126bvboxsync /*
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * The node is not allowed to be part of a list because we need it
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync * for the nodes to free list.
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync */
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync Assert(RTListIsEmpty(&pAstNode->ListNode));
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListInit(&ListFree);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(&ListFree, &pAstNode->ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync do
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync pAstNode = RTListGetFirst(&ListFree, VDSCRIPTASTCORE, ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListNodeRemove(&pAstNode->ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync switch (pAstNode->enmClass)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync case VDSCRIPTASTCLASS_FUNCTION:
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync {
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync PVDSCRIPTASTFN pFn = (PVDSCRIPTASTFN)pAstNode;
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync if (pFn->pRetType)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(&ListFree, &pFn->pRetType->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync if (pFn->pFnIde)
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync RTListAppend(&ListFree, &pFn->pFnIde->Core.ListNode);
39c2e57acd25ad706e24d3eed2cba74905506db0vboxsync
/* Put argument list on the to free list. */
while (!RTListIsEmpty(&pFn->ListArgs))
{
PVDSCRIPTASTCORE pArg = RTListGetFirst(&pFn->ListArgs, VDSCRIPTASTCORE, ListNode);
RTListNodeRemove(&pArg->ListNode);
RTListAppend(&ListFree, &pArg->ListNode);
}
/* Put compound statement onto the list. */
RTListAppend(&ListFree, &pFn->pCompoundStmts->Core.ListNode);
break;
}
case VDSCRIPTASTCLASS_FUNCTIONARG:
{
PVDSCRIPTASTFNARG pAstNodeArg = (PVDSCRIPTASTFNARG)pAstNode;
if (pAstNodeArg->pType)
RTListAppend(&ListFree, &pAstNodeArg->pType->Core.ListNode);
if (pAstNodeArg->pArgIde)
RTListAppend(&ListFree, &pAstNodeArg->pArgIde->Core.ListNode);
break;
}
case VDSCRIPTASTCLASS_IDENTIFIER:
break;
case VDSCRIPTASTCLASS_DECLARATION:
break;
case VDSCRIPTASTCLASS_STATEMENT:
{
vdScriptAstNodeStatmentPutOnFreeList(&ListFree, pAstNode);
break;
}
case VDSCRIPTASTCLASS_EXPRESSION:
{
vdScriptAStNodeExpressionPutOnFreeList(&ListFree, pAstNode);
break;
}
case VDSCRIPTASTCLASS_INVALID:
default:
AssertMsgFailedReturnVoid(("Invalid AST node class given %d\n", pAstNode->enmClass));
}
RTMemFree(pAstNode);
} while (!RTListIsEmpty(&ListFree));
}
DECLHIDDEN(PVDSCRIPTASTCORE) vdScriptAstNodeAlloc(VDSCRIPTASTCLASS enmClass)
{
size_t cbAlloc = 0;
switch (enmClass)
{
case VDSCRIPTASTCLASS_FUNCTION:
cbAlloc = sizeof(VDSCRIPTASTFN);
break;
case VDSCRIPTASTCLASS_FUNCTIONARG:
cbAlloc = sizeof(VDSCRIPTASTFNARG);
break;
case VDSCRIPTASTCLASS_DECLARATION:
cbAlloc = sizeof(VDSCRIPTASTDECL);
break;
case VDSCRIPTASTCLASS_STATEMENT:
cbAlloc = sizeof(VDSCRIPTASTSTMT);
break;
case VDSCRIPTASTCLASS_EXPRESSION:
cbAlloc = sizeof(VDSCRIPTASTEXPR);
break;
case VDSCRIPTASTCLASS_IDENTIFIER:
case VDSCRIPTASTCLASS_INVALID:
default:
AssertMsgFailedReturn(("Invalid AST node class given %d\n", enmClass), NULL);
}
PVDSCRIPTASTCORE pAstNode = (PVDSCRIPTASTCORE)RTMemAllocZ(cbAlloc);
if (pAstNode)
{
pAstNode->enmClass = enmClass;
RTListInit(&pAstNode->ListNode);
}
return pAstNode;
}
DECLHIDDEN(PVDSCRIPTASTIDE) vdScriptAstNodeIdeAlloc(unsigned cchIde)
{
PVDSCRIPTASTIDE pAstNode = (PVDSCRIPTASTIDE)RTMemAllocZ(RT_OFFSETOF(VDSCRIPTASTIDE, aszIde[cchIde + 1]));
if (pAstNode)
{
pAstNode->Core.enmClass = VDSCRIPTASTCLASS_IDENTIFIER;
RTListInit(&pAstNode->Core.ListNode);
}
return pAstNode;
}