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

Public Member Functions

virtual void init ()
 
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 FaceGenerator 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 876 of file langmap_generator.cpp.

Member Function Documentation

◆ gen_sequence()

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

Implements GeneratorBase.

Definition at line 917 of file langmap_generator.cpp.

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

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  }
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 FaceGenerator::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 999 of file langmap_generator.cpp.

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

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  }
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 FaceGenerator::init ( void  )
inlinevirtual

Implements GeneratorBase.

Definition at line 878 of file langmap_generator.cpp.

References be_global.

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

Member Data Documentation

◆ instance

FaceGenerator FaceGenerator::instance
static

Definition at line 1107 of file langmap_generator.cpp.

Referenced by langmap_generator::init().


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