Annotation of parser3/src/types/pa_vclass.h, revision 1.4
1.1 paf 1: /*
2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2 paf 4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1 paf 5:
1.4 ! paf 6: $Id: pa_vclass.h,v 1.3 2001/03/11 08:44:42 paf Exp $
1.1 paf 7: */
8:
9: #ifndef PA_VCLASS_H
10: #define PA_VCLASS_H
11:
12: #include "pa_valiased.h"
13: #include "pa_vhash.h"
14: #include "pa_vjunction.h"
15:
16: #define CLASS_NAME "CLASS"
17: #define BASE_NAME "BASE"
18:
1.4 ! paf 19: class Temp_method;
! 20:
1.1 paf 21: class VClass : public VAliased {
1.4 ! paf 22: friend Temp_method;
1.1 paf 23: public: // Value
24:
25: // all: for error reporting after fail(), etc
26: const char *type() const { return "class"; }
27:
28: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
29: Value *get_element(const String& aname);
30:
31: // object_class, operator_class: (field)=value - static values only
32: void put_element(const String& name, Value *value);
33:
34: // object_class, object_instance: object_class
35: VClass *get_class() { return this; }
36:
37: public: // usage
38:
39: VClass(Pool& apool) : VAliased(apool, *this),
40: fbase(0),
41: ffields(apool),
42: fmethods(apool) {
43: }
44:
45: void add_method(const String& name, Method& method) {
46: fmethods.put(name, &method);
47: }
1.3 paf 48: void add_native_method(
49: const char *cstr_name,
50: Native_code_ptr native_code,
51: int min_numbered_params_count, int max_numbered_params_count);
1.1 paf 52: // Hash& methods() { return fmethods; }
53:
54: void set_base(VClass& abase) {
55: // remember the guy
56: fbase=&abase;
57: }
58: VClass *base() { return fbase; }
59:
60: bool is_or_derived_from(VClass& vclass) {
61: return
62: this==&vclass ||
63: fbase && fbase->is_or_derived_from(vclass);
64: }
65:
66: Junction *get_junction(VAliased& self, const String& name) {
67: if(Method *method=static_cast<Method *>(fmethods.get(name)))
68: return NEW Junction(pool(), self, this, method, 0,0,0,0);
69: if(fbase)
70: return fbase->get_junction(self, name);
71: return 0;
72: }
73:
74: void set_field(const String& name, Value *value) {
1.4 ! paf 75: if(value) // used in ^process to temporarily remove @main
! 76: value->set_name(name);
1.1 paf 77: if(fbase && fbase->replace_field(name, value))
78: return;
79:
80: ffields.put(name, value);
81: }
82:
83: private:
84:
85: Value *get_field(const String& name) {
86: Value *result=static_cast<Value *>(ffields.get(name));
87: if(!result && fbase)
88: result=fbase->get_field(name);
89: return result;
90: }
91:
92: bool replace_field(const String& name, Value *value) {
93: return
94: (fbase && fbase->replace_field(name, value)) ||
95: ffields.put_replace(name, value);
96: }
1.4 ! paf 97:
! 98: private: // Temp_method
! 99:
! 100: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
! 101: Method *get_method(const String& name) {
! 102: return static_cast<Method *>(fmethods.get(name));
! 103: }
! 104:
! 105: // object_class, operator_class: (field)=value - static values only
! 106: void put_method(const String& name, Method *method) { fmethods.put(name, method); }
1.1 paf 107:
108: private:
109:
110: VClass *fbase;
111: Hash ffields;
112: Hash fmethods;
1.4 ! paf 113: };
! 114:
! 115: class Temp_method {
! 116: VClass& fclass;
! 117: const String& fname;
! 118: Method *saved_method;
! 119: public:
! 120: Temp_method(VClass& aclass, const String& aname, Method *amethod) :
! 121: fclass(aclass),
! 122: fname(aname),
! 123: saved_method(aclass.get_method(aname)) {
! 124: fclass.put_method(aname, amethod);
! 125: }
! 126: ~Temp_method() {
! 127: fclass.put_method(fname, saved_method);
! 128: }
1.1 paf 129: };
130:
131: #endif
E-mail: