Annotation of parser3/src/include/pa_vclass.h, revision 1.18.2.1
1.1 paf 1: /*
1.18.2.1! paf 2: $Id: pa_vclass.h,v 1.18 2001/02/25 14:47:12 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:
1.17 paf 13: #define CLASS_NAME "CLASS"
14: #define BASE_NAME "BASE"
15:
1.1 paf 16: class VClass : public Value {
17: public: // Value
18:
19: // all: for error reporting after fail(), etc
1.4 paf 20: const char *type() const { return "Class"; }
1.1 paf 21:
22: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.15 paf 23: Value *get_element(const String& aname) {
1.17 paf 24: // $NAME=my name
1.15 paf 25: if(aname==NAME_NAME)
26: return NEW VString(name());
1.17 paf 27: // $CLASS=my class=myself
28: if(aname==CLASS_NAME)
29: return this;
30: // $BASE=my parent
31: if(aname==BASE_NAME)
32: return base();
1.18.2.1! paf 33: // $method=junction(self+class+method)
! 34: if(Junction *junction=get_junction(*this, aname))
! 35: return NEW VJunction(*junction);
1.17 paf 36: // $field=static field
37: return get_field(aname);
1.1 paf 38: }
39:
40: // object_class, operator_class: (field)=value - static values only
1.4 paf 41: void put_element(const String& name, Value *value) {
1.17 paf 42: set_field(name, value);
1.1 paf 43: }
44:
45: // object_class, object_instance: object_class
1.17 paf 46: VClass *get_class() { return this; }
1.1 paf 47:
48: public: // usage
49:
1.14 paf 50: VClass(Pool& apool) :
1.1 paf 51: Value(apool),
1.17 paf 52: fields(apool),
1.15 paf 53: fmethods(apool),
1.17 paf 54: fbase(0) {
1.1 paf 55: }
56:
57: void add_method(const String& name, Method& method) {
1.15 paf 58: fmethods.put(name, &method);
1.1 paf 59: }
1.18.2.1! paf 60: // Hash& methods() { return fmethods; }
1.15 paf 61:
1.17 paf 62: void set_base(VClass& abase) {
63: // remember the guy
64: fbase=&abase;
1.15 paf 65: }
1.17 paf 66: VClass *base() { return fbase; }
1.18 paf 67:
68: bool is_or_derived_from(VClass& vclass) {
69: return
70: this==&vclass ||
71: fbase && fbase->is_or_derived_from(vclass);
1.18.2.1! paf 72: }
! 73:
! 74: Junction *get_junction(Value& self, const String& name) {
! 75: if(Method *method=static_cast<Method *>(fmethods.get(name)))
! 76: return NEW Junction(pool(), self, this, method, 0,0,0,0);
! 77: if(fbase)
! 78: return fbase->get_junction(self, name);
! 79: return 0;
1.18 paf 80: }
1.11 paf 81:
1.17 paf 82: private:
1.11 paf 83:
1.17 paf 84: Value *get_field(const String& name) {
85: Value *result=static_cast<Value *>(fields.get(name));
86: if(!result && fbase)
87: result=fbase->get_field(name);
88: return result;
89: }
90:
91: void set_field(const String& name, Value *value) {
92: if(fbase && fbase->replace_field(name, value))
93: return;
94:
95: fields.put(name, value);
96: }
97: bool replace_field(const String& name, Value *value) {
98: return
99: (fbase && fbase->replace_field(name, value)) ||
100: fields.put_replace(name, value);
101: }
102:
1.1 paf 103: private:
104:
1.17 paf 105: VClass *fbase;
106: Hash fields;
1.15 paf 107: Hash fmethods;
1.1 paf 108: };
109:
110: #endif
E-mail: