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