SafetyProfileGenerator Class Reference

Inheritance diagram for SafetyProfileGenerator:
Inheritance graph
[legend]
Collaboration diagram for SafetyProfileGenerator:
Collaboration graph
[legend]

List of all members.

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

Static Public Attributes

static SafetyProfileGenerator instance

Detailed Description

Definition at line 812 of file langmap_generator.cpp.


Member Function Documentation

virtual void SafetyProfileGenerator::gen_sequence ( UTL_ScopedName *  tdname,
AST_Sequence *  seq 
) [inline, virtual]

Implements GeneratorBase.

Definition at line 852 of file langmap_generator.cpp.

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

00853   {
00854     be_global->add_include("<tao/Seq_Out_T.h>", BE_GlobalData::STREAM_LANG_H);
00855     be_global->add_include("dds/DCPS/SafetyProfileSequence.h", BE_GlobalData::STREAM_LANG_H);
00856     be_global->add_include("dds/DCPS/SafetyProfileSequenceVar.h", BE_GlobalData::STREAM_LANG_H);
00857     const char* const nm = tdname->last_component()->get_string();
00858     AST_Type* elem = seq->base_type();
00859     const Classification elem_cls = classify(elem);
00860     const bool bounded = !seq->unbounded();
00861     const Helper var = (elem->size_type() == AST_Type::VARIABLE)
00862                         ? HLP_SEQ_VAR_VAR : HLP_SEQ_FIX_VAR,
00863       out = HLP_SEQ_OUT;
00864 
00865     std::string elem_type = map_type(elem), extra_tmp_args;
00866     if (elem_cls & CL_STRING) {
00867       const AST_Expression::ExprType char_type = (elem_cls & CL_WIDE)
00868         ? AST_Expression::EV_wchar : AST_Expression::EV_char;
00869       extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::StringEltPolicy< "
00870         + map_type(char_type) + ">";
00871     } else if (elem_cls & CL_ARRAY) {
00872       extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::ArrayEltPolicy<"
00873         + elem_type + "_forany>";
00874     } else if (elem->size_type() == AST_Type::VARIABLE) {
00875       extra_tmp_args = ", " +  helpers_[HLP_SEQ_NS] + "::VariEltPolicy<"
00876         + elem_type + ">";
00877     }
00878 
00879     std::string bound = helpers_[HLP_SEQ_NS] + "::Unbounded";
00880     if (bounded) {
00881       std::ostringstream oss;
00882       oss << helpers_[HLP_SEQ_NS] << "::Bounded<"
00883         << seq->max_size()->ev()->u.ulval << '>';
00884       bound = oss.str();
00885     }
00886 
00887     const std::string base = helpers_[HLP_SEQ] + "< " + elem_type + ", " + bound
00888                            + extra_tmp_args + " >",
00889       len_type = primtype_[AST_PredefinedType::PT_ulong],
00890       flag_type = primtype_[AST_PredefinedType::PT_boolean];
00891 
00892     be_global->lang_header_ <<
00893       "class " << nm << ";\n"
00894       "typedef " << helpers_[var] << '<' << nm << "> " << nm << "_var;\n"
00895       "typedef " << helpers_[out] << '<' << nm << "> " << nm << "_out;\n\n"
00896       "class " << exporter() << nm << " : public " << base << " {\n"
00897       "public:\n"
00898       "  typedef " << nm << "_var _var_type;\n"
00899       "  typedef " << nm << "_out _out_type;\n\n"
00900       "  " << nm << "() {}\n"
00901       "  " << nm << "(const " << nm << "& seq) : " << base << "(seq) {}\n"
00902       "  friend void swap(" << nm << "& a, " << nm << "& b) { a.swap(b); }\n"
00903       "  " << nm << "& operator=(const " << nm << "& rhs)\n"
00904       "  {\n"
00905       "    " << nm << " tmp(rhs);\n"
00906       "    swap(tmp);\n"
00907       "    return *this;\n"
00908       "  }\n";
00909 
00910     if (bounded) {
00911       be_global->lang_header_ <<
00912         "  " << nm << "(" << len_type << " length, " << elem_type << "* data, "
00913         << flag_type << " release = false)\n"
00914         "    : " << base << "(0u, length, data, release) {}\n";
00915     } else {
00916       be_global->lang_header_ <<
00917         "  " << nm << "(" << len_type << " maximum)\n"
00918         "    : " << base << "(maximum, 0u, 0, true) {}\n"
00919         "  " << nm << "(" << len_type << " maximum, " << len_type << " length, "
00920         << elem_type << "* data, " << flag_type << " release = false)\n"
00921         "    : " << base << "(maximum, length, data, release) {}\n";
00922     }
00923     be_global->lang_header_ <<
00924       "};\n\n";
00925 
00926     be_global->lang_header_ <<
00927       "inline ACE_CDR::Boolean operator<< (ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
00928 
00929     be_global->lang_header_ <<
00930       "inline ACE_CDR::Boolean operator>> (ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
00931   }

Here is the call graph for this function:

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

Implements GeneratorBase.

Definition at line 933 of file langmap_generator.cpp.

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

00937   {
00938     const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
00939     const char* const nm = name->last_component()->get_string();
00940     struct_decls(name, size);
00941     be_global->lang_header_ <<
00942       "\n"
00943       "struct " << exporter() << nm << " \n"
00944       "{\n"
00945       "  typedef " << nm << "_var _var_type;\n"
00946       "  typedef " << nm << "_out _out_type;\n\n";
00947 
00948     for (size_t i = 0; i < fields.size(); ++i) {
00949       AST_Type* field_type = fields[i]->field_type();
00950       const std::string field_name = fields[i]->local_name()->get_string();
00951       std::string type_name = map_type(field_type);
00952       const Classification cls = classify(field_type);
00953       if (cls & CL_STRING) {
00954         type_name = helpers_[(cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR];
00955       }
00956       be_global->lang_header_ <<
00957         "  " << type_name << ' ' << field_name << ";\n";
00958     }
00959 
00960     be_global->lang_header_ << "\n"
00961       "  bool operator==(const " << nm << "& rhs) const;\n"
00962       "  bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
00963       "  OPENDDS_POOL_ALLOCATION_HOOKS\n"
00964       "};\n\n";
00965 
00966     be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
00967     be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
00968 
00969     if (size == AST_Type::VARIABLE) {
00970       be_global->lang_header_ <<
00971         exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n";
00972     }
00973 
00974     be_global->lang_header_ <<
00975       exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
00976     be_global->lang_header_ <<
00977       exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
00978 
00979     {
00980       const ScopedNamespaceGuard guard(name, be_global->impl_);
00981       be_global->impl_ <<
00982         "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
00983         "{\n";
00984       for (size_t i = 0; i < fields.size(); ++i) {
00985         const std::string field_name = fields[i]->local_name()->get_string();
00986         AST_Type* field_type = resolveActualType(fields[i]->field_type());
00987         const Classification cls = classify(field_type);
00988         if (cls & CL_ARRAY) {
00989           std::string indent("  ");
00990           NestedForLoops nfl("int", "i",
00991             AST_Array::narrow_from_decl(field_type), indent, true);
00992           be_global->impl_ <<
00993             indent << "if (" << field_name << nfl.index_ << " != rhs."
00994             << field_name << nfl.index_ << ") {\n" <<
00995             indent << "  return false;\n" <<
00996             indent << "}\n";
00997         } else {
00998           be_global->impl_ <<
00999             "  if (" << field_name << " != rhs." << field_name << ") {\n"
01000             "    return false;\n"
01001             "  }\n";
01002         }
01003       }
01004       be_global->impl_ << "  return true;\n}\n\n";
01005 
01006       if (size == AST_Type::VARIABLE) {
01007         be_global->impl_ <<
01008           "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
01009           "{\n"
01010           "  using std::swap;\n";
01011         for (size_t i = 0; i < fields.size(); ++i) {
01012           const std::string fn = fields[i]->local_name()->get_string();
01013           AST_Type* field_type = resolveActualType(fields[i]->field_type());
01014           const Classification cls = classify(field_type);
01015           if (cls & CL_ARRAY) {
01016             ACE_CDR::ULong elems = 1;
01017             const std::string flat_fn = fn + array_dims(field_type, elems);
01018             be_global->add_include("<algorithm>", BE_GlobalData::STREAM_CPP);
01019             be_global->impl_ <<
01020               "  std::swap_ranges(lhs." << flat_fn << ", lhs." << flat_fn
01021                                         << " + " << elems << ", rhs." << flat_fn << ");\n";
01022           } else {
01023             be_global->impl_ <<
01024               "  swap(lhs." << fn << ", rhs." << fn << ");\n";
01025           }
01026         }
01027         be_global->impl_ << "}\n\n";
01028       }
01029 
01030       be_global->impl_ <<
01031         "ACE_CDR::Boolean operator<< (ACE_OutputCDR &, const " << nm << "&) { return true; }\n\n";
01032       be_global->impl_ <<
01033         "ACE_CDR::Boolean operator>> (ACE_InputCDR &, " << nm << "&) { return true; }\n\n";
01034     }
01035 
01036     gen_typecode(name);
01037     return true;
01038   }

Here is the call graph for this function:

virtual void SafetyProfileGenerator::init ( void   )  [inline, virtual]

Implements GeneratorBase.

Definition at line 815 of file langmap_generator.cpp.

References be_global.

00816   {
00817     be_global->add_include("tao/String_Manager_T.h", BE_GlobalData::STREAM_LANG_H);
00818     be_global->add_include("tao/CORBA_String.h", BE_GlobalData::STREAM_LANG_H);
00819     primtype_[AST_PredefinedType::PT_long] = "CORBA::Long";
00820     primtype_[AST_PredefinedType::PT_ulong] = "CORBA::ULong";
00821     primtype_[AST_PredefinedType::PT_longlong] = "CORBA::LongLong";
00822     primtype_[AST_PredefinedType::PT_ulonglong] = "CORBA::UnsignedLongLong";
00823     primtype_[AST_PredefinedType::PT_short] = "CORBA::Short";
00824     primtype_[AST_PredefinedType::PT_ushort] = "CORBA::UShort";
00825     primtype_[AST_PredefinedType::PT_float] = "CORBA::Float";
00826     primtype_[AST_PredefinedType::PT_double] = "CORBA::Double";
00827     primtype_[AST_PredefinedType::PT_longdouble] = "CORBA::LongDouble";
00828     primtype_[AST_PredefinedType::PT_char] = "CORBA::Char";
00829     primtype_[AST_PredefinedType::PT_wchar] = "CORBA::WChar";
00830     primtype_[AST_PredefinedType::PT_boolean] = "CORBA::Boolean";
00831     primtype_[AST_PredefinedType::PT_octet] = "CORBA::Octet";
00832     helpers_[HLP_STR_VAR] = "CORBA::String_var";
00833     helpers_[HLP_STR_OUT] = "CORBA::String_out";
00834     helpers_[HLP_WSTR_VAR] = "CORBA::WString_var";
00835     helpers_[HLP_WSTR_OUT] = "CORBA::WString_out";
00836     helpers_[HLP_STR_MGR] = "::TAO::String_Manager";
00837     helpers_[HLP_WSTR_MGR] = "CORBA::WString_mgr";
00838     helpers_[HLP_FIX_VAR] = "::TAO_Fixed_Var_T";
00839     helpers_[HLP_VAR_VAR] = "::TAO_Var_Var_T";
00840     helpers_[HLP_OUT] = "::TAO_Out_T";
00841     helpers_[HLP_SEQ] = "::OpenDDS::SafetyProfile::Sequence";
00842     helpers_[HLP_SEQ_NS] = "::OpenDDS::SafetyProfile";
00843     helpers_[HLP_SEQ_VAR_VAR] = "::OpenDDS::SafetyProfile::SequenceVar";
00844     helpers_[HLP_SEQ_FIX_VAR] = "::OpenDDS::SafetyProfile::SequenceVar";
00845     helpers_[HLP_SEQ_OUT] = "::TAO_Seq_Out_T";
00846     helpers_[HLP_ARR_VAR_VAR] = "::TAO_VarArray_Var_T";
00847     helpers_[HLP_ARR_FIX_VAR] = "::TAO_FixedArray_Var_T";
00848     helpers_[HLP_ARR_OUT] = "::TAO_Array_Out_T";
00849     helpers_[HLP_ARR_FORANY] = "::TAO_Array_Forany_T";
00850   }


Member Data Documentation

Definition at line 1040 of file langmap_generator.cpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1