--- parser3/src/classes/op.C 2016/09/20 09:55:02 1.232 +++ parser3/src/classes/op.C 2016/10/04 13:23:46 1.236 @@ -18,11 +18,7 @@ #include "pa_vclass.h" #include "pa_charset.h" -volatile const char * IDENT_OP_C="$Id: op.C,v 1.232 2016/09/20 09:55:02 moko Exp $"; - -// limits - -#define MAX_LOOPS 20000 +volatile const char * IDENT_OP_C="$Id: op.C,v 1.236 2016/10/04 13:23:46 moko Exp $"; // defines @@ -118,7 +114,7 @@ static void _untaint(Request& r, MethodP Value& vbody=params.as_junction(params.count()-1, "body must be code"); Temp_lang temp_lang(r, lang); // set temporarily specified ^untaint[language; - StringOrValue result=r.process(vbody); // process marking tainted with that lang + Value& result=r.process(vbody); // process marking tainted with that lang r.write_assign_lang(result); } } @@ -154,7 +150,10 @@ static void _process(Request& r, MethodP if(maybe_target_self.get_string() || maybe_target_self.get_junction()) target_self=&r.get_method_frame()->caller()->self(); else { - target_self=&maybe_target_self; index++; + target_self=&maybe_target_self; + if(params.count()==1) + throw Exception(PARSER_RUNTIME, 0, "no body specified"); + index++; } { @@ -193,7 +192,7 @@ static void _process(Request& r, MethodP line_no_alias_offset=value->as_int(); } else if(key == "replace") { valid_options++; - allow_class_replace=r.process_to_value(*value).as_bool(); + allow_class_replace=r.process(*value).as_bool(); } } @@ -241,15 +240,13 @@ static void _while(Request& r, MethodPar if(delim_maybe_code){ // delimiter set bool need_delim=false; while(true) { - if(++endless_loop_count>=MAX_LOOPS) // endless loop? - throw Exception(PARSER_RUNTIME, - 0, - "endless loop detected"); + if(++endless_loop_count>=pa_loop_limit) // endless loop? + throw Exception(PARSER_RUNTIME, 0, "endless loop detected"); - if(!r.process_to_value(vcondition, false/*don't intercept string*/).as_bool()) + if(!r.process(vcondition, false/*don't intercept string*/).as_bool()) break; - StringOrValue sv_processed=r.process(body_code); + Value& sv_processed=r.process(body_code); Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); const String* s_processed=sv_processed.get_string(); @@ -266,12 +263,10 @@ static void _while(Request& r, MethodPar } } else { while(true) { - if(++endless_loop_count>=MAX_LOOPS) // endless loop? - throw Exception(PARSER_RUNTIME, - 0, - "endless loop detected"); + if(++endless_loop_count>=pa_loop_limit) // endless loop? + throw Exception(PARSER_RUNTIME, 0, "endless loop detected"); - if(!r.process_to_value(vcondition, false/*don't intercept string*/).as_bool()) + if(!r.process(vcondition, false/*don't intercept string*/).as_bool()) break; r.process_write(body_code); @@ -298,7 +293,7 @@ static void _use(Request& r, MethodParam if(key == "replace") { valid_options++; - allow_class_replace=r.process_to_value(*value).as_bool(); + allow_class_replace=r.process(*value).as_bool(); } if(valid_options!=options->count()) @@ -335,10 +330,8 @@ static void _for(Request& r, MethodParam Value& body_code=params.as_junction(3, "body must be code"); Value* delim_maybe_code=params.count()>4?¶ms[4]:0; - if(to-from>=MAX_LOOPS) // too long loop? - throw Exception(PARSER_RUNTIME, - 0, - "endless loop detected"); + if(to-from>=pa_loop_limit) // too long loop? + throw Exception(PARSER_RUNTIME, 0, "endless loop detected"); VInt* vint=new VInt(0); @@ -350,7 +343,7 @@ static void _for(Request& r, MethodParam for(int i=from; i<=to; i++) { vint->set_int(i); - StringOrValue sv_processed=r.process(body_code); + Value& sv_processed=r.process(body_code); Request::Skip lskip=r.get_skip(); r.set_skip(Request::SKIP_NOTHING); const String* s_processed=sv_processed.get_string(); @@ -381,7 +374,7 @@ static void _for(Request& r, MethodParam static void _eval(Request& r, MethodParams& params) { Value& expr=params.as_junction(0, "need expression"); // evaluate expresion - Value& value_result=r.process_to_value(expr, + Value& value_result=r.process(expr, false/*don't intercept string*/).as_expr_result(); if(params.count()>1) { const String& fmt=params.as_string(1, "fmt must be string").trim(); @@ -451,7 +444,7 @@ public: }; #endif static void _switch(Request& r, MethodParams& params) { - Switch_data* data=new Switch_data(r, r.process_to_value(params[0])); + Switch_data* data=new Switch_data(r, r.process(params[0])); Temp_hash_value, void*> switch_data_setter(&r.classes_conf, switch_data_name, data); Value& cases_code=params.as_junction(1, "switch cases must be code"); @@ -484,7 +477,7 @@ static void _case(Request& r, MethodPara #endif for(int i=0; i_default=code; @@ -507,7 +500,7 @@ static void _case(Request& r, MethodPara } #ifndef DOXYGEN struct Try_catch_result { - StringOrValue processed_code; + ValueRef processed_code; const String* exception_should_be_handled; Try_catch_result(): exception_should_be_handled(0) {} @@ -530,7 +523,7 @@ public: /// used by ^try and ^cache, @returns $exception.handled[string] if any template -static Try_catch_result try_catch(Request& r, StringOrValue body_code(Request&, I), I info, Value* catch_code, bool could_be_handled_by_caller=false) { +static Try_catch_result try_catch(Request& r, Value& body_code(Request&, I), I info, Value* catch_code, bool could_be_handled_by_caller=false) { Try_catch_result result; // minor bug: context not restored if only finally code is present, see #1062 @@ -578,7 +571,7 @@ static Try_catch_result try_catch(Reques return result; } -static StringOrValue process_try_body_code(Request& r, Value* body_code) { +static Value& process_try_body_code(Request& r, Value* body_code) { return r.process(*body_code); } @@ -618,8 +611,8 @@ struct Locked_process_and_cache_put_acti -static StringOrValue process_cache_body_code(Request& r, Value* body_code) { - return StringOrValue(r.process_to_string(*body_code)); +static Value& process_cache_body_code(Request& r, Value* body_code) { + return r.process(*body_code); } /* @todo maybe network order worth spending some effort? @@ -646,7 +639,7 @@ static void locked_process_and_cache_put "$" EXCEPTION_VAR_NAME "." EXCEPTION_HANDLED_PART_NAME " value must be " "either boolean or string '" CACHE_EXCEPTION_HANDLED_CACHE_NAME "'"); } else - info.processed_code=&result.processed_code.as_string(); + info.processed_code=&((Value &)result.processed_code).as_string(); // expiration time not spoiled by ^cache(0) or something? if(info.scope->expires > time(0)) { @@ -818,8 +811,7 @@ static void _cache(Request& r, MethodPar Try_catch_result result=try_catch(r, process_try_body_code, &body_code, catch_code); r.write_assign_lang(result.processed_code); } else { - const String& processed_body=r.process_to_string(body_code); - r.write_assign_lang(processed_body); + r.write_assign_lang(r.process_to_string(body_code)); } } @@ -829,7 +821,6 @@ static void _try_operator(Request& r, Me Value* finally_code=(params.count()==3) ? ¶ms.as_junction(2, "finally_code must be code") : 0; Try_catch_result result; - StringOrValue finally_result; try{ // process try and catch code @@ -838,7 +829,7 @@ static void _try_operator(Request& r, Me // process finally code but ignore the result if(finally_code){ Temp_skip temp(r); - finally_result=r.process(*finally_code); + Value &finally_result=r.process(*finally_code); } rethrow; } @@ -846,17 +837,18 @@ static void _try_operator(Request& r, Me // process finally code if(finally_code){ Temp_skip temp(r); - finally_result=r.process(*finally_code); - } - - // no exception in try, catch or finally, writing the result + Value& finally_result=r.process(*finally_code); - // write out processed body_code or catch_code - r.write_pass_lang(result.processed_code); + // no exception in try/catch or finally, writing processed body_code or catch_code + r.write_pass_lang(result.processed_code); - // write out processed finally code - if(finally_code) + // write out processed finally code r.write_pass_lang(finally_result); + } else { + // no exception in try/catch, writing processed body_code or catch_code + r.write_pass_lang(result.processed_code); + } + } static void _throw_operator(Request&, MethodParams& params) {