Annotation of parser3/src/include/pa_value.h, revision 1.48
1.48 ! paf 1:
1.1 paf 2: /*
1.48 ! paf 3: $Id: pa_value.h,v 1.47 2001/03/08 17:14:51 paf Exp $
1.1 paf 4: */
5:
6: /*
7: data core
8: */
9:
10: #ifndef PA_VALUE_H
11: #define PA_VALUE_H
12:
1.9 paf 13: #include "pa_pool.h"
1.1 paf 14: #include "pa_string.h"
1.9 paf 15: #include "pa_array.h"
1.48 ! paf 16: #include "pa_exception.h"
1.1 paf 17:
1.27 paf 18: #define NAME_NAME "NAME"
19:
1.9 paf 20: class Value;
21: class VClass;
22: class Junction;
23: class WContext;
1.33 paf 24: class VAliased;
1.43 paf 25: class Request;
26:
1.48 ! paf 27: typedef void (*Native_code_ptr)(Request& request, Array *params);
1.9 paf 28:
29: class Method : public Pooled {
1.1 paf 30: public:
1.11 paf 31: const String& name;
1.44 paf 32: // either numbered params // for native-code methods = operators
1.48 ! paf 33: int min_numbered_params_count, max_numbered_params_count;
1.44 paf 34: // or named params&locals // for parser-code methods
35: Array *params_names; Array *locals_names;
36: // the Code
1.43 paf 37: const Array *parser_code;/*OR*/Native_code_ptr native_code;
1.9 paf 38:
39: Method(
40: Pool& apool,
1.11 paf 41: const String& aname,
1.48 ! paf 42: int amin_numbered_params_count, int amax_numbered_params_count,
1.44 paf 43: Array *aparams_names, Array *alocals_names,
1.43 paf 44: const Array *aparser_code, Native_code_ptr anative_code) :
1.19 paf 45:
1.9 paf 46: Pooled(apool),
47: name(aname),
1.48 ! paf 48: min_numbered_params_count(amin_numbered_params_count),
! 49: max_numbered_params_count(amax_numbered_params_count),
1.44 paf 50: params_names(aparams_names), locals_names(alocals_names),
1.43 paf 51: parser_code(aparser_code), native_code(anative_code) {
1.9 paf 52: }
1.48 ! paf 53:
! 54: void check_actual_numbered_params(Array *actual_numbered_params) {
! 55: int actual_count=actual_numbered_params?actual_numbered_params->size():0;
! 56: if(actual_count<min_numbered_params_count) // not proper count? bark
! 57: THROW(0, 0,
! 58: &name,
! 59: "native method accepts minimum %d parameters",
! 60: min_numbered_params_count);
! 61:
! 62: }
1.1 paf 63: };
64:
1.21 paf 65: class Junction : public Pooled {
1.2 paf 66: public:
67:
1.20 paf 68: Junction(Pool& apool,
1.34 paf 69: Value& aself,
1.33 paf 70: VClass *avclass, Method *amethod,
1.20 paf 71: Value *aroot,
72: Value *arcontext,
1.24 paf 73: WContext *awcontext,
1.23 paf 74: const Array *acode) : Pooled(apool),
1.20 paf 75:
1.24 paf 76: self(aself),
1.33 paf 77: vclass(avclass), method(amethod),
1.20 paf 78: root(aroot),
79: rcontext(arcontext),
1.24 paf 80: wcontext(awcontext),
1.20 paf 81: code(acode) {
82: }
83:
1.43 paf 84: // always present
1.34 paf 85: Value& self;
1.43 paf 86: // either these // so called 'method-junction'
1.33 paf 87: VClass *vclass; Method *method;
1.43 paf 88: // or these are present // so called 'code-junction'
1.21 paf 89: Value *root;
90: Value *rcontext;
1.24 paf 91: WContext *wcontext;
1.23 paf 92: const Array *code;
1.8 paf 93: };
94:
1.9 paf 95: class Value : public Pooled {
1.17 paf 96: public: // Value
1.9 paf 97:
98: // all: for error reporting after fail(), etc
1.13 paf 99: virtual const char *type() const =0;
1.43 paf 100: String& name() const { return *fname; }
1.9 paf 101:
1.40 paf 102: // unknown: false
103: // others: true
104: virtual bool get_defined() { return true; }
1.48 ! paf 105: // string: fvalue as VDouble
! 106: // bool: this
! 107: // double: this
! 108: // int: this
! 109: virtual Value *get_expr_result() { failed("getting expression result of '%s'"); return 0; }
1.40 paf 110:
1.13 paf 111: // string: value
1.16 paf 112: // unknown: ""
1.38 paf 113: // double: value
1.45 paf 114: // bool: must be 0: so in ^if(1>2) it would'nt become "FALSE" string which is 'true'
1.16 paf 115: // others: 0
1.13 paf 116: virtual String *get_string() { return 0; }
1.9 paf 117:
1.13 paf 118: // string: value
1.37 paf 119: // double: value
1.48 ! paf 120: // integer: finteger
1.39 paf 121: // bool: value
1.37 paf 122: virtual double get_double() { failed("getting numerical value of '%s'"); return 0; }
1.39 paf 123:
124: // unknown: false
125: // bool: value
126: // double: 0 or !0
127: // string: empty or not
1.40 paf 128: // hash: size!=0
129: // TODO table: count!=0
130: // others: true
1.39 paf 131: virtual bool get_bool() { return true; }
1.1 paf 132:
1.9 paf 133: // junction: auto_calc,root,self,rcontext,wcontext, code
1.23 paf 134: virtual Junction *get_junction() { return 0; }
1.8 paf 135:
1.1 paf 136: // hash: (key)=value
1.2 paf 137: // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.29 paf 138: // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
1.7 paf 139: // operator_class: (field)=value - static values only
1.24 paf 140: // codeframe: wcontext_transparent
1.30 paf 141: // methodframe: my or self_transparent
1.42 paf 142: virtual Value *get_element(const String& name) { failed("type is '%s', can not get element from it"); return 0; }
1.13 paf 143:
1.15 paf 144: // hash: (key)=value
1.9 paf 145: // object_class, operator_class: (field)=value - static values only
1.26 paf 146: // object_instance: (field)=value
1.24 paf 147: // codeframe: wcontext_transparent
1.30 paf 148: // methodframe: my or self_transparent
1.29 paf 149: virtual void put_element(const String& name, Value *value) { failed("type is '%s', can not put element to it"); }
1.5 paf 150:
151: // object_class, object_instance: object_class
1.32 paf 152: // wcontext: none yet | transparent
1.9 paf 153: virtual VClass *get_class() { return 0; }
1.34 paf 154:
155: // valiased: this
156: // wcontext: transparent
1.35 paf 157: // methodframe: self_transparent
1.36 paf 158: virtual VAliased *get_aliased() { return 0; }
1.9 paf 159:
1.17 paf 160: public: // usage
161:
1.28 paf 162: Value(Pool& apool) : Pooled(apool), fname(new(apool) String(apool)) {
163: fname->APPEND_CONST("unnamed");
164: }
1.17 paf 165:
1.27 paf 166: void set_name(String& aname) { fname=&aname; }
1.18 paf 167:
168: String& as_string() {
1.17 paf 169: String *result=get_string();
170: if(!result)
1.25 paf 171: failed("getting string of '%s'");
1.17 paf 172: return *result;
173: }
1.9 paf 174:
1.18 paf 175: private:
176:
1.27 paf 177: String *fname;
1.18 paf 178:
1.9 paf 179: private:
1.6 paf 180:
1.46 paf 181: void failed(char *action) const;
1.1 paf 182: };
183:
184: #endif
E-mail: