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

1.1       paf         1: /*
1.12    ! paf         2:   $Id: pa_vmframe.h,v 1.11 2001/03/06 15:02:47 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.12    ! paf        18:        Value *get_element(String& name) { 
1.1       paf        19:                Value *result=static_cast<Value *>(my.get(name));
                     20:                if(!result)
                     21:                        result=self->get_element(name);
                     22:                return result; 
                     23:        }
                     24:        // frame: my or self_transparent
                     25:        void put_element(const String& name, Value *value){ 
1.4       paf        26:                if(!my.put_replace(name, value))
1.1       paf        27:                        self->put_element(name, value);
                     28:        }
                     29: 
1.6       paf        30:        // frame: self_transparent
                     31:        VClass* get_class() { return self->get_class(); }
                     32: 
1.8       paf        33:        // methodframe: self_transparent
1.9       paf        34:        VAliased *get_aliased() { return self->get_aliased(); }
1.7       paf        35: 
1.1       paf        36: public: // usage
                     37: 
1.5       paf        38:        VMethodFrame(Pool& apool, const Junction& ajunction) : 
                     39:                WContext(apool, 0 /* empty */, false /* not constructing */),
                     40: 
1.1       paf        41:                junction(ajunction),
                     42:                store_param_index(0),
                     43:                my(apool),
                     44:                self(0) {
                     45:                if(Method* method=junction.method) { // method junction?
                     46:                        // remember local var names
                     47:                        // those are flags that name is local == to be looked up in 'my'
                     48:                        for(int i=0; i<method->locals_names.size(); i++) {
                     49:                                my.put(
                     50:                                        *static_cast<String *>(method->locals_names.get(i)), 
                     51:                                        NEW VUnknown(pool()));
                     52:                        }
                     53:                }
                     54:        }
                     55: 
1.7       paf        56:        void set_self(Value& aself) { self=&aself; }
1.1       paf        57: 
                     58:        void store_param(Value *value) {
                     59:                Method *method=junction.method;
                     60:                if(store_param_index==method->params_names.size())
                     61:                        THROW(0,0,
1.12    ! paf        62:                                &junction.self.name(),
        !            63:                                "%s method '%s' accepts maximum %d parameters", 
        !            64:                                        junction.self.type(),
        !            65:                                        method->name.cstr(),
        !            66:                                        method->params_names.size());
1.1       paf        67:                
1.10      paf        68:                String& name=*static_cast<String *>(method->params_names.get(store_param_index++));
                     69:                my.put(name, value);
                     70:                value->set_name(name);
1.1       paf        71:        }
                     72:        void fill_unspecified_params() {
                     73:                Method *method=junction.method;
                     74:                for(; store_param_index<method->params_names.size(); store_param_index++)
                     75:                        my.put(
                     76:                                *static_cast<String *>(method->params_names.get(store_param_index)), 
                     77:                                NEW VUnknown(pool()));
                     78:        }
                     79: 
                     80: public:
                     81:        
                     82:        const Junction& junction;
                     83: 
                     84: private:
                     85:        int store_param_index;
                     86:        Hash my;
1.7       paf        87:        Value *self;
1.1       paf        88: 
                     89: };
                     90: 
                     91: #endif

E-mail: