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

1.2       paf         1: /**    @file
                      2:        Parser: method frame class.
                      3: 
1.24      moko        4:        Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)
1.2       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)\
                      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.39    ! moko       12: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.38 2017/01/13 13:50:29 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);
        !            29:        if(r.get_skip())
        !            30:                throw Exception(PARSER_RUNTIME, 0, "%s is not allowed in expression passed to native method (parameter #%d)", skip_name[r.get_skip()], 1+index);
        !            31:        return result;
1.2       paf        32: }
                     33: 
1.37      moko       34: // Should be synced with Value::as_hash
1.21      misha      35: HashStringValue* MethodParams::as_hash(int index, const char* name) {
1.34      moko       36:        Value& value=get(index);
1.33      moko       37:        if(value.get_junction())
                     38:                throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     39:        if(!value.is_defined()) // empty hash is not defined, but we don't need it anyway
                     40:                return 0;
                     41:        if(HashStringValue* result=value.get_hash())
                     42:                return result;
                     43:        if(value.is_string() && value.get_string()->trim().is_empty())
                     44:                return 0;
1.32      moko       45:        throw Exception(PARSER_RUNTIME, 0, "%s must have hash representation (parameter #%d)", name ? name : "options", 1+index);
1.21      misha      46: }
                     47: 
                     48: Table* MethodParams::as_table(int index, const char* name) {
1.34      moko       49:        Value& value=get(index);
1.33      moko       50:        if(value.get_junction())
                     51:                throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     52:        if(Table* result=value.get_table())
                     53:                return result;
1.30      moko       54:        throw Exception(PARSER_RUNTIME, 0, "%s param must have table representation (parameter #%d)", name ? name : "options", 1+index);
1.23      moko       55: }
1.21      misha      56: 
1.2       paf        57: // VMethodFrame: methods
                     58: 
1.35      moko       59: void VNativeMethodFrame::call(Request &r){
                     60:        check_call_type();
                     61:        method.native_code(r, fnumbered_params);
                     62: }
                     63: 
                     64: void VParserMethodFrame::call(Request &r){
                     65:        check_call_type();
                     66:        r.recoursion_checked_execute(*method.parser_code);
1.38      moko       67:        r.check_skip_return();
1.35      moko       68: }
                     69: 
                     70: VParserMethodFrame::VParserMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : VMethodFrame(amethod, acaller, aself) {
                     71:        if(method.locals_names) { // are there any local var names?
                     72:                // remember them
                     73:                // those are flags that fname is local == to be looked up in 'my'
                     74:                for(Array_iterator<const String*> i(*method.locals_names); i.has_next(); ) {
                     75:                        // speedup: not checking for clash with "result" fname
                     76:                        const String& fname=*i.next();
                     77:                        set_my_variable(fname, *VString::empty());
1.2       paf        78:                }
1.35      moko       79:        }
1.14      misha      80: #ifdef OPTIMIZE_RESULT
1.35      moko       81:        if(method.result_optimization!=Method::RO_USE_WCONTEXT)
1.14      misha      82: #endif
1.35      moko       83:                set_my_variable(Symbols::RESULT_SYMBOL, void_result);
1.2       paf        84: }
                     85: 
1.35      moko       86: Value* VParserMethodFrame::get_result_variable() {
                     87:        Value* result=my.get(Symbols::RESULT_SYMBOL);
1.30      moko       88:        return result!=&void_result ? result : 0;
1.2       paf        89: }
1.36      moko       90: 
                     91: Value* VParserMethodFrame::get_caller_wrapper(){
                     92:        static VCallerWrapper *caller_wrapper_template=0;
                     93:        if(!caller())
                     94:                return 0;
                     95:        if(caller_wrapper_template && &caller_wrapper_template->caller() == caller())
                     96:                return caller_wrapper_template;
                     97:        return caller_wrapper_template=new VCallerWrapper(*caller());
                     98: }

E-mail: