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

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

E-mail: