--- parser3/src/include/Attic/pa_vobject.h 2001/02/24 13:18:19 1.1 +++ parser3/src/include/Attic/pa_vobject.h 2001/03/08 16:54:25 1.11 @@ -1,65 +1,71 @@ /* - $Id: pa_vobject.h,v 1.1 2001/02/24 13:18:19 paf Exp $ + $Id: pa_vobject.h,v 1.11 2001/03/08 16:54:25 paf Exp $ */ #ifndef PA_VOBJECT_H #define PA_VOBJECT_H -#include "pa_value.h" +#include "pa_valiased.h" #include "pa_vjunction.h" -class VObject : public Value { +class Temp_class_alias; + +class VObject : public VAliased { + friend Temp_class_alias; public: // Value // all: for error reporting after fail(), etc - const char *type() const { return "Object"; } - - // object_instance: (field)=value;(STATIC)=hash;(method)=method_ref - Value *get_element(const String& name) { - // $STATIC=STATIC hash - if(name==STATIC_NAME) - return &vclass.STATIC; - - // $method=junction(this+method) - if(Method *method=static_cast(vclass.methods.get(name))) { - Junction& j=*NEW Junction(pool(), - *this, - method,0,0,0,0); + const char *type() const { return "object"; } - return NEW VJunction(j); - } + // clone + Value *clone() { return NEW VObject(fclass_real, ffields); }; - // $field=fields.field - return static_cast(fields.get(name)); + // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref + Value *get_element(const String& name) { + // $CLASS=my class + if(name==CLASS_NAME) + return fclass_alias; + // $BASE=my parent + if(name==BASE_NAME) + return fclass_alias->base(); + // $method=junction(self+class+method) + if(Junction *junction=fclass_real.get_junction(*this, name)) + return NEW VJunction(*junction);; + // $field=ffields.field + return static_cast(ffields.get(name)); } // object_instance: (field)=value void put_element(const String& name, Value *value) { // speed1: - // will not check for '$STATIC(subst)' trick + // will not check for '$CLASS(subst)' trick // will hope that user ain't THAT self-hating person // speed2: // will not check for '$method_name(subst)' trick // -same- - fields.put(name, value); + ffields.put(name, value); } // object_class, object_instance: object_class - VClass *get_class() { return &vclass; } + VClass *get_class() { return &fclass_real; } public: // creation - VObject(Pool& apool, VClass& vclass) : - Value(apool), - vclass(vclass), - fields(apool) { + VObject(VClass& aclass_real) : VAliased(aclass_real.pool(), aclass_real), + fclass_real(aclass_real), + ffields(*new(aclass_real.pool()) Hash(aclass_real.pool())) { + } + + VObject(VClass& aclass_real, Hash& afields) : VAliased(aclass_real.pool(), aclass_real), + fclass_real(aclass_real), + ffields(afields) { } private: - VClass& vclass; - Hash fields; + VClass& fclass_real; + Hash& ffields; }; #endif