Annotation of parser3/src/include/pa_value.h, revision 1.49

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