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

1.1       paf         1: /*
1.40    ! paf         2:   $Id: pa_value.h,v 1.39 2001/03/06 15:30:48 paf Exp $
1.1       paf         3: */
                      4: 
                      5: /*
                      6:        data core
                      7: */
                      8: 
                      9: #ifndef PA_VALUE_H
                     10: #define PA_VALUE_H
                     11: 
1.9       paf        12: #include "pa_pool.h"
1.1       paf        13: #include "pa_string.h"
1.9       paf        14: #include "pa_array.h"
                     15: //#include "pa_voperator.h"
1.1       paf        16: 
1.27      paf        17: #define NAME_NAME "NAME"
                     18: 
1.9       paf        19: class Value;
                     20: class VClass;
                     21: //class VOperator;
                     22: class Junction;
                     23: class WContext;
1.33      paf        24: class VAliased;
1.9       paf        25: 
                     26: class Method : public Pooled {
1.1       paf        27: public:
1.11      paf        28:        const String& name;
                     29:        Array& params_names;
                     30:        Array& locals_names;
1.23      paf        31:        const Array& code;
1.9       paf        32: 
                     33:        Method(
                     34:                Pool& apool,
1.11      paf        35:                const String& aname,
                     36:                Array& aparams_names,
                     37:                Array& alocals_names,
1.23      paf        38:                const Array& acode) : 
1.19      paf        39: 
1.9       paf        40:                Pooled(apool),
                     41:                name(aname),
1.11      paf        42:                params_names(aparams_names),
                     43:                locals_names(alocals_names),
1.9       paf        44:                code(acode) {
                     45:        }
1.1       paf        46: };
                     47: 
1.9       paf        48: /*
1.7       paf        49: class Operator : public Method {
                     50:        // operator module static vars stored in there
1.9       paf        51:        VOperator_class *self;
1.7       paf        52: };
1.9       paf        53: */
1.7       paf        54: 
1.21      paf        55: class Junction : public Pooled {
1.2       paf        56: public:
                     57: 
1.20      paf        58:        Junction(Pool& apool,
1.34      paf        59:                Value& aself,
1.33      paf        60:                VClass *avclass, Method *amethod,
1.20      paf        61:                Value *aroot,
                     62:                Value *arcontext,
1.24      paf        63:                WContext *awcontext,
1.23      paf        64:                const Array *acode) : Pooled(apool),
1.20      paf        65:                
1.24      paf        66:                self(aself),
1.33      paf        67:                vclass(avclass), method(amethod),
1.20      paf        68:                root(aroot),
                     69:                rcontext(arcontext),
1.24      paf        70:                wcontext(awcontext),
1.20      paf        71:                code(acode) {
                     72:        }
                     73: 
1.34      paf        74:        Value& self;
1.33      paf        75:        VClass *vclass;  Method *method;
1.21      paf        76:        Value *root;
                     77:        Value *rcontext;
1.24      paf        78:        WContext *wcontext;
1.23      paf        79:        const Array *code;
1.8       paf        80: };
                     81: 
1.9       paf        82: class Value : public Pooled {
1.17      paf        83: public: // Value
1.9       paf        84: 
                     85:        // all: for error reporting after fail(), etc
1.13      paf        86:        virtual const char *type() const =0;
1.31      paf        87:        /*const*/ String& name() const { return *fname; }
1.9       paf        88: 
1.40    ! paf        89:        // unknown: false
        !            90:        // others: true
        !            91:        virtual bool get_defined() { return true; }
        !            92: 
1.13      paf        93:        // string: value
1.16      paf        94:        // unknown: ""
1.38      paf        95:        // double: value
1.16      paf        96:        // others: 0
1.13      paf        97:        virtual String *get_string() { return 0; }
1.9       paf        98:        
1.13      paf        99:        // string: value
1.37      paf       100:        // double: value
1.39      paf       101:        // bool: value
1.37      paf       102:        virtual double get_double() { failed("getting numerical value of '%s'"); return 0; }
1.39      paf       103: 
                    104:        // unknown: false
                    105:        // bool: value
                    106:        // double: 0 or !0
                    107:        // string: empty or not
1.40    ! paf       108:        // hash: size!=0
        !           109:        // TODO table: count!=0
        !           110:        // others: true
1.39      paf       111:        virtual bool get_bool() { return true; }
1.1       paf       112: 
1.9       paf       113:        // junction: auto_calc,root,self,rcontext,wcontext, code
1.23      paf       114:        virtual Junction *get_junction() { return 0; }
1.8       paf       115: 
1.1       paf       116:        // hash: (key)=value
1.2       paf       117:        // object_class: (field)=STATIC.value;(STATIC)=hash;(method)=method_ref with self=object_class
1.29      paf       118:        // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
1.7       paf       119:        // operator_class: (field)=value - static values only
1.24      paf       120:        // codeframe: wcontext_transparent
1.30      paf       121:        // methodframe: my or self_transparent
1.29      paf       122:        virtual Value *get_element(const String& name) { failed("type is '%s', can not get element from it"); return 0; }
1.13      paf       123:        
1.15      paf       124:        // hash: (key)=value
1.9       paf       125:        // object_class, operator_class: (field)=value - static values only
1.26      paf       126:        // object_instance: (field)=value
1.24      paf       127:        // codeframe: wcontext_transparent
1.30      paf       128:        // methodframe: my or self_transparent
1.29      paf       129:        virtual void put_element(const String& name, Value *value) { failed("type is '%s', can not put element to it"); }
1.5       paf       130: 
                    131:        // object_class, object_instance: object_class
1.32      paf       132:        // wcontext: none yet | transparent
1.9       paf       133:        virtual VClass *get_class() { return 0; }
1.34      paf       134: 
                    135:        // valiased: this
                    136:        // wcontext: transparent
1.35      paf       137:        // methodframe: self_transparent
1.36      paf       138:        virtual VAliased *get_aliased() { return 0; }
1.9       paf       139: 
1.17      paf       140: public: // usage
                    141: 
1.28      paf       142:        Value(Pool& apool) : Pooled(apool), fname(new(apool) String(apool)) {
                    143:                fname->APPEND_CONST("unnamed");
                    144:        }
1.17      paf       145: 
1.27      paf       146:        void set_name(String& aname) { fname=&aname; }
1.18      paf       147: 
                    148:        String& as_string() {
1.17      paf       149:                String *result=get_string(); 
                    150:                if(!result)
1.25      paf       151:                        failed("getting string of '%s'");
1.17      paf       152:                return *result;
                    153:        }
1.9       paf       154: 
1.18      paf       155: private:
                    156: 
1.27      paf       157:        String *fname;
1.18      paf       158: 
1.9       paf       159: private: 
1.6       paf       160: 
1.18      paf       161:        void failed(char *action);
1.1       paf       162: };
                    163: 
                    164: /*
                    165: descendants:
                    166:        text:+ value:String
                    167:     hash:+ keys&values:Hash
                    168:     table:+ columns_order:Array, columns:Hash, rows:Array
                    169:     object_class:+ STATIC:Hash, methods:Hash
                    170:     object_instance:+ object_class, fields:Hash
1.2       paf       171:     method_ref:+ self:Value/object_class, method:String
1.4       paf       172:     method_self_n_params_n_locals:+ self:Value/object_class[1st try], params_locals&values:Hash[2nd try]
1.8       paf       173:        junction:+ self:Value, code:String
1.1       paf       174: */
                    175: 
                    176: #endif

E-mail: