Annotation of parser3/src/types/pa_method.h, revision 1.17
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.17 ! moko 11: static const char * const IDENT_METHOD_H="$Date: 2009-08-08 13:30:21 $";
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.17 ! moko 84: String *extra_params; // method has *name as an argument
1.14 misha 85: #ifdef OPTIMIZE_RESULT
86: Result_optimization result_optimization;
87: #endif
1.2 paf 88:
1.13 misha 89: #ifdef OPTIMIZE_CALL
90: Call_optimization call_optimization;
91: #endif
92:
1.7 misha 93: Method(
1.13 misha 94: Call_type acall_type,
1.2 paf 95: int amin_numbered_params_count, int amax_numbered_params_count,
96: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 97: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15 misha 98: bool aall_vars_local=false
99: #ifdef OPTIMIZE_RESULT
100: , Result_optimization aresult_optimization=RO_UNKNOWN
101: #endif
102: #ifdef OPTIMIZE_CALL
103: , Call_optimization acall_optimization=CO_NONE
104: #endif
105: ) :
1.2 paf 106:
1.13 misha 107: call_type(acall_type),
1.2 paf 108: min_numbered_params_count(amin_numbered_params_count),
109: max_numbered_params_count(amax_numbered_params_count),
110: params_names(aparams_names), locals_names(alocals_names),
1.8 misha 111: parser_code(aparser_code), native_code(anative_code),
1.14 misha 112: #ifdef OPTIMIZE_RESULT
113: result_optimization(aresult_optimization),
114: #endif
1.13 misha 115: #ifdef OPTIMIZE_CALL
116: call_optimization(acall_optimization),
117: #endif
1.14 misha 118: all_vars_local(aall_vars_local){
1.17 ! moko 119: if (params_names){
! 120: const char *last_param = params_names->get(params_names->count()-1)->cstr();
! 121: if (*last_param == '*'){
! 122: extra_params = new String(pa_strdup(last_param+1));
! 123: params_names->remove(params_names->count()-1);
! 124: return;
! 125: }
! 126: }
! 127: extra_params = NULL;
1.2 paf 128: }
129:
130: /// call this before invoking to ensure proper actual numbered params count
131: void check_actual_numbered_params(
1.13 misha 132: Value& self, MethodParams* actual_numbered_params) const;
1.2 paf 133: };
134:
135: /// Auto-object used for temporarily substituting/removing elements
136: class Temp_value_element {
137: Value& fwhere;
138: const String& fname;
139: Value* saved;
140: public:
141: Temp_value_element(Value& awhere, const String& aname, Value* awhat) :
142: fwhere(awhere),
143: fname(aname),
1.16 misha 144: saved(awhere.get_element(aname)) {
145: fwhere.put_element(aname, awhat, false);
1.2 paf 146: }
147: ~Temp_value_element() {
1.16 misha 148: fwhere.put_element(fname, saved, false);
1.2 paf 149: }
150: };
151:
152:
153: #endif
E-mail: