Annotation of parser3/src/types/pa_vmethod_frame.C, revision 1.50

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.50    ! moko       12: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.49 2024/12/09 20:25:17 moko Exp $" IDENT_PA_VMETHOD_FRAME_H IDENT_PA_VCALLER_WRAPPER_H;
1.2       paf        13: 
                     14: // MethodParams: methods
                     15: 
1.39      moko       16: const char *skip_name[]={
                     17:        "",
                     18:        "continue",
                     19:        "break",
                     20:        "return"
                     21: };
                     22: 
1.32      moko       23: Value& MethodParams::get_processed(Value& value, const char* msg, int index, Request& r) {
                     24:        if(!value.get_junction())
                     25:                throw Exception(PARSER_RUNTIME, 0, "%s (parameter #%d)", msg, 1+index);
1.39      moko       26:        Value& result=r.process(value);
1.40      moko       27:        if(r.get_skip()){
                     28:                const char *skip=skip_name[r.get_skip()];
                     29:                r.set_skip(Request::SKIP_NOTHING);
                     30:                throw Exception(PARSER_RUNTIME, 0, "%s is not allowed in expression passed to native method (parameter #%d)", skip, 1+index);
                     31:        }
1.39      moko       32:        return result;
1.2       paf        33: }
                     34: 
1.37      moko       35: // Should be synced with Value::as_hash
1.21      misha      36: HashStringValue* MethodParams::as_hash(int index, const char* name) {
1.34      moko       37:        Value& value=get(index);
1.33      moko       38:        if(value.get_junction())
                     39:                throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     40:        if(!value.is_defined()) // empty hash is not defined, but we don't need it anyway
                     41:                return 0;
                     42:        if(HashStringValue* result=value.get_hash())
                     43:                return result;
                     44:        if(value.is_string() && value.get_string()->trim().is_empty())
                     45:                return 0;
1.32      moko       46:        throw Exception(PARSER_RUNTIME, 0, "%s must have hash representation (parameter #%d)", name ? name : "options", 1+index);
1.21      misha      47: }
                     48: 
                     49: Table* MethodParams::as_table(int index, const char* name) {
1.34      moko       50:        Value& value=get(index);
1.33      moko       51:        if(value.get_junction())
                     52:                throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     53:        if(Table* result=value.get_table())
                     54:                return result;
1.43      moko       55:        if(value.is_string() && value.get_string()->trim().is_empty())
                     56:                return 0;
1.30      moko       57:        throw Exception(PARSER_RUNTIME, 0, "%s param must have table representation (parameter #%d)", name ? name : "options", 1+index);
1.23      moko       58: }
1.21      misha      59: 
1.2       paf        60: // VMethodFrame: methods
                     61: 
1.35      moko       62: void VNativeMethodFrame::call(Request &r){
                     63:        check_call_type();
                     64:        method.native_code(r, fnumbered_params);
                     65: }
                     66: 
                     67: void VParserMethodFrame::call(Request &r){
                     68:        check_call_type();
1.47      moko       69:        r.recursion_checked_execute(*method.parser_code);
1.38      moko       70:        r.check_skip_return();
1.35      moko       71: }
                     72: 
1.50    ! moko       73: VParserMethodFrame::VParserMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : VMethodFrame(amethod, acaller, aself), my_result(NULL) {
1.35      moko       74:        if(method.locals_names) { // are there any local var names?
1.50    ! moko       75:                // remember them, those are flags that fname is local == to be looked up in 'my'
1.46      moko       76:                for(ArrayString::Iterator i(*method.locals_names); i; ) {
1.50    ! moko       77:                        // "result" excluded from local variables during compilation, no need to call set_my_variable
        !            78:                        my.put(*i.next(), VString::empty());
1.2       paf        79:                }
1.35      moko       80:        }
1.2       paf        81: }
1.36      moko       82: 
                     83: Value* VParserMethodFrame::get_caller_wrapper(){
                     84:        static VCallerWrapper *caller_wrapper_template=0;
                     85:        if(!caller())
                     86:                return 0;
                     87:        if(caller_wrapper_template && &caller_wrapper_template->caller() == caller())
                     88:                return caller_wrapper_template;
                     89:        return caller_wrapper_template=new VCallerWrapper(*caller());
                     90: }

E-mail: