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