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

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

E-mail: