Annotation of parser3/src/include/pa_vclass.h, revision 1.3
1.1 paf 1: /*
1.3 ! paf 2: $Id: pa_vclass.h,v 1.2 2001/02/21 17:36:30 paf Exp $
1.1 paf 3: */
4:
5: /*
6: data core
7: */
8:
9: #ifndef PA_VCLASS_H
10: #define PA_VCLASS_H
11:
12: #include "pa_value.h"
13: ///#include "pa_vhash.h"
14: class VHash {
15: public:
16: VHash(Pool& apool, Hash& hash) {}
17: };
18:
19: class VClass : public Value {
20: public: // Value
21:
22: // all: for error reporting after fail(), etc
1.2 paf 23: /*virtual*/ const char *get_type() const { return "Class"; }
1.1 paf 24:
25: // object_class: [class classname]
1.3 ! paf 26: /*virtual*/ /*String *get_string() const {
1.1 paf 27: String *result=new(pool()) String(pool());
28: result->APPEND("[class ", 0, 0, 0);
29: result->APPEND(name().cstr(), 0, 0, 0);
30: result->APPEND("]", 0, 0, 0);
31: return result;
1.3 ! paf 32: }*/
1.1 paf 33:
34: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.2 paf 35: /*virtual*/ Value *get_element(const String& name) const {
1.1 paf 36: // $STATIC=STATIC hash
37: if(name==STATIC_NAME)
1.2 paf 38: return 0;//TODO:new(pool()) VHash(pool(), STATIC);
1.1 paf 39:
40: // $field=STATIC.field
41: Value *result=static_cast<Value *>(STATIC.get(name));
42: if(!result) {
43: // $method=VMethod_ref
44: if(Method *method=get_method(name))
45: result=0;///new(pool()) VMethod_ref(this, method);
46: }
47:
48: return result;
49: }
50:
51: // object_class, operator_class: (field)=value - static values only
1.2 paf 52: /*virtual*/ void put_element(const String& name, Value *value) {
1.1 paf 53: STATIC.put(name, value);
54: }
55:
56: // object_instance, object_class: method
1.2 paf 57: /*virtual*/ Method *get_method(const String& name) const {
1.1 paf 58: return static_cast<Method *>(methods.get(name));
59: }
60:
61: // object_class, object_instance: object_class
1.2 paf 62: /*virtual*/ VClass *get_class() { return this; /*TODO: think when?*/ }
1.1 paf 63:
64: // object_class: true when this class is derived from 'ancestor'
1.2 paf 65: /*virtual*/ bool is_or_derived_from(VClass& ancestor) {
1.1 paf 66: if(this==&ancestor)
67: return true; // it's me
68:
69: return parents_hash.get(ancestor.name())!=0;
70: }
71:
72: public: // usage
73:
74: const String& name() const { return *fname; }
75:
76: public: // creation
77:
78: VClass(Pool& apool, String& aname, const Array& immediate_parents) :
79: Value(apool),
80: fname(&aname),
81: STATIC(apool),
82: methods(apool),
83: parents(apool),
84: parents_hash(apool) {
1.2 paf 85: // TODO: monkey immediate_parents
1.1 paf 86: // fill parents & parents_hash
87: }
88:
89: void rename(String *aname) { fname=aname; }
90:
91: void add_method(const String& name, Method& method) {
92: methods.put(name, &method);
93: }
94: void add_parent(VClass& parent) {
95: parents+=&parent;
96: parents_hash.put(parent.name(), &parent);
97: }
98:
99: private:
100:
101: String *fname;
102: Hash STATIC;
103: Hash methods;
104: Array parents; Hash parents_hash;
105: };
106:
107: #endif
E-mail: