FaceGenerator Class Reference

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

List of all members.

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

Static Public Attributes

static FaceGenerator instance

Detailed Description

Definition at line 577 of file langmap_generator.cpp.


Member Function Documentation

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

Implements GeneratorBase.

Definition at line 619 of file langmap_generator.cpp.

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

00620   {
00621     be_global->add_include("<tao/Seq_Out_T.h>", BE_GlobalData::STREAM_LANG_H);
00622     be_global->add_include("FACE/Sequence.h", BE_GlobalData::STREAM_LANG_H);
00623     be_global->add_include("FACE/SequenceVar.h", BE_GlobalData::STREAM_LANG_H);
00624     be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
00625     const char* const nm = tdname->last_component()->get_string();
00626     AST_Type* elem = seq->base_type();
00627     const Classification elem_cls = classify(elem);
00628     const bool bounded = !seq->unbounded();
00629     const Helper var = (elem->size_type() == AST_Type::VARIABLE)
00630                         ? HLP_SEQ_VAR_VAR : HLP_SEQ_FIX_VAR,
00631       out = HLP_SEQ_OUT;
00632 
00633     std::string elem_type = map_type(elem), extra_tmp_args;
00634     if (elem_cls & CL_STRING) {
00635       const AST_Expression::ExprType char_type = (elem_cls & CL_WIDE)
00636         ? AST_Expression::EV_wchar : AST_Expression::EV_char;
00637       extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::StringEltPolicy< "
00638         + map_type(char_type) + ">";
00639     } else if (elem_cls & CL_ARRAY) {
00640       extra_tmp_args = ", " + helpers_[HLP_SEQ_NS] + "::ArrayEltPolicy<"
00641         + elem_type + "_forany>";
00642     } else if (elem->size_type() == AST_Type::VARIABLE) {
00643       extra_tmp_args = ", " +  helpers_[HLP_SEQ_NS] + "::VariEltPolicy<"
00644         + elem_type + ">";
00645     }
00646 
00647     std::string bound = helpers_[HLP_SEQ_NS] + "::Unbounded";
00648     if (bounded) {
00649       std::ostringstream oss;
00650       oss << helpers_[HLP_SEQ_NS] << "::Bounded<"
00651         << seq->max_size()->ev()->u.ulval << '>';
00652       bound = oss.str();
00653     }
00654 
00655     const std::string base = helpers_[HLP_SEQ] + "< " + elem_type + ", " + bound
00656                            + extra_tmp_args + " >",
00657       len_type = primtype_[AST_PredefinedType::PT_ulong],
00658       flag_type = primtype_[AST_PredefinedType::PT_boolean];
00659 
00660     be_global->lang_header_ <<
00661       "class " << nm << ";\n"
00662       "typedef " << helpers_[var] << '<' << nm << "> " << nm << "_var;\n"
00663       "typedef " << helpers_[out] << '<' << nm << "> " << nm << "_out;\n\n"
00664       "class " << exporter() << nm << " : public " << base << " {\n"
00665       "public:\n"
00666       "  typedef " << nm << "_var _var_type;\n"
00667       "  typedef " << nm << "_out _out_type;\n\n"
00668       "  " << nm << "() {}\n"
00669       "  " << nm << "(const " << nm << "& seq) : " << base << "(seq) {}\n"
00670       "  friend void swap(" << nm << "& a, " << nm << "& b) { a.swap(b); }\n"
00671       "  " << nm << "& operator=(const " << nm << "& rhs)\n"
00672       "  {\n"
00673       "    " << nm << " tmp(rhs);\n"
00674       "    swap(tmp);\n"
00675       "    return *this;\n"
00676       "  }\n";
00677 
00678     if (bounded) {
00679       be_global->lang_header_ <<
00680         "  " << nm << "(" << len_type << " length, " << elem_type << "* data, "
00681         << flag_type << " release = false)\n"
00682         "    : " << base << "(0u, length, data, release) {}\n";
00683     } else {
00684       be_global->lang_header_ <<
00685         "  " << nm << "(" << len_type << " maximum)\n"
00686         "    : " << base << "(maximum, 0u, 0, true) {}\n"
00687         "  " << nm << "(" << len_type << " maximum, " << len_type << " length, "
00688         << elem_type << "* data, " << flag_type << " release = false)\n"
00689         "    : " << base << "(maximum, length, data, release) {}\n";
00690     }
00691     be_global->lang_header_ <<
00692       "};\n\n";
00693 
00694     be_global->lang_header_ <<
00695       "inline ACE_CDR::Boolean operator<< (ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
00696 
00697     be_global->lang_header_ <<
00698       "inline ACE_CDR::Boolean operator>> (ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
00699   }

Here is the call graph for this function:

bool FaceGenerator::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 701 of file langmap_generator.cpp.

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

00705   {
00706     const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
00707     const char* const nm = name->last_component()->get_string();
00708     struct_decls(name, size);
00709     be_global->lang_header_ <<
00710       "\n"
00711       "struct " << exporter() << nm << "\n"
00712       "{\n"
00713       "  typedef " << nm << "_var _var_type;\n"
00714       "  typedef " << nm << "_out _out_type;\n\n";
00715 
00716     for (size_t i = 0; i < fields.size(); ++i) {
00717       AST_Type* field_type = fields[i]->field_type();
00718       const std::string field_name = fields[i]->local_name()->get_string();
00719       std::string type_name = map_type(field_type);
00720       const Classification cls = classify(field_type);
00721       if (cls & CL_STRING) {
00722         type_name = helpers_[(cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR];
00723       }
00724       be_global->lang_header_ <<
00725         "  " << type_name << ' ' << field_name << ";\n";
00726     }
00727 
00728     be_global->lang_header_ << "\n"
00729       "  bool operator==(const " << nm << "& rhs) const;\n"
00730       "  bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
00731       "  OPENDDS_POOL_ALLOCATION_HOOKS\n"
00732       "};\n\n";
00733 
00734     be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
00735     be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
00736 
00737     if (size == AST_Type::VARIABLE) {
00738       be_global->lang_header_ <<
00739         exporter() << "void swap(" << nm << "& lhs, " << nm << "& rhs);\n\n";
00740     }
00741 
00742     be_global->lang_header_ <<
00743       exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
00744     be_global->lang_header_ <<
00745       exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
00746 
00747     {
00748       const ScopedNamespaceGuard guard(name, be_global->impl_);
00749       be_global->impl_ <<
00750         "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
00751         "{\n";
00752       for (size_t i = 0; i < fields.size(); ++i) {
00753         const std::string field_name = fields[i]->local_name()->get_string();
00754         AST_Type* field_type = resolveActualType(fields[i]->field_type());
00755         const Classification cls = classify(field_type);
00756         if (cls & CL_ARRAY) {
00757           std::string indent("  ");
00758           NestedForLoops nfl("int", "i",
00759             AST_Array::narrow_from_decl(field_type), indent, true);
00760           be_global->impl_ <<
00761             indent << "if (" << field_name << nfl.index_ << " != rhs."
00762             << field_name << nfl.index_ << ") {\n" <<
00763             indent << "  return false;\n" <<
00764             indent << "}\n";
00765         } else {
00766           be_global->impl_ <<
00767             "  if (" << field_name << " != rhs." << field_name << ") {\n"
00768             "    return false;\n"
00769             "  }\n";
00770         }
00771       }
00772       be_global->impl_ << "  return true;\n}\n\n";
00773 
00774       if (size == AST_Type::VARIABLE) {
00775         be_global->impl_ <<
00776           "void swap(" << nm << "& lhs, " << nm << "& rhs)\n"
00777           "{\n"
00778           "  using std::swap;\n";
00779         for (size_t i = 0; i < fields.size(); ++i) {
00780           const std::string fn = fields[i]->local_name()->get_string();
00781           AST_Type* field_type = resolveActualType(fields[i]->field_type());
00782           const Classification cls = classify(field_type);
00783           if (cls & CL_ARRAY) {
00784             ACE_CDR::ULong elems = 1;
00785             const std::string flat_fn = fn + array_dims(field_type, elems);
00786             be_global->add_include("<algorithm>", BE_GlobalData::STREAM_CPP);
00787             be_global->impl_ <<
00788               "  std::swap_ranges(lhs." << flat_fn << ", lhs." << flat_fn
00789                                         << " + " << elems << ", rhs." << flat_fn << ");\n";
00790           } else {
00791             be_global->impl_ <<
00792               "  swap(lhs." << fn << ", rhs." << fn << ");\n";
00793           }
00794         }
00795         be_global->impl_ << "}\n\n";
00796       }
00797 
00798       be_global->impl_ <<
00799         "ACE_CDR::Boolean operator<< (ACE_OutputCDR &, const " << nm << "&) { return true; }\n\n";
00800       be_global->impl_ <<
00801         "ACE_CDR::Boolean operator>> (ACE_InputCDR &, " << nm << "&) { return true; }\n\n";
00802     }
00803 
00804     gen_typecode(name);
00805     return true;
00806   }

Here is the call graph for this function:

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

Implements GeneratorBase.

Definition at line 580 of file langmap_generator.cpp.

References be_global.

00581   {
00582     be_global->add_include("FACE/types.hpp", BE_GlobalData::STREAM_LANG_H);
00583     be_global->add_include("FACE/StringManager.h", BE_GlobalData::STREAM_LANG_H);
00584     primtype_[AST_PredefinedType::PT_long] = "::FACE::Long";
00585     primtype_[AST_PredefinedType::PT_ulong] = "::FACE::UnsignedLong";
00586     primtype_[AST_PredefinedType::PT_longlong] = "::FACE::LongLong";
00587     primtype_[AST_PredefinedType::PT_ulonglong] = "::FACE::UnsignedLongLong";
00588     primtype_[AST_PredefinedType::PT_short] = "::FACE::Short";
00589     primtype_[AST_PredefinedType::PT_ushort] = "::FACE::UnsignedShort";
00590     primtype_[AST_PredefinedType::PT_float] = "::FACE::Float";
00591     primtype_[AST_PredefinedType::PT_double] = "::FACE::Double";
00592     primtype_[AST_PredefinedType::PT_longdouble] = "::FACE::LongDouble";
00593     primtype_[AST_PredefinedType::PT_char] = "::FACE::Char";
00594     primtype_[AST_PredefinedType::PT_wchar] = "::FACE::WChar";
00595     primtype_[AST_PredefinedType::PT_boolean] = "::FACE::Boolean";
00596     primtype_[AST_PredefinedType::PT_octet] = "::FACE::Octet";
00597     helpers_[HLP_STR_VAR] = "::FACE::String_var";
00598     helpers_[HLP_STR_OUT] = "::FACE::String_out";
00599     helpers_[HLP_WSTR_VAR] = "::FACE::WString_var";
00600     helpers_[HLP_WSTR_OUT] = "::FACE::WString_out";
00601     helpers_[HLP_STR_MGR] = "::OpenDDS::FaceTypes::String_mgr";
00602     helpers_[HLP_WSTR_MGR] = "::OpenDDS::FaceTypes::WString_mgr";
00603     helpers_[HLP_FIX_VAR] = "::TAO_Fixed_Var_T";
00604     helpers_[HLP_VAR_VAR] = "::TAO_Var_Var_T";
00605     helpers_[HLP_OUT] = "::TAO_Out_T";
00606     helpers_[HLP_SEQ] = "::OpenDDS::FaceTypes::Sequence";
00607     helpers_[HLP_SEQ_NS] = "::OpenDDS::FaceTypes";
00608     helpers_[HLP_SEQ_VAR_VAR] = "::OpenDDS::FaceTypes::SequenceVar";
00609     helpers_[HLP_SEQ_FIX_VAR] = "::OpenDDS::FaceTypes::SequenceVar";
00610     helpers_[HLP_SEQ_OUT] = "::TAO_Seq_Out_T";
00611     helpers_[HLP_ARR_VAR_VAR] = "::TAO_VarArray_Var_T";
00612     helpers_[HLP_ARR_FIX_VAR] = "::TAO_FixedArray_Var_T";
00613     helpers_[HLP_ARR_OUT] = "::TAO_Array_Out_T";
00614     helpers_[HLP_ARR_FORANY] = "::TAO_Array_Forany_T";
00615     helpers_[HLP_FIXED] = "::OpenDDS::FaceTypes::Fixed_T";
00616     helpers_[HLP_FIXED_CONSTANT] = "::OpenDDS::FaceTypes::Fixed";
00617   }


Member Data Documentation

Definition at line 808 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