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

1.2       paf         1: /** @file
                      2:        Parser: Method class decl.
                      3: 
1.13      misha       4:        Copyright (c) 2001-2009 ArtLebedev Group (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.15    ! misha      11: static const char * const IDENT_METHOD_H="$Date: 2009-05-13 07:35:27 $";
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"
                     17: 
                     18: /**
                     19:        native code method
                     20:        params can be NULL when 
                     21:        method min&max params (see VStateless_class::add_native_method)
                     22:        counts are zero.        
                     23: */
                     24: typedef void (*NativeCodePtr)(Request& request, MethodParams& params);
                     25: 
                     26: 
                     27: /** 
                     28:        class method.
                     29: 
                     30:        methods can have 
                     31:        - named or
                     32:        - numbered parameters
                     33: 
                     34:        methods can be
                     35:        - parser or 
                     36:        - native onces
                     37: 
                     38:        holds
                     39:        - parameter names or number limits
                     40:        - local names
                     41:        - code [parser or native]
                     42: */
                     43: class Method: public PA_Object {
                     44: public:
                     45: 
                     46:        /// allowed method call types
                     47:        enum Call_type {
                     48:                CT_ANY, ///< method can be called either statically or dynamically
                     49:                CT_STATIC, ///< method can be called only statically
                     50:                CT_DYNAMIC ///< method can be called only dynamically
                     51:        };
                     52:        
1.14      misha      53:        enum Result_optimization {
                     54:                RO_UNKNOWN,
                     55:                RO_USE_RESULT, // write to $result detected, will not collect all writes to output scope.
                     56:                RO_USE_WCONTEXT // native code or parser code without $result usage.
                     57:        };
                     58: 
1.13      misha      59:        enum Call_optimization {
                     60:                CO_NONE,
                     61:                CO_WITHOUT_FRAME, // for some native methods method frame is not required, faster
                     62:                CO_WITHOUT_WCONTEXT // for some native methods wcontext is not required, faster
                     63:        };
                     64: 
1.2       paf        65:        ///
                     66:        Call_type call_type;
                     67:        //@{
                     68:        /// @name either numbered params // for native-code methods = operators
                     69:        int min_numbered_params_count, max_numbered_params_count;
                     70:        //@}
                     71:        //@{
                     72:        /// @name or named params&locals // for parser-code methods
                     73:        ArrayString* params_names;  ArrayString* locals_names;
                     74:        //@}
                     75:        //@{
                     76:        /// @name the Code
                     77:        ArrayOperation* parser_code;/*OR*/NativeCodePtr native_code;
                     78:        //@}
1.12      misha      79: 
                     80:        VJunction *junction_template;
                     81: 
1.9       misha      82:        bool all_vars_local; // in local vars list 'locals' was specified: all vars are local
1.11      misha      83:        bool allways_use_result; // write to $result detected. will not collect all writes to output scope.
1.14      misha      84: #ifdef OPTIMIZE_RESULT
                     85:        Result_optimization result_optimization;
                     86: #endif
1.2       paf        87: 
1.13      misha      88: #ifdef OPTIMIZE_CALL
                     89:        Call_optimization call_optimization;
                     90: #endif
                     91: 
1.7       misha      92:        Method(
1.13      misha      93:                Call_type acall_type,
1.2       paf        94:                int amin_numbered_params_count, int amax_numbered_params_count,
                     95:                ArrayString* aparams_names, ArrayString* alocals_names,
1.8       misha      96:                ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15    ! misha      97:                bool aall_vars_local=false
        !            98: #ifdef OPTIMIZE_RESULT
        !            99:                , Result_optimization aresult_optimization=RO_UNKNOWN
        !           100: #endif
        !           101: #ifdef OPTIMIZE_CALL
        !           102:                , Call_optimization acall_optimization=CO_NONE
        !           103: #endif
        !           104:                ) :
1.2       paf       105: 
1.13      misha     106:                call_type(acall_type),
1.2       paf       107:                min_numbered_params_count(amin_numbered_params_count),
                    108:                max_numbered_params_count(amax_numbered_params_count),
                    109:                params_names(aparams_names), locals_names(alocals_names),
1.8       misha     110:                parser_code(aparser_code), native_code(anative_code),
1.14      misha     111: #ifdef OPTIMIZE_RESULT
                    112:                result_optimization(aresult_optimization),
                    113: #endif
1.13      misha     114: #ifdef OPTIMIZE_CALL
                    115:                call_optimization(acall_optimization),  
                    116: #endif
1.14      misha     117:                all_vars_local(aall_vars_local){
1.2       paf       118:        }
                    119: 
                    120:        /// call this before invoking to ensure proper actual numbered params count
                    121:        void check_actual_numbered_params(
1.13      misha     122:                Value& self, MethodParams* actual_numbered_params) const;
1.2       paf       123: };
                    124: 
                    125: ///    Auto-object used for temporarily substituting/removing elements
                    126: class Temp_value_element {
                    127:        Value& fwhere;
                    128:        const String& fname;
                    129:        Value* saved;
                    130: public:
                    131:        Temp_value_element(Value& awhere, const String& aname, Value* awhat) : 
                    132:                fwhere(awhere),
                    133:                fname(aname),
                    134:                saved(awhere.get_element(aname, awhere, false)) {
1.5       paf       135:                fwhere.put_element(fwhere, aname, awhat, false);
1.2       paf       136:        }
                    137:        ~Temp_value_element() { 
1.5       paf       138:                fwhere.put_element(fwhere, fname, saved, false);
1.2       paf       139:        }
                    140: };
                    141: 
                    142: 
                    143: #endif

E-mail: