|
|
| version 1.32, 2015/04/08 18:08:52 | version 1.38, 2015/10/26 01:21:54 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b reflection parser class. | Parser: @b reflection parser class. |
| Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 160 static void _class_name(Request& r, Meth | Line 160 static void _class_name(Request& r, Meth |
| r.write_no_lang(*get_class_name(¶ms[0])); | r.write_no_lang(*get_class_name(¶ms[0])); |
| } | } |
| static void _class_by_name(Request& r, MethodParams& params) { | |
| const String& class_name=params.as_string(0, "class_name must be string"); | |
| Value* class_value=r.get_class(class_name); | |
| if(!class_value) | |
| throw Exception(PARSER_RUNTIME, &class_name, "class is undefined"); | |
| r.write_no_lang(*class_value); | |
| } | |
| static void _base(Request& r, MethodParams& params) { | static void _base(Request& r, MethodParams& params) { |
| if(VStateless_class* lclass=params[0].get_class()) | if(VStateless_class* lclass=params[0].get_class()) |
| Line 326 static void _dynamical(Request& r, Metho | Line 333 static void _dynamical(Request& r, Metho |
| } | } |
| } | } |
| static void _is(Request& r, MethodParams& params) { | |
| const String& type=params.as_string(0, "class name must be string"); | |
| const String& name=params.as_string(params.count()-1, "element name must be string"); | |
| Value *context=params.count()==3 ? &(params.as_no_junction(1, "context must not be code")) : r.get_method_frame()->caller(); | |
| Value *value=context ? context->get_element(name) : 0; | |
| if(value) { | |
| if(type == "code" || type == "method") { | |
| Junction *junction=value->get_junction(); | |
| r.write_no_lang(VBool::get(junction && ((junction->code==0) ^ (type == "code"))) ); | |
| } else { | |
| r.write_no_lang(VBool::get( value->is(type.cstr()) )); | |
| } | |
| } else | |
| r.write_no_lang(VBool::get(type == "void")); | |
| } | |
| static void _copy(Request& r, MethodParams& params) { | static void _copy(Request& r, MethodParams& params) { |
| HashStringValue* src=params.as_no_junction(0, "source must not be code").get_hash(); | HashStringValue* src=params.as_no_junction(0, "source must not be code").get_hash(); |
| Line 344 static void _uid(Request& r, MethodParam | Line 368 static void _uid(Request& r, MethodParam |
| char local_buf[MAX_NUMBER]; | char local_buf[MAX_NUMBER]; |
| int size=snprintf(local_buf, sizeof(local_buf), "%p", &obj); | int size=snprintf(local_buf, sizeof(local_buf), "%p", &obj); |
| r.write_pass_lang(*new String(pa_strdup(local_buf, (size_t)size), String::L_CLEAN, size)); | r.write_pass_lang(*new String(String::C(pa_strdup(local_buf, (size_t)size), size))); |
| } | } |
| static void _delete(Request&, MethodParams& params) { | static void _delete(Request&, MethodParams& params) { |
| Line 369 MReflection::MReflection(): Methoded("re | Line 393 MReflection::MReflection(): Methoded("re |
| // ^reflection:class_name[object] | // ^reflection:class_name[object] |
| add_native_method("class_name", Method::CT_STATIC, _class_name, 1, 1); | add_native_method("class_name", Method::CT_STATIC, _class_name, 1, 1); |
| // ^reflection:class_by_name[class_name] | |
| add_native_method("class_by_name", Method::CT_STATIC, _class_by_name, 1, 1); | |
| // ^reflection:base_class[object] | // ^reflection:base_class[object] |
| add_native_method("base", Method::CT_STATIC, _base, 1, 1); | add_native_method("base", Method::CT_STATIC, _base, 1, 1); |
| Line 396 MReflection::MReflection(): Methoded("re | Line 423 MReflection::MReflection(): Methoded("re |
| // ^reflection:dynamical[[object or class, caller if absent]] | // ^reflection:dynamical[[object or class, caller if absent]] |
| add_native_method("dynamical", Method::CT_STATIC, _dynamical, 0, 1); | add_native_method("dynamical", Method::CT_STATIC, _dynamical, 0, 1); |
| // ^reflection:is[class_name|code|method;[context;]element_name] | |
| add_native_method("is", Method::CT_STATIC, _is, 2, 3); | |
| // ^reflection:copy[src;dst] | // ^reflection:copy[src;dst] |
| add_native_method("copy", Method::CT_STATIC, _copy, 2, 2); | add_native_method("copy", Method::CT_STATIC, _copy, 2, 2); |