Annotation of parser3/src/types/pa_method.h, revision 1.37
1.2 paf 1: /** @file
2: Parser: Method class decl.
3:
1.34 moko 4: Copyright (c) 2001-2024 Art. Lebedev Studio (http://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.37 ! moko 11: #define IDENT_PA_METHOD_H "$Id: pa_method.h,v 1.36 2024/12/07 15:14:56 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 {
1.37 ! moko 55: RO_UNKNOWN, // during first parser method call, until $result detected on method ends.
1.14 misha 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.14 misha 81: #ifdef OPTIMIZE_RESULT
82: Result_optimization result_optimization;
83: #endif
1.2 paf 84:
1.13 misha 85: #ifdef OPTIMIZE_CALL
86: Call_optimization call_optimization;
87: #endif
88:
1.29 moko 89: mutable VJunction *junction_template;
90:
1.35 moko 91: const String* name; // method name, never null
92: const String* extra_params; // last argument uses the *name notation
93: ArrayString* named_params; // last arguments use the .name notation
1.29 moko 94:
1.7 misha 95: Method(
1.13 misha 96: Call_type acall_type,
1.2 paf 97: int amin_numbered_params_count, int amax_numbered_params_count,
98: ArrayString* aparams_names, ArrayString* alocals_names,
1.8 misha 99: ArrayOperation* aparser_code, NativeCodePtr anative_code,
1.15 misha 100: bool aall_vars_local=false
101: #ifdef OPTIMIZE_RESULT
102: , Result_optimization aresult_optimization=RO_UNKNOWN
103: #endif
104: #ifdef OPTIMIZE_CALL
105: , Call_optimization acall_optimization=CO_NONE
106: #endif
107: ) :
1.2 paf 108:
1.13 misha 109: call_type(acall_type),
1.24 moko 110: min_numbered_params_count(amin_numbered_params_count), max_numbered_params_count(amax_numbered_params_count),
1.27 moko 111: params_names(aparams_names), params_count(0), locals_names(alocals_names),
1.8 misha 112: parser_code(aparser_code), native_code(anative_code),
1.24 moko 113: all_vars_local(aall_vars_local),
1.14 misha 114: #ifdef OPTIMIZE_RESULT
115: result_optimization(aresult_optimization),
116: #endif
1.13 misha 117: #ifdef OPTIMIZE_CALL
1.24 moko 118: call_optimization(acall_optimization),
1.13 misha 119: #endif
1.25 moko 120: junction_template(0),
121: name(&String::Empty) {
1.17 moko 122: if (params_names){
1.31 moko 123: params_count=(int)params_names->count();
1.27 moko 124: const char *last_param = params_names->get(params_count-1)->cstr();
1.18 moko 125: if (last_param[0] == '*' && last_param[1]){
1.17 moko 126: extra_params = new String(pa_strdup(last_param+1));
1.27 moko 127: params_names->remove(--params_count);
1.17 moko 128: return;
1.35 moko 129: } else if (last_param[0] == '.' && last_param[1]){
130: named_params = new ArrayString(params_count);
131: do {
1.36 moko 132: // local variables are not ordered, but direct order for reflection
133: named_params->insert(0, new String(pa_strdup(last_param+1)));
1.35 moko 134: params_names->remove(--params_count);
135: if (!params_count)
136: break;
137: last_param = params_names->get(params_count-1)->cstr();
138: } while (last_param[0] == '.' && last_param[1]);
139: return;
1.17 moko 140: }
141: }
142: extra_params = NULL;
1.35 moko 143: named_params = NULL;
1.2 paf 144: }
145:
146: /// call this before invoking to ensure proper actual numbered params count
1.24 moko 147: void check_actual_numbered_params(Value& self, MethodParams* actual_numbered_params) const;
1.20 misha 148:
1.28 moko 149: VJunction* get_vjunction(Value& aself) const {
1.20 misha 150: if(!junction_template)
151: return junction_template=new VJunction(aself, this);
152: return junction_template->get(aself);
153: }
1.2 paf 154: };
155:
156: #endif
E-mail: