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

1.8       paf         1: /**    @file
                      2:        Parser: stateless class.
                      3: 
1.35      misha       4:        Copyright (c) 2001-2009 ArtLebedev Group (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.40    ! misha       8: static const char * const IDENT_VSTATELESS_CLASS_C="$Date: 2009-05-13 07:35:27 $";
1.2       paf         9: 
                     10: #include "pa_vstateless_class.h"
1.24      paf        11: #include "pa_vproperty.h"
1.29      misha      12: #include "pa_vstring.h"
1.30      misha      13: #include "pa_vbool.h"
                     14: 
                     15: override Value& VStateless_class::as_expr_result(bool /*return_string_as_is=false*/) {
1.35      misha      16:        return VBool::get(as_bool());
1.30      misha      17: }
1.17      paf        18: 
1.24      paf        19: /// @TODO why?! request must be different ptr from global [used in VStateless_class.add_method]
1.17      paf        20: void VStateless_class::add_method(const String& name, Method& method) {
1.20      paf        21:        if(flocked)
1.31      misha      22:                throw Exception(PARSER_RUNTIME,
1.17      paf        23:                        &name,
                     24:                        "can not add method to system class (maybe you have forgotten .CLASS in ^process[$caller.CLASS]{...}?)");
1.20      paf        25: 
1.17      paf        26:        put_method(name, &method);
                     27: }
1.2       paf        28: 
                     29: void VStateless_class::add_native_method(
1.20      paf        30:        const char* cstr_name,
1.7       paf        31:        Method::Call_type call_type,
1.20      paf        32:        NativeCodePtr native_code,
1.38      misha      33:        int min_numbered_params_count, 
1.40    ! misha      34:        int max_numbered_params_count,
        !            35:        Method::Call_optimization
        !            36: #ifdef OPTIMIZE_CALL
        !            37:                call_optimization
        !            38: #endif
        !            39:        ) {
1.2       paf        40: 
1.20      paf        41:        const String& name=*new String(cstr_name);
1.2       paf        42:        
1.20      paf        43:        Method& method=*new Method(
1.7       paf        44:                call_type,
1.2       paf        45:                min_numbered_params_count, max_numbered_params_count,
                     46:                0/*params_names*/, 0/*locals_names*/,
1.40    ! misha      47:                0/*parser_code*/, native_code, false/*all_vars_local*/
        !            48: #ifdef OPTIMIZE_RESULT
        !            49:                , Method::RO_USE_WCONTEXT
        !            50: #endif
        !            51: #ifdef OPTIMIZE_CALL
        !            52:                , call_optimization
        !            53: #endif
        !            54:                );
1.39      misha      55: 
1.2       paf        56:        add_method(name, method);
1.16      paf        57: }
                     58: 
1.30      misha      59: /// VStateless_class: $CLASS, $CLASS_NAME, $method
1.32      misha      60: Value* VStateless_class::get_element(const String& aname, Value& aself, bool alooking_up) {
1.16      paf        61:        // $CLASS
                     62:        if(aname==CLASS_NAME)
                     63:                return this;
1.36      misha      64: 
1.29      misha      65:        // $CLASS_NAME
                     66:        if(aname==CLASS_NAMETEXT)
                     67:                return new VString(this->name());
1.36      misha      68: 
1.16      paf        69:        // $method=junction(self+class+method)
1.36      misha      70:        if(Method* method=get_method(aname)){
                     71:                if(!method->junction_template)
                     72:                        return method->junction_template=new VJunction(aself, method);
                     73: 
1.37      misha      74:                return method->junction_template->get(aself);
1.36      misha      75:        }
1.18      paf        76: 
                     77:        // base monkey
1.26      paf        78:        if(fbase) {
                     79:                if(Value* obase=aself.base()) // MXdoc has fbase but does not have object_base[ base() ]
1.32      misha      80:                        return fbase->get_element(aname, *obase, alooking_up);
1.26      paf        81:        }
1.18      paf        82: 
1.16      paf        83:        return 0;
1.23      paf        84: }
                     85: 
1.32      misha      86: void VStateless_class::put_method(const String& aname, Method* amethod){
1.25      paf        87:        fmethods.put(aname, amethod); 
1.2       paf        88: }
1.32      misha      89: 
                     90: Value* VStateless_class::get_default_getter(Value& aself, const String& aname){
                     91:        if(fdefault_getter)
                     92:                return new VJunction(aself, fdefault_getter, true /*getter*/, (String*)&aname);
                     93: 
                     94:        if(fbase)
                     95:                if(Value* obase=aself.base())
                     96:                        return fbase->get_default_getter(*obase, aname);
                     97: 
                     98:        return 0;
                     99: }
                    100: 
                    101: void VStateless_class::set_default_getter(Method* amethod){
                    102:        fdefault_getter=amethod;
                    103: }
                    104: 
1.33      misha     105: Value* VStateless_class::get_scalar(Value& aself){
                    106:        if(fscalar)
                    107:                return new VJunction(aself, fscalar, true /*getter*/);
                    108: 
                    109:        if(fbase)
                    110:                if(Value* obase=aself.base())
                    111:                        return fbase->get_scalar(*obase);
                    112: 
                    113:        return 0;
                    114: }
                    115: 
                    116: void VStateless_class::set_scalar(Method* amethod){
                    117:        fscalar=amethod;
1.34      misha     118: }

E-mail: