Annotation of parser3/src/include/pa_vclass.h, revision 1.28
1.1 paf 1: /*
1.28 ! paf 2: $Id: pa_vclass.h,v 1.27 2001/03/10 11:18:14 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_VCLASS_H
6: #define PA_VCLASS_H
7:
1.19 paf 8: #include "pa_valiased.h"
1.6 paf 9: #include "pa_vhash.h"
1.8 paf 10: #include "pa_vjunction.h"
1.1 paf 11:
1.17 paf 12: #define CLASS_NAME "CLASS"
13: #define BASE_NAME "BASE"
14:
1.19 paf 15: class VClass : public VAliased {
1.1 paf 16: public: // Value
17:
18: // all: for error reporting after fail(), etc
1.20 paf 19: const char *type() const { return "class"; }
1.23 paf 20:
1.1 paf 21: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.26 paf 22: Value *get_element(const String& aname);
1.1 paf 23:
24: // object_class, operator_class: (field)=value - static values only
1.26 paf 25: void put_element(const String& name, Value *value);
1.1 paf 26:
27: // object_class, object_instance: object_class
1.17 paf 28: VClass *get_class() { return this; }
1.1 paf 29:
30: public: // usage
31:
1.19 paf 32: VClass(Pool& apool) : VAliased(apool, *this),
1.23 paf 33: fbase(0),
1.25 paf 34: ffields(apool),
35: fmethods(apool) {
1.1 paf 36: }
37:
38: void add_method(const String& name, Method& method) {
1.15 paf 39: fmethods.put(name, &method);
1.1 paf 40: }
1.19 paf 41: // Hash& methods() { return fmethods; }
1.15 paf 42:
1.17 paf 43: void set_base(VClass& abase) {
44: // remember the guy
45: fbase=&abase;
1.15 paf 46: }
1.17 paf 47: VClass *base() { return fbase; }
1.18 paf 48:
49: bool is_or_derived_from(VClass& vclass) {
50: return
51: this==&vclass ||
52: fbase && fbase->is_or_derived_from(vclass);
1.19 paf 53: }
54:
55: Junction *get_junction(VAliased& self, const String& name) {
56: if(Method *method=static_cast<Method *>(fmethods.get(name)))
57: return NEW Junction(pool(), self, this, method, 0,0,0,0);
58: if(fbase)
59: return fbase->get_junction(self, name);
60: return 0;
1.18 paf 61: }
1.11 paf 62:
1.27 paf 63: void set_field(const String& name, Value *value) {
1.28 ! paf 64: value->set_name(name);
1.27 paf 65: if(fbase && fbase->replace_field(name, value))
66: return;
67:
68: ffields.put(name, value);
69: }
70:
1.17 paf 71: private:
1.11 paf 72:
1.17 paf 73: Value *get_field(const String& name) {
1.23 paf 74: Value *result=static_cast<Value *>(ffields.get(name));
1.17 paf 75: if(!result && fbase)
76: result=fbase->get_field(name);
77: return result;
78: }
79:
80: bool replace_field(const String& name, Value *value) {
81: return
82: (fbase && fbase->replace_field(name, value)) ||
1.23 paf 83: ffields.put_replace(name, value);
1.17 paf 84: }
85:
1.1 paf 86: private:
87:
1.17 paf 88: VClass *fbase;
1.25 paf 89: Hash ffields;
90: Hash fmethods;
1.1 paf 91: };
92:
93: #endif
E-mail: