GeneratorBase Class Reference

Inheritance diagram for GeneratorBase:
Inheritance graph
[legend]

List of all members.

Classes

struct  GenerateGettersAndSetters

Public Member Functions

virtual ~GeneratorBase ()
virtual void init ()=0
virtual void gen_sequence (UTL_ScopedName *tdname, AST_Sequence *seq)=0
virtual bool gen_struct (AST_Structure *s, UTL_ScopedName *name, const std::vector< AST_Field * > &fields, AST_Type::SIZE_TYPE size, const char *x)=0
bool gen_union (AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator)

Static Public Member Functions

static std::string generateDefaultValue (AST_Union *the_union, AST_Type *discriminator)
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 &name, AST_Type *field_type, const std::string &, std::string &, const std::string &)
static std::string generateAssign (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &)
static std::string generateEqual (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &)
static std::string generateReset (const std::string &name, AST_Type *field_type, const std::string &, std::string &, const std::string &)

Detailed Description

Definition at line 149 of file langmap_generator.cpp.


Constructor & Destructor Documentation

virtual GeneratorBase::~GeneratorBase (  )  [inline, virtual]

Definition at line 152 of file langmap_generator.cpp.

00152 {}


Member Function Documentation

static size_t GeneratorBase::countLabels ( const std::vector< AST_UnionBranch * > &  branches  )  [inline, static]

Definition at line 314 of file langmap_generator.cpp.

Referenced by needsDefault().

00315   {
00316     size_t count = 0;
00317 
00318     for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end();
00319          pos != limit;
00320          ++pos) {
00321       count += (*pos)->label_list_length();
00322     }
00323 
00324     return count;
00325   }

Here is the caller graph for this function:

virtual void GeneratorBase::gen_sequence ( UTL_ScopedName *  tdname,
AST_Sequence *  seq 
) [pure virtual]

Implemented in FaceGenerator, and SafetyProfileGenerator.

Referenced by langmap_generator::gen_typedef().

Here is the caller graph for this function:

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

Implemented in FaceGenerator, and SafetyProfileGenerator.

Referenced by langmap_generator::gen_struct().

Here is the caller graph for this function:

bool GeneratorBase::gen_union ( AST_Union *  u,
UTL_ScopedName *  name,
const std::vector< AST_UnionBranch * > &  branches,
AST_Type *  discriminator 
) [inline]

Definition at line 465 of file langmap_generator.cpp.

References be_global, generate_union_field(), generateAssign(), generateCopyCtor(), generateDefaultValue(), generateEqual(), generateReset(), generateSwitchForUnion(), needsDefault(), and scoped().

Referenced by langmap_generator::gen_union().

00466   {
00467     const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
00468     const char* const nm = name->last_component()->get_string();
00469     struct_decls(name, u->size_type(), "class");
00470     be_global->lang_header_ <<
00471       "\n"
00472       "class " << exporter() << nm << " \n"
00473       "{\n"
00474       " public:\n"
00475       "  typedef " << nm << "_var _var_type;\n"
00476       "  typedef " << nm << "_out _out_type;\n"
00477       "  " << nm << "();\n"
00478       "  " << nm << "(const " << nm << "&);\n"
00479       "  ~" << nm << "() { _reset(); };\n"
00480       "  " << nm << "& operator=(const " << nm << "&);\n"
00481       "  void _d(" << scoped(discriminator->name()) << " d) { _discriminator = d; }\n"
00482       "  " << scoped(discriminator->name()) << " _d() const { return _discriminator; }\n";
00483 
00484     std::for_each (branches.begin(), branches.end(), GenerateGettersAndSetters(u, discriminator));
00485 
00486     if (needsDefault(branches, discriminator)) {
00487       be_global->lang_header_ <<
00488         "  void _default() {\n"
00489         "    _reset();\n"
00490         "    _discriminator = " << generateDefaultValue(u, discriminator) << ";\n"
00491         "  }\n";
00492     }
00493 
00494     be_global->lang_header_ <<
00495       "  bool operator==(const " << nm << "& rhs) const;\n"
00496       "  bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
00497       "  OPENDDS_POOL_ALLOCATION_HOOKS\n";
00498 
00499     be_global->lang_header_ <<
00500       " private:\n"
00501       "  " << scoped(discriminator->name()) << " _discriminator;\n"
00502       "  union {\n";
00503 
00504     std::for_each (branches.begin(), branches.end(), generate_union_field);
00505 
00506     be_global->lang_header_ <<
00507       "  } _u;\n";
00508 
00509     be_global->lang_header_ <<
00510       "  void _reset();\n"
00511       "};\n\n";
00512 
00513     be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
00514     be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
00515 
00516     be_global->lang_header_ <<
00517       exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
00518     be_global->lang_header_ <<
00519       exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
00520 
00521     {
00522       const ScopedNamespaceGuard guard(name, be_global->impl_);
00523 
00524       be_global->impl_ <<
00525         nm << "::" << nm << "() { std::memset (this, 0, sizeof (" << nm << ")); }\n\n";
00526 
00527       be_global->impl_ <<
00528         nm << "::" << nm << "(const " << nm << "& other)\n"
00529         "{\n"
00530         "  this->_discriminator = other._discriminator;\n";
00531       generateSwitchForUnion("this->_discriminator", generateCopyCtor, branches, discriminator, "", "", "", false, false);
00532       be_global->impl_ <<
00533         "}\n\n";
00534 
00535       be_global->impl_ <<
00536         nm << "& " << nm << "::operator=(const " << nm << "& other)\n"
00537         "{\n" <<
00538         "  if (this == &other) {\n"
00539         "    return *this;\n"
00540         "  }\n\n"
00541         "  _reset();\n"
00542         "  this->_discriminator = other._discriminator;\n";
00543       generateSwitchForUnion("this->_discriminator", generateAssign, branches, discriminator, "", "", "", false, false);
00544       be_global->impl_ <<
00545         "  return *this;\n"
00546         "}\n\n";
00547 
00548       be_global->impl_ <<
00549         "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
00550         "{\n"
00551         "  if (this->_discriminator != rhs._discriminator) return false;\n";
00552       if (generateSwitchForUnion("this->_discriminator", generateEqual, branches, discriminator, "", "", "", false, false)) {
00553         be_global->impl_ <<
00554           "  return false;\n";
00555       }
00556       be_global->impl_ <<
00557         "}\n\n";
00558 
00559       be_global->impl_ <<
00560         "void " << nm << "::_reset()\n"
00561         "{\n";
00562       generateSwitchForUnion("this->_discriminator", generateReset, branches, discriminator, "", "", "", false, false);
00563       be_global->impl_ <<
00564         "}\n\n";
00565 
00566       be_global->impl_ <<
00567         "ACE_CDR::Boolean operator<<(ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
00568       be_global->impl_ <<
00569         "ACE_CDR::Boolean operator>>(ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
00570     }
00571 
00572     gen_typecode(name);
00573     return true;
00574   }

Here is the call graph for this function:

Here is the caller graph for this function:

static void GeneratorBase::generate_union_field ( AST_UnionBranch *  branch  )  [inline, static]

Definition at line 332 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

Referenced by gen_union().

00333   {
00334     AST_Type* field_type = branch->field_type();
00335     AST_Type* actual_field_type = resolveActualType(field_type);
00336     const Classification cls = classify(actual_field_type);
00337     if (cls & (CL_PRIMITIVE | CL_ENUM)) {
00338       be_global->lang_header_ <<
00339         "    " << map_type(field_type) << ' ' << branch->local_name()->get_string() << ";\n";
00340     } else if (cls & CL_STRING) {
00341       const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE)
00342         ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char;
00343       be_global->lang_header_ <<
00344         "    " << primtype_[chartype] << "* " << branch->local_name()->get_string() << ";\n";
00345     } else if (cls & CL_ARRAY) {
00346       be_global->lang_header_ <<
00347         "    " << map_type(field_type) << "_slice* " << branch->local_name()->get_string() << ";\n";
00348     } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
00349       be_global->lang_header_ <<
00350         "    " << map_type(field_type) << "* " << branch->local_name()->get_string() << ";\n";
00351     } else {
00352       std::cerr << "Unsupported type for union element\n";
00353     }
00354   }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string GeneratorBase::generateAssign ( const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
std::string &  ,
const std::string &   
) [inline, static]

Definition at line 382 of file langmap_generator.cpp.

References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

Referenced by gen_union().

00385   {
00386     std::stringstream ss;
00387     AST_Type* actual_field_type = resolveActualType(field_type);
00388     const Classification cls = classify(actual_field_type);
00389     if (cls & (CL_PRIMITIVE | CL_ENUM)) {
00390       ss <<
00391         "    this->_u." << name << " = other._u." << name << ";\n";
00392     } else if (cls & CL_STRING) {
00393       ss <<
00394         "    this->_u." << name << " = (other._u." << name << ") ? ::CORBA::string_dup(other._u." << name << ") : 0 ;\n";
00395     } else if (cls & CL_ARRAY) {
00396       ss <<
00397         "    this->_u." << name << " = (other._u." << name << ") ? " << map_type(field_type) << "_dup(other._u." << name << ") : 0 ;\n";
00398     } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
00399       ss <<
00400         "    this->_u." << name << " = (other._u." << name << ") ? new " << map_type(field_type) << "(*other._u." << name << ") : 0;\n";
00401     } else {
00402       std::cerr << "Unsupported type for union element\n";
00403     }
00404 
00405     return ss.str();
00406   }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string GeneratorBase::generateCopyCtor ( const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
std::string &  ,
const std::string &   
) [inline, static]

Definition at line 356 of file langmap_generator.cpp.

References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

Referenced by gen_union().

00359   {
00360     std::stringstream ss;
00361     AST_Type* actual_field_type = resolveActualType(field_type);
00362     const Classification cls = classify(actual_field_type);
00363     if (cls & (CL_PRIMITIVE | CL_ENUM)) {
00364       ss <<
00365         "    this->_u." << name << " = other._u." << name << ";\n";
00366     } else if (cls & CL_STRING) {
00367       ss <<
00368         "    this->_u." << name << " = (other._u." << name << ") ? ::CORBA::string_dup(other._u." << name << ") : 0 ;\n";
00369     } else if (cls & CL_ARRAY) {
00370       ss <<
00371         "    this->_u." << name << " = (other._u." << name << ") ? " << map_type(field_type) << "_dup(other._u." << name << ") : 0 ;\n";
00372     } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
00373       ss <<
00374         "    this->_u." << name << " = (other._u." << name << ") ? new " << map_type(field_type) << "(*other._u." << name << ") : 0;\n";
00375     } else {
00376       std::cerr << "Unsupported type for union element\n";
00377     }
00378 
00379     return ss.str();
00380   }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string GeneratorBase::generateDefaultValue ( AST_Union *  the_union,
AST_Type *  discriminator 
) [inline, static]

Definition at line 157 of file langmap_generator.cpp.

References ACE_TEXT(), LM_ERROR, and scoped().

Referenced by gen_union(), and GeneratorBase::GenerateGettersAndSetters::operator()().

00158   {
00159     std::stringstream first_label;
00160     AST_Union::DefaultValue dv;
00161     if (the_union->default_value(dv) == -1) {
00162       ACE_ERROR((LM_ERROR,
00163         ACE_TEXT("(%P|%t) ERROR: generateDefaultValue::")
00164         ACE_TEXT(" computing default value failed\n")));
00165       return first_label.str();
00166     }
00167 
00168     switch (the_union->udisc_type ())
00169       {
00170       case AST_Expression::EV_short:
00171         first_label << dv.u.short_val;
00172         break;
00173       case AST_Expression::EV_ushort:
00174         first_label << dv.u.ushort_val;
00175         break;
00176       case AST_Expression::EV_long:
00177         first_label << dv.u.long_val;
00178         break;
00179       case AST_Expression::EV_ulong:
00180         first_label << dv.u.ulong_val;
00181         break;
00182       case AST_Expression::EV_char:
00183         first_label << (int)dv.u.char_val;
00184         break;
00185       case AST_Expression::EV_bool:
00186         first_label << (dv.u.bool_val == 0 ? "false" : "true");
00187         break;
00188       case AST_Expression::EV_enum:
00189         {
00190           AST_Enum* e = AST_Enum::narrow_from_decl(discriminator);
00191           first_label << scoped(e->value_to_name(dv.u.enum_val));
00192           break;
00193         }
00194       case AST_Expression::EV_longlong:
00195         first_label << dv.u.longlong_val;
00196         break;
00197       case AST_Expression::EV_ulonglong:
00198         first_label << dv.u.ulonglong_val;
00199         break;
00200       default:
00201         std::cerr << "Illegal discriminator for union\n";
00202         break;
00203       }
00204 
00205     return first_label.str();
00206   }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string GeneratorBase::generateEqual ( const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
std::string &  ,
const std::string &   
) [inline, static]

Definition at line 408 of file langmap_generator.cpp.

References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

Referenced by gen_union().

00411   {
00412     std::stringstream ss;
00413 
00414     AST_Type* actual_field_type = resolveActualType(field_type);
00415     const Classification cls = classify(actual_field_type);
00416     if (cls & (CL_PRIMITIVE | CL_ENUM)) {
00417       ss <<
00418         "    return this->_u." << name << " == rhs._u." << name << ";\n";
00419     } else if (cls & CL_STRING) {
00420       ss <<
00421         "    return std::strcmp (this->_u." << name << ", rhs._u." << name << ") == 0 ;\n";
00422     } else if (cls & CL_ARRAY) {
00423       // TODO
00424       ss <<
00425         "    return false;\n";
00426     } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
00427       ss <<
00428         "    return *this->_u." << name << " == *rhs._u." << name << ";\n";
00429     } else {
00430       std::cerr << "Unsupported type for union element\n";
00431     }
00432 
00433     return ss.str();
00434   }

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string GeneratorBase::generateReset ( const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
std::string &  ,
const std::string &   
) [inline, static]

Definition at line 436 of file langmap_generator.cpp.

References AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_FIXED, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

Referenced by gen_union().

00439   {
00440     std::stringstream ss;
00441 
00442     AST_Type* actual_field_type = resolveActualType(field_type);
00443     const Classification cls = classify(actual_field_type);
00444     if (cls & (CL_PRIMITIVE | CL_ENUM)) {
00445       // Do nothing.
00446     } else if (cls & CL_STRING) {
00447       ss <<
00448         "    ::CORBA::string_free(this->_u." << name << ");\n"
00449         "    this->_u." << name << " = 0;\n";
00450     } else if (cls & CL_ARRAY) {
00451       ss <<
00452         "    " << map_type(field_type) << "_free(this->_u." << name << ");\n"
00453         "    this->_u." << name << " = 0;\n";
00454     } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
00455       ss <<
00456         "    delete this->_u." << name << ";\n"
00457         "    this->_u." << name << " = 0;\n";
00458     } else {
00459       std::cerr << "Unsupported type for union element\n";
00460     }
00461 
00462     return ss.str();
00463   }

Here is the call graph for this function:

Here is the caller graph for this function:

static bool GeneratorBase::hasDefaultLabel ( const std::vector< AST_UnionBranch * > &  branches  )  [inline, static]

Definition at line 298 of file langmap_generator.cpp.

Referenced by needsDefault().

00299   {
00300     for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end();
00301          pos != limit;
00302          ++pos) {
00303       AST_UnionBranch* branch = *pos;
00304       for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
00305         AST_UnionLabel* label = branch->label(j);
00306         if (label->label_kind() == AST_UnionLabel::UL_default) {
00307           return true;
00308         }
00309       }
00310     }
00311     return false;
00312   }

Here is the caller graph for this function:

virtual void GeneratorBase::init (  )  [pure virtual]

Implemented in FaceGenerator, and SafetyProfileGenerator.

Referenced by langmap_generator::init().

Here is the caller graph for this function:

static bool GeneratorBase::needsDefault ( const std::vector< AST_UnionBranch * > &  branches,
AST_Type *  discriminator 
) [inline, static]

Definition at line 327 of file langmap_generator.cpp.

References countLabels(), hasDefaultLabel(), and needSyntheticDefault().

Referenced by gen_union().

00328   {
00329     return !hasDefaultLabel(branches) && needSyntheticDefault(discriminator, countLabels(branches));
00330   }

Here is the call graph for this function:

Here is the caller graph for this function:


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