Annotation of parser3/src/types/pa_method.h, revision 1.28
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.28 ! moko 11: #define IDENT_PA_METHOD_H "$Id: pa_method.h,v 1.27 2016/11/03 16:17:38 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.27 moko 67:
1.24 moko 68: /// either numbered params for native-code methods = operators
1.2 paf 69: int min_numbered_params_count, max_numbered_params_count;
1.27 moko 70:
1.24 moko 71: /// or named params&locals for parser-code methods
1.27 moko 72: ArrayString* params_names;
73: int params_count;
74: ArrayString* locals_names;
75:
1.24 moko 76: /// the Code
77: ArrayOperation* parser_code; /*OR*/ NativeCodePtr native_code;
78:
79: bool all_vars_local; // in local vars list 'locals' was specified: all vars are local
1.12 misha 80:
1.28 ! moko 81: mutable VJunction *junction_template;
1.12 misha 82:
1.25 moko 83: const String *name; // method name, never null
84: const String *extra_params; // method has *name as an argument
1.24 moko 85:
1.14 misha 86: #ifdef OPTIMIZE_RESULT
87: Result_optimization result_optimization;
88: #endif
1.2 paf 89:
1.13 misha 90: #ifdef OPTIMIZE_CALL
91: Call_optimization call_optimization;
92: #endif
93:
1.7 misha 94: Method(
1.13 misha 95: Call_type acall_type,
1.2 paf 96: int amin_numbered_params_count, int amax_numbered_params_count,
97: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 98: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15 misha 99: bool aall_vars_local=false
100: #ifdef OPTIMIZE_RESULT
101: , Result_optimization aresult_optimization=RO_UNKNOWN
102: #endif
103: #ifdef OPTIMIZE_CALL
104: , Call_optimization acall_optimization=CO_NONE
105: #endif
106: ) :
1.2 paf 107:
1.13 misha 108: call_type(acall_type),
1.24 moko 109: min_numbered_params_count(amin_numbered_params_count), max_numbered_params_count(amax_numbered_params_count),
1.27 moko 110: params_names(aparams_names), params_count(0), locals_names(alocals_names),
1.8 misha 111: parser_code(aparser_code), native_code(anative_code),
1.24 moko 112: all_vars_local(aall_vars_local),
1.14 misha 113: #ifdef OPTIMIZE_RESULT
114: result_optimization(aresult_optimization),
115: #endif
1.13 misha 116: #ifdef OPTIMIZE_CALL
1.24 moko 117: call_optimization(acall_optimization),
1.13 misha 118: #endif
1.25 moko 119: junction_template(0),
120: name(&String::Empty) {
1.17 moko 121: if (params_names){
1.27 moko 122: params_count=params_names->count();
123: const char *last_param = params_names->get(params_count-1)->cstr();
1.18 moko 124: if (last_param[0] == '*' && last_param[1]){
1.17 moko 125: extra_params = new String(pa_strdup(last_param+1));
1.27 moko 126: params_names->remove(--params_count);
1.17 moko 127: return;
128: }
129: }
130: extra_params = NULL;
1.2 paf 131: }
132:
133: /// call this before invoking to ensure proper actual numbered params count
1.24 moko 134: void check_actual_numbered_params(Value& self, MethodParams* actual_numbered_params) const;
1.20 misha 135:
1.28 ! moko 136: VJunction* get_vjunction(Value& aself) const {
1.20 misha 137: if(!junction_template)
138: return junction_template=new VJunction(aself, this);
139: return junction_template->get(aself);
140: }
1.2 paf 141: };
142:
143: #endif
E-mail: