--- parser3/src/include/Attic/pa_vmframe.h 2001/02/25 17:58:29 1.8 +++ parser3/src/include/Attic/pa_vmframe.h 2001/03/09 04:47:27 1.20 @@ -1,5 +1,5 @@ /* - $Id: pa_vmframe.h,v 1.8 2001/02/25 17:58:29 paf Exp $ + $Id: pa_vmframe.h,v 1.20 2001/03/09 04:47:27 paf Exp $ */ #ifndef PA_VMFRAME_H @@ -13,73 +13,110 @@ class VMethodFrame : public WContext { public: // Value // all: for error reporting after fail(), etc - const char *type() const { return "MethodFrame"; } + const char *type() const { return "method_frame"; } // frame: my or self_transparent Value *get_element(const String& name) { - Value *result=static_cast(my.get(name)); - if(!result) - result=self->get_element(name); - return result; + if(my) { + Value *result=static_cast(my->get(name)); + if(result) + return result; + } + return fself->get_element(name); } // frame: my or self_transparent void put_element(const String& name, Value *value){ - if(!my.put_replace(name, value)) - self->put_element(name, value); + if(!(my && my->put_replace(name, value))) + fself->put_element(name, value); } // frame: self_transparent - VClass* get_class() { return self->get_class(); } + VClass* get_class() { return fself->get_class(); } // methodframe: self_transparent - Value *get_aliased() { return self->get_aliased(); } + VAliased *get_aliased() { return fself->get_aliased(); } public: // usage - VMethodFrame(Pool& apool, const Junction& ajunction) : + VMethodFrame(Pool& apool, const Junction& ajunction/*info: always method-junction*/) : WContext(apool, 0 /* empty */, false /* not constructing */), junction(ajunction), store_param_index(0), - my(apool), - self(0) { - if(Method* method=junction.method) { // method junction? - // remember local var names + my(0), fself(0) { + + Method &method=*junction.method; + + if(method.numbered_params_count) // are this method params numbered? + fnumbered_params=NEW Array(pool()); // create storage + else // named params + my=NEW Hash(pool()); // create storage + + if(method.locals_names) { // there are any local var names? + // remember them // those are flags that name is local == to be looked up in 'my' - for(int i=0; ilocals_names.size(); i++) { - my.put( - *static_cast(method->locals_names.get(i)), - NEW VUnknown(pool())); + for(int i=0; isize(); i++) { + Value *value=NEW VUnknown(pool()); + String& name=*static_cast(method.locals_names->get(i)); + value->set_name(name); + my->put(name, value); } } } - void set_self(Value& aself) { self=&aself; } + void set_self(Value& aself) { fself=&aself; } void store_param(Value *value) { - Method *method=junction.method; - if(store_param_index==method->params_names.size()) + Method& method=*junction.method; + int max_params= + method.numbered_params_count?method.numbered_params_count: + method.params_names?method.params_names->size(): + 0; + if(store_param_index==max_params) THROW(0,0, - &name(), - "call: too many params (max=%d)", method->params_names.size()); + &junction.self.name(), + "%s method '%s' accepts maximum %d parameter(s)", + junction.self.type(), + method.name.cstr(), + max_params); - my.put(*static_cast(method->params_names.get(store_param_index++)), value); + if(method.numbered_params_count) { // are this method params numbered? + *fnumbered_params+=value; + } else { // named param + String& name=*static_cast( + method.params_names->get(store_param_index++)); + my->put(name, value); // remember param + value->set_name(name); // set param's 'name' + } } void fill_unspecified_params() { - Method *method=junction.method; - for(; store_param_indexparams_names.size(); store_param_index++) - my.put( - *static_cast(method->params_names.get(store_param_index)), - NEW VUnknown(pool())); + Method &method=*junction.method; + if(method.numbered_params_count) { // are this method params numbered? + for(; store_param_indexset_name(/*"Param#" . store_param_index*/); + *fnumbered_params+=value; + } + } else { // named params + if(method.params_names) // there are any parameters might need filling? + for(; store_param_indexsize(); store_param_index++) { + Value *value=NEW VUnknown(pool()); + String& name=*static_cast(method.params_names->get(store_param_index)); + value->set_name(name); + my->put(name, value); + } + } } + Array& numbered_params() { return *fnumbered_params; } + public: const Junction& junction; private: int store_param_index; - Hash my; - Value *self; + Hash *my;/*OR*/Array *fnumbered_params; + Value *fself; };