Annotation of parser3/src/types/pa_method.h, revision 1.14
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.14 ! misha 11: static const char * const IDENT_METHOD_H="$Date: 2009-05-04 09:25:32 $";
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.14 ! misha 84: #ifdef OPTIMIZE_RESULT
! 85: Result_optimization result_optimization;
! 86: #endif
1.2 paf 87:
1.13 misha 88: #ifdef OPTIMIZE_CALL
89: Call_optimization call_optimization;
90: #endif
91:
1.7 misha 92: Method(
1.13 misha 93: Call_type acall_type,
1.2 paf 94: int amin_numbered_params_count, int amax_numbered_params_count,
95: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 96: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.14 ! misha 97: bool aall_vars_local=false,
! 98: Result_optimization aresult_optimization=RO_UNKNOWN,
! 99: Call_optimization acall_optimization=CO_NONE) :
1.2 paf 100:
1.13 misha 101: call_type(acall_type),
1.2 paf 102: min_numbered_params_count(amin_numbered_params_count),
103: max_numbered_params_count(amax_numbered_params_count),
104: params_names(aparams_names), locals_names(alocals_names),
1.8 misha 105: parser_code(aparser_code), native_code(anative_code),
1.14 ! misha 106: #ifdef OPTIMIZE_RESULT
! 107: result_optimization(aresult_optimization),
! 108: #endif
1.13 misha 109: #ifdef OPTIMIZE_CALL
110: call_optimization(acall_optimization),
111: #endif
1.14 ! misha 112: all_vars_local(aall_vars_local){
1.2 paf 113: }
114:
115: /// call this before invoking to ensure proper actual numbered params count
116: void check_actual_numbered_params(
1.13 misha 117: Value& self, MethodParams* actual_numbered_params) const;
1.2 paf 118: };
119:
120: /// Auto-object used for temporarily substituting/removing elements
121: class Temp_value_element {
122: Value& fwhere;
123: const String& fname;
124: Value* saved;
125: public:
126: Temp_value_element(Value& awhere, const String& aname, Value* awhat) :
127: fwhere(awhere),
128: fname(aname),
129: saved(awhere.get_element(aname, awhere, false)) {
1.5 paf 130: fwhere.put_element(fwhere, aname, awhat, false);
1.2 paf 131: }
132: ~Temp_value_element() {
1.5 paf 133: fwhere.put_element(fwhere, fname, saved, false);
1.2 paf 134: }
135: };
136:
137:
138: #endif
E-mail: