Annotation of parser3/src/types/pa_value.h, revision 1.21
1.1 paf 1: /*
2: Parser
3: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.2 paf 4: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1 paf 5:
1.21 ! paf 6: $Id: pa_value.h,v 1.20 2001/03/18 17:39:30 paf Exp $
1.1 paf 7: */
8:
9: /*
10: data core
11: */
12:
13: #ifndef PA_VALUE_H
14: #define PA_VALUE_H
15:
16: #include "pa_pool.h"
17: #include "pa_string.h"
18: #include "pa_array.h"
19: #include "pa_exception.h"
1.13 paf 20: #include "pa_globals.h"
1.1 paf 21:
1.9 paf 22: class VStateless_class;
1.1 paf 23: class WContext;
24: class VAliased;
25: class Request;
1.7 paf 26: class VTable;
1.17 paf 27: class Junction;
28: class Method;
1.20 paf 29: class Hash;
1.1 paf 30:
31: class Value : public Pooled {
32: public: // Value
33:
34: // all: for error reporting after fail(), etc
35: virtual const char *type() const =0;
36: const String& name() const { return *fname; }
37:
38: // unknown: false
39: // others: true
40: virtual bool get_defined() { return true; }
1.15 paf 41: // string: fstring as VDouble
1.1 paf 42: // bool: this
43: // double: this
44: // int: this
1.21 ! paf 45: // unknown: this
1.7 paf 46: virtual Value *get_expr_result() { bark("(%s) can not be used in expression"); return 0; }
1.19 paf 47:
1.20 paf 48: // hash: fhash
49: // response: ffields
50: virtual Hash *get_hash() { return 0; }
1.1 paf 51:
52: // string: value
53: // unknown: ""
54: // double: value
55: // bool: must be 0: so in ^if(1>2) it would'nt become "FALSE" string which is 'true'
56: // others: 0
1.16 paf 57: // WContext: accumulated fstring
1.1 paf 58: virtual const String *get_string() { return 0; }
59:
60: // string: value
61: // double: value
62: // integer: finteger
63: // bool: value
1.7 paf 64: virtual double get_double() { bark("(%s) does not have numerical value"); return 0; }
1.1 paf 65:
66: // unknown: false
67: // bool: value
1.15 paf 68: // integer: 0 or !0
1.1 paf 69: // double: 0 or !0
1.15 paf 70: virtual bool get_bool() { bark("(%s) does not have logical value"); return 0; }
1.1 paf 71:
1.7 paf 72: // junction: itself
1.1 paf 73: virtual Junction *get_junction() { return 0; }
74:
1.6 paf 75: // table: itself
1.7 paf 76: virtual VTable *get_vtable() { return 0; }
1.6 paf 77:
1.1 paf 78: // hash: (key)=value
79: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.3 paf 80: // object_base: (CLASS)=vclass;(BASE)=base;(method)=method_ref
1.1 paf 81: // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
82: // operator_class: (field)=value - static values only
83: // codeframe: wcontext_transparent
84: // methodframe: my or self_transparent
1.6 paf 85: // table: column
1.9 paf 86: // env: CLASS,BASE,method,field
1.11 paf 87: // form: CLASS,BASE,method,field
1.14 paf 88: // string: $CLASS,$BASE,$method
1.17 paf 89: // request: CLASS,BASE,method,fields
1.18 paf 90: // response: CLASS,BASE,method,fields
1.21 ! paf 91: // cookie: CLASS,BASE,method,field
1.7 paf 92: virtual Value *get_element(const String& name) { bark("(%s) does not have elements"); return 0; }
1.1 paf 93:
94: // hash: (key)=value
95: // object_class, operator_class: (field)=value - static values only
96: // object_instance: (field)=value
97: // codeframe: wcontext_transparent
98: // methodframe: my or self_transparent
1.18 paf 99: // response: (attribute)=value
1.21 ! paf 100: // cookie: field
1.7 paf 101: virtual void put_element(const String& name, Value *value) { bark("(%s) does not accept elements"); }
1.1 paf 102:
103: // object_class, object_instance: object_class
104: // wcontext: none yet | transparent
1.12 paf 105: // form: this
106: // class: this
107: // env: this
1.17 paf 108: // request: this
1.18 paf 109: // hash: this
1.21 ! paf 110: // vcookie: this
1.9 paf 111: virtual VStateless_class *get_class() { return 0; }
1.1 paf 112:
113: // valiased: this
114: // wcontext: transparent
115: // methodframe: self_transparent
116: virtual VAliased *get_aliased() { return 0; }
117:
118: public: // usage
119:
120: Value(Pool& apool) : Pooled(apool), fname(unnamed_name) {
121: }
122:
123: void set_name(const String& aname) { fname=&aname; }
124:
125: const String& as_string() {
126: const String *result=get_string();
127: if(!result)
1.7 paf 128: bark("(%s) not a string");
1.6 paf 129:
130: return *result;
131: }
132:
1.7 paf 133: VTable& as_vtable() {
134: VTable *result=get_vtable();
1.6 paf 135: if(!result)
1.7 paf 136: bark("(%s) not a table object");
1.6 paf 137:
1.1 paf 138: return *result;
139: }
140:
141: private:
142:
143: const String *fname;
144:
1.6 paf 145: protected:
1.1 paf 146:
1.7 paf 147: void bark(char *action) const {
1.1 paf 148: THROW(0,0,
149: &name(),
150: action, type());
151: }
152:
1.17 paf 153: };
154:
155: typedef void (*Native_code_ptr)(Request& request,
156: const String& method_name, Array *params);
157:
158: class Junction : public Pooled {
159: public:
160:
161: Junction(Pool& apool,
162: Value& aself,
163: VStateless_class *avclass, const Method *amethod,
164: Value *aroot,
165: Value *arcontext,
166: WContext *awcontext,
167: const Array *acode) : Pooled(apool),
168:
169: self(aself),
170: vclass(avclass), method(amethod),
171: root(aroot),
172: rcontext(arcontext),
173: wcontext(awcontext),
174: code(acode) {
175: }
176:
177: // always present
178: Value& self;
179: // either these // so called 'method-junction'
180: VStateless_class *vclass; const Method *method;
181: // or these are present // so called 'code-junction'
182: Value *root;
183: Value *rcontext;
184: WContext *wcontext;
185: const Array *code;
186: };
187:
188: class Method : public Pooled {
189: public:
190: const String& name;
191: // either numbered params // for native-code methods = operators
192: int min_numbered_params_count, max_numbered_params_count;
193: // or named params&locals // for parser-code methods
194: Array *params_names; Array *locals_names;
195: // the Code
196: const Array *parser_code;/*OR*/Native_code_ptr native_code;
197:
198: Method(
199: Pool& apool,
200: const String& aname,
201: int amin_numbered_params_count, int amax_numbered_params_count,
202: Array *aparams_names, Array *alocals_names,
203: const Array *aparser_code, Native_code_ptr anative_code) :
204:
205: Pooled(apool),
206: name(aname),
207: min_numbered_params_count(amin_numbered_params_count),
208: max_numbered_params_count(amax_numbered_params_count),
209: params_names(aparams_names), locals_names(alocals_names),
210: parser_code(aparser_code), native_code(anative_code) {
211: }
212:
213: void check_actual_numbered_params(
214: Value& self, const String& actual_name, Array *actual_numbered_params) const {
215: int actual_count=actual_numbered_params?actual_numbered_params->size():0;
216: if(actual_count<min_numbered_params_count) // not proper count? bark
217: THROW(0, 0,
218: &actual_name,
219: "native method of %s (%s) accepts minimum %d parameter(s)",
220: self.name().cstr(),
221: self.type(),
222: min_numbered_params_count);
223:
224: }
1.1 paf 225: };
226:
227: #endif
E-mail: