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

Go to the source code of this file.

Functions

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)
 
string type_to_default (const std::string &indent, AST_Type *type, const string &name, bool is_anonymous, bool is_union)
 
std::string field_type_name (AST_Field *field, AST_Type *field_type)
 
AST_Type * deepest_named_type (AST_Type *type)
 

Function Documentation

◆ 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 
)

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)

◆ type_to_default()

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

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

◆ type_to_default_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 
)

Definition at line 322 of file dds_generator.cpp.

References deepest_named_type(), dds_generator::get_tag_name(), name, and scoped().

Referenced by type_to_default().

324 {
325  // TODO: Most of what's in here looks like it could be replaced with RefWrapper
326  string val;
327  string temp = name;
328  if (temp.size() > 2 && temp.substr(temp.size() - 2, 2) == "()") {
329  temp.erase(temp.size() - 2);
330  }
331  temp += "_temp";
332  replace(temp.begin(), temp.end(), '.', '_');
333  replace(temp.begin(), temp.end(), '[', '_');
334  replace(temp.begin(), temp.end(), ']', '_');
335  if (use_cxx11) {
336  string n = scoped(deepest_named_type(type)->name());
337  if (is_anonymous) {
338  n = n.substr(0, n.rfind("::") + 2) + "AnonymousType_" + type->local_name()->get_string();
339  n = (fld_cls == AST_Decl::NT_sequence) ? (n + "_seq") : n;
340  }
341  val += indent + "set_default(IDL::DistinctType<" + n + ", " + dds_generator::get_tag_name(n) + ">(" +
342  (is_union ? "tmp" : name) + "));\n";
343  } else {
344  string n = scoped(type->name());
345  if (is_anonymous) {
346  n = n.substr(0, n.rfind("::") + 2) + "_" + type->local_name()->get_string();
347  n = (fld_cls == AST_Decl::NT_sequence) ? (n + "_seq") : n;
348  }
349  val = indent + n + "_forany " + temp + "(const_cast<"
350  + n + "_slice*>(" + (is_union ? "tmp": name) + "));\n";
351  val += indent + "set_default(" + temp + ");\n";
352  }
353  if (is_union) {
354  val += indent + name + "(tmp);\n";
355  }
356  return val;
357 }
static std::string get_tag_name(const std::string &base_name, const std::string &qualifier="")
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)