Public Member Functions | |
virtual | ~GeneratorBase () |
virtual void | init ()=0 |
virtual void | gen_sequence (UTL_ScopedName *tdname, AST_Sequence *seq)=0 |
virtual bool | gen_struct (AST_Structure *s, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *x)=0 |
bool | gen_union (AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator) |
Static Public Member Functions | |
static std::string | generateDefaultValue (AST_Union *the_union, AST_Type *discriminator) |
static bool | hasDefaultLabel (const std::vector< AST_UnionBranch * > &branches) |
static size_t | countLabels (const std::vector< AST_UnionBranch * > &branches) |
static bool | needsDefault (const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator) |
static void | generate_union_field (AST_UnionBranch *branch) |
static std::string | generateCopyCtor (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &) |
static std::string | generateAssign (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &) |
static std::string | generateEqual (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &) |
static std::string | generateReset (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &) |
Classes | |
struct | GenerateGettersAndSetters |
Definition at line 148 of file langmap_generator.cpp.
virtual GeneratorBase::~GeneratorBase | ( | ) | [inline, virtual] |
static size_t GeneratorBase::countLabels | ( | const std::vector< AST_UnionBranch * > & | branches | ) | [inline, static] |
Definition at line 308 of file langmap_generator.cpp.
Referenced by needsDefault().
00309 { 00310 size_t count = 0; 00311 00312 for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end(); 00313 pos != limit; 00314 ++pos) { 00315 count += (*pos)->label_list_length(); 00316 } 00317 00318 return count; 00319 }
virtual void GeneratorBase::gen_sequence | ( | UTL_ScopedName * | tdname, | |
AST_Sequence * | seq | |||
) | [pure virtual] |
Implemented in FaceGenerator, and SafetyProfileGenerator.
Referenced by langmap_generator::gen_typedef().
virtual bool GeneratorBase::gen_struct | ( | AST_Structure * | s, | |
UTL_ScopedName * | name, | |||
const std::vector< AST_Field * > & | fields, | |||
AST_Type::SIZE_TYPE | size, | |||
const char * | x | |||
) | [pure virtual] |
Implemented in FaceGenerator, and SafetyProfileGenerator.
Referenced by langmap_generator::gen_struct().
bool GeneratorBase::gen_union | ( | AST_Union * | u, | |
UTL_ScopedName * | name, | |||
const std::vector< AST_UnionBranch * > & | branches, | |||
AST_Type * | discriminator | |||
) | [inline] |
Definition at line 459 of file langmap_generator.cpp.
References BE_GlobalData::add_include(), be_global, exporter(), gen_typecode(), generate_union_field(), generateAssign(), generateCopyCtor(), generateDefaultValue(), generateEqual(), generateReset(), generateSwitchForUnion(), BE_GlobalData::impl_, BE_GlobalData::lang_header_, needsDefault(), scoped(), BE_GlobalData::STREAM_LANG_H, and struct_decls().
Referenced by langmap_generator::gen_union().
00460 { 00461 const ScopedNamespaceGuard namespaces(name, be_global->lang_header_); 00462 const char* const nm = name->last_component()->get_string(); 00463 struct_decls(name, u->size_type(), "class"); 00464 be_global->lang_header_ << 00465 "\n" 00466 "class " << exporter() << nm << " \n" 00467 "{\n" 00468 " public:\n" 00469 " typedef " << nm << "_var _var_type;\n" 00470 " typedef " << nm << "_out _out_type;\n" 00471 " " << nm << "();\n" 00472 " " << nm << "(const " << nm << "&);\n" 00473 " ~" << nm << "() { _reset(); };\n" 00474 " " << nm << "& operator=(const " << nm << "&);\n" 00475 " void _d(" << scoped(discriminator->name()) << " d) { _discriminator = d; }\n" 00476 " " << scoped(discriminator->name()) << " _d() const { return _discriminator; }\n"; 00477 00478 std::for_each (branches.begin(), branches.end(), GenerateGettersAndSetters(u, discriminator)); 00479 00480 if (needsDefault(branches, discriminator)) { 00481 be_global->lang_header_ << 00482 " void _default() {\n" 00483 " _reset();\n" 00484 " _discriminator = " << generateDefaultValue(u, discriminator) << ";\n" 00485 " }\n"; 00486 } 00487 00488 be_global->lang_header_ << 00489 " bool operator==(const " << nm << "& rhs) const;\n" 00490 " bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n" 00491 " OPENDDS_POOL_ALLOCATION_HOOKS\n"; 00492 00493 be_global->lang_header_ << 00494 " private:\n" 00495 " " << scoped(discriminator->name()) << " _discriminator;\n" 00496 " union {\n"; 00497 00498 std::for_each (branches.begin(), branches.end(), generate_union_field); 00499 00500 be_global->lang_header_ << 00501 " } _u;\n"; 00502 00503 be_global->lang_header_ << 00504 " void _reset();\n" 00505 "};\n\n"; 00506 00507 be_global->add_include("dds/DCPS/PoolAllocationBase.h"); 00508 be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H); 00509 00510 be_global->lang_header_ << 00511 exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n"; 00512 be_global->lang_header_ << 00513 exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n"; 00514 00515 { 00516 const ScopedNamespaceGuard guard(name, be_global->impl_); 00517 00518 be_global->impl_ << 00519 nm << "::" << nm << "() { std::memset (this, 0, sizeof (" << nm << ")); }\n\n"; 00520 00521 be_global->impl_ << 00522 nm << "::" << nm << "(const " << nm << "& other) {\n" << 00523 " this->_discriminator = other._discriminator;\n"; 00524 generateSwitchForUnion("this->_discriminator", generateCopyCtor, branches, discriminator, "", "", "", false, false); 00525 be_global->impl_ << 00526 "}\n\n"; 00527 00528 be_global->impl_ << 00529 nm << "& " << nm << "::operator=(const " << nm << "& other) {\n" << 00530 " if (this != &other) {\n" << 00531 " _reset();\n" << 00532 " this->_discriminator = other._discriminator;\n"; 00533 generateSwitchForUnion("this->_discriminator", generateAssign, branches, discriminator, "", "", "", false, false); 00534 be_global->impl_ << 00535 " }\n" 00536 " return *this;\n" 00537 "}\n\n"; 00538 00539 be_global->impl_ << 00540 "bool " << nm << "::operator==(const " << nm << "& rhs) const\n" 00541 "{\n" 00542 " if (this->_discriminator != rhs._discriminator) return false;"; 00543 generateSwitchForUnion("this->_discriminator", generateEqual, branches, discriminator, "", "", "", false, false); 00544 be_global->impl_ << 00545 " return false;\n" 00546 " }\n"; 00547 00548 be_global->impl_ << 00549 "void " << nm << "::_reset()\n" 00550 "{\n"; 00551 generateSwitchForUnion("this->_discriminator", generateReset, branches, discriminator, "", "", "", false, false); 00552 be_global->impl_ << 00553 " }\n"; 00554 00555 be_global->impl_ << 00556 "ACE_CDR::Boolean operator<< (ACE_OutputCDR &, const " << nm << "&) { return true; }\n\n"; 00557 be_global->impl_ << 00558 "ACE_CDR::Boolean operator>> (ACE_InputCDR &, " << nm << "&) { return true; }\n\n"; 00559 } 00560 00561 gen_typecode(name); 00562 return true; 00563 }
static void GeneratorBase::generate_union_field | ( | AST_UnionBranch * | branch | ) | [inline, static] |
Definition at line 326 of file langmap_generator.cpp.
References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), BE_GlobalData::lang_header_, map_type(), primtype_, and AstTypeClassification::resolveActualType().
Referenced by gen_union().
00327 { 00328 AST_Type* field_type = branch->field_type(); 00329 AST_Type* actual_field_type = resolveActualType(field_type); 00330 const Classification cls = classify(actual_field_type); 00331 if (cls & (CL_PRIMITIVE | CL_ENUM)) { 00332 be_global->lang_header_ << 00333 " " << map_type(field_type) << ' ' << branch->local_name()->get_string() << ";\n"; 00334 } else if (cls & CL_STRING) { 00335 const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE) 00336 ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char; 00337 be_global->lang_header_ << 00338 " " << primtype_[chartype] << "* " << branch->local_name()->get_string() << ";\n"; 00339 } else if (cls & CL_ARRAY) { 00340 be_global->lang_header_ << 00341 " " << map_type(field_type) << "_slice* " << branch->local_name()->get_string() << ";\n"; 00342 } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) { 00343 be_global->lang_header_ << 00344 " " << map_type(field_type) << "* " << branch->local_name()->get_string() << ";\n"; 00345 } else { 00346 std::cerr << "Unsupported type for union element\n"; 00347 } 00348 }
static std::string GeneratorBase::generateAssign | ( | const std::string & | name, | |
AST_Type * | field_type, | |||
const std::string & | , | |||
std::string & | , | |||
const std::string & | ||||
) | [inline, static] |
Definition at line 376 of file langmap_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), map_type(), and AstTypeClassification::resolveActualType().
Referenced by gen_union().
00379 { 00380 std::stringstream ss; 00381 AST_Type* actual_field_type = resolveActualType(field_type); 00382 const Classification cls = classify(actual_field_type); 00383 if (cls & (CL_PRIMITIVE | CL_ENUM)) { 00384 ss << 00385 " this->_u." << name << " = other._u." << name << ";\n"; 00386 } else if (cls & CL_STRING) { 00387 ss << 00388 " this->_u." << name << " = (other._u." << name << ") ? ::CORBA::string_dup(other._u." << name << ") : 0 ;\n"; 00389 } else if (cls & CL_ARRAY) { 00390 ss << 00391 " this->_u." << name << " = (other._u." << name << ") ? " << map_type(field_type) << "_dup(other._u." << name << ") : 0 ;\n"; 00392 } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) { 00393 ss << 00394 " this->_u." << name << " = (other._u." << name << ") ? new " << map_type(field_type) << "(*other._u." << name << ") : 0;\n"; 00395 } else { 00396 std::cerr << "Unsupported type for union element\n"; 00397 } 00398 00399 return ss.str(); 00400 }
static std::string GeneratorBase::generateCopyCtor | ( | const std::string & | name, | |
AST_Type * | field_type, | |||
const std::string & | , | |||
std::string & | , | |||
const std::string & | ||||
) | [inline, static] |
Definition at line 350 of file langmap_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), map_type(), and AstTypeClassification::resolveActualType().
Referenced by gen_union().
00353 { 00354 std::stringstream ss; 00355 AST_Type* actual_field_type = resolveActualType(field_type); 00356 const Classification cls = classify(actual_field_type); 00357 if (cls & (CL_PRIMITIVE | CL_ENUM)) { 00358 ss << 00359 " this->_u." << name << " = other._u." << name << ";\n"; 00360 } else if (cls & CL_STRING) { 00361 ss << 00362 " this->_u." << name << " = (other._u." << name << ") ? ::CORBA::string_dup(other._u." << name << ") : 0 ;\n"; 00363 } else if (cls & CL_ARRAY) { 00364 ss << 00365 " this->_u." << name << " = (other._u." << name << ") ? " << map_type(field_type) << "_dup(other._u." << name << ") : 0 ;\n"; 00366 } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) { 00367 ss << 00368 " this->_u." << name << " = (other._u." << name << ") ? new " << map_type(field_type) << "(*other._u." << name << ") : 0;\n"; 00369 } else { 00370 std::cerr << "Unsupported type for union element\n"; 00371 } 00372 00373 return ss.str(); 00374 }
static std::string GeneratorBase::generateDefaultValue | ( | AST_Union * | the_union, | |
AST_Type * | discriminator | |||
) | [inline, static] |
Definition at line 156 of file langmap_generator.cpp.
References scoped().
Referenced by gen_union(), and GeneratorBase::GenerateGettersAndSetters::operator()().
00157 { 00158 std::stringstream first_label; 00159 AST_Union::DefaultValue dv; 00160 the_union->default_value(dv); 00161 00162 switch (the_union->udisc_type ()) 00163 { 00164 case AST_Expression::EV_short: 00165 first_label << dv.u.short_val; 00166 break; 00167 case AST_Expression::EV_ushort: 00168 first_label << dv.u.ushort_val; 00169 break; 00170 case AST_Expression::EV_long: 00171 first_label << dv.u.long_val; 00172 break; 00173 case AST_Expression::EV_ulong: 00174 first_label << dv.u.ulong_val; 00175 break; 00176 case AST_Expression::EV_char: 00177 first_label << (int)dv.u.char_val; 00178 break; 00179 case AST_Expression::EV_bool: 00180 first_label << (dv.u.bool_val == 0 ? "false" : "true"); 00181 break; 00182 case AST_Expression::EV_enum: 00183 { 00184 AST_Enum* e = AST_Enum::narrow_from_decl(discriminator); 00185 first_label << scoped(e->value_to_name(dv.u.enum_val)); 00186 break; 00187 } 00188 case AST_Expression::EV_longlong: 00189 first_label << dv.u.longlong_val; 00190 break; 00191 case AST_Expression::EV_ulonglong: 00192 first_label << dv.u.ulonglong_val; 00193 break; 00194 default: 00195 std::cerr << "Illegal discriminator for union\n"; 00196 break; 00197 } 00198 00199 return first_label.str(); 00200 }
static std::string GeneratorBase::generateEqual | ( | const std::string & | name, | |
AST_Type * | field_type, | |||
const std::string & | , | |||
std::string & | , | |||
const std::string & | ||||
) | [inline, static] |
Definition at line 402 of file langmap_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().
Referenced by gen_union().
00405 { 00406 std::stringstream ss; 00407 00408 AST_Type* actual_field_type = resolveActualType(field_type); 00409 const Classification cls = classify(actual_field_type); 00410 if (cls & (CL_PRIMITIVE | CL_ENUM)) { 00411 ss << 00412 " return this->_u." << name << " == rhs._u." << name << ";\n"; 00413 } else if (cls & CL_STRING) { 00414 ss << 00415 " return std::strcmp (this->_u." << name << ", rhs._u." << name << ") == 0 ;\n"; 00416 } else if (cls & CL_ARRAY) { 00417 // TODO 00418 ss << 00419 " return false;\n"; 00420 } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) { 00421 ss << 00422 " return *this->_u." << name << " == *rhs._u." << name << ";\n"; 00423 } else { 00424 std::cerr << "Unsupported type for union element\n"; 00425 } 00426 00427 return ss.str(); 00428 }
static std::string GeneratorBase::generateReset | ( | const std::string & | name, | |
AST_Type * | field_type, | |||
const std::string & | , | |||
std::string & | , | |||
const std::string & | ||||
) | [inline, static] |
Definition at line 430 of file langmap_generator.cpp.
References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), map_type(), and AstTypeClassification::resolveActualType().
Referenced by gen_union().
00433 { 00434 std::stringstream ss; 00435 00436 AST_Type* actual_field_type = resolveActualType(field_type); 00437 const Classification cls = classify(actual_field_type); 00438 if (cls & (CL_PRIMITIVE | CL_ENUM)) { 00439 // Do nothing. 00440 } else if (cls & CL_STRING) { 00441 ss << 00442 " ::CORBA::string_free(this->_u." << name << ");\n" 00443 " this->_u." << name << " = 0;\n"; 00444 } else if (cls & CL_ARRAY) { 00445 ss << 00446 " " << map_type(field_type) << "_free(this->_u." << name << ");\n" 00447 " this->_u." << name << " = 0;\n"; 00448 } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) { 00449 ss << 00450 " delete this->_u." << name << ";\n" 00451 " this->_u." << name << " = 0;\n"; 00452 } else { 00453 std::cerr << "Unsupported type for union element\n"; 00454 } 00455 00456 return ss.str(); 00457 }
static bool GeneratorBase::hasDefaultLabel | ( | const std::vector< AST_UnionBranch * > & | branches | ) | [inline, static] |
Definition at line 292 of file langmap_generator.cpp.
Referenced by needsDefault().
00293 { 00294 for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end(); 00295 pos != limit; 00296 ++pos) { 00297 AST_UnionBranch* branch = *pos; 00298 for (unsigned long j = 0; j < branch->label_list_length(); ++j) { 00299 AST_UnionLabel* label = branch->label(j); 00300 if (label->label_kind() == AST_UnionLabel::UL_default) { 00301 return true; 00302 } 00303 } 00304 } 00305 return false; 00306 }
virtual void GeneratorBase::init | ( | ) | [pure virtual] |
static bool GeneratorBase::needsDefault | ( | const std::vector< AST_UnionBranch * > & | branches, | |
AST_Type * | discriminator | |||
) | [inline, static] |
Definition at line 321 of file langmap_generator.cpp.
References countLabels(), hasDefaultLabel(), and needSyntheticDefault().
Referenced by gen_union().
00322 { 00323 return !hasDefaultLabel(branches) && needSyntheticDefault(discriminator, countLabels(branches)); 00324 }