Annotation of parser3/src/types/pa_value.h, revision 1.33
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.33 ! paf 8: $Id: pa_value.h,v 1.32 2001/03/24 19:12:23 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.31 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.29 paf 94: - VAliased: $CLASS, $BASE
95: - VStateless_class: +$method
96: - VStateless_object: +$method
1.25 paf 97: - VCode_frame: wcontext_transparent
1.26 paf 98: - VMethod_frame: my or self_transparent
1.25 paf 99: - VTable: column
1.28 paf 100: - VEnv: field
1.25 paf 101: - VForm: CLASS,BASE,method,field
102: - VString: $CLASS,$BASE,$method
1.30 paf 103: - VRequest: fields
1.25 paf 104: - VResponse: CLASS,BASE,method,fields
1.28 paf 105: - VCookie: field
1.27 paf 106: - VFile: CLASS,BASE,method,field
1.26 paf 107: */
1.7 paf 108: virtual Value *get_element(const String& name) { bark("(%s) does not have elements"); return 0; }
1.31 paf 109: /** store Value element under @a name
1.22 paf 110: @return for
1.25 paf 111: - VHash: (key)=value
112: - VStateless_object: (CLASS)=vclass;(BASE)=base;(method)=method_ref
1.26 paf 113: - VStateless_class: (field)=value - static values only
114: - VStateless_object: (field)=value
1.25 paf 115: - VCode_frame: wcontext_transparent
1.26 paf 116: - VMethod_frame: my or self_transparent
1.25 paf 117: - VResponse: (attribute)=value
118: - VCookie: field
1.22 paf 119: */
1.7 paf 120: virtual void put_element(const String& name, Value *value) { bark("(%s) does not accept elements"); }
1.23 paf 121: /** extract VStateless_class
1.22 paf 122: @return for
1.25 paf 123: - VStateless_class: this
124: - VStateless_object: fclass_real
1.26 paf 125: - WContext: none yet | transparent
1.22 paf 126: */
1.9 paf 127: virtual VStateless_class *get_class() { return 0; }
1.23 paf 128: /** extract VAliased
1.22 paf 129: @return for
1.33 ! paf 130: - VAliased: this
1.26 paf 131: - WContext: transparent
132: - VMethod_frame: self_transparent
1.22 paf 133: */
1.1 paf 134: virtual VAliased *get_aliased() { return 0; }
1.32 paf 135:
136: /** extract VTable
137: @return for
138: - VTable: this
139: */
140: virtual VTable *get_vtable() { return 0; }
1.1 paf 141:
142: public: // usage
143:
144: Value(Pool& apool) : Pooled(apool), fname(unnamed_name) {
145: }
146:
1.22 paf 147: /// set's the name which is used in error messages
1.1 paf 148: void set_name(const String& aname) { fname=&aname; }
149:
1.26 paf 150: /// @return sure String. if it doesn't have string value barks
1.1 paf 151: const String& as_string() {
152: const String *result=get_string();
153: if(!result)
1.7 paf 154: bark("(%s) not a string");
1.6 paf 155:
1.1 paf 156: return *result;
157: }
158:
159: private:
160:
161: const String *fname;
162:
1.6 paf 163: protected:
1.1 paf 164:
1.22 paf 165: /// throws exception specifying bark-reason and name() type() of problematic value
166: void bark(char *reason) const {
1.1 paf 167: THROW(0,0,
168: &name(),
1.22 paf 169: reason, type());
1.1 paf 170: }
171:
1.17 paf 172: };
173:
1.22 paf 174: /// native code method
1.17 paf 175: typedef void (*Native_code_ptr)(Request& request,
176: const String& method_name, Array *params);
177:
1.23 paf 178: /** \b junction is some code joined with context of it's evaluation.
1.22 paf 179:
180: there are code-junctions and method-junctions
181: - code-junctions are used when some parameter passed in cury brackets
182: - method-junctions used in ^method[] calls or $method references
183: */
1.17 paf 184: class Junction : public Pooled {
185: public:
186:
187: Junction(Pool& apool,
188: Value& aself,
189: VStateless_class *avclass, const Method *amethod,
190: Value *aroot,
191: Value *arcontext,
192: WContext *awcontext,
193: const Array *acode) : Pooled(apool),
194:
195: self(aself),
196: vclass(avclass), method(amethod),
197: root(aroot),
198: rcontext(arcontext),
199: wcontext(awcontext),
200: code(acode) {
201: }
202:
1.22 paf 203: /// always present
1.17 paf 204: Value& self;
1.22 paf 205: //@{
206: /// @name either these // so called 'method-junction'
1.17 paf 207: VStateless_class *vclass; const Method *method;
1.22 paf 208: //@}
209: //@{
210: /// @name or these are present // so called 'code-junction'
1.17 paf 211: Value *root;
212: Value *rcontext;
213: WContext *wcontext;
214: const Array *code;
1.22 paf 215: //@}
1.17 paf 216: };
217:
1.23 paf 218: /**
1.22 paf 219: class method.
220:
221: methods can have
222: - named or
223: - numbered parameters
224:
225: methods can be
226: - parser or
227: - native onces
228:
229: hold
230: - parameter names or number limits
231: - local names
232: - code [parser or native]
233: */
1.17 paf 234: class Method : public Pooled {
235: public:
1.22 paf 236: /// method name for error reporting
1.17 paf 237: const String& name;
1.22 paf 238: //@{
239: /// @name either numbered params // for native-code methods = operators
1.17 paf 240: int min_numbered_params_count, max_numbered_params_count;
1.22 paf 241: //@}
242: //@{
243: /// @name or named params&locals // for parser-code methods
1.17 paf 244: Array *params_names; Array *locals_names;
1.22 paf 245: //@}
246: //@{
247: /// @name the Code
1.17 paf 248: const Array *parser_code;/*OR*/Native_code_ptr native_code;
1.22 paf 249: //@}
1.17 paf 250:
251: Method(
252: Pool& apool,
253: const String& aname,
254: int amin_numbered_params_count, int amax_numbered_params_count,
255: Array *aparams_names, Array *alocals_names,
256: const Array *aparser_code, Native_code_ptr anative_code) :
257:
258: Pooled(apool),
259: name(aname),
260: min_numbered_params_count(amin_numbered_params_count),
261: max_numbered_params_count(amax_numbered_params_count),
262: params_names(aparams_names), locals_names(alocals_names),
263: parser_code(aparser_code), native_code(anative_code) {
264: }
265:
1.22 paf 266: /// call this before invoking to ensure proper actual numbered params count
1.17 paf 267: void check_actual_numbered_params(
268: Value& self, const String& actual_name, Array *actual_numbered_params) const {
269: int actual_count=actual_numbered_params?actual_numbered_params->size():0;
270: if(actual_count<min_numbered_params_count) // not proper count? bark
271: THROW(0, 0,
272: &actual_name,
273: "native method of %s (%s) accepts minimum %d parameter(s)",
274: self.name().cstr(),
275: self.type(),
276: min_numbered_params_count);
277:
278: }
1.1 paf 279: };
280:
281: #endif
E-mail: