Annotation of parser3/src/types/pa_vmframe.h, revision 1.7

1.1       paf         1: /*
                      2:        Parser
                      3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2       paf         4:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1       paf         5: 
1.7     ! paf         6:        $Id: pa_vmframe.h,v 1.6 2001/03/13 13:43:32 paf Exp $
1.1       paf         7: */
                      8: 
                      9: #ifndef PA_VMFRAME_H
                     10: #define PA_VMFRAME_H
                     11: 
                     12: #include "pa_wcontext.h"
                     13: #include "pa_vunknown.h"
                     14: #include "pa_vjunction.h"
                     15: 
                     16: class VMethodFrame : public WContext {
                     17: public: // Value
                     18: 
                     19:        // all: for error reporting after fail(), etc
                     20:        const char *type() const { return "method_frame"; }
                     21:        // frame: my or self_transparent
                     22:        Value *get_element(const String& name) { 
                     23:                if(my) {
                     24:                        Value *result=static_cast<Value *>(my->get(name));
                     25:                        if(result)
                     26:                                return result;
                     27:                }
                     28:                return fself->get_element(name); 
                     29:        }
                     30:        // frame: my or self_transparent
                     31:        void put_element(const String& name, Value *value){ 
                     32:                if(!(my && my->put_replace(name, value)))
                     33:                        fself->put_element(name, value);
                     34:        }
                     35: 
                     36:        // frame: self_transparent
1.6       paf        37:        VStateless_class* get_class() { return fself->get_class(); }
1.1       paf        38: 
                     39:        // methodframe: self_transparent
                     40:        VAliased *get_aliased() { return fself->get_aliased(); }
                     41: 
                     42: public: // usage
                     43: 
                     44:        VMethodFrame(Pool& apool, const Junction& ajunction/*info: always method-junction*/) : 
                     45:                WContext(apool, 0 /* empty */, false /* not constructing */),
                     46: 
                     47:                junction(ajunction),
                     48:                store_param_index(0),
                     49:                my(0), fnumbered_params(0),
                     50:                fself(0) {
                     51: 
1.5       paf        52:                const Method &method=*junction.method;
1.1       paf        53: 
                     54:                if(method.max_numbered_params_count) // are this method params numbered?
                     55:                        fnumbered_params=NEW Array(pool()); // create storage
                     56:                else // named params
                     57:                        my=NEW Hash(pool()); // create storage
                     58: 
                     59:                if(method.locals_names) { // there are any local var names?
                     60:                        // remember them
                     61:                        // those are flags that name is local == to be looked up in 'my'
                     62:                        for(int i=0; i<method.locals_names->size(); i++) {
                     63:                                Value *value=NEW VUnknown(pool());
1.4       paf        64:                                const String& name=*method.locals_names->get_string(i);
1.1       paf        65:                                my->put(name, value);
                     66:                                value->set_name(name);
                     67:                        }
                     68:                }
                     69:        }
                     70: 
                     71:        void set_self(Value& aself) { fself=&aself; }
                     72: 
1.3       paf        73:        void store_param(const String& actual_method_name, Value *value) {
1.5       paf        74:                const Method& method=*junction.method;
1.1       paf        75:                int max_params=
                     76:                        method.max_numbered_params_count?method.max_numbered_params_count:
                     77:                        method.params_names?method.params_names->size():
                     78:                        0;
                     79:                if(store_param_index==max_params)
                     80:                        THROW(0,0,
1.3       paf        81:                                &actual_method_name,
                     82:                                "method of %s (%s) accepts maximum %d parameter(s)", 
                     83:                                        junction.self.name().cstr(),
1.1       paf        84:                                        junction.self.type(),
                     85:                                        max_params);
                     86:                
                     87:                if(method.max_numbered_params_count) { // are this method params numbered?
                     88:                        *fnumbered_params+=value;
                     89:                } else { // named param
1.7     ! paf        90:                        const String& name=*method.params_names->get_string(store_param_index);
1.1       paf        91:                        my->put(name, value); // remember param
                     92:                        value->set_name(name); // set param's 'name'
                     93:                }
1.7     ! paf        94:                store_param_index++;
1.1       paf        95:        }
                     96:        void fill_unspecified_params() {
1.5       paf        97:                const Method &method=*junction.method;
1.1       paf        98:                if(method.params_names) // there are any named parameters might need filling?
                     99:                        for(; store_param_index<method.params_names->size(); store_param_index++) {
                    100:                                Value *value=NEW VUnknown(pool());
1.4       paf       101:                                const String& name=*method.params_names->get_string(store_param_index);
1.1       paf       102:                                my->put(name, value);
                    103:                                value->set_name(name);
                    104:                        }
                    105:        }
                    106: 
                    107:        Array *numbered_params() { return fnumbered_params; }
                    108: 
                    109: public:
                    110:        
                    111:        const Junction& junction;
                    112: 
                    113: private:
                    114:        int store_param_index;
                    115:        Hash *my;/*OR*/Array *fnumbered_params;
                    116:        Value *fself;
                    117: 
                    118: };
                    119: 
                    120: #endif

E-mail: