compiler/cpp/src/generate/t_hs_generator.cc
/**
 * Generates a process function definition.
 *
 * @param tfunction The function to write a dispatcher for
 */
Generates a process function definition.
@param tfunction The function to write a dispatcher for
Generates a process function definition . @param tfunction The function to write a dispatcher for
void t_hs_generator::generate_process_function(t_service* tservice,
                                               t_function* tfunction) {
  (void) tservice;
  string funname = decapitalize(tfunction->get_name());
  indent(f_service_) << "process_" << funname << " (seqid, iprot, oprot, handler) = do" << endl;
  indent_up();
  string argsname = capitalize(tfunction->get_name()) + "_args";
  string resultname = capitalize(tfunction->get_name()) + "_result";
  t_struct* arg_struct = tfunction->get_arglist();
  const vector<t_field*>& fields = arg_struct->get_members();
  vector<t_field*>::const_iterator f_iter;
  indent(f_service_) << "args <- read_" << argsname << " iprot" << endl;
  indent(f_service_) << "readMessageEnd iprot" << endl;
  t_struct* xs = tfunction->get_xceptions();
  const vector<t_field*>& xceptions = xs->get_members();
  vector<t_field*>::const_iterator x_iter;
  size_t n = xceptions.size();
  if (!tfunction->is_oneway()) {
    if (!tfunction->get_returntype()->is_void())
      n++;
    indent(f_service_) << "rs <- return (" << resultname;
    for(size_t i = 0; i < n; i++)
      f_service_ << " Nothing";
    f_service_ << ")" << endl;
  }
  indent(f_service_) << "res <- ";
  if (xceptions.size() > 0) {
    for(size_t i = 0; i < xceptions.size(); i++) {
      f_service_ << "(Control.Exception.catch" << endl;
      indent_up();
      indent(f_service_);
    }
  }
  f_service_ << "(do" << endl;
  indent_up();
  indent(f_service_);
  if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void())
    f_service_ << "res <- ";
  f_service_ << "Iface." << decapitalize(tfunction->get_name()) << " handler";
  for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter)
    f_service_ <<  " (f_" << argsname <<  "_" << (*f_iter)->get_name() << " args)";
  if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
    f_service_ << endl;
    indent(f_service_) << "return rs{f_" << resultname << "_success= Just res}";
  } else if (!tfunction->is_oneway()) {
    f_service_ << endl;
    indent(f_service_) << "return rs";
  }
  f_service_ << ")" << endl;
  indent_down();
  if (xceptions.size() > 0 && !tfunction->is_oneway()) {
    for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
      indent(f_service_) << "(\\e  -> " << endl;
      indent_up();
      if (!tfunction->is_oneway()) {
        indent(f_service_) << "return rs{f_" << resultname << "_" << (*x_iter)->get_name() << " =Just e}";
      } else {
        indent(f_service_) << "return ()";
      }
      f_service_ << "))" << endl;
      indent_down();
      indent_down();
    }
  }
  if (tfunction->is_oneway()) {
    indent(f_service_) << "return ()" << endl;
    indent_down();
    return;
  }
  indent(f_service_ ) << "writeMessageBegin oprot (\"" << tfunction->get_name() << "\", M_REPLY, seqid);" << endl;
  indent(f_service_ ) << "write_" << resultname << " oprot res" << endl;
  indent(f_service_ ) << "writeMessageEnd oprot" << endl;
  indent(f_service_ ) << "tFlush (getTransport oprot)" << endl;
  indent_down();
}
void t_hs_generator :: generate_process_function ( t_service * tservice , t_function * tfunction ) { ( void ) tservice ; string funname = decapitalize ( tfunction -> get_name ( ) ) ; indent ( f_service_ ) << " " << funname << " " << endl ; indent_up ( ) ; string argsname = capitalize ( tfunction -> get_name ( ) ) + " " ; string resultname = capitalize ( tfunction -> get_name ( ) ) + " " ; t_struct * arg_struct = tfunction -> get_arglist ( ) ; const vector < t_field * > & fields = arg_struct -> get_members ( ) ; vector < t_field * > :: const_iterator f_iter ; indent ( f_service_ ) << " " << argsname << " " << endl ; indent ( f_service_ ) << " " << endl ; t_struct * xs = tfunction -> get_xceptions ( ) ; const vector < t_field * > & xceptions = xs -> get_members ( ) ; vector < t_field * > :: const_iterator x_iter ; size_t n = xceptions . size ( ) ; if ( ! tfunction -> is_oneway ( ) ) { if ( ! tfunction -> get_returntype ( ) -> is_void ( ) ) n ++ ; indent ( f_service_ ) << " " << resultname ; for ( size_t i = 0 ; i < n ; i ++ ) f_service_ << " " ; f_service_ << " " << endl ; } indent ( f_service_ ) << " " ; if ( xceptions . size ( ) > 0 ) { for ( size_t i = 0 ; i < xceptions . size ( ) ; i ++ ) { f_service_ << " " << endl ; indent_up ( ) ; indent ( f_service_ ) ; } } f_service_ << " " << endl ; indent_up ( ) ; indent ( f_service_ ) ; if ( ! tfunction -> is_oneway ( ) && ! tfunction -> get_returntype ( ) -> is_void ( ) ) f_service_ << " " ; f_service_ << " " << decapitalize ( tfunction -> get_name ( ) ) << " " ; for ( f_iter = fields . begin ( ) ; f_iter != fields . end ( ) ; ++ f_iter ) f_service_ << " " << argsname << " " << ( * f_iter ) -> get_name ( ) << " " ; if ( ! tfunction -> is_oneway ( ) && ! tfunction -> get_returntype ( ) -> is_void ( ) ) { f_service_ << endl ; indent ( f_service_ ) << " " << resultname << " " ; } else if ( ! tfunction -> is_oneway ( ) ) { f_service_ << endl ; indent ( f_service_ ) << " " ; } f_service_ << " " << endl ; indent_down ( ) ; if ( xceptions . size ( ) > 0 && ! tfunction -> is_oneway ( ) ) { for ( x_iter = xceptions . begin ( ) ; x_iter != xceptions . end ( ) ; ++ x_iter ) { indent ( f_service_ ) << " \\ " << endl ; indent_up ( ) ; if ( ! tfunction -> is_oneway ( ) ) { indent ( f_service_ ) << " " << resultname << " " << ( * x_iter ) -> get_name ( ) << " " ; } else { indent ( f_service_ ) << " " ; } f_service_ << " " << endl ; indent_down ( ) ; indent_down ( ) ; } } if ( tfunction -> is_oneway ( ) ) { indent ( f_service_ ) << " " << endl ; indent_down ( ) ; return ; } indent ( f_service_ ) << " \" " << tfunction -> get_name ( ) << " \" " << endl ; indent ( f_service_ ) << " " << resultname << " " << endl ; indent ( f_service_ ) << " " << endl ; indent ( f_service_ ) << " " << endl ; indent_down ( ) ; }
Generates a process function definition.
Generates a process function definition .
// Open function // Generate the function call // Try block for a function with exceptions // Shortcut out here for oneway functions // Close function