compiler/cpp/src/generate/t_hs_generator.cc
/**
 * Converts the parse type to an haskell type
 */
Converts the parse type to an haskell type
Converts the parse type to an haskell type
string t_hs_generator::render_hs_type(t_type* type, bool needs_parens) {
  type = get_true_type(type);
  string type_repr;
  if (type->is_base_type()) {
    t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
    switch (tbase) {
    case t_base_type::TYPE_VOID:   return "()";
    case t_base_type::TYPE_STRING: return (((t_base_type*)type)->is_binary() ? "ByteString" : "Text");
    case t_base_type::TYPE_BOOL:   return "Bool";
    case t_base_type::TYPE_BYTE:   return "Int8";
    case t_base_type::TYPE_I16:    return "Int16";
    case t_base_type::TYPE_I32:    return "Int32";
    case t_base_type::TYPE_I64:    return "Int64";
    case t_base_type::TYPE_DOUBLE: return "Double";
    }
  } else if (type->is_enum()) {
    return capitalize(((t_enum*)type)->get_name());
  } else if (type->is_struct() || type->is_xception()) {
    return type_name((t_struct*)type);
  } else if (type->is_map()) {
    t_type* ktype = ((t_map*)type)->get_key_type();
    t_type* vtype = ((t_map*)type)->get_val_type();
    type_repr = "Map.HashMap " + render_hs_type(ktype, true) + " " + render_hs_type(vtype, true);
  } else if (type->is_set()) {
    t_type* etype = ((t_set*)type)->get_elem_type();
    type_repr = "Set.HashSet " + render_hs_type(etype, true) ;
  } else if (type->is_list()) {
    t_type* etype = ((t_list*)type)->get_elem_type();
    type_repr = "Vector.Vector " + render_hs_type(etype, true);
  } else {
    throw "INVALID TYPE IN type_to_enum: " + type->get_name();
  }
  return needs_parens ? "(" + type_repr + ")" : type_repr;
}
string t_hs_generator :: render_hs_type ( t_type * type , bool needs_parens ) { type = get_true_type ( type ) ; string type_repr ; if ( type -> is_base_type ( ) ) { t_base_type :: t_base tbase = ( ( t_base_type * ) type ) -> get_base ( ) ; switch ( tbase ) { case t_base_type :: TYPE_VOID : return " " ; case t_base_type :: TYPE_STRING : return ( ( ( t_base_type * ) type ) -> is_binary ( ) ? " " : " " ) ; case t_base_type :: TYPE_BOOL : return " " ; case t_base_type :: TYPE_BYTE : return " " ; case t_base_type :: TYPE_I16 : return " " ; case t_base_type :: TYPE_I32 : return " " ; case t_base_type :: TYPE_I64 : return " " ; case t_base_type :: TYPE_DOUBLE : return " " ; } } else if ( type -> is_enum ( ) ) { return capitalize ( ( ( t_enum * ) type ) -> get_name ( ) ) ; } else if ( type -> is_struct ( ) || type -> is_xception ( ) ) { return type_name ( ( t_struct * ) type ) ; } else if ( type -> is_map ( ) ) { t_type * ktype = ( ( t_map * ) type ) -> get_key_type ( ) ; t_type * vtype = ( ( t_map * ) type ) -> get_val_type ( ) ; type_repr = " " + render_hs_type ( ktype , true ) + " " + render_hs_type ( vtype , true ) ; } else if ( type -> is_set ( ) ) { t_type * etype = ( ( t_set * ) type ) -> get_elem_type ( ) ; type_repr = " " + render_hs_type ( etype , true ) ; } else if ( type -> is_list ( ) ) { t_type * etype = ( ( t_list * ) type ) -> get_elem_type ( ) ; type_repr = " " + render_hs_type ( etype , true ) ; } else { throw " " + type -> get_name ( ) ; } return needs_parens ? " " + type_repr + " " : type_repr ; }
Converts the parse type to an haskell type
Converts the parse type to an haskell type