Annotation of parser3/src/include/pa_vclass.h, revision 1.16
1.1 paf 1: /*
1.16 ! paf 2: $Id: pa_vclass.h,v 1.15 2001/02/25 08:12:21 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.15 paf 20: Value *get_element(const String& aname) {
1.13 paf 21: // $NAME=name()
1.15 paf 22: if(aname==NAME_NAME)
23: return NEW VString(name());
1.13 paf 24: // $PARENTS=parents table
1.15 paf 25: if(aname==PARENTS_NAME)
1.13 paf 26: return 0;// TODO: table of parents
1.1 paf 27: // $STATIC=STATIC hash
1.15 paf 28: if(aname==STATICS_NAME)
1.13 paf 29: return &STATICS;
1.1 paf 30:
1.7 paf 31: // $method=junction(this+method)
1.15 paf 32: if(Method *method=static_cast<Method *>(methods().get(aname))) {
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.15 paf 41: return STATICS.get_element(aname);
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: public: // usage
53:
1.14 paf 54: VClass(Pool& apool) :
1.1 paf 55: Value(apool),
1.13 paf 56: STATICS(apool),
1.15 paf 57: fmethods(apool),
1.1 paf 58: parents(apool),
59: parents_hash(apool) {
60: }
61:
62: void add_method(const String& name, Method& method) {
1.15 paf 63: fmethods.put(name, &method);
1.1 paf 64: }
1.15 paf 65: Hash& methods() { return fmethods; }
66:
1.1 paf 67: void add_parent(VClass& parent) {
68: parents+=&parent;
1.12 paf 69: parents_hash.put(*parent.name(), &parent);
1.14 paf 70: // TODO: monkey immediate_parent
71: // fill parents & parents_hash
1.1 paf 72: }
1.16 ! paf 73: /*
1.15 paf 74: // true when me_or_ancestor is me or my ancestor
75: bool is_or_derived_from(VClass& me_or_ancestor) {
76: if(this==&me_or_ancestor)
77: return true; // it's me
78:
79: return parents_hash.get(*me_or_ancestor.name())!=0;
80: }
1.16 ! paf 81: */
1.11 paf 82: public: //usage
83:
1.13 paf 84: VHash STATICS;
1.11 paf 85:
1.1 paf 86: private:
87:
1.15 paf 88: Hash fmethods;
1.1 paf 89: Array parents; Hash parents_hash;
90: };
91:
92: #endif
E-mail: