OpenDDS  Snapshot(2023/04/28-20:55)
Functions
metaclass_generator.cpp File Reference
#include "metaclass_generator.h"
#include "marshal_generator.h"
#include "field_info.h"
#include "be_extern.h"
#include "topic_keys.h"
#include <utl_identifier.h>
#include <cstddef>
#include <stdexcept>
Include dependency graph for metaclass_generator.cpp:

Go to the source code of this file.

Functions

void generate_anon_fields (AST_Structure *node)
 
static std::string gen_union_branch (const std::string &, AST_Decl *branch, const std::string &, AST_Type *br_type, const std::string &, bool, Intro &, const std::string &)
 

Function Documentation

◆ gen_union_branch()

static std::string gen_union_branch ( const std::string &  ,
AST_Decl *  branch,
const std::string &  ,
AST_Type *  br_type,
const std::string &  ,
bool  ,
Intro ,
const std::string &   
)
static

Definition at line 615 of file metaclass_generator.cpp.

References be_global, AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_SCALAR, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::classify(), deepest_named_type(), field_type_name(), dds_generator::get_tag_name(), name, dds_generator::scoped_helper(), and to_cxx_type().

Referenced by metaclass_generator::gen_union().

617 {
618  const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
619  std::stringstream ss;
620  const Classification br_cls = classify(br_type);
621  ss <<
622  " if (is_mutable && !ser.read_parameter_id(member_id, field_size, must_understand)) {\n"
623  " return false;\n"
624  " }\n";
625  if (br_cls & CL_STRING) {
626  ss <<
627  " ACE_CDR::ULong len;\n"
628  " if (!(ser >> len && ser.skip(len))) return false;\n";
629  } else if (br_cls & CL_SCALAR) {
630  size_t sz = 0;
631  to_cxx_type(br_type, sz);
632  ss <<
633  " if (!ser.skip(1, " << sz << ")) return false;\n";
634  } else {
635  std::string pre, post;
636  if (!use_cxx11 && (br_cls & CL_ARRAY)) {
637  post = "_forany";
638  } else if (use_cxx11 && (br_cls & (CL_ARRAY | CL_SEQUENCE))) {
639  pre = "IDL::DistinctType<";
641  }
642  ss <<
643  " if (!gen_skip_over(ser, static_cast<" << pre
644  << field_type_name(dynamic_cast<AST_Field*>(branch), br_type) << post <<
645  "*>(0))) return false;\n";
646  }
647 
648  ss <<
649  " return true;\n";
650  return ss.str();
651 }
std::string to_cxx_type(AST_Type *type, std::size_t &size)
Classification classify(AST_Type *type)
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
const Classification CL_STRING
const Classification CL_SCALAR
std::string field_type_name(AST_Field *field, AST_Type *field_type)
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
AST_Type * deepest_named_type(AST_Type *type)
const Classification CL_ARRAY
const char *const name
Definition: debug.cpp:60
BE_GlobalData * be_global
Definition: be_global.cpp:44
const Classification CL_SEQUENCE

◆ generate_anon_fields()

void generate_anon_fields ( AST_Structure *  node)

Definition at line 412 of file metaclass_generator.cpp.

References Function::addArg(), FieldInfo::arr_, array_element_count(), FieldInfo::as_act_, be_global, Fields::begin(), AstTypeClassification::CL_ARRAY, AstTypeClassification::CL_ENUM, AstTypeClassification::CL_PRIMITIVE, AstTypeClassification::CL_SEQUENCE, AstTypeClassification::CL_STRING, AstTypeClassification::CL_STRUCTURE, AstTypeClassification::classify(), deepest_named_type(), Fields::end(), Function::endArgs(), marshal_generator::generate_dheader_code(), dds_generator::get_tag_name(), FieldInfo::is_new(), FieldInfo::length_, name, FieldInfo::ptr_, AstTypeClassification::resolveActualType(), scoped(), dds_generator::scoped_helper(), FieldInfo::seq_, and to_cxx_type().

Referenced by metaclass_generator::gen_struct(), and metaclass_generator::gen_union().

413 {
414  const Fields fields(node);
415  FieldInfo::EleLenSet anonymous_seq_generated;
416  for (Fields::Iterator i = fields.begin(); i != fields.end(); ++i) {
417  AST_Field* const field = *i;
418  if (field->field_type()->anonymous()) {
419  FieldInfo af(*field);
420  if (af.arr_ || (af.seq_ && af.is_new(anonymous_seq_generated))) {
421  Function f("gen_skip_over", "bool");
422  f.addArg("ser", "Serializer&");
423  f.addArg("", af.ptr_);
424  f.endArgs();
425 
426  AST_Type* elem;
427  if (af.seq_ != 0) {
428  elem = af.seq_->base_type();
429  } else {
430  elem = af.arr_->base_type();
431  }
432  be_global->impl_ <<
433  " const Encoding& encoding = ser.encoding();\n"
434  " ACE_UNUSED_ARG(encoding);\n";
435  Classification elem_cls = classify(elem);
436  const bool primitive = elem_cls & CL_PRIMITIVE;
438  " if (!ser.read_delimiter(total_size)) {\n"
439  " return false;\n"
440  " }\n", !primitive, true);
441 
442  std::string len;
443  if (af.arr_) {
444  std::ostringstream strstream;
445  strstream << array_element_count(af.arr_);
446  len = strstream.str();
447  } else { // Sequence
448  be_global->impl_ <<
449  " ACE_CDR::ULong length;\n"
450  " if (!(ser >> length)) return false;\n";
451  len = "length";
452  }
453  const std::string cxx_elem = scoped(elem->name());
454  AST_Type* elem_orig = elem;
455  elem = resolveActualType(elem);
456  elem_cls = classify(elem);
457 
458  if ((elem_cls & (CL_PRIMITIVE | CL_ENUM))) {
459  // fixed-length sequence/array element -> skip all elements at once
460  size_t sz = 0;
461  to_cxx_type(af.as_act_, sz);
462  be_global->impl_ <<
463  " return ser.skip(" << af.length_ << ", " << sz << ");\n";
464  } else {
465  be_global->impl_ <<
466  " for (ACE_CDR::ULong i = 0; i < " << len << "; ++i) {\n";
467  if (elem_cls & CL_STRING) {
468  be_global->impl_ <<
469  " ACE_CDR::ULong strlength;\n"
470  " if (!(ser >> strlength && ser.skip(strlength))) return false;\n";
471  } else if (elem_cls & (CL_ARRAY | CL_SEQUENCE | CL_STRUCTURE)) {
472  std::string pre, post;
473  const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
474  if (!use_cxx11 && (elem_cls & CL_ARRAY)) {
475  post = "_forany";
476  } else if (use_cxx11 && (elem_cls & (CL_ARRAY | CL_SEQUENCE))) {
477  pre = "IDL::DistinctType<";
478  post = ", " + dds_generator::get_tag_name(dds_generator::scoped_helper(deepest_named_type(elem_orig)->name(), "_")) + ">";
479  }
480  be_global->impl_ <<
481  " if (!gen_skip_over(ser, static_cast<" << pre << cxx_elem << post
482  << "*>(0))) return false;\n";
483  }
484  be_global->impl_ <<
485  " }\n"
486  " return true;\n";
487  }
488 
489  }
490  }
491  }
492 }
std::string to_cxx_type(AST_Type *type, std::size_t &size)
Classification classify(AST_Type *type)
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
const Classification CL_STRING
const Classification CL_PRIMITIVE
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
AST_Type * deepest_named_type(AST_Type *type)
const Classification CL_ARRAY
AST_Type * resolveActualType(AST_Type *element)
static void generate_dheader_code(const std::string &code, bool dheader_required, bool is_ser_func=true)
const char *const name
Definition: debug.cpp:60
std::string scoped(UTL_ScopedName *sn, EscapeContext ec=EscapeContext_Normal)
std::set< EleLen > EleLenSet
Definition: field_info.h:31
const Classification CL_STRUCTURE
BE_GlobalData * be_global
Definition: be_global.cpp:44
ACE_CDR::ULong array_element_count(AST_Array *arr)
const Classification CL_ENUM
const Classification CL_SEQUENCE