vbscript: Added support for exit for statement in 'for in' loops.

This commit is contained in:
Jacek Caban 2012-07-03 19:18:00 +02:00 committed by Alexandre Julliard
parent f8deed7c2f
commit 00dfcb08b8
2 changed files with 15 additions and 5 deletions

View File

@ -650,7 +650,8 @@ static HRESULT compile_dowhile_statement(compile_ctx_t *ctx, while_statement_t *
static HRESULT compile_foreach_statement(compile_ctx_t *ctx, foreach_statement_t *stat) static HRESULT compile_foreach_statement(compile_ctx_t *ctx, foreach_statement_t *stat)
{ {
unsigned loop_start, loop_end; statement_ctx_t loop_ctx = {1};
unsigned loop_start;
HRESULT hres; HRESULT hres;
hres = compile_expression(ctx, stat->group_expr); hres = compile_expression(ctx, stat->group_expr);
@ -661,14 +662,14 @@ static HRESULT compile_foreach_statement(compile_ctx_t *ctx, foreach_statement_t
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
loop_start = ctx->instr_cnt; loop_start = ctx->instr_cnt;
if(!(loop_end = alloc_label(ctx))) if(!(loop_ctx.for_end_label = alloc_label(ctx)))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
hres = push_instr_uint_bstr(ctx, OP_enumnext, loop_end, stat->identifier); hres = push_instr_uint_bstr(ctx, OP_enumnext, loop_ctx.for_end_label, stat->identifier);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
hres = compile_statement(ctx, NULL, stat->body); hres = compile_statement(ctx, &loop_ctx, stat->body);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
@ -676,7 +677,7 @@ static HRESULT compile_foreach_statement(compile_ctx_t *ctx, foreach_statement_t
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
label_set_addr(ctx, loop_end); label_set_addr(ctx, loop_ctx.for_end_label);
return S_OK; return S_OK;
} }

View File

@ -431,6 +431,15 @@ next
Call ok(y = 3, "y = " & y) Call ok(y = 3, "y = " & y)
Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x)) Call ok(getVT(x) = "VT_EMPTY*", "getVT(x) = " & getVT(x))
Call collectionObj.reset()
y = false
for each x in collectionObj
if x = 2 then exit for
y = 1
next
Call ok(y = 1, "y = " & y)
Call ok(x = 2, "x = " & x)
if false then if false then
Sub testsub Sub testsub
x = true x = true