--- parser3/src/classes/op.C 2003/03/24 14:53:55 1.127.2.22.2.16 +++ parser3/src/classes/op.C 2003/04/03 10:18:24 1.127.2.22.2.26 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_OP_C="$Date: 2003/03/24 14:53:55 $"; +static const char* IDENT_OP_C="$Date: 2003/04/03 10:18:24 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -31,7 +31,6 @@ static const char* IDENT_OP_C="$Date: 20 class VClassMAIN: public VClass { public: VClassMAIN(); - override ~VClassMAIN() {} }; // defines for statics @@ -39,10 +38,6 @@ public: #define SWITCH_DATA_NAME "SWITCH-DATA" #define CACHE_DATA_NAME "CACHE-DATA" #define EXCEPTION_VAR_NAME "exception" -#define EXCEPTION_TYPE_PART_NAME "type" -#define EXCEPTION_SOURCE_PART_NAME "source" -#define EXCEPTION_COMMENT_PART_NAME "comment" -#define EXCEPTION_HANDLED_PART_NAME "handled" // statics @@ -52,10 +47,6 @@ static const String switch_data_name(SWI static const String cache_data_name(CACHE_DATA_NAME); static const String exception_var_name(EXCEPTION_VAR_NAME); -static const String exception_type_part_name(EXCEPTION_TYPE_PART_NAME); -static const String exception_source_part_name(EXCEPTION_SOURCE_PART_NAME); -static const String exception_comment_part_name(EXCEPTION_COMMENT_PART_NAME); -static const String exception_handled_part_name(EXCEPTION_HANDLED_PART_NAME); // helpers @@ -147,16 +138,11 @@ static void _process(Request& r, MethodP params->as_no_junction(0, "target must not be code") :r.get_method_frame()->caller()->self(); { - Value& vjunction=params->as_junction(params->count()-1, "body must be code"); - VStateless_class *target_class=target_self.get_last_derived_class(); if(!target_class) throw Exception("parser.runtime", 0, "no target class"); - - // evaluate source to process - const String& source=r.process_to_string(vjunction); // temporary remove language change Temp_lang temp_lang(r, String::L_PASS_APPENDED); @@ -164,34 +150,18 @@ static void _process(Request& r, MethodP Temp_method temp_method_main(*target_class, main_method_name, 0); // temporary zero @auto so it wouldn't be auto-called in Request::use_buf Temp_method temp_method_auto(*target_class, auto_method_name, 0); -#ifdef LATER - // calculate pseudo file name of processed chars - // would be something like "/some/file(4) process" - char local_place[MAX_STRING]; -#ifndef NO_STRING_ORIGIN - const String_fragment::Origin& source_origin=source->origin(); - const String_fragment::Origin& method_origin=method_name->origin(); - size_t place_size; - if(source_origin.file==method_origin.file) - place_size=snprintf(local_place, MAX_STRING, "%s(%d) %s", // same file - source_origin.file?source_origin.file:"unknown_file", 1+source_origin.line, - method_name->cstr().get())+1; - else // different files ^process{external__file_text__or__sql} - place_size=snprintf(local_place, MAX_STRING, "%s", - source_origin.file?source_origin.file:"unknown_file")+1; -#else - strncpy(local_place, method_name->cstr(), MAX_STRING-1); place[MAX_STRING-1]=0; - size_t place_size=strlen(local_place)+1; -#endif - char *heap_place=pool.copy(local_place, place_size); -#endif - // process source code, append processed methods to 'self' class - // maybe-define new @main - r.use_buf(*target_class, - source.cstr(String::L_UNSPECIFIED, r.connection()), - *new String("later"), //new String(heap_place, place_size, true /*tainted*/), - "later"); //heap_place); - + + if(const String* file_name=params->last().get_string()) { // ^process...[file] + r.use_file(*target_class, r.absolute(*file_name), true/*ignore_class_path*/); + } else { // process...{string} + Value& vjunction=params->as_junction(params->count()-1, "body must be code"); + // evaluate source to process + const String& source=r.process_to_string(vjunction); + r.use_buf(*target_class, + source.cstr(String::L_UNSPECIFIED, r.connection(false)), + pseudo_file_no__process); + } + // main_method main_method=target_class->get_method(main_method_name); } @@ -269,7 +239,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_to_value(expr, /*0/*no name YET* /,*/ true/*don't intercept string*/).as_expr_result(); if(params->count()>1) { @@ -413,7 +383,6 @@ class Cache_data: public PA_Object { public: time_t expires; }; -DECLARE_OBJECT_PTR(Cache_data); struct Locked_process_and_cache_put_action_info { Request *r; Cache_data *data; @@ -588,25 +557,9 @@ static void _cache(Request& r, MethodPar // never reached } -// also used in pa_request.C to pass param to @unhandled_exception -VHash& exception2vhash(const Exception& e) { - VHash& result=*new VHash; - HashStringValue& hash=result.hash(); - if(const char* type=e.type(true)) - hash.put(exception_type_part_name, new VString(*new String(type))); - if(const String* asource=e.problem_source()) { - String& source=*new String; - source.append(*asource, String::L_TAINTED, true/*forced*/); - - hash.put(exception_source_part_name, new VString(source)); - } - if(const char* comment=e.comment(true)) - hash.put(exception_comment_part_name, - new VString(*new String(comment, 0, true/*tainted*/))); - hash.put(exception_handled_part_name, new VBool(false)); - return result; -} + +// also used in pa_request.C to pass param to @unhandled_exception static void _try_operator(Request& r, MethodParams* params) { Value& body_code=params->as_junction(0, "body_code must be code"); @@ -621,22 +574,22 @@ static void _try_operator(Request& r, Me Request_context_saver throw_context(r); // taking snapshot of throw-context [stack trace contains error] try_context.restore(); // restoring try-context to perform catch-code - VHash& vhash=exception2vhash(e); + Request::Exception_details details=r.get_details(e); Junction* junction=catch_code.get_junction(); Value* method_frame=junction->method_frame; Value* saved_exception_var_value=method_frame->get_element(exception_var_name, *method_frame, false); - junction->method_frame->put_element(exception_var_name, &vhash, false); + junction->method_frame->put_element(exception_var_name, &details.vhash, false); result=r.process(catch_code); bool handled=false; if(Value* value= - vhash.hash().get(exception_handled_part_name)) + details.vhash.hash().get(exception_handled_part_name)) handled=value->as_bool(); junction->method_frame->put_element(exception_var_name, saved_exception_var_value, false); if(!handled) { throw_context.restore(); // restoring throw-context [exception were not handled] - throw(e); // rethrow + rethrow; } } // write out result @@ -748,6 +701,5 @@ VClassMAIN::VClassMAIN(): VClass() { // constructor & configurator VStateless_class& VClassMAIN_create() { - return *new VClassMAIN; }