OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Static Public Member Functions | List of all members
dds_generator Class Referenceabstract

#include <dds_generator.h>

Inheritance diagram for dds_generator:
Inheritance graph
[legend]

Public Member Functions

virtual ~dds_generator ()=0
 
virtual bool do_included_files () const
 
virtual void gen_prologue ()
 
virtual void gen_epilogue ()
 
virtual bool gen_const (UTL_ScopedName *, bool, AST_Constant *)
 
virtual bool gen_enum (AST_Enum *, UTL_ScopedName *, const std::vector< AST_EnumVal *> &, const char *)
 
virtual bool gen_struct (AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)=0
 
virtual bool gen_struct_fwd (UTL_ScopedName *, AST_Type::SIZE_TYPE)
 
virtual bool gen_typedef (AST_Typedef *node, UTL_ScopedName *name, AST_Type *base, const char *repoid)=0
 
virtual bool gen_interf (AST_Interface *, UTL_ScopedName *, bool, const std::vector< AST_Interface *> &, const std::vector< AST_Interface *> &, const std::vector< AST_Attribute *> &, const std::vector< AST_Operation *> &, const char *)
 
virtual bool gen_interf_fwd (UTL_ScopedName *)
 
virtual bool gen_native (AST_Native *, UTL_ScopedName *, const char *)
 
virtual bool gen_union (AST_Union *node, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *discriminator, const char *repoid)=0
 
virtual bool gen_union_fwd (AST_UnionFwd *, UTL_ScopedName *, AST_Type::SIZE_TYPE)
 

Static Public Member Functions

static std::string get_tag_name (const std::string &base_name, bool nested_key_only=false)
 
static std::string get_xtag_name (UTL_ScopedName *name)
 
static bool cxx_escaped (const std::string &s)
 
static std::string valid_var_name (const std::string &str)
 
static std::string to_string (Identifier *id, EscapeContext ec=EscapeContext_Normal)
 
static std::string scoped_helper (UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
 
static std::string module_scope_helper (UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)
 

Detailed Description

Definition at line 48 of file dds_generator.h.

Constructor & Destructor Documentation

◆ ~dds_generator()

dds_generator::~dds_generator ( )
pure virtual

Definition at line 15 of file dds_generator.cpp.

15 {}

Member Function Documentation

◆ cxx_escaped()

bool dds_generator::cxx_escaped ( const std::string &  s)
static

Definition at line 21 of file dds_generator.cpp.

22 {
23  return s.substr(0, cxx_escape.size()) == cxx_escape;
24 }

◆ do_included_files()

virtual bool dds_generator::do_included_files ( ) const
inlinevirtual

Reimplemented in itl_generator.

Definition at line 60 of file dds_generator.h.

60 { return false; }

◆ gen_const()

virtual bool dds_generator::gen_const ( UTL_ScopedName *  ,
bool  ,
AST_Constant *   
)
inlinevirtual

Reimplemented in composite_generator, and langmap_generator.

Definition at line 66 of file dds_generator.h.

69  { return true; }

◆ gen_enum()

virtual bool dds_generator::gen_enum ( AST_Enum *  ,
UTL_ScopedName *  ,
const std::vector< AST_EnumVal *> &  ,
const char *   
)
inlinevirtual

◆ gen_epilogue()

virtual void dds_generator::gen_epilogue ( )
inlinevirtual

Reimplemented in composite_generator, itl_generator, and typeobject_generator.

Definition at line 64 of file dds_generator.h.

64 {}

◆ gen_interf()

virtual bool dds_generator::gen_interf ( AST_Interface *  ,
UTL_ScopedName *  ,
bool  ,
const std::vector< AST_Interface *> &  ,
const std::vector< AST_Interface *> &  ,
const std::vector< AST_Attribute *> &  ,
const std::vector< AST_Operation *> &  ,
const char *   
)
inlinevirtual

Reimplemented in composite_generator.

Definition at line 88 of file dds_generator.h.

94  { return true; }

◆ gen_interf_fwd()

virtual bool dds_generator::gen_interf_fwd ( UTL_ScopedName *  )
inlinevirtual

Reimplemented in composite_generator, and langmap_generator.

Definition at line 96 of file dds_generator.h.

97  { return true; }

◆ gen_native()

virtual bool dds_generator::gen_native ( AST_Native *  ,
UTL_ScopedName *  ,
const char *   
)
inlinevirtual

Reimplemented in composite_generator.

Definition at line 99 of file dds_generator.h.

References gen_union().

100  { return true; }

◆ gen_prologue()

virtual void dds_generator::gen_prologue ( )
inlinevirtual

Reimplemented in composite_generator, and itl_generator.

Definition at line 62 of file dds_generator.h.

62 {}

◆ gen_struct()

virtual bool dds_generator::gen_struct ( AST_Structure *  node,
UTL_ScopedName *  name,
const std::vector< AST_Field *> &  fields,
AST_Type::SIZE_TYPE  size,
const char *  repoid 
)
pure virtual

◆ gen_struct_fwd()

virtual bool dds_generator::gen_struct_fwd ( UTL_ScopedName *  ,
AST_Type::SIZE_TYPE   
)
inlinevirtual

Reimplemented in composite_generator, and langmap_generator.

Definition at line 81 of file dds_generator.h.

References gen_typedef().

83  { return true; }

◆ gen_typedef()

virtual bool dds_generator::gen_typedef ( AST_Typedef *  node,
UTL_ScopedName *  name,
AST_Type *  base,
const char *  repoid 
)
pure virtual

◆ gen_union()

virtual bool dds_generator::gen_union ( AST_Union *  node,
UTL_ScopedName *  name,
const std::vector< AST_UnionBranch *> &  branches,
AST_Type *  discriminator,
const char *  repoid 
)
pure virtual

◆ gen_union_fwd()

virtual bool dds_generator::gen_union_fwd ( AST_UnionFwd *  ,
UTL_ScopedName *  ,
AST_Type::SIZE_TYPE   
)
inlinevirtual

Reimplemented in composite_generator, and langmap_generator.

Definition at line 107 of file dds_generator.h.

References EscapeContext_Normal, module_scope_helper(), scoped_helper(), and to_string().

109  { return true; }

◆ get_tag_name()

std::string dds_generator::get_tag_name ( const std::string &  base_name,
bool  nested_key_only = false 
)
static

Definition at line 61 of file dds_generator.cpp.

Referenced by func(), marshal_generator::gen_enum(), marshal_generator::gen_field_getValueFromSerialized(), metaclass_generator::gen_struct(), metaclass_generator::gen_typedef(), generateCaseBody(), FieldInfo::ref(), and type_to_default_array().

62 {
63  return valid_var_name(base_name) + (nested_key_only ? "_nested_key_only" : "") + "_tag";
64 }
static std::string valid_var_name(const std::string &str)

◆ get_xtag_name()

std::string dds_generator::get_xtag_name ( UTL_ScopedName *  name)
static

Definition at line 66 of file dds_generator.cpp.

Referenced by ts_generator::generate_ts(), and typeobject_generator::tag_type().

67 {
68  return scoped_helper(name, "_") + "_xtag";
69 }
const char *const name
Definition: debug.cpp:60
static std::string scoped_helper(UTL_ScopedName *sn, const char *sep, EscapeContext cxt=EscapeContext_Normal)

◆ module_scope_helper()

string dds_generator::module_scope_helper ( UTL_ScopedName *  sn,
const char *  sep,
EscapeContext  cxt = EscapeContext_Normal 
)
static

Definition at line 117 of file dds_generator.cpp.

References EscapeContext_FromGenIdl, EscapeContext_Normal, and OpenDDS::DCPS::to_string().

Referenced by gen_union_fwd(), and module_scope().

118 {
119  string sname;
120 
121  for (; sn && sn->tail(); sn = static_cast<UTL_ScopedName*>(sn->tail())) {
122  sname += to_string(sn->head(), ec == EscapeContext_FromGenIdl ? EscapeContext_Normal : ec);
123 
124  if (sname.size()) {
125  sname += sep;
126  }
127  }
128 
129  return sname;
130 }
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)
This is for everything else.
Definition: dds_generator.h:45
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
Definition: dds_generator.h:41

◆ scoped_helper()

string dds_generator::scoped_helper ( UTL_ScopedName *  sn,
const char *  sep,
EscapeContext  cxt = EscapeContext_Normal 
)
static

Definition at line 100 of file dds_generator.cpp.

References EscapeContext_FromGenIdl, EscapeContext_Normal, and OpenDDS::DCPS::to_string().

Referenced by canonical_name(), func(), langmap_generator::gen_const(), metaclass_generator::gen_enum(), marshal_generator::gen_field_getValueFromSerialized(), metaclass_generator::gen_struct(), gen_union_fwd(), face_ts_generator::generate(), ts_generator::generate_ts(), generateCaseBody(), and scoped().

101 {
102  string sname;
103 
104  for (; sn; sn = static_cast<UTL_ScopedName*>(sn->tail())) {
105  const bool not_last = sn->tail();
106  sname += to_string(sn->head(),
107  (ec == EscapeContext_FromGenIdl && not_last) ? EscapeContext_Normal : ec);
108 
109  if (sname.size() && not_last) {
110  sname += sep;
111  }
112  }
113 
114  return sname;
115 }
static std::string to_string(Identifier *id, EscapeContext ec=EscapeContext_Normal)
This is for everything else.
Definition: dds_generator.h:45
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
Definition: dds_generator.h:41

◆ to_string()

string dds_generator::to_string ( Identifier id,
EscapeContext  ec = EscapeContext_Normal 
)
static

Definition at line 71 of file dds_generator.cpp.

References EscapeContext_ForGenIdl, EscapeContext_FromGenIdl, EscapeContext_Normal, and EscapeContext_StripEscapes.

Referenced by canonical_name(), gen_union_fwd(), ts_generator::generate_ts(), and ScopedNamespaceGuard::ScopedNamespaceGuard().

72 {
73  string str = id->get_string();
74  switch (ec) {
76  if (id->escaped()) {
77  // If it was escaped in the input, it must be escaped in generated IDL.
78  if (cxx_escaped(str)) {
79  // Strip "_cxx"
80  str = str.substr(cxx_escape.size() - 1);
81  } else {
82  str = '_' + str;
83  }
84  }
85  break;
88  if (id->escaped() && cxx_escaped(str)) {
89  // If this is a C++ keyword that was inserted into generated IDL, the
90  // "_cxx_" was stripped.
91  str = str.substr(cxx_escape.size());
92  }
93  break;
95  break;
96  }
97  return str;
98 }
static bool cxx_escaped(const std::string &s)
Strip any escapes.
Definition: dds_generator.h:43
This is for generated IDL. (Like *TypeSupport.idl)
Definition: dds_generator.h:39
This is for everything else.
Definition: dds_generator.h:45
This is for a name coming from generated IDL. (Like *TypeSupportC.h)
Definition: dds_generator.h:41

◆ valid_var_name()

std::string dds_generator::valid_var_name ( const std::string &  str)
static

Definition at line 26 of file dds_generator.cpp.

Referenced by marshal_generator::gen_enum().

27 {
28  // Replace invalid characters with a single underscore
29  // Replace existing "_" with "_9" to prevent collision
30  const std::string invalid_chars("<>()[]*.: ");
31  std::string s;
32  char last_char = '\0';
33  for (size_t i = 0; i < str.size(); ++i) {
34  const char c = str[i];
35  if (invalid_chars.find(c) == std::string::npos) {
36  s.push_back(c);
37  last_char = c;
38  if (c == '_') {
39  s.push_back('9');
40  last_char = '9';
41  }
42  } else if (last_char != '_') {
43  s.push_back('_');
44  last_char = '_';
45  }
46  }
47 
48  // Remove underscores at start and end
49  if (s.size() > 1 && s[0] == '_') {
50  if (!cxx_escaped(s)) {
51  s.erase(0, 1);
52  }
53  }
54  if (s.size() > 1 && s[s.size() - 1] == '_') {
55  s.erase(s.size() - 1, 1);
56  }
57 
58  return s;
59 }
static bool cxx_escaped(const std::string &s)

The documentation for this class was generated from the following files: