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