Annotation of parser3/src/include/pa_vclass.h, revision 1.13
1.1 paf 1: /*
1.13 ! paf 2: $Id: pa_vclass.h,v 1.12 2001/02/24 13:21:58 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.13 ! paf 10: #include "pa_vstring.h"
1.8 paf 11: #include "pa_vjunction.h"
1.1 paf 12:
13: class VClass : public Value {
14: public: // Value
15:
16: // all: for error reporting after fail(), etc
1.4 paf 17: const char *type() const { return "Class"; }
1.1 paf 18:
19: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.4 paf 20: Value *get_element(const String& name) {
1.13 ! paf 21: // $NAME=name()
! 22: if(name==NAME_NAME)
! 23: return NEW VString(VClass::name());
! 24: // $PARENTS=parents table
! 25: if(name==PARENTS_NAME)
! 26: return 0;// TODO: table of parents
1.1 paf 27: // $STATIC=STATIC hash
1.13 ! paf 28: if(name==STATICS_NAME)
! 29: return &STATICS;
1.1 paf 30:
1.7 paf 31: // $method=junction(this+method)
32: if(Method *method=static_cast<Method *>(methods.get(name))) {
1.8 paf 33: Junction& j=*NEW Junction(pool(),
1.10 paf 34: *this,
35: method,0,0,0,0);
1.7 paf 36:
37: return NEW VJunction(j);
1.1 paf 38: }
39:
1.7 paf 40: // $field=STATIC.field
1.13 ! paf 41: return STATICS.get_element(name);
1.1 paf 42: }
43:
44: // object_class, operator_class: (field)=value - static values only
1.4 paf 45: void put_element(const String& name, Value *value) {
1.13 ! paf 46: STATICS.put_element(name, value);
1.1 paf 47: }
48:
49: // object_class, object_instance: object_class
1.4 paf 50: VClass *get_class() { return this; /*TODO: think when?*/ }
1.1 paf 51:
52: // object_class: true when this class is derived from 'ancestor'
1.4 paf 53: bool is_or_derived_from(VClass& ancestor) {
1.1 paf 54: if(this==&ancestor)
55: return true; // it's me
56:
1.12 paf 57: return parents_hash.get(*ancestor.name())!=0;
1.1 paf 58: }
59:
60: public: // usage
61:
1.11 paf 62: VClass(Pool& apool, const Array& immediate_parents) :
1.1 paf 63: Value(apool),
1.13 ! paf 64: STATICS(apool),
1.1 paf 65: methods(apool),
66: parents(apool),
67: parents_hash(apool) {
1.2 paf 68: // TODO: monkey immediate_parents
1.1 paf 69: // fill parents & parents_hash
70: }
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;
1.12 paf 77: parents_hash.put(*parent.name(), &parent);
1.1 paf 78: }
79:
1.11 paf 80: public: //usage
81:
1.13 ! paf 82: VHash STATICS;
1.11 paf 83:
1.1 paf 84: private:
85:
86: Hash methods;
87: Array parents; Hash parents_hash;
88: };
89:
90: #endif
E-mail: