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 566 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 608 of file langmap_generator.cpp.

References BE_GlobalData::add_include(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), exporter(), helpers_, HLP_SEQ, HLP_SEQ_FIX_VAR, HLP_SEQ_NS, HLP_SEQ_OUT, HLP_SEQ_VAR_VAR, BE_GlobalData::lang_header_, map_type(), primtype_, and BE_GlobalData::STREAM_LANG_H.

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

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 690 of file langmap_generator.cpp.

References BE_GlobalData::add_include(), array_dims(), be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), exporter(), gen_typecode(), helpers_, HLP_STR_MGR, HLP_WSTR_MGR, BE_GlobalData::impl_, NestedForLoops::index_, BE_GlobalData::lang_header_, map_type(), AstTypeClassification::resolveActualType(), BE_GlobalData::STREAM_CPP, BE_GlobalData::STREAM_LANG_H, and struct_decls().

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

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

Implements GeneratorBase.

Definition at line 569 of file langmap_generator.cpp.

References BE_GlobalData::add_include(), be_global, helpers_, HLP_ARR_FIX_VAR, HLP_ARR_FORANY, HLP_ARR_OUT, HLP_ARR_VAR_VAR, HLP_FIX_VAR, HLP_FIXED, HLP_FIXED_CONSTANT, HLP_OUT, HLP_SEQ, HLP_SEQ_FIX_VAR, HLP_SEQ_NS, HLP_SEQ_OUT, HLP_SEQ_VAR_VAR, HLP_STR_MGR, HLP_STR_OUT, HLP_STR_VAR, HLP_VAR_VAR, HLP_WSTR_MGR, HLP_WSTR_OUT, HLP_WSTR_VAR, primtype_, and BE_GlobalData::STREAM_LANG_H.

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


Member Data Documentation

FaceGenerator FaceGenerator::instance [static]

Definition at line 797 of file langmap_generator.cpp.

Referenced by langmap_generator::init().


The documentation for this class was generated from the following file:
Generated on Fri Feb 12 20:05:56 2016 for OpenDDS by  doxygen 1.4.7