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

1.1       paf         1: /*
1.12    ! paf         2:   $Id: pa_vclass.h,v 1.11 2001/02/24 13:18:19 paf Exp $
1.1       paf         3: */
                      4: 
                      5: #ifndef PA_VCLASS_H
                      6: #define PA_VCLASS_H
                      7: 
                      8: #include "pa_value.h"
1.6       paf         9: #include "pa_vhash.h"
1.8       paf        10: #include "pa_vjunction.h"
1.1       paf        11: 
                     12: class VClass : public Value {
                     13: public: // Value
                     14:        
                     15:        // all: for error reporting after fail(), etc
1.4       paf        16:        const char *type() const { return "Class"; }
1.1       paf        17: 
                     18:        // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.4       paf        19:        Value *get_element(const String& name) {
1.1       paf        20:                // $STATIC=STATIC hash
                     21:                if(name==STATIC_NAME)
1.7       paf        22:                        return &STATIC;
1.1       paf        23: 
1.7       paf        24:                // $method=junction(this+method)
                     25:                if(Method *method=static_cast<Method *>(methods.get(name))) {
1.8       paf        26:                        Junction& j=*NEW Junction(pool(), 
1.10      paf        27:                                *this,
                     28:                                method,0,0,0,0);
1.7       paf        29: 
                     30:                        return NEW VJunction(j);
1.1       paf        31:                }
                     32: 
1.7       paf        33:                // $field=STATIC.field
                     34:                return STATIC.get_element(name);
1.1       paf        35:        }
                     36: 
                     37:        // object_class, operator_class: (field)=value - static values only
1.4       paf        38:        void put_element(const String& name, Value *value) {
1.7       paf        39:                STATIC.put_element(name, value);
1.1       paf        40:        }
                     41: 
                     42:        // object_class, object_instance: object_class
1.4       paf        43:        VClass *get_class() { return this; /*TODO: think when?*/ }
1.1       paf        44: 
                     45:        // object_class: true when this class is derived from 'ancestor'
1.4       paf        46:        bool is_or_derived_from(VClass& ancestor) {
1.1       paf        47:                if(this==&ancestor)
                     48:                        return true; // it's me
                     49: 
1.12    ! paf        50:                return parents_hash.get(*ancestor.name())!=0;
1.1       paf        51:        }
                     52: 
                     53: public: // usage
                     54: 
1.11      paf        55:        VClass(Pool& apool, const Array& immediate_parents) : 
1.1       paf        56:                Value(apool), 
                     57:                STATIC(apool),
                     58:                methods(apool),
                     59:                parents(apool),
                     60:                parents_hash(apool) {
1.2       paf        61:                // TODO: monkey immediate_parents 
1.1       paf        62:                        // fill parents & parents_hash
                     63:        }
                     64: 
                     65:        void add_method(const String& name, Method& method) {
                     66:                methods.put(name, &method);
                     67:        }
                     68:        void add_parent(VClass& parent) {
                     69:                parents+=&parent;
1.12    ! paf        70:                parents_hash.put(*parent.name(), &parent);
1.1       paf        71:        }
                     72: 
1.11      paf        73: public: //usage
                     74: 
                     75:        VHash STATIC;
                     76: 
1.1       paf        77: private:
                     78: 
                     79:        Hash methods;
                     80:        Array parents;  Hash parents_hash;
                     81: };
                     82: 
                     83: #endif

E-mail: