Annotation of parser3/src/types/pa_vstateless_class.h, revision 1.81

1.6       paf         1: /** @file
                      2:        Parser: stateless class decls.
                      3: 
1.78      moko        4:        Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)
1.23      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.2       paf         6: */
                      7: 
                      8: #ifndef PA_VSTATELESS_CLASS_H
                      9: #define PA_VSTATELESS_CLASS_H
1.27      paf        10: 
1.81    ! moko       11: #define IDENT_PA_VSTATELESS_CLASS_H "$Id: pa_vstateless_class.h,v 1.80 2016/04/06 16:08:20 moko Exp $"
1.43      paf        12: 
                     13: // include
1.2       paf        14: 
1.45      paf        15: #include "pa_pool.h"
1.13      paf        16: #include "pa_hash.h"
1.2       paf        17: #include "pa_vjunction.h"
1.43      paf        18: #include "pa_method.h"
1.2       paf        19: 
1.38      paf        20: // defines
                     21: 
                     22: #define CLASS_NAME "CLASS"
1.81    ! moko       23: #define CLASS_NAME_ELEMENT_NAME "CLASS_NAME"
        !            24: extern const String class_element_name, class_name_element_name;
1.38      paf        25: 
                     26: // forwards
                     27: 
1.43      paf        28: class VStateless_class;
1.59      misha      29: typedef Array<VStateless_class*> ArrayClass;
1.66      misha      30: typedef HashString<Property *> HashStringProperty;
                     31: typedef HashString<Method *> HashStringMethod;
1.43      paf        32: 
1.2       paf        33: class Temp_method;
                     34: 
1.6       paf        35: /**
1.30      paf        36:        object' class. stores
                     37:        - base: VClass::base()
                     38:        - methods: VStateless_class::fmethods
1.6       paf        39: 
1.30      paf        40:        @see Method, VStateless_object, Temp_method
1.6       paf        41: */
1.39      paf        42: class VStateless_class: public Value {
1.19      paf        43:        friend class Temp_method;
1.43      paf        44: 
1.66      misha      45:        HashStringMethod fmethods;
1.43      paf        46: 
                     47:        bool flocked;
1.57      misha      48:        bool fall_vars_local;
1.61      misha      49:        bool fpartial;
1.70      misha      50:        Method::Call_type fcall_type;
1.43      paf        51: 
                     52: protected:
                     53: 
                     54:        VStateless_class* fbase;
1.68      misha      55:        /// all derived classes, recursively
1.66      misha      56:        ArrayClass fderived;
                     57: 
1.60      misha      58:        Method* fscalar;
1.58      misha      59:        Method* fdefault_getter;
1.71      moko       60:        Method* fdefault_setter;
1.43      paf        61: 
1.2       paf        62: public: // Value
                     63:        
1.5       paf        64:        /// VStateless_class: this
1.69      misha      65:        override VStateless_class* get_class() { return this; }
1.41      paf        66:        /// VStateless_class: fbase
1.69      misha      67:        override VStateless_class* base() { return fbase; }
1.66      misha      68: 
                     69:        override Value* get_element(const String& aname) { return get_element(*this, aname); }
                     70:        /// get_element with aself for VObject junctions
                     71:        virtual Value* get_element(Value& aself, const String& aname);
                     72: 
1.75      moko       73:        override const VJunction* put_element(const String& aname, Value* avalue) {     return put_element(*this, aname, avalue); }
1.66      misha      74:        /// put_element with aself for VObject junctions
1.75      moko       75:        virtual const VJunction* put_element(Value& aself, const String& aname, Value* /*avalue*/) {    
1.72      moko       76:                aself.bark("element can not be stored to %s", &aname); 
                     77:                return 0;
                     78:        }
1.66      misha      79: 
1.74      moko       80:        override Value& as_expr_result();
1.60      misha      81: 
1.66      misha      82:        Value* get_scalar(Value& aself);
                     83:        void set_scalar(Method* amethod);
1.2       paf        84: 
1.66      misha      85:        Value* get_default_getter(Value& aself, const String& aname);
                     86:        void set_default_getter(Method* amethod);
1.71      moko       87:        bool has_default_getter();
                     88: 
                     89:        VJunction* get_default_setter(Value& aself, const String& aname);
                     90:        void set_default_setter(Method* amethod);
                     91:        bool has_default_setter();
1.60      misha      92: 
1.66      misha      93:        void add_derived(VStateless_class &aclass);
1.61      misha      94: 
1.2       paf        95: public: // usage
                     96: 
1.80      moko       97:        VStateless_class(VStateless_class* amethoded_donor=0):
1.43      paf        98:                flocked(false),
1.66      misha      99:                fbase(0),
                    100:                fderived(0),
1.58      misha     101:                fall_vars_local(false),
1.61      misha     102:                fpartial(false),
1.60      misha     103:                fscalar(0),
1.70      misha     104:                fdefault_getter(0),
1.71      moko      105:                fdefault_setter(0),
1.70      misha     106:                fcall_type(Method::CT_ANY)
1.80      moko      107:        {
                    108:                if(amethoded_donor)
                    109:                        fmethods.merge_dont_replace(amethoded_donor->fmethods);
1.2       paf       110:        }
                    111: 
1.43      paf       112:        void lock() { flocked=true; }
                    113: 
                    114:        Method* get_method(const String& aname) const { 
                    115:                return fmethods.get(aname);
1.2       paf       116:        }
                    117: 
1.66      misha     118:        HashStringMethod get_methods(){
1.65      misha     119:                return fmethods;
                    120:        }
                    121: 
1.61      misha     122:        bool is_vars_local(){
                    123:                return fall_vars_local;
                    124:        }
                    125: 
                    126:        void set_all_vars_local(){
1.57      misha     127:                fall_vars_local=true;
                    128:        }
                    129: 
1.61      misha     130:        bool is_partial(){
                    131:                return fpartial;
                    132:        }
                    133: 
                    134:        void set_partial(){
                    135:                fpartial=true;
1.57      misha     136:        }
                    137: 
1.70      misha     138:        Method::Call_type get_methods_call_type(){
                    139:                return fcall_type;
                    140:        }
                    141: 
                    142:        void set_methods_call_type(Method::Call_type call_type){
                    143:                if(fcall_type!=Method::CT_ANY)
                    144:                        throw Exception(PARSER_RUNTIME,
                    145:                                                0,
                    146:                                                "You can specify call type option in a class only once"
                    147:                                        );
                    148:                fcall_type=call_type;
                    149:        }
                    150: 
1.2       paf       151:        void add_native_method(
1.43      paf       152:                const char* cstr_name,
1.9       paf       153:                Method::Call_type call_type,
1.43      paf       154:                NativeCodePtr native_code,
1.62      misha     155:                int min_numbered_params_count, 
                    156:                int max_numbered_params_count, 
                    157:                Method::Call_optimization call_optimization=Method::CO_WITHOUT_WCONTEXT);
1.66      misha     158: 
1.68      misha     159:        void set_method(const String& aname, Method* amethod);
                    160: 
1.66      misha     161:        /// overrided in VClass
1.80      moko      162:        virtual void set_type(const char *atype) {}
1.68      misha     163:        virtual void real_set_method(const String& aname, Method* amethod);
1.66      misha     164:        virtual HashStringProperty* get_properties(){ return 0; };
                    165:        virtual void set_base(VStateless_class* abase);
1.2       paf       166:        
1.43      paf       167:        VStateless_class* base_class() { return fbase; }
1.2       paf       168: 
1.66      misha     169:        bool derived_from(VStateless_class& vclass){
1.77      moko      170:                return fbase==&vclass || ( fbase && fbase->derived_from(vclass) );
1.31      paf       171:        }
                    172: 
1.21      paf       173:        /// @returns new value for current class, used in classes/ & VClass
1.66      misha     174:        virtual Value* create_new_value(Pool&) { return 0; }
1.2       paf       175: };
                    176: 
1.6       paf       177: ///    Auto-object used for temporarily substituting/removing class method
1.2       paf       178: class Temp_method {
                    179:        VStateless_class& fclass;
                    180:        const String& fname;
1.43      paf       181:        Method* saved_method;
1.2       paf       182: public:
1.43      paf       183:        Temp_method(VStateless_class& aclass, const String& aname, Method* amethod) : 
1.2       paf       184:                fclass(aclass),
                    185:                fname(aname),
                    186:                saved_method(aclass.get_method(aname)) {
1.67      misha     187:                fclass.set_method(aname, amethod);
1.2       paf       188:        }
                    189:        ~Temp_method() { 
1.67      misha     190:                fclass.set_method(fname, saved_method);
1.2       paf       191:        }
                    192: };
                    193: 
                    194: #endif

E-mail: