OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Cxx11Generator Struct Reference
Inheritance diagram for Cxx11Generator:
Inheritance graph
[legend]
Collaboration diagram for Cxx11Generator:
Collaboration graph
[legend]

Public Member Functions

void init ()
 
std::string map_type_string (AST_PredefinedType::PredefinedType chartype, bool)
 
std::string const_keyword (AST_Expression::ExprType type)
 
void gen_simple_out (const char *)
 
bool scoped_enum ()
 
std::string enum_base ()
 
void gen_union_pragma_pre ()
 
void gen_union_pragma_post ()
 
void struct_decls (UTL_ScopedName *name, AST_Type::SIZE_TYPE, const char *)
 
void gen_array (UTL_ScopedName *tdname, AST_Array *arr)
 
void gen_array_traits (UTL_ScopedName *, AST_Array *)
 
void gen_array_typedef (const char *, AST_Type *)
 
void gen_typedef_varout (const char *, AST_Type *)
 
void gen_sequence (UTL_ScopedName *tdname, AST_Sequence *seq)
 
bool gen_struct (AST_Structure *, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE, const char *)
 
bool gen_union (AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
 
- Public Member Functions inherited from GeneratorBase
virtual ~GeneratorBase ()
 
std::string map_type (AST_Type *type)
 
std::string map_type (AST_Field *field)
 
std::string map_type (AST_Expression::ExprType type)
 

Static Public Member Functions

static void gen_typecode_ptrs (const std::string &type)
 
static void gen_array (AST_Array *arr, const std::string &type, const std::string &elem, const std::string &ind="")
 
static void gen_sequence (const std::string &type, const std::string &elem, const std::string &ind="")
 
static void gen_common_strunion_pre (const char *nm)
 
static void gen_common_strunion_post (const char *nm)
 
static void gen_struct_members (AST_Field *field)
 
static void union_field (AST_UnionBranch *branch)
 
static void union_accessors (AST_UnionBranch *branch)
 
static std::string union_copy (const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
 
static std::string union_move (const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
 
static std::string union_assign (const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
 
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 &)
 
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 &)
 
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 &)
 
- Static Public Member Functions inherited from GeneratorBase
static std::string generateDefaultValue (AST_Union *the_union)
 
static bool hasDefaultLabel (const std::vector< AST_UnionBranch *> &branches)
 
static size_t countLabels (const std::vector< AST_UnionBranch *> &branches)
 
static bool needsDefault (const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
 
static void generate_union_field (AST_UnionBranch *branch)
 
static std::string generateCopyCtor (const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
 
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 std::string generateEqual (const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
 
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 Public Attributes

static Cxx11Generator instance
 

Detailed Description

Definition at line 1346 of file langmap_generator.cpp.

Member Function Documentation

◆ const_keyword()

std::string Cxx11Generator::const_keyword ( AST_Expression::ExprType  type)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1405 of file langmap_generator.cpp.

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  }

◆ enum_base()

std::string Cxx11Generator::enum_base ( )
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1419 of file langmap_generator.cpp.

1419 { return " : uint32_t"; }

◆ gen_array() [1/2]

static void Cxx11Generator::gen_array ( AST_Array *  arr,
const std::string &  type,
const std::string &  elem,
const std::string &  ind = "" 
)
inlinestatic

Definition at line 1446 of file langmap_generator.cpp.

References be_global.

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  }
ACE_UINT32 ULong
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_array() [2/2]

void Cxx11Generator::gen_array ( UTL_ScopedName *  tdname,
AST_Array *  arr 
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1458 of file langmap_generator.cpp.

1459  {
1460  gen_array(arr, tdname->last_component()->get_string(), map_type(arr->base_type()));
1461  }
std::string map_type(AST_Type *type)
static void gen_array(AST_Array *arr, const std::string &type, const std::string &elem, const std::string &ind="")

◆ gen_array_traits()

void Cxx11Generator::gen_array_traits ( UTL_ScopedName *  ,
AST_Array *   
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1463 of file langmap_generator.cpp.

1463 {}

◆ gen_array_typedef()

void Cxx11Generator::gen_array_typedef ( const char *  ,
AST_Type *   
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1464 of file langmap_generator.cpp.

1464 {}

◆ gen_common_strunion_post()

static void Cxx11Generator::gen_common_strunion_post ( const char *  nm)
inlinestatic

Definition at line 1487 of file langmap_generator.cpp.

References be_global.

1488  {
1489  be_global->lang_header_ <<
1490  "};\n\n"
1491  << exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n";
1492  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_common_strunion_pre()

static void Cxx11Generator::gen_common_strunion_pre ( const char *  nm)
inlinestatic

Definition at line 1478 of file langmap_generator.cpp.

References be_global.

1479  {
1480  be_global->lang_header_ <<
1481  "\n"
1482  "class " << exporter() << nm << "\n"
1483  "{\n"
1484  "public:\n\n";
1485  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_sequence() [1/2]

static void Cxx11Generator::gen_sequence ( const std::string &  type,
const std::string &  elem,
const std::string &  ind = "" 
)
inlinestatic

Definition at line 1467 of file langmap_generator.cpp.

References be_global.

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  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_sequence() [2/2]

void Cxx11Generator::gen_sequence ( UTL_ScopedName *  tdname,
AST_Sequence *  seq 
)
inlinevirtual

Implements GeneratorBase.

Definition at line 1473 of file langmap_generator.cpp.

1474  {
1475  gen_sequence(tdname->last_component()->get_string(), map_type(seq->base_type()));
1476  }
std::string map_type(AST_Type *type)
static void gen_sequence(const std::string &type, const std::string &elem, const std::string &ind="")

◆ gen_simple_out()

void Cxx11Generator::gen_simple_out ( const char *  )
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1416 of file langmap_generator.cpp.

1416 {}

◆ gen_struct()

bool Cxx11Generator::gen_struct ( AST_Structure *  ,
UTL_ScopedName *  name,
const std::vector< AST_Field *> &  fields,
AST_Type::SIZE_TYPE  ,
const char *   
)
inlinevirtual

Implements GeneratorBase.

Definition at line 1544 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, and AstTypeClassification::classify().

1547  {
1548  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1549  const ScopedNamespaceGuard namespaces2(name, be_global->impl_);
1550  const char* const nm = name->last_component()->get_string();
1552 
1553  std::for_each(fields.begin(), fields.end(), gen_struct_members);
1554 
1555  be_global->lang_header_ <<
1556  " " << nm << "() = default;\n"
1557  " " << (fields.size() == 1 ? "explicit " : "") << nm << '(';
1558  be_global->impl_ <<
1559  nm << "::" << nm << '(';
1560 
1561  std::string init_list, swaps;
1562  for (size_t i = 0; i < fields.size(); ++i) {
1563  const std::string fn = fields[i]->local_name()->get_string();
1564  const std::string ft = map_type(fields[i]);
1565  const Classification cls = classify(fields[i]->field_type());
1566  const bool by_ref = (cls & (CL_PRIMITIVE | CL_ENUM)) == 0;
1567  const std::string param = (by_ref ? "const " : "") + ft + (by_ref ? "&" : "")
1568  + ' ' + fn + (i < fields.size() - 1 ? ",\n " : ")");
1569  be_global->lang_header_ << param;
1570  be_global->impl_ << param;
1571  init_list += '_' + fn + '(' + fn + ')';
1572  if (i < fields.size() - 1) init_list += "\n , ";
1573  swaps += " swap(lhs._" + fn + ", rhs._" + fn + ");\n";
1574  }
1575  be_global->lang_header_ << ";\n\n";
1576  be_global->impl_ << "\n : " << init_list << "\n{}\n\n";
1577 
1579  be_global->impl_ <<
1580  "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
1581  "{\n"
1582  " using std::swap;\n"
1583  << swaps << "}\n\n";
1584  gen_typecode_ptrs(nm);
1585  return true;
1586  }
std::string map_type(AST_Type *type)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
static void gen_common_strunion_post(const char *nm)
static void gen_common_strunion_pre(const char *nm)
const Classification CL_ENUM
static void gen_typecode_ptrs(const std::string &type)
const char *const name
Definition: debug.cpp:60
static void gen_struct_members(AST_Field *field)
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_struct_members()

static void Cxx11Generator::gen_struct_members ( AST_Field *  field)
inlinestatic

Definition at line 1494 of file langmap_generator.cpp.

References FieldInfo::act_, FieldInfo::arr_, FieldInfo::as_base_, OpenDDS::DCPS::assign(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, FieldInfo::cls_, OpenDDS::DCPS::move(), FieldInfo::name_, FieldInfo::seq_, FieldInfo::type_, and FieldInfo::type_name_.

1495  {
1496  FieldInfo af(*field);
1497  if (af.type_->anonymous() && af.as_base_) {
1498  const std::string elem_type = generator_->map_type(af.as_base_);
1499  if (af.arr_) {
1500  gen_array(af.arr_, af.type_name_, elem_type, " ");
1501  } else if (af.seq_) {
1502  gen_sequence(af.type_name_, elem_type, " ");
1503  }
1504  }
1505 
1506  const std::string lang_field_type = generator_->map_type(field);
1507  const std::string assign_pre = "{ _" + af.name_ + " = ",
1508  assign = assign_pre + "val; }\n",
1509  move = assign_pre + "std::move(val); }\n",
1510  ret = "{ return _" + af.name_ + "; }\n";
1511  std::string initializer;
1512  if (af.cls_ & (CL_PRIMITIVE | CL_ENUM)) {
1513  be_global->lang_header_ <<
1514  " void " << af.name_ << '(' << lang_field_type << " val) " << assign <<
1515  " " << lang_field_type << ' ' << af.name_ << "() const " << ret <<
1516  " " << lang_field_type << "& " << af.name_ << "() " << ret;
1517  if (af.cls_ & CL_ENUM) {
1518  AST_Enum* enu = dynamic_cast<AST_Enum*>(af.act_);
1519  for (UTL_ScopeActiveIterator it(enu, UTL_Scope::IK_decls); !it.is_done(); it.next()) {
1520  if (it.item()->node_type() == AST_Decl::NT_enum_val) {
1521  initializer = '{' + generator_->map_type(af.type_)
1522  + "::" + it.item()->local_name()->get_string() + '}';
1523  break;
1524  }
1525  }
1526  } else {
1527  initializer = "{}";
1528  }
1529  } else {
1530  if (af.cls_ & CL_ARRAY) {
1531  initializer = "{}";
1532  }
1533  be_global->add_include("<utility>", BE_GlobalData::STREAM_LANG_H);
1534  be_global->lang_header_ <<
1535  " void " << af.name_ << "(const " << lang_field_type << "& val) " << assign <<
1536  " void " << af.name_ << '(' << lang_field_type << "&& val) " << move <<
1537  " const " << lang_field_type << "& " << af.name_ << "() const " << ret <<
1538  " " << lang_field_type << "& " << af.name_ << "() " << ret;
1539  }
1540  be_global->lang_header_ <<
1541  " " << lang_field_type << " _" << af.name_ << initializer << ";\n\n";
1542  }
const Classification CL_ARRAY
static void gen_sequence(const std::string &type, const std::string &elem, const std::string &ind="")
const Classification CL_PRIMITIVE
static void gen_array(AST_Array *arr, const std::string &type, const std::string &elem, const std::string &ind="")
T::rv_reference move(T &p)
Definition: unique_ptr.h:141
const Classification CL_ENUM
void assign(EntityId_t &dest, const EntityId_t &src)
Definition: GuidUtils.h:157
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_typecode_ptrs()

static void Cxx11Generator::gen_typecode_ptrs ( const std::string &  type)
inlinestatic

Definition at line 1391 of file langmap_generator.cpp.

References be_global.

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  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_typedef_varout()

void Cxx11Generator::gen_typedef_varout ( const char *  ,
AST_Type *   
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1465 of file langmap_generator.cpp.

1465 {}

◆ gen_union()

bool Cxx11Generator::gen_union ( AST_Union *  u,
UTL_ScopedName *  name,
const std::vector< AST_UnionBranch *> &  branches,
AST_Type *  discriminator 
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1710 of file langmap_generator.cpp.

References be_global, and generateSwitchForUnion().

1712  {
1713  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
1714  const char* const nm = name->last_component()->get_string();
1715  const std::string d_type = generator_->map_type(discriminator);
1716  const std::string defVal = generateDefaultValue(u);
1717 
1720 
1721  be_global->lang_header_ <<
1722  " " << nm << "() { _activate(" << defVal << "); }\n"
1723  " " << nm << "(const " << nm << "& rhs);\n"
1724  " " << nm << "(" << nm << "&& rhs);\n"
1725  " " << nm << "& operator=(const " << nm << "& rhs);\n"
1726  " " << nm << "& operator=(" << nm << "&& rhs);\n"
1727  " ~" << nm << "() { _reset(); }\n\n"
1728  " " << d_type << " _d() const { return _disc; }\n"
1729  " void _d(" << d_type << " d) { _disc = d; }\n\n";
1730 
1731  std::for_each(branches.begin(), branches.end(), union_accessors);
1732  if (needsDefault(branches, discriminator)) {
1733  be_global->lang_header_ <<
1734  " void _default() { _reset(); _activate(" << defVal << "); }\n\n";
1735  }
1736 
1737  be_global->lang_header_ <<
1738  "private:\n"
1739  " bool _set = false;\n"
1740  " " << d_type << " _disc;\n\n"
1741  " union {\n";
1742 
1743  std::for_each(branches.begin(), branches.end(), union_field);
1744 
1745  be_global->lang_header_ <<
1746  " };\n\n"
1747  " void _activate(" << d_type << " d);\n"
1748  " void _reset();\n";
1749 
1752 
1753  const ScopedNamespaceGuard namespacesCpp(name, be_global->impl_);
1754  be_global->impl_ <<
1755  nm << "::" << nm << "(const " << nm << "& rhs)\n"
1756  "{\n"
1757  " _activate(rhs._disc);\n";
1758  generateSwitchForUnion(u, "_disc", union_copy, branches, discriminator, "", "", "", false, false);
1759  be_global->impl_ <<
1760  "}\n\n" <<
1761  nm << "::" << nm << '(' << nm << "&& rhs)\n"
1762  "{\n"
1763  " _activate(rhs._disc);\n";
1764  generateSwitchForUnion(u, "_disc", union_move, branches, discriminator, "", "", "", false, false);
1765  be_global->impl_ <<
1766  "}\n\n" <<
1767  nm << "& " << nm << "::operator=(const " << nm << "& rhs)\n"
1768  "{\n"
1769  " if (this == &rhs) {\n"
1770  " return *this;\n"
1771  " }\n";
1772  generateSwitchForUnion(u, "rhs._disc", union_assign, branches, discriminator, "", "", "", false, false);
1773  be_global->impl_ <<
1774  " _disc = rhs._disc;\n"
1775  " return *this;\n"
1776  "}\n\n" <<
1777  nm << "& " << nm << "::operator=(" << nm << "&& rhs)\n"
1778  "{\n"
1779  " if (this == &rhs) {\n"
1780  " return *this;\n"
1781  " }\n";
1782  generateSwitchForUnion(u, "rhs._disc", union_move_assign, branches, discriminator, "", "", "", false, false);
1783  be_global->impl_ <<
1784  " _disc = rhs._disc;\n"
1785  " return *this;\n"
1786  "}\n\n" <<
1787  "void " << nm << "::_activate(" << d_type << " d)\n"
1788  "{\n"
1789  " if (_set && d != _disc) {\n"
1790  " _reset();\n"
1791  " }\n";
1792  generateSwitchForUnion(u, "d", union_activate, branches, discriminator, "", "", "", false, false);
1793  be_global->impl_ <<
1794  " _set = true;\n"
1795  " _disc = d;\n"
1796  "}\n\n"
1797  "void " << nm << "::_reset()\n"
1798  "{\n"
1799  " if (!_set) return;\n";
1800  generateSwitchForUnion(u, "_disc", union_reset, branches, discriminator, "", "", "", false, false);
1801  be_global->impl_ <<
1802  " _set = false;\n"
1803  "}\n\n"
1804  "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
1805  "{\n"
1806  " std::swap(lhs, rhs);\n"
1807  "}\n\n";
1808 
1809  gen_typecode_ptrs(nm);
1810  return true;
1811  }
static std::string union_move(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
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 &)
static void gen_common_strunion_post(const char *nm)
static void gen_common_strunion_pre(const char *nm)
static std::string union_assign(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
static void union_accessors(AST_UnionBranch *branch)
static void union_field(AST_UnionBranch *branch)
static void gen_typecode_ptrs(const std::string &type)
static bool needsDefault(const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
static std::string union_copy(const std::string &, AST_Decl *, const std::string &name, AST_Type *, const std::string &, bool, Intro &, const std::string &)
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 &)
const char *const name
Definition: debug.cpp:60
static std::string generateDefaultValue(AST_Union *the_union)
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)
BE_GlobalData * be_global
Definition: be_global.cpp:43
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 &)

◆ gen_union_pragma_post()

void Cxx11Generator::gen_union_pragma_post ( )
inline

Definition at line 1432 of file langmap_generator.cpp.

References be_global.

1433  {
1434  be_global->lang_header_ <<
1435  "#if defined(__GNUC__) && !defined(__clang__)\n"
1436  "# pragma GCC diagnostic pop\n"
1437  "#endif\n\n";
1438  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_union_pragma_pre()

void Cxx11Generator::gen_union_pragma_pre ( )
inline

Definition at line 1421 of file langmap_generator.cpp.

References be_global.

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  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ init()

void Cxx11Generator::init ( void  )
inlinevirtual

Implements GeneratorBase.

Definition at line 1348 of file langmap_generator.cpp.

References be_global.

Referenced by langmap_generator::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  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ map_type_string()

std::string Cxx11Generator::map_type_string ( AST_PredefinedType::PredefinedType  chartype,
bool   
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1400 of file langmap_generator.cpp.

1401  {
1402  return chartype == AST_PredefinedType::PT_char ? "std::string" : "std::wstring";
1403  }

◆ scoped_enum()

bool Cxx11Generator::scoped_enum ( )
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1418 of file langmap_generator.cpp.

1418 { return true; }

◆ struct_decls()

void Cxx11Generator::struct_decls ( UTL_ScopedName *  name,
AST_Type::SIZE_TYPE  ,
const char *   
)
inlinevirtual

Reimplemented from GeneratorBase.

Definition at line 1440 of file langmap_generator.cpp.

References be_global.

1441  {
1442  be_global->lang_header_ <<
1443  "class " << name->last_component()->get_string() << ";\n";
1444  }
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ union_accessors()

static void Cxx11Generator::union_accessors ( AST_UnionBranch *  branch)
inlinestatic

Definition at line 1597 of file langmap_generator.cpp.

References OpenDDS::DCPS::assign(), be_global, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::classify(), getEnumLabel(), OpenDDS::DCPS::move(), and AstTypeClassification::resolveActualType().

1598  {
1599  AST_Type* field_type = branch->field_type();
1600  AST_Type* actual_field_type = resolveActualType(field_type);
1601  const std::string lang_field_type = generator_->map_type(field_type);
1602  const Classification cls = classify(actual_field_type);
1603  const char* nm = branch->local_name()->get_string();
1604 
1605  AST_UnionLabel* label = branch->label(0);
1606  AST_Union* union_ = dynamic_cast<AST_Union*>(branch->defined_in());
1607  AST_Type* dtype = resolveActualType(union_->disc_type());
1608  const std::string disc_type = generator_->map_type(dtype);
1609 
1610  std::string dval;
1611  if (label->label_kind() == AST_UnionLabel::UL_default) {
1612  dval = generateDefaultValue(union_);
1613  } else if (dtype->node_type() == AST_Decl::NT_enum) {
1614  dval = getEnumLabel(label->label_val(), dtype);
1615  } else {
1616  std::ostringstream strm;
1617  strm << *label->label_val()->ev();
1618  dval = strm.str();
1619  }
1620 
1621  std::string disc_param, disc_name = dval;
1622  if (label->label_kind() == AST_UnionLabel::UL_default ||
1623  branch->label_list_length() > 1) {
1624  disc_name = "disc";
1625  disc_param = ", " + disc_type + " disc = " + dval;
1626  }
1627 
1628  const std::string assign_pre = "{ _activate(" + disc_name + "); _"
1629  + std::string(nm) + " = ",
1630  assign = assign_pre + "val; }\n",
1631  move = assign_pre + "std::move(val); }\n",
1632  ret = "{ return _" + std::string(nm) + "; }\n";
1633  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
1634  be_global->lang_header_ <<
1635  " void " << nm << '(' << lang_field_type << " val" << disc_param
1636  << ") " << assign <<
1637  " " << lang_field_type << ' ' << nm << "() const " << ret <<
1638  " " << lang_field_type << "& " << nm << "() " << ret << "\n";
1639  } else {
1640  be_global->add_include("<utility>", BE_GlobalData::STREAM_LANG_H);
1641  be_global->lang_header_ <<
1642  " void " << nm << "(const " << lang_field_type << "& val" << disc_param
1643  << ") " << assign <<
1644  " void " << nm << '(' << lang_field_type << "&& val" << disc_param
1645  << ") " << move <<
1646  " const " << lang_field_type << "& " << nm << "() const " << ret <<
1647  " " << lang_field_type << "& " << nm << "() " << ret << "\n";
1648  }
1649  }
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
T::rv_reference move(T &p)
Definition: unique_ptr.h:141
const Classification CL_ENUM
std::string getEnumLabel(AST_Expression *label_val, AST_Type *disc)
void assign(EntityId_t &dest, const EntityId_t &src)
Definition: GuidUtils.h:157
static std::string generateDefaultValue(AST_Union *the_union)
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ union_activate()

static std::string Cxx11Generator::union_activate ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 1679 of file langmap_generator.cpp.

References AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

1682  {
1683  AST_Type* actual_field_type = resolveActualType(type);
1684  const std::string lang_field_type = generator_->map_type(type);
1685  const Classification cls = classify(actual_field_type);
1686  if (!(cls & (CL_PRIMITIVE | CL_ENUM))) {
1687  return " new(&_" + name + ") " + lang_field_type + ";\n";
1688  }
1689  return "";
1690  }
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_ENUM
const char *const name
Definition: debug.cpp:60

◆ union_assign()

static std::string Cxx11Generator::union_assign ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  ,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 1665 of file langmap_generator.cpp.

1668  {
1669  return " " + name + "(rhs._" + name + ");\n";
1670  }
const char *const name
Definition: debug.cpp:60

◆ union_copy()

static std::string Cxx11Generator::union_copy ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  ,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 1651 of file langmap_generator.cpp.

1654  {
1655  return " _" + name + " = rhs._" + name + ";\n";
1656  }
const char *const name
Definition: debug.cpp:60

◆ union_field()

static void Cxx11Generator::union_field ( AST_UnionBranch *  branch)
inlinestatic

Definition at line 1588 of file langmap_generator.cpp.

References be_global.

1589  {
1590  AST_Type* field_type = branch->field_type();
1591  const std::string lang_field_type = generator_->map_type(field_type);
1592  be_global->lang_header_ <<
1593  " " << lang_field_type << " _" << branch->local_name()->get_string()
1594  << ";\n";
1595  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ union_move()

static std::string Cxx11Generator::union_move ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  ,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 1658 of file langmap_generator.cpp.

1661  {
1662  return " _" + name + " = std::move(rhs._" + name + ");\n";
1663  }
const char *const name
Definition: debug.cpp:60

◆ union_move_assign()

static std::string Cxx11Generator::union_move_assign ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  ,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 1672 of file langmap_generator.cpp.

1675  {
1676  return " " + name + "(std::move(rhs._" + name + "));\n";
1677  }
const char *const name
Definition: debug.cpp:60

◆ union_reset()

static std::string Cxx11Generator::union_reset ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 1692 of file langmap_generator.cpp.

References AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_STRING, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

1695  {
1696  AST_Type* actual_field_type = resolveActualType(type);
1697  const std::string lang_field_type = generator_->map_type(type);
1698  const Classification cls = classify(actual_field_type);
1699  if (cls & CL_STRING) {
1700  return " _" + name + ".~basic_string();\n";
1701  } else if (!(cls & (CL_PRIMITIVE | CL_ENUM))) {
1702  const size_t idx = lang_field_type.rfind("::");
1703  const std::string dtor_name = (idx == std::string::npos) ? lang_field_type
1704  : lang_field_type.substr(idx + 2);
1705  return " _" + name + ".~" + dtor_name + "();\n";
1706  }
1707  return "";
1708  }
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const char *const name
Definition: debug.cpp:60

Member Data Documentation

◆ instance

Cxx11Generator Cxx11Generator::instance
static

Definition at line 1813 of file langmap_generator.cpp.

Referenced by langmap_generator::init().


The documentation for this struct was generated from the following file: