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

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.40    ! moko       12: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.39 2017/01/17 17:26:54 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.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();
                     69:        r.recoursion_checked_execute(*method.parser_code);
1.38      moko       70:        r.check_skip_return();
1.35      moko       71: }
                     72: 
                     73: VParserMethodFrame::VParserMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : VMethodFrame(amethod, acaller, aself) {
                     74:        if(method.locals_names) { // are there any local var names?
                     75:                // remember them
                     76:                // those are flags that fname is local == to be looked up in 'my'
                     77:                for(Array_iterator<const String*> i(*method.locals_names); i.has_next(); ) {
                     78:                        // speedup: not checking for clash with "result" fname
                     79:                        const String& fname=*i.next();
                     80:                        set_my_variable(fname, *VString::empty());
1.2       paf        81:                }
1.35      moko       82:        }
1.14      misha      83: #ifdef OPTIMIZE_RESULT
1.35      moko       84:        if(method.result_optimization!=Method::RO_USE_WCONTEXT)
1.14      misha      85: #endif
1.35      moko       86:                set_my_variable(Symbols::RESULT_SYMBOL, void_result);
1.2       paf        87: }
                     88: 
1.35      moko       89: Value* VParserMethodFrame::get_result_variable() {
                     90:        Value* result=my.get(Symbols::RESULT_SYMBOL);
1.30      moko       91:        return result!=&void_result ? result : 0;
1.2       paf        92: }
1.36      moko       93: 
                     94: Value* VParserMethodFrame::get_caller_wrapper(){
                     95:        static VCallerWrapper *caller_wrapper_template=0;
                     96:        if(!caller())
                     97:                return 0;
                     98:        if(caller_wrapper_template && &caller_wrapper_template->caller() == caller())
                     99:                return caller_wrapper_template;
                    100:        return caller_wrapper_template=new VCallerWrapper(*caller());
                    101: }

E-mail: