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

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

E-mail: