Annotation of parser3/src/types/pa_method.h, revision 1.24
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.24 ! moko 11: #define IDENT_PA_METHOD_H "$Id: pa_method.h,v 1.23 2015/10/26 01:22:00 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,
62: CO_WITHOUT_FRAME, // for some native methods method frame is not required, faster
63: CO_WITHOUT_WCONTEXT // for some native methods wcontext is not required, faster
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.17 moko 78: String *extra_params; // method has *name as an argument
1.24 ! moko 79:
1.14 misha 80: #ifdef OPTIMIZE_RESULT
81: Result_optimization result_optimization;
82: #endif
1.2 paf 83:
1.13 misha 84: #ifdef OPTIMIZE_CALL
85: Call_optimization call_optimization;
86: #endif
87:
1.7 misha 88: Method(
1.13 misha 89: Call_type acall_type,
1.2 paf 90: int amin_numbered_params_count, int amax_numbered_params_count,
91: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 92: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15 misha 93: bool aall_vars_local=false
94: #ifdef OPTIMIZE_RESULT
95: , Result_optimization aresult_optimization=RO_UNKNOWN
96: #endif
97: #ifdef OPTIMIZE_CALL
98: , Call_optimization acall_optimization=CO_NONE
99: #endif
100: ) :
1.2 paf 101:
1.13 misha 102: call_type(acall_type),
1.24 ! moko 103: min_numbered_params_count(amin_numbered_params_count), max_numbered_params_count(amax_numbered_params_count),
1.2 paf 104: params_names(aparams_names), locals_names(alocals_names),
1.8 misha 105: parser_code(aparser_code), native_code(anative_code),
1.24 ! moko 106: all_vars_local(aall_vars_local),
1.14 misha 107: #ifdef OPTIMIZE_RESULT
108: result_optimization(aresult_optimization),
109: #endif
1.13 misha 110: #ifdef OPTIMIZE_CALL
1.24 ! moko 111: call_optimization(acall_optimization),
1.13 misha 112: #endif
1.24 ! moko 113: junction_template(0) {
1.17 moko 114: if (params_names){
115: const char *last_param = params_names->get(params_names->count()-1)->cstr();
1.18 moko 116: if (last_param[0] == '*' && last_param[1]){
1.17 moko 117: extra_params = new String(pa_strdup(last_param+1));
118: params_names->remove(params_names->count()-1);
119: return;
120: }
121: }
122: extra_params = NULL;
1.2 paf 123: }
124:
125: /// call this before invoking to ensure proper actual numbered params count
1.24 ! moko 126: void check_actual_numbered_params(Value& self, MethodParams* actual_numbered_params) const;
1.20 misha 127:
128: VJunction* get_vjunction(Value& aself) {
129: if(!junction_template)
130: return junction_template=new VJunction(aself, this);
131: return junction_template->get(aself);
132: }
1.2 paf 133: };
134:
135: #endif
E-mail: