Annotation of parser3/src/types/pa_value.h, revision 1.3
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.3 ! paf 6: $Id: pa_value.h,v 1.2 2001/03/11 08:16:37 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:
31: typedef void (*Native_code_ptr)(Request& request, Array *params);
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:
58: void check_actual_numbered_params(Array *actual_numbered_params) {
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,
62: &name,
63: "native method accepts minimum %d parameters",
64: min_numbered_params_count);
65:
66: }
67: };
68:
69: class Junction : public Pooled {
70: public:
71:
72: Junction(Pool& apool,
73: Value& aself,
74: VClass *avclass, Method *amethod,
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'
91: VClass *vclass; Method *method;
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
113: virtual Value *get_expr_result() { failed("getting expression result of '%s'"); return 0; }
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
126: virtual double get_double() { failed("getting numerical value of '%s'"); return 0; }
127:
128: // unknown: false
129: // bool: value
130: // double: 0 or !0
131: // string: empty or not
132: // hash: size!=0
133: // TODO table: count!=0
134: // others: true
135: virtual bool get_bool() { return true; }
136:
137: // junction: auto_calc,root,self,rcontext,wcontext, code
138: virtual Junction *get_junction() { return 0; }
139:
140: // hash: (key)=value
141: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.3 ! paf 142: // object_base: (CLASS)=vclass;(BASE)=base;(method)=method_ref
1.1 paf 143: // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
144: // operator_class: (field)=value - static values only
145: // codeframe: wcontext_transparent
146: // methodframe: my or self_transparent
147: virtual Value *get_element(const String& name) { failed("type is '%s', can not get element from it"); return 0; }
148:
149: // hash: (key)=value
150: // object_class, operator_class: (field)=value - static values only
151: // object_instance: (field)=value
152: // codeframe: wcontext_transparent
153: // methodframe: my or self_transparent
154: virtual void put_element(const String& name, Value *value) { failed("type is '%s', can not put element to it"); }
155:
156: // object_class, object_instance: object_class
157: // wcontext: none yet | transparent
158: virtual VClass *get_class() { return 0; }
159:
160: // valiased: this
161: // wcontext: transparent
162: // methodframe: self_transparent
163: virtual VAliased *get_aliased() { return 0; }
164:
165: public: // usage
166:
167: Value(Pool& apool) : Pooled(apool), fname(unnamed_name) {
168: }
169:
170: void set_name(const String& aname) { fname=&aname; }
171:
172: const String& as_string() {
173: const String *result=get_string();
174: if(!result)
175: failed("getting string of '%s'");
176: return *result;
177: }
178:
179: private:
180:
181: const String *fname;
182:
183: private:
184:
185: void failed(char *action) const {
186: THROW(0,0,
187: &name(),
188: action, type());
189: }
190:
191: };
192:
193: #endif
E-mail: