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

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

E-mail: