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

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.2     ! paf         6:        $Id: pa_vmframe.h,v 1.1 2001/03/11 07:52:45 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
                     37:        VClass* get_class() { return fself->get_class(); }
                     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: 
                     52:                Method &method=*junction.method;
                     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());
                     64:                                String& name=*static_cast<String *>(method.locals_names->get(i));
                     65:                                my->put(name, value);
                     66:                                value->set_name(name);
                     67:                        }
                     68:                }
                     69:        }
                     70: 
                     71:        void set_self(Value& aself) { fself=&aself; }
                     72: 
                     73:        void store_param(Value *value) {
                     74:                Method& method=*junction.method;
                     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,
                     81:                                &junction.self.name(),
                     82:                                "(%s) method '%s' accepts maximum %d parameter(s)", 
                     83:                                        junction.self.type(),
                     84:                                        method.name.cstr(),
                     85:                                        max_params);
                     86:                
                     87:                if(method.max_numbered_params_count) { // are this method params numbered?
                     88:                        *fnumbered_params+=value;
                     89:                } else { // named param
                     90:                        String& name=*static_cast<String *>(
                     91:                                method.params_names->get(store_param_index++));
                     92:                        my->put(name, value); // remember param
                     93:                        value->set_name(name); // set param's 'name'
                     94:                }
                     95:        }
                     96:        void fill_unspecified_params() {
                     97:                Method &method=*junction.method;
                     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());
                    101:                                String& name=*static_cast<String *>(
                    102:                                        method.params_names->get(store_param_index));
                    103:                                my->put(name, value);
                    104:                                value->set_name(name);
                    105:                        }
                    106:        }
                    107: 
                    108:        Array *numbered_params() { return fnumbered_params; }
                    109: 
                    110: public:
                    111:        
                    112:        const Junction& junction;
                    113: 
                    114: private:
                    115:        int store_param_index;
                    116:        Hash *my;/*OR*/Array *fnumbered_params;
                    117:        Value *fself;
                    118: 
                    119: };
                    120: 
                    121: #endif

E-mail: