Annotation of parser3/src/types/pa_vmethod_frame.C, revision 1.55
1.2 paf 1: /** @file
2: Parser: method frame class.
3:
1.54 moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://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"
1.51 moko 11: #include "pa_vfile.h"
1.2 paf 12:
1.55 ! moko 13: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.54 2026/04/25 13:38:46 moko Exp $" IDENT_PA_VMETHOD_FRAME_H IDENT_PA_VCALLER_WRAPPER_H;
1.2 paf 14:
15: // MethodParams: methods
16:
1.39 moko 17: const char *skip_name[]={
18: "",
19: "continue",
20: "break",
21: "return"
22: };
23:
1.32 moko 24: Value& MethodParams::get_processed(Value& value, const char* msg, int index, Request& r) {
25: if(!value.get_junction())
26: throw Exception(PARSER_RUNTIME, 0, "%s (parameter #%d)", msg, 1+index);
1.39 moko 27: Value& result=r.process(value);
1.55 ! moko 28: if(Request::Skip skip=r.get_skip()){
! 29: if(skip==Request::SKIP_INTERRUPTED)
! 30: r.throw_interrupted();
1.40 moko 31: r.set_skip(Request::SKIP_NOTHING);
1.55 ! moko 32: throw Exception(PARSER_RUNTIME, 0, "%s is not allowed in expression passed to native method (parameter #%d)", skip_name[skip], 1+index);
1.40 moko 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.53 moko 48: throw Exception(PARSER_RUNTIME, 0, "%s must have hash representation (parameter #%d is '%s')", name ? name : "options", 1+index, value.type());
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.53 moko 59: throw Exception(PARSER_RUNTIME, 0, "%s param must have table representation (parameter #%d is '%s')", name ? name : "options", 1+index, value.type());
1.23 moko 60: }
1.21 misha 61:
1.51 moko 62: const String& MethodParams::as_file_name(int index) {
1.52 moko 63: const String* result=get(index).get_string();
64: if(result && !result->is_empty())
65: return *result;
1.53 moko 66: throw Exception(PARSER_RUNTIME, 0, "%s (parameter #%d is '%s')", FILE_NAME_MUST_BE_NE_STRING, 1+index, get(index).type());
1.51 moko 67: }
68:
69: const String& MethodParams::as_file_spec(int index) {
70: if(VFile* vfile=dynamic_cast<VFile *>(&get(index)))
71: return vfile->get_element(name_name)->as_string();
72: return as_string(index, FILE_NAME_MUST_BE_STRING_OR_FILE);
73: }
74:
1.2 paf 75: // VMethodFrame: methods
76:
1.35 moko 77: void VNativeMethodFrame::call(Request &r){
78: check_call_type();
79: method.native_code(r, fnumbered_params);
80: }
81:
82: void VParserMethodFrame::call(Request &r){
83: check_call_type();
1.47 moko 84: r.recursion_checked_execute(*method.parser_code);
1.38 moko 85: r.check_skip_return();
1.35 moko 86: }
87:
1.50 moko 88: VParserMethodFrame::VParserMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : VMethodFrame(amethod, acaller, aself), my_result(NULL) {
1.35 moko 89: if(method.locals_names) { // are there any local var names?
1.50 moko 90: // remember them, those are flags that fname is local == to be looked up in 'my'
1.46 moko 91: for(ArrayString::Iterator i(*method.locals_names); i; ) {
1.50 moko 92: // "result" excluded from local variables during compilation, no need to call set_my_variable
93: my.put(*i.next(), VString::empty());
1.2 paf 94: }
1.35 moko 95: }
1.2 paf 96: }
1.36 moko 97:
98: Value* VParserMethodFrame::get_caller_wrapper(){
99: static VCallerWrapper *caller_wrapper_template=0;
100: if(!caller())
101: return 0;
102: if(caller_wrapper_template && &caller_wrapper_template->caller() == caller())
103: return caller_wrapper_template;
104: return caller_wrapper_template=new VCallerWrapper(*caller());
105: }
E-mail: