Annotation of parser3/src/include/pa_value.h, revision 1.46
1.1 paf 1: /*
1.46 ! paf 2: $Id: pa_value.h,v 1.45 2001/03/08 13:42:31 paf Exp $
1.1 paf 3: */
4:
5: /*
6: data core
7: */
8:
9: #ifndef PA_VALUE_H
10: #define PA_VALUE_H
11:
1.9 paf 12: #include "pa_pool.h"
1.1 paf 13: #include "pa_string.h"
1.9 paf 14: #include "pa_array.h"
1.1 paf 15:
1.27 paf 16: #define NAME_NAME "NAME"
17:
1.9 paf 18: class Value;
19: class VClass;
20: class Junction;
21: class WContext;
1.33 paf 22: class VAliased;
1.43 paf 23: class Request;
24:
1.44 paf 25: typedef void (*Native_code_ptr)(Request& request, Array& params);
1.9 paf 26:
27: class Method : public Pooled {
1.1 paf 28: public:
1.11 paf 29: const String& name;
1.44 paf 30: // either numbered params // for native-code methods = operators
31: int numbered_params_count;
32: // or named params&locals // for parser-code methods
33: Array *params_names; Array *locals_names;
34: // the Code
1.43 paf 35: const Array *parser_code;/*OR*/Native_code_ptr native_code;
1.9 paf 36:
37: Method(
38: Pool& apool,
1.11 paf 39: const String& aname,
1.44 paf 40: int anumbered_params_count,
41: Array *aparams_names, Array *alocals_names,
1.43 paf 42: const Array *aparser_code, Native_code_ptr anative_code) :
1.19 paf 43:
1.9 paf 44: Pooled(apool),
45: name(aname),
1.44 paf 46: numbered_params_count(anumbered_params_count),
47: params_names(aparams_names), locals_names(alocals_names),
1.43 paf 48: parser_code(aparser_code), native_code(anative_code) {
1.9 paf 49: }
1.1 paf 50: };
51:
1.21 paf 52: class Junction : public Pooled {
1.2 paf 53: public:
54:
1.20 paf 55: Junction(Pool& apool,
1.34 paf 56: Value& aself,
1.33 paf 57: VClass *avclass, Method *amethod,
1.20 paf 58: Value *aroot,
59: Value *arcontext,
1.24 paf 60: WContext *awcontext,
1.23 paf 61: const Array *acode) : Pooled(apool),
1.20 paf 62:
1.24 paf 63: self(aself),
1.33 paf 64: vclass(avclass), method(amethod),
1.20 paf 65: root(aroot),
66: rcontext(arcontext),
1.24 paf 67: wcontext(awcontext),
1.20 paf 68: code(acode) {
69: }
70:
1.43 paf 71: // always present
1.34 paf 72: Value& self;
1.43 paf 73: // either these // so called 'method-junction'
1.33 paf 74: VClass *vclass; Method *method;
1.43 paf 75: // or these are present // so called 'code-junction'
1.21 paf 76: Value *root;
77: Value *rcontext;
1.24 paf 78: WContext *wcontext;
1.23 paf 79: const Array *code;
1.8 paf 80: };
81:
1.9 paf 82: class Value : public Pooled {
1.17 paf 83: public: // Value
1.9 paf 84:
85: // all: for error reporting after fail(), etc
1.13 paf 86: virtual const char *type() const =0;
1.43 paf 87: String& name() const { return *fname; }
1.46 ! paf 88: virtual Value *clone() const { failed("cloning '%s'"); return 0; }
1.9 paf 89:
1.40 paf 90: // unknown: false
91: // others: true
92: virtual bool get_defined() { return true; }
93:
1.13 paf 94: // string: value
1.16 paf 95: // unknown: ""
1.38 paf 96: // double: value
1.45 paf 97: // bool: must be 0: so in ^if(1>2) it would'nt become "FALSE" string which is 'true'
1.16 paf 98: // others: 0
1.13 paf 99: virtual String *get_string() { return 0; }
1.9 paf 100:
1.13 paf 101: // string: value
1.37 paf 102: // double: value
1.39 paf 103: // bool: value
1.37 paf 104: virtual double get_double() { failed("getting numerical value of '%s'"); return 0; }
1.39 paf 105:
106: // unknown: false
107: // bool: value
108: // double: 0 or !0
109: // string: empty or not
1.40 paf 110: // hash: size!=0
111: // TODO table: count!=0
112: // others: true
1.39 paf 113: virtual bool get_bool() { return true; }
1.1 paf 114:
1.9 paf 115: // junction: auto_calc,root,self,rcontext,wcontext, code
1.23 paf 116: virtual Junction *get_junction() { return 0; }
1.8 paf 117:
1.1 paf 118: // hash: (key)=value
1.2 paf 119: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.29 paf 120: // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
1.7 paf 121: // operator_class: (field)=value - static values only
1.24 paf 122: // codeframe: wcontext_transparent
1.30 paf 123: // methodframe: my or self_transparent
1.42 paf 124: virtual Value *get_element(const String& name) { failed("type is '%s', can not get element from it"); return 0; }
1.13 paf 125:
1.15 paf 126: // hash: (key)=value
1.9 paf 127: // object_class, operator_class: (field)=value - static values only
1.26 paf 128: // object_instance: (field)=value
1.24 paf 129: // codeframe: wcontext_transparent
1.30 paf 130: // methodframe: my or self_transparent
1.29 paf 131: virtual void put_element(const String& name, Value *value) { failed("type is '%s', can not put element to it"); }
1.5 paf 132:
133: // object_class, object_instance: object_class
1.32 paf 134: // wcontext: none yet | transparent
1.9 paf 135: virtual VClass *get_class() { return 0; }
1.34 paf 136:
137: // valiased: this
138: // wcontext: transparent
1.35 paf 139: // methodframe: self_transparent
1.36 paf 140: virtual VAliased *get_aliased() { return 0; }
1.9 paf 141:
1.17 paf 142: public: // usage
143:
1.28 paf 144: Value(Pool& apool) : Pooled(apool), fname(new(apool) String(apool)) {
145: fname->APPEND_CONST("unnamed");
146: }
1.17 paf 147:
1.27 paf 148: void set_name(String& aname) { fname=&aname; }
1.18 paf 149:
150: String& as_string() {
1.17 paf 151: String *result=get_string();
152: if(!result)
1.25 paf 153: failed("getting string of '%s'");
1.17 paf 154: return *result;
155: }
1.9 paf 156:
1.18 paf 157: private:
158:
1.27 paf 159: String *fname;
1.18 paf 160:
1.9 paf 161: private:
1.6 paf 162:
1.46 ! paf 163: void failed(char *action) const;
1.1 paf 164: };
165:
166: #endif
E-mail: