Annotation of parser3/src/types/pa_value.h, revision 1.7
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.7 ! paf 6: $Id: pa_value.h,v 1.6 2001/03/12 12:00:06 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;
25: class VClass;
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(
60: const String& actual_name, Array *actual_numbered_params) {
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,
76: VClass *avclass, Method *amethod,
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'
93: VClass *vclass; Method *method;
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.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
164: virtual VClass *get_class() { return 0; }
165:
166: // valiased: this
167: // wcontext: transparent
168: // methodframe: self_transparent
169: virtual VAliased *get_aliased() { return 0; }
170:
171: public: // usage
172:
173: Value(Pool& apool) : Pooled(apool), fname(unnamed_name) {
174: }
175:
176: void set_name(const String& aname) { fname=&aname; }
177:
178: const String& as_string() {
179: const String *result=get_string();
180: if(!result)
1.7 ! paf 181: bark("(%s) not a string");
1.6 paf 182:
183: return *result;
184: }
185:
1.7 ! paf 186: VTable& as_vtable() {
! 187: VTable *result=get_vtable();
1.6 paf 188: if(!result)
1.7 ! paf 189: bark("(%s) not a table object");
1.6 paf 190:
1.1 paf 191: return *result;
192: }
193:
194: private:
195:
196: const String *fname;
197:
1.6 paf 198: protected:
1.1 paf 199:
1.7 ! paf 200: void bark(char *action) const {
1.1 paf 201: THROW(0,0,
202: &name(),
203: action, type());
204: }
205:
206: };
207:
208: #endif
E-mail: