Annotation of parser3/src/include/pa_vclass.h, revision 1.25.2.2

1.1       paf         1: /*
1.25.2.2! paf         2:   $Id: pa_vclass.h,v 1.25.2.1 2001/03/08 17:39:08 paf Exp $
1.1       paf         3: */
                      4: 
                      5: #ifndef PA_VCLASS_H
                      6: #define PA_VCLASS_H
                      7: 
1.19      paf         8: #include "pa_valiased.h"
1.6       paf         9: #include "pa_vhash.h"
1.8       paf        10: #include "pa_vjunction.h"
1.1       paf        11: 
1.17      paf        12: #define CLASS_NAME "CLASS"
                     13: #define BASE_NAME "BASE"
                     14: 
1.19      paf        15: class VClass : public VAliased {
1.1       paf        16: public: // Value
                     17:        
                     18:        // all: for error reporting after fail(), etc
1.20      paf        19:        const char *type() const { return "class"; }
1.23      paf        20: 
1.1       paf        21:        // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.25.2.1  paf        22:        Value *get_element(const String& aname);
1.1       paf        23: 
                     24:        // object_class, operator_class: (field)=value - static values only
1.25.2.1  paf        25:        void put_element(const String& name, Value *value);
1.1       paf        26: 
                     27:        // object_class, object_instance: object_class
1.17      paf        28:        VClass *get_class() { return this; }
1.1       paf        29: 
                     30: public: // usage
                     31: 
1.19      paf        32:        VClass(Pool& apool) : VAliased(apool, *this), 
1.23      paf        33:                fbase(0),
1.25      paf        34:                ffields(apool),
                     35:                fmethods(apool) {
1.1       paf        36:        }
                     37: 
                     38:        void add_method(const String& name, Method& method) {
1.15      paf        39:                fmethods.put(name, &method);
1.1       paf        40:        }
1.19      paf        41: //     Hash& methods() { return fmethods; }
1.15      paf        42:        
1.17      paf        43:        void set_base(VClass& abase) {
                     44:                // remember the guy
                     45:                fbase=&abase;
1.15      paf        46:        }
1.17      paf        47:        VClass *base() { return fbase; }
1.18      paf        48: 
                     49:        bool is_or_derived_from(VClass& vclass) {
                     50:                return 
                     51:                        this==&vclass || 
                     52:                        fbase && fbase->is_or_derived_from(vclass);
1.19      paf        53:        }
                     54: 
                     55:        Junction *get_junction(VAliased& self, const String& name) {
                     56:                if(Method *method=static_cast<Method *>(fmethods.get(name)))
                     57:                        return NEW Junction(pool(), self, this, method, 0,0,0,0);
                     58:                if(fbase)
                     59:                        return fbase->get_junction(self, name);
                     60:                return 0; 
1.18      paf        61:        }
1.11      paf        62: 
1.17      paf        63: private:
1.11      paf        64: 
1.17      paf        65:        Value *get_field(const String& name) {
1.23      paf        66:                Value *result=static_cast<Value *>(ffields.get(name));
1.17      paf        67:                if(!result && fbase)
                     68:                        result=fbase->get_field(name);
                     69:                return result;
                     70:        }
                     71:                
                     72:        void set_field(const String& name, Value *value) {
                     73:                if(fbase && fbase->replace_field(name, value))
                     74:                        return;
                     75: 
1.23      paf        76:                ffields.put(name, value);
1.17      paf        77:        }
                     78:        bool replace_field(const String& name, Value *value) {
                     79:                return 
                     80:                        (fbase && fbase->replace_field(name, value)) ||
1.23      paf        81:                        ffields.put_replace(name, value);
1.17      paf        82:        }
                     83:        
1.1       paf        84: private:
                     85: 
1.17      paf        86:        VClass *fbase;
1.25      paf        87:        Hash ffields;
                     88:        Hash fmethods;
1.1       paf        89: };
                     90: 
                     91: #endif

E-mail: