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