--- parser3/src/classes/reflection.C 2016/12/02 17:39:29 1.74 +++ parser3/src/classes/reflection.C 2016/12/08 21:05:43 1.78 @@ -10,7 +10,7 @@ #include "pa_vbool.h" #include "pa_vobject.h" -volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.74 2016/12/02 17:39:29 moko Exp $"; +volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.78 2016/12/08 21:05:43 moko Exp $"; static const String class_type_methoded("methoded"); @@ -51,7 +51,7 @@ static void _create(Request& r, MethodPa const String* class_name=0; const String* constructor_name=0; - Value& voptions=params.as_no_junction(0, "params must not be code"); + Value& voptions=params.as_no_junction(0, "param must not be code"); if(HashStringValue* options=voptions.get_hash()) { int valid_options=0; if(Value* vclass_name=options->get("class")) { @@ -78,7 +78,7 @@ static void _create(Request& r, MethodPa params_offset=1; } else { - class_name=¶ms.as_string(0, "param must be string or hash"); + class_name=¶ms.as_string(0, "param must not be code"); if(params.count()==1) throw Exception(PARSER_RUNTIME, 0, "constructor name must be specified"); @@ -497,6 +497,39 @@ static void _mixin(Request& r, MethodPar } } +String::Language get_untaint_lang(const String& lang_name); // op.C + +static void _tainting(Request& r, MethodParams& params) { + const String& str=params.as_string(params.count()-1, "param must be string"); + String::Language lang = String::L_UNSPECIFIED; + bool optimized=false; + + if(params.count()==2){ + const String& slang=params.as_string(0, "language name must be string"); + if(slang == "optimized") + optimized=true; + else if(slang == "tainted") + lang=String::L_TAINTED; + else lang=get_untaint_lang(slang); + } + + if(!str.is_empty()){ + char *visual=str.visualize_langs(); + + if(optimized){ + for(char *c=visual; *c; c++) + *c = *c<0 ? '+':'-'; + } else if(lang != String::L_UNSPECIFIED){ + for(char *c=visual; *c; c++) + *c = *c==lang ? '+':'-'; + } else { + for(char *c=visual; *c; c++) + *c = *c & 0x7F; + } + + r.write(*new String(visual)); + } +} // constructor MReflection::MReflection(): Methoded("reflection") { @@ -566,4 +599,7 @@ MReflection::MReflection(): Methoded("re // ^reflection:mixin[object or class or junction;options] add_native_method("mixin", Method::CT_STATIC, _mixin, 1, 2); + // ^reflection:tainting[[language or 'tainted' or 'optimized';]string] + add_native_method("tainting", Method::CT_STATIC, _tainting, 1, 2); + }