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

Public Member Functions

virtual void init ()
 
virtual 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 size, const char *)
 
- Public Member Functions inherited from GeneratorBase
virtual ~GeneratorBase ()
 
virtual std::string const_keyword (AST_Expression::ExprType)
 
std::string map_type (AST_Type *type)
 
std::string map_type (AST_Field *field)
 
virtual std::string map_type_string (AST_PredefinedType::PredefinedType chartype, bool constant)
 
std::string map_type (AST_Expression::ExprType type)
 
virtual void gen_simple_out (const char *nm)
 
virtual bool scoped_enum ()
 
virtual std::string enum_base ()
 
virtual void struct_decls (UTL_ScopedName *name, AST_Type::SIZE_TYPE size, const char *struct_or_class="struct")
 
virtual bool gen_union (AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
 
virtual void gen_array (UTL_ScopedName *tdname, AST_Array *arr)
 
virtual void gen_array_traits (UTL_ScopedName *tdname, AST_Array *arr)
 
virtual void gen_array_typedef (const char *nm, AST_Type *base)
 
virtual void gen_typedef_varout (const char *nm, AST_Type *base)
 

Static Public Attributes

static SafetyProfileGenerator instance
 

Additional Inherited Members

- 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 &)
 

Detailed Description

Definition at line 1111 of file langmap_generator.cpp.

Member Function Documentation

◆ gen_sequence()

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

Implements GeneratorBase.

Definition at line 1154 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, and AstTypeClassification::classify().

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  }
const Classification CL_ARRAY
std::string map_type(AST_Type *type)
Classification classify(AST_Type *type)
const Classification CL_STRING
BE_GlobalData * be_global
Definition: be_global.cpp:43
const Classification CL_WIDE

◆ gen_struct()

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

Implements GeneratorBase.

Definition at line 1235 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), NestedForLoops::index_, and AstTypeClassification::resolveActualType().

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  }
const Classification CL_ARRAY
std::string map_type(AST_Type *type)
AST_Type * resolveActualType(AST_Type *element)
Classification classify(AST_Type *type)
const Classification CL_STRING
ACE_UINT32 ULong
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43
const Classification CL_WIDE
virtual void struct_decls(UTL_ScopedName *name, AST_Type::SIZE_TYPE size, const char *struct_or_class="struct")

◆ init()

virtual void SafetyProfileGenerator::init ( void  )
inlinevirtual

Implements GeneratorBase.

Definition at line 1113 of file langmap_generator.cpp.

References be_global.

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

Member Data Documentation

◆ instance

SafetyProfileGenerator SafetyProfileGenerator::instance
static

Definition at line 1342 of file langmap_generator.cpp.

Referenced by langmap_generator::init().


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