Annotation of parser3/src/include/pa_vclass.h, revision 1.1
1.1 ! paf 1: /*
! 2: $Id: pa_value.h,v 1.8 2001/02/15 14:18:49 paf Exp $
! 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
! 23: const char *get_type() const { return "Class"; }
! 24:
! 25: // object_class: [class classname]
! 26: virtual String *get_string() const {
! 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;
! 32: }
! 33:
! 34: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
! 35: virtual Value *get_element(const String& name) const {
! 36: // $STATIC=STATIC hash
! 37: if(name==STATIC_NAME)
! 38: return 0;//new(pool()) VHash(pool(), STATIC);
! 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
! 52: virtual void put_element(const String& name, Value *value) {
! 53: STATIC.put(name, value);
! 54: }
! 55:
! 56: // object_instance, object_class: method
! 57: Method *get_method(const String& name) const {
! 58: return static_cast<Method *>(methods.get(name));
! 59: }
! 60:
! 61: // object_class, object_instance: object_class
! 62: VClass *get_class() { return this; /*TODO: think when?*/ }
! 63:
! 64: // object_class: true when this class is derived from 'ancestor'
! 65: bool is_or_derived_from(VClass& ancestor) {
! 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) {
! 85: // monkey immediate_parents
! 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: /*
! 108: descendants:
! 109: text:+ value:String
! 110: hash:+ keys&values:Hash
! 111: table:+ columns_order:Array, columns:Hash, rows:Array
! 112: object_class:+ STATIC:Hash, methods:Hash
! 113: object_instance:+ object_class, fields:Hash
! 114: method_ref:+ self:Value/object_class, method:String
! 115: method_self_n_params_n_locals:+ self:Value/object_class[1st try], params_locals&values:Hash[2nd try]
! 116: junction:+ self:Value, code:String
! 117: */
! 118:
! 119: #endif
E-mail: