Annotation of parser3/src/types/pa_method.h, revision 1.26

1.2       paf         1: /** @file
                      2:        Parser: Method class decl.
                      3: 
1.23      moko        4:        Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)
1.2       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
                      8: #ifndef PA_METHOD_H
                      9: #define PA_METHOD_H
                     10: 
1.26    ! moko       11: #define IDENT_PA_METHOD_H "$Id: pa_method.h,v 1.25 2016/09/26 20:22:33 moko Exp $"
1.2       paf        12: 
1.13      misha      13: #define OPTIMIZE_CALL
1.14      misha      14: #define OPTIMIZE_RESULT
1.2       paf        15: 
                     16: #include "pa_operation.h"
1.20      misha      17: #include "pa_vjunction.h"
1.2       paf        18: 
                     19: /**
                     20:        native code method
                     21:        params can be NULL when 
                     22:        method min&max params (see VStateless_class::add_native_method)
                     23:        counts are zero.        
                     24: */
                     25: typedef void (*NativeCodePtr)(Request& request, MethodParams& params);
                     26: 
                     27: 
                     28: /** 
                     29:        class method.
                     30: 
                     31:        methods can have 
                     32:        - named or
                     33:        - numbered parameters
                     34: 
                     35:        methods can be
                     36:        - parser or 
                     37:        - native onces
                     38: 
                     39:        holds
                     40:        - parameter names or number limits
                     41:        - local names
                     42:        - code [parser or native]
                     43: */
                     44: class Method: public PA_Object {
                     45: public:
                     46: 
                     47:        /// allowed method call types
                     48:        enum Call_type {
                     49:                CT_ANY, ///< method can be called either statically or dynamically
                     50:                CT_STATIC, ///< method can be called only statically
                     51:                CT_DYNAMIC ///< method can be called only dynamically
                     52:        };
                     53:        
1.14      misha      54:        enum Result_optimization {
                     55:                RO_UNKNOWN,
                     56:                RO_USE_RESULT, // write to $result detected, will not collect all writes to output scope.
                     57:                RO_USE_WCONTEXT // native code or parser code without $result usage.
                     58:        };
                     59: 
1.13      misha      60:        enum Call_optimization {
                     61:                CO_NONE,
1.26    ! moko       62:                CO_WITHOUT_FRAME, // for some native methods method frame is not required, faster but $self is unavailable
        !            63:                CO_WITHOUT_WCONTEXT // for all native methods wcontext is not required, as no $result, faster
1.13      misha      64:        };
                     65: 
1.2       paf        66:        Call_type call_type;
1.24      moko       67:        /// either numbered params for native-code methods = operators
1.2       paf        68:        int min_numbered_params_count, max_numbered_params_count;
1.24      moko       69:        /// or named params&locals for parser-code methods
1.2       paf        70:        ArrayString* params_names;  ArrayString* locals_names;
1.24      moko       71:        /// the Code
                     72:        ArrayOperation* parser_code; /*OR*/ NativeCodePtr native_code;
                     73: 
                     74:        bool all_vars_local; // in local vars list 'locals' was specified: all vars are local
1.12      misha      75: 
                     76:        VJunction *junction_template;
                     77: 
1.25      moko       78:        const String *name; // method name, never null
                     79:        const String *extra_params; // method has *name as an argument
1.24      moko       80: 
1.14      misha      81: #ifdef OPTIMIZE_RESULT
                     82:        Result_optimization result_optimization;
                     83: #endif
1.2       paf        84: 
1.13      misha      85: #ifdef OPTIMIZE_CALL
                     86:        Call_optimization call_optimization;
                     87: #endif
                     88: 
1.7       misha      89:        Method(
1.13      misha      90:                Call_type acall_type,
1.2       paf        91:                int amin_numbered_params_count, int amax_numbered_params_count,
                     92:                ArrayString* aparams_names, ArrayString* alocals_names,
1.8       misha      93:                ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15      misha      94:                bool aall_vars_local=false
                     95: #ifdef OPTIMIZE_RESULT
                     96:                , Result_optimization aresult_optimization=RO_UNKNOWN
                     97: #endif
                     98: #ifdef OPTIMIZE_CALL
                     99:                , Call_optimization acall_optimization=CO_NONE
                    100: #endif
                    101:                ) :
1.2       paf       102: 
1.13      misha     103:                call_type(acall_type),
1.24      moko      104:                min_numbered_params_count(amin_numbered_params_count), max_numbered_params_count(amax_numbered_params_count),
1.2       paf       105:                params_names(aparams_names), locals_names(alocals_names),
1.8       misha     106:                parser_code(aparser_code), native_code(anative_code),
1.24      moko      107:                all_vars_local(aall_vars_local),
1.14      misha     108: #ifdef OPTIMIZE_RESULT
                    109:                result_optimization(aresult_optimization),
                    110: #endif
1.13      misha     111: #ifdef OPTIMIZE_CALL
1.24      moko      112:                call_optimization(acall_optimization),
1.13      misha     113: #endif
1.25      moko      114:                junction_template(0),
                    115:                name(&String::Empty) {
1.17      moko      116:                        if (params_names){
                    117:                                const char *last_param = params_names->get(params_names->count()-1)->cstr();
1.18      moko      118:                                if (last_param[0] == '*' && last_param[1]){
1.17      moko      119:                                        extra_params = new String(pa_strdup(last_param+1));
                    120:                                        params_names->remove(params_names->count()-1);
                    121:                                        return;
                    122:                                }
                    123:                        }
                    124:                        extra_params = NULL;
1.2       paf       125:        }
                    126: 
                    127:        /// call this before invoking to ensure proper actual numbered params count
1.24      moko      128:        void check_actual_numbered_params(Value& self, MethodParams* actual_numbered_params) const;
1.20      misha     129: 
                    130:        VJunction* get_vjunction(Value& aself) {
                    131:                if(!junction_template)
                    132:                        return junction_template=new VJunction(aself, this);
                    133:                return junction_template->get(aself);
                    134:        }
1.2       paf       135: };
                    136: 
                    137: #endif

E-mail: