Annotation of parser3/src/include/pa_vclass.h, revision 1.17
1.1 paf 1: /*
1.17 ! paf 2: $Id: pa_vclass.h,v 1.16 2001/02/25 10:11:49 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.7 paf 33: // $method=junction(this+method)
1.15 paf 34: if(Method *method=static_cast<Method *>(methods().get(aname))) {
1.8 paf 35: Junction& j=*NEW Junction(pool(),
1.10 paf 36: *this,
37: method,0,0,0,0);
1.7 paf 38:
39: return NEW VJunction(j);
1.1 paf 40: }
1.17 ! paf 41: // $field=static field
! 42: return get_field(aname);
1.1 paf 43: }
44:
45: // object_class, operator_class: (field)=value - static values only
1.4 paf 46: void put_element(const String& name, Value *value) {
1.17 ! paf 47: set_field(name, value);
1.1 paf 48: }
49:
50: // object_class, object_instance: object_class
1.17 ! paf 51: VClass *get_class() { return this; }
1.1 paf 52:
53: public: // usage
54:
1.14 paf 55: VClass(Pool& apool) :
1.1 paf 56: Value(apool),
1.17 ! paf 57: fields(apool),
1.15 paf 58: fmethods(apool),
1.17 ! paf 59: fbase(0) {
1.1 paf 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.17 ! paf 67: void set_base(VClass& abase) {
! 68: // remember the guy
! 69: fbase=&abase;
! 70:
! 71: // append base_method to my methods unless already there is one
! 72: // 'virtual' here
! 73: fmethods.merge_dont_replace(abase.methods());
1.15 paf 74: }
1.17 ! paf 75: VClass *base() { return fbase; }
1.11 paf 76:
1.17 ! paf 77: private:
1.11 paf 78:
1.17 ! paf 79: Value *get_field(const String& name) {
! 80: Value *result=static_cast<Value *>(fields.get(name));
! 81: if(!result && fbase)
! 82: result=fbase->get_field(name);
! 83: return result;
! 84: }
! 85:
! 86: void set_field(const String& name, Value *value) {
! 87: if(fbase && fbase->replace_field(name, value))
! 88: return;
! 89:
! 90: fields.put(name, value);
! 91: }
! 92: bool replace_field(const String& name, Value *value) {
! 93: return
! 94: (fbase && fbase->replace_field(name, value)) ||
! 95: fields.put_replace(name, value);
! 96: }
! 97:
1.1 paf 98: private:
99:
1.17 ! paf 100: VClass *fbase;
! 101: Hash fields;
1.15 paf 102: Hash fmethods;
1.1 paf 103: };
104:
105: #endif
E-mail: