Logo Search packages:      
Sourcecode: parser version File versions  Download package

StringOrValue Request::process ( Value input_value,
bool  intercept_string = true 
)

processes any code-junction there may be inside of value

Parameters:
intercept_string 
  • true: they want result=string value, possible object result goes to wcontext
  • false: they want any result[string|object] nothing goes to wcontext. used in (expression) params evaluation
using the fact it's either string_ or value_ result requested to speed up checkes

Definition at line 929 of file execute.C.

References Junction::auto_name, Junction::code, Array< T >::count(), Value::get_junction(), Junction::is_getter, VMethodFrame::junction, Junction::method, Junction::method_frame, method_frame, Method::params_names, Method::parser_code, Junction::rcontext, recoursion_checked_execute(), WContext::result(), Junction::self, VMethodFrame::set_self(), VMethodFrame::store_param(), and Junction::wcontext.

Referenced by try_catch().

                                                                        {
      Junction* junction=input_value.get_junction();
      if(junction) {
            if(junction->is_getter) { // is it a getter-junction?
                  int param_count=junction->method->params_names?junction->method->params_names->count():0;
                  if(junction->auto_name){ // default getter
                        if(param_count>1)
                              throw Exception(PARSER_RUNTIME,
                                    0,
                                    "default getter method can't have more then 1 parameter (has %d parameters)", param_count);
                  } else if(param_count)
                        throw Exception(PARSER_RUNTIME,
                              0,
                              "getter method must have no parameters (has %d parameters)", param_count);

                  VMethodFrame frame(*junction, method_frame/*caller*/);

                  if(junction->auto_name && param_count)
                        frame.store_param(*new VString(*junction->auto_name));

                  frame.set_self(frame.junction.self);

                  VMethodFrame *saved_method_frame=method_frame;
                  Value* saved_rcontext=rcontext;
                  WContext *saved_wcontext=wcontext;

                  rcontext=wcontext=&frame;
                  method_frame=&frame;

                  recoursion_checked_execute(*frame.junction.method->parser_code); // parser code, execute it
                  StringOrValue result=wcontext->result();

                  method_frame=saved_method_frame;
                  wcontext=saved_wcontext;
                  rcontext=saved_rcontext;

                  return result;
            }

            if(junction->code) { // is it a code-junction?
                  // process it
                  StringOrValue result;
#ifdef DEBUG_EXECUTE
                  debug_printf(sapi_info, "ja->\n");
#endif

                  if(!junction->method_frame)
                        throw Exception(PARSER_RUNTIME,
                        0,
                        "junction used outside of context");

                  VMethodFrame *saved_method_frame=method_frame;  
                  Value* saved_rcontext=rcontext;  
                  WContext *saved_wcontext=wcontext;

                  method_frame=junction->method_frame;
                  rcontext=junction->rcontext;

                  // for expression method params
                  // wcontext is set 0
                  // using the fact in decision "which wwrapper to use"
                  bool using_code_frame=intercept_string && junction->wcontext;
                  if(using_code_frame) {
                        // almost plain wwrapper about junction wcontext 

                        VCodeFrame local(*junction->wcontext);
                        wcontext=&local;

                        // execute it
                        recoursion_checked_execute(*junction->code);

                        // CodeFrame soul:
                        result=wcontext->result();
                  } else {
                        // plain wwrapper
                        WWrapper local(0/*empty*/, wcontext);
                        wcontext=&local;

                        // execute it
                        recoursion_checked_execute(*junction->code);

                        result=wcontext->result();
                  }

                  wcontext=saved_wcontext;
                  rcontext=saved_rcontext;
                  method_frame=saved_method_frame;

#ifdef DEBUG_EXECUTE
                  debug_printf(sapi_info, "<-ja returned");
#endif
                  return result;
            }

            // it is then method-junction, do not explode it
            // just return it as we do for usual objects
      }     

      return input_value;
}


Generated by  Doxygen 1.6.0   Back to index