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

1.2       paf         1: /**    @file
                      2:        Parser: method frame class.
                      3: 
1.19      moko        4:        Copyright (c) 2001-2012 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.22    ! misha      11: volatile const char * IDENT_PA_VMETHOD_FRAME_C="$Id: pa_vmethod_frame.C,v 1.21 2012/06/08 11:44:02 misha Exp $" IDENT_PA_VMETHOD_FRAME_H;
1.19      moko       12: 
1.2       paf        13: // globals
                     14: 
1.15      misha      15: const String result_var_name(RESULT_VAR_NAME), caller_element_name(CALLER_ELEMENT_NAME), self_element_name(SELF_ELEMENT_NAME);
1.22    ! misha      16: #ifdef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
        !            17: const String class_element_name(CLASS_ELEMENT_NAME), class_name_element_name(CLASS_NAME_ELEMENT_NAME);
        !            18: #endif
        !            19: 
1.14      misha      20: VVoid void_result; // unique value to be sure the result is changed
1.2       paf        21: 
                     22: // MethodParams: methods
                     23: 
1.7       paf        24: Value& MethodParams::get_processed(Value* value, const char* msg, int index, Request& r) {
                     25:                return r.process_to_value(as_junction(value, msg, index), false /*do not intercept string*/);
1.2       paf        26: }
                     27: 
1.21      misha      28: HashStringValue* MethodParams::as_hash(int index, const char* name) {
                     29:        Value* value=get(index);
                     30:        if(value) {
                     31:                if(value->get_junction())
                     32:                        throw Exception(PARSER_RUNTIME,
                     33:                                0,
                     34:                                "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     35:                if(!value->is_defined()) // empty hash is not defined, but we don't need it anyway
                     36:                        return 0;
                     37:                if(HashStringValue* result=value->get_hash())
                     38:                        return result;
                     39:                if(value->is_string() && value->get_string()->trim().is_empty())
                     40:                        return 0;
                     41:        }
                     42:        throw Exception(PARSER_RUNTIME,
                     43:                0,
                     44:                "%s must have hash representation (parameter #%d)", name ? name : "options", 1+index);
                     45: }
                     46: 
                     47: Table* MethodParams::as_table(int index, const char* name) {
                     48:        Value* value=get(index);
                     49:        if(value) {
                     50:                if(value->get_junction())
                     51:                        throw Exception(PARSER_RUNTIME,
                     52:                                0,
                     53:                                "%s param must not be code (parameter #%d)", name ? name : "options", 1+index);
                     54:                if(Table* result=value->get_table())
                     55:                        return result;
                     56:        }
                     57:        throw Exception(PARSER_RUNTIME,
                     58:                0,
                     59:                "%s param must have table representation (parameter #%d)", name ? name : "options", 1+index);
                     60: };
                     61: 
1.2       paf        62: // VMethodFrame: methods
                     63: 
1.18      moko       64: VMethodFrame::VMethodFrame(const Method& amethod, VMethodFrame *acaller, Value& aself) : 
1.16      misha      65:        WContext(0 /* no parent, junctions can be reattached only up to VMethodFrame */),
1.4       paf        66:        fcaller(acaller),
1.12      misha      67:        my(0),
1.18      moko       68:        fself(aself),
                     69:        method(amethod) {
1.2       paf        70: 
1.18      moko       71:        put_element_impl=(method.all_vars_local)?&VMethodFrame::put_element_local:&VMethodFrame::put_element_global;
1.9       misha      72: 
1.18      moko       73:        if(!method.max_numbered_params_count){ // this method uses numbered params?
1.17      misha      74:                my=new HashString<Value*>;
1.2       paf        75: 
                     76:                if(method.locals_names) { // are there any local var names?
                     77:                        // remember them
                     78:                        // those are flags that fname is local == to be looked up in 'my'
                     79:                        for(Array_iterator<const String*> i(*method.locals_names); i.has_next(); ) {
                     80:                                // speedup: not checking for clash with "result" fname
                     81:                                const String& fname=*i.next();
1.20      moko       82:                                set_my_variable(fname, *VString::empty());
1.2       paf        83:                        }
                     84:                }
1.14      misha      85: #ifdef OPTIMIZE_RESULT
1.18      moko       86:                if(method.result_optimization!=Method::RO_USE_WCONTEXT)
1.14      misha      87: #endif
                     88:                        set_my_variable(result_var_name, void_result);
1.2       paf        89:        }
                     90: }
                     91: 
                     92: Value* VMethodFrame::get_result_variable() {
1.11      misha      93:        if(!my)
                     94:                return 0;
                     95: 
1.15      misha      96:        Value* result=my->get(result_var_name);
1.14      misha      97:        return result!=&void_result?result:0;
1.2       paf        98: }

E-mail: