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

1.1       paf         1: /*
1.2     ! paf         2:   $Id: pa_vmframe.h,v 1.1 2001/02/24 11:20:32 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
                     16:        const char *type() const { return "MethodFrame"; }
                     17:        // frame: my or self_transparent
                     18:        Value *get_element(const String& name) { 
                     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){ 
                     26:                if(!my.replace(name, value))
                     27:                        self->put_element(name, value);
                     28:        }
                     29: 
                     30:        // frame: none yet | transparent
                     31:        VClass *get_class() const { return self->get_class(); }
                     32: 
                     33: public: // usage
                     34: 
                     35:        VMethodFrame(Pool& apool, const Junction& ajunction) : WContext(apool, 0 /* empty */),
                     36:                junction(ajunction),
                     37:                store_param_index(0),
                     38:                my(apool),
                     39:                self(0) {
                     40:                if(Method* method=junction.method) { // method junction?
                     41:                        // remember local var names
                     42:                        // those are flags that name is local == to be looked up in 'my'
                     43:                        for(int i=0; i<method->locals_names.size(); i++) {
                     44:                                my.put(
                     45:                                        *static_cast<String *>(method->locals_names.get(i)), 
                     46:                                        NEW VUnknown(pool()));
                     47:                        }
                     48:                }
                     49:        }
                     50: 
                     51:        void set_self(Value *aself) { self=aself; }
                     52: 
                     53:        void store_param(Value *value) {
                     54:                Method *method=junction.method;
                     55:                if(store_param_index==method->params_names.size())
                     56:                        THROW(0,0,
                     57:                                name(),
                     58:                                "call: too many params (max=%d)", method->params_names.size());
                     59:                
                     60:                my.put(*static_cast<String *>(method->params_names.get(store_param_index++)), value);
                     61:        }
                     62:        void fill_unspecified_params() {
                     63:                Method *method=junction.method;
                     64:                for(; store_param_index<method->params_names.size(); store_param_index++)
                     65:                        my.put(
                     66:                                *static_cast<String *>(method->params_names.get(store_param_index)), 
                     67:                                NEW VUnknown(pool()));
                     68:        }
                     69: 
                     70: public:
                     71:        
                     72:        const Junction& junction;
                     73: 
                     74: private:
                     75:        int store_param_index;
                     76:        Hash my;
                     77:        Value *self;
                     78: 
                     79: };
                     80: 
                     81: #endif

E-mail: