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

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

E-mail: