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