OpenDDS  Snapshot(2023/04/28-20:55)
langmap_generator.cpp
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #include "langmap_generator.h"
7 
8 #include "field_info.h"
9 #include "be_extern.h"
10 
11 #include <dds/DCPS/Definitions.h>
12 
13 #ifdef ACE_HAS_CDR_FIXED
14 # include <ast_fixed.h>
15 #endif
16 #include <utl_identifier.h>
17 
18 #include <ace/CDR_Base.h>
19 
20 #include <map>
21 #include <iostream>
22 
23 using namespace AstTypeClassification;
24 
25 struct GeneratorBase;
26 
27 namespace {
28  std::string string_ns = "::CORBA";
29 
30  GeneratorBase* generator_ = 0;
31 
32  std::map<AST_PredefinedType::PredefinedType, std::string> primtype_;
33 
34  enum Helper {
35  HLP_STR_VAR, HLP_STR_OUT, HLP_WSTR_VAR, HLP_WSTR_OUT,
36  HLP_STR_MGR, HLP_WSTR_MGR,
37  HLP_FIX_VAR, HLP_VAR_VAR, HLP_OUT,
38  HLP_SEQ, HLP_SEQ_NS, HLP_SEQ_VAR_VAR, HLP_SEQ_FIX_VAR, HLP_SEQ_OUT,
39  HLP_ARR_VAR_VAR, HLP_ARR_FIX_VAR, HLP_ARR_OUT, HLP_ARR_FORANY,
40  HLP_FIXED, HLP_FIXED_CONSTANT
41  };
42  std::map<Helper, std::string> helpers_;
43 
44  std::string exporter()
45  {
46  return be_global->export_macro().empty() ? ""
47  : be_global->export_macro().c_str() + std::string(" ");
48  }
49 
50  std::string array_zero_indices(AST_Array* arr)
51  {
52  std::string indices;
53  for (ACE_CDR::ULong i = 1; i < arr->n_dims(); ++i) {
54  indices += "[0]";
55  }
56  return indices;
57  }
58 
59  std::string array_dims(AST_Type* type, ACE_CDR::ULong& elems)
60  {
61  AST_Array* const arr = dynamic_cast<AST_Array*>(type);
62  std::string ret = array_zero_indices(arr);
63  elems *= array_element_count(arr);
64  AST_Type* base = resolveActualType(arr->base_type());
65  if (dynamic_cast<AST_Array*>(base)) {
66  ret += "[0]" + array_dims(base, elems);
67  }
68  return ret;
69  }
70 
71  void gen_typecode(UTL_ScopedName* name)
72  {
73  if (be_global->suppress_typecode() || be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
74  return;
75  }
76  const char* const nm = name->last_component()->get_string();
77  be_global->lang_header_ <<
78  "extern " << exporter() << "const ::CORBA::TypeCode_ptr _tc_" << nm
79  << ";\n";
80  const ScopedNamespaceGuard cppNs(name, be_global->impl_);
81  be_global->impl_ <<
82  "const ::CORBA::TypeCode_ptr _tc_" << nm << " = 0;\n";
83  }
84 
85 }
86 
88 {
89  virtual ~GeneratorBase() {}
90  virtual void init() = 0;
91  virtual void gen_sequence(UTL_ScopedName* tdname, AST_Sequence* seq) = 0;
92  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;
93 
94  virtual std::string const_keyword(AST_Expression::ExprType)
95  {
96  return "const";
97  }
98 
99  std::string map_type(AST_Type* type)
100  {
101  if (dynamic_cast<AST_Typedef*>(type)) {
102  return scoped(type->name());
103  }
104  const Classification cls = classify(type);
105  if (cls & CL_PRIMITIVE) {
106  AST_Type* actual = resolveActualType(type);
107  return primtype_[dynamic_cast<AST_PredefinedType*>(actual)->pt()];
108  }
109  if (cls & CL_STRING) {
110  const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE)
111  ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char;
112  return map_type_string(chartype, false);
113  }
114  if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_ARRAY | CL_ENUM | CL_FIXED)) {
115  return scoped(type->name());
116  }
117  if (cls & CL_INTERFACE) {
118  return scoped(type->name()) + "_var";
119  }
120  return "<<unknown>>";
121  }
122 
123  std::string map_type(AST_Field* field)
124  {
125  FieldInfo af(*field);
126  return (af.type_->anonymous() && af.as_base_) ? af.type_name_ : map_type(af.type_);
127  }
128 
129  virtual std::string map_type_string(AST_PredefinedType::PredefinedType chartype, bool constant)
130  {
131  return primtype_[chartype] + '*' + (constant ? " const" : "");
132  }
133 
134  std::string map_type(AST_Expression::ExprType type)
135  {
136  AST_PredefinedType::PredefinedType pt = AST_PredefinedType::PT_void;
137  switch (type) {
138 #if OPENDDS_HAS_EXPLICIT_INTS
139  case AST_Expression::EV_int8: pt = AST_PredefinedType::PT_int8; break;
140  case AST_Expression::EV_uint8: pt = AST_PredefinedType::PT_uint8; break;
141 #endif
142  case AST_Expression::EV_short: pt = AST_PredefinedType::PT_short; break;
143  case AST_Expression::EV_ushort: pt = AST_PredefinedType::PT_ushort; break;
144  case AST_Expression::EV_long: pt = AST_PredefinedType::PT_long; break;
145  case AST_Expression::EV_ulong: pt = AST_PredefinedType::PT_ulong; break;
146  case AST_Expression::EV_longlong: pt = AST_PredefinedType::PT_longlong; break;
147  case AST_Expression::EV_ulonglong: pt = AST_PredefinedType::PT_ulonglong; break;
148  case AST_Expression::EV_float: pt = AST_PredefinedType::PT_float; break;
149  case AST_Expression::EV_double: pt = AST_PredefinedType::PT_double; break;
150  case AST_Expression::EV_longdouble: pt = AST_PredefinedType::PT_longdouble; break;
151  case AST_Expression::EV_char: pt = AST_PredefinedType::PT_char; break;
152  case AST_Expression::EV_wchar: pt = AST_PredefinedType::PT_wchar; break;
153  case AST_Expression::EV_octet: pt = AST_PredefinedType::PT_octet; break;
154  case AST_Expression::EV_bool: pt = AST_PredefinedType::PT_boolean; break;
155  case AST_Expression::EV_string: pt = AST_PredefinedType::PT_char; break;
156  case AST_Expression::EV_wstring: pt = AST_PredefinedType::PT_wchar; break;
157 #ifdef ACE_HAS_CDR_FIXED
158  case AST_Expression::EV_fixed:
159  be_global->add_include("FACE/Fixed.h", BE_GlobalData::STREAM_LANG_H);
160  return helpers_[HLP_FIXED_CONSTANT];
161 #endif
162  default:
163  be_util::misc_error_and_abort("Unhandled ExprType value in map_type");
164  }
165 
166  if (type == AST_Expression::EV_string || type == AST_Expression::EV_wstring)
167  return map_type_string(pt, true);
168 
169  return primtype_[pt];
170  }
171 
172  virtual void gen_simple_out(const char* nm)
173  {
174  be_global->lang_header_ <<
175  "typedef " << nm << "& " << nm << "_out;\n";
176  }
177 
178  virtual bool scoped_enum() { return false; }
179  virtual std::string enum_base() { return ""; }
180 
181  virtual void struct_decls(UTL_ScopedName* name, AST_Type::SIZE_TYPE size, const char* struct_or_class = "struct")
182  {
183  be_global->add_include("<tao/VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
184  const char* const nm = name->last_component()->get_string();
185  be_global->lang_header_ <<
186  struct_or_class << ' ' << nm << ";\n";
187  switch (size) {
188  case AST_Type::SIZE_UNKNOWN:
189  be_global->lang_header_ << "/* Unknown size */\n";
190  break;
191  case AST_Type::FIXED:
192  be_global->lang_header_ <<
193  "typedef " << helpers_[HLP_FIX_VAR] << '<' << nm << "> " << nm << "_var;\n" <<
194  "typedef " << nm << "& " << nm << "_out;\n";
195  break;
196  case AST_Type::VARIABLE:
197  be_global->lang_header_ <<
198  "typedef " << helpers_[HLP_VAR_VAR] << '<' << nm << "> " << nm << "_var;\n" <<
199  "typedef " << helpers_[HLP_OUT] << '<' << nm << "> " << nm << "_out;\n";
200  break;
201  }
202  }
203 
204  static std::string generateDefaultValue(AST_Union* the_union)
205  {
206  std::stringstream first_label;
207  AST_Union::DefaultValue dv;
208  if (the_union->default_value(dv) == -1) {
210  ACE_TEXT("(%P|%t) ERROR: generateDefaultValue::")
211  ACE_TEXT(" computing default value failed\n")));
212  return "";
213  }
214 
215  switch (the_union->udisc_type ())
216  {
217 #if OPENDDS_HAS_EXPLICIT_INTS
218  case AST_Expression::EV_int8:
219  first_label << signed(dv.u.char_val);
220  break;
221  case AST_Expression::EV_uint8:
222  first_label << unsigned(dv.u.char_val);
223  break;
224 #endif
225  case AST_Expression::EV_short:
226  first_label << dv.u.short_val;
227  break;
228  case AST_Expression::EV_ushort:
229  first_label << dv.u.ushort_val;
230  break;
231  case AST_Expression::EV_long:
232  first_label << dv.u.long_val;
233  break;
234  case AST_Expression::EV_ulong:
235  first_label << dv.u.ulong_val;
236  break;
237  case AST_Expression::EV_char:
238  first_label << (int)dv.u.char_val;
239  break;
240  case AST_Expression::EV_bool:
241  first_label << (dv.u.bool_val == 0 ? "false" : "true");
242  break;
243  case AST_Expression::EV_enum:
244  {
245  AST_Enum* e = dynamic_cast<AST_Enum*>(the_union->disc_type());
246  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11 ||
247  be_global->language_mapping() == BE_GlobalData::LANGMAP_FACE_CXX) {
248  std::string prefix = scoped(e->name());
249  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_FACE_CXX) {
250  size_t pos = prefix.rfind("::");
251  if (pos == std::string::npos) {
252  prefix = "";
253  } else {
254  prefix = prefix.substr(0, pos) + "::";
255  }
256  } else {
257  prefix += "::";
258  }
259  first_label << prefix;
260  UTL_ScopedName* default_name;
261  if (dv.u.enum_val < static_cast<ACE_CDR::ULong>(e->member_count())) {
262  default_name = e->value_to_name(dv.u.enum_val);
263  } else {
264  const Fields fields(the_union);
265  AST_UnionBranch* ub = dynamic_cast<AST_UnionBranch*>(*(fields.begin()));
266  AST_Expression::AST_ExprValue* ev = ub->label(0)->label_val()->ev();
267  default_name = e->value_to_name(ev->u.eval);
268  }
269  first_label << default_name->last_component()->get_string();
270  } else {
271  first_label << scoped(e->value_to_name(dv.u.enum_val));
272  }
273  break;
274  }
275  case AST_Expression::EV_longlong:
276  first_label << dv.u.longlong_val;
277  break;
278  case AST_Expression::EV_ulonglong:
279  first_label << dv.u.ulonglong_val;
280  break;
281  default:
282  be_util::misc_error_and_abort("Unhandled ExprType value in generateDefaultValue");
283  }
284 
285  return first_label.str();
286  }
287 
289  {
290  AST_Union* the_union;
291  AST_Type* discriminator;
292 
293  GenerateUnionAccessors(AST_Union* u, AST_Type* d)
294  : the_union(u)
295  , discriminator(d)
296  { }
297 
298  void operator()(AST_UnionBranch* branch)
299  {
300  const char* field_name = branch->local_name()->get_string();
301  std::stringstream first_label;
302  {
303  AST_UnionLabel* label = branch->label(0);
304  if (label->label_kind() == AST_UnionLabel::UL_default) {
305  first_label << generateDefaultValue(the_union);
306  } else if (discriminator->node_type() == AST_Decl::NT_enum) {
307  first_label << getEnumLabel(label->label_val(), discriminator);
308  } else {
309  first_label << *label->label_val()->ev();
310  }
311  }
312 
313  AST_Type* field_type = branch->field_type();
314  const std::string field_type_string = generator_->map_type(field_type);
315  AST_Type* actual_field_type = resolveActualType(field_type);
316  const Classification cls = classify(actual_field_type);
317  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
318  be_global->lang_header_ <<
319  " void " << field_name << " (" << field_type_string << " x) {\n"
320  " _reset();\n"
321  " this->_u." << field_name << " = x;\n"
322  " _discriminator = " << first_label.str() << ";\n"
323  " }\n"
324  " " << field_type_string << ' ' << field_name << " () const {\n"
325  " return this->_u." << field_name << ";\n"
326  " }\n";
327  } else if (cls & CL_STRING) {
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];
330  be_global->lang_header_ <<
331  " void " << field_name << " (" << primtype << "* x) {\n"
332  " _reset();\n" <<
333  " this->_u." << field_name << " = x;\n"
334  " _discriminator = " << first_label.str() << ";\n"
335  " }\n"
336  " void " << field_name << " (const " << primtype << "* x) {\n"
337  " _reset();\n"
338  " this->_u." << field_name << " = " << string_ns << "::string_dup(x);\n"
339  " _discriminator = " << first_label.str() << ";\n"
340  " }\n"
341  " void " << field_name << " (const " << helper << "& x) {\n"
342  " _reset();\n" <<
343  " this->_u." << field_name << " = " << string_ns << "::string_dup(x.in());\n"
344  " _discriminator = " << first_label.str() << ";\n"
345  " }\n"
346  " const " << primtype << "* " << field_name << " () const {\n"
347  " return this->_u." << field_name << ";\n"
348  " }\n";
349  } else if (cls & CL_ARRAY) {
350  be_global->lang_header_ <<
351  " void " << field_name << " (" << field_type_string << " x) {\n"
352  " _reset();\n" <<
353  " this->_u." << field_name << " = " << field_type_string << "_dup(x);\n"
354  " _discriminator = " << first_label.str() << ";\n"
355  " }\n"
356  " " << field_type_string << "_slice* " << field_name << " () const {\n"
357  " return this->_u." << field_name << ";\n"
358  " }\n";
359  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
360  be_global->lang_header_ <<
361  " void " << field_name << " (const " << field_type_string << "& x) {\n"
362  " _reset();\n"
363  " this->_u." << field_name << " = new " << field_type_string << "(x);\n"
364  " _discriminator = " << first_label.str() << ";\n"
365  " }\n"
366  " const " << field_type_string << "& " << field_name << " () const {\n"
367  " return *this->_u." << field_name << ";\n"
368  " }\n"
369  " " << field_type_string << "& " << field_name << " () {\n"
370  " return *this->_u." << field_name << ";\n"
371  " }\n";
372  } else {
373  std::cerr << "Unsupported type for union element\n";
374  }
375  }
376  };
377 
378  static bool hasDefaultLabel (const std::vector<AST_UnionBranch*>& branches)
379  {
380  for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end();
381  pos != limit;
382  ++pos) {
383  AST_UnionBranch* branch = *pos;
384  for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
385  AST_UnionLabel* label = branch->label(j);
386  if (label->label_kind() == AST_UnionLabel::UL_default) {
387  return true;
388  }
389  }
390  }
391  return false;
392  }
393 
394  static size_t countLabels (const std::vector<AST_UnionBranch*>& branches)
395  {
396  size_t count = 0;
397 
398  for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end();
399  pos != limit;
400  ++pos) {
401  count += (*pos)->label_list_length();
402  }
403 
404  return count;
405  }
406 
407  static bool needsDefault (const std::vector<AST_UnionBranch*>& branches, AST_Type* discriminator)
408  {
409  return !hasDefaultLabel(branches) && needSyntheticDefault(discriminator, countLabels(branches));
410  }
411 
412  static void generate_union_field(AST_UnionBranch* branch)
413  {
414  AST_Type* field_type = branch->field_type();
415  AST_Type* actual_field_type = resolveActualType(field_type);
416  const Classification cls = classify(actual_field_type);
417  const std::string lang_field_type = generator_->map_type(field_type);
418  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
419  be_global->lang_header_ <<
420  " " << lang_field_type << ' ' << branch->local_name()->get_string() << ";\n";
421  } else if (cls & CL_STRING) {
422  const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE)
423  ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char;
424  be_global->lang_header_ <<
425  " " << primtype_[chartype] << "* " << branch->local_name()->get_string() << ";\n";
426  } else if (cls & CL_ARRAY) {
427  be_global->lang_header_ <<
428  " " << lang_field_type << "_slice* " << branch->local_name()->get_string() << ";\n";
429  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
430  be_global->lang_header_ <<
431  " " << lang_field_type << "* " << branch->local_name()->get_string() << ";\n";
432  } else {
433  std::cerr << "Unsupported type for union element\n";
434  }
435  }
436 
437  static std::string generateCopyCtor(const std::string&, AST_Decl*, const std::string& name, AST_Type* field_type,
438  const std::string&, bool, Intro&,
439  const std::string&)
440  {
441  std::stringstream ss;
442  AST_Type* actual_field_type = resolveActualType(field_type);
443  const Classification cls = classify(actual_field_type);
444  const std::string lang_field_type = generator_->map_type(field_type);
445  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
446  ss <<
447  " this->_u." << name << " = other._u." << name << ";\n";
448  } else if (cls & CL_STRING) {
449  ss <<
450  " this->_u." << name << " = (other._u." << name << ") ? " << string_ns << "::string_dup(other._u." << name << ") : 0 ;\n";
451  } else if (cls & CL_ARRAY) {
452  ss <<
453  " this->_u." << name << " = (other._u." << name << ") ? " << lang_field_type << "_dup(other._u." << name << ") : 0 ;\n";
454  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
455  ss <<
456  " this->_u." << name << " = (other._u." << name << ") ? new " << lang_field_type << "(*other._u." << name << ") : 0;\n";
457  } else {
458  std::cerr << "Unsupported type for union element\n";
459  }
460 
461  return ss.str();
462  }
463 
464  static std::string generateAssign(const std::string&, AST_Decl*, const std::string& name, AST_Type* field_type,
465  const std::string&, bool, Intro&,
466  const std::string&)
467  {
468  std::stringstream ss;
469  AST_Type* actual_field_type = resolveActualType(field_type);
470  const Classification cls = classify(actual_field_type);
471  const std::string lang_field_type = generator_->map_type(field_type);
472  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
473  ss <<
474  " this->_u." << name << " = other._u." << name << ";\n";
475  } else if (cls & CL_STRING) {
476  ss <<
477  " this->_u." << name << " = (other._u." << name << ") ? " << string_ns << "::string_dup(other._u." << name << ") : 0 ;\n";
478  } else if (cls & CL_ARRAY) {
479  ss <<
480  " this->_u." << name << " = (other._u." << name << ") ? " << lang_field_type << "_dup(other._u." << name << ") : 0 ;\n";
481  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
482  ss <<
483  " this->_u." << name << " = (other._u." << name << ") ? new " << lang_field_type << "(*other._u." << name << ") : 0;\n";
484  } else {
485  std::cerr << "Unsupported type for union element\n";
486  }
487 
488  return ss.str();
489  }
490 
491  static std::string generateEqual(const std::string&, AST_Decl*, const std::string& name, AST_Type* field_type,
492  const std::string&, bool, Intro&,
493  const std::string&)
494  {
495  std::stringstream ss;
496 
497  AST_Type* actual_field_type = resolveActualType(field_type);
498  const Classification cls = classify(actual_field_type);
499  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
500  ss <<
501  " return this->_u." << name << " == rhs._u." << name << ";\n";
502  } else if (cls & CL_STRING) {
503  ss <<
504  " return std::strcmp (this->_u." << name << ", rhs._u." << name << ") == 0 ;\n";
505  } else if (cls & CL_ARRAY) {
506  // TODO
507  ss <<
508  " return false;\n";
509  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
510  ss <<
511  " return *this->_u." << name << " == *rhs._u." << name << ";\n";
512  } else {
513  std::cerr << "Unsupported type for union element\n";
514  }
515 
516  return ss.str();
517  }
518 
519  static std::string generateReset(const std::string&, AST_Decl*, const std::string& name, AST_Type* field_type,
520  const std::string&, bool, Intro&,
521  const std::string&)
522  {
523  std::stringstream ss;
524 
525  AST_Type* actual_field_type = resolveActualType(field_type);
526  const Classification cls = classify(actual_field_type);
527  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
528  // Do nothing.
529  } else if (cls & CL_STRING) {
530  ss <<
531  " " << string_ns << "::string_free(this->_u." << name << ");\n"
532  " this->_u." << name << " = 0;\n";
533  } else if (cls & CL_ARRAY) {
534  ss <<
535  " " << generator_->map_type(field_type) << "_free(this->_u." << name << ");\n"
536  " this->_u." << name << " = 0;\n";
537  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
538  ss <<
539  " delete this->_u." << name << ";\n"
540  " this->_u." << name << " = 0;\n";
541  } else {
542  std::cerr << "Unsupported type for union element\n";
543  }
544 
545  return ss.str();
546  }
547 
548  virtual bool gen_union(AST_Union* u, UTL_ScopedName* name,
549  const std::vector<AST_UnionBranch*>& branches, AST_Type* discriminator)
550  {
551  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
552  const char* const nm = name->last_component()->get_string();
553  struct_decls(name, u->size_type(), "class");
554  be_global->lang_header_ <<
555  "\n"
556  "class " << exporter() << nm << "\n"
557  "{\n"
558  " public:\n"
559  " typedef " << nm << "_var _var_type;\n"
560  " typedef " << nm << "_out _out_type;\n"
561  " " << nm << "();\n"
562  " " << nm << "(const " << nm << "&);\n"
563  " ~" << nm << "() { _reset(); };\n"
564  " " << nm << "& operator=(const " << nm << "&);\n"
565  " void _d(" << scoped(discriminator->name()) << " d) { _discriminator = d; }\n"
566  " " << scoped(discriminator->name()) << " _d() const { return _discriminator; }\n";
567 
568  std::for_each (branches.begin(), branches.end(), GenerateUnionAccessors(u, discriminator));
569 
570  if (needsDefault(branches, discriminator)) {
571  be_global->lang_header_ <<
572  " void _default() {\n"
573  " _reset();\n"
574  " _discriminator = " << generateDefaultValue(u) << ";\n"
575  " }\n";
576  }
577 
578  be_global->lang_header_ <<
579  " bool operator==(const " << nm << "& rhs) const;\n"
580  " bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
581  " OPENDDS_POOL_ALLOCATION_HOOKS\n";
582 
583  be_global->lang_header_ <<
584  " private:\n"
585  " " << scoped(discriminator->name()) << " _discriminator;\n"
586  " union {\n";
587 
588  std::for_each (branches.begin(), branches.end(), generate_union_field);
589 
590  be_global->lang_header_ <<
591  " } _u;\n";
592 
593  be_global->lang_header_ <<
594  " void _reset();\n"
595  "};\n\n";
596 
597  be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
598  be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
599 
600  be_global->lang_header_ <<
601  exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
602  be_global->lang_header_ <<
603  exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
604 
605  {
606  const ScopedNamespaceGuard guard(name, be_global->impl_);
607 
608  be_global->impl_ <<
609  nm << "::" << nm << "() { std::memset (this, 0, sizeof (" << nm << ")); }\n\n";
610 
611  be_global->impl_ <<
612  nm << "::" << nm << "(const " << nm << "& other)\n"
613  "{\n"
614  " this->_discriminator = other._discriminator;\n";
615  generateSwitchForUnion(u, "this->_discriminator", generateCopyCtor, branches, discriminator, "", "", "", false, false);
616  be_global->impl_ <<
617  "}\n\n";
618 
619  be_global->impl_ <<
620  nm << "& " << nm << "::operator=(const " << nm << "& other)\n"
621  "{\n" <<
622  " if (this == &other) {\n"
623  " return *this;\n"
624  " }\n\n"
625  " _reset();\n"
626  " this->_discriminator = other._discriminator;\n";
627  generateSwitchForUnion(u, "this->_discriminator", generateAssign, branches, discriminator, "", "", "", false, false);
628  be_global->impl_ <<
629  " return *this;\n"
630  "}\n\n";
631 
632  be_global->impl_ <<
633  "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
634  "{\n"
635  " if (this->_discriminator != rhs._discriminator) return false;\n";
636  if (generateSwitchForUnion(u, "this->_discriminator", generateEqual, branches, discriminator, "", "", "", false, false)) {
637  be_global->impl_ <<
638  " return false;\n";
639  }
640  be_global->impl_ <<
641  "}\n\n";
642 
643  be_global->impl_ <<
644  "void " << nm << "::_reset()\n"
645  "{\n";
646  generateSwitchForUnion(u, "this->_discriminator", generateReset, branches, discriminator, "", "", "", false, false);
647  be_global->impl_ <<
648  "}\n\n";
649 
650  be_global->impl_ <<
651  "ACE_CDR::Boolean operator<<(ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
652  be_global->impl_ <<
653  "ACE_CDR::Boolean operator>>(ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
654  }
655 
656  gen_typecode(name);
657  return true;
658  }
659 
660  virtual void gen_array(UTL_ScopedName* tdname, AST_Array* arr)
661  {
662  be_global->add_include("<tao/Array_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
663  be_global->add_include("dds/DCPS/SafetyProfilePool.h", BE_GlobalData::STREAM_LANG_H);
664  const char* const nm = tdname->last_component()->get_string();
665  AST_Type* elem = arr->base_type();
666  const Classification elem_cls = classify(elem);
667  const Helper var = (elem->size_type() == AST_Type::VARIABLE)
668  ? HLP_ARR_VAR_VAR : HLP_ARR_FIX_VAR,
669  out = HLP_ARR_OUT,
670  forany = HLP_ARR_FORANY;
671 
672  std::ostringstream bound, nofirst, total;
673  const std::string zeros = array_zero_indices(arr);
674  for (ACE_CDR::ULong dim = 0; dim < arr->n_dims(); ++dim) {
675  const ACE_CDR::ULong extent = arr->dims()[dim]->ev()->u.ulval;
676  bound << '[' << extent << ']';
677  if (dim) {
678  nofirst << '[' << extent << ']';
679  total << " * ";
680  }
681  total << extent;
682  }
683 
684  std::string elem_type = map_type(elem);
685  if (elem_cls & CL_STRING) {
686  elem_type = helpers_[(elem_cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR];
687  }
688 
689  std::string out_type = nm;
690  if (elem->size_type() == AST_Type::VARIABLE) {
691  out_type = helpers_[out] + '<' + nm + ", " + nm + "_var, " + nm +
692  "_slice, " + nm + "_tag>";
693  }
694 
695  be_global->lang_header_ <<
696  "typedef " << elem_type << ' ' << nm << bound.str() << ";\n"
697  "typedef " << elem_type << ' ' << nm << "_slice" << nofirst.str() << ";\n"
698  "struct " << nm << "_tag {};\n"
699  "typedef " << helpers_[var] << '<' << nm << ", " << nm << "_slice, "
700  << nm << "_tag> " << nm << "_var;\n"
701  "typedef " << out_type << ' ' << nm << "_out;\n"
702  "typedef " << helpers_[forany] << '<' << nm << ", " << nm << "_slice, "
703  << nm << "_tag> " << nm << "_forany;\n\n" <<
704  exporter() << nm << "_slice* " << nm << "_alloc();\n" <<
705  exporter() << "void " << nm << "_init_i(" << elem_type << "* begin);\n" <<
706  exporter() << "void " << nm << "_fini_i(" << elem_type << "* begin);\n" <<
707  exporter() << "void " << nm << "_free(" << nm << "_slice* slice);\n" <<
708  exporter() << nm << "_slice* " << nm << "_dup(const " << nm
709  << "_slice* slice);\n" <<
710  exporter() << "void " << nm << "_copy(" << nm << "_slice* dst, const "
711  << nm << "_slice* src);\n\n";
712  const ScopedNamespaceGuard namespaces(tdname, be_global->impl_);
713  be_global->impl_ <<
714  nm << "_slice* " << nm << "_alloc()\n"
715  "{\n"
716  " void* const raw = ACE_Allocator::instance()->malloc"
717  "(sizeof(" << nm << "));\n"
718  " " << nm << "_slice* const slice = static_cast<" << nm << "_slice*"
719  << ">(raw);\n"
720  " " << nm << "_init_i(slice" << zeros << ");\n"
721  " return slice;\n"
722  "}\n\n"
723  "void " << nm << "_init_i(" << elem_type << "* begin)\n"
724  "{\n";
725 
726  if (elem_cls & (CL_PRIMITIVE | CL_ENUM)) {
727  be_global->impl_ << " ACE_UNUSED_ARG(begin);\n";
728  } else if (elem_cls & CL_ARRAY) {
729  std::string indent = " ";
730  const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent);
731  be_global->impl_ <<
732  indent << elem_type << "_init_i(begin" << nfl.index_ << ");\n";
733  } else {
734  be_global->impl_ <<
735  " std::uninitialized_fill_n(begin, " << total.str() << ", "
736  << elem_type << "());\n";
737  }
738 
739  be_global->impl_ <<
740  "}\n\n"
741  "void " << nm << "_fini_i(" << elem_type << "* begin)\n"
742  "{\n";
743 
744  if (elem_cls & (CL_PRIMITIVE | CL_ENUM)) {
745  be_global->impl_ << " ACE_UNUSED_ARG(begin);\n";
746  } else if (elem_cls & CL_ARRAY) {
747  std::string indent = " ";
748  const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent);
749  be_global->impl_ <<
750  indent << elem_type << "_fini_i(begin" << nfl.index_ << ");\n";
751  } else {
752  const std::string::size_type idx_last = elem_type.rfind("::");
753  const std::string elem_last =
754  (elem_cls & CL_STRING) ? "StringManager" :
755  ((idx_last == std::string::npos) ? elem_type
756  : elem_type.substr(idx_last + 2));
757  be_global->impl_ <<
758  " for (int i = 0; i < " << total.str() << "; ++i) {\n"
759  " begin[i]."
760  "~" << elem_last << "();\n"
761  " }\n";
762  }
763 
764  be_global->impl_ <<
765  "}\n\n"
766  "void " << nm << "_free(" << nm << "_slice* slice)\n"
767  "{\n"
768  " if (!slice) return;\n"
769  " " << nm << "_fini_i(slice" << zeros << ");\n"
770  " ACE_Allocator::instance()->free(slice);\n"
771  "}\n\n" <<
772  nm << "_slice* " << nm << "_dup(const " << nm << "_slice* slice)\n"
773  "{\n"
774  " " << nm << "_slice* const arr = " << nm << "_alloc();\n"
775  " if (arr) " << nm << "_copy(arr, slice);\n"
776  " return arr;\n"
777  "}\n\n"
778  "void " << nm << "_copy(" << nm << "_slice* dst, const " << nm
779  << "_slice* src)\n"
780  "{\n"
781  " if (!src || !dst) return;\n";
782 
783  {
784  std::string indent = " ";
785  const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent);
786  if (elem_cls & CL_ARRAY) {
787  be_global->impl_ <<
788  indent << elem_type << "_copy(dst" << nfl.index_ << ", src"
789  << nfl.index_ << ");\n";
790  } else {
791  be_global->impl_ <<
792  indent << "dst" << nfl.index_ << " = src" << nfl.index_ << ";\n";
793  }
794  }
795 
796  be_global->impl_ <<
797  "}\n\n";
798 
799  be_global->lang_header_ <<
800  "inline ACE_CDR::Boolean operator<<(ACE_OutputCDR &, const " << nm << "_forany&) { return true; }\n\n"
801  "inline ACE_CDR::Boolean operator>>(ACE_InputCDR &, " << nm << "_forany&) { return true; }\n\n";
802  }
803 
804  // Outside of user's namespace: add Traits for arrays so that they can be
805  // used in Sequences and Array_var/_out/_forany.
806  virtual void gen_array_traits(UTL_ScopedName* tdname, AST_Array* arr)
807  {
808  const std::string nm = scoped(tdname);
809  const std::string zeros = array_zero_indices(arr);
810  be_global->lang_header_ <<
811  "TAO_BEGIN_VERSIONED_NAMESPACE_DECL\nnamespace TAO {\n"
812  "template <>\n"
813  "struct " << exporter() << "Array_Traits<" << nm << "_forany>\n"
814  "{\n"
815  " static void free(" << nm << "_slice* slice)\n"
816  " {\n"
817  " " << nm << "_free(slice);\n"
818  " }\n\n"
819  " static " << nm << "_slice* dup(const " << nm << "_slice* slice)\n"
820  " {\n"
821  " return " << nm << "_dup(slice);\n"
822  " }\n\n"
823  " static void copy(" << nm << "_slice* dst, const " << nm
824  << "_slice* src)\n"
825  " {\n"
826  " " << nm << "_copy(dst, src);\n"
827  " }\n\n"
828  " static " << nm << "_slice* alloc()\n"
829  " {\n"
830  " return " << nm << "_alloc();\n"
831  " }\n\n"
832  " static void zero(" << nm << "_slice* slice)\n"
833  " {\n"
834  " " << nm << "_fini_i(slice" << zeros << ");\n"
835  " " << nm << "_init_i(slice" << zeros << ");\n"
836  " }\n"
837  " static void construct(" << nm << "_slice* slice)\n"
838  " {\n"
839  " " << nm << "_init_i(slice" << zeros << ");\n"
840  " }\n"
841  " static void destroy(" << nm << "_slice* slice)\n"
842  " {\n"
843  " " << nm << "_fini_i(slice" << zeros << ");\n"
844  " }\n"
845  "};\n}\nTAO_END_VERSIONED_NAMESPACE_DECL\n\n";
846  }
847 
848  virtual void gen_array_typedef(const char* nm, AST_Type* base)
849  {
850  be_global->lang_header_ <<
851  "typedef " << map_type(base) << "_var " << nm << "_var;\n" <<
852  "typedef " << map_type(base) << "_slice " << nm << "_slice;\n" <<
853  "typedef " << map_type(base) << "_forany " << nm << "_forany;\n\n" <<
854  "inline " << nm << "_slice *" << nm << "_alloc() { return " << map_type(base) << "_alloc(); }\n" <<
855  "inline " << nm << "_slice* " << nm << "_dup(" << nm << "_slice *a) { return " << map_type(base) << "_dup(a); }\n" <<
856  "inline void " << nm << "_copy(" << nm << "_slice* to, const " << nm << "_slice* from) { " << map_type(base) << "_copy(to, from); }\n" <<
857  "inline void " << nm << "_free(" << nm << "_slice *a) { " << map_type(base) << "_free(a); }\n";
858  }
859 
860  virtual void gen_typedef_varout(const char* nm, AST_Type* base)
861  {
862  const Classification cls = classify(base);
863  if (cls & CL_STRING) {
864  const Helper var = (cls & CL_WIDE) ? HLP_WSTR_VAR : HLP_STR_VAR,
865  out = (cls & CL_WIDE) ? HLP_WSTR_OUT : HLP_STR_OUT;
866  be_global->lang_header_ <<
867  "typedef " << helpers_[var] << ' ' << nm << "_var;\n"
868  "typedef " << helpers_[out] << ' ' << nm << "_out;\n";
869  } else {
870  be_global->lang_header_ <<
871  "typedef " << generator_->map_type(base) << "_out " << nm << "_out;\n";
872  }
873  }
874 };
875 
877 {
878  virtual void init()
879  {
880  be_global->add_include("FACE/types.hpp", BE_GlobalData::STREAM_LANG_H);
881  be_global->add_include("FACE/StringManager.h", BE_GlobalData::STREAM_LANG_H);
882  primtype_[AST_PredefinedType::PT_long] = "::FACE::Long";
883  primtype_[AST_PredefinedType::PT_ulong] = "::FACE::UnsignedLong";
884  primtype_[AST_PredefinedType::PT_longlong] = "::FACE::LongLong";
885  primtype_[AST_PredefinedType::PT_ulonglong] = "::FACE::UnsignedLongLong";
886  primtype_[AST_PredefinedType::PT_short] = "::FACE::Short";
887  primtype_[AST_PredefinedType::PT_ushort] = "::FACE::UnsignedShort";
888  primtype_[AST_PredefinedType::PT_float] = "::FACE::Float";
889  primtype_[AST_PredefinedType::PT_double] = "::FACE::Double";
890  primtype_[AST_PredefinedType::PT_longdouble] = "::FACE::LongDouble";
891  primtype_[AST_PredefinedType::PT_char] = "::FACE::Char";
892  primtype_[AST_PredefinedType::PT_wchar] = "::FACE::WChar";
893  primtype_[AST_PredefinedType::PT_boolean] = "::FACE::Boolean";
894  primtype_[AST_PredefinedType::PT_octet] = "::FACE::Octet";
895  helpers_[HLP_STR_VAR] = "::FACE::String_var";
896  helpers_[HLP_STR_OUT] = "::FACE::String_out";
897  helpers_[HLP_WSTR_VAR] = "::FACE::WString_var";
898  helpers_[HLP_WSTR_OUT] = "::FACE::WString_out";
899  helpers_[HLP_STR_MGR] = "::OpenDDS::FaceTypes::String_mgr";
900  helpers_[HLP_WSTR_MGR] = "::OpenDDS::FaceTypes::WString_mgr";
901  helpers_[HLP_FIX_VAR] = "::TAO_Fixed_Var_T";
902  helpers_[HLP_VAR_VAR] = "::TAO_Var_Var_T";
903  helpers_[HLP_OUT] = "::TAO_Out_T";
904  helpers_[HLP_SEQ] = "::OpenDDS::FaceTypes::Sequence";
905  helpers_[HLP_SEQ_NS] = "::OpenDDS::FaceTypes";
906  helpers_[HLP_SEQ_VAR_VAR] = "::OpenDDS::FaceTypes::SequenceVar";
907  helpers_[HLP_SEQ_FIX_VAR] = "::OpenDDS::FaceTypes::SequenceVar";
908  helpers_[HLP_SEQ_OUT] = "::TAO_Seq_Out_T";
909  helpers_[HLP_ARR_VAR_VAR] = "::TAO_VarArray_Var_T";
910  helpers_[HLP_ARR_FIX_VAR] = "::TAO_FixedArray_Var_T";
911  helpers_[HLP_ARR_OUT] = "::TAO_Array_Out_T";
912  helpers_[HLP_ARR_FORANY] = "::TAO_Array_Forany_T";
913  helpers_[HLP_FIXED] = "::OpenDDS::FaceTypes::Fixed_T";
914  helpers_[HLP_FIXED_CONSTANT] = "::OpenDDS::FaceTypes::Fixed";
915  }
916 
917  void gen_sequence(UTL_ScopedName* tdname, AST_Sequence* seq)
918  {
919  be_global->add_include("<tao/Seq_Out_T.h>", BE_GlobalData::STREAM_LANG_H);
920  be_global->add_include("FACE/Sequence.h", BE_GlobalData::STREAM_LANG_H);
921  be_global->add_include("FACE/SequenceVar.h", BE_GlobalData::STREAM_LANG_H);
922  be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
923  const char* const nm = tdname->last_component()->get_string();
924  AST_Type* elem = seq->base_type();
925  const Classification elem_cls = classify(elem);
926  const bool bounded = !seq->unbounded();
927  const Helper var = (elem->size_type() == AST_Type::VARIABLE)
928  ? HLP_SEQ_VAR_VAR : HLP_SEQ_FIX_VAR,
929  out = HLP_SEQ_OUT;
930 
931  std::string elem_type = map_type(elem), extra_tmp_args;
932  if (elem_cls & CL_STRING) {
933  const AST_Expression::ExprType char_type = (elem_cls & CL_WIDE)
934  ? AST_Expression::EV_wchar : AST_Expression::EV_char;
935  extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::StringEltPolicy< "
936  + map_type(char_type) + ">";
937  } else if (elem_cls & CL_ARRAY) {
938  extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::ArrayEltPolicy<"
939  + elem_type + "_forany>";
940  } else if (elem->size_type() == AST_Type::VARIABLE) {
941  extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::VariEltPolicy<"
942  + elem_type + ">";
943  }
944 
945  std::string bound = helpers_[HLP_SEQ_NS] + "::Unbounded";
946  if (bounded) {
947  std::ostringstream oss;
948  oss << helpers_[HLP_SEQ_NS] << "::Bounded<"
949  << seq->max_size()->ev()->u.ulval << '>';
950  bound = oss.str();
951  }
952 
953  const std::string base = helpers_[HLP_SEQ] + "< " + elem_type + ", " + bound
954  + extra_tmp_args + " >",
955  len_type = primtype_[AST_PredefinedType::PT_ulong],
956  flag_type = primtype_[AST_PredefinedType::PT_boolean];
957 
958  be_global->lang_header_ <<
959  "class " << nm << ";\n"
960  "typedef " << helpers_[var] << '<' << nm << "> " << nm << "_var;\n"
961  "typedef " << helpers_[out] << '<' << nm << "> " << nm << "_out;\n\n"
962  "class " << exporter() << nm << " : public " << base << " {\n"
963  "public:\n"
964  " typedef " << nm << "_var _var_type;\n"
965  " typedef " << nm << "_out _out_type;\n\n"
966  " " << nm << "() {}\n"
967  " " << nm << "(const " << nm << "& seq) : " << base << "(seq) {}\n"
968  " friend void swap(" << nm << "& a, " << nm << "& b) { a.swap(b); }\n"
969  " " << nm << "& operator=(const " << nm << "& rhs)\n"
970  " {\n"
971  " " << nm << " tmp(rhs);\n"
972  " swap(tmp);\n"
973  " return *this;\n"
974  " }\n";
975 
976  if (bounded) {
977  be_global->lang_header_ <<
978  " " << nm << "(" << len_type << " length, " << elem_type << "* data, "
979  << flag_type << " release = false)\n"
980  " : " << base << "(0u, length, data, release) {}\n";
981  } else {
982  be_global->lang_header_ <<
983  " " << nm << "(" << len_type << " maximum)\n"
984  " : " << base << "(maximum, 0u, 0, true) {}\n"
985  " " << nm << "(" << len_type << " maximum, " << len_type << " length, "
986  << elem_type << "* data, " << flag_type << " release = false)\n"
987  " : " << base << "(maximum, length, data, release) {}\n";
988  }
989  be_global->lang_header_ <<
990  "};\n\n";
991 
992  be_global->lang_header_ <<
993  "inline ACE_CDR::Boolean operator<< (ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
994 
995  be_global->lang_header_ <<
996  "inline ACE_CDR::Boolean operator>> (ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
997  }
998 
999  bool gen_struct(AST_Structure*, UTL_ScopedName* name,
1000  const std::vector<AST_Field*>& fields,
1001  AST_Type::SIZE_TYPE size,
1002  const char*)
1003  {
1004  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1005  const char* const nm = name->last_component()->get_string();
1006  struct_decls(name, size);
1007  be_global->lang_header_ <<
1008  "\n"
1009  "struct " << exporter() << nm << "\n"
1010  "{\n"
1011  " typedef " << nm << "_var _var_type;\n"
1012  " typedef " << nm << "_out _out_type;\n\n";
1013 
1014  for (size_t i = 0; i < fields.size(); ++i) {
1015  AST_Type* field_type = fields[i]->field_type();
1016  const std::string field_name = fields[i]->local_name()->get_string();
1017  std::string type_name = map_type(field_type);
1018 
1019  const Classification cls = classify(field_type);
1020  if (cls & CL_STRING) {
1021  type_name = helpers_[(cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR];
1022  }
1023  be_global->lang_header_ <<
1024  " " << type_name << ' ' << field_name << ";\n";
1025  }
1026 
1027  be_global->lang_header_ << "\n"
1028  " bool operator==(const " << nm << "& rhs) const;\n"
1029  " bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
1030  " OPENDDS_POOL_ALLOCATION_HOOKS\n"
1031  "};\n\n";
1032 
1033  be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
1034  be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
1035 
1036  if (size == AST_Type::VARIABLE) {
1037  be_global->lang_header_ <<
1038  exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n";
1039  }
1040 
1041  be_global->lang_header_ <<
1042  exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
1043  be_global->lang_header_ <<
1044  exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
1045 
1046  {
1047  const ScopedNamespaceGuard guard(name, be_global->impl_);
1048  be_global->impl_ <<
1049  "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
1050  "{\n";
1051  for (size_t i = 0; i < fields.size(); ++i) {
1052  const std::string field_name = fields[i]->local_name()->get_string();
1053  AST_Type* field_type = resolveActualType(fields[i]->field_type());
1054  const Classification cls = classify(field_type);
1055  if (cls & CL_ARRAY) {
1056  std::string indent(" ");
1057  NestedForLoops nfl("int", "i",
1058  dynamic_cast<AST_Array*>(field_type), indent, true);
1059  be_global->impl_ <<
1060  indent << "if (" << field_name << nfl.index_ << " != rhs."
1061  << field_name << nfl.index_ << ") {\n" <<
1062  indent << " return false;\n" <<
1063  indent << "}\n";
1064  } else {
1065  be_global->impl_ <<
1066  " if (" << field_name << " != rhs." << field_name << ") {\n"
1067  " return false;\n"
1068  " }\n";
1069  }
1070  }
1071  be_global->impl_ << " return true;\n}\n\n";
1072 
1073  if (size == AST_Type::VARIABLE) {
1074  be_global->impl_ <<
1075  "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
1076  "{\n"
1077  " using std::swap;\n";
1078  for (size_t i = 0; i < fields.size(); ++i) {
1079  const std::string fn = fields[i]->local_name()->get_string();
1080  AST_Type* field_type = resolveActualType(fields[i]->field_type());
1081  const Classification cls = classify(field_type);
1082  if (cls & CL_ARRAY) {
1083  ACE_CDR::ULong elems = 1;
1084  const std::string flat_fn = fn + array_dims(field_type, elems);
1085  be_global->add_include("<algorithm>", BE_GlobalData::STREAM_CPP);
1086  be_global->impl_ <<
1087  " std::swap_ranges(lhs." << flat_fn << ", lhs." << flat_fn
1088  << " + " << elems << ", rhs." << flat_fn << ");\n";
1089  } else {
1090  be_global->impl_ <<
1091  " swap(lhs." << fn << ", rhs." << fn << ");\n";
1092  }
1093  }
1094  be_global->impl_ << "}\n\n";
1095  }
1096 
1097  be_global->impl_ <<
1098  "ACE_CDR::Boolean operator<< (ACE_OutputCDR &, const " << nm << "&) { return true; }\n\n";
1099  be_global->impl_ <<
1100  "ACE_CDR::Boolean operator>> (ACE_InputCDR &, " << nm << "&) { return true; }\n\n";
1101  }
1102 
1103  gen_typecode(name);
1104  return true;
1105  }
1106 
1108 };
1110 
1112 {
1113  virtual void init()
1114  {
1115  be_global->add_include("tao/String_Manager_T.h", BE_GlobalData::STREAM_LANG_H);
1116  be_global->add_include("tao/CORBA_String.h", BE_GlobalData::STREAM_LANG_H);
1117  primtype_[AST_PredefinedType::PT_long] = "CORBA::Long";
1118  primtype_[AST_PredefinedType::PT_ulong] = "CORBA::ULong";
1119  primtype_[AST_PredefinedType::PT_longlong] = "CORBA::LongLong";
1120  primtype_[AST_PredefinedType::PT_ulonglong] = "CORBA::ULongLong";
1121  primtype_[AST_PredefinedType::PT_short] = "CORBA::Short";
1122  primtype_[AST_PredefinedType::PT_ushort] = "CORBA::UShort";
1123 #if OPENDDS_HAS_EXPLICIT_INTS
1124  primtype_[AST_PredefinedType::PT_int8] = "CORBA::Int8";
1125  primtype_[AST_PredefinedType::PT_uint8] = "CORBA::UInt8";
1126 #endif
1127  primtype_[AST_PredefinedType::PT_float] = "CORBA::Float";
1128  primtype_[AST_PredefinedType::PT_double] = "CORBA::Double";
1129  primtype_[AST_PredefinedType::PT_longdouble] = "CORBA::LongDouble";
1130  primtype_[AST_PredefinedType::PT_char] = "CORBA::Char";
1131  primtype_[AST_PredefinedType::PT_wchar] = "CORBA::WChar";
1132  primtype_[AST_PredefinedType::PT_boolean] = "CORBA::Boolean";
1133  primtype_[AST_PredefinedType::PT_octet] = "CORBA::Octet";
1134  helpers_[HLP_STR_VAR] = "CORBA::String_var";
1135  helpers_[HLP_STR_OUT] = "CORBA::String_out";
1136  helpers_[HLP_WSTR_VAR] = "CORBA::WString_var";
1137  helpers_[HLP_WSTR_OUT] = "CORBA::WString_out";
1138  helpers_[HLP_STR_MGR] = "::TAO::String_Manager";
1139  helpers_[HLP_WSTR_MGR] = "CORBA::WString_mgr";
1140  helpers_[HLP_FIX_VAR] = "::TAO_Fixed_Var_T";
1141  helpers_[HLP_VAR_VAR] = "::TAO_Var_Var_T";
1142  helpers_[HLP_OUT] = "::TAO_Out_T";
1143  helpers_[HLP_SEQ] = "::OpenDDS::SafetyProfile::Sequence";
1144  helpers_[HLP_SEQ_NS] = "::OpenDDS::SafetyProfile";
1145  helpers_[HLP_SEQ_VAR_VAR] = "::OpenDDS::SafetyProfile::SequenceVar";
1146  helpers_[HLP_SEQ_FIX_VAR] = "::OpenDDS::SafetyProfile::SequenceVar";
1147  helpers_[HLP_SEQ_OUT] = "::TAO_Seq_Out_T";
1148  helpers_[HLP_ARR_VAR_VAR] = "::TAO_VarArray_Var_T";
1149  helpers_[HLP_ARR_FIX_VAR] = "::TAO_FixedArray_Var_T";
1150  helpers_[HLP_ARR_OUT] = "::TAO_Array_Out_T";
1151  helpers_[HLP_ARR_FORANY] = "::TAO_Array_Forany_T";
1152  }
1153 
1154  virtual void gen_sequence(UTL_ScopedName* tdname, AST_Sequence* seq)
1155  {
1156  be_global->add_include("<tao/Seq_Out_T.h>", BE_GlobalData::STREAM_LANG_H);
1157  be_global->add_include("dds/DCPS/SafetyProfileSequence.h", BE_GlobalData::STREAM_LANG_H);
1158  be_global->add_include("dds/DCPS/SafetyProfileSequenceVar.h", BE_GlobalData::STREAM_LANG_H);
1159  const char* const nm = tdname->last_component()->get_string();
1160  AST_Type* elem = seq->base_type();
1161  const Classification elem_cls = classify(elem);
1162  const bool bounded = !seq->unbounded();
1163  const Helper var = (elem->size_type() == AST_Type::VARIABLE)
1164  ? HLP_SEQ_VAR_VAR : HLP_SEQ_FIX_VAR,
1165  out = HLP_SEQ_OUT;
1166 
1167  std::string elem_type = map_type(elem), extra_tmp_args;
1168  if (elem_cls & CL_STRING) {
1169  const AST_Expression::ExprType char_type = (elem_cls & CL_WIDE)
1170  ? AST_Expression::EV_wchar : AST_Expression::EV_char;
1171  extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::StringEltPolicy< "
1172  + map_type(char_type) + ">";
1173  } else if (elem_cls & CL_ARRAY) {
1174  extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::ArrayEltPolicy<"
1175  + elem_type + "_forany>";
1176  } else if (elem->size_type() == AST_Type::VARIABLE) {
1177  extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::VariEltPolicy<"
1178  + elem_type + ">";
1179  }
1180 
1181  std::string bound = helpers_[HLP_SEQ_NS] + "::Unbounded";
1182  if (bounded) {
1183  std::ostringstream oss;
1184  oss << helpers_[HLP_SEQ_NS] << "::Bounded<"
1185  << seq->max_size()->ev()->u.ulval << '>';
1186  bound = oss.str();
1187  }
1188 
1189  const std::string base = helpers_[HLP_SEQ] + "< " + elem_type + ", " + bound
1190  + extra_tmp_args + " >",
1191  len_type = primtype_[AST_PredefinedType::PT_ulong],
1192  flag_type = primtype_[AST_PredefinedType::PT_boolean];
1193 
1194  be_global->lang_header_ <<
1195  "class " << nm << ";\n"
1196  "typedef " << helpers_[var] << '<' << nm << "> " << nm << "_var;\n"
1197  "typedef " << helpers_[out] << '<' << nm << "> " << nm << "_out;\n\n"
1198  "class " << exporter() << nm << " : public " << base << " {\n"
1199  "public:\n"
1200  " typedef " << nm << "_var _var_type;\n"
1201  " typedef " << nm << "_out _out_type;\n\n"
1202  " " << nm << "() {}\n"
1203  " " << nm << "(const " << nm << "& seq) : " << base << "(seq) {}\n"
1204  " friend void swap(" << nm << "& a, " << nm << "& b) { a.swap(b); }\n"
1205  " " << nm << "& operator=(const " << nm << "& rhs)\n"
1206  " {\n"
1207  " " << nm << " tmp(rhs);\n"
1208  " swap(tmp);\n"
1209  " return *this;\n"
1210  " }\n";
1211 
1212  if (bounded) {
1213  be_global->lang_header_ <<
1214  " " << nm << "(" << len_type << " length, " << elem_type << "* data, "
1215  << flag_type << " release = false)\n"
1216  " : " << base << "(0u, length, data, release) {}\n";
1217  } else {
1218  be_global->lang_header_ <<
1219  " " << nm << "(" << len_type << " maximum)\n"
1220  " : " << base << "(maximum, 0u, 0, true) {}\n"
1221  " " << nm << "(" << len_type << " maximum, " << len_type << " length, "
1222  << elem_type << "* data, " << flag_type << " release = false)\n"
1223  " : " << base << "(maximum, length, data, release) {}\n";
1224  }
1225  be_global->lang_header_ <<
1226  "};\n\n";
1227 
1228  be_global->lang_header_ <<
1229  "inline ACE_CDR::Boolean operator<< (ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
1230 
1231  be_global->lang_header_ <<
1232  "inline ACE_CDR::Boolean operator>> (ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
1233  }
1234 
1235  bool gen_struct(AST_Structure*, UTL_ScopedName* name,
1236  const std::vector<AST_Field*>& fields,
1237  AST_Type::SIZE_TYPE size,
1238  const char*)
1239  {
1240  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1241  const char* const nm = name->last_component()->get_string();
1242  struct_decls(name, size);
1243  be_global->lang_header_ <<
1244  "\n"
1245  "struct " << exporter() << nm << "\n"
1246  "{\n"
1247  " typedef " << nm << "_var _var_type;\n"
1248  " typedef " << nm << "_out _out_type;\n\n";
1249 
1250  for (size_t i = 0; i < fields.size(); ++i) {
1251  AST_Type* field_type = fields[i]->field_type();
1252  const std::string field_name = fields[i]->local_name()->get_string();
1253  std::string type_name = map_type(field_type);
1254  const Classification cls = classify(field_type);
1255  if (cls & CL_STRING) {
1256  type_name = helpers_[(cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR];
1257  }
1258  be_global->lang_header_ <<
1259  " " << type_name << ' ' << field_name << ";\n";
1260  }
1261 
1262  be_global->lang_header_ << "\n"
1263  " bool operator==(const " << nm << "& rhs) const;\n"
1264  " bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
1265  " OPENDDS_POOL_ALLOCATION_HOOKS\n"
1266  "};\n\n";
1267 
1268  be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
1269  be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
1270 
1271  if (size == AST_Type::VARIABLE) {
1272  be_global->lang_header_ <<
1273  exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n";
1274  }
1275 
1276  be_global->lang_header_ <<
1277  exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
1278  be_global->lang_header_ <<
1279  exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
1280 
1281  {
1282  const ScopedNamespaceGuard guard(name, be_global->impl_);
1283  be_global->impl_ <<
1284  "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
1285  "{\n";
1286  for (size_t i = 0; i < fields.size(); ++i) {
1287  const std::string field_name = fields[i]->local_name()->get_string();
1288  AST_Type* field_type = resolveActualType(fields[i]->field_type());
1289  const Classification cls = classify(field_type);
1290  if (cls & CL_ARRAY) {
1291  std::string indent(" ");
1292  NestedForLoops nfl("int", "i",
1293  dynamic_cast<AST_Array*>(field_type), indent, true);
1294  be_global->impl_ <<
1295  indent << "if (" << field_name << nfl.index_ << " != rhs."
1296  << field_name << nfl.index_ << ") {\n" <<
1297  indent << " return false;\n" <<
1298  indent << "}\n";
1299  } else {
1300  be_global->impl_ <<
1301  " if (" << field_name << " != rhs." << field_name << ") {\n"
1302  " return false;\n"
1303  " }\n";
1304  }
1305  }
1306  be_global->impl_ << " return true;\n}\n\n";
1307 
1308  if (size == AST_Type::VARIABLE) {
1309  be_global->impl_ <<
1310  "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
1311  "{\n"
1312  " using std::swap;\n";
1313  for (size_t i = 0; i < fields.size(); ++i) {
1314  const std::string fn = fields[i]->local_name()->get_string();
1315  AST_Type* field_type = resolveActualType(fields[i]->field_type());
1316  const Classification cls = classify(field_type);
1317  if (cls & CL_ARRAY) {
1318  ACE_CDR::ULong elems = 1;
1319  const std::string flat_fn = fn + array_dims(field_type, elems);
1320  be_global->add_include("<algorithm>", BE_GlobalData::STREAM_CPP);
1321  be_global->impl_ <<
1322  " std::swap_ranges(lhs." << flat_fn << ", lhs." << flat_fn
1323  << " + " << elems << ", rhs." << flat_fn << ");\n";
1324  } else {
1325  be_global->impl_ <<
1326  " swap(lhs." << fn << ", rhs." << fn << ");\n";
1327  }
1328  }
1329  be_global->impl_ << "}\n\n";
1330  }
1331 
1332  be_global->impl_ <<
1333  "ACE_CDR::Boolean operator<< (ACE_OutputCDR &, const " << nm << "&) { return true; }\n\n";
1334  be_global->impl_ <<
1335  "ACE_CDR::Boolean operator>> (ACE_InputCDR &, " << nm << "&) { return true; }\n\n";
1336  }
1337 
1338  gen_typecode(name);
1339  return true;
1340  }
1341 
1343 };
1345 
1347 {
1348  void init()
1349  {
1350  be_global->add_include("<cstdint>", BE_GlobalData::STREAM_LANG_H);
1351  be_global->add_include("<string>", BE_GlobalData::STREAM_LANG_H);
1352  primtype_[AST_PredefinedType::PT_long] = "int32_t";
1353  primtype_[AST_PredefinedType::PT_ulong] = "uint32_t";
1354  primtype_[AST_PredefinedType::PT_longlong] = "int64_t";
1355  primtype_[AST_PredefinedType::PT_ulonglong] = "uint64_t";
1356  primtype_[AST_PredefinedType::PT_short] = "int16_t";
1357  primtype_[AST_PredefinedType::PT_ushort] = "uint16_t";
1358 #if OPENDDS_HAS_EXPLICIT_INTS
1359  primtype_[AST_PredefinedType::PT_int8] = "int8_t";
1360  primtype_[AST_PredefinedType::PT_uint8] = "uint8_t";
1361 #endif
1362  primtype_[AST_PredefinedType::PT_float] = "float";
1363  primtype_[AST_PredefinedType::PT_double] = "double";
1364  primtype_[AST_PredefinedType::PT_longdouble] = "long double";
1365  primtype_[AST_PredefinedType::PT_char] = "char";
1366  primtype_[AST_PredefinedType::PT_wchar] = "wchar_t";
1367  primtype_[AST_PredefinedType::PT_boolean] = "bool";
1368  primtype_[AST_PredefinedType::PT_octet] = "uint8_t";
1369  helpers_[HLP_STR_VAR] = "std::string";
1370  helpers_[HLP_STR_OUT] = "std::string";
1371  helpers_[HLP_WSTR_VAR] = "std::wstring";
1372  helpers_[HLP_WSTR_OUT] = "std::wstring";
1373  helpers_[HLP_STR_MGR] = "std::string";
1374  helpers_[HLP_WSTR_MGR] = "std::wstring";
1375  helpers_[HLP_FIX_VAR] = "<<fixed-size var>>";
1376  helpers_[HLP_VAR_VAR] = "<<variable-size var>>";
1377  helpers_[HLP_OUT] = "<<out>>";
1378  helpers_[HLP_SEQ] = "std::vector";
1379  helpers_[HLP_SEQ_NS] = "std";
1380  helpers_[HLP_SEQ_VAR_VAR] = "<<variable sequence var>>";
1381  helpers_[HLP_SEQ_FIX_VAR] = "<<fixed sequence var>>";
1382  helpers_[HLP_SEQ_OUT] = "<<sequence out>>";
1383  helpers_[HLP_ARR_VAR_VAR] = "<<variable array var>>";
1384  helpers_[HLP_ARR_FIX_VAR] = "<<fixed array var>>";
1385  helpers_[HLP_ARR_OUT] = "<<array out>>";
1386  helpers_[HLP_ARR_FORANY] = "<<array forany>>";
1387  helpers_[HLP_FIXED] = "IDL::Fixed_T";
1388  helpers_[HLP_FIXED_CONSTANT] = "IDL::Fixed_T";
1389  }
1390 
1391  static void gen_typecode_ptrs(const std::string& type)
1392  {
1393  if (!be_global->suppress_typecode()) {
1394  be_global->add_include("tao/Basic_Types.h", BE_GlobalData::STREAM_LANG_H);
1395  be_global->lang_header_ << "extern const ::CORBA::TypeCode_ptr _tc_" << type << ";\n";
1396  be_global->impl_ << "const ::CORBA::TypeCode_ptr _tc_" << type << " = nullptr;\n";
1397  }
1398  }
1399 
1400  std::string map_type_string(AST_PredefinedType::PredefinedType chartype, bool)
1401  {
1402  return chartype == AST_PredefinedType::PT_char ? "std::string" : "std::wstring";
1403  }
1404 
1405  std::string const_keyword(AST_Expression::ExprType type)
1406  {
1407  switch (type) {
1408  case AST_Expression::EV_string:
1409  case AST_Expression::EV_wstring:
1410  return "const";
1411  default:
1412  return "constexpr";
1413  }
1414  }
1415 
1416  void gen_simple_out(const char*) {}
1417 
1418  bool scoped_enum() { return true; }
1419  std::string enum_base() { return " : uint32_t"; }
1420 
1422  {
1423  // Older versions of gcc will complain because it appears that a primitive
1424  // default constructor is not called for anonymous unions.
1425  be_global->lang_header_ <<
1426  "#if defined(__GNUC__) && !defined(__clang__)\n"
1427  "# pragma GCC diagnostic push\n"
1428  "# pragma GCC diagnostic ignored \"-Wmaybe-uninitialized\"\n"
1429  "#endif\n";
1430  }
1431 
1433  {
1434  be_global->lang_header_ <<
1435  "#if defined(__GNUC__) && !defined(__clang__)\n"
1436  "# pragma GCC diagnostic pop\n"
1437  "#endif\n\n";
1438  }
1439 
1440  void struct_decls(UTL_ScopedName* name, AST_Type::SIZE_TYPE, const char*)
1441  {
1442  be_global->lang_header_ <<
1443  "class " << name->last_component()->get_string() << ";\n";
1444  }
1445 
1446  static void gen_array(AST_Array* arr, const std::string& type, const std::string& elem, const std::string& ind = "")
1447  {
1448  std::string array;
1449  std::ostringstream bounds;
1450  for (ACE_CDR::ULong dim = arr->n_dims(); dim; --dim) {
1451  array += "std::array<";
1452  bounds << ", " << arr->dims()[dim - 1]->ev()->u.ulval << '>';
1453  }
1454  be_global->add_include("<array>", BE_GlobalData::STREAM_LANG_H);
1455  be_global->lang_header_ << ind << "using " << type << " = " << array << elem << bounds.str() << ";\n";
1456  }
1457 
1458  void gen_array(UTL_ScopedName* tdname, AST_Array* arr)
1459  {
1460  gen_array(arr, tdname->last_component()->get_string(), map_type(arr->base_type()));
1461  }
1462 
1463  void gen_array_traits(UTL_ScopedName*, AST_Array*) {}
1464  void gen_array_typedef(const char*, AST_Type*) {}
1465  void gen_typedef_varout(const char*, AST_Type*) {}
1466 
1467  static void gen_sequence(const std::string& type, const std::string& elem, const std::string& ind = "")
1468  {
1469  be_global->add_include("<vector>", BE_GlobalData::STREAM_LANG_H);
1470  be_global->lang_header_ << ind << "using " << type << " = std::vector<" << elem << ">;\n";
1471  }
1472 
1473  void gen_sequence(UTL_ScopedName* tdname, AST_Sequence* seq)
1474  {
1475  gen_sequence(tdname->last_component()->get_string(), map_type(seq->base_type()));
1476  }
1477 
1478  static void gen_common_strunion_pre(const char* nm)
1479  {
1480  be_global->lang_header_ <<
1481  "\n"
1482  "class " << exporter() << nm << "\n"
1483  "{\n"
1484  "public:\n\n";
1485  }
1486 
1487  static void gen_common_strunion_post(const char* nm)
1488  {
1489  be_global->lang_header_ <<
1490  "};\n\n"
1491  "using " << nm << "_out = " << nm << "&; // for tao_idl compatibility\n\n"
1492  << exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n";
1493  }
1494 
1495  static void gen_struct_members(AST_Field* field)
1496  {
1497  FieldInfo af(*field);
1498  if (af.type_->anonymous() && af.as_base_) {
1499  const std::string elem_type = generator_->map_type(af.as_base_);
1500  if (af.arr_) {
1501  gen_array(af.arr_, af.type_name_, elem_type, " ");
1502  } else if (af.seq_) {
1503  gen_sequence(af.type_name_, elem_type, " ");
1504  }
1505  }
1506 
1507  const std::string lang_field_type = generator_->map_type(field);
1508  const std::string assign_pre = "{ _" + af.name_ + " = ",
1509  assign = assign_pre + "val; }\n",
1510  move = assign_pre + "std::move(val); }\n",
1511  ret = "{ return _" + af.name_ + "; }\n";
1512  std::string initializer;
1513  if (af.cls_ & (CL_PRIMITIVE | CL_ENUM)) {
1514  be_global->lang_header_ <<
1515  " void " << af.name_ << '(' << lang_field_type << " val) " << assign <<
1516  " " << lang_field_type << ' ' << af.name_ << "() const " << ret <<
1517  " " << lang_field_type << "& " << af.name_ << "() " << ret;
1518  if (af.cls_ & CL_ENUM) {
1519  AST_Enum* enu = dynamic_cast<AST_Enum*>(af.act_);
1520  for (UTL_ScopeActiveIterator it(enu, UTL_Scope::IK_decls); !it.is_done(); it.next()) {
1521  if (it.item()->node_type() == AST_Decl::NT_enum_val) {
1522  initializer = '{' + generator_->map_type(af.type_)
1523  + "::" + it.item()->local_name()->get_string() + '}';
1524  break;
1525  }
1526  }
1527  } else {
1528  initializer = "{}";
1529  }
1530  } else {
1531  if (af.cls_ & CL_ARRAY) {
1532  initializer = "{}";
1533  }
1534  be_global->add_include("<utility>", BE_GlobalData::STREAM_LANG_H);
1535  be_global->lang_header_ <<
1536  " void " << af.name_ << "(const " << lang_field_type << "& val) " << assign <<
1537  " void " << af.name_ << '(' << lang_field_type << "&& val) " << move <<
1538  " const " << lang_field_type << "& " << af.name_ << "() const " << ret <<
1539  " " << lang_field_type << "& " << af.name_ << "() " << ret;
1540  }
1541  be_global->lang_header_ <<
1542  " " << lang_field_type << " _" << af.name_ << initializer << ";\n\n";
1543  }
1544 
1545  bool gen_struct(AST_Structure*, UTL_ScopedName* name,
1546  const std::vector<AST_Field*>& fields,
1547  AST_Type::SIZE_TYPE, const char*)
1548  {
1549  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1550  const ScopedNamespaceGuard namespaces2(name, be_global->impl_);
1551  const char* const nm = name->last_component()->get_string();
1552  gen_common_strunion_pre(nm);
1553 
1554  std::for_each(fields.begin(), fields.end(), gen_struct_members);
1555 
1556  be_global->lang_header_ <<
1557  " " << nm << "() = default;\n"
1558  " " << (fields.size() == 1 ? "explicit " : "") << nm << '(';
1559  be_global->impl_ <<
1560  nm << "::" << nm << '(';
1561 
1562  std::string init_list, swaps;
1563  for (size_t i = 0; i < fields.size(); ++i) {
1564  const std::string fn = fields[i]->local_name()->get_string();
1565  const std::string ft = map_type(fields[i]);
1566  const Classification cls = classify(fields[i]->field_type());
1567  const bool by_ref = (cls & (CL_PRIMITIVE | CL_ENUM)) == 0;
1568  const std::string param = (by_ref ? "const " : "") + ft + (by_ref ? "&" : "")
1569  + ' ' + fn + (i < fields.size() - 1 ? ",\n " : ")");
1570  be_global->lang_header_ << param;
1571  be_global->impl_ << param;
1572  init_list += '_' + fn + '(' + fn + ')';
1573  if (i < fields.size() - 1) init_list += "\n , ";
1574  swaps += " swap(lhs._" + fn + ", rhs._" + fn + ");\n";
1575  }
1576  be_global->lang_header_ << ";\n\n";
1577  be_global->impl_ << "\n : " << init_list << "\n{}\n\n";
1578 
1579  gen_common_strunion_post(nm);
1580  be_global->impl_ <<
1581  "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
1582  "{\n"
1583  " using std::swap;\n"
1584  << swaps << "}\n\n";
1585  gen_typecode_ptrs(nm);
1586  return true;
1587  }
1588 
1589  static void union_field(AST_UnionBranch* branch)
1590  {
1591  AST_Type* field_type = branch->field_type();
1592  const std::string lang_field_type = generator_->map_type(field_type);
1593  be_global->lang_header_ <<
1594  " " << lang_field_type << " _" << branch->local_name()->get_string()
1595  << ";\n";
1596  }
1597 
1598  static void union_accessors(AST_UnionBranch* branch)
1599  {
1600  AST_Type* field_type = branch->field_type();
1601  AST_Type* actual_field_type = resolveActualType(field_type);
1602  const std::string lang_field_type = generator_->map_type(field_type);
1603  const Classification cls = classify(actual_field_type);
1604  const char* nm = branch->local_name()->get_string();
1605 
1606  AST_UnionLabel* label = branch->label(0);
1607  AST_Union* union_ = dynamic_cast<AST_Union*>(branch->defined_in());
1608  AST_Type* dtype = resolveActualType(union_->disc_type());
1609  const std::string disc_type = generator_->map_type(dtype);
1610 
1611  std::string dval;
1612  if (label->label_kind() == AST_UnionLabel::UL_default) {
1613  dval = generateDefaultValue(union_);
1614  } else if (dtype->node_type() == AST_Decl::NT_enum) {
1615  dval = getEnumLabel(label->label_val(), dtype);
1616  } else {
1617  std::ostringstream strm;
1618  strm << *label->label_val()->ev();
1619  dval = strm.str();
1620  }
1621 
1622  std::string disc_param, disc_name = dval;
1623  if (label->label_kind() == AST_UnionLabel::UL_default ||
1624  branch->label_list_length() > 1) {
1625  disc_name = "disc";
1626  disc_param = ", " + disc_type + " disc = " + dval;
1627  }
1628 
1629  const std::string assign_pre = "{ _activate(" + disc_name + "); _"
1630  + std::string(nm) + " = ",
1631  assign = assign_pre + "val; }\n",
1632  move = assign_pre + "std::move(val); }\n",
1633  ret = "{ return _" + std::string(nm) + "; }\n";
1634  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
1635  be_global->lang_header_ <<
1636  " void " << nm << '(' << lang_field_type << " val" << disc_param
1637  << ") " << assign <<
1638  " " << lang_field_type << ' ' << nm << "() const " << ret <<
1639  " " << lang_field_type << "& " << nm << "() " << ret << "\n";
1640  } else {
1641  be_global->add_include("<utility>", BE_GlobalData::STREAM_LANG_H);
1642  be_global->lang_header_ <<
1643  " void " << nm << "(const " << lang_field_type << "& val" << disc_param
1644  << ") " << assign <<
1645  " void " << nm << '(' << lang_field_type << "&& val" << disc_param
1646  << ") " << move <<
1647  " const " << lang_field_type << "& " << nm << "() const " << ret <<
1648  " " << lang_field_type << "& " << nm << "() " << ret << "\n";
1649  }
1650  }
1651 
1652  static std::string union_copy(const std::string&, AST_Decl*, const std::string& name, AST_Type*,
1653  const std::string&, bool, Intro&,
1654  const std::string&)
1655  {
1656  return " _" + name + " = rhs._" + name + ";\n";
1657  }
1658 
1659  static std::string union_move(const std::string&, AST_Decl*, const std::string& name, AST_Type*,
1660  const std::string&, bool, Intro&,
1661  const std::string&)
1662  {
1663  return " _" + name + " = std::move(rhs._" + name + ");\n";
1664  }
1665 
1666  static std::string union_assign(const std::string&, AST_Decl*, const std::string& name, AST_Type*,
1667  const std::string&, bool, Intro&,
1668  const std::string&)
1669  {
1670  return " " + name + "(rhs._" + name + ");\n";
1671  }
1672 
1673  static std::string union_move_assign(const std::string&, AST_Decl*, const std::string& name, AST_Type*,
1674  const std::string&, bool, Intro&,
1675  const std::string&)
1676  {
1677  return " " + name + "(std::move(rhs._" + name + "));\n";
1678  }
1679 
1680  static std::string union_activate(const std::string&, AST_Decl*, const std::string& name, AST_Type* type,
1681  const std::string&, bool, Intro&,
1682  const std::string&)
1683  {
1684  AST_Type* actual_field_type = resolveActualType(type);
1685  const std::string lang_field_type = generator_->map_type(type);
1686  const Classification cls = classify(actual_field_type);
1687  if (!(cls & (CL_PRIMITIVE | CL_ENUM))) {
1688  return " new(&_" + name + ") " + lang_field_type + ";\n";
1689  }
1690  return "";
1691  }
1692 
1693  static std::string union_reset(const std::string&, AST_Decl*, const std::string& name, AST_Type* type,
1694  const std::string&, bool, Intro&,
1695  const std::string&)
1696  {
1697  AST_Type* actual_field_type = resolveActualType(type);
1698  const std::string lang_field_type = generator_->map_type(type);
1699  const Classification cls = classify(actual_field_type);
1700  if (cls & CL_STRING) {
1701  return " _" + name + ".~basic_string();\n";
1702  } else if (!(cls & (CL_PRIMITIVE | CL_ENUM))) {
1703  const size_t idx = lang_field_type.rfind("::");
1704  const std::string dtor_name = (idx == std::string::npos) ? lang_field_type
1705  : lang_field_type.substr(idx + 2);
1706  return " _" + name + ".~" + dtor_name + "();\n";
1707  }
1708  return "";
1709  }
1710 
1711  bool gen_union(AST_Union* u, UTL_ScopedName* name,
1712  const std::vector<AST_UnionBranch*>& branches, AST_Type* discriminator)
1713  {
1714  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1715  const char* const nm = name->last_component()->get_string();
1716  const std::string d_type = generator_->map_type(discriminator);
1717  const std::string defVal = generateDefaultValue(u);
1718 
1719  gen_union_pragma_pre();
1720  gen_common_strunion_pre(nm);
1721 
1722  be_global->lang_header_ <<
1723  " " << nm << "() { _activate(" << defVal << "); }\n"
1724  " " << nm << "(const " << nm << "& rhs);\n"
1725  " " << nm << "(" << nm << "&& rhs);\n"
1726  " " << nm << "& operator=(const " << nm << "& rhs);\n"
1727  " " << nm << "& operator=(" << nm << "&& rhs);\n"
1728  " ~" << nm << "() { _reset(); }\n\n"
1729  " " << d_type << " _d() const { return _disc; }\n"
1730  " void _d(" << d_type << " d) { _disc = d; }\n\n";
1731 
1732  std::for_each(branches.begin(), branches.end(), union_accessors);
1733  if (needsDefault(branches, discriminator)) {
1734  be_global->lang_header_ <<
1735  " void _default() { _reset(); _activate(" << defVal << "); }\n\n";
1736  }
1737 
1738  be_global->lang_header_ <<
1739  "private:\n"
1740  " bool _set = false;\n"
1741  " " << d_type << " _disc;\n\n"
1742  " union {\n";
1743 
1744  std::for_each(branches.begin(), branches.end(), union_field);
1745 
1746  be_global->lang_header_ <<
1747  " };\n\n"
1748  " void _activate(" << d_type << " d);\n"
1749  " void _reset();\n";
1750 
1751  gen_common_strunion_post(nm);
1752  gen_union_pragma_post();
1753 
1754  const ScopedNamespaceGuard namespacesCpp(name, be_global->impl_);
1755  be_global->impl_ <<
1756  nm << "::" << nm << "(const " << nm << "& rhs)\n"
1757  "{\n"
1758  " _activate(rhs._disc);\n";
1759  generateSwitchForUnion(u, "_disc", union_copy, branches, discriminator, "", "", "", false, false);
1760  be_global->impl_ <<
1761  "}\n\n" <<
1762  nm << "::" << nm << '(' << nm << "&& rhs)\n"
1763  "{\n"
1764  " _activate(rhs._disc);\n";
1765  generateSwitchForUnion(u, "_disc", union_move, branches, discriminator, "", "", "", false, false);
1766  be_global->impl_ <<
1767  "}\n\n" <<
1768  nm << "& " << nm << "::operator=(const " << nm << "& rhs)\n"
1769  "{\n"
1770  " if (this == &rhs) {\n"
1771  " return *this;\n"
1772  " }\n";
1773  generateSwitchForUnion(u, "rhs._disc", union_assign, branches, discriminator, "", "", "", false, false);
1774  be_global->impl_ <<
1775  " _disc = rhs._disc;\n"
1776  " return *this;\n"
1777  "}\n\n" <<
1778  nm << "& " << nm << "::operator=(" << nm << "&& rhs)\n"
1779  "{\n"
1780  " if (this == &rhs) {\n"
1781  " return *this;\n"
1782  " }\n";
1783  generateSwitchForUnion(u, "rhs._disc", union_move_assign, branches, discriminator, "", "", "", false, false);
1784  be_global->impl_ <<
1785  " _disc = rhs._disc;\n"
1786  " return *this;\n"
1787  "}\n\n" <<
1788  "void " << nm << "::_activate(" << d_type << " d)\n"
1789  "{\n"
1790  " if (_set && d != _disc) {\n"
1791  " _reset();\n"
1792  " }\n";
1793  generateSwitchForUnion(u, "d", union_activate, branches, discriminator, "", "", "", false, false);
1794  be_global->impl_ <<
1795  " _set = true;\n"
1796  " _disc = d;\n"
1797  "}\n\n"
1798  "void " << nm << "::_reset()\n"
1799  "{\n"
1800  " if (!_set) return;\n";
1801  generateSwitchForUnion(u, "_disc", union_reset, branches, discriminator, "", "", "", false, false);
1802  be_global->impl_ <<
1803  " _set = false;\n"
1804  "}\n\n"
1805  "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
1806  "{\n"
1807  " std::swap(lhs, rhs);\n"
1808  "}\n\n";
1809 
1810  gen_typecode_ptrs(nm);
1811  return true;
1812  }
1813 
1815 };
1817 
1819 {
1820  switch (be_global->language_mapping()) {
1821  case BE_GlobalData::LANGMAP_FACE_CXX:
1822  string_ns = "::FACE";
1823  generator_ = &FaceGenerator::instance;
1824  generator_->init();
1825  break;
1826  case BE_GlobalData::LANGMAP_SP_CXX:
1827  string_ns = "::CORBA";
1828  generator_ = &SafetyProfileGenerator::instance;
1829  generator_->init();
1830  break;
1831  case BE_GlobalData::LANGMAP_CXX11:
1832  string_ns = "::CORBA";
1833  generator_ = &Cxx11Generator::instance;
1834  generator_->init();
1835  break;
1836  default: break;
1837  }
1838 }
1839 
1840 bool langmap_generator::gen_const(UTL_ScopedName* name, bool,
1841  AST_Constant* constant)
1842 {
1843  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1844  const char* const nm = name->last_component()->get_string();
1845 
1846  const AST_Expression::ExprType type = constant->et();
1847  const bool is_enum = (type == AST_Expression::EV_enum);
1848  const std::string type_name = is_enum
1849  ? scoped(constant->enum_full_name()) : generator_->map_type(type);
1850  be_global->lang_header_ <<
1851  generator_->const_keyword(type) << ' ' << type_name << ' ' << nm << " = ";
1852 
1853  if (is_enum) {
1854  UTL_ScopedName* const enumerator = constant->constant_value()->n();
1855  if (generator_->scoped_enum()) {
1856  be_global->lang_header_ << type_name << "::"
1857  << to_string(enumerator->last_component()) << ";\n";
1858  } else {
1859  be_global->lang_header_ << dds_generator::scoped_helper(enumerator, "::") << ";\n";
1860  }
1861  } else {
1862  be_global->lang_header_ << *constant->constant_value()->ev() << ";\n";
1863  }
1864  return true;
1865 }
1866 
1867 bool langmap_generator::gen_enum(AST_Enum*, UTL_ScopedName* name,
1868  const std::vector<AST_EnumVal*>& contents,
1869  const char*)
1870 {
1871  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1872  const char* const nm = name->last_component()->get_string();
1873  const char* scoped_enum = generator_->scoped_enum() ? "class " : "";
1874  const std::string enum_base = generator_->enum_base();
1875  be_global->lang_header_ <<
1876  "enum " << scoped_enum << nm << enum_base << " {\n";
1877  for (size_t i = 0; i < contents.size(); ++i) {
1878  be_global->lang_header_ <<
1879  " " << contents[i]->local_name()->get_string()
1880  << ((i < contents.size() - 1) ? ",\n" : "\n");
1881  }
1882  be_global->lang_header_ <<
1883  "};\n\n";
1884  generator_->gen_simple_out(nm);
1885  gen_typecode(name);
1886  return true;
1887 }
1888 
1890  AST_Type::SIZE_TYPE size)
1891 {
1892  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1893  generator_->struct_decls(name, size);
1894  return true;
1895 }
1896 
1897 bool langmap_generator::gen_struct(AST_Structure* s, UTL_ScopedName* name,
1898  const std::vector<AST_Field*>& fields,
1899  AST_Type::SIZE_TYPE size,
1900  const char* x)
1901 {
1902  return generator_->gen_struct(s, name, fields, size, x);
1903 }
1904 
1905 namespace {
1906 
1907 #ifdef ACE_HAS_CDR_FIXED
1908  void gen_fixed(UTL_ScopedName* name, AST_Fixed* fixed)
1909  {
1910  be_global->add_include("FACE/Fixed.h", BE_GlobalData::STREAM_LANG_H);
1911  const char* const nm = name->last_component()->get_string();
1912  be_global->lang_header_ <<
1913  "typedef " << helpers_[HLP_FIXED] << '<' << *fixed->digits()->ev()
1914  << ", " << *fixed->scale()->ev() << "> " << nm << ";\n"
1915  "typedef " << nm << "& " << nm << "_out;\n";
1916  }
1917 #endif
1918 }
1919 
1920 bool langmap_generator::gen_typedef(AST_Typedef*, UTL_ScopedName* name, AST_Type* base,
1921  const char*)
1922 {
1923  AST_Array* arr = 0;
1924  {
1925  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1926  const char* const nm = name->last_component()->get_string();
1927 
1928  switch (base->node_type()) {
1929  case AST_Decl::NT_sequence:
1930  generator_->gen_sequence(name, dynamic_cast<AST_Sequence*>(base));
1931  break;
1932  case AST_Decl::NT_array:
1933  generator_->gen_array(name, arr = dynamic_cast<AST_Array*>(base));
1934  break;
1935  case AST_Decl::NT_fixed:
1936 # ifdef ACE_HAS_CDR_FIXED
1937  gen_fixed(name, dynamic_cast<AST_Fixed*>(base));
1938  break;
1939 # else
1940  std::cerr << "ERROR: fixed data type (for " << nm << ") is not supported"
1941  " with this version of ACE+TAO\n";
1942  return false;
1943 # endif
1944  default:
1945  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
1946  be_global->lang_header_ <<
1947  "using " << nm << " = " << generator_->map_type(base) << ";\n";
1948  } else {
1949  be_global->lang_header_ <<
1950  "typedef " << generator_->map_type(base) << ' ' << nm << ";\n";
1951  }
1952 
1953  generator_->gen_typedef_varout(nm, base);
1954 
1955  AST_Type* actual_base = resolveActualType(base);
1956  if (actual_base->node_type() == AST_Decl::NT_array) {
1957  generator_->gen_array_typedef(nm, base);
1958  }
1959 
1960  break;
1961  }
1962 
1963  gen_typecode(name);
1964  }
1965  if (arr) generator_->gen_array_traits(name, arr);
1966  return true;
1967 }
1968 
1969 bool langmap_generator::gen_union_fwd(AST_UnionFwd* node,
1970  UTL_ScopedName* name,
1971  AST_Type::SIZE_TYPE)
1972 {
1973  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1974  generator_->struct_decls(name, node->full_definition()->size_type(), "class");
1975  return true;
1976 }
1977 
1978 bool langmap_generator::gen_union(AST_Union* u, UTL_ScopedName* name,
1979  const std::vector<AST_UnionBranch*>& branches,
1980  AST_Type* discriminator,
1981  const char*)
1982 {
1983  return generator_->gen_union(u, name, branches, discriminator);
1984 }
1985 
1987 {
1988  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
1989  return true;
1990  }
1991 
1992  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1993 
1994  be_global->add_include("<tao/Objref_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
1995  const char* const nm = name->last_component()->get_string();
1996  be_global->lang_header_ <<
1997  "class " << nm << ";\n"
1998  "typedef " << nm << '*' << nm << "_ptr;\n"
1999  "typedef TAO_Objref_Var_T<" << nm << "> " << nm << "_var;\n"
2000  "typedef TAO_Objref_Out_T<" << nm << "> " << nm << "_out;\n";
2001 
2002  return true;
2003 }
static size_t countLabels(const std::vector< AST_UnionBranch *> &branches)
bool gen_union(AST_Union *, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *repoid)
bool gen_union(AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
Classification classify(AST_Type *type)
virtual void struct_decls(UTL_ScopedName *name, AST_Type::SIZE_TYPE size, const char *struct_or_class="struct")
static std::string union_activate(const std::string &, AST_Decl *, const std::string &name, AST_Type *type, const std::string &, bool, Intro &, const std::string &)
#define ACE_ERROR(X)
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
const char * c_str(void) const
virtual void gen_array_typedef(const char *nm, AST_Type *base)
const Classification CL_STRING
bool gen_union_fwd(AST_UnionFwd *, UTL_ScopedName *name, AST_Type::SIZE_TYPE size)
void gen_array_typedef(const char *, AST_Type *)
static std::string union_assign(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
Iterator begin() const
bool gen_typedef(AST_Typedef *, UTL_ScopedName *name, AST_Type *type, const char *repoid)
bool gen_enum(AST_Enum *, UTL_ScopedName *name, const std::vector< AST_EnumVal *> &contents, const char *repoid)
static FaceGenerator instance
virtual ~GeneratorBase()
const Classification CL_WIDE
bool gen_struct_fwd(UTL_ScopedName *name, AST_Type::SIZE_TYPE size)
const Classification CL_PRIMITIVE
static std::string union_move(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
std::string map_type_string(AST_PredefinedType::PredefinedType chartype, bool)
virtual std::string const_keyword(AST_Expression::ExprType)
virtual void gen_simple_out(const char *nm)
static std::string union_reset(const std::string &, AST_Decl *, const std::string &name, AST_Type *type, const std::string &, bool, Intro &, const std::string &)
bool gen_struct(AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *)
static void gen_common_strunion_post(const char *nm)
const std::string name_
Definition: field_info.h:41
T::rv_reference move(T &p)
Definition: unique_ptr.h:141
virtual void gen_array_traits(UTL_ScopedName *tdname, AST_Array *arr)
void operator()(AST_UnionBranch *branch)
void gen_simple_out(const char *)
const Classification CL_ARRAY
AST_Type * act_
Definition: field_info.h:46
virtual bool scoped_enum()
bool needSyntheticDefault(AST_Type *disc, size_t n_labels)
static void gen_array(AST_Array *arr, const std::string &type, const std::string &elem, const std::string &ind="")
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)
static void union_accessors(AST_UnionBranch *branch)
static void gen_common_strunion_pre(const char *nm)
std::string getEnumLabel(AST_Expression *label_val, AST_Type *disc)
const AstTypeClassification::Classification cls_
Definition: field_info.h:47
std::string index_
bool gen_struct(AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *)
bool gen_struct(AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)
static std::string generateReset(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
static SafetyProfileGenerator instance
virtual void gen_array(UTL_ScopedName *tdname, AST_Array *arr)
static void gen_typecode_ptrs(const std::string &type)
virtual void gen_sequence(UTL_ScopedName *tdname, AST_Sequence *seq)
static std::string union_copy(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
AST_Type * resolveActualType(AST_Type *element)
std::string const_keyword(AST_Expression::ExprType type)
virtual void init()
int init(void)
static void gen_sequence(const std::string &type, const std::string &elem, const std::string &ind="")
void gen_array_traits(UTL_ScopedName *, AST_Array *)
void struct_decls(UTL_ScopedName *name, AST_Type::SIZE_TYPE, const char *)
static std::string generateDefaultValue(AST_Union *the_union)
ACE_UINT32 ULong
virtual std::string enum_base()
bool empty(void) const
virtual std::string map_type_string(AST_PredefinedType::PredefinedType chartype, bool constant)
void gen_sequence(UTL_ScopedName *tdname, AST_Sequence *seq)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")
const Classification CL_FIXED
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
AST_Type * type_
Definition: field_info.h:40
AST_Array * arr_
Definition: field_info.h:48
static std::string generateAssign(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
static bool needsDefault(const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
static bool hasDefaultLabel(const std::vector< AST_UnionBranch *> &branches)
void gen_typedef_varout(const char *, AST_Type *)
std::string enum_base()
void gen_array(UTL_ScopedName *tdname, AST_Array *arr)
const Classification CL_STRUCTURE
virtual bool gen_union(AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
AST_Type * as_base_
Definition: field_info.h:50
std::string map_type(AST_Type *type)
bool gen_interf_fwd(UTL_ScopedName *name)
static Cxx11Generator instance
bool gen_const(UTL_ScopedName *name, bool nestedInInteface, AST_Constant *constant)
static void gen_struct_members(AST_Field *field)
BE_GlobalData * be_global
Definition: be_global.cpp:44
ACE_CDR::ULong array_element_count(AST_Array *arr)
const Classification CL_INTERFACE
std::string map_type(AST_Expression::ExprType type)
const char * to_string(MessageId value)
void assign(EntityId_t &dest, const EntityId_t &src)
Definition: GuidUtils.h:157
bool gen_struct(AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE, const char *)
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
virtual void gen_typedef_varout(const char *nm, AST_Type *base)
const Classification CL_ENUM
GenerateUnionAccessors(AST_Union *u, AST_Type *d)
const Classification CL_SEQUENCE
LM_ERROR
static void union_field(AST_UnionBranch *branch)
static std::string generateEqual(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
AST_Sequence * seq_
Definition: field_info.h:49
void gen_sequence(UTL_ScopedName *tdname, AST_Sequence *seq)
const Classification CL_UNION
static void generate_union_field(AST_UnionBranch *branch)
static std::string union_move_assign(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
std::string map_type(AST_Field *field)
static std::string generateCopyCtor(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
const std::string type_name_
Definition: field_info.h:45