Annotation of parser3/src/types/pa_value.h, revision 1.20

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

E-mail: