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