--- parser3/src/include/Attic/pa_vclass.h 2001/02/21 17:36:30 1.2 +++ parser3/src/include/Attic/pa_vclass.h 2001/02/25 08:12:21 1.15 @@ -1,106 +1,91 @@ /* - $Id: pa_vclass.h,v 1.2 2001/02/21 17:36:30 paf Exp $ -*/ - -/* - data core + $Id: pa_vclass.h,v 1.15 2001/02/25 08:12:21 paf Exp $ */ #ifndef PA_VCLASS_H #define PA_VCLASS_H #include "pa_value.h" -///#include "pa_vhash.h" -class VHash { -public: - VHash(Pool& apool, Hash& hash) {} -}; +#include "pa_vhash.h" +#include "pa_vstring.h" +#include "pa_vjunction.h" class VClass : public Value { public: // Value // all: for error reporting after fail(), etc - /*virtual*/ const char *get_type() const { return "Class"; } - - // object_class: [class classname] - /*virtual*/ String *get_string() const { - String *result=new(pool()) String(pool()); - result->APPEND("[class ", 0, 0, 0); - result->APPEND(name().cstr(), 0, 0, 0); - result->APPEND("]", 0, 0, 0); - return result; - } + const char *type() const { return "Class"; } // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class - /*virtual*/ Value *get_element(const String& name) const { + Value *get_element(const String& aname) { + // $NAME=name() + if(aname==NAME_NAME) + return NEW VString(name()); + // $PARENTS=parents table + if(aname==PARENTS_NAME) + return 0;// TODO: table of parents // $STATIC=STATIC hash - if(name==STATIC_NAME) - return 0;//TODO:new(pool()) VHash(pool(), STATIC); + if(aname==STATICS_NAME) + return &STATICS; - // $field=STATIC.field - Value *result=static_cast(STATIC.get(name)); - if(!result) { - // $method=VMethod_ref - if(Method *method=get_method(name)) - result=0;///new(pool()) VMethod_ref(this, method); + // $method=junction(this+method) + if(Method *method=static_cast(methods().get(aname))) { + Junction& j=*NEW Junction(pool(), + *this, + method,0,0,0,0); + + return NEW VJunction(j); } - return result; + // $field=STATIC.field + return STATICS.get_element(aname); } // object_class, operator_class: (field)=value - static values only - /*virtual*/ void put_element(const String& name, Value *value) { - STATIC.put(name, value); - } - - // object_instance, object_class: method - /*virtual*/ Method *get_method(const String& name) const { - return static_cast(methods.get(name)); + void put_element(const String& name, Value *value) { + STATICS.put_element(name, value); } // object_class, object_instance: object_class - /*virtual*/ VClass *get_class() { return this; /*TODO: think when?*/ } - - // object_class: true when this class is derived from 'ancestor' - /*virtual*/ bool is_or_derived_from(VClass& ancestor) { - if(this==&ancestor) - return true; // it's me - - return parents_hash.get(ancestor.name())!=0; - } + VClass *get_class() { return this; /*TODO: think when?*/ } public: // usage - - const String& name() const { return *fname; } -public: // creation - - VClass(Pool& apool, String& aname, const Array& immediate_parents) : + VClass(Pool& apool) : Value(apool), - fname(&aname), - STATIC(apool), - methods(apool), + STATICS(apool), + fmethods(apool), parents(apool), parents_hash(apool) { - // TODO: monkey immediate_parents - // fill parents & parents_hash } - - void rename(String *aname) { fname=aname; } void add_method(const String& name, Method& method) { - methods.put(name, &method); + fmethods.put(name, &method); } + Hash& methods() { return fmethods; } + void add_parent(VClass& parent) { parents+=&parent; - parents_hash.put(parent.name(), &parent); + parents_hash.put(*parent.name(), &parent); + // TODO: monkey immediate_parent + // fill parents & parents_hash } + // true when me_or_ancestor is me or my ancestor + bool is_or_derived_from(VClass& me_or_ancestor) { + if(this==&me_or_ancestor) + return true; // it's me + + return parents_hash.get(*me_or_ancestor.name())!=0; + } + +public: //usage + + VHash STATICS; + private: - String *fname; - Hash STATIC; - Hash methods; + Hash fmethods; Array parents; Hash parents_hash; };