dds_generator.h File Reference

#include "be_extern.h"
#include "utl_scoped_name.h"
#include "utl_identifier.h"
#include "utl_string.h"
#include "ast.h"
#include "ast_component_fwd.h"
#include "ast_eventtype_fwd.h"
#include "ast_structure_fwd.h"
#include "ast_union_fwd.h"
#include "ast_valuetype_fwd.h"
#include "ace/CDR_Base.h"
#include <string>
#include <vector>
#include <cstring>
#include "../DCPS/RestoreOutputStreamState.h"
Include dependency graph for dds_generator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dds_generator
class  composite_generator
struct  NamespaceGuard
struct  ScopedNamespaceGuard
struct  Function
struct  NestedForLoops

Namespaces

namespace  AstTypeClassification

Typedefs

typedef size_t AstTypeClassification::Classification
typedef std::string(* CommonFn )(const std::string &name, AST_Type *type, const std::string &prefix, std::string &intro, const std::string &)

Enumerations

enum  WrapDirection { WD_OUTPUT, WD_INPUT }

Functions

std::string scoped (UTL_ScopedName *sn)
std::string module_scope (UTL_ScopedName *sn)
AST_Type * AstTypeClassification::resolveActualType (AST_Type *element)
Classification AstTypeClassification::classify (AST_Type *type)
std::string wrapPrefix (AST_Type *type, WrapDirection wd)
std::string getWrapper (const std::string &name, AST_Type *type, WrapDirection wd)
std::string getEnumLabel (AST_Expression *label_val, AST_Type *disc)
std::ostream & operator<< (std::ostream &o, const AST_Expression::AST_ExprValue &ev)
void generateBranchLabels (AST_UnionBranch *branch, AST_Type *discriminator, size_t &n_labels, bool &has_default)
bool needSyntheticDefault (AST_Type *disc, size_t n_labels)
void generateCaseBody (CommonFn commonFn, AST_UnionBranch *branch, const char *statementPrefix, const char *namePrefix, const char *uni, bool generateBreaks, bool parens)
bool generateSwitchBody (CommonFn commonFn, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const char *uni="", bool forceDisableDefault=false, bool parens=true, bool breaks=true)
bool generateSwitchForUnion (const char *switchExpr, CommonFn commonFn, const std::vector< AST_UnionBranch * > &branches, AST_Type *discriminator, const char *statementPrefix, const char *namePrefix="", const char *uni="", bool forceDisableDefault=false, bool parens=true, bool breaks=true)
 returns true if a default: branch was generated (no default: label in IDL)

Variables

const Classification AstTypeClassification::CL_UNKNOWN = 0
const Classification AstTypeClassification::CL_SCALAR = 1
const Classification AstTypeClassification::CL_PRIMITIVE = 2
const Classification AstTypeClassification::CL_STRUCTURE = 4
const Classification AstTypeClassification::CL_STRING = 8
const Classification AstTypeClassification::CL_ENUM = 16
const Classification AstTypeClassification::CL_UNION = 32
const Classification AstTypeClassification::CL_ARRAY = 64
const Classification AstTypeClassification::CL_SEQUENCE = 128
const Classification AstTypeClassification::CL_WIDE = 256
const Classification AstTypeClassification::CL_BOUNDED = 512
const Classification AstTypeClassification::CL_INTERFACE = 1024
const Classification AstTypeClassification::CL_FIXED = 2048

Typedef Documentation

typedef std::string(* CommonFn)(const std::string &name, AST_Type *type, const std::string &prefix, std::string &intro, const std::string &)

Definition at line 479 of file dds_generator.h.


Enumeration Type Documentation

Enumerator:
WD_OUTPUT 
WD_INPUT 

Definition at line 335 of file dds_generator.h.

00335 {WD_OUTPUT, WD_INPUT};


Function Documentation

void generateBranchLabels ( AST_UnionBranch *  branch,
AST_Type *  discriminator,
size_t n_labels,
bool &  has_default 
) [inline]

Definition at line 437 of file dds_generator.h.

References be_global, and getEnumLabel().

Referenced by generateSwitchBody().

00439 {
00440   for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
00441     ++n_labels;
00442     AST_UnionLabel* label = branch->label(j);
00443     if (label->label_kind() == AST_UnionLabel::UL_default) {
00444       be_global->impl_ << "  default:";
00445       has_default = true;
00446     } else if (discriminator->node_type() == AST_Decl::NT_enum) {
00447       be_global->impl_ << "  case "
00448         << getEnumLabel(label->label_val(), discriminator) << ':';
00449     } else {
00450       be_global->impl_ << "  case " << *label->label_val()->ev() << ':';
00451     }
00452     be_global->impl_<< ((j == branch->label_list_length() - 1) ? " {\n" : "\n");
00453   }
00454 }

Here is the call graph for this function:

Here is the caller graph for this function:

void generateCaseBody ( CommonFn  commonFn,
AST_UnionBranch *  branch,
const char *  statementPrefix,
const char *  namePrefix,
const char *  uni,
bool  generateBreaks,
bool  parens 
) [inline]

Definition at line 484 of file dds_generator.h.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), getWrapper(), AstTypeClassification::resolveActualType(), scoped(), and WD_INPUT.

Referenced by generateSwitchBody(), and generateSwitchForUnion().

00487 {
00488   using namespace AstTypeClassification;
00489   std::string intro, name = branch->local_name()->get_string();
00490   if (namePrefix == std::string(">> ")) {
00491     std::string brType = scoped(branch->field_type()->name()), forany;
00492     AST_Type* br = resolveActualType(branch->field_type());
00493     Classification br_cls = classify(br);
00494     if (!br->in_main_file()
00495         && br->node_type() != AST_Decl::NT_pre_defined) {
00496       be_global->add_referenced(br->file_name().c_str());
00497     }
00498     std::string rhs;
00499     if (br_cls & CL_STRING) {
00500       if (be_global->language_mapping() == BE_GlobalData::LANGMAP_FACE_CXX) {
00501         brType = std::string("FACE::") + ((br_cls & CL_WIDE) ? "W" : "")
00502           + "String_var";
00503       } else {
00504         brType = std::string("CORBA::") + ((br_cls & CL_WIDE) ? "W" : "")
00505           + "String_var";
00506       }
00507       rhs = "tmp.out()";
00508     } else if (br_cls & CL_ARRAY) {
00509       forany = "    " + brType + "_forany fa = tmp;\n";
00510       rhs = getWrapper("fa", br, WD_INPUT);
00511     } else {
00512       rhs = getWrapper("tmp", br, WD_INPUT);
00513     }
00514     be_global->impl_ <<
00515       "    " << brType << " tmp;\n" << forany <<
00516       "    if (strm >> " << rhs << ") {\n"
00517       "      uni." << name << "(tmp);\n"
00518       "      uni._d(disc);\n"
00519       "      return true;\n"
00520       "    }\n"
00521       "    return false;\n";
00522   } else {
00523     const char* breakString = generateBreaks ? "    break;\n" : "";
00524 
00525     std::string expr = commonFn(name + (parens ? "()" : ""), branch->field_type(),
00526                                 std::string(namePrefix) + "uni", intro, uni);
00527     be_global->impl_ <<
00528       (intro.empty() ? "" : "  ") << intro;
00529     if (*statementPrefix) {
00530       be_global->impl_ <<
00531         "    " << statementPrefix << " " << expr << ";\n" <<
00532         (statementPrefix == std::string("return") ? "" : breakString);
00533     } else {
00534       be_global->impl_ << expr << breakString;
00535     }
00536   }
00537 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool generateSwitchBody ( CommonFn  commonFn,
const std::vector< AST_UnionBranch * > &  branches,
AST_Type *  discriminator,
const char *  statementPrefix,
const char *  namePrefix = "",
const char *  uni = "",
bool  forceDisableDefault = false,
bool  parens = true,
bool  breaks = true 
) [inline]

Definition at line 540 of file dds_generator.h.

References be_global, generateBranchLabels(), generateCaseBody(), and needSyntheticDefault().

Referenced by generateSwitchForUnion().

00546 {
00547   size_t n_labels = 0;
00548   bool has_default = false;
00549   for (size_t i = 0; i < branches.size(); ++i) {
00550     AST_UnionBranch* branch = branches[i];
00551     if (forceDisableDefault) {
00552       bool foundDefault = false;
00553       for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
00554         if (branch->label(j)->label_kind() == AST_UnionLabel::UL_default) {
00555           foundDefault = true;
00556         }
00557       }
00558       if (foundDefault) {
00559         has_default = true;
00560         continue;
00561       }
00562     }
00563     generateBranchLabels(branch, discriminator, n_labels, has_default);
00564     generateCaseBody(commonFn, branch, statementPrefix, namePrefix, uni, breaks, parens);
00565     be_global->impl_ <<
00566       "  }\n";
00567   }
00568   if (!has_default && needSyntheticDefault(discriminator, n_labels)) {
00569     be_global->impl_ <<
00570       "  default:\n" <<
00571       ((namePrefix == std::string(">> ")) ? "    uni._d(disc);\n" : "") <<
00572       "    break;\n";
00573     return true;
00574   }
00575   return false;
00576 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool generateSwitchForUnion ( const char *  switchExpr,
CommonFn  commonFn,
const std::vector< AST_UnionBranch * > &  branches,
AST_Type *  discriminator,
const char *  statementPrefix,
const char *  namePrefix = "",
const char *  uni = "",
bool  forceDisableDefault = false,
bool  parens = true,
bool  breaks = true 
) [inline]

returns true if a default: branch was generated (no default: label in IDL)

Definition at line 580 of file dds_generator.h.

References be_global, generateCaseBody(), generateSwitchBody(), and AstTypeClassification::resolveActualType().

Referenced by v8_generator::gen_union(), metaclass_generator::gen_union(), marshal_generator::gen_union(), and GeneratorBase::gen_union().

00586 {
00587   using namespace AstTypeClassification;
00588   AST_Type* dt = resolveActualType(discriminator);
00589   AST_PredefinedType* bt = AST_PredefinedType::narrow_from_decl(dt);
00590   if (bt && bt->pt() == AST_PredefinedType::PT_boolean) {
00591     AST_UnionBranch* true_branch = 0;
00592     AST_UnionBranch* false_branch = 0;
00593     AST_UnionBranch* default_branch = 0;
00594     for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(),
00595          limit = branches.end(); pos != limit; ++pos) {
00596       AST_UnionBranch* branch = *pos;
00597       for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
00598         AST_UnionLabel* label = branch->label(j);
00599         if (label->label_kind() == AST_UnionLabel::UL_default) {
00600           default_branch = branch;
00601         } else if (label->label_val()->ev()->u.bval) {
00602           true_branch = branch;
00603         } else if (!label->label_val()->ev()->u.bval) {
00604           false_branch = branch;
00605         }
00606       }
00607     }
00608 
00609     if (true_branch || false_branch) {
00610       be_global->impl_ <<
00611         "  if (" << switchExpr << ") {\n";
00612     } else {
00613       be_global->impl_ <<
00614         "  {\n";
00615     }
00616 
00617     if (true_branch || default_branch) {
00618       generateCaseBody(commonFn, true_branch ? true_branch : default_branch,
00619                        statementPrefix, namePrefix, uni, false, parens);
00620     }
00621 
00622     if (false_branch || (default_branch && true_branch)) {
00623       be_global->impl_ <<
00624         "  } else {\n";
00625       generateCaseBody(commonFn, false_branch ? false_branch : default_branch,
00626                        statementPrefix, namePrefix, uni, false, parens);
00627     }
00628 
00629     be_global->impl_ <<
00630       "  }\n";
00631 
00632     return !default_branch && bool(true_branch) != bool(false_branch);
00633 
00634   } else {
00635     be_global->impl_ <<
00636       "  switch (" << switchExpr << ") {\n";
00637     bool b(generateSwitchBody(commonFn, branches, discriminator,
00638                               statementPrefix, namePrefix, uni,
00639                               forceDisableDefault, parens, breaks));
00640     be_global->impl_ <<
00641       "  }\n";
00642     return b;
00643   }
00644 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string getEnumLabel ( AST_Expression *  label_val,
AST_Type *  disc 
) [inline]

Definition at line 379 of file dds_generator.h.

References scoped().

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

00380 {
00381   std::string e = scoped(disc->name()),
00382     label = label_val->n()->last_component()->get_string();
00383   const size_t colon = e.rfind("::");
00384   if (colon == std::string::npos) {
00385     return label;
00386   }
00387   return e.replace(colon + 2, std::string::npos, label);
00388 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string getWrapper ( const std::string &  name,
AST_Type *  type,
WrapDirection  wd 
) [inline]

Definition at line 372 of file dds_generator.h.

References wrapPrefix().

Referenced by metaclass_generator::gen_union(), marshal_generator::gen_union(), and generateCaseBody().

00373 {
00374   std::string pre = wrapPrefix(type, wd);
00375   return (pre.empty()) ? name : (pre + name + ')');
00376 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string module_scope ( UTL_ScopedName *  sn  )  [inline]

Definition at line 225 of file dds_generator.h.

References dds_generator::module_scope_helper().

00226 {
00227   return dds_generator::module_scope_helper(sn, "::");
00228 }

Here is the call graph for this function:

bool needSyntheticDefault ( AST_Type *  disc,
size_t  n_labels 
) [inline]

Definition at line 457 of file dds_generator.h.

Referenced by generateSwitchBody(), and GeneratorBase::needsDefault().

00458 {
00459   AST_Decl::NodeType nt = disc->node_type();
00460   if (nt == AST_Decl::NT_enum) return true;
00461 
00462   AST_PredefinedType* pdt = AST_PredefinedType::narrow_from_decl(disc);
00463   switch (pdt->pt()) {
00464   case AST_PredefinedType::PT_boolean:
00465     return n_labels < 2;
00466   case AST_PredefinedType::PT_char:
00467     return n_labels < ACE_OCTET_MAX;
00468   case AST_PredefinedType::PT_short:
00469   case AST_PredefinedType::PT_ushort:
00470     return n_labels < ACE_UINT16_MAX;
00471   case AST_PredefinedType::PT_long:
00472   case AST_PredefinedType::PT_ulong:
00473     return n_labels < ACE_UINT32_MAX;
00474   default:
00475     return true;
00476   }
00477 }

Here is the caller graph for this function:

std::ostream& operator<< ( std::ostream &  o,
const AST_Expression::AST_ExprValue &  ev 
) [inline]

Definition at line 391 of file dds_generator.h.

References ACE_CDR::Fixed::MAX_STRING_SIZE.

00393 {
00394   OpenDDS::DCPS::RestoreOutputStreamState ross(o);
00395   switch (ev.et) {
00396   case AST_Expression::EV_octet:
00397     return o << static_cast<int>(ev.u.oval);
00398   case AST_Expression::EV_short:
00399     return o << ev.u.sval;
00400   case AST_Expression::EV_ushort:
00401     return o << ev.u.usval << 'u';
00402   case AST_Expression::EV_long:
00403     return o << ev.u.lval;
00404   case AST_Expression::EV_ulong:
00405     return o << ev.u.ulval << 'u';
00406   case AST_Expression::EV_longlong:
00407     return o << ev.u.llval << "LL";
00408   case AST_Expression::EV_ulonglong:
00409     return o << ev.u.ullval << "ULL";
00410   case AST_Expression::EV_wchar:
00411     return o << "L'" << static_cast<char>(ev.u.wcval) << '\'';
00412   case AST_Expression::EV_char:
00413     return o << '\'' << ev.u.cval << '\'';
00414   case AST_Expression::EV_bool:
00415     return o << std::boolalpha << static_cast<bool>(ev.u.bval);
00416   case AST_Expression::EV_float:
00417     return o << ev.u.fval << 'f';
00418   case AST_Expression::EV_double:
00419     return o << ev.u.dval;
00420   case AST_Expression::EV_wstring:
00421     return o << "L\"" << ev.u.wstrval << '"';
00422   case AST_Expression::EV_string:
00423     return o << '"' << ev.u.strval->get_string() << '"';
00424 #ifdef ACE_HAS_CDR_FIXED
00425   case AST_Expression::EV_fixed: {
00426     char buf[ACE_CDR::Fixed::MAX_STRING_SIZE];
00427     ev.u.fixedval.to_string(buf, sizeof buf);
00428     return o << "\"" << buf << "\"";
00429   }
00430 #endif
00431   default:
00432     return o;
00433   }
00434 }

std::string scoped ( UTL_ScopedName *  sn  )  [inline]
std::string wrapPrefix ( AST_Type *  type,
WrapDirection  wd 
) [inline]

Definition at line 338 of file dds_generator.h.

References WD_OUTPUT.

Referenced by getWrapper().

00339 {
00340   switch (type->node_type()) {
00341   case AST_Decl::NT_pre_defined: {
00342     AST_PredefinedType* p = AST_PredefinedType::narrow_from_decl(type);
00343     switch (p->pt()) {
00344     case AST_PredefinedType::PT_char:
00345       return (wd == WD_OUTPUT)
00346         ? "ACE_OutputCDR::from_char(" : "ACE_InputCDR::to_char(";
00347     case AST_PredefinedType::PT_wchar:
00348       return (wd == WD_OUTPUT)
00349         ? "ACE_OutputCDR::from_wchar(" : "ACE_InputCDR::to_wchar(";
00350     case AST_PredefinedType::PT_octet:
00351       return (wd == WD_OUTPUT)
00352         ? "ACE_OutputCDR::from_octet(" : "ACE_InputCDR::to_octet(";
00353     case AST_PredefinedType::PT_boolean:
00354       return (wd == WD_OUTPUT)
00355         ? "ACE_OutputCDR::from_boolean(" : "ACE_InputCDR::to_boolean(";
00356     default:
00357       return "";
00358     }
00359   }
00360   case AST_Decl::NT_string:
00361     return (wd == WD_OUTPUT)
00362       ? "ACE_OutputCDR::from_string(" : "ACE_InputCDR::to_string(";
00363   case AST_Decl::NT_wstring:
00364     return (wd == WD_OUTPUT)
00365       ? "ACE_OutputCDR::from_wstring(" : "ACE_InputCDR::to_wstring(";
00366   default:
00367     return "";
00368   }
00369 }

Here is the caller graph for this function:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1