--- parser3/src/classes/op.C 2003/02/20 14:53:33 1.127.2.13 +++ parser3/src/classes/op.C 2003/03/08 16:43:45 1.127.2.21 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_OP_C="$Date: 2003/02/20 14:53:33 $"; +static const char* IDENT_OP_C="$Date: 2003/03/08 16:43:45 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -16,6 +16,7 @@ static const char* IDENT_OP_C="$Date: 20 #include "pa_sql_connection.h" #include "pa_vdate.h" #include "pa_vmethod_frame.h" +#include "pa_vclass.h" // limits @@ -55,7 +56,6 @@ static StringPtr exception_source_part_n static StringPtr exception_comment_part_name(new String(EXCEPTION_COMMENT_PART_NAME)); static StringPtr exception_handled_part_name(new String(EXCEPTION_HANDLED_PART_NAME)); - // helpers class Untaint_lang_name2enum: public Hash { @@ -97,7 +97,7 @@ static void _if(Request& r, StringPtr /* static void _untaint(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); - uchar lang; + String_UL lang; if(params->count()==1) lang=String::UL_AS_IS; // mark as simply 'tainted'. useful in html from sql else { @@ -120,7 +120,7 @@ static void _untaint(Request& r, StringP static void _taint(Request& r, StringPtr /*method_name*/, MethodParams* params) { Pool& pool=r.pool(); - uchar lang; + String_UL lang; if(params->count()==1) lang=String::UL_TAINTED; // mark as simply 'tainted'. useful in table:set else { @@ -145,7 +145,8 @@ static void _taint(Request& r, StringPtr static void _process(Request& r, StringPtr method_name, MethodParams* params) { Pool& pool=r.pool(); - const Method *main_method; + StringPtr source; // must be declared here to prevent premature destruction + MethodPtr main_method; ValuePtr target_self=params->count()>1? params->as_no_junction(0, "target must not be code") :ValuePtr(&r.get_method_frame()->caller()->self()); @@ -159,7 +160,7 @@ static void _process(Request& r, StringP "no target class"); // evaluate source to process - StringPtr source=r.process_to_string(vjunction); + source=r.process_to_string(vjunction); // temporary remove language change Temp_lang temp_lang(r, String::UL_PASS_APPENDED); @@ -178,7 +179,7 @@ static void _process(Request& r, StringP 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())+1; + 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; @@ -191,7 +192,7 @@ static void _process(Request& r, StringP // process source code, append processed methods to 'self' class // maybe-define new @main r.use_buf(*target_class, - source->cstr(String::UL_UNSPECIFIED, r.connection(StringPtr(0))), + source->cstr(pool, String::UL_UNSPECIFIED, r.connection(StringPtr(0))), StringPtr(new String(heap_place, place_size, true /*tainted*/)), heap_place); @@ -508,7 +509,7 @@ StringPtr cache_get(Pool& pool, Charset& return result; } - return 0; + return StringPtr(0); } static time_t as_expires(Request& r, StringPtr method_name, MethodParams* params, int index, time_t now) { @@ -685,17 +686,17 @@ static void _throw_operator(Request& r, if(HashStringValue *hash=param0->get_hash(method_name)) { const char* type=0; if(ValuePtr value=hash->get(exception_type_part_name)) - type=value->as_string(&pool)->cstr(); - StringPtr source(0); + type=value->as_string(&pool)->cstr(pool); + StringPtr source; if(ValuePtr value=hash->get(exception_source_part_name)) source=value->as_string(&pool); - CharPtr comment(0); + CharPtr comment; if(ValuePtr value=hash->get(exception_comment_part_name)) comment=value->as_string(&pool)->cstr(); throw Exception(type, source?source:method_name, - comment); + "%s", comment?comment.get():""); } else throw Exception("parser.runtime", method_name, @@ -705,15 +706,27 @@ static void _throw_operator(Request& r, StringPtr source=params->as_string(1, "source must be string"); CharPtr comment=params->count()>2? params->as_string(2, "comment must be string")->cstr() :CharPtr(0); - throw Exception(type, source, "%s", comment?comment:""); + throw Exception(type, source, "%s", comment?comment.get():""); } } - + +#if defined(WIN32) && defined(_DEBUG) +# define PA_BPT +static void _bpt(Request& r, StringPtr method_name, MethodParams* params) { + _asm int 3; +} +#endif + // constructor VClassMAIN::VClassMAIN(): VClass() { set_name(StringPtr(new String(MAIN_CLASS_NAME))); +#ifdef PA_BPT + // ^bpt[] + add_native_method("bpt", Method::CT_ANY, _bpt, 0, 0); +#endif + // ^if(condition){code-when-true} // ^if(condition){code-when-true}{code-when-false} add_native_method("if", Method::CT_ANY, _if, 2, 3);