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