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

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

E-mail: