--- parser3/src/main/execute.C 2005/07/26 12:54:09 1.309 +++ parser3/src/main/execute.C 2007/10/17 08:00:38 1.317 @@ -1,11 +1,11 @@ /** @file Parser: executor part of request class. - Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_EXECUTE_C="$Date: 2005/07/26 12:54:09 $"; +static const char * const IDENT_EXECUTE_C="$Date: 2007/10/17 08:00:38 $"; #include "pa_opcode.h" #include "pa_array.h" @@ -113,6 +113,8 @@ void Request::execute(ArrayOperation& op debug_printf(sapi_info, "execution-------------------------\n"); #endif for(Array_iterator i(ops); i.has_next(); ) { + if(get_skip()) + return; if(get_interrupted()) { set_interrupted(false); throw Exception("parser.interrupted", @@ -145,7 +147,7 @@ void Request::execute(ArrayOperation& op const String& name=stack.pop().string(); Value* value=classes().get(name); if(!value) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, &name, "class is undefined"); @@ -172,7 +174,7 @@ void Request::execute(ArrayOperation& op case OP_WITH_WRITE: { if(wcontext==method_frame) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "$.name outside of $name[...]"); @@ -209,18 +211,18 @@ void Request::execute(ArrayOperation& op debug_printf(sapi_info, " (%d)\n", local_ops.count()); debug_dump(sapi_info, 1, local_ops); #endif - Value& value=*new VJunction(new Junction( + Value& value=*new VJunction( get_self(), 0, method_frame, rcontext, wcontext, - &local_ops)); + &local_ops); const String& name=stack.pop().string(); debug_name=&name; Value& ncontext=stack.pop().value(); - if(const Junction* junction=ncontext.put_element(name, &value, false)) - if(junction!=PUT_ELEMENT_REPLACED_ELEMENT) - throw Exception("parser.runtime", + if(const VJunction* vjunction=ncontext.put_element(ncontext, name, &value, false)) + if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) + throw Exception(PARSER_RUNTIME, 0, "property value can not be code, use [] or () brackets"); @@ -357,12 +359,12 @@ void Request::execute(ArrayOperation& op // hence, we zero junction.wcontext here, and later // in .process we would test that field // in decision "which wwrapper to use" - Value& value=*new VJunction(new Junction( + Value& value=*new VJunction( get_self(), 0, method_frame, rcontext, opcode==OP_EXPR_CODE__STORE_PARAM?0:wcontext, - &local_ops)); + &local_ops); // store param // this op is executed from CALL local_ops only, so can not check method_frame_to_fill==0 frame.store_param(value); @@ -398,11 +400,11 @@ void Request::execute(ArrayOperation& op Junction* junction=value.get_junction(); if(!junction) { if(value.is("void")) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "undefined method"); else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "is '%s', not a method or junction, can not call it", value.type()); @@ -414,7 +416,7 @@ void Request::execute(ArrayOperation& op // $junction{code} // ^junction[] if(!junction->method) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, "is '%s', it is code junction, can not call it", value.type()); @@ -439,11 +441,12 @@ void Request::execute(ArrayOperation& op if(frame.junction.method->call_type!=Method::CT_STATIC) { // this is a constructor call - if(Value* value=called_class.create_new_value(fpool)) { + HashStringValue& new_object_fields=*new HashStringValue(); + if(Value* value=called_class.create_new_value(fpool, new_object_fields)) { // some stateless_class creatable derivates new_self=value; } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, //&frame.name(), "is not a constructor, system class '%s' can be constructed only implicitly", called_class.name().cstr()); @@ -452,7 +455,7 @@ void Request::execute(ArrayOperation& op String::L_CLEAN // not used, always an object, not string ); } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, //&frame.name(), "method is static and can not be used as constructor"); } else @@ -482,7 +485,7 @@ void Request::execute(ArrayOperation& op } else // parser code, execute it recoursion_checked_execute(*method.parser_code); } else - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, //&frame.name(), "is not allowed to be called %s", call_type==Method::CT_STATIC?"statically":"dynamically"); @@ -547,14 +550,14 @@ void Request::execute(ArrayOperation& op case OP_FEXISTS: { Value& a=stack.pop().value(); - Value& value=*new VBool(file_readable(absolute(a.as_string()))); + Value& value=*new VBool(file_exist(absolute(a.as_string()))); stack.push(value); break; } case OP_DEXISTS: { Value& a=stack.pop().value(); - Value& value=*new VBool(dir_readable(absolute(a.as_string()))); + Value& value=*new VBool(dir_exists(absolute(a.as_string()))); stack.push(value); break; } @@ -836,7 +839,7 @@ Value& Request::get_element(Value& ncont Value* value=0; if(can_call_operator) { if(Method* method=main_class.get_method(name)) // looking operator of that name FIRST - value=new VJunction(new Junction(main_class, method)); + value=new VJunction(main_class, method); } if(!value) { if(!wcontext->get_constructing() // not constructing @@ -856,7 +859,7 @@ Value& Request::get_element(Value& ncont if(value && wcontext->get_constructing()) if(Junction* junction=value->get_junction()) { if(junction->self.get_class()!=&ncontext) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, &name, "constructor must be declared in class '%s'", ncontext.get_class()->name_cstr()); @@ -873,17 +876,18 @@ value_ready: void Request::put_element(Value& ncontext, const String& name, Value& value) { // put_element can return property-setting-junction - if(const Junction* junction=ncontext.put_element(name, &value, false)) - if(junction!=PUT_ELEMENT_REPLACED_ELEMENT) { + if(const VJunction* vjunction=ncontext.put_element(ncontext, name, &value, false)) + if(vjunction!=PUT_ELEMENT_REPLACED_ELEMENT) { + const Junction& junction=vjunction->junction(); // process it - ArrayString* params_names=junction->method->params_names; + ArrayString* params_names=junction.method->params_names; int param_count=params_names? params_names->count(): 0; if(param_count!=1) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "setter method must have ONE parameter (has %d parameters)", param_count); - VMethodFrame frame(*junction, method_frame/*caller*/); + VMethodFrame frame(junction, method_frame/*caller*/); frame.store_param(value); frame.set_self(frame.junction.self); @@ -895,7 +899,7 @@ void Request::put_element(Value& ncontex rcontext=wcontext=&frame; method_frame=&frame; - // prevent non-string writes for better error reporting + // prevent non-string writes for better error reporting [setters are not expected to return anything] wcontext->write(*method_frame); recoursion_checked_execute(*frame.junction.method->parser_code); // parser code, execute it @@ -924,12 +928,13 @@ StringOrValue Request::process(Value& in if(junction->is_getter) { // is it a getter-junction? // process it - VMethodFrame frame(*junction, method_frame/*caller*/); if(junction->method->params_names) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "getter method must have no parameters"); + VMethodFrame frame(*junction, method_frame/*caller*/); + frame.set_self(frame.junction.self); VMethodFrame *saved_method_frame=method_frame; @@ -957,7 +962,7 @@ StringOrValue Request::process(Value& in #endif if(!junction->method_frame) - throw Exception("parser.runtime", + throw Exception(PARSER_RUNTIME, 0, "junction used outside of context"); @@ -1038,6 +1043,7 @@ StringOrValue Request::execute_method(VM const String* Request::execute_method(Value& aself, const Method& method, VString* optional_param, bool do_return_string) { + VMethodFrame *saved_method_frame=method_frame; Value* saved_rcontext=rcontext; WContext *saved_wcontext=wcontext; @@ -1072,13 +1078,13 @@ const String* Request::execute_method(Va Request::Execute_nonvirtual_method_result Request::execute_nonvirtual_method(VStateless_class& aclass, - const String& method_name, VString* optional_param, + const String& method_name, + VString* optional_param, bool do_return_string) { Execute_nonvirtual_method_result result; result.method=aclass.get_method(method_name); if(result.method) - result.string=execute_method(aclass, *result.method, optional_param, - do_return_string); + result.string=execute_method(aclass, *result.method, optional_param, do_return_string); return result; }