Annotation of parser3/src/include/pa_vmframe.h, revision 1.20

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

E-mail: