Changeset 44855 in vbox for trunk/src/VBox/Storage/testcase
- Timestamp:
- Feb 27, 2013 10:15:42 PM (12 years ago)
- Location:
- trunk/src/VBox/Storage/testcase
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/VDScript.cpp
r44842 r44855 2366 2366 rc = vdScriptParserError(pThis, VERR_INVALID_PARAMETER, RT_SRC_POS, "Parser: Expected \";\", got ...\n"); 2367 2367 } 2368 else 2369 pAstNodeStmt->pExpr = NULL; /* No expression for return. */ 2368 2370 } 2369 2371 else -
trunk/src/VBox/Storage/testcase/VDScriptAst.cpp
r44840 r44855 24 24 #include "VDScriptAst.h" 25 25 26 /** 27 * Put all child nodes of the given expression AST node onto the given to free list. 28 * 29 * @returns nothing. 30 * @param pList The free list to append everything to. 31 * @param pAstNode The expression node to free. 32 */ 33 static void vdScriptAStNodeExpressionPutOnFreeList(PRTLISTANCHOR pList, PVDSCRIPTASTCORE pAstNode) 34 { 35 AssertMsgReturnVoid(pAstNode->enmClass == VDSCRIPTASTCLASS_EXPRESSION, 36 ("Given AST node is not a statement\n")); 37 38 PVDSCRIPTASTEXPR pExpr = (PVDSCRIPTASTEXPR)pAstNode; 39 switch (pExpr->enmType) 40 { 41 case VDSCRIPTEXPRTYPE_PRIMARY_NUMCONST: 42 case VDSCRIPTEXPRTYPE_PRIMARY_STRINGCONST: 43 case VDSCRIPTEXPRTYPE_PRIMARY_IDENTIFIER: 44 case VDSCRIPTEXPRTYPE_ASSIGNMENT_LIST: 45 case VDSCRIPTEXPRTYPE_POSTFIX_INCREMENT: 46 case VDSCRIPTEXPRTYPE_POSTFIX_DECREMENT: 47 case VDSCRIPTEXPRTYPE_POSTFIX_FNCALL: 48 case VDSCRIPTEXPRTYPE_UNARY_INCREMENT: 49 case VDSCRIPTEXPRTYPE_UNARY_DECREMENT: 50 case VDSCRIPTEXPRTYPE_UNARY_POSSIGN: 51 case VDSCRIPTEXPRTYPE_UNARY_NEGSIGN: 52 case VDSCRIPTEXPRTYPE_UNARY_INVERT: 53 case VDSCRIPTEXPRTYPE_UNARY_NEGATE: 54 case VDSCRIPTEXPRTYPE_MULTIPLICATION: 55 case VDSCRIPTEXPRTYPE_DIVISION: 56 case VDSCRIPTEXPRTYPE_MODULUS: 57 case VDSCRIPTEXPRTYPE_ADDITION: 58 case VDSCRIPTEXPRTYPE_SUBTRACTION: 59 case VDSCRIPTEXPRTYPE_LSR: 60 case VDSCRIPTEXPRTYPE_LSL: 61 case VDSCRIPTEXPRTYPE_LOWER: 62 case VDSCRIPTEXPRTYPE_HIGHER: 63 case VDSCRIPTEXPRTYPE_LOWEREQUAL: 64 case VDSCRIPTEXPRTYPE_HIGHEREQUAL: 65 case VDSCRIPTEXPRTYPE_EQUAL: 66 case VDSCRIPTEXPRTYPE_NOTEQUAL: 67 case VDSCRIPTEXPRTYPE_BITWISE_AND: 68 case VDSCRIPTEXPRTYPE_BITWISE_XOR: 69 case VDSCRIPTEXPRTYPE_BITWISE_OR: 70 case VDSCRIPTEXPRTYPE_LOGICAL_AND: 71 case VDSCRIPTEXPRTYPE_LOGICAL_OR: 72 case VDSCRIPTEXPRTYPE_ASSIGN: 73 case VDSCRIPTEXPRTYPE_ASSIGN_MULT: 74 case VDSCRIPTEXPRTYPE_ASSIGN_DIV: 75 case VDSCRIPTEXPRTYPE_ASSIGN_MOD: 76 case VDSCRIPTEXPRTYPE_ASSIGN_ADD: 77 case VDSCRIPTEXPRTYPE_ASSIGN_SUB: 78 case VDSCRIPTEXPRTYPE_ASSIGN_LSL: 79 case VDSCRIPTEXPRTYPE_ASSIGN_LSR: 80 case VDSCRIPTEXPRTYPE_ASSIGN_AND: 81 case VDSCRIPTEXPRTYPE_ASSIGN_XOR: 82 case VDSCRIPTEXPRTYPE_ASSIGN_OR: 83 case VDSCRIPTEXPRTYPE_INVALID: 84 default: 85 AssertMsgFailedReturnVoid(("Invalid AST node expression type %d\n", 86 pExpr->enmType)); 87 } 88 } 89 90 /** 91 * Free a given statement AST node and put everything on the given to free list. 92 * 93 * @returns nothing. 94 * @param pList The free list to append everything to. 95 * @param pAstNode The statement node to free. 96 */ 97 static void vdScriptAstNodeStatmentPutOnFreeList(PRTLISTANCHOR pList, PVDSCRIPTASTCORE pAstNode) 98 { 99 AssertMsgReturnVoid(pAstNode->enmClass == VDSCRIPTASTCLASS_STATEMENT, 100 ("Given AST node is not a statement\n")); 101 102 PVDSCRIPTASTSTMT pStmt = (PVDSCRIPTASTSTMT)pAstNode; 103 switch (pStmt->enmStmtType) 104 { 105 case VDSCRIPTSTMTTYPE_COMPOUND: 106 { 107 /* Put all declarations on the to free list. */ 108 while (!RTListIsEmpty(&pStmt->Compound.ListDecls)) 109 { 110 PVDSCRIPTASTCORE pNode = RTListGetFirst(&pStmt->Compound.ListDecls, VDSCRIPTASTCORE, ListNode); 111 RTListNodeRemove(&pNode->ListNode); 112 RTListAppend(pList, &pNode->ListNode); 113 } 114 115 /* Put all statements on the to free list. */ 116 while (!RTListIsEmpty(&pStmt->Compound.ListStmts)) 117 { 118 PVDSCRIPTASTCORE pNode = RTListGetFirst(&pStmt->Compound.ListDecls, VDSCRIPTASTCORE, ListNode); 119 RTListNodeRemove(&pNode->ListNode); 120 RTListAppend(pList, &pNode->ListNode); 121 } 122 break; 123 } 124 case VDSCRIPTSTMTTYPE_EXPRESSION: 125 { 126 RTListAppend(pList, &pStmt->pExpr->Core.ListNode); 127 break; 128 } 129 case VDSCRIPTSTMTTYPE_IF: 130 { 131 RTListAppend(pList, &pStmt->If.pCond->Core.ListNode); 132 RTListAppend(pList, &pStmt->If.pTrueStmt->Core.ListNode); 133 if (pStmt->If.pElseStmt) 134 RTListAppend(pList, &pStmt->If.pElseStmt->Core.ListNode); 135 break; 136 } 137 case VDSCRIPTSTMTTYPE_SWITCH: 138 { 139 RTListAppend(pList, &pStmt->Switch.pCond->Core.ListNode); 140 RTListAppend(pList, &pStmt->Switch.pStmt->Core.ListNode); 141 break; 142 } 143 case VDSCRIPTSTMTTYPE_WHILE: 144 { 145 RTListAppend(pList, &pStmt->While.pCond->Core.ListNode); 146 RTListAppend(pList, &pStmt->While.pStmt->Core.ListNode); 147 break; 148 } 149 case VDSCRIPTSTMTTYPE_FOR: 150 { 151 RTListAppend(pList, &pStmt->For.pExprStart->Core.ListNode); 152 RTListAppend(pList, &pStmt->For.pExprCond->Core.ListNode); 153 RTListAppend(pList, &pStmt->For.pExpr3->Core.ListNode); 154 RTListAppend(pList, &pStmt->For.pStmt->Core.ListNode); 155 break; 156 } 157 case VDSCRIPTSTMTTYPE_RETURN: 158 { 159 if (pStmt->pExpr) 160 RTListAppend(pList, &pStmt->pExpr->Core.ListNode); 161 break; 162 } 163 case VDSCRIPTSTMTTYPE_CASE: 164 { 165 RTListAppend(pList, &pStmt->Case.pExpr->Core.ListNode); 166 RTListAppend(pList, &pStmt->Case.pStmt->Core.ListNode); 167 break; 168 } 169 case VDSCRIPTSTMTTYPE_DEFAULT: 170 { 171 RTListAppend(pList, &pStmt->Case.pStmt->Core.ListNode); 172 break; 173 } 174 case VDSCRIPTSTMTTYPE_CONTINUE: 175 case VDSCRIPTSTMTTYPE_BREAK: 176 break; 177 case VDSCRIPTSTMTTYPE_INVALID: 178 default: 179 AssertMsgFailedReturnVoid(("Invalid AST node statement type %d\n", 180 pStmt->enmStmtType)); 181 } 182 } 183 26 184 DECLHIDDEN(void) vdScriptAstNodeFree(PVDSCRIPTASTCORE pAstNode) 27 185 { 28 switch (pAstNode->enmClass) 29 { 30 case VDSCRIPTASTCLASS_FUNCTION: 31 { 32 /** @todo. */ 33 break; 34 } 35 case VDSCRIPTASTCLASS_FUNCTIONARG: 36 { 37 PVDSCRIPTASTFNARG pAstNodeArg = (PVDSCRIPTASTFNARG)pAstNode; 38 if (pAstNodeArg->pType) 39 vdScriptAstNodeFree(&pAstNodeArg->pType->Core); 40 if (pAstNodeArg->pArgIde) 41 vdScriptAstNodeFree(&pAstNodeArg->pArgIde->Core); 42 break; 43 } 44 case VDSCRIPTASTCLASS_IDENTIFIER: 45 break; 46 case VDSCRIPTASTCLASS_DECLARATION: 47 break; 48 case VDSCRIPTASTCLASS_STATEMENT: 49 break; 50 case VDSCRIPTASTCLASS_EXPRESSION: 51 break; 52 case VDSCRIPTASTCLASS_INVALID: 53 default: 54 AssertMsgFailedReturnVoid(("Invalid AST node class given %d\n", pAstNode->enmClass)); 55 } 56 57 RTMemFree(pAstNode); 186 RTLISTANCHOR ListFree; 187 188 /* 189 * The node is not allowed to be part of a list because we need it 190 * for the nodes to free list. 191 */ 192 Assert(RTListIsEmpty(&pAstNode->ListNode)); 193 RTListInit(&ListFree); 194 RTListAppend(&ListFree, &pAstNode->ListNode); 195 196 do 197 { 198 pAstNode = RTListGetFirst(&ListFree, VDSCRIPTASTCORE, ListNode); 199 RTListNodeRemove(&pAstNode->ListNode); 200 201 switch (pAstNode->enmClass) 202 { 203 case VDSCRIPTASTCLASS_FUNCTION: 204 { 205 PVDSCRIPTASTFN pFn = (PVDSCRIPTASTFN)pAstNode; 206 207 if (pFn->pRetType) 208 RTListAppend(&ListFree, &pFn->pRetType->Core.ListNode); 209 if (pFn->pFnIde) 210 RTListAppend(&ListFree, &pFn->pFnIde->Core.ListNode); 211 212 /* Put argument list on the to free list. */ 213 while (!RTListIsEmpty(&pFn->ListArgs)) 214 { 215 PVDSCRIPTASTCORE pArg = RTListGetFirst(&pFn->ListArgs, VDSCRIPTASTCORE, ListNode); 216 RTListNodeRemove(&pArg->ListNode); 217 RTListAppend(&ListFree, &pArg->ListNode); 218 } 219 220 /* Put compound statement onto the list. */ 221 RTListAppend(&ListFree, &pFn->pCompoundStmts->Core.ListNode); 222 break; 223 } 224 case VDSCRIPTASTCLASS_FUNCTIONARG: 225 { 226 PVDSCRIPTASTFNARG pAstNodeArg = (PVDSCRIPTASTFNARG)pAstNode; 227 if (pAstNodeArg->pType) 228 RTListAppend(&ListFree, &pAstNodeArg->pType->Core.ListNode); 229 if (pAstNodeArg->pArgIde) 230 RTListAppend(&ListFree, &pAstNodeArg->pArgIde->Core.ListNode); 231 break; 232 } 233 case VDSCRIPTASTCLASS_IDENTIFIER: 234 break; 235 case VDSCRIPTASTCLASS_DECLARATION: 236 break; 237 case VDSCRIPTASTCLASS_STATEMENT: 238 { 239 vdScriptAstNodeStatmentPutOnFreeList(&ListFree, pAstNode); 240 break; 241 } 242 case VDSCRIPTASTCLASS_EXPRESSION: 243 { 244 vdScriptAStNodeExpressionPutOnFreeList(&ListFree, pAstNode); 245 break; 246 } 247 case VDSCRIPTASTCLASS_INVALID: 248 default: 249 AssertMsgFailedReturnVoid(("Invalid AST node class given %d\n", pAstNode->enmClass)); 250 } 251 252 RTMemFree(pAstNode); 253 } while (!RTListIsEmpty(&ListFree)); 254 58 255 } 59 256 -
trunk/src/VBox/Storage/testcase/VDScriptAst.h
r44840 r44855 121 121 /** Identifier. */ 122 122 VDSCRIPTEXPRTYPE_PRIMARY_IDENTIFIER, 123 /** List of assignment expressions . */123 /** List of assignment expressions as in a = b = c = ... . */ 124 124 VDSCRIPTEXPRTYPE_ASSIGNMENT_LIST, 125 /** Assignment expression. */126 VDSCRIPTEXPRTYPE_ASSIGNMENT,127 125 /** Postfix increment expression. */ 128 126 VDSCRIPTEXPRTYPE_POSTFIX_INCREMENT, … … 315 313 /** Invalid. */ 316 314 VDSCRIPTSTMTTYPE_INVALID = 0, 317 /** Labeled statement. */318 VDSCRIPTSTMTTYPE_LABELED,319 315 /** Compound statement. */ 320 316 VDSCRIPTSTMTTYPE_COMPOUND, … … 357 353 union 358 354 { 359 /** Labeled statement (case, default). */360 struct361 {362 /** Conditional expression, if NULL this is a statement for "default" */363 PVDSCRIPTASTEXPR pCondExpr;364 /** Statement to execute. */365 PVDSCRIPTASTSTMT pExec;366 } Labeled;367 355 /** Compound statement. */ 368 356 struct … … 373 361 RTLISTANCHOR ListStmts; 374 362 } Compound; 375 /** case statement. */363 /** case, default statement. */ 376 364 struct 377 365 {
Note:
See TracChangeset
for help on using the changeset viewer.