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