Annotation of parser3/src/types/pa_method.h, revision 1.39
1.2 paf 1: /** @file
2: Parser: Method class decl.
3:
1.39 ! moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.33 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.2 paf 6: */
7:
8: #ifndef PA_METHOD_H
9: #define PA_METHOD_H
10:
1.39 ! moko 11: #define IDENT_PA_METHOD_H "$Id: pa_method.h,v 1.38 2026/04/24 20:14:33 moko Exp $"
1.2 paf 12:
1.13 misha 13: #define OPTIMIZE_CALL
1.14 misha 14: #define OPTIMIZE_RESULT
1.38 moko 15: #define OPTIMIZE_MY_HASH
1.2 paf 16:
17: #include "pa_operation.h"
1.20 misha 18: #include "pa_vjunction.h"
1.2 paf 19:
20: /**
21: native code method
1.38 moko 22: params can be NULL when
1.2 paf 23: method min&max params (see VStateless_class::add_native_method)
1.38 moko 24: counts are zero.
1.2 paf 25: */
26: typedef void (*NativeCodePtr)(Request& request, MethodParams& params);
27:
28:
29: /**
30: class method.
31:
32: methods can have
33: - named or
34: - numbered parameters
35:
36: methods can be
37: - parser or
38: - native onces
39:
40: holds
41: - parameter names or number limits
42: - local names
43: - code [parser or native]
44: */
45: class Method: public PA_Object {
46: public:
47:
48: /// allowed method call types
49: enum Call_type {
50: CT_ANY, ///< method can be called either statically or dynamically
51: CT_STATIC, ///< method can be called only statically
52: CT_DYNAMIC ///< method can be called only dynamically
53: };
54:
1.14 misha 55: enum Result_optimization {
1.37 moko 56: RO_UNKNOWN, // during first parser method call, until $result detected on method ends.
1.14 misha 57: RO_USE_RESULT, // write to $result detected, will not collect all writes to output scope.
58: RO_USE_WCONTEXT // native code or parser code without $result usage.
59: };
60:
1.13 misha 61: enum Call_optimization {
62: CO_NONE,
1.26 moko 63: CO_WITHOUT_FRAME, // for some native methods method frame is not required, faster but $self is unavailable
64: CO_WITHOUT_WCONTEXT // for all native methods wcontext is not required, as no $result, faster
1.13 misha 65: };
66:
1.2 paf 67: Call_type call_type;
1.27 moko 68:
1.24 moko 69: /// either numbered params for native-code methods = operators
1.2 paf 70: int min_numbered_params_count, max_numbered_params_count;
1.27 moko 71:
1.24 moko 72: /// or named params&locals for parser-code methods
1.27 moko 73: ArrayString* params_names;
74: int params_count;
75: ArrayString* locals_names;
76:
1.24 moko 77: /// the Code
78: ArrayOperation* parser_code; /*OR*/ NativeCodePtr native_code;
79:
80: bool all_vars_local; // in local vars list 'locals' was specified: all vars are local
1.12 misha 81:
1.14 misha 82: #ifdef OPTIMIZE_RESULT
83: Result_optimization result_optimization;
84: #endif
1.2 paf 85:
1.13 misha 86: #ifdef OPTIMIZE_CALL
87: Call_optimization call_optimization;
88: #endif
89:
1.29 moko 90: mutable VJunction *junction_template;
91:
1.35 moko 92: const String* name; // method name, never null
93: const String* extra_params; // last argument uses the *name notation
94: ArrayString* named_params; // last arguments use the .name notation
1.29 moko 95:
1.7 misha 96: Method(
1.13 misha 97: Call_type acall_type,
1.2 paf 98: int amin_numbered_params_count, int amax_numbered_params_count,
99: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 100: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15 misha 101: bool aall_vars_local=false
102: #ifdef OPTIMIZE_RESULT
103: , Result_optimization aresult_optimization=RO_UNKNOWN
104: #endif
105: #ifdef OPTIMIZE_CALL
106: , Call_optimization acall_optimization=CO_NONE
107: #endif
108: ) :
1.2 paf 109:
1.13 misha 110: call_type(acall_type),
1.24 moko 111: min_numbered_params_count(amin_numbered_params_count), max_numbered_params_count(amax_numbered_params_count),
1.27 moko 112: params_names(aparams_names), params_count(0), locals_names(alocals_names),
1.8 misha 113: parser_code(aparser_code), native_code(anative_code),
1.24 moko 114: all_vars_local(aall_vars_local),
1.14 misha 115: #ifdef OPTIMIZE_RESULT
116: result_optimization(aresult_optimization),
117: #endif
1.13 misha 118: #ifdef OPTIMIZE_CALL
1.24 moko 119: call_optimization(acall_optimization),
1.13 misha 120: #endif
1.25 moko 121: junction_template(0),
122: name(&String::Empty) {
1.17 moko 123: if (params_names){
1.31 moko 124: params_count=(int)params_names->count();
1.27 moko 125: const char *last_param = params_names->get(params_count-1)->cstr();
1.18 moko 126: if (last_param[0] == '*' && last_param[1]){
1.17 moko 127: extra_params = new String(pa_strdup(last_param+1));
1.27 moko 128: params_names->remove(--params_count);
1.17 moko 129: return;
1.35 moko 130: } else if (last_param[0] == '.' && last_param[1]){
131: named_params = new ArrayString(params_count);
132: do {
1.36 moko 133: // local variables are not ordered, but direct order for reflection
134: named_params->insert(0, new String(pa_strdup(last_param+1)));
1.35 moko 135: params_names->remove(--params_count);
136: if (!params_count)
137: break;
138: last_param = params_names->get(params_count-1)->cstr();
139: } while (last_param[0] == '.' && last_param[1]);
140: return;
1.17 moko 141: }
142: }
143: extra_params = NULL;
1.35 moko 144: named_params = NULL;
1.2 paf 145: }
146:
147: /// call this before invoking to ensure proper actual numbered params count
1.24 moko 148: void check_actual_numbered_params(Value& self, MethodParams* actual_numbered_params) const;
1.20 misha 149:
1.28 moko 150: VJunction* get_vjunction(Value& aself) const {
1.20 misha 151: if(!junction_template)
152: return junction_template=new VJunction(aself, this);
153: return junction_template->get(aself);
154: }
1.2 paf 155: };
156:
157: #endif
E-mail: