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

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.10    ! paf         6:        $Id: pa_vmframe.h,v 1.9 2001/03/27 16:35:57 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
1.6       paf        37:        VStateless_class* get_class() { return fself->get_class(); }
1.1       paf        38: 
                     39:        // methodframe: self_transparent
                     40:        VAliased *get_aliased() { return fself->get_aliased(); }
                     41: 
1.8       paf        42: public: // wcontext
                     43: 
                     44:        Value *result() const {
                     45:                // check the $result value
                     46:                Value *result=my?static_cast<Value*>(my->get(*result_var_name)):0;
                     47:                // if we have one, return it, else return as usual: accumulated fstring or fvalue
1.9       paf        48:                return result && result->is_defined()?result:WContext::result();
1.8       paf        49:        }
                     50: 
1.1       paf        51: public: // usage
                     52: 
                     53:        VMethodFrame(Pool& apool, const Junction& ajunction/*info: always method-junction*/) : 
                     54:                WContext(apool, 0 /* empty */, false /* not constructing */),
                     55: 
                     56:                junction(ajunction),
                     57:                store_param_index(0),
                     58:                my(0), fnumbered_params(0),
                     59:                fself(0) {
                     60: 
1.5       paf        61:                const Method &method=*junction.method;
1.1       paf        62: 
                     63:                if(method.max_numbered_params_count) // are this method params numbered?
                     64:                        fnumbered_params=NEW Array(pool()); // create storage
1.8       paf        65:                else { // named params
1.1       paf        66:                        my=NEW Hash(pool()); // create storage
1.8       paf        67:                        
                     68:                        if(method.locals_names) { // are there any local var names?
                     69:                                // remember them
                     70:                                // those are flags that name is local == to be looked up in 'my'
                     71:                                for(int i=0; i<method.locals_names->size(); i++) {
                     72:                                        // speedup: not checking for clash with "result" name
                     73:                                        Value *value=NEW VUnknown(pool());
                     74:                                        const String& name=*method.locals_names->get_string(i);
                     75:                                        my->put(name, value);
                     76:                                        value->set_name(name);
                     77:                                }
                     78:                        }
                     79:                        { // always there is one local: $result
                     80:                                Value *result_value=NEW VUnknown(pool());
                     81:                                my->put(*result_var_name, result_value);
                     82:                                result_value->set_name(*result_var_name);
1.1       paf        83:                        }
                     84:                }
                     85:        }
                     86: 
                     87:        void set_self(Value& aself) { fself=&aself; }
1.10    ! paf        88:        Value *self() { return fself; }
1.1       paf        89: 
1.3       paf        90:        void store_param(const String& actual_method_name, Value *value) {
1.5       paf        91:                const Method& method=*junction.method;
1.1       paf        92:                int max_params=
                     93:                        method.max_numbered_params_count?method.max_numbered_params_count:
                     94:                        method.params_names?method.params_names->size():
                     95:                        0;
                     96:                if(store_param_index==max_params)
                     97:                        THROW(0,0,
1.3       paf        98:                                &actual_method_name,
                     99:                                "method of %s (%s) accepts maximum %d parameter(s)", 
                    100:                                        junction.self.name().cstr(),
1.1       paf       101:                                        junction.self.type(),
                    102:                                        max_params);
                    103:                
                    104:                if(method.max_numbered_params_count) { // are this method params numbered?
                    105:                        *fnumbered_params+=value;
                    106:                } else { // named param
1.8       paf       107:                        // speedup: not checking for clash with "result" name
1.7       paf       108:                        const String& name=*method.params_names->get_string(store_param_index);
1.1       paf       109:                        my->put(name, value); // remember param
                    110:                        value->set_name(name); // set param's 'name'
                    111:                }
1.7       paf       112:                store_param_index++;
1.1       paf       113:        }
                    114:        void fill_unspecified_params() {
1.5       paf       115:                const Method &method=*junction.method;
1.1       paf       116:                if(method.params_names) // there are any named parameters might need filling?
                    117:                        for(; store_param_index<method.params_names->size(); store_param_index++) {
                    118:                                Value *value=NEW VUnknown(pool());
1.4       paf       119:                                const String& name=*method.params_names->get_string(store_param_index);
1.1       paf       120:                                my->put(name, value);
                    121:                                value->set_name(name);
                    122:                        }
                    123:        }
                    124: 
                    125:        Array *numbered_params() { return fnumbered_params; }
                    126: 
                    127: public:
                    128:        
                    129:        const Junction& junction;
                    130: 
                    131: private:
                    132:        int store_param_index;
                    133:        Hash *my;/*OR*/Array *fnumbered_params;
                    134:        Value *fself;
                    135: 
                    136: };
                    137: 
                    138: #endif

E-mail: