#include "be_extern.h"
#include "utl_scoped_name.h"
#include "utl_identifier.h"
#include "utl_string.h"
#include "ast.h"
#include "ast_component_fwd.h"
#include "ast_eventtype_fwd.h"
#include "ast_structure_fwd.h"
#include "ast_union_fwd.h"
#include "ast_valuetype_fwd.h"
#include "ace/CDR_Base.h"
#include <string>
#include <vector>
#include <cstring>
Include dependency graph for dds_generator.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Namespaces | |
namespace | AstTypeClassification |
Classes | |
class | dds_generator |
class | composite_generator |
struct | NamespaceGuard |
struct | ScopedNamespaceGuard |
struct | Function |
struct | NestedForLoops |
struct | RestoreOutputStreamState |
Typedefs | |
typedef size_t | AstTypeClassification::Classification |
typedef std::string(*) | CommonFn (const std::string &name, AST_Type *type, const std::string &prefix, std::string &intro, const std::string &) |
Enumerations | |
enum | WrapDirection { WD_OUTPUT, WD_INPUT } |
Functions | |
std::string | scoped (UTL_ScopedName *sn) |
std::string | module_scope (UTL_ScopedName *sn) |
AST_Type * | AstTypeClassification::resolveActualType (AST_Type *element) |
Classification | AstTypeClassification::classify (AST_Type *type) |
std::string | wrapPrefix (AST_Type *type, WrapDirection wd) |
std::string | getWrapper (const std::string &name, AST_Type *type, WrapDirection wd) |
std::string | getEnumLabel (AST_Expression *label_val, AST_Type *disc) |
std::ostream & | operator<< (std::ostream &o, const AST_Expression::AST_ExprValue &ev) |
void | generateBranchLabels (AST_UnionBranch *branch, AST_Type *discriminator, size_t &n_labels, bool &has_default) |
bool | needSyntheticDefault (AST_Type *disc, size_t n_labels) |
void | generateCaseBody (CommonFn commonFn, AST_UnionBranch *branch, const char *statementPrefix, const char *namePrefix, const std::string &uni, bool generateBreaks, bool parens) |
void | generateSwitchBodyForUnion (CommonFn commonFn, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const std::string &uni="", bool forceDisableDefault=false, bool parens=true) |
void | generateSwitchForUnion (const std::string &switchExpr, CommonFn commonFn, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const std::string &uni="", bool forceDisableDefault=false, bool parens=true) |
Variables | |
const Classification | AstTypeClassification::CL_UNKNOWN = 0 |
const Classification | AstTypeClassification::CL_SCALAR = 1 |
const Classification | AstTypeClassification::CL_PRIMITIVE = 2 |
const Classification | AstTypeClassification::CL_STRUCTURE = 4 |
const Classification | AstTypeClassification::CL_STRING = 8 |
const Classification | AstTypeClassification::CL_ENUM = 16 |
const Classification | AstTypeClassification::CL_UNION = 32 |
const Classification | AstTypeClassification::CL_ARRAY = 64 |
const Classification | AstTypeClassification::CL_SEQUENCE = 128 |
const Classification | AstTypeClassification::CL_WIDE = 256 |
const Classification | AstTypeClassification::CL_BOUNDED = 512 |
const Classification | AstTypeClassification::CL_INTERFACE = 1024 |
const Classification | AstTypeClassification::CL_FIXED = 2048 |
typedef std::string(*) CommonFn(const std::string &name, AST_Type *type, const std::string &prefix, std::string &intro, const std::string &) |
Definition at line 530 of file dds_generator.h.
enum WrapDirection |
void generateBranchLabels | ( | AST_UnionBranch * | branch, | |
AST_Type * | discriminator, | |||
size_t & | n_labels, | |||
bool & | has_default | |||
) | [inline] |
Definition at line 489 of file dds_generator.h.
References be_global, getEnumLabel(), and BE_GlobalData::impl_.
Referenced by generateSwitchBodyForUnion().
00491 { 00492 for (unsigned long j = 0; j < branch->label_list_length(); ++j) { 00493 ++n_labels; 00494 AST_UnionLabel* label = branch->label(j); 00495 if (label->label_kind() == AST_UnionLabel::UL_default) { 00496 be_global->impl_ << " default:\n"; 00497 has_default = true; 00498 } else if (discriminator->node_type() == AST_Decl::NT_enum) { 00499 be_global->impl_ << " case " 00500 << getEnumLabel(label->label_val(), discriminator) << ":\n"; 00501 } else { 00502 be_global->impl_ << " case " << *label->label_val()->ev() << ":\n"; 00503 } 00504 } 00505 }
void generateCaseBody | ( | CommonFn | commonFn, | |
AST_UnionBranch * | branch, | |||
const char * | statementPrefix, | |||
const char * | namePrefix, | |||
const std::string & | uni, | |||
bool | generateBreaks, | |||
bool | parens | |||
) | [inline] |
Definition at line 534 of file dds_generator.h.
References BE_GlobalData::add_referenced(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), getWrapper(), BE_GlobalData::impl_, BE_GlobalData::LANGMAP_FACE_CXX, BE_GlobalData::language_mapping(), AstTypeClassification::resolveActualType(), scoped(), and WD_INPUT.
Referenced by generateSwitchBodyForUnion(), and generateSwitchForUnion().
00541 { 00542 using namespace AstTypeClassification; 00543 std::string intro, name = branch->local_name()->get_string(); 00544 if (namePrefix == std::string(">> ")) { 00545 std::string brType = scoped(branch->field_type()->name()), forany; 00546 AST_Type* br = resolveActualType(branch->field_type()); 00547 Classification br_cls = classify(br); 00548 if (!br->in_main_file() 00549 && br->node_type() != AST_Decl::NT_pre_defined) { 00550 be_global->add_referenced(br->file_name().c_str()); 00551 } 00552 std::string rhs; 00553 if (br_cls & CL_STRING) { 00554 if (be_global->language_mapping() == BE_GlobalData::LANGMAP_FACE_CXX) { 00555 brType = std::string("FACE::") + ((br_cls & CL_WIDE) ? "W" : "") 00556 + "String_var"; 00557 } else { 00558 brType = std::string("CORBA::") + ((br_cls & CL_WIDE) ? "W" : "") 00559 + "String_var"; 00560 } 00561 rhs = "tmp.out()"; 00562 } else if (br_cls & CL_ARRAY) { 00563 forany = " " + brType + "_forany fa = tmp;\n"; 00564 rhs = getWrapper("fa", br, WD_INPUT); 00565 } else { 00566 rhs = getWrapper("tmp", br, WD_INPUT); 00567 } 00568 be_global->impl_ << 00569 " {\n" 00570 " " << brType << " tmp;\n" << forany << 00571 " if (strm >> " << rhs << ") {\n" 00572 " uni." << name << "(tmp);\n" 00573 " uni._d(disc);\n" 00574 " return true;\n" 00575 " }\n" 00576 " return false;\n" 00577 " }\n"; 00578 } else { 00579 const char* breakString = (generateBreaks) ? " break;\n" : ""; 00580 00581 std::string expr = commonFn(name + (parens ? "()" : ""), branch->field_type(), 00582 std::string(namePrefix) + "uni", intro, uni); 00583 be_global->impl_ << 00584 " {\n" << 00585 (intro.length() ? " " : "") << intro; 00586 if (*statementPrefix) { 00587 be_global->impl_ << 00588 " " << statementPrefix << " " << expr << ";\n" << 00589 (statementPrefix == std::string("return") ? "" : breakString); 00590 } else { 00591 be_global->impl_ << expr << breakString; 00592 } 00593 be_global->impl_<< 00594 " }\n"; 00595 } 00596 }
void generateSwitchBodyForUnion | ( | CommonFn | commonFn, | |
const std::vector< AST_UnionBranch * > & | branches, | |||
AST_Type * | discriminator, | |||
const char * | statementPrefix, | |||
const char * | namePrefix = "" , |
|||
const std::string & | uni = "" , |
|||
bool | forceDisableDefault = false , |
|||
bool | parens = true | |||
) | [inline] |
Definition at line 598 of file dds_generator.h.
References be_global, generateBranchLabels(), generateCaseBody(), BE_GlobalData::impl_, and needSyntheticDefault().
Referenced by generateSwitchForUnion(), and genRtpsParameter().
00604 { 00605 size_t n_labels = 0; 00606 bool has_default = false; 00607 for (size_t i = 0; i < branches.size(); ++i) { 00608 AST_UnionBranch* branch = branches[i]; 00609 if (forceDisableDefault) { 00610 bool foundDefault = false; 00611 for (unsigned long j = 0; j < branch->label_list_length(); ++j) { 00612 if (branch->label(j)->label_kind() == AST_UnionLabel::UL_default) { 00613 foundDefault = true; 00614 } 00615 } 00616 if (foundDefault) { 00617 has_default = true; 00618 continue; 00619 } 00620 } 00621 generateBranchLabels(branch, discriminator, n_labels, has_default); 00622 generateCaseBody(commonFn, branch, statementPrefix, namePrefix, uni, true, parens); 00623 } 00624 if (!has_default && needSyntheticDefault(discriminator, n_labels)) { 00625 be_global->impl_ << 00626 " default:\n" << 00627 ((namePrefix == std::string(">> ")) ? " uni._d(disc);\n" : "") << 00628 " break;\n"; 00629 } 00630 }
void generateSwitchForUnion | ( | const std::string & | switchExpr, | |
CommonFn | commonFn, | |||
const std::vector< AST_UnionBranch * > & | branches, | |||
AST_Type * | discriminator, | |||
const char * | statementPrefix, | |||
const char * | namePrefix = "" , |
|||
const std::string & | uni = "" , |
|||
bool | forceDisableDefault = false , |
|||
bool | parens = true | |||
) | [inline] |
Definition at line 632 of file dds_generator.h.
References be_global, generateCaseBody(), generateSwitchBodyForUnion(), BE_GlobalData::impl_, and AstTypeClassification::resolveActualType().
Referenced by metaclass_generator::gen_union(), marshal_generator::gen_union(), GeneratorBase::gen_union(), genRtpsParameter(), and genRtpsSubmessage().
00636 { 00637 using namespace AstTypeClassification; 00638 AST_Type* dt = resolveActualType(discriminator); 00639 AST_PredefinedType* bt = AST_PredefinedType::narrow_from_decl(dt); 00640 if (bt && bt->pt() == AST_PredefinedType::PT_boolean) { 00641 AST_UnionBranch* true_branch = 0; 00642 AST_UnionBranch* false_branch = 0; 00643 AST_UnionBranch* default_branch = 0; 00644 for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end(); 00645 pos != limit; 00646 ++pos) { 00647 AST_UnionBranch* branch = *pos; 00648 for (unsigned long j = 0; j < branch->label_list_length(); ++j) { 00649 AST_UnionLabel* label = branch->label(j); 00650 if (label->label_kind() == AST_UnionLabel::UL_default) { 00651 default_branch = branch; 00652 } 00653 if (label->label_val()->ev()->u.bval) { 00654 true_branch = branch; 00655 } 00656 if (!label->label_val()->ev()->u.bval) { 00657 false_branch = branch; 00658 } 00659 } 00660 } 00661 00662 be_global->impl_ << 00663 " if (" << switchExpr << ") \n"; 00664 if (true_branch || default_branch) { 00665 generateCaseBody(commonFn, true_branch ? true_branch : default_branch, statementPrefix, namePrefix, uni, false, parens); 00666 } 00667 be_global->impl_ << 00668 " else \n"; 00669 if (false_branch || default_branch) { 00670 generateCaseBody(commonFn, false_branch ? false_branch : default_branch, statementPrefix, namePrefix, uni, false, parens); 00671 } 00672 } 00673 else { 00674 be_global->impl_ << 00675 " switch (" << switchExpr << ") {\n"; 00676 generateSwitchBodyForUnion(commonFn, branches, discriminator, statementPrefix, namePrefix, uni, forceDisableDefault, parens); 00677 be_global->impl_ << 00678 " }\n"; 00679 } 00680 }
std::string getEnumLabel | ( | AST_Expression * | label_val, | |
AST_Type * | disc | |||
) | [inline] |
Definition at line 420 of file dds_generator.h.
References scoped().
Referenced by generateBranchLabels(), and GeneratorBase::GenerateGettersAndSetters::operator()().
00421 { 00422 std::string e = scoped(disc->name()), 00423 label = label_val->n()->last_component()->get_string(); 00424 const size_t colon = e.rfind("::"); 00425 if (colon == std::string::npos) { 00426 return label; 00427 } 00428 return e.replace(colon + 2, std::string::npos, label); 00429 }
std::string getWrapper | ( | const std::string & | name, | |
AST_Type * | type, | |||
WrapDirection | wd | |||
) | [inline] |
Definition at line 413 of file dds_generator.h.
References wrapPrefix().
Referenced by findSizeCommon(), gen_field_getValueFromSerialized(), gen_sequence(), metaclass_generator::gen_union(), marshal_generator::gen_union(), generateCaseBody(), and streamCommon().
00414 { 00415 std::string pre = wrapPrefix(type, wd); 00416 return (pre.empty()) ? name : (pre + name + ')'); 00417 }
std::string module_scope | ( | UTL_ScopedName * | sn | ) | [inline] |
Definition at line 223 of file dds_generator.h.
References dds_generator::module_scope_helper().
Referenced by ts_generator::gen_struct().
00224 { 00225 return dds_generator::module_scope_helper(sn, "::"); 00226 }
bool needSyntheticDefault | ( | AST_Type * | disc, | |
size_t | n_labels | |||
) | [inline] |
Definition at line 508 of file dds_generator.h.
Referenced by generateSwitchBodyForUnion(), and GeneratorBase::needsDefault().
00509 { 00510 AST_Decl::NodeType nt = disc->node_type(); 00511 if (nt == AST_Decl::NT_enum) return true; 00512 00513 AST_PredefinedType* pdt = AST_PredefinedType::narrow_from_decl(disc); 00514 switch (pdt->pt()) { 00515 case AST_PredefinedType::PT_boolean: 00516 return n_labels < 2; 00517 case AST_PredefinedType::PT_char: 00518 return n_labels < ACE_OCTET_MAX; 00519 case AST_PredefinedType::PT_short: 00520 case AST_PredefinedType::PT_ushort: 00521 return n_labels < ACE_UINT16_MAX; 00522 case AST_PredefinedType::PT_long: 00523 case AST_PredefinedType::PT_ulong: 00524 return n_labels < ACE_UINT32_MAX; 00525 default: 00526 return true; 00527 } 00528 }
std::ostream& operator<< | ( | std::ostream & | o, | |
const AST_Expression::AST_ExprValue & | ev | |||
) | [inline] |
Definition at line 442 of file dds_generator.h.
00444 { 00445 RestoreOutputStreamState ross(o); 00446 switch (ev.et) { 00447 case AST_Expression::EV_octet: 00448 return o << static_cast<int>(ev.u.oval); 00449 case AST_Expression::EV_short: 00450 return o << ev.u.sval; 00451 case AST_Expression::EV_ushort: 00452 return o << ev.u.usval << 'u'; 00453 case AST_Expression::EV_long: 00454 return o << ev.u.lval; 00455 case AST_Expression::EV_ulong: 00456 return o << ev.u.ulval << 'u'; 00457 case AST_Expression::EV_longlong: 00458 return o << ev.u.llval << "LL"; 00459 case AST_Expression::EV_ulonglong: 00460 return o << ev.u.ullval << "ULL"; 00461 case AST_Expression::EV_wchar: 00462 return o << "L'" << static_cast<char>(ev.u.wcval) << '\''; 00463 case AST_Expression::EV_char: 00464 return o << '\'' << ev.u.cval << '\''; 00465 case AST_Expression::EV_bool: 00466 return o << std::boolalpha << static_cast<bool>(ev.u.bval); 00467 case AST_Expression::EV_float: 00468 return o << ev.u.fval << 'f'; 00469 case AST_Expression::EV_double: 00470 return o << ev.u.dval; 00471 case AST_Expression::EV_wstring: 00472 return o << "L\"" << ev.u.wstrval << '"'; 00473 case AST_Expression::EV_string: 00474 return o << '"' << ev.u.strval->get_string() << '"'; 00475 #ifdef ACE_HAS_CDR_FIXED 00476 case AST_Expression::EV_fixed: 00477 { 00478 char buf[ACE_CDR::Fixed::MAX_STRING_SIZE]; 00479 ev.u.fixedval.to_string(buf, sizeof buf); 00480 return o << "\"" << buf << "\""; 00481 } 00482 #endif 00483 default: 00484 return o; 00485 } 00486 }
std::string scoped | ( | UTL_ScopedName * | sn | ) | [inline] |
Definition at line 218 of file dds_generator.h.
References dds_generator::scoped_helper().
Referenced by assign_field(), builtInSeq(), delegateToNested(), findSizeCommon(), func(), wireshark_generator::gen_array(), gen_array(), gen_array_traits(), langmap_generator::gen_const(), marshal_generator::gen_enum(), gen_field_createQC(), gen_sequence(), v8_generator::gen_struct(), ts_generator::gen_struct(), metaclass_generator::gen_struct(), marshal_generator::gen_struct(), keys_generator::gen_struct(), wireshark_generator::gen_typedef(), v8_generator::gen_typedef(), metaclass_generator::gen_typedef(), wireshark_generator::gen_union(), ts_generator::gen_union(), metaclass_generator::gen_union(), marshal_generator::gen_union(), GeneratorBase::gen_union(), face_ts_generator::generate(), java_ts_generator::generate(), generateCaseBody(), GeneratorBase::generateDefaultValue(), getEnumLabel(), getMaxSizeExprPrimitive(), map_type(), streamCommon(), to_cxx_type(), write_branch(), and write_field().
00219 { 00220 return dds_generator::scoped_helper(sn, "::"); 00221 }
std::string wrapPrefix | ( | AST_Type * | type, | |
WrapDirection | wd | |||
) | [inline] |
Definition at line 378 of file dds_generator.h.
References WD_OUTPUT.
Referenced by getWrapper().
00379 { 00380 switch (type->node_type()) { 00381 case AST_Decl::NT_pre_defined: 00382 { 00383 AST_PredefinedType* p = AST_PredefinedType::narrow_from_decl(type); 00384 switch (p->pt()) { 00385 case AST_PredefinedType::PT_char: 00386 return (wd == WD_OUTPUT) 00387 ? "ACE_OutputCDR::from_char(" : "ACE_InputCDR::to_char("; 00388 case AST_PredefinedType::PT_wchar: 00389 return (wd == WD_OUTPUT) 00390 ? "ACE_OutputCDR::from_wchar(" : "ACE_InputCDR::to_wchar("; 00391 case AST_PredefinedType::PT_octet: 00392 return (wd == WD_OUTPUT) 00393 ? "ACE_OutputCDR::from_octet(" : "ACE_InputCDR::to_octet("; 00394 case AST_PredefinedType::PT_boolean: 00395 return (wd == WD_OUTPUT) 00396 ? "ACE_OutputCDR::from_boolean(" : "ACE_InputCDR::to_boolean("; 00397 default: 00398 return ""; 00399 } 00400 } 00401 case AST_Decl::NT_string: 00402 return (wd == WD_OUTPUT) 00403 ? "ACE_OutputCDR::from_string(" : "ACE_InputCDR::to_string("; 00404 case AST_Decl::NT_wstring: 00405 return (wd == WD_OUTPUT) 00406 ? "ACE_OutputCDR::from_wstring(" : "ACE_InputCDR::to_wstring("; 00407 default: 00408 return ""; 00409 } 00410 }