Diff for /parser3/src/include/Attic/pa_vclass.h between versions 1.4 and 1.20

version 1.4, 2001/02/22 09:14:25 version 1.20, 2001/03/06 15:02:46
Line 2 Line 2
   $Id$    $Id$
 */  */
   
 /*  
         data core  
 */  
   
 #ifndef PA_VCLASS_H  #ifndef PA_VCLASS_H
 #define PA_VCLASS_H  #define PA_VCLASS_H
   
 #include "pa_value.h"  #include "pa_valiased.h"
 ///#include "pa_vhash.h"  #include "pa_vhash.h"
 class VHash {  #include "pa_vstring.h"
 public:  #include "pa_vjunction.h"
         VHash(Pool& apool, Hash& hash) {}  
 };  
   
 class VClass : public Value {  #define CLASS_NAME "CLASS"
   #define BASE_NAME "BASE"
   
   class VClass : public VAliased {
 public: // Value  public: // Value
                   
         // all: for error reporting after fail(), etc          // all: for error reporting after fail(), etc
         const char *type() const { return "Class"; }          const char *type() const { return "class"; }
   
         // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class          // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
         Value *get_element(const String& name) {          Value *get_element(const String& aname) {
                 // $STATIC=STATIC hash                  // $NAME=my name
                 if(name==STATIC_NAME)                  if(aname==NAME_NAME)
                         return 0;//TODO:new(pool()) VHash(pool(), STATIC);                          return NEW VString(class_alias->name());
                   // $CLASS=my class=myself
                 // $field=STATIC.field                  if(aname==CLASS_NAME)
                 Value *result=static_cast<Value *>(STATIC.get(name));                          return class_alias;
                 if(!result) {                  // $BASE=my parent
                         // $method=VMethod_ref                  if(aname==BASE_NAME)
                         if(Method *method=get_method(name))                          return class_alias->base();
                                 result=0;///new(pool()) VMethod_ref(this, method);                  // $method=junction(self+class+method)
                 }                  if(Junction *junction=get_junction(*this, aname))
                           return NEW VJunction(*junction);
                 return result;                  // $field=static field
                   return get_field(aname);
         }          }
   
         // object_class, operator_class: (field)=value - static values only          // object_class, operator_class: (field)=value - static values only
         void put_element(const String& name, Value *value) {          void put_element(const String& name, Value *value) {
                 STATIC.put(name, value);                  set_field(name, value);
         }  
   
         // object_instance, object_class: method  
         Method *get_method(const String& name) const {  
                 return static_cast<Method *>(methods.get(name));  
         }          }
   
         // object_class, object_instance: object_class          // object_class, object_instance: object_class
         VClass *get_class() { return this; /*TODO: think when?*/ }          VClass *get_class() { return this; }
   
         // object_class: true when this class is derived from 'ancestor'  
         bool is_or_derived_from(VClass& ancestor) {  
                 if(this==&ancestor)  
                         return true; // it's me  
   
                 return parents_hash.get(ancestor.name())!=0;  
         }  
   
 public: // usage  public: // usage
           
         const String& name() const { return *fname; }  
   
 public: // creation  
   
         VClass(Pool& apool, String& aname, const Array& immediate_parents) :           VClass(Pool& apool) : VAliased(apool, *this), 
                 Value(apool),                   fields(apool),
                 fname(&aname),                  fmethods(apool),
                 STATIC(apool),                  fbase(0) {
                 methods(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) {          void add_method(const String& name, Method& method) {
                 methods.put(name, &method);                  fmethods.put(name, &method);
         }          }
         void add_parent(VClass& parent) {  //      Hash& methods() { return fmethods; }
                 parents+=&parent;          
                 parents_hash.put(parent.name(), &parent);          void set_base(VClass& abase) {
                   // remember the guy
                   fbase=&abase;
           }
           VClass *base() { return fbase; }
   
           bool is_or_derived_from(VClass& vclass) {
                   return 
                           this==&vclass || 
                           fbase && fbase->is_or_derived_from(vclass);
           }
   
           Junction *get_junction(VAliased& self, const String& name) {
                   if(Method *method=static_cast<Method *>(fmethods.get(name)))
                           return NEW Junction(pool(), self, this, method, 0,0,0,0);
                   if(fbase)
                           return fbase->get_junction(self, name);
                   return 0; 
         }          }
   
 private:  private:
   
         String *fname;          Value *get_field(const String& name) {
         Hash STATIC;                  Value *result=static_cast<Value *>(fields.get(name));
         Hash methods;                  if(!result && fbase)
         Array parents;  Hash parents_hash;                          result=fbase->get_field(name);
                   return result;
           }
                   
           void set_field(const String& name, Value *value) {
                   if(fbase && fbase->replace_field(name, value))
                           return;
   
                   fields.put(name, value);
           }
           bool replace_field(const String& name, Value *value) {
                   return 
                           (fbase && fbase->replace_field(name, value)) ||
                           fields.put_replace(name, value);
           }
           
   private:
   
           VClass *fbase;
           Hash fields;
           Hash fmethods;
 };  };
   
 #endif  #endif

Removed from v.1.4  
changed lines
  Added in v.1.20


E-mail: