Changeset 44962 in vbox for trunk/src/VBox/Storage
- Timestamp:
- Mar 7, 2013 9:37:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/testcase/VDScriptInterp.cpp
r44941 r44962 146 146 PVDSCRIPTASTSTMT pStmtCurr; 147 147 } Compound; 148 /** Pointer to an AST node. */ 149 PVDSCRIPTASTCORE pAstNode; 148 150 } Ctrl; 149 151 }; … … 195 197 vdScriptStackPush(&pThis->StackValues); 196 198 return VINF_SUCCESS; 199 } 200 201 /** 202 * Pushes an AST node onto the control stack. 203 * 204 * @returns VBox status code. 205 * @param pThis The interpreter context. 206 * @param enmCtrlType The control entry type. 207 */ 208 DECLINLINE(int) vdScriptInterpreterPushAstEntry(PVDSCRIPTINTERPCTX pThis, 209 PVDSCRIPTASTCORE pAstNode) 210 { 211 PVDSCRIPTINTERPCTRL pCtrl = NULL; 212 213 pCtrl = (PVDSCRIPTINTERPCTRL)vdScriptStackGetUnused(&pThis->StackCtrl); 214 215 if (pCtrl) 216 { 217 pCtrl->fEvalAst = true; 218 pCtrl->pAstNode = pAstNode; 219 vdScriptStackPush(&pThis->StackCtrl); 220 return VINF_SUCCESS; 221 } 222 223 return vdScriptInterpreterError(pThis, VERR_NO_MEMORY, RT_SRC_POS, "Out of memory adding an entry on the control stack"); 197 224 } 198 225 … … 247 274 248 275 /** 249 * Pushes a n AST node onto the controlstack.276 * Pushes a while statement control entry onto the stack. 250 277 * 251 278 * @returns VBox status code. 252 279 * @param pThis The interpreter context. 253 * @param enmCtrlType The control entry type.254 */ 255 DECLINLINE(int) vdScriptInterpreterPush AstEntry(PVDSCRIPTINTERPCTX pThis,256 PVDSCRIPTASTCORE pAstNode) 257 { 280 * @param pStmt The while statement. 281 */ 282 DECLINLINE(int) vdScriptInterpreterPushWhileCtrlEntry(PVDSCRIPTINTERPCTX pThis, PVDSCRIPTASTSTMT pStmt) 283 { 284 int rc = VINF_SUCCESS; 258 285 PVDSCRIPTINTERPCTRL pCtrl = NULL; 259 286 260 287 pCtrl = (PVDSCRIPTINTERPCTRL)vdScriptStackGetUnused(&pThis->StackCtrl); 261 262 288 if (pCtrl) 263 289 { 264 pCtrl->fEvalAst = true; 265 pCtrl->pAstNode = pAstNode; 290 pCtrl->fEvalAst = false; 291 pCtrl->Ctrl.enmCtrlType = VDSCRIPTINTERPCTRLTYPE_WHILE; 292 pCtrl->Ctrl.pAstNode = &pStmt->Core; 266 293 vdScriptStackPush(&pThis->StackCtrl); 267 return VINF_SUCCESS; 268 } 269 270 return vdScriptInterpreterError(pThis, VERR_NO_MEMORY, RT_SRC_POS, "Out of memory adding an entry on the control stack"); 294 295 rc = vdScriptInterpreterPushAstEntry(pThis, &pStmt->While.pCond->Core); 296 if ( RT_SUCCESS(rc) 297 && pStmt->While.fDoWhile) 298 { 299 /* Push the statement to execute for do ... while loops because they run at least once. */ 300 rc = vdScriptInterpreterPushAstEntry(pThis, &pStmt->While.pStmt->Core); 301 if (RT_FAILURE(rc)) 302 { 303 /* Cleanup while control statement and AST node. */ 304 vdScriptStackPop(&pThis->StackCtrl); 305 vdScriptStackPop(&pThis->StackCtrl); 306 } 307 } 308 else if (RT_FAILURE(rc)) 309 vdScriptStackPop(&pThis->StackCtrl); /* Cleanup the while control statement. */ 310 } 311 else 312 rc = vdScriptInterpreterError(pThis, VERR_NO_MEMORY, RT_SRC_POS, "Out of memory adding an entry on the control stack"); 313 314 return rc; 271 315 } 272 316 … … 494 538 case VDSCRIPTSTMTTYPE_IF: 495 539 case VDSCRIPTSTMTTYPE_SWITCH: 540 AssertMsgFailed(("TODO\n")); 541 break; 496 542 case VDSCRIPTSTMTTYPE_WHILE: 543 { 544 rc = vdScriptInterpreterPushWhileCtrlEntry(pThis, pStmt); 545 break; 546 } 497 547 case VDSCRIPTSTMTTYPE_FOR: 498 548 case VDSCRIPTSTMTTYPE_CONTINUE: … … 501 551 case VDSCRIPTSTMTTYPE_CASE: 502 552 case VDSCRIPTSTMTTYPE_DEFAULT: 553 AssertMsgFailed(("TODO\n")); 554 break; 503 555 default: 504 556 AssertMsgFailed(("Invalid statement type: %d\n", pStmt->enmStmtType)); … … 699 751 break; 700 752 } 753 case VDSCRIPTINTERPCTRLTYPE_WHILE: 754 { 755 PVDSCRIPTASTSTMT pWhileStmt = (PVDSCRIPTASTSTMT)pCtrl->Ctrl.pAstNode; 756 757 /* Check whether the condition passed. */ 758 VDSCRIPTARG Cond; 759 vdScriptInterpreterPopValue(pThis, &Cond); 760 AssertMsg(Cond.enmType == VDSCRIPTTYPE_BOOL, 761 ("Value on stack is not of boolean type\n")); 762 763 if (Cond.f) 764 { 765 /* Execute the loop another round. */ 766 rc = vdScriptInterpreterPushAstEntry(pThis, &pWhileStmt->While.pCond->Core); 767 if (RT_SUCCESS(rc)) 768 { 769 rc = vdScriptInterpreterPushAstEntry(pThis, &pWhileStmt->While.pStmt->Core); 770 if (RT_FAILURE(rc)) 771 vdScriptStackPop(&pThis->StackCtrl); 772 } 773 } 774 else 775 vdScriptStackPop(&pThis->StackCtrl); /* Remove while control statement. */ 776 break; 777 } 701 778 default: 702 779 AssertMsgFailed(("Invalid evaluation control type on the stack: %d\n",
Note:
See TracChangeset
for help on using the changeset viewer.