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

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

E-mail: