Annotation of parser3/src/types/pa_vstateless_class.C, revision 1.54

1.8       paf         1: /**    @file
                      2:        Parser: stateless class.
                      3: 
1.52      moko        4:        Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)
1.13      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)\
1.14      paf         6: */
1.8       paf         7: 
1.2       paf         8: #include "pa_vstateless_class.h"
1.29      misha       9: #include "pa_vstring.h"
1.30      misha      10: #include "pa_vbool.h"
1.45      moko       11: #include "pa_request.h"
1.30      misha      12: 
1.54    ! moko       13: volatile const char * IDENT_PA_VSTATELESS_CLASS_C="$Id: pa_vstateless_class.C,v 1.53 2016/04/06 20:47:15 moko Exp $" IDENT_PA_VSTATELESS_CLASS_H IDENT_PA_METHOD_H;
1.47      moko       14: 
1.54    ! moko       15: const String class_element_name(CLASS_NAME), class_name_element_name(CLASS_NAME_ELEMENT_NAME);
1.41      misha      16: 
1.48      moko       17: override Value& VStateless_class::as_expr_result() {
1.35      misha      18:        return VBool::get(as_bool());
1.30      misha      19: }
1.17      paf        20: 
1.43      misha      21: /// @TODO why?! request must be different ptr from global [used in VStateless_class.set_method]
                     22: void VStateless_class::set_method(const String& aname, Method* amethod) {
1.20      paf        23:        if(flocked)
1.31      misha      24:                throw Exception(PARSER_RUNTIME,
1.42      misha      25:                        &aname,
1.17      paf        26:                        "can not add method to system class (maybe you have forgotten .CLASS in ^process[$caller.CLASS]{...}?)");
1.20      paf        27: 
1.43      misha      28:        if(fderived.count()) {
                     29:                Method *omethod=fmethods.get(aname);
                     30:                Array_iterator<VStateless_class *> i(fderived);
                     31:                while(i.has_next()) {
                     32:                        VStateless_class *c=i.next();
                     33:                        if(c->fmethods.get(aname)==omethod)
1.44      misha      34:                                c->real_set_method(aname, amethod);
1.43      misha      35:                }
                     36:        }
1.44      misha      37:        real_set_method(aname, amethod); 
                     38: }
                     39: 
                     40: void VStateless_class::real_set_method(const String& aname, Method* amethod) {
                     41:        fmethods.put(aname, amethod);
1.17      paf        42: }
1.2       paf        43: 
                     44: void VStateless_class::add_native_method(
1.20      paf        45:        const char* cstr_name,
1.7       paf        46:        Method::Call_type call_type,
1.20      paf        47:        NativeCodePtr native_code,
1.38      misha      48:        int min_numbered_params_count, 
1.40      misha      49:        int max_numbered_params_count,
                     50:        Method::Call_optimization
                     51: #ifdef OPTIMIZE_CALL
                     52:                call_optimization
                     53: #endif
                     54:        ) {
1.2       paf        55: 
1.43      misha      56:        Method* method=new Method(
1.7       paf        57:                call_type,
1.2       paf        58:                min_numbered_params_count, max_numbered_params_count,
                     59:                0/*params_names*/, 0/*locals_names*/,
1.40      misha      60:                0/*parser_code*/, native_code, false/*all_vars_local*/
                     61: #ifdef OPTIMIZE_RESULT
                     62:                , Method::RO_USE_WCONTEXT
                     63: #endif
                     64: #ifdef OPTIMIZE_CALL
                     65:                , call_optimization
                     66: #endif
                     67:                );
1.39      misha      68: 
1.43      misha      69:        set_method(*new String(cstr_name), method);
1.16      paf        70: }
                     71: 
1.51      misha      72: /// VStateless_class: $method
1.42      misha      73: Value* VStateless_class::get_element(Value& aself, const String& aname) {
1.51      misha      74: #ifndef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
1.16      paf        75:        // $CLASS
1.54    ! moko       76:        if(aname==class_element_name)
1.16      paf        77:                return this;
1.36      misha      78: 
1.29      misha      79:        // $CLASS_NAME
1.54    ! moko       80:        if(aname==class_name_element_name)
1.53      moko       81:                return new VString(*new String(type()));
1.51      misha      82: #endif
1.36      misha      83: 
1.16      paf        84:        // $method=junction(self+class+method)
1.49      misha      85:        if(Method* method=get_method(aname))
                     86:                return method->get_vjunction(aself);
1.18      paf        87: 
1.42      misha      88:        return 0;
                     89: }
                     90: 
                     91: Value* VStateless_class::get_scalar(Value& aself){
                     92:        if(fscalar)
                     93:                return new VJunction(aself, fscalar, true /*getter*/);
1.16      paf        94:        return 0;
1.23      paf        95: }
                     96: 
1.42      misha      97: void VStateless_class::set_scalar(Method* amethod){
                     98:        fscalar=amethod;
1.2       paf        99: }
1.32      misha     100: 
                    101: Value* VStateless_class::get_default_getter(Value& aself, const String& aname){
1.46      moko      102:        if(fdefault_getter && aself.is_enabled_default_getter())
1.32      misha     103:                return new VJunction(aself, fdefault_getter, true /*getter*/, (String*)&aname);
                    104:        return 0;
                    105: }
                    106: 
                    107: void VStateless_class::set_default_getter(Method* amethod){
                    108:        fdefault_getter=amethod;
                    109: }
                    110: 
1.46      moko      111: bool VStateless_class::has_default_getter(){
                    112:        return fdefault_getter != NULL;
                    113: }
                    114: 
                    115: VJunction* VStateless_class::get_default_setter(Value& aself, const String& aname){
1.50      moko      116:        if(fdefault_setter && aself.is_enabled_default_setter())
1.46      moko      117:                return new VJunction(aself, fdefault_setter, false /*setter*/, (String*)&aname);
                    118:        return 0;
                    119: }
                    120: 
                    121: void VStateless_class::set_default_setter(Method* amethod){
                    122:        fdefault_setter=amethod;
                    123: }
                    124: 
                    125: bool VStateless_class::has_default_setter(){
                    126:        return fdefault_setter != NULL;
                    127: }
                    128: 
1.42      misha     129: void VStateless_class::set_base(VStateless_class* abase){
                    130:        if(abase){
                    131:                fbase=abase;
                    132:                fbase->add_derived(*this);
                    133: 
1.45      moko      134:                bool no_auto = fmethods.get(auto_method_name) == NULL;
1.42      misha     135:                // we assume there is no derivatives at this point
                    136:                fmethods.merge_dont_replace(abase->fmethods);
1.45      moko      137:                // we don't want to inherit @auto (issue #75)
                    138:                if (no_auto) fmethods.remove(auto_method_name);
1.42      misha     139: 
                    140:                if(fbase->fscalar && !fscalar)
                    141:                        fscalar=fbase->fscalar;
                    142:                if(fbase->fdefault_getter && !fdefault_getter)
                    143:                        fdefault_getter=fbase->fdefault_getter;
1.46      moko      144:                if(fbase->fdefault_setter && !fdefault_setter)
                    145:                        fdefault_setter=fbase->fdefault_setter;
1.42      misha     146:        }
1.33      misha     147: }
                    148: 
1.42      misha     149: void VStateless_class::add_derived(VStateless_class &aclass){
                    150:        fderived+=&aclass;
                    151:        if (fbase)
                    152:                fbase->add_derived(aclass);
1.34      misha     153: }

E-mail: