6 #ifndef dds_generator_H 7 #define dds_generator_H 14 #include <utl_scoped_name.h> 15 #include <utl_identifier.h> 16 #include <utl_string.h> 18 #include <ast_component_fwd.h> 19 #include <ast_eventtype_fwd.h> 20 #include <ast_structure_fwd.h> 21 #include <ast_union_fwd.h> 22 #include <ast_valuetype_fwd.h> 52 static std::string
get_tag_name(
const std::string& base_name,
const std::string& qualifier =
"");
71 virtual bool gen_enum(AST_Enum* , UTL_ScopedName* ,
72 const std::vector<AST_EnumVal*>& ,
76 virtual bool gen_struct(AST_Structure* node, UTL_ScopedName* name,
77 const std::vector<AST_Field*>& fields,
78 AST_Type::SIZE_TYPE size,
79 const char* repoid) = 0;
85 virtual bool gen_typedef(AST_Typedef* node, UTL_ScopedName* name, AST_Type* base,
86 const char* repoid) = 0;
88 virtual bool gen_interf(AST_Interface* , UTL_ScopedName* ,
bool ,
89 const std::vector<AST_Interface*>& ,
90 const std::vector<AST_Interface*>& ,
91 const std::vector<AST_Attribute*>& ,
92 const std::vector<AST_Operation*>& ,
99 virtual bool gen_native(AST_Native* , UTL_ScopedName* ,
const char* )
102 virtual bool gen_union(AST_Union* node, UTL_ScopedName* name,
103 const std::vector<AST_UnionBranch*>& branches,
104 AST_Type* discriminator,
105 const char* repoid) = 0;
108 AST_Type::SIZE_TYPE )
142 AST_Constant* constant);
144 bool gen_enum(AST_Enum* node, UTL_ScopedName* name,
145 const std::vector<AST_EnumVal*>& contents,
const char* repoid);
147 bool gen_struct(AST_Structure* node, UTL_ScopedName* name,
148 const std::vector<AST_Field*>& fields,
149 AST_Type::SIZE_TYPE size,
const char* repoid);
151 bool gen_struct_fwd(UTL_ScopedName* name, AST_Type::SIZE_TYPE size);
153 bool gen_typedef(AST_Typedef* node, UTL_ScopedName* name, AST_Type* base,
const char* repoid);
155 bool gen_interf(AST_Interface* node, UTL_ScopedName* name,
bool local,
156 const std::vector<AST_Interface*>& inherits,
157 const std::vector<AST_Interface*>& inherits_flat,
158 const std::vector<AST_Attribute*>& attrs,
159 const std::vector<AST_Operation*>& ops,
const char* repoid);
163 bool gen_native(AST_Native* node, UTL_ScopedName* name,
const char* repoid);
165 bool gen_union(AST_Union* node, UTL_ScopedName* name,
166 const std::vector<AST_UnionBranch*>& branches,
167 AST_Type* discriminator,
170 bool gen_union_fwd(AST_UnionFwd*, UTL_ScopedName* name, AST_Type::SIZE_TYPE size);
174 template <
typename InputIterator>
176 : components_(begin, end) {}
188 std::vector<std::string>*
ns_;
196 default_ns_.push_back(
"OpenDDS");
197 default_ns_.push_back(
"DCPS");
201 std::string start_ns =
"OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL\n";
202 for (
size_t i = 0; i < ns_->size(); ++i) {
206 start_ns +=
"namespace " + (*ns_)[i] +
" {";
218 for (
size_t i = 0; i < ns_->size(); ++i) {
224 end_ns +=
"\nOPENDDS_END_VERSIONED_NAMESPACE_DECL\n\n";
233 const char* keyword =
"namespace")
238 const bool idl = !std::strcmp(keyword,
"module");
240 for (n_ = 0; name->tail();
241 name =
static_cast<UTL_ScopedName*
>(name->tail())) {
242 const char* str = name->head()->get_string();
248 if (idl) semi_ =
";";
253 for (
int i = 0; i < n_; ++i)
os_ <<
'}' << semi_ <<
'\n';
267 const char* template_args = 0)
269 , extra_newline_(true)
273 const string tmpl = string(
"template<") + template_args +
"> ";
278 bool use_exp = ace_exporter !=
"";
279 string exporter = use_exp ? (string(
" ") + ace_exporter.
c_str()) :
"";
280 be_global->header_ << ace_exporter << (use_exp ?
"\n" :
"")
281 << returntype <<
" " << name <<
"(";
282 be_global->impl_ << returntype <<
" " << name <<
"(";
287 std::string sig = (has_arg_ ?
", " :
"") + type + (name[0] ?
" " :
"")
288 + (name[0] ?
name :
"");
292 preamble_ +=
" ACE_UNUSED_ARG(" + std::string(name) +
");\n";
300 be_global->impl_ <<
")\n{\n" << preamble_;
306 if (extra_newline_) {
315 const std::string& what,
316 bool impl =
true,
bool header =
true,
317 const std::string& indent =
"")
322 , extra_newline_(true)
324 output(
"#" + indent +
"if" + what +
"\n");
329 output(
"#" + indent_ +
"endif // if" + what_ +
"\n");
330 if (extra_newline_) {
335 void output(
const std::string& str)
const 347 extra_newline_ =
value;
375 if (element->node_type() == AST_Decl::NT_typedef) {
376 AST_Typedef* td =
dynamic_cast<AST_Typedef*
>(element);
377 return td->primitive_base_type();
380 switch(element->node_type()) {
381 case AST_Decl::NT_interface_fwd:
383 AST_InterfaceFwd* td =
dynamic_cast<AST_InterfaceFwd*
>(element);
384 return td->full_definition();
386 case AST_Decl::NT_valuetype_fwd:
388 AST_ValueTypeFwd* td =
dynamic_cast<AST_ValueTypeFwd*
>(element);
389 return td->full_definition();
391 case AST_Decl::NT_union_fwd:
393 AST_UnionFwd* td =
dynamic_cast<AST_UnionFwd*
>(element);
394 return td->full_definition();
396 case AST_Decl::NT_struct_fwd:
398 AST_StructureFwd* td =
dynamic_cast<AST_StructureFwd*
>(element);
399 return td->full_definition();
401 case AST_Decl::NT_component_fwd:
403 AST_ComponentFwd* td =
dynamic_cast<AST_ComponentFwd*
>(element);
404 return td->full_definition();
406 case AST_Decl::NT_eventtype_fwd:
408 AST_EventTypeFwd* td =
dynamic_cast<AST_EventTypeFwd*
>(element);
409 return td->full_definition();
425 switch (type->node_type()) {
426 case AST_Decl::NT_pre_defined: {
427 AST_PredefinedType* p =
dynamic_cast<AST_PredefinedType*
>(type);
429 case AST_PredefinedType::PT_any:
430 case AST_PredefinedType::PT_object:
432 case AST_PredefinedType::PT_wchar:
438 case AST_Decl::NT_array:
440 case AST_Decl::NT_union:
442 case AST_Decl::NT_string:
443 case AST_Decl::NT_wstring:
445 ((
dynamic_cast<AST_String*
>(type)->max_size()->ev()->u.ulval == 0)
447 ((type->node_type() == AST_Decl::NT_wstring) ?
CL_WIDE : 0);
448 case AST_Decl::NT_sequence:
450 ((
dynamic_cast<AST_Sequence*
>(type)->unbounded()) ? 0 :
CL_BOUNDED);
451 case AST_Decl::NT_struct:
453 case AST_Decl::NT_enum:
455 case AST_Decl::NT_interface:
457 #ifdef ACE_HAS_CDR_FIXED 458 case AST_Decl::NT_fixed:
468 NestedForLoops(
const char* type,
const char* prefix, AST_Array* arr,
469 std::string& indent,
bool followTypedefs =
false);
482 switch (type->node_type()) {
483 case AST_Decl::NT_pre_defined: {
484 AST_PredefinedType*
const p =
dynamic_cast<AST_PredefinedType*
>(type);
486 case AST_PredefinedType::PT_char:
488 ?
"ACE_OutputCDR::from_char(" :
"ACE_InputCDR::to_char(";
489 case AST_PredefinedType::PT_wchar:
491 ?
"ACE_OutputCDR::from_wchar(" :
"ACE_InputCDR::to_wchar(";
492 case AST_PredefinedType::PT_octet:
494 ?
"ACE_OutputCDR::from_octet(" :
"ACE_InputCDR::to_octet(";
495 case AST_PredefinedType::PT_boolean:
497 ?
"ACE_OutputCDR::from_boolean(" :
"ACE_InputCDR::to_boolean(";
498 #if OPENDDS_HAS_EXPLICIT_INTS 499 case AST_PredefinedType::PT_uint8:
501 ?
"ACE_OutputCDR::from_uint8(" :
"ACE_InputCDR::to_uint8(";
502 case AST_PredefinedType::PT_int8:
504 ?
"ACE_OutputCDR::from_int8(" :
"ACE_InputCDR::to_int8(";
510 case AST_Decl::NT_string:
512 ?
"ACE_OutputCDR::from_string(" :
"ACE_InputCDR::to_string(";
513 case AST_Decl::NT_wstring:
515 ?
"ACE_OutputCDR::from_wstring(" :
"ACE_InputCDR::to_wstring(";
523 return be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11 ?
533 return "ACE_CDR::ULong";
540 AST_PredefinedType* p =
dynamic_cast<AST_PredefinedType*
>(t);
542 case AST_PredefinedType::PT_long:
544 return "ACE_CDR::Long";
545 case AST_PredefinedType::PT_ulong:
547 return "ACE_CDR::ULong";
548 case AST_PredefinedType::PT_longlong:
550 return "ACE_CDR::LongLong";
551 case AST_PredefinedType::PT_ulonglong:
553 return "ACE_CDR::ULongLong";
554 case AST_PredefinedType::PT_short:
556 return "ACE_CDR::Short";
557 case AST_PredefinedType::PT_ushort:
559 return "ACE_CDR::UShort";
560 #if OPENDDS_HAS_EXPLICIT_INTS 561 case AST_PredefinedType::PT_int8:
563 return "ACE_CDR::Int8";
564 case AST_PredefinedType::PT_uint8:
566 return "ACE_CDR::UInt8";
568 case AST_PredefinedType::PT_float:
570 return "ACE_CDR::Float";
571 case AST_PredefinedType::PT_double:
573 return "ACE_CDR::Double";
574 case AST_PredefinedType::PT_longdouble:
576 return "ACE_CDR::LongDouble";
577 case AST_PredefinedType::PT_char:
579 return "ACE_CDR::Char";
580 case AST_PredefinedType::PT_wchar:
582 return "ACE_CDR::WChar";
583 case AST_PredefinedType::PT_boolean:
585 return "ACE_CDR::Boolean";
586 case AST_PredefinedType::PT_octet:
588 return "ACE_CDR::Octet";
589 case AST_PredefinedType::PT_any:
590 case AST_PredefinedType::PT_object:
591 case AST_PredefinedType::PT_value:
592 case AST_PredefinedType::PT_abstract:
593 case AST_PredefinedType::PT_void:
594 case AST_PredefinedType::PT_pseudo:
599 return scoped(type->name());
606 if (
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
609 return (wd ==
WD_OUTPUT ?
"Serializer::FromBoundedString" :
"Serializer::ToBoundedString")
610 + std::string(cls &
CL_WIDE ?
"<wchar_t>(" :
"<char>(") + name +
')';
614 return (pre.empty()) ? name : (pre + name +
')');
620 std::string e =
scoped(disc->name()),
621 label = label_val->n()->last_component()->get_string();
622 if (
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
623 return e +
"::" + label;
625 const size_t colon = e.rfind(
"::");
626 if (colon == std::string::npos) {
629 return e.replace(colon + 2, std::string::npos, label);
634 const AST_Expression::AST_ExprValue& ev)
639 case AST_Expression::EV_octet:
640 return hex_value(o <<
"0x", static_cast<int>(ev.u.oval), 1);
641 #if OPENDDS_HAS_EXPLICIT_INTS 642 case AST_Expression::EV_int8:
643 return o << static_cast<short>(ev.u.int8val);
644 case AST_Expression::EV_uint8:
645 return o << static_cast<unsigned short>(ev.u.uint8val);
647 case AST_Expression::EV_short:
648 return o << ev.u.sval;
649 case AST_Expression::EV_ushort:
650 return o << ev.u.usval <<
'u';
651 case AST_Expression::EV_long:
652 return signed_int_helper<ACE_CDR::Long>(o, ev.u.lval,
ACE_INT32_MIN);
653 case AST_Expression::EV_ulong:
654 return o << ev.u.ulval <<
'u';
655 case AST_Expression::EV_longlong:
656 return signed_int_helper<ACE_CDR::LongLong>(o, ev.u.llval,
ACE_INT64_MIN) <<
"LL";
657 case AST_Expression::EV_ulonglong:
658 return o << ev.u.ullval <<
"ULL";
659 case AST_Expression::EV_wchar:
660 return char_helper<ACE_CDR::WChar>(o <<
"L'", ev.u.wcval) <<
'\'';
661 case AST_Expression::EV_char:
662 return char_helper<ACE_CDR::Char>(o <<
'\'', ev.u.cval) <<
'\'';
663 case AST_Expression::EV_bool:
664 return o << std::boolalpha << static_cast<bool>(ev.u.bval);
665 case AST_Expression::EV_float:
666 return o << ev.u.fval <<
'f';
667 case AST_Expression::EV_double:
668 return o << ev.u.dval;
669 case AST_Expression::EV_wstring:
670 return o <<
"L\"" << ev.u.wstrval <<
'"';
671 case AST_Expression::EV_string:
672 return o <<
'"' << ev.u.strval->get_string() <<
'"';
673 #ifdef ACE_HAS_CDR_FIXED 674 case AST_Expression::EV_fixed: {
676 ev.u.fixedval.to_string(buf,
sizeof buf);
677 return o <<
"\"" << buf <<
"\"";
680 case AST_Expression::EV_enum:
681 case AST_Expression::EV_longdouble:
682 case AST_Expression::EV_any:
683 case AST_Expression::EV_object:
684 case AST_Expression::EV_void:
685 case AST_Expression::EV_none:
687 "Unsupported ExprType value in operator<<(std::ostream, AST_ExprValue)");
690 "Unhandled ExprType value in operator<<(std::ostream, AST_ExprValue)");
697 std::ostringstream arg;
700 AST_String*
const str =
dynamic_cast<AST_String*
>(type);
701 arg << str->max_size()->ev()->u.ulval;
703 AST_Sequence*
const seq =
dynamic_cast<AST_Sequence*
>(type);
704 arg << seq->max_size()->ev()->u.ulval;
710 const std::string&
name,
bool is_anonymous =
false,
bool is_union =
false);
714 size_t& n_labels,
bool& has_default)
716 for (
unsigned long j = 0; j < branch->label_list_length(); ++j) {
718 AST_UnionLabel* label = branch->label(j);
719 if (label->label_kind() == AST_UnionLabel::UL_default) {
722 }
else if (discriminator->node_type() == AST_Decl::NT_enum) {
724 <<
getEnumLabel(label->label_val(), discriminator) <<
':';
726 be_global->impl_ <<
" case " << *label->label_val()->ev() <<
':';
728 be_global->impl_<< ((j == branch->label_list_length() - 1) ?
" {\n" :
"\n");
735 AST_Decl::NodeType nt = disc->node_type();
736 if (nt == AST_Decl::NT_enum)
return true;
738 AST_PredefinedType* pdt =
dynamic_cast<AST_PredefinedType*
>(disc);
740 case AST_PredefinedType::PT_boolean:
742 #if OPENDDS_HAS_EXPLICIT_INTS 743 case AST_PredefinedType::PT_int8:
744 case AST_PredefinedType::PT_uint8:
746 case AST_PredefinedType::PT_char:
747 case AST_PredefinedType::PT_octet:
749 case AST_PredefinedType::PT_short:
750 case AST_PredefinedType::PT_ushort:
751 case AST_PredefinedType::PT_wchar:
753 case AST_PredefinedType::PT_long:
754 case AST_PredefinedType::PT_ulong:
767 void join(std::ostream& os,
const std::string& indent)
769 for (LineVec::iterator i = line_vec.begin(); i != line_vec.end(); ++i) {
770 os << indent << *i <<
'\n';
776 if (line_set.insert(line).second) {
777 line_vec.push_back(line);
783 for (LineVec::const_iterator i = other.
line_vec.begin(); i != other.
line_vec.end(); ++i) {
789 std::string
field_type_name(AST_Field* field, AST_Type* field_type = 0);
800 const std::string& indent, AST_Decl* node,
801 const std::string&
name, AST_Type* type,
802 const std::string& prefix,
bool wrap_nested_key_only,
Intro& intro,
808 AST_UnionBranch* branch,
809 const char* statementPrefix,
const char* namePrefix,
const char* uni,
bool generateBreaks,
bool parens)
812 const BE_GlobalData::LanguageMapping lmap =
be_global->language_mapping();
813 const bool use_cxx11 = lmap == BE_GlobalData::LANGMAP_CXX11;
814 const std::string
name = branch->local_name()->get_string();
815 if (namePrefix == std::string(
">> ")) {
820 if (!br->in_main_file()
821 && br->node_type() != AST_Decl::NT_pre_defined) {
822 be_global->add_referenced(br->file_name().c_str());
826 const bool is_face = lmap == BE_GlobalData::LANGMAP_FACE_CXX;
827 const bool is_wide = br_cls &
CL_WIDE;
829 const std::string bound_string_suffix = (is_bound_string && !is_face) ?
".c_str()" :
"";
831 if (is_bound_string) {
832 const std::string to_type = is_face ? is_wide ?
"ACE_InputCDR::to_wstring" :
"ACE_InputCDR::to_string" 833 : is_wide ?
"Serializer::ToBoundedString<wchar_t>" :
"Serializer::ToBoundedString<char>";
834 const std::string face_suffix = is_face ?
".out()" :
"";
835 brType = is_face ? is_wide ?
"FACE::WString_var" :
"FACE::String_var" 836 : is_wide ?
"OPENDDS_WSTRING" :
"OPENDDS_STRING";
837 rhs = to_type +
"(tmp" + face_suffix +
", " +
bounded_arg(br) +
")";
839 const std::string nmspace = is_face ?
"FACE::" :
"CORBA::";
840 brType = use_cxx11 ? std::string(
"std::") + (is_wide ?
"w" :
"") +
"string" 841 : nmspace + (is_wide ?
"W" :
"") +
"String_var";
842 rhs = use_cxx11 ?
"tmp" :
"tmp.out()";
844 rhs =
"IDL::DistinctType<" + brType +
", " 848 forany =
" " + brType +
"_forany fa = tmp;\n";
854 if (*statementPrefix) {
858 " " << brType <<
" tmp;\n" << forany <<
859 " if (strm >> " << rhs <<
") {\n" 860 " uni." << name << (use_cxx11 ?
"(std::move(tmp));\n" :
"(tmp" + bound_string_suffix +
");\n") <<
868 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n" 872 if (is_bound_string) {
873 const std::string check_not_empty =
"!tmp.empty()";
874 const std::string get_length = use_cxx11 ?
"tmp.length()" :
"ACE_OS::strlen(tmp.c_str())";
875 const std::string inout = use_cxx11 ?
"" :
".inout()";
876 const std::string strtype = br_cls & CL_WIDE ?
"std::wstring" :
"std::string";
878 " if (strm.get_construction_status() == Serializer::BoundConstructionFailure && " << check_not_empty <<
" && (" 879 <<
bounded_arg(br) <<
" < " << get_length <<
")) {\n" 880 " " << strtype <<
" s = tmp.c_str();\n" 882 " uni." << name <<
"(s.c_str());\n" 883 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n" 886 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n" 891 " if(strm.get_construction_status() == Serializer::ElementConstructionFailure) {\n" 894 " uni." << name << (use_cxx11 ?
"(std::move(tmp));\n" :
"(tmp);\n") <<
896 " strm.set_construction_status(Serializer::ConstructionSuccessful);\n" 902 " strm.set_construction_status(Serializer::ElementConstructionFailure);\n" 906 const char* breakString = generateBreaks ?
" break;\n" :
"";
907 const std::string indent =
" ";
909 std::ostringstream contents;
913 << commonFn2(indent, branch, name + (parens ?
"()" :
""), branch->field_type(),
"uni",
false, intro,
"")
914 << indent <<
"if (!strm.write_parameter_id(" <<
id <<
", size)) {\n" 915 << indent <<
" return false;\n" 918 const std::string expr = commonFn(indent, branch,
919 name + (parens ?
"()" :
""), branch->field_type(),
920 std::string(namePrefix) +
"uni",
false, intro, uni);
921 if (*statementPrefix) {
923 indent << statementPrefix <<
" " << expr <<
";\n" <<
924 (statementPrefix == std::string(
"return") ?
"" : breakString);
926 contents << expr << breakString;
935 const std::vector<AST_UnionBranch*>& branches,
936 AST_Type* discriminator,
const char* statementPrefix,
937 const char* namePrefix =
"",
const char* uni =
"",
938 bool forceDisableDefault =
false,
bool parens =
true,
939 bool breaks =
true,
CommonFn commonFn2 = 0)
942 bool has_default =
false;
943 for (
size_t i = 0; i < branches.size(); ++i) {
944 AST_UnionBranch* branch = branches[i];
945 if (forceDisableDefault) {
946 bool foundDefault =
false;
947 for (
unsigned long j = 0; j < branch->label_list_length(); ++j) {
948 if (branch->label(j)->label_kind() == AST_UnionLabel::UL_default) {
959 uni, breaks, parens);
966 ((namePrefix == std::string(
">> ")) ?
" uni._d(disc);\n" :
"") <<
976 const std::vector<AST_UnionBranch*>& branches,
977 AST_Type* discriminator,
const char* statementPrefix,
978 const char* namePrefix =
"",
const char* uni =
"",
979 bool forceDisableDefault =
false,
bool parens =
true,
980 bool breaks =
true,
CommonFn commonFn2 = 0)
984 AST_PredefinedType* bt =
dynamic_cast<AST_PredefinedType*
>(dt);
985 if (bt && bt->pt() == AST_PredefinedType::PT_boolean) {
986 AST_UnionBranch* true_branch = 0;
987 AST_UnionBranch* false_branch = 0;
988 AST_UnionBranch* default_branch = 0;
989 for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(),
990 limit = branches.end(); pos != limit; ++pos) {
991 AST_UnionBranch* branch = *pos;
992 for (
unsigned long j = 0; j < branch->label_list_length(); ++j) {
993 AST_UnionLabel* label = branch->label(j);
994 if (label->label_kind() == AST_UnionLabel::UL_default) {
995 default_branch = branch;
996 }
else if (label->label_val()->ev()->u.bval) {
997 true_branch = branch;
998 }
else if (!label->label_val()->ev()->u.bval) {
999 false_branch = branch;
1004 if (true_branch || false_branch) {
1006 " if (" << switchExpr <<
") {\n";
1012 if (true_branch || default_branch) {
1013 generateCaseBody(commonFn, commonFn2, true_branch ? true_branch : default_branch,
1014 statementPrefix, namePrefix, uni,
false, parens);
1017 if (false_branch || (default_branch && true_branch)) {
1020 generateCaseBody(commonFn, commonFn2, false_branch ? false_branch : default_branch,
1021 statementPrefix, namePrefix, uni,
false, parens);
1027 return !default_branch && bool(true_branch) != bool(false_branch);
1031 " switch (" << switchExpr <<
") {\n";
1033 statementPrefix, namePrefix, uni,
1034 forceDisableDefault, parens, breaks,
1044 const std::string& full_var_name_,
bool is_union_member =
false)
1046 const bool use_cxx11 =
be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
1047 if (!use_cxx11 || is_union_member || full_var_name_.empty()) {
1048 return full_var_name_;
1051 std::string full_var_name(full_var_name_);
1052 std::string::size_type n = 0;
1053 while ((n = full_var_name.find(
'.', n)) != std::string::npos) {
1054 if (full_var_name[n-1] !=
']') {
1055 full_var_name.insert(n,
"()");
1062 while ((n = full_var_name.find(
'[', n)) != std::string::npos) {
1063 full_var_name.insert(n,
"()");
1066 return full_var_name[full_var_name.size() - 1] ==
']' 1067 ? full_var_name : full_var_name +
"()";
1079 if (!struct_node || index >= struct_node->nfields()) {
1082 AST_Field** field_ptrptr;
1083 struct_node->field(field_ptrptr, index);
1084 return field_ptrptr ? *field_ptrptr : 0;
1090 for (
unsigned i = 0; i < node->nfields(); ++i) {
1110 explicit Iterator(AST_Structure* node = 0,
unsigned pos = 0,
bool explicit_keys_only =
false)
1113 , explicit_keys_only_(explicit_keys_only)
1120 return node_ && pos_ < node_->nfields();
1136 for (; check() && explicit_keys_only_ && !
be_global->is_key(**
this); ++pos_) {
1166 return node_ == other.
node_ 1167 && pos_ == other.
pos_ 1173 return !(*
this == other);
1184 , explicit_keys_only_(explicit_keys_only(node, filter))
1201 return Iterator(node_, 0, explicit_keys_only_);
1225 count *= arr->dims()[i]->ev()->u.ulval;
1234 AST_Sequence*
const seq =
dynamic_cast<AST_Sequence*
>(act);
1235 AST_Array*
const arr =
dynamic_cast<AST_Array*
>(act);
1236 if (seq && !seq->unbounded()) {
1237 return seq->max_size()->ev()->u.ulval;
1248 AST_Sequence*
const seq =
dynamic_cast<AST_Sequence*
>(act);
1249 AST_Array*
const arr =
dynamic_cast<AST_Array*
>(act);
1251 return seq->base_type();
1253 return arr->base_type();
1264 AST_Type*
const non_aliased_type = type;
1268 static std::vector<AST_Type*> type_stack;
1271 for (
size_t i = 0; i < type_stack.size(); ++i) {
1272 if (type == type_stack[i]) {
1276 type_stack.push_back(type);
1278 bool result =
false;
1279 const std::string
name =
scoped(type->name());
1281 std::string template_name;
1282 if (
be_global->special_serialization(non_aliased_type, template_name)) {
1291 AST_Structure*
const struct_node =
dynamic_cast<AST_Structure*
>(type);
1297 const Fields fields(struct_node);
1306 }
else if (type_class &
CL_UNION) {
1312 type_stack.pop_back();
1320 return be_global->language_mapping() != BE_GlobalData::LANGMAP_CXX11 &&
1328 return be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11 &&
1337 const size_t shift_len = 3;
1339 if (rv.size() > shift_len) {
1340 const std::string first3 = rv.substr(0, shift_len);
1350 const size_t shift_len = 3;
1351 if (s.size() > shift_len) {
1352 const std::string first3 = s.substr(0, shift_len);
1381 const std::string& to_wrap,
bool is_const =
true)
1384 , type_name_(type_name)
1387 , is_const_(is_const)
1388 , nested_key_only_(false)
1389 , classic_array_copy_(false)
1390 , dynamic_data_adapter_(false)
1397 const std::string& fieldref,
const std::string& local,
bool is_const =
true)
1400 , type_name_(type_name)
1404 , is_const_(is_const)
1405 , nested_key_only_(false)
1406 , classic_array_copy_(false)
1407 , dynamic_data_adapter_(false)
1417 if (is_const_ && !std::strcmp(shift_op_,
shift_in)) {
1420 const std::string const_str = is_const_ ?
"const " :
"";
1421 const bool forany = classic_array_copy_ ||
needs_forany(type_);
1423 needs_dda_tag_ = dynamic_data_adapter_ && (forany || distinct_type);
1424 nested_key_only_ = nested_key_only_ &&
1426 wrapped_type_name_ = type_name_;
1429 if (to_wrap_.size()) {
1433 if (local_.size()) {
1434 ref_ +=
'.' + local_;
1438 if (forany && !dynamic_data_adapter_) {
1439 const std::string forany_type = type_name_ +
"_forany";
1440 if (classic_array_copy_) {
1442 classic_array_copy_var_ = var_name;
1444 intro->insert(type_name_ +
"_var " + var_name +
"= " + type_name_ +
"_alloc();");
1449 wrapped_type_name_ = forany_type;
1451 std::string line = forany_type +
" " + var_name;
1452 if (classic_array_copy_) {
1453 line +=
" = " + ref_ +
".inout();";
1455 line +=
"(const_cast<" + type_name_ +
"_slice*>(" + ref_ +
"));";
1457 intro->insert(line);
1462 if (nested_key_only_) {
1463 wrapped_type_name_ =
1464 std::string(
"NestedKeyOnly<") + const_str + wrapped_type_name_ +
">";
1465 value_access_post_ =
".value" + value_access_post_;
1466 const std::string nko_arg =
"(" + ref_ +
")";
1468 ref_ = wrapped_type_name_ + nko_arg;
1472 intro->insert(wrapped_type_name_ +
" " + ref_ + nko_arg +
";");
1477 if (distinct_type && !dynamic_data_adapter_) {
1478 wrapped_type_name_ =
1479 std::string(
"IDL::DistinctType<") + const_str + wrapped_type_name_ +
1480 ", " + get_tag_name_i() +
">";
1481 value_access_pre_ +=
"(*";
1482 value_access_post_ =
".val_)" + value_access_post_;
1483 const std::string idt_arg =
"(" + ref_ +
")";
1485 ref_ = wrapped_type_name_ + idt_arg;
1489 intro->insert(wrapped_type_name_ +
" " + ref_ + idt_arg +
";");
1495 wrapped_type_name_ = const_str + wrapped_type_name_ + (by_ref ?
"&" :
"");
1509 return wrapped_type_name_;
1515 return needs_dda_tag_;
1520 if (cpp11_ || needs_dda_tag_) {
1528 return get_tag_name_i();
1533 return var_name.size() ? var_name : to_wrap_;
1538 return value_access_pre_ + get_var_name(var_name) + value_access_post_;
1543 return value_access() + (cpp11_ ?
".empty()" :
".length() == 0");
1548 const std::string
value = value_access();
1549 return cpp11_ ?
"static_cast<uint32_t>(" + value +
".size())" : value +
".length()";
1554 const std::string
value = value_access();
1555 return value + (cpp11_ ?
".resize" :
".length") +
"(" + new_size +
");\n";
1560 return value_access() + (cpp11_ ?
".data()" :
".get_buffer()");
1565 AST_Array*
const array_node =
dynamic_cast<AST_Array*
>(type_);
1568 ref =
"(&" + value_access();
1574 ref = value_access();
1576 return ref +=
"[" + index +
"]";
1581 return shift_op_ +
ref();
1586 return type_name_ +
"_copy(" + to_wrap_ +
", " + classic_array_copy_var_ +
".in());";
1599 std::string qualifier;
1600 if (nested_key_only_) {
1601 qualifier =
"_nested_key_only";
1602 }
else if (needs_dda_tag_) {
std::string bounded_arg(AST_Type *type)
std::string to_cxx_type(AST_Type *type, std::size_t &size)
std::string type_to_default(const std::string &indent, AST_Type *type, const std::string &name, bool is_anonymous=false, bool is_union=false)
Classification classify(AST_Type *type)
virtual bool gen_typedef(AST_Typedef *node, UTL_ScopedName *name, AST_Type *base, const char *repoid)=0
void join(std::ostream &os, const std::string &indent)
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
const char * c_str(void) const
std::string field_type_name(AST_Field *field, AST_Type *field_type=0)
bool needs_forany(AST_Type *type)
std::string string_type(AstTypeClassification::Classification cls)
bool struct_has_explicit_keys(AST_Structure *node)
const LogLevel::Value value
const Classification CL_STRING
std::ostream & operator<<(std::ostream &o, const AST_Expression::AST_ExprValue &ev)
std::string get_tag_name() const
AST_Typedef * typedef_node_
const std::string type_name_
void output(const std::string &str) const
void insert(const std::string &line)
bool operator!=(const Iterator &other) const
ScopedNamespaceGuard(UTL_ScopedName *name, std::ostream &os, const char *keyword="namespace")
AST_Type * deepest_named_type(AST_Type *type)
const char *const shift_in
const Classification CL_SCALAR
void generateBranchLabels(AST_UnionBranch *branch, AST_Type *discriminator, size_t &n_labels, bool &has_default)
const Classification CL_WIDE
const bool explicit_keys_only_
std::string get_tag_name_i() const
virtual ~dds_generator()=0
const Classification CL_PRIMITIVE
static std::string get_xtag_name(UTL_ScopedName *name)
void generateCaseBody(CommonFn commonFn, CommonFn commonFn2, AST_UnionBranch *branch, const char *statementPrefix, const char *namePrefix, const char *uni, bool generateBreaks, bool parens)
std::string seq_get_length() const
virtual bool gen_interf_fwd(UTL_ScopedName *)
std::ostream & hex_value(std::ostream &o, unsigned value, size_t bytes)
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
std::string classic_array_copy_var_
std::string seq_get_buffer() const
std::string value_access_pre_
virtual bool gen_const(UTL_ScopedName *, bool, AST_Constant *)
static bool explicit_keys_only(AST_Structure *node, FieldFilter filter)
void extra_newline(bool value)
reference_wrapper< T > ref(T &r)
Iterator(AST_Structure *node=0, unsigned pos=0, bool explicit_keys_only=false)
std::string strip_shift_op(const std::string &s)
RefWrapper(AST_Type *type, const std::string &type_name, const std::string &to_wrap, bool is_const=true)
const Classification CL_BOUNDED
This is for everything else.
virtual bool gen_interf(AST_Interface *, UTL_ScopedName *, bool, const std::vector< AST_Interface *> &, const std::vector< AST_Interface *> &, const std::vector< AST_Attribute *> &, const std::vector< AST_Operation *> &, const char *)
std::string wrapped_type_name_
const std::string fieldref_
const Classification CL_ARRAY
void insert(const Intro &other)
static bool cxx_escaped(const std::string &s)
bool needSyntheticDefault(AST_Type *disc, size_t n_labels)
std::string get_var_name(const std::string &var_name) const
bool generateSwitchBody(AST_Union *, CommonFn commonFn, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const char *uni="", bool forceDisableDefault=false, bool parens=true, bool breaks=true, CommonFn commonFn2=0)
bool generateSwitchForUnion(AST_Union *u, const char *switchExpr, CommonFn commonFn, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const char *uni="", bool forceDisableDefault=false, bool parens=true, bool breaks=true, CommonFn commonFn2=0)
returns true if a default: branch was generated (no default: label in IDL)
std::string canonical_name(UTL_ScopedName *sn)
std::vector< std::string > * ns_
std::string getEnumLabel(AST_Expression *label_val, AST_Type *disc)
ACE_CDR::ULong container_element_limit(AST_Type *type)
Christopher Diggins *renamed files *fixing compilation errors *adding Visual C project file *removed make Max Lybbert *removed references to missing and unused header
std::string wrapped_type_name() const
virtual bool gen_enum(AST_Enum *, UTL_ScopedName *, const std::vector< AST_EnumVal *> &, const char *)
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)
Function(const std::string &name, const std::string returntype, const char *template_args=0)
std::string getWrapper(const std::string &name, AST_Type *type, WrapDirection wd)
static std::string valid_var_name(const std::string &str)
AST_Type * resolveActualType(AST_Type *element)
This is for generated IDL. (Like *TypeSupport.idl)
const Classification CL_UNKNOWN
virtual bool do_included_files() const
Fields(AST_Structure *node=0, FieldFilter filter=FieldFilter_All)
std::string classic_array_copy() const
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
std::string insert_cxx11_accessor_parens(const std::string &full_var_name_, bool is_union_member=false)
AST_Structure *const node_
static std::string module_scope_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
std::string seq_check_empty() const
std::string value_access(const std::string &var_name="") const
AST_Type * container_base_type(AST_Type *type)
const char *const shift_op_
NamespaceGuard(bool enabled=true, std::vector< std::string > *ns=0)
virtual bool gen_union_fwd(AST_UnionFwd *, UTL_ScopedName *, AST_Type::SIZE_TYPE)
AST_Structure * node() const
std::string flat_collection_access(std::string index) const
const Classification CL_FIXED
RefWrapper(AST_Type *type, const std::string &type_name, const std::string &fieldref, const std::string &local, bool is_const=true)
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
virtual bool gen_native(AST_Native *, UTL_ScopedName *, const char *)
std::string seq_resize(const std::string &new_size) const
std::vector< std::string > default_ns_
std::string stream() const
const Classification CL_STRUCTURE
const std::string to_wrap_
std::set< std::string > LineSet
void addArg(const char *name, const std::string &type)
void add_generator(dds_generator *gen)
std::vector< dds_generator * > components_
BE_GlobalData * be_global
std::string module_scope(UTL_ScopedName *sn)
ACE_CDR::ULong array_element_count(AST_Array *arr)
std::input_iterator_tag iterator_category
std::vector< std::string > LineVec
std::string(* CommonFn)(const std::string &indent, AST_Decl *node, const std::string &name, AST_Type *type, const std::string &prefix, bool wrap_nested_key_only, Intro &intro, const std::string &)
void generate_tag() const
bool needs_dda_tag() const
const char * get_shift_op(const std::string &s)
const Classification CL_INTERFACE
RefWrapper & done(Intro *intro=0)
bool dynamic_data_adapter_
const std::string indent_
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
virtual bool gen_struct_fwd(UTL_ScopedName *, AST_Type::SIZE_TYPE)
virtual bool gen_union(AST_Union *node, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *repoid)=0
Iterator operator[](unsigned position) const
int insert(Container &c, const ValueType &v)
AST_Field * operator*() const
virtual bool gen_struct(AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)=0
virtual void gen_prologue()
std::string value_access_post_
const Classification CL_ENUM
const char *const shift_out
const Classification CL_SEQUENCE
bool operator==(const Iterator &other) const
composite_generator(InputIterator begin, InputIterator end)
PreprocessorIfGuard(const std::string &what, bool impl=true, bool header=true, const std::string &indent="")
std::string wrapPrefix(AST_Type *type, WrapDirection wd)
bool needs_distinct_type(AST_Type *type)
bool needs_nested_key_only(AST_Type *type)
const Classification CL_UNION
AST_Field * get_struct_field(AST_Structure *struct_node, unsigned index)
virtual void gen_epilogue()