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

1.1       paf         1: /*
1.23    ! paf         2:        Parser
        !             3:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
        !             4:        Author: Alexander Petrosyan <paf@design.ru>
        !             5: 
        !             6:        $Id: pa_string.C,v 1.35 2001/03/10 12:12:51 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
1.11      paf        20:        const char *type() const { return "method_frame"; }
1.1       paf        21:        // frame: my or self_transparent
1.13      paf        22:        Value *get_element(const String& name) { 
1.20      paf        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); 
1.1       paf        29:        }
                     30:        // frame: my or self_transparent
                     31:        void put_element(const String& name, Value *value){ 
1.20      paf        32:                if(!(my && my->put_replace(name, value)))
1.15      paf        33:                        fself->put_element(name, value);
1.1       paf        34:        }
                     35: 
1.6       paf        36:        // frame: self_transparent
1.15      paf        37:        VClass* get_class() { return fself->get_class(); }
1.6       paf        38: 
1.8       paf        39:        // methodframe: self_transparent
1.15      paf        40:        VAliased *get_aliased() { return fself->get_aliased(); }
1.7       paf        41: 
1.1       paf        42: public: // usage
                     43: 
1.16      paf        44:        VMethodFrame(Pool& apool, const Junction& ajunction/*info: always method-junction*/) : 
1.5       paf        45:                WContext(apool, 0 /* empty */, false /* not constructing */),
                     46: 
1.1       paf        47:                junction(ajunction),
                     48:                store_param_index(0),
1.21      paf        49:                my(0), fnumbered_params(0),
                     50:                fself(0) {
1.16      paf        51: 
                     52:                Method &method=*junction.method;
                     53: 
1.21      paf        54:                if(method.max_numbered_params_count) // are this method params numbered?
1.16      paf        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++) {
1.17      paf        63:                                Value *value=NEW VUnknown(pool());
                     64:                                String& name=*static_cast<String *>(method.locals_names->get(i));
1.22      paf        65:                                my->put(name, value);
1.17      paf        66:                                value->set_name(name);
1.1       paf        67:                        }
                     68:                }
                     69:        }
                     70: 
1.15      paf        71:        void set_self(Value& aself) { fself=&aself; }
1.1       paf        72: 
                     73:        void store_param(Value *value) {
1.16      paf        74:                Method& method=*junction.method;
                     75:                int max_params=
1.21      paf        76:                        method.max_numbered_params_count?method.max_numbered_params_count:
1.16      paf        77:                        method.params_names?method.params_names->size():
                     78:                        0;
1.14      paf        79:                if(store_param_index==max_params)
1.1       paf        80:                        THROW(0,0,
1.12      paf        81:                                &junction.self.name(),
1.21      paf        82:                                "(%s) method '%s' accepts maximum %d parameter(s)", 
1.12      paf        83:                                        junction.self.type(),
1.16      paf        84:                                        method.name.cstr(),
1.14      paf        85:                                        max_params);
1.1       paf        86:                
1.21      paf        87:                if(method.max_numbered_params_count) { // are this method params numbered?
1.16      paf        88:                        *fnumbered_params+=value;
1.18      paf        89:                } else { // named param
1.16      paf        90:                        String& name=*static_cast<String *>(
                     91:                                method.params_names->get(store_param_index++));
1.19      paf        92:                        my->put(name, value); // remember param
                     93:                        value->set_name(name); // set param's 'name'
1.16      paf        94:                }
1.1       paf        95:        }
                     96:        void fill_unspecified_params() {
1.16      paf        97:                Method &method=*junction.method;
1.21      paf        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++) {
1.17      paf       100:                                Value *value=NEW VUnknown(pool());
1.21      paf       101:                                String& name=*static_cast<String *>(
                    102:                                        method.params_names->get(store_param_index));
1.22      paf       103:                                my->put(name, value);
1.21      paf       104:                                value->set_name(name);
1.17      paf       105:                        }
1.1       paf       106:        }
                    107: 
1.21      paf       108:        Array *numbered_params() { return fnumbered_params; }
1.16      paf       109: 
1.1       paf       110: public:
                    111:        
                    112:        const Junction& junction;
                    113: 
                    114: private:
                    115:        int store_param_index;
1.16      paf       116:        Hash *my;/*OR*/Array *fnumbered_params;
1.15      paf       117:        Value *fself;
1.1       paf       118: 
                    119: };
                    120: 
                    121: #endif

E-mail: