--- parser3/src/classes/hash.C 2007/12/28 11:23:13 1.82 +++ parser3/src/classes/hash.C 2008/05/15 09:33:37 1.84 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_HASH_C="$Date: 2007/12/28 11:23:13 $"; +static const char * const IDENT_HASH_C="$Date: 2008/05/15 09:33:37 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -342,6 +342,7 @@ struct Foreach_info { Value* body_code; Value* delim_maybe_code; + Value* var_context; VString* vkey; bool need_delim; }; @@ -351,18 +352,21 @@ static bool one_foreach_cycle( HashStringValue::value_type avalue, Foreach_info *info) { info->vkey->set_string(*new String(akey, String::L_TAINTED)); - Value& ncontext=*info->r->get_method_frame()->caller(); - ncontext.put_element(ncontext, *info->key_var_name, info->vkey, false); - ncontext.put_element(ncontext, *info->value_var_name, avalue, false); + Value& var_context=*info->var_context; + var_context.put_element(var_context, *info->key_var_name, info->vkey, false); + var_context.put_element(var_context, *info->value_var_name, avalue, false); StringOrValue sv_processed=info->r->process(*info->body_code); Request::Skip lskip=info->r->get_skip(); info->r->set_skip(Request::SKIP_NOTHING); + const String* s_processed=sv_processed.get_string(); if(info->delim_maybe_code && s_processed && s_processed->length()) { // delimiter set and we have body if(info->need_delim) // need delim & iteration produced string? info->r->write_pass_lang(info->r->process(*info->delim_maybe_code)); - info->need_delim=true; + else + info->need_delim=true; } + info->r->write_pass_lang(sv_processed); return lskip==Request::SKIP_BREAK; @@ -376,9 +380,10 @@ static void _foreach(Request& r, MethodP ¶ms.as_string(0, "key-var name must be string"), ¶ms.as_string(1, "value-var name must be string"), ¶ms.as_junction(2, "body must be code"), - params.count()>3?params.get(3):0, + /*delimiter*/params.count()>3?params.get(3):0, + /*var_context*/r.get_method_frame()->caller(), /*vkey=*/new VString, - false + /*need_delim*/false }; VHash& self=GET_SELF(r, VHash);