OpenDDS  Snapshot(2023/04/28-20:55)
Classes | Namespaces | Typedefs | Enumerations | Functions | Variables
dds_generator.h File Reference
#include "be_extern.h"
#include "be_util.h"
#include <dds/DCPS/ValueHelper.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 <set>
#include <stdexcept>
#include <iomanip>
#include <cctype>
#include <climits>
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
 
class  PreprocessorIfGuard
 
struct  NestedForLoops
 
struct  Intro
 
class  Fields
 
class  Fields::Iterator
 
struct  RefWrapper
 

Namespaces

 AstTypeClassification
 

Typedefs

typedef size_t AstTypeClassification::Classification
 
typedef std::string(* CommonFn) (const std::string &indent, AST_Decl *node, const std::string &name, AST_Type *type, const std::string &prefix, bool wrap_nested_key_only, Intro &intro, const std::string &)
 

Enumerations

enum  EscapeContext { EscapeContext_ForGenIdl, EscapeContext_FromGenIdl, EscapeContext_StripEscapes, EscapeContext_Normal }
 
enum  WrapDirection { WD_OUTPUT, WD_INPUT }
 
enum  FieldFilter { FieldFilter_All, FieldFilter_NestedKeyOnly, FieldFilter_KeyOnly }
 

Functions

std::string canonical_name (UTL_ScopedName *sn)
 
std::string canonical_name (Identifier *id)
 
std::string canonical_name (AST_Decl *node)
 
std::string scoped (UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
 
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 string_type (AstTypeClassification::Classification cls)
 
std::string to_cxx_type (AST_Type *type, std::size_t &size)
 
std::string getWrapper (const std::string &name, AST_Type *type, WrapDirection wd)
 
std::string getEnumLabel (AST_Expression *label_val, AST_Type *disc)
 
std::ostreamoperator<< (std::ostream &o, const AST_Expression::AST_ExprValue &ev)
 
std::string bounded_arg (AST_Type *type)
 
std::string type_to_default (const std::string &indent, AST_Type *type, const std::string &name, bool is_anonymous=false, bool is_union=false)
 
void generateBranchLabels (AST_UnionBranch *branch, AST_Type *discriminator, size_t &n_labels, bool &has_default)
 
bool needSyntheticDefault (AST_Type *disc, size_t n_labels)
 
std::string field_type_name (AST_Field *field, AST_Type *field_type=0)
 
AST_Type * deepest_named_type (AST_Type *type)
 
void generateCaseBody (CommonFn commonFn, CommonFn commonFn2, AST_UnionBranch *branch, const char *statementPrefix, const char *namePrefix, const char *uni, bool generateBreaks, bool parens)
 
bool generateSwitchBody (AST_Union *, 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, CommonFn commonFn2=0)
 
bool generateSwitchForUnion (AST_Union *u, 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, CommonFn commonFn2=0)
 returns true if a default: branch was generated (no default: label in IDL) More...
 
std::string insert_cxx11_accessor_parens (const std::string &full_var_name_, bool is_union_member=false)
 
AST_Field * get_struct_field (AST_Structure *struct_node, unsigned index)
 
bool struct_has_explicit_keys (AST_Structure *node)
 
ACE_CDR::ULong array_element_count (AST_Array *arr)
 
ACE_CDR::ULong container_element_limit (AST_Type *type)
 
AST_Type * container_base_type (AST_Type *type)
 
bool needs_nested_key_only (AST_Type *type)
 
bool needs_forany (AST_Type *type)
 
bool needs_distinct_type (AST_Type *type)
 
std::string strip_shift_op (const std::string &s)
 
const char * get_shift_op (const std::string &s)
 

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
 
const char *const shift_out = "<< "
 
const char *const shift_in = ">> "
 

Typedef Documentation

◆ CommonFn

typedef std::string(* CommonFn) (const std::string &indent, AST_Decl *node, const std::string &name, AST_Type *type, const std::string &prefix, bool wrap_nested_key_only, Intro &intro, const std::string &)

Definition at line 799 of file dds_generator.h.

Enumeration Type Documentation

◆ EscapeContext

How to handle IDL underscore escaping. Depends on where the name is going and where the name came from.

Enumerator
EscapeContext_ForGenIdl 

This is for generated IDL. (Like *TypeSupport.idl)

EscapeContext_FromGenIdl 

This is for a name coming from generated IDL. (Like *TypeSupportC.h)

EscapeContext_StripEscapes 

Strip any escapes.

EscapeContext_Normal 

This is for everything else.

Definition at line 37 of file dds_generator.h.

37  {
38  /// This is for generated IDL. (Like *TypeSupport.idl)
40  /// This is for a name coming from generated IDL. (Like *TypeSupportC.h)
42  /// Strip any escapes
44  /// This is for everything else.
46 };
This is for everything else.
Definition: dds_generator.h:45
Strip any escapes.
Definition: dds_generator.h:43
This is for generated IDL. (Like *TypeSupport.idl)
Definition: dds_generator.h:39
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
Definition: dds_generator.h:41

◆ FieldFilter

Enumerator
FieldFilter_All 
FieldFilter_NestedKeyOnly 
FieldFilter_KeyOnly 

Definition at line 1070 of file dds_generator.h.

◆ WrapDirection

Enumerator
WD_OUTPUT 
WD_INPUT 

Definition at line 477 of file dds_generator.h.

Function Documentation

◆ array_element_count()

ACE_CDR::ULong array_element_count ( AST_Array *  arr)
inline

Definition at line 1221 of file dds_generator.h.

Referenced by container_element_limit(), marshal_generator::gen_enum(), metaclass_generator::gen_typedef(), and generate_anon_fields().

1222 {
1223  ACE_CDR::ULong count = 1;
1224  for (ACE_CDR::ULong i = 0; i < arr->n_dims(); ++i) {
1225  count *= arr->dims()[i]->ev()->u.ulval;
1226  }
1227  return count;
1228 }
ACE_UINT32 ULong

◆ bounded_arg()

std::string bounded_arg ( AST_Type *  type)
inline

Definition at line 694 of file dds_generator.h.

References AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::classify(), name, and type_to_default().

Referenced by marshal_generator::gen_enum(), marshal_generator::gen_typedef(), and generateCaseBody().

695 {
696  using namespace AstTypeClassification;
697  std::ostringstream arg;
698  const Classification cls = classify(type);
699  if (cls & CL_STRING) {
700  AST_String* const str = dynamic_cast<AST_String*>(type);
701  arg << str->max_size()->ev()->u.ulval;
702  } else if (cls & CL_SEQUENCE) {
703  AST_Sequence* const seq = dynamic_cast<AST_Sequence*>(type);
704  arg << seq->max_size()->ev()->u.ulval;
705  }
706  return arg.str();
707 }
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_SEQUENCE

◆ canonical_name() [1/3]

std::string canonical_name ( UTL_ScopedName *  sn)
inline

◆ canonical_name() [2/3]

std::string canonical_name ( Identifier id)
inline

Definition at line 125 of file dds_generator.h.

References EscapeContext_StripEscapes, and dds_generator::to_string().

126 {
128 }
Strip any escapes.
Definition: dds_generator.h:43
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)

◆ canonical_name() [3/3]

std::string canonical_name ( AST_Decl *  node)
inline

Definition at line 130 of file dds_generator.h.

References canonical_name().

131 {
132  return canonical_name(node->local_name());
133 }
std::string canonical_name(UTL_ScopedName *sn)

◆ container_base_type()

AST_Type* container_base_type ( AST_Type *  type)
inline

Definition at line 1245 of file dds_generator.h.

References AstTypeClassification::resolveActualType().

Referenced by FieldInfo::EleLen::EleLen().

1246 {
1247  AST_Type* const act = AstTypeClassification::resolveActualType(type);
1248  AST_Sequence* const seq = dynamic_cast<AST_Sequence*>(act);
1249  AST_Array* const arr = dynamic_cast<AST_Array*>(act);
1250  if (seq) {
1251  return seq->base_type();
1252  } else if (arr) {
1253  return arr->base_type();
1254  }
1255  return 0;
1256 }
AST_Type * resolveActualType(AST_Type *element)

◆ container_element_limit()

ACE_CDR::ULong container_element_limit ( AST_Type *  type)
inline

Definition at line 1231 of file dds_generator.h.

References array_element_count(), and AstTypeClassification::resolveActualType().

1232 {
1233  AST_Type* const act = AstTypeClassification::resolveActualType(type);
1234  AST_Sequence* const seq = dynamic_cast<AST_Sequence*>(act);
1235  AST_Array* const arr = dynamic_cast<AST_Array*>(act);
1236  if (seq && !seq->unbounded()) {
1237  return seq->max_size()->ev()->u.ulval;
1238  } else if (arr) {
1239  return array_element_count(arr);
1240  }
1241  return 0;
1242 }
AST_Type * resolveActualType(AST_Type *element)
ACE_CDR::ULong array_element_count(AST_Array *arr)

◆ deepest_named_type()

AST_Type* deepest_named_type ( AST_Type *  type)

For the some situations, like a tag name, the type name we need is the deepest named type, not the actual type. This will be the name of the deepest typedef if it's an array or sequence, otherwise the name of the type.

Definition at line 442 of file dds_generator.cpp.

Referenced by field_type_name(), marshal_generator::gen_enum(), marshal_generator::gen_field_getValueFromSerialized(), metaclass_generator::gen_typedef(), gen_union_branch(), generate_anon_fields(), Intro::insert(), and type_to_default_array().

443 {
444  AST_Type* consider = type;
445  AST_Type* named_type = type;
446  while (consider->node_type() == AST_Decl::NT_typedef) {
447  named_type = consider;
448  consider = dynamic_cast<AST_Typedef*>(named_type)->base_type();
449  }
450  return named_type;
451 }

◆ field_type_name()

std::string field_type_name ( AST_Field *  field,
AST_Type *  field_type = 0 
)

Definition at line 425 of file dds_generator.cpp.

References FieldInfo::as_base_, AstTypeClassification::CL_STRING, AstTypeClassification::classify(), deepest_named_type(), name, scoped(), FieldInfo::scoped_type_, string_type(), and FieldInfo::type_.

Referenced by marshal_generator::gen_field_getValueFromSerialized(), marshal_generator::gen_typedef(), gen_union_branch(), generateCaseBody(), and Intro::insert().

426 {
427  if (!field_type) {
428  field_type = field->field_type();
429  }
430  const Classification cls = classify(field_type);
431  const std::string name = (cls & CL_STRING) ?
432  string_type(cls) : scoped(deepest_named_type(field_type)->name());
433  if (field) {
434  FieldInfo af(*field);
435  if (af.as_base_ && af.type_->anonymous()) {
436  return af.scoped_type_;
437  }
438  }
439  return name;
440 }
Classification classify(AST_Type *type)
std::string string_type(AstTypeClassification::Classification cls)
const Classification CL_STRING
AST_Type * deepest_named_type(AST_Type *type)
const char *const name
Definition: debug.cpp:60
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)

◆ generateBranchLabels()

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

Definition at line 713 of file dds_generator.h.

References be_global, and getEnumLabel().

Referenced by generateSwitchBody().

715 {
716  for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
717  ++n_labels;
718  AST_UnionLabel* label = branch->label(j);
719  if (label->label_kind() == AST_UnionLabel::UL_default) {
720  be_global->impl_ << " default:";
721  has_default = true;
722  } else if (discriminator->node_type() == AST_Decl::NT_enum) {
723  be_global->impl_ << " case "
724  << getEnumLabel(label->label_val(), discriminator) << ':';
725  } else {
726  be_global->impl_ << " case " << *label->label_val()->ev() << ':';
727  }
728  be_global->impl_<< ((j == branch->label_list_length() - 1) ? " {\n" : "\n");
729  }
730 }
std::string getEnumLabel(AST_Expression *label_val, AST_Type *disc)
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ generateCaseBody()

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

Definition at line 806 of file dds_generator.h.

References be_global, bounded_arg(), AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_BOUNDED, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), field_type_name(), dds_generator::get_tag_name(), getWrapper(), Intro::join(), name, AstTypeClassification::resolveActualType(), tryconstructfailaction_trim, tryconstructfailaction_use_default, type_to_default(), and WD_INPUT.

Referenced by generateSwitchBody(), and generateSwitchForUnion().

810 {
811  using namespace AstTypeClassification;
812  const BE_GlobalData::LanguageMapping lmap = be_global->language_mapping();
813  const bool use_cxx11 = lmap == BE_GlobalData::LANGMAP_CXX11;
814  const std::string name = branch->local_name()->get_string();
815  if (namePrefix == std::string(">> ")) {
816  std::string brType = field_type_name(branch, branch->field_type());
817  std::string forany;
818  AST_Type* br = resolveActualType(branch->field_type());
819  Classification br_cls = classify(br);
820  if (!br->in_main_file()
821  && br->node_type() != AST_Decl::NT_pre_defined) {
822  be_global->add_referenced(br->file_name().c_str());
823  }
824 
825  std::string rhs;
826  const bool is_face = lmap == BE_GlobalData::LANGMAP_FACE_CXX;
827  const bool is_wide = br_cls & CL_WIDE;
828  const bool is_bound_string = (br_cls & (CL_STRING | CL_BOUNDED)) == (CL_STRING | CL_BOUNDED);
829  const std::string bound_string_suffix = (is_bound_string && !is_face) ? ".c_str()" : "";
830 
831  if (is_bound_string) {
832  const std::string to_type = is_face ? is_wide ? "ACE_InputCDR::to_wstring" : "ACE_InputCDR::to_string"
833  : is_wide ? "Serializer::ToBoundedString<wchar_t>" : "Serializer::ToBoundedString<char>";
834  const std::string face_suffix = is_face ? ".out()" : "";
835  brType = is_face ? is_wide ? "FACE::WString_var" : "FACE::String_var"
836  : is_wide ? "OPENDDS_WSTRING" : "OPENDDS_STRING";
837  rhs = to_type + "(tmp" + face_suffix + ", " + bounded_arg(br) + ")";
838  } else if (br_cls & CL_STRING) {
839  const std::string nmspace = is_face ? "FACE::" : "CORBA::";
840  brType = use_cxx11 ? std::string("std::") + (is_wide ? "w" : "") + "string"
841  : nmspace + (is_wide ? "W" : "") + "String_var";
842  rhs = use_cxx11 ? "tmp" : "tmp.out()";
843  } else if (use_cxx11 && (br_cls & (CL_ARRAY | CL_SEQUENCE))) { //array or seq C++11
844  rhs = "IDL::DistinctType<" + brType + ", "
846  + ">(tmp)";
847  } else if (br_cls & CL_ARRAY) { //array classic
848  forany = " " + brType + "_forany fa = tmp;\n";
849  rhs = getWrapper("fa", br, WD_INPUT);
850  } else { // anything else
851  rhs = getWrapper("tmp", br, WD_INPUT);
852  }
853 
854  if (*statementPrefix) {
855  be_global->impl_ << statementPrefix;
856  }
857  be_global->impl_ <<
858  " " << brType << " tmp;\n" << forany <<
859  " if (strm >> " << rhs << ") {\n"
860  " uni." << name << (use_cxx11 ? "(std::move(tmp));\n" : "(tmp" + bound_string_suffix + ");\n") <<
861  " uni._d(disc);\n"
862  " return true;\n"
863  " }\n";
864 
865  if (be_global->try_construct(branch) == tryconstructfailaction_use_default) {
866  be_global->impl_ <<
867  type_to_default(" ", br, "uni." + name, branch->anonymous(), true) <<
868  " strm.set_construction_status(Serializer::ConstructionSuccessful);\n"
869  " return true;\n";
870  } else if ((be_global->try_construct(branch) == tryconstructfailaction_trim) && (br_cls & CL_BOUNDED) &&
871  (br_cls & (CL_STRING | CL_SEQUENCE))) {
872  if (is_bound_string) {
873  const std::string check_not_empty = "!tmp.empty()";
874  const std::string get_length = use_cxx11 ? "tmp.length()" : "ACE_OS::strlen(tmp.c_str())";
875  const std::string inout = use_cxx11 ? "" : ".inout()";
876  const std::string strtype = br_cls & CL_WIDE ? "std::wstring" : "std::string";
877  be_global->impl_ <<
878  " if (strm.get_construction_status() == Serializer::BoundConstructionFailure && " << check_not_empty << " && ("
879  << bounded_arg(br) << " < " << get_length << ")) {\n"
880  " " << strtype << " s = tmp.c_str();\n"
881  " s.resize(" << bounded_arg(br) << ");\n"
882  " uni." << name << "(s.c_str());\n"
883  " strm.set_construction_status(Serializer::ConstructionSuccessful);\n"
884  " return true;\n"
885  " } else {\n"
886  " strm.set_construction_status(Serializer::ElementConstructionFailure);\n"
887  " return false;\n"
888  " }\n";
889  } else if (br_cls & CL_SEQUENCE) {
890  be_global->impl_ <<
891  " if(strm.get_construction_status() == Serializer::ElementConstructionFailure) {\n"
892  " return false;\n"
893  " }\n"
894  " uni." << name << (use_cxx11 ? "(std::move(tmp));\n" : "(tmp);\n") <<
895  " uni._d(disc);\n"
896  " strm.set_construction_status(Serializer::ConstructionSuccessful);\n"
897  " return true;\n";
898  }
899  } else {
900  //discard/default
901  be_global->impl_ <<
902  " strm.set_construction_status(Serializer::ElementConstructionFailure);\n"
903  " return false;\n ";
904  }
905  } else {
906  const char* breakString = generateBreaks ? " break;\n" : "";
907  const std::string indent = " ";
908  Intro intro;
909  std::ostringstream contents;
910  if (commonFn2) {
911  const OpenDDS::XTypes::MemberId id = be_global->get_id(branch);
912  contents
913  << commonFn2(indent, branch, name + (parens ? "()" : ""), branch->field_type(), "uni", false, intro, "")
914  << indent << "if (!strm.write_parameter_id(" << id << ", size)) {\n"
915  << indent << " return false;\n"
916  << indent << "}\n";
917  }
918  const std::string expr = commonFn(indent, branch,
919  name + (parens ? "()" : ""), branch->field_type(),
920  std::string(namePrefix) + "uni", false, intro, uni);
921  if (*statementPrefix) {
922  contents <<
923  indent << statementPrefix << " " << expr << ";\n" <<
924  (statementPrefix == std::string("return") ? "" : breakString);
925  } else {
926  contents << expr << breakString;
927  }
928  intro.join(be_global->impl_, indent);
929  be_global->impl_ << contents.str();
930  }
931 }
std::string bounded_arg(AST_Type *type)
std::string type_to_default(const std::string &indent, AST_Type *type, const std::string &name, bool is_anonymous=false, bool is_union=false)
Classification classify(AST_Type *type)
void join(std::ostream &os, const std::string &indent)
std::string field_type_name(AST_Field *field, AST_Type *field_type=0)
ACE_CDR::ULong MemberId
Definition: TypeObject.h:910
const Classification CL_STRING
const Classification CL_WIDE
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
const Classification CL_BOUNDED
const Classification CL_ARRAY
std::string getWrapper(const std::string &name, AST_Type *type, WrapDirection wd)
AST_Type * resolveActualType(AST_Type *element)
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:44
const Classification CL_SEQUENCE

◆ generateSwitchBody()

bool generateSwitchBody ( AST_Union *  ,
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,
CommonFn  commonFn2 = 0 
)
inline

Definition at line 934 of file dds_generator.h.

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

Referenced by marshal_generator::gen_field_getValueFromSerialized(), and generateSwitchForUnion().

940 {
941  size_t n_labels = 0;
942  bool has_default = false;
943  for (size_t i = 0; i < branches.size(); ++i) {
944  AST_UnionBranch* branch = branches[i];
945  if (forceDisableDefault) {
946  bool foundDefault = false;
947  for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
948  if (branch->label(j)->label_kind() == AST_UnionLabel::UL_default) {
949  foundDefault = true;
950  }
951  }
952  if (foundDefault) {
953  has_default = true;
954  continue;
955  }
956  }
957  generateBranchLabels(branch, discriminator, n_labels, has_default);
958  generateCaseBody(commonFn, commonFn2, branch, statementPrefix, namePrefix,
959  uni, breaks, parens);
960  be_global->impl_ <<
961  " }\n";
962  }
963  if (!has_default && needSyntheticDefault(discriminator, n_labels)) {
964  be_global->impl_ <<
965  " default:\n" <<
966  ((namePrefix == std::string(">> ")) ? " uni._d(disc);\n" : "") <<
967  " break;\n";
968  return true;
969  }
970  return false;
971 }
void generateBranchLabels(AST_UnionBranch *branch, AST_Type *discriminator, size_t &n_labels, bool &has_default)
void generateCaseBody(CommonFn commonFn, CommonFn commonFn2, AST_UnionBranch *branch, const char *statementPrefix, const char *namePrefix, const char *uni, bool generateBreaks, bool parens)
bool needSyntheticDefault(AST_Type *disc, size_t n_labels)
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ generateSwitchForUnion()

bool generateSwitchForUnion ( AST_Union *  u,
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,
CommonFn  commonFn2 = 0 
)
inline

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

Definition at line 975 of file dds_generator.h.

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

Referenced by marshal_generator::gen_field_getValueFromSerialized(), marshal_generator::gen_union(), value_writer_generator::gen_union(), value_reader_generator::gen_union(), metaclass_generator::gen_union(), GeneratorBase::gen_union(), and Cxx11Generator::gen_union().

981 {
982  using namespace AstTypeClassification;
983  AST_Type* dt = resolveActualType(discriminator);
984  AST_PredefinedType* bt = dynamic_cast<AST_PredefinedType*>(dt);
985  if (bt && bt->pt() == AST_PredefinedType::PT_boolean) {
986  AST_UnionBranch* true_branch = 0;
987  AST_UnionBranch* false_branch = 0;
988  AST_UnionBranch* default_branch = 0;
989  for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(),
990  limit = branches.end(); pos != limit; ++pos) {
991  AST_UnionBranch* branch = *pos;
992  for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
993  AST_UnionLabel* label = branch->label(j);
994  if (label->label_kind() == AST_UnionLabel::UL_default) {
995  default_branch = branch;
996  } else if (label->label_val()->ev()->u.bval) {
997  true_branch = branch;
998  } else if (!label->label_val()->ev()->u.bval) {
999  false_branch = branch;
1000  }
1001  }
1002  }
1003 
1004  if (true_branch || false_branch) {
1005  be_global->impl_ <<
1006  " if (" << switchExpr << ") {\n";
1007  } else {
1008  be_global->impl_ <<
1009  " {\n";
1010  }
1011 
1012  if (true_branch || default_branch) {
1013  generateCaseBody(commonFn, commonFn2, true_branch ? true_branch : default_branch,
1014  statementPrefix, namePrefix, uni, false, parens);
1015  }
1016 
1017  if (false_branch || (default_branch && true_branch)) {
1018  be_global->impl_ <<
1019  " } else {\n";
1020  generateCaseBody(commonFn, commonFn2, false_branch ? false_branch : default_branch,
1021  statementPrefix, namePrefix, uni, false, parens);
1022  }
1023 
1024  be_global->impl_ <<
1025  " }\n";
1026 
1027  return !default_branch && bool(true_branch) != bool(false_branch);
1028 
1029  } else {
1030  be_global->impl_ <<
1031  " switch (" << switchExpr << ") {\n";
1032  bool b(generateSwitchBody(u, commonFn, branches, discriminator,
1033  statementPrefix, namePrefix, uni,
1034  forceDisableDefault, parens, breaks,
1035  commonFn2));
1036  be_global->impl_ <<
1037  " }\n";
1038  return b;
1039  }
1040 }
void generateCaseBody(CommonFn commonFn, CommonFn commonFn2, AST_UnionBranch *branch, const char *statementPrefix, const char *namePrefix, const char *uni, bool generateBreaks, bool parens)
bool generateSwitchBody(AST_Union *, 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, CommonFn commonFn2=0)
AST_Type * resolveActualType(AST_Type *element)
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ get_shift_op()

const char* get_shift_op ( const std::string &  s)
inline

Definition at line 1348 of file dds_generator.h.

References shift_in, and shift_out.

1349 {
1350  const size_t shift_len = 3;
1351  if (s.size() > shift_len) {
1352  const std::string first3 = s.substr(0, shift_len);
1353  if (first3 == shift_in) {
1354  return shift_in;
1355  }
1356  if (first3 == shift_out) {
1357  return shift_out;
1358  }
1359  }
1360  return "";
1361 }
const char *const shift_in
const char *const shift_out

◆ get_struct_field()

AST_Field* get_struct_field ( AST_Structure *  struct_node,
unsigned  index 
)
inline

Definition at line 1077 of file dds_generator.h.

Referenced by marshal_generator::gen_typedef(), Fields::Iterator::operator*(), and struct_has_explicit_keys().

1078 {
1079  if (!struct_node || index >= struct_node->nfields()) {
1080  return 0;
1081  }
1082  AST_Field** field_ptrptr;
1083  struct_node->field(field_ptrptr, index);
1084  return field_ptrptr ? *field_ptrptr : 0;
1085 }

◆ getEnumLabel()

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

Definition at line 618 of file dds_generator.h.

References be_global, and scoped().

Referenced by generateBranchLabels(), GeneratorBase::GenerateUnionAccessors::operator()(), and Cxx11Generator::union_accessors().

619 {
620  std::string e = scoped(disc->name()),
621  label = label_val->n()->last_component()->get_string();
622  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
623  return e + "::" + label;
624  }
625  const size_t colon = e.rfind("::");
626  if (colon == std::string::npos) {
627  return label;
628  }
629  return e.replace(colon + 2, std::string::npos, label);
630 }
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ getWrapper()

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

Definition at line 603 of file dds_generator.h.

References be_global, AstTypeClassification::CL_BOUNDED, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), WD_OUTPUT, and wrapPrefix().

Referenced by marshal_generator::gen_enum(), marshal_generator::gen_field_getValueFromSerialized(), marshal_generator::gen_typedef(), marshal_generator::gen_union(), metaclass_generator::gen_union(), marshal_generator::gen_union_default(), and generateCaseBody().

604 {
605  using namespace AstTypeClassification;
606  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11) {
607  const Classification cls = classify(type);
608  if ((cls & (CL_BOUNDED | CL_STRING)) == (CL_BOUNDED | CL_STRING)) {
609  return (wd == WD_OUTPUT ? "Serializer::FromBoundedString" : "Serializer::ToBoundedString")
610  + std::string(cls & CL_WIDE ? "<wchar_t>(" : "<char>(") + name + ')';
611  }
612  }
613  std::string pre = wrapPrefix(type, wd);
614  return (pre.empty()) ? name : (pre + name + ')');
615 }
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_WIDE
const Classification CL_BOUNDED
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:44
std::string wrapPrefix(AST_Type *type, WrapDirection wd)

◆ insert_cxx11_accessor_parens()

std::string insert_cxx11_accessor_parens ( const std::string &  full_var_name_,
bool  is_union_member = false 
)
inline

Definition at line 1043 of file dds_generator.h.

References be_global.

Referenced by keys_generator::gen_struct(), and marshal_generator::gen_typedef().

1045 {
1046  const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
1047  if (!use_cxx11 || is_union_member || full_var_name_.empty()) {
1048  return full_var_name_;
1049  }
1050 
1051  std::string full_var_name(full_var_name_);
1052  std::string::size_type n = 0;
1053  while ((n = full_var_name.find('.', n)) != std::string::npos) {
1054  if (full_var_name[n-1] != ']') {
1055  full_var_name.insert(n, "()");
1056  n += 3;
1057  } else {
1058  ++n;
1059  }
1060  }
1061  n = 0;
1062  while ((n = full_var_name.find('[', n)) != std::string::npos) {
1063  full_var_name.insert(n, "()");
1064  n += 3;
1065  }
1066  return full_var_name[full_var_name.size() - 1] == ']'
1067  ? full_var_name : full_var_name + "()";
1068 }
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ module_scope()

std::string module_scope ( UTL_ScopedName *  sn)
inline

Definition at line 367 of file dds_generator.h.

References dds_generator::module_scope_helper().

Referenced by value_writer_generator::gen_enum().

368 {
369  return dds_generator::module_scope_helper(sn, "::");
370 }
static std::string module_scope_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)

◆ needs_distinct_type()

bool needs_distinct_type ( AST_Type *  type)
inline

Definition at line 1324 of file dds_generator.h.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::classify(), and AstTypeClassification::resolveActualType().

Referenced by RefWrapper::done().

1325 {
1326  using namespace AstTypeClassification;
1327  const Classification type_class = classify(resolveActualType(type));
1328  return be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11 &&
1329  type_class & (CL_SEQUENCE | CL_ARRAY);
1330 }
Classification classify(AST_Type *type)
const Classification CL_ARRAY
AST_Type * resolveActualType(AST_Type *element)
BE_GlobalData * be_global
Definition: be_global.cpp:44
const Classification CL_SEQUENCE

◆ needs_forany()

bool needs_forany ( AST_Type *  type)
inline

Definition at line 1316 of file dds_generator.h.

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

Referenced by RefWrapper::done().

1317 {
1318  using namespace AstTypeClassification;
1319  const Classification type_class = classify(resolveActualType(type));
1320  return be_global->language_mapping() != BE_GlobalData::LANGMAP_CXX11 &&
1321  type_class & CL_ARRAY;
1322 }
Classification classify(AST_Type *type)
const Classification CL_ARRAY
AST_Type * resolveActualType(AST_Type *element)
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ needs_nested_key_only()

bool needs_nested_key_only ( AST_Type *  type)
inline

Returns true for a type if nested key serialization is different from normal serialization.

Definition at line 1262 of file dds_generator.h.

References be_global, Fields::begin(), AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::CL_UNION, AstTypeClassification::classify(), Fields::end(), name, AstTypeClassification::resolveActualType(), scoped(), and struct_has_explicit_keys().

Referenced by RefWrapper::done(), and marshal_generator::gen_enum().

1263 {
1264  AST_Type* const non_aliased_type = type;
1265 
1266  using namespace AstTypeClassification;
1267 
1268  static std::vector<AST_Type*> type_stack;
1269  type = resolveActualType(type);
1270  // Check if we have encountered the same type recursively
1271  for (size_t i = 0; i < type_stack.size(); ++i) {
1272  if (type == type_stack[i]) {
1273  return true;
1274  }
1275  }
1276  type_stack.push_back(type);
1277 
1278  bool result = false;
1279  const std::string name = scoped(type->name());
1280 
1281  std::string template_name;
1282  if (be_global->special_serialization(non_aliased_type, template_name)) {
1283  result = false;
1284  } else {
1285  const Classification type_class = classify(type);
1286  if (type_class & CL_ARRAY) {
1287  result = needs_nested_key_only(dynamic_cast<AST_Array*>(type)->base_type());
1288  } else if (type_class & CL_SEQUENCE) {
1289  result = needs_nested_key_only(dynamic_cast<AST_Sequence*>(type)->base_type());
1290  } else if (type_class & CL_STRUCTURE) {
1291  AST_Structure* const struct_node = dynamic_cast<AST_Structure*>(type);
1292  // TODO(iguessthislldo): Possible optimization: If everything in a struct
1293  // was a key recursively, then we could return false.
1294  if (struct_has_explicit_keys(struct_node)) {
1295  result = true;
1296  } else {
1297  const Fields fields(struct_node);
1298  const Fields::Iterator fields_end = fields.end();
1299  for (Fields::Iterator i = fields.begin(); i != fields_end; ++i) {
1300  if (needs_nested_key_only((*i)->field_type())) {
1301  result = true;
1302  break;
1303  }
1304  }
1305  }
1306  } else if (type_class & CL_UNION) {
1307  // A union will always be different as a key because it's just the
1308  // discriminator.
1309  result = true;
1310  }
1311  }
1312  type_stack.pop_back();
1313  return result;
1314 }
Classification classify(AST_Type *type)
bool struct_has_explicit_keys(AST_Structure *node)
const Classification CL_ARRAY
AST_Type * resolveActualType(AST_Type *element)
const char *const name
Definition: debug.cpp:60
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
const Classification CL_STRUCTURE
BE_GlobalData * be_global
Definition: be_global.cpp:44
const Classification CL_SEQUENCE
bool needs_nested_key_only(AST_Type *type)
const Classification CL_UNION

◆ needSyntheticDefault()

bool needSyntheticDefault ( AST_Type *  disc,
size_t  n_labels 
)
inline

Definition at line 733 of file dds_generator.h.

References ACE_OCTET_MAX, ACE_UINT16_MAX, and ACE_UINT32_MAX.

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

734 {
735  AST_Decl::NodeType nt = disc->node_type();
736  if (nt == AST_Decl::NT_enum) return true;
737 
738  AST_PredefinedType* pdt = dynamic_cast<AST_PredefinedType*>(disc);
739  switch (pdt->pt()) {
740  case AST_PredefinedType::PT_boolean:
741  return n_labels < 2;
742 #if OPENDDS_HAS_EXPLICIT_INTS
743  case AST_PredefinedType::PT_int8:
744  case AST_PredefinedType::PT_uint8:
745 #endif
746  case AST_PredefinedType::PT_char:
747  case AST_PredefinedType::PT_octet:
748  return n_labels < ACE_OCTET_MAX;
749  case AST_PredefinedType::PT_short:
750  case AST_PredefinedType::PT_ushort:
751  case AST_PredefinedType::PT_wchar:
752  return n_labels < ACE_UINT16_MAX;
753  case AST_PredefinedType::PT_long:
754  case AST_PredefinedType::PT_ulong:
755  return n_labels < ACE_UINT32_MAX;
756  default:
757  return true;
758  }
759 }
#define ACE_OCTET_MAX
#define ACE_UINT16_MAX
#define ACE_UINT32_MAX

◆ operator<<()

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

Definition at line 633 of file dds_generator.h.

References ACE_INT32_MIN, ACE_INT64_MIN, OpenDDS::DCPS::hex_value(), ACE_CDR::Fixed::MAX_STRING_SIZE, and be_util::misc_error_and_abort().

635 {
636  using namespace OpenDDS::DCPS;
637  RestoreOutputStreamState ross(o);
638  switch (ev.et) {
639  case AST_Expression::EV_octet:
640  return hex_value(o << "0x", static_cast<int>(ev.u.oval), 1);
641 #if OPENDDS_HAS_EXPLICIT_INTS
642  case AST_Expression::EV_int8:
643  return o << static_cast<short>(ev.u.int8val);
644  case AST_Expression::EV_uint8:
645  return o << static_cast<unsigned short>(ev.u.uint8val);
646 #endif
647  case AST_Expression::EV_short:
648  return o << ev.u.sval;
649  case AST_Expression::EV_ushort:
650  return o << ev.u.usval << 'u';
651  case AST_Expression::EV_long:
652  return signed_int_helper<ACE_CDR::Long>(o, ev.u.lval, ACE_INT32_MIN);
653  case AST_Expression::EV_ulong:
654  return o << ev.u.ulval << 'u';
655  case AST_Expression::EV_longlong:
656  return signed_int_helper<ACE_CDR::LongLong>(o, ev.u.llval, ACE_INT64_MIN) << "LL";
657  case AST_Expression::EV_ulonglong:
658  return o << ev.u.ullval << "ULL";
659  case AST_Expression::EV_wchar:
660  return char_helper<ACE_CDR::WChar>(o << "L'", ev.u.wcval) << '\'';
661  case AST_Expression::EV_char:
662  return char_helper<ACE_CDR::Char>(o << '\'', ev.u.cval) << '\'';
663  case AST_Expression::EV_bool:
664  return o << std::boolalpha << static_cast<bool>(ev.u.bval);
665  case AST_Expression::EV_float:
666  return o << ev.u.fval << 'f';
667  case AST_Expression::EV_double:
668  return o << ev.u.dval;
669  case AST_Expression::EV_wstring:
670  return o << "L\"" << ev.u.wstrval << '"';
671  case AST_Expression::EV_string:
672  return o << '"' << ev.u.strval->get_string() << '"';
673 #ifdef ACE_HAS_CDR_FIXED
674  case AST_Expression::EV_fixed: {
676  ev.u.fixedval.to_string(buf, sizeof buf);
677  return o << "\"" << buf << "\"";
678  }
679 #endif
680  case AST_Expression::EV_enum:
681  case AST_Expression::EV_longdouble:
682  case AST_Expression::EV_any:
683  case AST_Expression::EV_object:
684  case AST_Expression::EV_void:
685  case AST_Expression::EV_none:
687  "Unsupported ExprType value in operator<<(std::ostream, AST_ExprValue)");
688  }
690  "Unhandled ExprType value in operator<<(std::ostream, AST_ExprValue)");
691  return o;
692 }
#define ACE_INT32_MIN
std::ostream & hex_value(std::ostream &o, unsigned value, size_t bytes)
Definition: ValueHelper.h:50
#define ACE_INT64_MIN
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.

◆ scoped()

std::string scoped ( UTL_ScopedName *  sn,
EscapeContext  ec = EscapeContext_Normal 
)
inline

Definition at line 358 of file dds_generator.h.

References dds_generator::scoped_helper().

Referenced by field_type_name(), GeneratorBase::gen_array_traits(), langmap_generator::gen_const(), marshal_generator::gen_enum(), value_writer_generator::gen_enum(), value_reader_generator::gen_enum(), metaclass_generator::gen_enum(), marshal_generator::gen_field_getValueFromSerialized(), marshal_generator::gen_struct(), value_writer_generator::gen_struct(), value_reader_generator::gen_struct(), metaclass_generator::gen_struct(), dynamic_data_adapter_generator::gen_typedef(), marshal_generator::gen_typedef(), metaclass_generator::gen_typedef(), marshal_generator::gen_union(), value_writer_generator::gen_union(), value_reader_generator::gen_union(), metaclass_generator::gen_union(), GeneratorBase::gen_union(), marshal_generator::gen_union_default(), java_ts_generator::generate(), face_ts_generator::generate(), generate_anon_fields(), ts_generator::generate_ts(), GeneratorBase::generateDefaultValue(), getEnumLabel(), GeneratorBase::map_type(), needs_nested_key_only(), FieldInfo::scoped_type(), to_cxx_type(), type_to_default(), type_to_default_array(), and FieldInfo::underscore().

359 {
360  // Add the leading scope operator here to make type names "fully-qualified" and avoid
361  // naming collisions with identifiers in OpenDDS::DCPS.
362  // The leading space allows this string to be used directly in a <>-delimeted template
363  // argument list while avoiding the <: digraph.
364  return " ::" + dds_generator::scoped_helper(sn, "::", ec);
365 }
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)

◆ string_type()

std::string string_type ( AstTypeClassification::Classification  cls)
inline

Definition at line 521 of file dds_generator.h.

References be_global, and AstTypeClassification::CL_WIDE.

Referenced by field_type_name(), metaclass_generator::gen_enum(), and to_cxx_type().

522 {
523  return be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11 ?
524  ((cls & AstTypeClassification::CL_WIDE) ? "std::wstring" : "std::string") :
525  (cls & AstTypeClassification::CL_WIDE) ? "TAO::WString_Manager" : "TAO::String_Manager";
526 }
const Classification CL_WIDE
BE_GlobalData * be_global
Definition: be_global.cpp:44

◆ strip_shift_op()

std::string strip_shift_op ( const std::string &  s)
inline

Definition at line 1335 of file dds_generator.h.

References shift_in, and shift_out.

1336 {
1337  const size_t shift_len = 3;
1338  std::string rv = s;
1339  if (rv.size() > shift_len) {
1340  const std::string first3 = rv.substr(0, shift_len);
1341  if (first3 == shift_out || first3 == shift_in) {
1342  rv.erase(0, 3);
1343  }
1344  }
1345  return rv;
1346 }
const char *const shift_in
const char *const shift_out

◆ struct_has_explicit_keys()

bool struct_has_explicit_keys ( AST_Structure *  node)
inline

Definition at line 1088 of file dds_generator.h.

References be_global, and get_struct_field().

Referenced by Fields::explicit_keys_only(), OpenDDS::XTypes::DynamicDataXcdrReadImpl::get_item_count(), OpenDDS::XTypes::DynamicDataXcdrReadImpl::get_member_id_at_index(), needs_nested_key_only(), OpenDDS::XTypes::DynamicDataImpl::DataContainer::serialize_structure_xcdr2(), and OpenDDS::XTypes::DynamicDataImpl::DataContainer::serialized_size_structure_xcdr2().

1089 {
1090  for (unsigned i = 0; i < node->nfields(); ++i) {
1091  if (be_global->is_key(get_struct_field(node, i))) {
1092  return true;
1093  }
1094  }
1095  return false;
1096 }
BE_GlobalData * be_global
Definition: be_global.cpp:44
AST_Field * get_struct_field(AST_Structure *struct_node, unsigned index)

◆ to_cxx_type()

std::string to_cxx_type ( AST_Type *  type,
std::size_t &  size 
)
inline

Definition at line 528 of file dds_generator.h.

References AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_STRING, AstTypeClassification::classify(), be_util::misc_error_and_abort(), AstTypeClassification::resolveActualType(), scoped(), and string_type().

Referenced by marshal_generator::gen_field_getValueFromSerialized(), metaclass_generator::gen_typedef(), gen_union_branch(), and generate_anon_fields().

529 {
531  if (cls & AstTypeClassification::CL_ENUM) {
532  size = 4;
533  return "ACE_CDR::ULong";
534  }
536  return string_type(cls);
537  }
539  AST_Type* t = AstTypeClassification::resolveActualType(type);
540  AST_PredefinedType* p = dynamic_cast<AST_PredefinedType*>(t);
541  switch (p->pt()) {
542  case AST_PredefinedType::PT_long:
543  size = 4;
544  return "ACE_CDR::Long";
545  case AST_PredefinedType::PT_ulong:
546  size = 4;
547  return "ACE_CDR::ULong";
548  case AST_PredefinedType::PT_longlong:
549  size = 8;
550  return "ACE_CDR::LongLong";
551  case AST_PredefinedType::PT_ulonglong:
552  size = 8;
553  return "ACE_CDR::ULongLong";
554  case AST_PredefinedType::PT_short:
555  size = 2;
556  return "ACE_CDR::Short";
557  case AST_PredefinedType::PT_ushort:
558  size = 2;
559  return "ACE_CDR::UShort";
560 #if OPENDDS_HAS_EXPLICIT_INTS
561  case AST_PredefinedType::PT_int8:
562  size = 1;
563  return "ACE_CDR::Int8";
564  case AST_PredefinedType::PT_uint8:
565  size = 1;
566  return "ACE_CDR::UInt8";
567 #endif
568  case AST_PredefinedType::PT_float:
569  size = 4;
570  return "ACE_CDR::Float";
571  case AST_PredefinedType::PT_double:
572  size = 8;
573  return "ACE_CDR::Double";
574  case AST_PredefinedType::PT_longdouble:
575  size = 16;
576  return "ACE_CDR::LongDouble";
577  case AST_PredefinedType::PT_char:
578  size = 1;
579  return "ACE_CDR::Char";
580  case AST_PredefinedType::PT_wchar:
581  size = 2;
582  return "ACE_CDR::WChar";
583  case AST_PredefinedType::PT_boolean:
584  size = 1;
585  return "ACE_CDR::Boolean";
586  case AST_PredefinedType::PT_octet:
587  size = 1;
588  return "ACE_CDR::Octet";
589  case AST_PredefinedType::PT_any:
590  case AST_PredefinedType::PT_object:
591  case AST_PredefinedType::PT_value:
592  case AST_PredefinedType::PT_abstract:
593  case AST_PredefinedType::PT_void:
594  case AST_PredefinedType::PT_pseudo:
595  be_util::misc_error_and_abort("Unsupported predefined type in to_cxx_type");
596  }
597  be_util::misc_error_and_abort("Unhandled predefined type in to_cxx_type");
598  }
599  return scoped(type->name());
600 }
Classification classify(AST_Type *type)
std::string string_type(AstTypeClassification::Classification cls)
const Classification CL_STRING
const Classification CL_PRIMITIVE
AST_Type * resolveActualType(AST_Type *element)
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
const Classification CL_ENUM

◆ type_to_default()

std::string type_to_default ( const std::string &  indent,
AST_Type *  type,
const std::string &  name,
bool  is_anonymous = false,
bool  is_union = false 
)

Definition at line 359 of file dds_generator.cpp.

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

Referenced by bounded_arg(), marshal_generator::gen_enum(), marshal_generator::gen_struct(), marshal_generator::gen_typedef(), marshal_generator::gen_union(), marshal_generator::gen_union_default(), and generateCaseBody().

361 {
362  AST_Type* actual_type = resolveActualType(type);
363  Classification fld_cls = classify(actual_type);
364  const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
365  string def_val;
366  std::string pre = " = ";
367  std::string post;
368  if (is_union) {
369  pre = "(";
370  post = ")";
371  }
372  if (fld_cls & (CL_STRUCTURE | CL_UNION)) {
373  return indent + "set_default(" + name + (is_union ? "()" : "") + ");\n";
374  } else if (fld_cls & CL_ARRAY) {
375  return type_to_default_array(
376  indent, type, name, is_anonymous, is_union, use_cxx11, fld_cls);
377  } else if (fld_cls & CL_ENUM) {
378  // For now, simply return the first value of the enumeration.
379  // Must be changed, if support for @default_literal is desired.
380  AST_Enum* enu = dynamic_cast<AST_Enum*>(actual_type);
381  UTL_ScopeActiveIterator i(enu, UTL_Scope::IK_decls);
382  AST_EnumVal *item = dynamic_cast<AST_EnumVal*>(i.item());
383  if (use_cxx11) {
384  def_val = scoped(type->name()) + "::" + item->local_name()->get_string();
385  } else {
386  def_val = scoped(item->name());
387  }
388  } else if (fld_cls & CL_SEQUENCE) {
389  string seq_resize_func = (use_cxx11) ? "resize" : "length";
390  if (is_union) {
391  return indent + "tmp." + seq_resize_func + "(0);\n"
392  + indent + name + "(tmp);\n";
393  } else {
394  return indent + name + "." + seq_resize_func + "(0);\n";
395  }
396  } else if (fld_cls & CL_STRING) {
397  def_val = (fld_cls & CL_WIDE) ? "L\"\"" : "\"\"";
398  if (!use_cxx11 && (fld_cls & CL_WIDE)) def_val = "TAO::WString_Manager::s_traits::default_initializer()";
399  } else if (fld_cls & (CL_PRIMITIVE | CL_FIXED)) {
400  AST_PredefinedType* pt = dynamic_cast<AST_PredefinedType*>(actual_type);
401  if (pt && (pt->pt() == AST_PredefinedType::PT_longdouble)) {
402  if (use_cxx11) {
403  def_val = "0.0L";
404  } else {
405  string temp_val = "ACE_CDR::LongDouble val = ACE_CDR_LONG_DOUBLE_INITIALIZER";
406  if (is_union) {
407  def_val = "val";
408  return indent + temp_val + ";\n" +
409  indent + name + pre + def_val + post + ";\n";
410  } else {
411  def_val = "ACE_CDR_LONG_DOUBLE_ASSIGNMENT(" + name + ", val)";
412  return indent + "{\n"
413  " " + indent + temp_val + ";\n"
414  " " + indent + def_val + ";\n" +
415  indent + "}\n";
416  }
417  }
418  } else {
419  def_val = "0";
420  }
421  }
422  return indent + name + pre + def_val + post + ";\n";
423 }
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_WIDE
const Classification CL_PRIMITIVE
const Classification CL_ARRAY
string type_to_default_array(const std::string &indent, AST_Type *type, const string &name, bool is_anonymous, bool is_union, bool use_cxx11, Classification fld_cls)
AST_Type * resolveActualType(AST_Type *element)
const char *const name
Definition: debug.cpp:60
const Classification CL_FIXED
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
const Classification CL_STRUCTURE
BE_GlobalData * be_global
Definition: be_global.cpp:44
const Classification CL_ENUM
const Classification CL_SEQUENCE
const Classification CL_UNION

◆ wrapPrefix()

std::string wrapPrefix ( AST_Type *  type,
WrapDirection  wd 
)
inline

Definition at line 480 of file dds_generator.h.

References WD_OUTPUT.

Referenced by getWrapper().

481 {
482  switch (type->node_type()) {
483  case AST_Decl::NT_pre_defined: {
484  AST_PredefinedType* const p = dynamic_cast<AST_PredefinedType*>(type);
485  switch (p->pt()) {
486  case AST_PredefinedType::PT_char:
487  return (wd == WD_OUTPUT)
488  ? "ACE_OutputCDR::from_char(" : "ACE_InputCDR::to_char(";
489  case AST_PredefinedType::PT_wchar:
490  return (wd == WD_OUTPUT)
491  ? "ACE_OutputCDR::from_wchar(" : "ACE_InputCDR::to_wchar(";
492  case AST_PredefinedType::PT_octet:
493  return (wd == WD_OUTPUT)
494  ? "ACE_OutputCDR::from_octet(" : "ACE_InputCDR::to_octet(";
495  case AST_PredefinedType::PT_boolean:
496  return (wd == WD_OUTPUT)
497  ? "ACE_OutputCDR::from_boolean(" : "ACE_InputCDR::to_boolean(";
498 #if OPENDDS_HAS_EXPLICIT_INTS
499  case AST_PredefinedType::PT_uint8:
500  return (wd == WD_OUTPUT)
501  ? "ACE_OutputCDR::from_uint8(" : "ACE_InputCDR::to_uint8(";
502  case AST_PredefinedType::PT_int8:
503  return (wd == WD_OUTPUT)
504  ? "ACE_OutputCDR::from_int8(" : "ACE_InputCDR::to_int8(";
505 #endif
506  default:
507  return "";
508  }
509  }
510  case AST_Decl::NT_string:
511  return (wd == WD_OUTPUT)
512  ? "ACE_OutputCDR::from_string(" : "ACE_InputCDR::to_string(";
513  case AST_Decl::NT_wstring:
514  return (wd == WD_OUTPUT)
515  ? "ACE_OutputCDR::from_wstring(" : "ACE_InputCDR::to_wstring(";
516  default:
517  return "";
518  }
519 }

Variable Documentation

◆ shift_in

const char* const shift_in = ">> "

Definition at line 1333 of file dds_generator.h.

Referenced by RefWrapper::done(), get_shift_op(), and strip_shift_op().

◆ shift_out

const char* const shift_out = "<< "

Definition at line 1332 of file dds_generator.h.

Referenced by get_shift_op(), and strip_shift_op().