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

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.30    ! moko       11: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.29 2016/10/04 13:23:46 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.7       paf        17: Value& MethodParams::get_processed(Value* value, const char* msg, int index, Request& r) {
1.29      moko       18:                return r.process(as_junction(value, msg, index), false /*do not intercept string*/);
1.2       paf        19: }
                     20: 
1.21      misha      21: HashStringValue* MethodParams::as_hash(int index, const char* name) {
                     22:        Value* value=get(index);
                     23:        if(value) {
                     24:                if(value->get_junction())
1.30    ! moko       25:                        throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
1.21      misha      26:                if(!value->is_defined()) // empty hash is not defined, but we don't need it anyway
                     27:                        return 0;
                     28:                if(HashStringValue* result=value->get_hash())
                     29:                        return result;
                     30:                if(value->is_string() && value->get_string()->trim().is_empty())
                     31:                        return 0;
                     32:        }
                     33:        throw Exception(PARSER_RUNTIME,
                     34:                0,
                     35:                "%s must have hash representation (parameter #%d)", name ? name : "options", 1+index);
                     36: }
                     37: 
                     38: Table* MethodParams::as_table(int index, const char* name) {
                     39:        Value* value=get(index);
                     40:        if(value) {
                     41:                if(value->get_junction())
1.30    ! moko       42:                        throw Exception(PARSER_RUNTIME, 0, "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
1.21      misha      43:                if(Table* result=value->get_table())
                     44:                        return result;
                     45:        }
1.30    ! moko       46:        throw Exception(PARSER_RUNTIME, 0, "%s param must have table representation (parameter #%d)", name ? name : "options", 1+index);
1.23      moko       47: }
1.21      misha      48: 
1.2       paf        49: // VMethodFrame: methods
                     50: 
1.30    ! moko       51: VMethodFrame::VMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) :
1.16      misha      52:        WContext(0 /* no parent, junctions can be reattached only up to VMethodFrame */),
1.4       paf        53:        fcaller(acaller),
1.12      misha      54:        my(0),
1.18      moko       55:        fself(aself),
                     56:        method(amethod) {
1.2       paf        57: 
1.30    ! moko       58:        put_element_impl=(method.all_vars_local) ? &VMethodFrame::put_element_local : &VMethodFrame::put_element_global;
1.9       misha      59: 
1.18      moko       60:        if(!method.max_numbered_params_count){ // this method uses numbered params?
1.17      misha      61:                my=new HashString<Value*>;
1.2       paf        62: 
                     63:                if(method.locals_names) { // are there any local var names?
                     64:                        // remember them
                     65:                        // those are flags that fname is local == to be looked up in 'my'
                     66:                        for(Array_iterator<const String*> i(*method.locals_names); i.has_next(); ) {
                     67:                                // speedup: not checking for clash with "result" fname
                     68:                                const String& fname=*i.next();
1.20      moko       69:                                set_my_variable(fname, *VString::empty());
1.2       paf        70:                        }
                     71:                }
1.14      misha      72: #ifdef OPTIMIZE_RESULT
1.18      moko       73:                if(method.result_optimization!=Method::RO_USE_WCONTEXT)
1.14      misha      74: #endif
1.28      moko       75:                        set_my_variable(Symbols::RESULT_SYMBOL, void_result);
1.2       paf        76:        }
                     77: }
                     78: 
                     79: Value* VMethodFrame::get_result_variable() {
1.11      misha      80:        if(!my)
                     81:                return 0;
                     82: 
1.28      moko       83:        Value* result=my->get(Symbols::RESULT_SYMBOL);
1.30    ! moko       84:        return result!=&void_result ? result : 0;
1.2       paf        85: }

E-mail: