--- parser3/src/classes/reflection.C 2024/11/04 03:53:25 1.94 +++ parser3/src/classes/reflection.C 2025/05/26 00:52:15 1.98 @@ -8,9 +8,10 @@ #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.94 2024/11/04 03:53:25 moko Exp $"; +volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.98 2025/05/26 00:52:15 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"); @@ -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()) @@ -359,16 +361,27 @@ static void _method_info(Request& r, Met // parser code const String* filespec = r.get_method_filespec(method); if( filespec ) - hash->put("file", new VString(*filespec)); + HASH_PUT_CSTR(*hash, "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++) - hash->put(pa_uitoa(i), new VString(*method->params_names->get(i))); + hash->put(String::Body::uitoa(i), new VString(*method->params_names->get(i))); 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)){ @@ -612,8 +625,8 @@ static void _stack(Request& r, MethodPar if(!method.native_code){ Operation::Origin origin=r.get_method_origin(&method); if(origin.file_no){ - current->put("file", new VString(*r.get_used_filespec(origin.file_no))); - current->put("line", new VInt(origin.line)); // no +1 as declaration before first command + HASH_PUT_CSTR(*current, "file", new VString(*r.get_used_filespec(origin.file_no))); + HASH_PUT_CSTR(*current, "line", new VInt(origin.line)); // no +1 as declaration before first command } if(show_args || show_locals){ @@ -632,7 +645,7 @@ static void _stack(Request& r, MethodPar args->put(*method.extra_params, caller->get_element(*method.extra_params)); if(show_args) - current->put("args", &vargs); + HASH_PUT_CSTR(*current, "args", &vargs); if(show_locals){ VHash& vlocals=*new VHash; @@ -647,12 +660,12 @@ static void _stack(Request& r, MethodPar } } - current->put("locals", &vlocals); + HASH_PUT_CSTR(*current, "locals", &vlocals); } } } - result->put(pa_uitoa(index), &vcurrent); + result->put(String::Body::uitoa(index), &vcurrent); } caller=caller->caller(); index++;