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

1.1       paf         1: /*
1.8     ! paf         2:   $Id: pa_vclass.h,v 1.7 2001/02/23 18:12:44 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.7       paf        27:                                method,
                     28:                                this,this,this,0);
                     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: 
                     50:                return parents_hash.get(ancestor.name())!=0;
                     51:        }
                     52: 
                     53: public: // usage
                     54:        
                     55:        const String& name() const { return *fname; }
                     56: 
                     57: public: // creation
                     58: 
                     59:        VClass(Pool& apool, String& aname, const Array& immediate_parents) : 
                     60:                Value(apool), 
                     61:                fname(&aname),
                     62:                STATIC(apool),
                     63:                methods(apool),
                     64:                parents(apool),
                     65:                parents_hash(apool) {
1.2       paf        66:                // TODO: monkey immediate_parents 
1.1       paf        67:                        // fill parents & parents_hash
                     68:        }
                     69:        
                     70:        void rename(String *aname) { fname=aname; }
                     71: 
                     72:        void add_method(const String& name, Method& method) {
                     73:                methods.put(name, &method);
                     74:        }
                     75:        void add_parent(VClass& parent) {
                     76:                parents+=&parent;
                     77:                parents_hash.put(parent.name(), &parent);
                     78:        }
                     79: 
                     80: private:
                     81: 
                     82:        String *fname;
1.7       paf        83:        VHash STATIC;
1.1       paf        84:        Hash methods;
                     85:        Array parents;  Hash parents_hash;
                     86: };
                     87: 
                     88: #endif

E-mail: