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

1.1       paf         1: /*
1.18    ! paf         2:   $Id: pa_vmframe.h,v 1.17 2001/03/08 15:32:51 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.16      paf        19:                Value *result=static_cast<Value *>(my->get(name));
1.1       paf        20:                if(!result)
1.15      paf        21:                        result=fself->get_element(name);
1.1       paf        22:                return result; 
                     23:        }
                     24:        // frame: my or self_transparent
                     25:        void put_element(const String& name, Value *value){ 
1.16      paf        26:                if(!my->put_replace(name, value))
1.15      paf        27:                        fself->put_element(name, value);
1.1       paf        28:        }
                     29: 
1.6       paf        30:        // frame: self_transparent
1.15      paf        31:        VClass* get_class() { return fself->get_class(); }
1.6       paf        32: 
1.8       paf        33:        // methodframe: self_transparent
1.15      paf        34:        VAliased *get_aliased() { return fself->get_aliased(); }
1.7       paf        35: 
1.1       paf        36: public: // usage
                     37: 
1.16      paf        38:        VMethodFrame(Pool& apool, const Junction& ajunction/*info: always method-junction*/) : 
1.5       paf        39:                WContext(apool, 0 /* empty */, false /* not constructing */),
                     40: 
1.1       paf        41:                junction(ajunction),
                     42:                store_param_index(0),
1.16      paf        43:                my(0), fself(0) {
                     44: 
                     45:                Method &method=*junction.method;
                     46: 
                     47:                if(method.numbered_params_count) // are this method params numbered?
                     48:                        fnumbered_params=NEW Array(pool()); // create storage
                     49:                else // named params
                     50:                        my=NEW Hash(pool()); // create storage
                     51: 
                     52:                if(method.locals_names) { // there are any local var names?
                     53:                        // remember them
                     54:                        // those are flags that name is local == to be looked up in 'my'
                     55:                        for(int i=0; i<method.locals_names->size(); i++) {
1.17      paf        56:                                Value *value=NEW VUnknown(pool());
                     57:                                String& name=*static_cast<String *>(method.locals_names->get(i));
                     58:                                value->set_name(name);
                     59:                                my->put(name, value);
1.1       paf        60:                        }
                     61:                }
                     62:        }
                     63: 
1.15      paf        64:        void set_self(Value& aself) { fself=&aself; }
1.1       paf        65: 
                     66:        void store_param(Value *value) {
1.16      paf        67:                Method& method=*junction.method;
                     68:                int max_params=
                     69:                        method.numbered_params_count?method.numbered_params_count:
                     70:                        method.params_names?method.params_names->size():
                     71:                        0;
1.14      paf        72:                if(store_param_index==max_params)
1.1       paf        73:                        THROW(0,0,
1.12      paf        74:                                &junction.self.name(),
1.18    ! paf        75:                                "%s method '%s' accepts maximum %d parameter(s)", 
1.12      paf        76:                                        junction.self.type(),
1.16      paf        77:                                        method.name.cstr(),
1.14      paf        78:                                        max_params);
1.1       paf        79:                
1.16      paf        80:                if(method.numbered_params_count) { // are this method params numbered?
                     81:                        *fnumbered_params+=value;
1.18    ! paf        82:                } else { // named param
        !            83:                        // clone it
1.16      paf        84:                        String& name=*static_cast<String *>(
                     85:                                method.params_names->get(store_param_index++));
1.18    ! paf        86:                        Value *copy=value->clone(); // make a copy of a value so to safely rename it
        !            87:                        my->put(name, copy); // remember param
        !            88:                        copy->set_name(name); // rename 'copy' to 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: