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

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.36    ! moko       12: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.35 2016/11/03 16:17:38 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.32      moko       18: Value& MethodParams::get_processed(Value& value, const char* msg, int index, Request& r) {
                     19:        if(!value.get_junction())
                     20:                throw Exception(PARSER_RUNTIME, 0, "%s (parameter #%d)", msg, 1+index);
                     21:        return r.process(value);
1.2       paf        22: }
                     23: 
1.21      misha      24: HashStringValue* MethodParams::as_hash(int index, const char* name) {
1.34      moko       25:        Value& value=get(index);
1.33      moko       26:        if(value.get_junction())
                     27:                throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     28:        if(!value.is_defined()) // empty hash is not defined, but we don't need it anyway
                     29:                return 0;
                     30:        if(HashStringValue* result=value.get_hash())
                     31:                return result;
                     32:        if(value.is_string() && value.get_string()->trim().is_empty())
                     33:                return 0;
1.32      moko       34:        throw Exception(PARSER_RUNTIME, 0, "%s must have hash representation (parameter #%d)", name ? name : "options", 1+index);
1.21      misha      35: }
                     36: 
                     37: Table* MethodParams::as_table(int index, const char* name) {
1.34      moko       38:        Value& value=get(index);
1.33      moko       39:        if(value.get_junction())
                     40:                throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     41:        if(Table* result=value.get_table())
                     42:                return result;
1.30      moko       43:        throw Exception(PARSER_RUNTIME, 0, "%s param must have table representation (parameter #%d)", name ? name : "options", 1+index);
1.23      moko       44: }
1.21      misha      45: 
1.2       paf        46: // VMethodFrame: methods
                     47: 
1.35      moko       48: void VNativeMethodFrame::call(Request &r){
                     49:        check_call_type();
                     50:        method.native_code(r, fnumbered_params);
                     51: }
                     52: 
                     53: void VParserMethodFrame::call(Request &r){
                     54:        check_call_type();
                     55:        r.recoursion_checked_execute(*method.parser_code);
                     56: }
                     57: 
                     58: VParserMethodFrame::VParserMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : VMethodFrame(amethod, acaller, aself) {
                     59:        if(method.locals_names) { // are there any local var names?
                     60:                // remember them
                     61:                // those are flags that fname is local == to be looked up in 'my'
                     62:                for(Array_iterator<const String*> i(*method.locals_names); i.has_next(); ) {
                     63:                        // speedup: not checking for clash with "result" fname
                     64:                        const String& fname=*i.next();
                     65:                        set_my_variable(fname, *VString::empty());
1.2       paf        66:                }
1.35      moko       67:        }
1.14      misha      68: #ifdef OPTIMIZE_RESULT
1.35      moko       69:        if(method.result_optimization!=Method::RO_USE_WCONTEXT)
1.14      misha      70: #endif
1.35      moko       71:                set_my_variable(Symbols::RESULT_SYMBOL, void_result);
1.2       paf        72: }
                     73: 
1.35      moko       74: Value* VParserMethodFrame::get_result_variable() {
                     75:        Value* result=my.get(Symbols::RESULT_SYMBOL);
1.30      moko       76:        return result!=&void_result ? result : 0;
1.2       paf        77: }
1.36    ! moko       78: 
        !            79: Value* VParserMethodFrame::get_caller_wrapper(){
        !            80:        static VCallerWrapper *caller_wrapper_template=0;
        !            81:        if(!caller())
        !            82:                return 0;
        !            83:        if(caller_wrapper_template && &caller_wrapper_template->caller() == caller())
        !            84:                return caller_wrapper_template;
        !            85:        return caller_wrapper_template=new VCallerWrapper(*caller());
        !            86: }

E-mail: