--- parser3/src/classes/reflection.C 2025/10/04 15:51:54 1.99 +++ parser3/src/classes/reflection.C 2026/04/25 13:38:46 1.104 @@ -1,7 +1,7 @@ /** @file Parser: @b reflection parser class. - Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ @@ -11,7 +11,7 @@ #include "pa_varray.h" #include "pa_vobject.h" -volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.99 2025/10/04 15:51:54 moko Exp $"; +volatile const char * IDENT_REFLECTION_C="$Id: reflection.C,v 1.104 2026/04/25 13:38:46 moko Exp $"; static const String class_type_methoded("methoded"); @@ -126,7 +126,7 @@ static void _create(Request& r, MethodPa static void _classes(Request& r, MethodParams&) { VHash& result=*new VHash; - for(HashString::Iterator i(r.classes()); i; i.next()){ + for(OrderedHashString::Iterator i(r.classes()); i; i.next()){ result.hash().put(i.key(), i.value()->get_methods().count()>0 ? new VString(class_type_methoded) : VVoid::get() ); } r.write(result); @@ -475,29 +475,22 @@ static void _mixin(Request& r, MethodPar if(params.count()>1) if(HashStringValue* options=params.as_hash(1, "mixin options")) { - int valid_options=0; for(HashStringValue::Iterator i(*options); i; i.next() ){ String::Body key=i.key(); Value* value=i.value(); if(key == "to") { vtarget=value; - valid_options++; } else if(key == "name") { name=&value->as_string(); - valid_options++; } else if(key == "methods") { copy_methods=r.process(*value).as_bool(); - valid_options++; } else if(key == "fields") { copy_fields=r.process(*value).as_bool(); - valid_options++; } else if(key == "overwrite") { overwrite=r.process(*value).as_bool(); - valid_options++; - } + } else + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } - if(valid_options!=options->count()) - throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } if(!vtarget) @@ -543,23 +536,21 @@ static void _override(Request& r, Method const Method* method=j ? j->method : 0; if(!method) throw Exception(PARSER_RUNTIME, 0, "param must be method junction"); + if(method->native_code) + throw Exception(PARSER_RUNTIME, 0, "param must not be native method"); const String *name=method->name; Value* vtarget=0; if(params.count()>1) if(HashStringValue* options=params.as_hash(1, "override options")) { - int valid_options=0; for(HashStringValue::Iterator i(*options); i; i.next() ){ if(i.key() == "to") { vtarget=i.value(); - valid_options++; } else if(i.key() == "name") { name=&i.value()->as_string(); - valid_options++; - } + } else + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } - if(valid_options!=options->count()) - throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } if(!vtarget) @@ -607,6 +598,13 @@ static void _tainting(Request& r, Method } } +struct LocalsInfo { HashStringValue* args; HashStringValue* locals; }; + +static void collect_local(const String::Body& key, Value* value, LocalsInfo* info) { + if(!info->args->contains(key) && (key != "result")) + info->locals->put(key, value->get_junction() ? VVoid::get() : value); +} + static void _stack(Request& r, MethodParams& params) { bool show_args=false; bool show_locals=false; @@ -616,28 +614,20 @@ static void _stack(Request& r, MethodPar if(params.count()>0) if(HashStringValue* options=params.as_hash(0, "stack options")) { - int valid_options=0; for(HashStringValue::Iterator i(*options); i; i.next() ){ String::Body key=i.key(); Value* value=i.value(); - if(key == "args") { show_args=r.process(*value).as_bool(); - valid_options++; } else if(key == "locals") { show_locals=r.process(*value).as_bool(); - valid_options++; } else if(key == "limit") { limit=r.process(*value).as_int(); - valid_options++; } else if(key == "offset") { offset=r.process(*value).as_int(); - valid_options++; - } + } else + throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } - - if(valid_options!=options->count()) - throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); } limit+=offset; @@ -686,14 +676,10 @@ static void _stack(Request& r, MethodPar VHash& vlocals=*new VHash; HashStringValue* locals=vlocals.get_hash(); - if(VParserMethodFrame* frame=dynamic_cast(caller)) - for(HashString::Iterator h(frame->my); h; h.next()){ - String::Body key=h.key(); - Value* value=h.value(); - if(!args->contains(key) && (key != "result")){ - locals->put(key, value->get_junction() ? VVoid::get() : value); - } - } + if(VParserMethodFrame* frame=dynamic_cast(caller)){ + LocalsInfo linfo = { args, locals }; + frame->my.for_each(collect_local, &linfo); + } HASH_PUT_CSTR(*current, "locals", &vlocals); }