Annotation of parser3/src/include/pa_vclass.h, revision 1.6
1.1 paf 1: /*
1.6 ! paf 2: $Id: pa_vclass.h,v 1.5 2001/02/22 11:08:06 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.1 paf 10:
11: class VClass : public Value {
12: public: // Value
13:
14: // all: for error reporting after fail(), etc
1.4 paf 15: const char *type() const { return "Class"; }
1.1 paf 16:
17: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.4 paf 18: Value *get_element(const String& name) {
1.1 paf 19: // $STATIC=STATIC hash
20: if(name==STATIC_NAME)
1.5 paf 21: return 0;//TODO:NEW VHash(pool(), STATIC);
1.1 paf 22:
23: // $field=STATIC.field
24: Value *result=static_cast<Value *>(STATIC.get(name));
25: if(!result) {
26: // $method=VMethod_ref
27: if(Method *method=get_method(name))
1.5 paf 28: result=0;///NEW VMethod_ref(this, method);
1.1 paf 29: }
30:
31: return result;
32: }
33:
34: // object_class, operator_class: (field)=value - static values only
1.4 paf 35: void put_element(const String& name, Value *value) {
1.1 paf 36: STATIC.put(name, value);
37: }
38:
39: // object_instance, object_class: method
1.4 paf 40: Method *get_method(const String& name) const {
1.1 paf 41: return static_cast<Method *>(methods.get(name));
42: }
43:
44: // object_class, object_instance: object_class
1.4 paf 45: VClass *get_class() { return this; /*TODO: think when?*/ }
1.1 paf 46:
47: // object_class: true when this class is derived from 'ancestor'
1.4 paf 48: bool is_or_derived_from(VClass& ancestor) {
1.1 paf 49: if(this==&ancestor)
50: return true; // it's me
51:
52: return parents_hash.get(ancestor.name())!=0;
53: }
54:
55: public: // usage
56:
57: const String& name() const { return *fname; }
58:
59: public: // creation
60:
61: VClass(Pool& apool, String& aname, const Array& immediate_parents) :
62: Value(apool),
63: fname(&aname),
64: STATIC(apool),
65: methods(apool),
66: parents(apool),
67: parents_hash(apool) {
1.2 paf 68: // TODO: monkey immediate_parents
1.1 paf 69: // fill parents & parents_hash
70: }
71:
72: void rename(String *aname) { fname=aname; }
73:
74: void add_method(const String& name, Method& method) {
75: methods.put(name, &method);
76: }
77: void add_parent(VClass& parent) {
78: parents+=&parent;
79: parents_hash.put(parent.name(), &parent);
80: }
81:
82: private:
83:
84: String *fname;
85: Hash STATIC;
86: Hash methods;
87: Array parents; Hash parents_hash;
88: };
89:
90: #endif
E-mail: