Annotation of parser3/src/types/pa_method.h, revision 1.21
1.2 paf 1: /** @file
2: Parser: Method class decl.
3:
1.19 moko 4: Copyright (c) 2001-2012 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.21 ! moko 11: #define IDENT_PA_METHOD_H "$Id: pa_method.h,v 1.20 2012/06/05 10:28:43 misha 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: ///
67: Call_type call_type;
68: //@{
69: /// @name either numbered params // for native-code methods = operators
70: int min_numbered_params_count, max_numbered_params_count;
71: //@}
72: //@{
73: /// @name or named params&locals // for parser-code methods
74: ArrayString* params_names; ArrayString* locals_names;
75: //@}
76: //@{
77: /// @name the Code
78: ArrayOperation* parser_code;/*OR*/NativeCodePtr native_code;
79: //@}
1.12 misha 80:
81: VJunction *junction_template;
82:
1.9 misha 83: bool all_vars_local; // in local vars list 'locals' was specified: all vars are local
1.11 misha 84: bool allways_use_result; // write to $result detected. will not collect all writes to output scope.
1.17 moko 85: String *extra_params; // method has *name as an argument
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.2 paf 109: min_numbered_params_count(amin_numbered_params_count),
110: max_numbered_params_count(amax_numbered_params_count),
111: params_names(aparams_names), locals_names(alocals_names),
1.8 misha 112: parser_code(aparser_code), native_code(anative_code),
1.14 misha 113: #ifdef OPTIMIZE_RESULT
114: result_optimization(aresult_optimization),
115: #endif
1.13 misha 116: #ifdef OPTIMIZE_CALL
117: call_optimization(acall_optimization),
118: #endif
1.14 misha 119: all_vars_local(aall_vars_local){
1.17 moko 120: if (params_names){
121: const char *last_param = params_names->get(params_names->count()-1)->cstr();
1.18 moko 122: if (last_param[0] == '*' && last_param[1]){
1.17 moko 123: extra_params = new String(pa_strdup(last_param+1));
124: params_names->remove(params_names->count()-1);
125: return;
126: }
127: }
128: extra_params = NULL;
1.2 paf 129: }
130:
131: /// call this before invoking to ensure proper actual numbered params count
132: void check_actual_numbered_params(
1.13 misha 133: Value& self, MethodParams* actual_numbered_params) const;
1.20 misha 134:
135: VJunction* get_vjunction(Value& aself) {
136: if(!junction_template)
137: return junction_template=new VJunction(aself, this);
138: return junction_template->get(aself);
139: }
1.2 paf 140: };
141:
142: /// Auto-object used for temporarily substituting/removing elements
143: class Temp_value_element {
144: Value& fwhere;
145: const String& fname;
146: Value* saved;
147: public:
148: Temp_value_element(Value& awhere, const String& aname, Value* awhat) :
149: fwhere(awhere),
150: fname(aname),
1.16 misha 151: saved(awhere.get_element(aname)) {
1.21 ! moko 152: fwhere.put_element(aname, awhat);
1.2 paf 153: }
154: ~Temp_value_element() {
1.21 ! moko 155: fwhere.put_element(fname, saved);
1.2 paf 156: }
157: };
158:
159:
160: #endif
E-mail: