Diff for /parser3/src/include/Attic/pa_vclass.h between versions 1.12 and 1.18

version 1.12, 2001/02/24 13:21:58 version 1.18, 2001/02/25 14:47:12
Line 7 Line 7
   
 #include "pa_value.h"  #include "pa_value.h"
 #include "pa_vhash.h"  #include "pa_vhash.h"
   #include "pa_vstring.h"
 #include "pa_vjunction.h"  #include "pa_vjunction.h"
   
   #define CLASS_NAME "CLASS"
   #define BASE_NAME "BASE"
   
 class VClass : public Value {  class VClass : public Value {
 public: // Value  public: // Value
                   
Line 16  public: // Value Line 20  public: // Value
         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 &STATIC;                          return NEW VString(name());
                   // $CLASS=my class=myself
                   if(aname==CLASS_NAME)
                           return this;
                   // $BASE=my parent
                   if(aname==BASE_NAME)
                           return base();
                 // $method=junction(this+method)                  // $method=junction(this+method)
                 if(Method *method=static_cast<Method *>(methods.get(name))) {                  if(Method *method=static_cast<Method *>(methods().get(aname))) {
                         Junction& j=*NEW Junction(pool(),                           Junction& j=*NEW Junction(pool(), 
                                 *this,                                  *this,
                                 method,0,0,0,0);                                  method,0,0,0,0);
   
                         return NEW VJunction(j);                          return NEW VJunction(j);
                 }                  }
                   // $field=static field
                 // $field=STATIC.field                  return get_field(aname);
                 return STATIC.get_element(name);  
         }          }
   
         // 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_element(name, value);                  set_field(name, value);
         }          }
   
         // 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
   
         VClass(Pool& apool, const Array& immediate_parents) :           VClass(Pool& apool) : 
                 Value(apool),                   Value(apool), 
                 STATIC(apool),                  fields(apool),
                 methods(apool),                  fmethods(apool),
                 parents(apool),                  fbase(0) {
                 parents_hash(apool) {  
                 // TODO: monkey immediate_parents   
                         // fill parents & parents_hash  
         }          }
   
         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;
                   
                   // append base_method to my methods unless already there is one
                   // 'virtual' here
                   fmethods.merge_dont_replace(abase.methods());
           }
           VClass *base() { return fbase; }
   
           bool is_or_derived_from(VClass& vclass) {
                   return 
                           this==&vclass || 
                           fbase && fbase->is_or_derived_from(vclass);
         }          }
   
 public: //usage  private:
   
         VHash STATIC;  
   
           Value *get_field(const String& name) {
                   Value *result=static_cast<Value *>(fields.get(name));
                   if(!result && fbase)
                           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:  private:
   
         Hash methods;          VClass *fbase;
         Array parents;  Hash parents_hash;          Hash fields;
           Hash fmethods;
 };  };
   
 #endif  #endif

Removed from v.1.12  
changed lines
  Added in v.1.18


E-mail: