Annotation of parser3/src/types/pa_value.h, revision 1.24
1.22 paf 1: /** @file
1.24 ! paf 2: Parser: Value, Method, Junction class decls.
! 3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.24 ! paf 5:
1.2 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.1 paf 7:
1.24 ! paf 8: $Id: pa_value.h,v 1.23 2001/03/19 16:44:04 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_VALUE_H
12: #define PA_VALUE_H
13:
14: #include "pa_pool.h"
15: #include "pa_string.h"
16: #include "pa_array.h"
17: #include "pa_exception.h"
1.13 paf 18: #include "pa_globals.h"
1.1 paf 19:
1.9 paf 20: class VStateless_class;
1.1 paf 21: class WContext;
22: class VAliased;
23: class Request;
1.7 paf 24: class VTable;
1.17 paf 25: class Junction;
26: class Method;
1.20 paf 27: class Hash;
1.1 paf 28:
1.22 paf 29: /// grandfather of all \a values in \b Parser
1.1 paf 30: class Value : public Pooled {
31: public: // Value
32:
1.22 paf 33: /// - all: for error reporting after fail(), etc
1.1 paf 34: virtual const char *type() const =0;
1.22 paf 35: /// - all: for error reporting after fail(), etc
1.1 paf 36: const String& name() const { return *fname; }
1.23 paf 37: /** is this value defined?
1.22 paf 38: @return for
39: - unknown: false
40: - others: true
41: */
1.1 paf 42: virtual bool get_defined() { return true; }
1.23 paf 43: /** what's the meaning of this value in context of expression?
1.22 paf 44: @return for
45: - string: fstring as VDouble
46: - bool: this
47: - double: this
48: - int: this
49: - unknown: this
50: */
1.7 paf 51: virtual Value *get_expr_result() { bark("(%s) can not be used in expression"); return 0; }
1.23 paf 52: /** extract Hash
1.22 paf 53: @return for
54: - hash: fhash
55: - response: ffields
56: */
1.20 paf 57: virtual Hash *get_hash() { return 0; }
1.23 paf 58: /** extract const String
1.22 paf 59: @return for
60: - string: value
61: - unknown: ""
62: - double: value
63: - bool: must be 0: so in ^if(1>2) it would'nt become "FALSE" string which is 'true'
64: - others: 0
65: - WContext: accumulated fstring
66: */
1.1 paf 67: virtual const String *get_string() { return 0; }
1.23 paf 68: /** extract double
1.22 paf 69: @return for
70: - string: value
71: - double: value
72: - integer: finteger
73: - bool: value
74: */
1.7 paf 75: virtual double get_double() { bark("(%s) does not have numerical value"); return 0; }
1.23 paf 76: /** extract bool
1.22 paf 77: @return for
78: - unknown: false
79: - bool: value
80: - integer: 0 or !0
81: - double: 0 or !0
82: */
1.15 paf 83: virtual bool get_bool() { bark("(%s) does not have logical value"); return 0; }
1.23 paf 84: /** extract Junction
1.22 paf 85: @return for
86: - junction: itself
87: */
1.1 paf 88: virtual Junction *get_junction() { return 0; }
1.23 paf 89: /** extract VTable
1.22 paf 90: @return for
91: - table: itself
92: */
1.7 paf 93: virtual VTable *get_vtable() { return 0; }
1.23 paf 94: /** extract Value element
1.22 paf 95: @return for
96: - hash: (key)=value
97: - object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
98: - object_base: (CLASS)=vclass;(BASE)=base;(method)=method_ref
99: - object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
100: - operator_class: (field)=value - static values only
101: - codeframe: wcontext_transparent
102: - methodframe: my or self_transparent
103: - table: column
104: - env: CLASS,BASE,method,field
105: - form: CLASS,BASE,method,field
106: - string: $CLASS,$BASE,$method
107: - request: CLASS,BASE,method,fields
108: - response: CLASS,BASE,method,fields
109: - cookie: CLASS,BASE,method,field
110: */
1.7 paf 111: virtual Value *get_element(const String& name) { bark("(%s) does not have elements"); return 0; }
1.23 paf 112: /** store Value element under \a name
1.22 paf 113: @return for
114: - hash: (key)=value
115: - object_class, operator_class: (field)=value - static values only
116: - object_instance: (field)=value
117: - codeframe: wcontext_transparent
118: - methodframe: my or self_transparent
119: - response: (attribute)=value
120: - cookie: field
121: */
1.7 paf 122: virtual void put_element(const String& name, Value *value) { bark("(%s) does not accept elements"); }
1.23 paf 123: /** extract VStateless_class
1.22 paf 124: @return for
125: - object_class, object_instance: object_class
126: - wcontext: none yet | transparent
127: - form: this
128: - class: this
129: - env: this
130: - request: this
131: - hash: this
132: - vcookie: this
133: */
1.9 paf 134: virtual VStateless_class *get_class() { return 0; }
1.23 paf 135: /** extract VAliased
1.22 paf 136: @return for
137: - valiased: this
138: - wcontext: transparent
139: - methodframe: self_transparent
140: */
1.1 paf 141: virtual VAliased *get_aliased() { return 0; }
142:
143: public: // usage
144:
145: Value(Pool& apool) : Pooled(apool), fname(unnamed_name) {
146: }
147:
1.22 paf 148: /// set's the name which is used in error messages
1.1 paf 149: void set_name(const String& aname) { fname=&aname; }
150:
1.22 paf 151: /// \return sure String. if it doesn't have string value barks
1.1 paf 152: const String& as_string() {
153: const String *result=get_string();
154: if(!result)
1.7 paf 155: bark("(%s) not a string");
1.6 paf 156:
157: return *result;
158: }
159:
1.22 paf 160: /// \return sure VTable. if it doesn't have string value barks
1.7 paf 161: VTable& as_vtable() {
162: VTable *result=get_vtable();
1.6 paf 163: if(!result)
1.7 paf 164: bark("(%s) not a table object");
1.6 paf 165:
1.1 paf 166: return *result;
167: }
168:
169: private:
170:
171: const String *fname;
172:
1.6 paf 173: protected:
1.1 paf 174:
1.22 paf 175: /// throws exception specifying bark-reason and name() type() of problematic value
176: void bark(char *reason) const {
1.1 paf 177: THROW(0,0,
178: &name(),
1.22 paf 179: reason, type());
1.1 paf 180: }
181:
1.17 paf 182: };
183:
1.22 paf 184: /// native code method
1.17 paf 185: typedef void (*Native_code_ptr)(Request& request,
186: const String& method_name, Array *params);
187:
1.23 paf 188: /** \b junction is some code joined with context of it's evaluation.
1.22 paf 189:
190: there are code-junctions and method-junctions
191: - code-junctions are used when some parameter passed in cury brackets
192: - method-junctions used in ^method[] calls or $method references
193: */
1.17 paf 194: class Junction : public Pooled {
195: public:
196:
197: Junction(Pool& apool,
198: Value& aself,
199: VStateless_class *avclass, const Method *amethod,
200: Value *aroot,
201: Value *arcontext,
202: WContext *awcontext,
203: const Array *acode) : Pooled(apool),
204:
205: self(aself),
206: vclass(avclass), method(amethod),
207: root(aroot),
208: rcontext(arcontext),
209: wcontext(awcontext),
210: code(acode) {
211: }
212:
1.22 paf 213: /// always present
1.17 paf 214: Value& self;
1.22 paf 215: //@{
216: /// @name either these // so called 'method-junction'
1.17 paf 217: VStateless_class *vclass; const Method *method;
1.22 paf 218: //@}
219: //@{
220: /// @name or these are present // so called 'code-junction'
1.17 paf 221: Value *root;
222: Value *rcontext;
223: WContext *wcontext;
224: const Array *code;
1.22 paf 225: //@}
1.17 paf 226: };
227:
1.23 paf 228: /**
1.22 paf 229: class method.
230:
231: methods can have
232: - named or
233: - numbered parameters
234:
235: methods can be
236: - parser or
237: - native onces
238:
239: hold
240: - parameter names or number limits
241: - local names
242: - code [parser or native]
243: */
1.17 paf 244: class Method : public Pooled {
245: public:
1.22 paf 246: /// method name for error reporting
1.17 paf 247: const String& name;
1.22 paf 248: //@{
249: /// @name either numbered params // for native-code methods = operators
1.17 paf 250: int min_numbered_params_count, max_numbered_params_count;
1.22 paf 251: //@}
252: //@{
253: /// @name or named params&locals // for parser-code methods
1.17 paf 254: Array *params_names; Array *locals_names;
1.22 paf 255: //@}
256: //@{
257: /// @name the Code
1.17 paf 258: const Array *parser_code;/*OR*/Native_code_ptr native_code;
1.22 paf 259: //@}
1.17 paf 260:
261: Method(
262: Pool& apool,
263: const String& aname,
264: int amin_numbered_params_count, int amax_numbered_params_count,
265: Array *aparams_names, Array *alocals_names,
266: const Array *aparser_code, Native_code_ptr anative_code) :
267:
268: Pooled(apool),
269: name(aname),
270: min_numbered_params_count(amin_numbered_params_count),
271: max_numbered_params_count(amax_numbered_params_count),
272: params_names(aparams_names), locals_names(alocals_names),
273: parser_code(aparser_code), native_code(anative_code) {
274: }
275:
1.22 paf 276: /// call this before invoking to ensure proper actual numbered params count
1.17 paf 277: void check_actual_numbered_params(
278: Value& self, const String& actual_name, Array *actual_numbered_params) const {
279: int actual_count=actual_numbered_params?actual_numbered_params->size():0;
280: if(actual_count<min_numbered_params_count) // not proper count? bark
281: THROW(0, 0,
282: &actual_name,
283: "native method of %s (%s) accepts minimum %d parameter(s)",
284: self.name().cstr(),
285: self.type(),
286: min_numbered_params_count);
287:
288: }
1.1 paf 289: };
290:
291: #endif
E-mail: