300 const char* field_name = branch->local_name()->get_string();
301 std::stringstream first_label;
303 AST_UnionLabel* label = branch->label(0);
304 if (label->label_kind() == AST_UnionLabel::UL_default) {
306 }
else if (
discriminator->node_type() == AST_Decl::NT_enum) {
309 first_label << *label->label_val()->ev();
313 AST_Type* field_type = branch->field_type();
314 const std::string field_type_string = generator_->map_type(field_type);
319 " void " << field_name <<
" (" << field_type_string <<
" x) {\n" 321 " this->_u." << field_name <<
" = x;\n" 322 " _discriminator = " << first_label.str() <<
";\n" 324 " " << field_type_string <<
' ' << field_name <<
" () const {\n" 325 " return this->_u." << field_name <<
";\n" 328 const std::string& primtype = (cls &
CL_WIDE) ? primtype_[AST_PredefinedType::PT_wchar] : primtype_[AST_PredefinedType::PT_char];
329 const std::string& helper = (cls &
CL_WIDE) ? helpers_[HLP_WSTR_VAR] : helpers_[HLP_STR_VAR];
331 " void " << field_name <<
" (" << primtype <<
"* x) {\n" 333 " this->_u." << field_name <<
" = x;\n" 334 " _discriminator = " << first_label.str() <<
";\n" 336 " void " << field_name <<
" (const " << primtype <<
"* x) {\n" 338 " this->_u." << field_name <<
" = " << string_ns <<
"::string_dup(x);\n" 339 " _discriminator = " << first_label.str() <<
";\n" 341 " void " << field_name <<
" (const " << helper <<
"& x) {\n" 343 " this->_u." << field_name <<
" = " << string_ns <<
"::string_dup(x.in());\n" 344 " _discriminator = " << first_label.str() <<
";\n" 346 " const " << primtype <<
"* " << field_name <<
" () const {\n" 347 " return this->_u." << field_name <<
";\n" 351 " void " << field_name <<
" (" << field_type_string <<
" x) {\n" 353 " this->_u." << field_name <<
" = " << field_type_string <<
"_dup(x);\n" 354 " _discriminator = " << first_label.str() <<
";\n" 356 " " << field_type_string <<
"_slice* " << field_name <<
" () const {\n" 357 " return this->_u." << field_name <<
";\n" 361 " void " << field_name <<
" (const " << field_type_string <<
"& x) {\n" 363 " this->_u." << field_name <<
" = new " << field_type_string <<
"(x);\n" 364 " _discriminator = " << first_label.str() <<
";\n" 366 " const " << field_type_string <<
"& " << field_name <<
" () const {\n" 367 " return *this->_u." << field_name <<
";\n" 369 " " << field_type_string <<
"& " << field_name <<
" () {\n" 370 " return *this->_u." << field_name <<
";\n" 373 std::cerr <<
"Unsupported type for union element\n";
const Classification CL_ARRAY
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
std::string getEnumLabel(AST_Expression *label_val, AST_Type *disc)
static std::string generateDefaultValue(AST_Union *the_union)
BE_GlobalData * be_global
const Classification CL_WIDE