Annotation of parser3/src/types/pa_vmethod_frame.C, revision 1.49
1.2 paf 1: /** @file
2: Parser: method frame class.
3:
1.48 moko 4: Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.44 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>\
1.2 paf 6: */
7:
8: #include "pa_vmethod_frame.h"
1.36 moko 9: #include "pa_vcaller_wrapper.h"
1.2 paf 10: #include "pa_request.h"
11:
1.49 ! moko 12: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.48 2024/11/04 03:53:26 moko Exp $" IDENT_PA_VMETHOD_FRAME_H IDENT_PA_VCALLER_WRAPPER_H;
1.22 misha 13:
1.36 moko 14: static VVoid void_result; // unique value to be sure the result is changed
1.2 paf 15:
16: // MethodParams: methods
17:
1.39 moko 18: const char *skip_name[]={
19: "",
20: "continue",
21: "break",
22: "return"
23: };
24:
1.32 moko 25: Value& MethodParams::get_processed(Value& value, const char* msg, int index, Request& r) {
26: if(!value.get_junction())
27: throw Exception(PARSER_RUNTIME, 0, "%s (parameter #%d)", msg, 1+index);
1.39 moko 28: Value& result=r.process(value);
1.40 moko 29: if(r.get_skip()){
30: const char *skip=skip_name[r.get_skip()];
31: r.set_skip(Request::SKIP_NOTHING);
32: throw Exception(PARSER_RUNTIME, 0, "%s is not allowed in expression passed to native method (parameter #%d)", skip, 1+index);
33: }
1.39 moko 34: return result;
1.2 paf 35: }
36:
1.37 moko 37: // Should be synced with Value::as_hash
1.21 misha 38: HashStringValue* MethodParams::as_hash(int index, const char* name) {
1.34 moko 39: Value& value=get(index);
1.33 moko 40: if(value.get_junction())
41: throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
42: if(!value.is_defined()) // empty hash is not defined, but we don't need it anyway
43: return 0;
44: if(HashStringValue* result=value.get_hash())
45: return result;
46: if(value.is_string() && value.get_string()->trim().is_empty())
47: return 0;
1.32 moko 48: throw Exception(PARSER_RUNTIME, 0, "%s must have hash representation (parameter #%d)", name ? name : "options", 1+index);
1.21 misha 49: }
50:
51: Table* MethodParams::as_table(int index, const char* name) {
1.34 moko 52: Value& value=get(index);
1.33 moko 53: if(value.get_junction())
54: throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
55: if(Table* result=value.get_table())
56: return result;
1.43 moko 57: if(value.is_string() && value.get_string()->trim().is_empty())
58: return 0;
1.30 moko 59: throw Exception(PARSER_RUNTIME, 0, "%s param must have table representation (parameter #%d)", name ? name : "options", 1+index);
1.23 moko 60: }
1.21 misha 61:
1.2 paf 62: // VMethodFrame: methods
63:
1.35 moko 64: void VNativeMethodFrame::call(Request &r){
65: check_call_type();
66: method.native_code(r, fnumbered_params);
67: }
68:
69: void VParserMethodFrame::call(Request &r){
70: check_call_type();
1.47 moko 71: r.recursion_checked_execute(*method.parser_code);
1.38 moko 72: r.check_skip_return();
1.35 moko 73: }
74:
75: VParserMethodFrame::VParserMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : VMethodFrame(amethod, acaller, aself) {
76: if(method.locals_names) { // are there any local var names?
77: // remember them
78: // those are flags that fname is local == to be looked up in 'my'
1.46 moko 79: for(ArrayString::Iterator i(*method.locals_names); i; ) {
1.35 moko 80: // speedup: not checking for clash with "result" fname
81: const String& fname=*i.next();
1.49 ! moko 82: set_my_variable(fname, VString::empty());
1.2 paf 83: }
1.35 moko 84: }
1.14 misha 85: #ifdef OPTIMIZE_RESULT
1.35 moko 86: if(method.result_optimization!=Method::RO_USE_WCONTEXT)
1.14 misha 87: #endif
1.49 ! moko 88: set_my_variable(Symbols::RESULT_SYMBOL, &void_result);
1.2 paf 89: }
90:
1.35 moko 91: Value* VParserMethodFrame::get_result_variable() {
92: Value* result=my.get(Symbols::RESULT_SYMBOL);
1.30 moko 93: return result!=&void_result ? result : 0;
1.2 paf 94: }
1.36 moko 95:
96: Value* VParserMethodFrame::get_caller_wrapper(){
97: static VCallerWrapper *caller_wrapper_template=0;
98: if(!caller())
99: return 0;
100: if(caller_wrapper_template && &caller_wrapper_template->caller() == caller())
101: return caller_wrapper_template;
102: return caller_wrapper_template=new VCallerWrapper(*caller());
103: }
E-mail: