OpenDDS  Snapshot(2023/04/07-19:43)
Classes | Public Member Functions | Static Public Member Functions | List of all members
GeneratorBase Struct Referenceabstract
Inheritance diagram for GeneratorBase:
Inheritance graph
[legend]

Classes

struct  GenerateUnionAccessors
 

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
 
virtual std::string const_keyword (AST_Expression::ExprType)
 
std::string map_type (AST_Type *type)
 
std::string map_type (AST_Field *field)
 
virtual std::string map_type_string (AST_PredefinedType::PredefinedType chartype, bool constant)
 
std::string map_type (AST_Expression::ExprType type)
 
virtual void gen_simple_out (const char *nm)
 
virtual bool scoped_enum ()
 
virtual std::string enum_base ()
 
virtual void struct_decls (UTL_ScopedName *name, AST_Type::SIZE_TYPE size, const char *struct_or_class="struct")
 
virtual bool gen_union (AST_Union *u, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
 
virtual void gen_array (UTL_ScopedName *tdname, AST_Array *arr)
 
virtual void gen_array_traits (UTL_ScopedName *tdname, AST_Array *arr)
 
virtual void gen_array_typedef (const char *nm, AST_Type *base)
 
virtual void gen_typedef_varout (const char *nm, AST_Type *base)
 

Static Public Member Functions

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

Detailed Description

Definition at line 87 of file langmap_generator.cpp.

Constructor & Destructor Documentation

◆ ~GeneratorBase()

virtual GeneratorBase::~GeneratorBase ( )
inlinevirtual

Definition at line 89 of file langmap_generator.cpp.

References init(), and name.

89 {}

Member Function Documentation

◆ const_keyword()

virtual std::string GeneratorBase::const_keyword ( AST_Expression::ExprType  )
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 94 of file langmap_generator.cpp.

95  {
96  return "const";
97  }

◆ countLabels()

static size_t GeneratorBase::countLabels ( const std::vector< AST_UnionBranch *> &  branches)
inlinestatic

Definition at line 394 of file langmap_generator.cpp.

395  {
396  size_t count = 0;
397 
398  for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end();
399  pos != limit;
400  ++pos) {
401  count += (*pos)->label_list_length();
402  }
403 
404  return count;
405  }

◆ enum_base()

virtual std::string GeneratorBase::enum_base ( )
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 179 of file langmap_generator.cpp.

179 { return ""; }

◆ gen_array()

virtual void GeneratorBase::gen_array ( UTL_ScopedName *  tdname,
AST_Array *  arr 
)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 660 of file langmap_generator.cpp.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_WIDE, AstTypeClassification::classify(), and NestedForLoops::index_.

661  {
662  be_global->add_include("<tao/Array_VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
663  be_global->add_include("dds/DCPS/SafetyProfilePool.h", BE_GlobalData::STREAM_LANG_H);
664  const char* const nm = tdname->last_component()->get_string();
665  AST_Type* elem = arr->base_type();
666  const Classification elem_cls = classify(elem);
667  const Helper var = (elem->size_type() == AST_Type::VARIABLE)
668  ? HLP_ARR_VAR_VAR : HLP_ARR_FIX_VAR,
669  out = HLP_ARR_OUT,
670  forany = HLP_ARR_FORANY;
671 
672  std::ostringstream bound, nofirst, total;
673  const std::string zeros = array_zero_indices(arr);
674  for (ACE_CDR::ULong dim = 0; dim < arr->n_dims(); ++dim) {
675  const ACE_CDR::ULong extent = arr->dims()[dim]->ev()->u.ulval;
676  bound << '[' << extent << ']';
677  if (dim) {
678  nofirst << '[' << extent << ']';
679  total << " * ";
680  }
681  total << extent;
682  }
683 
684  std::string elem_type = map_type(elem);
685  if (elem_cls & CL_STRING) {
686  elem_type = helpers_[(elem_cls & CL_WIDE) ? HLP_WSTR_MGR : HLP_STR_MGR];
687  }
688 
689  std::string out_type = nm;
690  if (elem->size_type() == AST_Type::VARIABLE) {
691  out_type = helpers_[out] + '<' + nm + ", " + nm + "_var, " + nm +
692  "_slice, " + nm + "_tag>";
693  }
694 
695  be_global->lang_header_ <<
696  "typedef " << elem_type << ' ' << nm << bound.str() << ";\n"
697  "typedef " << elem_type << ' ' << nm << "_slice" << nofirst.str() << ";\n"
698  "struct " << nm << "_tag {};\n"
699  "typedef " << helpers_[var] << '<' << nm << ", " << nm << "_slice, "
700  << nm << "_tag> " << nm << "_var;\n"
701  "typedef " << out_type << ' ' << nm << "_out;\n"
702  "typedef " << helpers_[forany] << '<' << nm << ", " << nm << "_slice, "
703  << nm << "_tag> " << nm << "_forany;\n\n" <<
704  exporter() << nm << "_slice* " << nm << "_alloc();\n" <<
705  exporter() << "void " << nm << "_init_i(" << elem_type << "* begin);\n" <<
706  exporter() << "void " << nm << "_fini_i(" << elem_type << "* begin);\n" <<
707  exporter() << "void " << nm << "_free(" << nm << "_slice* slice);\n" <<
708  exporter() << nm << "_slice* " << nm << "_dup(const " << nm
709  << "_slice* slice);\n" <<
710  exporter() << "void " << nm << "_copy(" << nm << "_slice* dst, const "
711  << nm << "_slice* src);\n\n";
712  const ScopedNamespaceGuard namespaces(tdname, be_global->impl_);
713  be_global->impl_ <<
714  nm << "_slice* " << nm << "_alloc()\n"
715  "{\n"
716  " void* const raw = ACE_Allocator::instance()->malloc"
717  "(sizeof(" << nm << "));\n"
718  " " << nm << "_slice* const slice = static_cast<" << nm << "_slice*"
719  << ">(raw);\n"
720  " " << nm << "_init_i(slice" << zeros << ");\n"
721  " return slice;\n"
722  "}\n\n"
723  "void " << nm << "_init_i(" << elem_type << "* begin)\n"
724  "{\n";
725 
726  if (elem_cls & (CL_PRIMITIVE | CL_ENUM)) {
727  be_global->impl_ << " ACE_UNUSED_ARG(begin);\n";
728  } else if (elem_cls & CL_ARRAY) {
729  std::string indent = " ";
730  const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent);
731  be_global->impl_ <<
732  indent << elem_type << "_init_i(begin" << nfl.index_ << ");\n";
733  } else {
734  be_global->impl_ <<
735  " std::uninitialized_fill_n(begin, " << total.str() << ", "
736  << elem_type << "());\n";
737  }
738 
739  be_global->impl_ <<
740  "}\n\n"
741  "void " << nm << "_fini_i(" << elem_type << "* begin)\n"
742  "{\n";
743 
744  if (elem_cls & (CL_PRIMITIVE | CL_ENUM)) {
745  be_global->impl_ << " ACE_UNUSED_ARG(begin);\n";
746  } else if (elem_cls & CL_ARRAY) {
747  std::string indent = " ";
748  const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent);
749  be_global->impl_ <<
750  indent << elem_type << "_fini_i(begin" << nfl.index_ << ");\n";
751  } else {
752  const std::string::size_type idx_last = elem_type.rfind("::");
753  const std::string elem_last =
754  (elem_cls & CL_STRING) ? "StringManager" :
755  ((idx_last == std::string::npos) ? elem_type
756  : elem_type.substr(idx_last + 2));
757  be_global->impl_ <<
758  " for (int i = 0; i < " << total.str() << "; ++i) {\n"
759  " begin[i]."
760  "~" << elem_last << "();\n"
761  " }\n";
762  }
763 
764  be_global->impl_ <<
765  "}\n\n"
766  "void " << nm << "_free(" << nm << "_slice* slice)\n"
767  "{\n"
768  " if (!slice) return;\n"
769  " " << nm << "_fini_i(slice" << zeros << ");\n"
770  " ACE_Allocator::instance()->free(slice);\n"
771  "}\n\n" <<
772  nm << "_slice* " << nm << "_dup(const " << nm << "_slice* slice)\n"
773  "{\n"
774  " " << nm << "_slice* const arr = " << nm << "_alloc();\n"
775  " if (arr) " << nm << "_copy(arr, slice);\n"
776  " return arr;\n"
777  "}\n\n"
778  "void " << nm << "_copy(" << nm << "_slice* dst, const " << nm
779  << "_slice* src)\n"
780  "{\n"
781  " if (!src || !dst) return;\n";
782 
783  {
784  std::string indent = " ";
785  const NestedForLoops nfl("ACE_CDR::ULong", "i", arr, indent);
786  if (elem_cls & CL_ARRAY) {
787  be_global->impl_ <<
788  indent << elem_type << "_copy(dst" << nfl.index_ << ", src"
789  << nfl.index_ << ");\n";
790  } else {
791  be_global->impl_ <<
792  indent << "dst" << nfl.index_ << " = src" << nfl.index_ << ";\n";
793  }
794  }
795 
796  be_global->impl_ <<
797  "}\n\n";
798 
799  be_global->lang_header_ <<
800  "inline ACE_CDR::Boolean operator<<(ACE_OutputCDR &, const " << nm << "_forany&) { return true; }\n\n"
801  "inline ACE_CDR::Boolean operator>>(ACE_InputCDR &, " << nm << "_forany&) { return true; }\n\n";
802  }
const Classification CL_ARRAY
std::string map_type(AST_Type *type)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
ACE_UINT32 ULong
BE_GlobalData * be_global
Definition: be_global.cpp:43
const Classification CL_WIDE

◆ gen_array_traits()

virtual void GeneratorBase::gen_array_traits ( UTL_ScopedName *  tdname,
AST_Array *  arr 
)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 806 of file langmap_generator.cpp.

References be_global, and scoped().

807  {
808  const std::string nm = scoped(tdname);
809  const std::string zeros = array_zero_indices(arr);
810  be_global->lang_header_ <<
811  "TAO_BEGIN_VERSIONED_NAMESPACE_DECL\nnamespace TAO {\n"
812  "template <>\n"
813  "struct " << exporter() << "Array_Traits<" << nm << "_forany>\n"
814  "{\n"
815  " static void free(" << nm << "_slice* slice)\n"
816  " {\n"
817  " " << nm << "_free(slice);\n"
818  " }\n\n"
819  " static " << nm << "_slice* dup(const " << nm << "_slice* slice)\n"
820  " {\n"
821  " return " << nm << "_dup(slice);\n"
822  " }\n\n"
823  " static void copy(" << nm << "_slice* dst, const " << nm
824  << "_slice* src)\n"
825  " {\n"
826  " " << nm << "_copy(dst, src);\n"
827  " }\n\n"
828  " static " << nm << "_slice* alloc()\n"
829  " {\n"
830  " return " << nm << "_alloc();\n"
831  " }\n\n"
832  " static void zero(" << nm << "_slice* slice)\n"
833  " {\n"
834  " " << nm << "_fini_i(slice" << zeros << ");\n"
835  " " << nm << "_init_i(slice" << zeros << ");\n"
836  " }\n"
837  " static void construct(" << nm << "_slice* slice)\n"
838  " {\n"
839  " " << nm << "_init_i(slice" << zeros << ");\n"
840  " }\n"
841  " static void destroy(" << nm << "_slice* slice)\n"
842  " {\n"
843  " " << nm << "_fini_i(slice" << zeros << ");\n"
844  " }\n"
845  "};\n}\nTAO_END_VERSIONED_NAMESPACE_DECL\n\n";
846  }
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_array_typedef()

virtual void GeneratorBase::gen_array_typedef ( const char *  nm,
AST_Type *  base 
)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 848 of file langmap_generator.cpp.

References be_global.

849  {
850  be_global->lang_header_ <<
851  "typedef " << map_type(base) << "_var " << nm << "_var;\n" <<
852  "typedef " << map_type(base) << "_slice " << nm << "_slice;\n" <<
853  "typedef " << map_type(base) << "_forany " << nm << "_forany;\n\n" <<
854  "inline " << nm << "_slice *" << nm << "_alloc() { return " << map_type(base) << "_alloc(); }\n" <<
855  "inline " << nm << "_slice* " << nm << "_dup(" << nm << "_slice *a) { return " << map_type(base) << "_dup(a); }\n" <<
856  "inline void " << nm << "_copy(" << nm << "_slice* to, const " << nm << "_slice* from) { " << map_type(base) << "_copy(to, from); }\n" <<
857  "inline void " << nm << "_free(" << nm << "_slice *a) { " << map_type(base) << "_free(a); }\n";
858  }
std::string map_type(AST_Type *type)
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_sequence()

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

◆ gen_simple_out()

virtual void GeneratorBase::gen_simple_out ( const char *  nm)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 172 of file langmap_generator.cpp.

References be_global.

173  {
174  be_global->lang_header_ <<
175  "typedef " << nm << "& " << nm << "_out;\n";
176  }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_struct()

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

◆ gen_typedef_varout()

virtual void GeneratorBase::gen_typedef_varout ( const char *  nm,
AST_Type *  base 
)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 860 of file langmap_generator.cpp.

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

861  {
862  const Classification cls = classify(base);
863  if (cls & CL_STRING) {
864  const Helper var = (cls & CL_WIDE) ? HLP_WSTR_VAR : HLP_STR_VAR,
865  out = (cls & CL_WIDE) ? HLP_WSTR_OUT : HLP_STR_OUT;
866  be_global->lang_header_ <<
867  "typedef " << helpers_[var] << ' ' << nm << "_var;\n"
868  "typedef " << helpers_[out] << ' ' << nm << "_out;\n";
869  } else {
870  be_global->lang_header_ <<
871  "typedef " << generator_->map_type(base) << "_out " << nm << "_out;\n";
872  }
873  }
Classification classify(AST_Type *type)
const Classification CL_STRING
BE_GlobalData * be_global
Definition: be_global.cpp:43
const Classification CL_WIDE

◆ gen_union()

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

Reimplemented in Cxx11Generator.

Definition at line 548 of file langmap_generator.cpp.

References be_global, generateSwitchForUnion(), and scoped().

550  {
551  const ScopedNamespaceGuard namespaces(name, be_global->lang_header_);
552  const char* const nm = name->last_component()->get_string();
553  struct_decls(name, u->size_type(), "class");
554  be_global->lang_header_ <<
555  "\n"
556  "class " << exporter() << nm << "\n"
557  "{\n"
558  " public:\n"
559  " typedef " << nm << "_var _var_type;\n"
560  " typedef " << nm << "_out _out_type;\n"
561  " " << nm << "();\n"
562  " " << nm << "(const " << nm << "&);\n"
563  " ~" << nm << "() { _reset(); };\n"
564  " " << nm << "& operator=(const " << nm << "&);\n"
565  " void _d(" << scoped(discriminator->name()) << " d) { _discriminator = d; }\n"
566  " " << scoped(discriminator->name()) << " _d() const { return _discriminator; }\n";
567 
568  std::for_each (branches.begin(), branches.end(), GenerateUnionAccessors(u, discriminator));
569 
570  if (needsDefault(branches, discriminator)) {
571  be_global->lang_header_ <<
572  " void _default() {\n"
573  " _reset();\n"
574  " _discriminator = " << generateDefaultValue(u) << ";\n"
575  " }\n";
576  }
577 
578  be_global->lang_header_ <<
579  " bool operator==(const " << nm << "& rhs) const;\n"
580  " bool operator!=(const " << nm << "& rhs) const { return !(*this == rhs); }\n"
581  " OPENDDS_POOL_ALLOCATION_HOOKS\n";
582 
583  be_global->lang_header_ <<
584  " private:\n"
585  " " << scoped(discriminator->name()) << " _discriminator;\n"
586  " union {\n";
587 
588  std::for_each (branches.begin(), branches.end(), generate_union_field);
589 
590  be_global->lang_header_ <<
591  " } _u;\n";
592 
593  be_global->lang_header_ <<
594  " void _reset();\n"
595  "};\n\n";
596 
597  be_global->add_include("dds/DCPS/PoolAllocationBase.h", BE_GlobalData::STREAM_LANG_H);
598  be_global->add_include("<ace/CDR_Stream.h>", BE_GlobalData::STREAM_LANG_H);
599 
600  be_global->lang_header_ <<
601  exporter() << "ACE_CDR::Boolean operator<< (ACE_OutputCDR& os, const " << nm << "& x);\n\n";
602  be_global->lang_header_ <<
603  exporter() << "ACE_CDR::Boolean operator>> (ACE_InputCDR& os, " << nm << "& x);\n\n";
604 
605  {
606  const ScopedNamespaceGuard guard(name, be_global->impl_);
607 
608  be_global->impl_ <<
609  nm << "::" << nm << "() { std::memset (this, 0, sizeof (" << nm << ")); }\n\n";
610 
611  be_global->impl_ <<
612  nm << "::" << nm << "(const " << nm << "& other)\n"
613  "{\n"
614  " this->_discriminator = other._discriminator;\n";
615  generateSwitchForUnion(u, "this->_discriminator", generateCopyCtor, branches, discriminator, "", "", "", false, false);
616  be_global->impl_ <<
617  "}\n\n";
618 
619  be_global->impl_ <<
620  nm << "& " << nm << "::operator=(const " << nm << "& other)\n"
621  "{\n" <<
622  " if (this == &other) {\n"
623  " return *this;\n"
624  " }\n\n"
625  " _reset();\n"
626  " this->_discriminator = other._discriminator;\n";
627  generateSwitchForUnion(u, "this->_discriminator", generateAssign, branches, discriminator, "", "", "", false, false);
628  be_global->impl_ <<
629  " return *this;\n"
630  "}\n\n";
631 
632  be_global->impl_ <<
633  "bool " << nm << "::operator==(const " << nm << "& rhs) const\n"
634  "{\n"
635  " if (this->_discriminator != rhs._discriminator) return false;\n";
636  if (generateSwitchForUnion(u, "this->_discriminator", generateEqual, branches, discriminator, "", "", "", false, false)) {
637  be_global->impl_ <<
638  " return false;\n";
639  }
640  be_global->impl_ <<
641  "}\n\n";
642 
643  be_global->impl_ <<
644  "void " << nm << "::_reset()\n"
645  "{\n";
646  generateSwitchForUnion(u, "this->_discriminator", generateReset, branches, discriminator, "", "", "", false, false);
647  be_global->impl_ <<
648  "}\n\n";
649 
650  be_global->impl_ <<
651  "ACE_CDR::Boolean operator<<(ACE_OutputCDR&, const " << nm << "&) { return true; }\n\n";
652  be_global->impl_ <<
653  "ACE_CDR::Boolean operator>>(ACE_InputCDR&, " << nm << "&) { return true; }\n\n";
654  }
655 
656  gen_typecode(name);
657  return true;
658  }
static std::string generateEqual(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
static bool needsDefault(const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator)
const char *const name
Definition: debug.cpp:60
static std::string generateDefaultValue(AST_Union *the_union)
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)
BE_GlobalData * be_global
Definition: be_global.cpp:43
static std::string generateAssign(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
static void generate_union_field(AST_UnionBranch *branch)
static std::string generateCopyCtor(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)
virtual void struct_decls(UTL_ScopedName *name, AST_Type::SIZE_TYPE size, const char *struct_or_class="struct")
static std::string generateReset(const std::string &, AST_Decl *, const std::string &name, AST_Type *field_type, const std::string &, bool, Intro &, const std::string &)

◆ generate_union_field()

static void GeneratorBase::generate_union_field ( AST_UnionBranch *  branch)
inlinestatic

Definition at line 412 of file langmap_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(), and AstTypeClassification::resolveActualType().

413  {
414  AST_Type* field_type = branch->field_type();
415  AST_Type* actual_field_type = resolveActualType(field_type);
416  const Classification cls = classify(actual_field_type);
417  const std::string lang_field_type = generator_->map_type(field_type);
418  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
419  be_global->lang_header_ <<
420  " " << lang_field_type << ' ' << branch->local_name()->get_string() << ";\n";
421  } else if (cls & CL_STRING) {
422  const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE)
423  ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char;
424  be_global->lang_header_ <<
425  " " << primtype_[chartype] << "* " << branch->local_name()->get_string() << ";\n";
426  } else if (cls & CL_ARRAY) {
427  be_global->lang_header_ <<
428  " " << lang_field_type << "_slice* " << branch->local_name()->get_string() << ";\n";
429  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
430  be_global->lang_header_ <<
431  " " << lang_field_type << "* " << branch->local_name()->get_string() << ";\n";
432  } else {
433  std::cerr << "Unsupported type for union element\n";
434  }
435  }
const Classification CL_ARRAY
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
BE_GlobalData * be_global
Definition: be_global.cpp:43
const Classification CL_WIDE

◆ generateAssign()

static std::string GeneratorBase::generateAssign ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 464 of file langmap_generator.cpp.

References 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::classify(), and AstTypeClassification::resolveActualType().

467  {
468  std::stringstream ss;
469  AST_Type* actual_field_type = resolveActualType(field_type);
470  const Classification cls = classify(actual_field_type);
471  const std::string lang_field_type = generator_->map_type(field_type);
472  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
473  ss <<
474  " this->_u." << name << " = other._u." << name << ";\n";
475  } else if (cls & CL_STRING) {
476  ss <<
477  " this->_u." << name << " = (other._u." << name << ") ? " << string_ns << "::string_dup(other._u." << name << ") : 0 ;\n";
478  } else if (cls & CL_ARRAY) {
479  ss <<
480  " this->_u." << name << " = (other._u." << name << ") ? " << lang_field_type << "_dup(other._u." << name << ") : 0 ;\n";
481  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
482  ss <<
483  " this->_u." << name << " = (other._u." << name << ") ? new " << lang_field_type << "(*other._u." << name << ") : 0;\n";
484  } else {
485  std::cerr << "Unsupported type for union element\n";
486  }
487 
488  return ss.str();
489  }
const Classification CL_ARRAY
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
const char *const name
Definition: debug.cpp:60

◆ generateCopyCtor()

static std::string GeneratorBase::generateCopyCtor ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 437 of file langmap_generator.cpp.

References 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::classify(), and AstTypeClassification::resolveActualType().

440  {
441  std::stringstream ss;
442  AST_Type* actual_field_type = resolveActualType(field_type);
443  const Classification cls = classify(actual_field_type);
444  const std::string lang_field_type = generator_->map_type(field_type);
445  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
446  ss <<
447  " this->_u." << name << " = other._u." << name << ";\n";
448  } else if (cls & CL_STRING) {
449  ss <<
450  " this->_u." << name << " = (other._u." << name << ") ? " << string_ns << "::string_dup(other._u." << name << ") : 0 ;\n";
451  } else if (cls & CL_ARRAY) {
452  ss <<
453  " this->_u." << name << " = (other._u." << name << ") ? " << lang_field_type << "_dup(other._u." << name << ") : 0 ;\n";
454  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
455  ss <<
456  " this->_u." << name << " = (other._u." << name << ") ? new " << lang_field_type << "(*other._u." << name << ") : 0;\n";
457  } else {
458  std::cerr << "Unsupported type for union element\n";
459  }
460 
461  return ss.str();
462  }
const Classification CL_ARRAY
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
const char *const name
Definition: debug.cpp:60

◆ generateDefaultValue()

static std::string GeneratorBase::generateDefaultValue ( AST_Union *  the_union)
inlinestatic

Definition at line 204 of file langmap_generator.cpp.

References ACE_ERROR, ACE_TEXT(), be_global, Fields::begin(), LM_ERROR, be_util::misc_error_and_abort(), and scoped().

205  {
206  std::stringstream first_label;
207  AST_Union::DefaultValue dv;
208  if (the_union->default_value(dv) == -1) {
209  ACE_ERROR((LM_ERROR,
210  ACE_TEXT("(%P|%t) ERROR: generateDefaultValue::")
211  ACE_TEXT(" computing default value failed\n")));
212  return "";
213  }
214 
215  switch (the_union->udisc_type ())
216  {
217 #if OPENDDS_HAS_EXPLICIT_INTS
218  case AST_Expression::EV_int8:
219  first_label << signed(dv.u.char_val);
220  break;
221  case AST_Expression::EV_uint8:
222  first_label << unsigned(dv.u.char_val);
223  break;
224 #endif
225  case AST_Expression::EV_short:
226  first_label << dv.u.short_val;
227  break;
228  case AST_Expression::EV_ushort:
229  first_label << dv.u.ushort_val;
230  break;
231  case AST_Expression::EV_long:
232  first_label << dv.u.long_val;
233  break;
234  case AST_Expression::EV_ulong:
235  first_label << dv.u.ulong_val;
236  break;
237  case AST_Expression::EV_char:
238  first_label << (int)dv.u.char_val;
239  break;
240  case AST_Expression::EV_bool:
241  first_label << (dv.u.bool_val == 0 ? "false" : "true");
242  break;
243  case AST_Expression::EV_enum:
244  {
245  AST_Enum* e = dynamic_cast<AST_Enum*>(the_union->disc_type());
246  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11 ||
247  be_global->language_mapping() == BE_GlobalData::LANGMAP_FACE_CXX) {
248  std::string prefix = scoped(e->name());
249  if (be_global->language_mapping() == BE_GlobalData::LANGMAP_FACE_CXX) {
250  size_t pos = prefix.rfind("::");
251  if (pos == std::string::npos) {
252  prefix = "";
253  } else {
254  prefix = prefix.substr(0, pos) + "::";
255  }
256  } else {
257  prefix += "::";
258  }
259  first_label << prefix;
260  UTL_ScopedName* default_name;
261  if (dv.u.enum_val < static_cast<ACE_CDR::ULong>(e->member_count())) {
262  default_name = e->value_to_name(dv.u.enum_val);
263  } else {
264  const Fields fields(the_union);
265  AST_UnionBranch* ub = dynamic_cast<AST_UnionBranch*>(*(fields.begin()));
266  AST_Expression::AST_ExprValue* ev = ub->label(0)->label_val()->ev();
267  default_name = e->value_to_name(ev->u.eval);
268  }
269  first_label << default_name->last_component()->get_string();
270  } else {
271  first_label << scoped(e->value_to_name(dv.u.enum_val));
272  }
273  break;
274  }
275  case AST_Expression::EV_longlong:
276  first_label << dv.u.longlong_val;
277  break;
278  case AST_Expression::EV_ulonglong:
279  first_label << dv.u.ulonglong_val;
280  break;
281  default:
282  be_util::misc_error_and_abort("Unhandled ExprType value in generateDefaultValue");
283  }
284 
285  return first_label.str();
286  }
#define ACE_ERROR(X)
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
ACE_TEXT("TCP_Factory")
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ generateEqual()

static std::string GeneratorBase::generateEqual ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 491 of file langmap_generator.cpp.

References 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::classify(), and AstTypeClassification::resolveActualType().

494  {
495  std::stringstream ss;
496 
497  AST_Type* actual_field_type = resolveActualType(field_type);
498  const Classification cls = classify(actual_field_type);
499  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
500  ss <<
501  " return this->_u." << name << " == rhs._u." << name << ";\n";
502  } else if (cls & CL_STRING) {
503  ss <<
504  " return std::strcmp (this->_u." << name << ", rhs._u." << name << ") == 0 ;\n";
505  } else if (cls & CL_ARRAY) {
506  // TODO
507  ss <<
508  " return false;\n";
509  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
510  ss <<
511  " return *this->_u." << name << " == *rhs._u." << name << ";\n";
512  } else {
513  std::cerr << "Unsupported type for union element\n";
514  }
515 
516  return ss.str();
517  }
const Classification CL_ARRAY
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
const char *const name
Definition: debug.cpp:60

◆ generateReset()

static std::string GeneratorBase::generateReset ( const std::string &  ,
AST_Decl *  ,
const std::string &  name,
AST_Type *  field_type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
inlinestatic

Definition at line 519 of file langmap_generator.cpp.

References 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::classify(), and AstTypeClassification::resolveActualType().

522  {
523  std::stringstream ss;
524 
525  AST_Type* actual_field_type = resolveActualType(field_type);
526  const Classification cls = classify(actual_field_type);
527  if (cls & (CL_PRIMITIVE | CL_ENUM)) {
528  // Do nothing.
529  } else if (cls & CL_STRING) {
530  ss <<
531  " " << string_ns << "::string_free(this->_u." << name << ");\n"
532  " this->_u." << name << " = 0;\n";
533  } else if (cls & CL_ARRAY) {
534  ss <<
535  " " << generator_->map_type(field_type) << "_free(this->_u." << name << ");\n"
536  " this->_u." << name << " = 0;\n";
537  } else if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_FIXED)) {
538  ss <<
539  " delete this->_u." << name << ";\n"
540  " this->_u." << name << " = 0;\n";
541  } else {
542  std::cerr << "Unsupported type for union element\n";
543  }
544 
545  return ss.str();
546  }
const Classification CL_ARRAY
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
const char *const name
Definition: debug.cpp:60

◆ hasDefaultLabel()

static bool GeneratorBase::hasDefaultLabel ( const std::vector< AST_UnionBranch *> &  branches)
inlinestatic

Definition at line 378 of file langmap_generator.cpp.

379  {
380  for (std::vector<AST_UnionBranch*>::const_iterator pos = branches.begin(), limit = branches.end();
381  pos != limit;
382  ++pos) {
383  AST_UnionBranch* branch = *pos;
384  for (unsigned long j = 0; j < branch->label_list_length(); ++j) {
385  AST_UnionLabel* label = branch->label(j);
386  if (label->label_kind() == AST_UnionLabel::UL_default) {
387  return true;
388  }
389  }
390  }
391  return false;
392  }

◆ init()

virtual void GeneratorBase::init ( )
pure virtual

◆ map_type() [1/3]

std::string GeneratorBase::map_type ( AST_Type *  type)
inline

Definition at line 99 of file langmap_generator.cpp.

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

100  {
101  if (dynamic_cast<AST_Typedef*>(type)) {
102  return scoped(type->name());
103  }
104  const Classification cls = classify(type);
105  if (cls & CL_PRIMITIVE) {
106  AST_Type* actual = resolveActualType(type);
107  return primtype_[dynamic_cast<AST_PredefinedType*>(actual)->pt()];
108  }
109  if (cls & CL_STRING) {
110  const AST_PredefinedType::PredefinedType chartype = (cls & CL_WIDE)
111  ? AST_PredefinedType::PT_wchar : AST_PredefinedType::PT_char;
112  return map_type_string(chartype, false);
113  }
114  if (cls & (CL_STRUCTURE | CL_UNION | CL_SEQUENCE | CL_ARRAY | CL_ENUM | CL_FIXED)) {
115  return scoped(type->name());
116  }
117  if (cls & CL_INTERFACE) {
118  return scoped(type->name()) + "_var";
119  }
120  return "<<unknown>>";
121  }
const Classification CL_ARRAY
const Classification CL_INTERFACE
const Classification CL_FIXED
const Classification CL_UNION
const Classification CL_STRUCTURE
AST_Type * resolveActualType(AST_Type *element)
const Classification CL_PRIMITIVE
Classification classify(AST_Type *type)
const Classification CL_STRING
const Classification CL_ENUM
const Classification CL_SEQUENCE
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
virtual std::string map_type_string(AST_PredefinedType::PredefinedType chartype, bool constant)
const Classification CL_WIDE

◆ map_type() [2/3]

std::string GeneratorBase::map_type ( AST_Field *  field)
inline

Definition at line 123 of file langmap_generator.cpp.

References FieldInfo::as_base_, FieldInfo::type_, and FieldInfo::type_name_.

124  {
125  FieldInfo af(*field);
126  return (af.type_->anonymous() && af.as_base_) ? af.type_name_ : map_type(af.type_);
127  }
std::string map_type(AST_Type *type)

◆ map_type() [3/3]

std::string GeneratorBase::map_type ( AST_Expression::ExprType  type)
inline

Definition at line 134 of file langmap_generator.cpp.

References be_global, and be_util::misc_error_and_abort().

135  {
136  AST_PredefinedType::PredefinedType pt = AST_PredefinedType::PT_void;
137  switch (type) {
138 #if OPENDDS_HAS_EXPLICIT_INTS
139  case AST_Expression::EV_int8: pt = AST_PredefinedType::PT_int8; break;
140  case AST_Expression::EV_uint8: pt = AST_PredefinedType::PT_uint8; break;
141 #endif
142  case AST_Expression::EV_short: pt = AST_PredefinedType::PT_short; break;
143  case AST_Expression::EV_ushort: pt = AST_PredefinedType::PT_ushort; break;
144  case AST_Expression::EV_long: pt = AST_PredefinedType::PT_long; break;
145  case AST_Expression::EV_ulong: pt = AST_PredefinedType::PT_ulong; break;
146  case AST_Expression::EV_longlong: pt = AST_PredefinedType::PT_longlong; break;
147  case AST_Expression::EV_ulonglong: pt = AST_PredefinedType::PT_ulonglong; break;
148  case AST_Expression::EV_float: pt = AST_PredefinedType::PT_float; break;
149  case AST_Expression::EV_double: pt = AST_PredefinedType::PT_double; break;
150  case AST_Expression::EV_longdouble: pt = AST_PredefinedType::PT_longdouble; break;
151  case AST_Expression::EV_char: pt = AST_PredefinedType::PT_char; break;
152  case AST_Expression::EV_wchar: pt = AST_PredefinedType::PT_wchar; break;
153  case AST_Expression::EV_octet: pt = AST_PredefinedType::PT_octet; break;
154  case AST_Expression::EV_bool: pt = AST_PredefinedType::PT_boolean; break;
155  case AST_Expression::EV_string: pt = AST_PredefinedType::PT_char; break;
156  case AST_Expression::EV_wstring: pt = AST_PredefinedType::PT_wchar; break;
157 #ifdef ACE_HAS_CDR_FIXED
158  case AST_Expression::EV_fixed:
159  be_global->add_include("FACE/Fixed.h", BE_GlobalData::STREAM_LANG_H);
160  return helpers_[HLP_FIXED_CONSTANT];
161 #endif
162  default:
163  be_util::misc_error_and_abort("Unhandled ExprType value in map_type");
164  }
165 
166  if (type == AST_Expression::EV_string || type == AST_Expression::EV_wstring)
167  return map_type_string(pt, true);
168 
169  return primtype_[pt];
170  }
void misc_error_and_abort(const std::string &message, AST_Decl *node=0)
Report a miscellaneous error and abort.
BE_GlobalData * be_global
Definition: be_global.cpp:43
virtual std::string map_type_string(AST_PredefinedType::PredefinedType chartype, bool constant)

◆ map_type_string()

virtual std::string GeneratorBase::map_type_string ( AST_PredefinedType::PredefinedType  chartype,
bool  constant 
)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 129 of file langmap_generator.cpp.

130  {
131  return primtype_[chartype] + '*' + (constant ? " const" : "");
132  }

◆ needsDefault()

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

Definition at line 407 of file langmap_generator.cpp.

References needSyntheticDefault().

408  {
409  return !hasDefaultLabel(branches) && needSyntheticDefault(discriminator, countLabels(branches));
410  }
bool needSyntheticDefault(AST_Type *disc, size_t n_labels)
static size_t countLabels(const std::vector< AST_UnionBranch *> &branches)
static bool hasDefaultLabel(const std::vector< AST_UnionBranch *> &branches)

◆ scoped_enum()

virtual bool GeneratorBase::scoped_enum ( )
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 178 of file langmap_generator.cpp.

178 { return false; }

◆ struct_decls()

virtual void GeneratorBase::struct_decls ( UTL_ScopedName *  name,
AST_Type::SIZE_TYPE  size,
const char *  struct_or_class = "struct" 
)
inlinevirtual

Reimplemented in Cxx11Generator.

Definition at line 181 of file langmap_generator.cpp.

References be_global.

182  {
183  be_global->add_include("<tao/VarOut_T.h>", BE_GlobalData::STREAM_LANG_H);
184  const char* const nm = name->last_component()->get_string();
185  be_global->lang_header_ <<
186  struct_or_class << ' ' << nm << ";\n";
187  switch (size) {
188  case AST_Type::SIZE_UNKNOWN:
189  be_global->lang_header_ << "/* Unknown size */\n";
190  break;
191  case AST_Type::FIXED:
192  be_global->lang_header_ <<
193  "typedef " << helpers_[HLP_FIX_VAR] << '<' << nm << "> " << nm << "_var;\n" <<
194  "typedef " << nm << "& " << nm << "_out;\n";
195  break;
196  case AST_Type::VARIABLE:
197  be_global->lang_header_ <<
198  "typedef " << helpers_[HLP_VAR_VAR] << '<' << nm << "> " << nm << "_var;\n" <<
199  "typedef " << helpers_[HLP_OUT] << '<' << nm << "> " << nm << "_out;\n";
200  break;
201  }
202  }
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:43

The documentation for this struct was generated from the following file: