|
|
| version 1.49, 2016/07/20 17:27:42 | version 1.52, 2016/09/19 22:27:57 |
|---|---|
| Line 8 | Line 8 |
| #include "pa_vmethod_frame.h" | #include "pa_vmethod_frame.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vbool.h" | #include "pa_vbool.h" |
| #include "pa_vobject.h" | |
| volatile const char * IDENT_REFLECTION_C="$Id$"; | volatile const char * IDENT_REFLECTION_C="$Id$"; |
| Line 51 static void _create(Request& r, MethodPa | Line 52 static void _create(Request& r, MethodPa |
| Value* constructor_value=vclass->get_element(constructor_name); | Value* constructor_value=vclass->get_element(constructor_name); |
| if(!constructor_value || !constructor_value->get_junction()) | if(!constructor_value || !constructor_value->get_junction()) |
| throw Exception(PARSER_RUNTIME, | throw Exception(PARSER_RUNTIME, &constructor_name, "constructor must be declared in class '%s'", vclass->type()); |
| &constructor_name, | |
| "constructor must be declared in class '%s'", | |
| vclass->type()); | |
| Junction* junction=constructor_value->get_junction(); | Junction* junction=constructor_value->get_junction(); |
| const Method* method=junction->method; | const Method* method=junction->method; |
| Line 158 static void _base(Request& r, MethodPara | Line 156 static void _base(Request& r, MethodPara |
| } | } |
| // classes with fields only, like env & console or without base | // classes with fields only, like env & console or without base |
| r.write_no_lang(*VVoid::get()); | r.write_value(*VVoid::get()); |
| } | } |
| Line 193 static void _methods(Request& r, MethodP | Line 191 static void _methods(Request& r, MethodP |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } | } |
| static VJunction &method_junction(Value &self, Method &method, const String *name=0){ | |
| if(method.native_code) | |
| throw Exception(PARSER_RUNTIME, name, "method must not be native"); | |
| if(!(dynamic_cast<VObject*>(&self) || dynamic_cast<VClass*>(&self))) | |
| throw Exception(PARSER_RUNTIME, 0, "self must be parser object or class"); | |
| return *method.get_vjunction(self); | |
| } | |
| static void _method(Request& r, MethodParams& params) { | static void _method(Request& r, MethodParams& params) { |
| Value& o=params.as_no_junction(0, "first param must be object or class, not junction"); | Value &source=*params.get(0); |
| if(Junction *j=source.get_junction()){ | |
| if(Method* method=const_cast<Method*>(j->method)){ | |
| Value& self=params.count()>1 ? params.as_no_junction(1, "self must be object, not junction") : r.get_method_frame()->caller()->self(); | |
| r.write_no_lang(method_junction(self, *method)); | |
| return; | |
| } | |
| throw Exception(PARSER_RUNTIME, 0, "param must be method junction"); | |
| } | |
| if(params.count()==1) | |
| throw Exception(PARSER_RUNTIME, 0, "method name must be specified"); | |
| const String& name=params.as_string(1, "method name must be string"); | const String& name=params.as_string(1, "method name must be string"); |
| if(VStateless_class* vclass=o.get_class()) { | if(VStateless_class* vclass=source.get_class()) { |
| if(Method* method=vclass->get_method(name)) | if(Method* method=vclass->get_method(name)){ |
| r.write_no_lang(*method->get_vjunction(o)); | r.write_no_lang( params.count()>2 ? method_junction(params.as_no_junction(2, "self must be object, not junction"), *method, &name) : *method->get_vjunction(source) ); |
| } else { | return; |
| // class which does not have methods (env, console, etc) | } |
| } | } |
| r.write_value(*VVoid::get()); | |
| } | } |
| static void _fields(Request& r, MethodParams& params) { | static void _fields(Request& r, MethodParams& params) { |
| Line 241 static void _method_info(Request& r, Met | Line 263 static void _method_info(Request& r, Met |
| const String& method_name=params.as_string(1, "method_name must be string"); | const String& method_name=params.as_string(1, "method_name must be string"); |
| Method* method=vclass->get_method(method_name); | Method* method=vclass->get_method(method_name); |
| if(!method) | if(!method) |
| throw Exception(PARSER_RUNTIME, &method_name, "method not found in class %s", class_name.cstr()); | throw Exception(PARSER_RUNTIME, &method_name, "method not found in class '%s'", vclass->type()); |
| VHash& result=*new VHash; | VHash& result=*new VHash; |
| HashStringValue* hash=result.get_hash(); | HashStringValue* hash=result.get_hash(); |
| Line 377 MReflection::MReflection(): Methoded("re | Line 399 MReflection::MReflection(): Methoded("re |
| add_native_method("methods", Method::CT_STATIC, _methods, 1, 1); | add_native_method("methods", Method::CT_STATIC, _methods, 1, 1); |
| // ^reflection:method[object or class;method_name] | // ^reflection:method[object or class;method_name] |
| add_native_method("method", Method::CT_STATIC, _method, 2, 2); | add_native_method("method", Method::CT_STATIC, _method, 1, 3); |
| // ^reflection:method_info[class_name;method_name] | // ^reflection:method_info[class_name;method_name] |
| add_native_method("method_info", Method::CT_STATIC, _method_info, 2, 2); | add_native_method("method_info", Method::CT_STATIC, _method_info, 2, 2); |