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