--- parser3/src/classes/reflection.C 2024/10/02 22:54:02 1.92 +++ parser3/src/classes/reflection.C 2024/12/23 16:59:17 1.97 @@ -1,16 +1,17 @@ /** @file Parser: @b reflection parser class. - Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ #include "pa_vmethod_frame.h" #include "pa_request.h" #include "pa_vbool.h" +#include "pa_varray.h" #include "pa_vobject.h" -volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.92 2024/10/02 22:54:02 moko Exp $"; +volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.97 2024/12/23 16:59:17 moko Exp $"; static const String class_type_methoded("methoded"); @@ -26,6 +27,7 @@ static const String method_overridden("o static const String method_min_params("min_params"); static const String method_max_params("max_params"); static const String method_extra_param("extra_param"); +static const String method_named_params("named_params"); static const String def_class("class"); @@ -197,7 +199,7 @@ static void _def(Request& r, MethodParam // can't use get_class because it will call @autouse[] if the class wasn't loaded r.write(VBool::get(r.classes().get(name)!=0)); } else { - throw Exception(PARSER_RUNTIME, &type, "is invalid type, must be '%s'", def_class.cstr()); + throw Exception(PARSER_RUNTIME, &type, "is an invalid type, must be '%s'", def_class.cstr()); } } @@ -256,7 +258,7 @@ static void _method(Request& r, MethodPa if(Junction *j=source.get_junction()){ if(Method* method=const_cast(j->method)){ - Value& self=params.count()>1 ? params.as_no_junction(1, "self must be object, not junction") : r.get_method_frame()->caller()->self(); + Value& self=params.count()>1 ? params.as_no_junction(1, "self must be object") : r.get_method_frame()->caller()->self(); r.write(method_junction(self, *method)); return; } @@ -270,7 +272,7 @@ static void _method(Request& r, MethodPa if(VStateless_class* vclass=source.get_class()) { if(Method* method=vclass->get_method(name)){ - r.write( params.count()>2 ? method_junction(params.as_no_junction(2, "self must be object, not junction"), *method) : *method->get_vjunction(source) ); + r.write( params.count()>2 ? method_junction(params.as_no_junction(2, "self must be object"), *method) : *method->get_vjunction(source) ); return; } } @@ -278,7 +280,7 @@ static void _method(Request& r, MethodPa } static void _fields(Request& r, MethodParams& params) { - Value& o=params.as_no_junction(0, "param must be object or class, not junction"); + Value& o=params.as_no_junction(0, "param must be object or class"); if(HashStringValue* fields=o.get_fields()) r.write(*new VHash(*fields)); @@ -287,7 +289,7 @@ static void _fields(Request& r, MethodPa } static void _fields_reference(Request& r, MethodParams& params) { - Value& o=params.as_no_junction(0, "param must be object or hash, not junction"); + Value& o=params.as_no_junction(0, "param must be object or hash"); if(HashStringValue* fields=o.get_fields_reference()) r.write(*new VHashReference(*fields)); @@ -296,7 +298,7 @@ static void _fields_reference(Request& r } static void _field(Request& r, MethodParams& params) { - Value& o=params.as_no_junction(0, "first param must be object or class, not junction"); + Value& o=params.as_no_junction(0, "first param must be object or class"); const String& name=params.as_string(1, "field name must be string"); if(HashStringValue* fields=o.get_fields()) @@ -361,7 +363,7 @@ static void _method_info(Request& r, Met if( filespec ) hash->put("file", new VString(*filespec)); - hash->put(method_max_params, new VInt(method->params_names ? method->params_names->count() : 0)); + hash->put(method_max_params, new VInt(method->params_count + (method->named_params ? 1 : 0))); if(method->params_names) for(size_t i=0; iparams_names->count(); i++) @@ -369,6 +371,17 @@ static void _method_info(Request& r, Met if(method->extra_params) hash->put(method_extra_param, new VString(*method->extra_params)); + if(method->named_params){ + size_t named_count=method->named_params->count(); + VArray& named_params=*new VArray(named_count); + ArrayValue &array=named_params.array(); + + for(size_t i=0; inamed_params)[i]; + array+=new VString(fname); + } + hash->put(method_named_params, &named_params); + } } r.write(result); @@ -438,7 +451,7 @@ static void _uid(Request& r, MethodParam } static void _delete(Request&, MethodParams& params) { - Value* v=¶ms.as_no_junction(0, "param must be object or class, not junction"); + Value* v=¶ms.as_no_junction(0, "param must be object or class"); const String& key=params.as_string(1, "field name must be string"); if(VObject* o=dynamic_cast(v)){