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

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

E-mail: