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