--- parser3/src/include/Attic/pa_value.h 2001/02/21 11:10:02 1.9 +++ parser3/src/include/Attic/pa_value.h 2001/02/23 21:59:07 1.21 @@ -1,5 +1,5 @@ /* - $Id: pa_value.h,v 1.9 2001/02/21 11:10:02 paf Exp $ + $Id: pa_value.h,v 1.21 2001/02/23 21:59:07 paf Exp $ */ /* @@ -10,7 +10,6 @@ #define PA_VALUE_H #include "pa_pool.h" -#include "pa_exception.h" #include "pa_string.h" #include "pa_array.h" //#include "pa_voperator.h" @@ -23,21 +22,22 @@ class WContext; class Method : public Pooled { public: - String& name; - Array& param_names; - Array& local_names; + const String& name; + Array& params_names; + Array& locals_names; Array& code; Method( Pool& apool, - String& aname, - Array& aparam_names, - Array& alocal_names, + const String& aname, + Array& aparams_names, + Array& alocals_names, Array& acode) : + Pooled(apool), name(aname), - param_names(aparam_names), - local_names(alocal_names), + params_names(aparams_names), + locals_names(alocals_names), code(acode) { } }; @@ -49,69 +49,92 @@ class Operator : public Method { }; */ -class Method_ref { +class Junction : public Pooled { public: - Value *self; - Method& method; -}; -class Junction { - bool auto_calc; - Value& root; + Junction(Pool& apool, + Method *amethod, + Value *aroot, + Value *aself, + Value *arcontext, + Array *acode) : Pooled(apool), + + method(amethod), + root(aroot), + self(aself), + rcontext(arcontext), + code(acode) { + } + + Method *method; + Value *root; Value *self; - Value& rcontext; - WContext& wcontext; - Array& code; + Value *rcontext; + Array *code; }; class Value : public Pooled { -public: - - Value(Pool& apool) : Pooled(apool) {} - -public: +public: // Value // all: for error reporting after fail(), etc - virtual const char *get_type() const =0; + virtual const char *type() const =0; + const String *name() const { return fname; } - // text: value - // object_class: [class classname] - virtual String *get_string() { failed("getting string representation"); return 0; } + // string: value + // unknown: "" + // others: 0 + virtual String *get_string() { return 0; } - // text: value - virtual void put_string(const String *astring) { failed("storing string"); } - - // method_ref: self, method - virtual Method_ref *get_method_ref() { failed("extracting method reference"); return 0; } + // string: value + virtual void put_string(String *astring) { failed("storing string to %s:%s"); } // junction: auto_calc,root,self,rcontext,wcontext, code - virtual Junction *get_junction() { failed("getting junction"); } + virtual Junction *get_junction() { failed("can not call '%s', is not a method or a junction (it is '%s')"); return 0; } // hash: (key)=value // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class // object_instance: (field)=value;(STATIC)=hash;(method)=method_ref // operator_class: (field)=value - static values only - virtual Value *get_element(const String& name) const =0; - + // wcontext: transparent + // frame: my or self_transparent + virtual Value *get_element(const String& name) { failed("getting element from %s:%s"); return 0; } + + // hash: (key)=value // object_class, operator_class: (field)=value - static values only - virtual void put_element(const String& name, Value *value)=0; - - // object_instance, object_class: method - virtual Method *get_method(const String& name) const { return 0; } + // wcontext: transparent + // frame: my or self_transparent + virtual void put_element(const String& name, Value *value) { failed("putting element to %s:%s"); } // object_class, object_instance: object_class + // frame: transparent + // wcontext: transparent virtual VClass *get_class() { return 0; } // object_class: true when this class is this or derived from 'ancestor' - virtual bool is_or_derived_from(VClass& ancestor) { failed("thoghts of ancestors"); return false; } + // frame: transparent + // wcontext: transparent + virtual bool is_or_derived_from(VClass& ancestor) { failed("thoghts of ancestors of %s:%s"); return false; } -private: +public: // usage + + Value(Pool& apool) : Pooled(apool), fname(0) {} - void failed(char *action) { - pool().exception().raise(0,0, - 0, - action); + void set_name(const String& aname) { fname=&aname; } + + String& as_string() { + String *result=get_string(); + if(!result) + failed("getting string of %s:%s"); + return *result; } + +private: + + const String *fname; + +private: + + void failed(char *action); }; /*