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

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

E-mail: