compiler/cpp/src/generate/t_go_generator.cc
/**
 * Converts the parse type to a go tyoe
 */
Converts the parse type to a go tyoe
Converts the parse type to a go tyoe
string t_go_generator::type_to_go_type(t_type* type) {
  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:
      throw "";
    case t_base_type::TYPE_STRING:
      return "string";
    case t_base_type::TYPE_BOOL:
      return "bool";
    case t_base_type::TYPE_BYTE:
      return "byte";
    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 "float64";
    }
  } else if (type->is_enum()) {
    return publicize(type->get_name());
  } else if (type->is_struct() || type->is_xception()) {
    return string("*") + publicize(type->get_name());
  } else if (type->is_map()) {
    return "thrift.TMap";
  } else if (type->is_set()) {
    return "thrift.TSet";
  } else if (type->is_list()) {
    return "thrift.TList";
  } else if (type->is_typedef()) {
    return publicize(((t_typedef*)type)->get_symbolic());
  }
  throw "INVALID TYPE IN type_to_go_type: " + type->get_name();
}
string t_go_generator :: type_to_go_type ( t_type * type ) { 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 : throw " " ; case t_base_type :: TYPE_STRING : return " " ; 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 publicize ( type -> get_name ( ) ) ; } else if ( type -> is_struct ( ) || type -> is_xception ( ) ) { return string ( " " ) + publicize ( type -> get_name ( ) ) ; } else if ( type -> is_map ( ) ) { return " " ; } else if ( type -> is_set ( ) ) { return " " ; } else if ( type -> is_list ( ) ) { return " " ; } else if ( type -> is_typedef ( ) ) { return publicize ( ( ( t_typedef * ) type ) -> get_symbolic ( ) ) ; } throw " " + type -> get_name ( ) ; }
Converts the parse type to a go tyoe
Converts the parse type to a go tyoe
//type = get_true_type(type); //t_map* t = (t_map*)type; //string keyType = type_to_go_type(t->get_key_type()); //string valueType = type_to_go_type(t->get_val_type()); //return string("map[") + keyType + "]" + valueType; //t_set* t = (t_set*)type; //string elemType = type_to_go_type(t->get_elem_type()); //return string("[]") + elemType; //t_list* t = (t_list*)type; //string elemType = type_to_go_type(t->get_elem_type()); //return string("[]") + elemType;