|
|
| version 1.12, 2001/02/22 08:16:09 | version 1.41, 2001/03/07 13:54:46 |
|---|---|
| Line 10 | Line 10 |
| #define PA_VALUE_H | #define PA_VALUE_H |
| #include "pa_pool.h" | #include "pa_pool.h" |
| #include "pa_exception.h" | |
| #include "pa_string.h" | #include "pa_string.h" |
| #include "pa_array.h" | #include "pa_array.h" |
| //#include "pa_voperator.h" | //#include "pa_voperator.h" |
| #define NAME_NAME "NAME" | |
| class Value; | class Value; |
| class VClass; | class VClass; |
| //class VOperator; | //class VOperator; |
| class Junction; | class Junction; |
| class WContext; | class WContext; |
| class VAliased; | |
| class Method : public Pooled { | class Method : public Pooled { |
| public: | public: |
| const String& name; | const String& name; |
| Array& params_names; | Array& params_names; |
| Array& locals_names; | Array& locals_names; |
| Array& code; | const Array& code; |
| Method( | Method( |
| Pool& apool, | Pool& apool, |
| const String& aname, | const String& aname, |
| Array& aparams_names, | Array& aparams_names, |
| Array& alocals_names, | Array& alocals_names, |
| Array& acode) : | const Array& acode) : |
| Pooled(apool), | Pooled(apool), |
| name(aname), | name(aname), |
| params_names(aparams_names), | params_names(aparams_names), |
| Line 49 class Operator : public Method { | Line 52 class Operator : public Method { |
| }; | }; |
| */ | */ |
| class Method_ref { | class Junction : public Pooled { |
| public: | public: |
| Value *self; | |
| Method& method; | |
| }; | |
| class Junction { | Junction(Pool& apool, |
| bool auto_calc; | Value& aself, |
| Value& root; | VClass *avclass, Method *amethod, |
| Value *self; | Value *aroot, |
| Value& rcontext; | Value *arcontext, |
| WContext& wcontext; | WContext *awcontext, |
| Array& code; | const Array *acode) : Pooled(apool), |
| self(aself), | |
| vclass(avclass), method(amethod), | |
| root(aroot), | |
| rcontext(arcontext), | |
| wcontext(awcontext), | |
| code(acode) { | |
| } | |
| Value& self; | |
| VClass *vclass; Method *method; | |
| Value *root; | |
| Value *rcontext; | |
| WContext *wcontext; | |
| const Array *code; | |
| }; | }; |
| class Value : public Pooled { | class Value : public Pooled { |
| public: | public: // Value |
| Value(Pool& apool) : Pooled(apool) {} | |
| public: | |
| // all: for error reporting after fail(), etc | // 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 | // unknown: false |
| // object_class: [class classname] | // others: true |
| virtual String *get_string() { /*vclass: failed("getting string representation"); */return 0; } | virtual bool get_defined() { return true; } |
| // string: value | |
| // unknown: "" | |
| // double: value | |
| // others: 0 | |
| virtual String *get_string() { return 0; } | |
| // text: value | // string: value |
| virtual void put_string(const String *astring) { failed("storing string"); } | // double: value |
| // bool: value | |
| // method_ref: self, method | virtual double get_double() { failed("getting numerical value of '%s'"); return 0; } |
| virtual Method_ref *get_method_ref() { failed("extracting method reference"); return 0; } | |
| // unknown: false | |
| // bool: value | |
| // double: 0 or !0 | |
| // string: empty or not | |
| // hash: size!=0 | |
| // TODO table: count!=0 | |
| // others: true | |
| virtual bool get_bool() { return true; } | |
| // junction: auto_calc,root,self,rcontext,wcontext, code | // junction: auto_calc,root,self,rcontext,wcontext, code |
| virtual Junction *get_junction() { failed("getting junction"); return 0; } | virtual Junction *get_junction() { return 0; } |
| // hash: (key)=value | // hash: (key)=value |
| // 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 |
| // object_instance: (field)=value;(STATIC)=hash;(method)=method_ref | // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref |
| // operator_class: (field)=value - static values only | // operator_class: (field)=value - static values only |
| virtual Value *get_element(const String& name) const =0; | // codeframe: wcontext_transparent |
| // methodframe: my or self_transparent | |
| virtual Value *get_element(String& name) { failed("type is '%s', can not get element from it"); return 0; } | |
| // hash: (key)=value | |
| // object_class, operator_class: (field)=value - static values only | // object_class, operator_class: (field)=value - static values only |
| virtual void put_element(const String& name, Value *value)=0; | // object_instance: (field)=value |
| // codeframe: wcontext_transparent | |
| // object_instance, object_class: method | // methodframe: my or self_transparent |
| virtual Method *get_method(const String& name) const { return 0; } | virtual void put_element(const String& name, Value *value) { failed("type is '%s', can not put element to it"); } |
| // object_class, object_instance: object_class | // object_class, object_instance: object_class |
| // wcontext: none yet | transparent | |
| virtual VClass *get_class() { return 0; } | virtual VClass *get_class() { return 0; } |
| // object_class: true when this class is this or derived from 'ancestor' | // valiased: this |
| virtual bool is_or_derived_from(VClass& ancestor) { failed("thoghts of ancestors"); return false; } | // wcontext: transparent |
| // methodframe: self_transparent | |
| virtual VAliased *get_aliased() { return 0; } | |
| private: | public: // usage |
| void failed(char *action) { | Value(Pool& apool) : Pooled(apool), fname(new(apool) String(apool)) { |
| pool().exception().raise(0,0, | fname->APPEND_CONST("unnamed"); |
| 0, | |
| action); | |
| } | } |
| }; | |
| /* | void set_name(String& aname) { fname=&aname; } |
| descendants: | |
| text:+ value:String | String& as_string() { |
| hash:+ keys&values:Hash | String *result=get_string(); |
| table:+ columns_order:Array, columns:Hash, rows:Array | if(!result) |
| object_class:+ STATIC:Hash, methods:Hash | failed("getting string of '%s'"); |
| object_instance:+ object_class, fields:Hash | return *result; |
| method_ref:+ self:Value/object_class, method:String | } |
| method_self_n_params_n_locals:+ self:Value/object_class[1st try], params_locals&values:Hash[2nd try] | |
| junction:+ self:Value, code:String | private: |
| */ | |
| String *fname; | |
| private: | |
| void failed(char *action); | |
| }; | |
| #endif | #endif |