OpenDDS  Snapshot(2023/04/07-19:43)
Classes | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
itl_generator Class Reference

#include <itl_generator.h>

Inheritance diagram for itl_generator:
Inheritance graph
[legend]
Collaboration diagram for itl_generator:
Collaboration graph
[legend]

Classes

struct  Close
 
struct  Indent
 
struct  Open
 

Public Member Functions

 itl_generator ()
 
bool do_included_files () const
 
void gen_prologue ()
 
void gen_epilogue ()
 
bool gen_enum (AST_Enum *, UTL_ScopedName *name, const std::vector< AST_EnumVal *> &contents, const char *repoid)
 
bool gen_struct (AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)
 
bool gen_typedef (AST_Typedef *, UTL_ScopedName *, AST_Type *, const char *)
 
bool gen_union (AST_Union *, UTL_ScopedName *, const std::vector< AST_UnionBranch *> &, AST_Type *, const char *)
 
- Public Member Functions inherited from dds_generator
virtual ~dds_generator ()=0
 
virtual bool gen_const (UTL_ScopedName *, bool, AST_Constant *)
 
virtual bool gen_struct_fwd (UTL_ScopedName *, AST_Type::SIZE_TYPE)
 
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_fwd (AST_UnionFwd *, UTL_ScopedName *, AST_Type::SIZE_TYPE)
 

Public Attributes

int level_
 

Private Member Functions

void new_type ()
 

Private Attributes

size_t count_
 

Additional Inherited Members

- Static Public Member Functions inherited from dds_generator
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 14 of file itl_generator.h.

Constructor & Destructor Documentation

◆ itl_generator()

itl_generator::itl_generator ( )
inline

Definition at line 16 of file itl_generator.h.

17  : level_(0)
18  , count_(0)
19  {}

Member Function Documentation

◆ do_included_files()

bool itl_generator::do_included_files ( ) const
inlinevirtual

Reimplemented from dds_generator.

Definition at line 21 of file itl_generator.h.

References gen_enum(), gen_epilogue(), gen_prologue(), gen_struct(), gen_typedef(), gen_union(), and name.

21 { return true; }

◆ gen_enum()

bool itl_generator::gen_enum ( AST_Enum *  ,
UTL_ScopedName *  name,
const std::vector< AST_EnumVal *> &  contents,
const char *  repoid 
)
virtual

Reimplemented from dds_generator.

Definition at line 162 of file itl_generator.cpp.

References be_global.

Referenced by do_included_files().

164 {
165  new_type();
166 
167  be_global->itl_ << Open(this)
168  << Indent(this) << "{\n"
169  << Open(this)
170  << Indent(this) << "\"kind\" : \"alias\",\n"
171  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
172  << Indent(this) << "\"type\" :\n"
173  << Open(this)
174  << Indent(this) << "{\n"
175  << Open(this)
176  << Indent(this) << "\"kind\" : \"int\",\n"
177  << Indent(this) << "\"bits\" : 32,\n"
178  << Indent(this) << "\"unsigned\" : true,\n"
179  << Indent(this) << "\"constrained\" : true,\n"
180  << Indent(this) << "\"values\" : {";
181 
182  for (size_t i = 0; i < contents.size(); ++i) {
183  if (i > 0)
184  be_global->itl_ << ", ";
185  be_global->itl_ << '"' << contents[i]->local_name()->get_string() << '"'
186  << " : "
187  << '"' << i << '"';
188  }
189 
190  be_global->itl_ << "}\n";
191  be_global->itl_ << Close(this)
192  << Indent(this) << "}\n"
193  << Close(this);
194 
195  be_global->itl_ << Close(this)
196  << Indent(this) << "}\n"
197  << Close(this);
198 
199  return true;
200 }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_epilogue()

void itl_generator::gen_epilogue ( )
virtual

Reimplemented from dds_generator.

Definition at line 147 of file itl_generator.cpp.

References be_global.

Referenced by do_included_files().

148 {
149  be_global->itl_ << Indent(this) << "]\n"
150  << Close(this)
151  << Close(this)
152  << Indent(this) << "}\n";
153 }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_prologue()

void itl_generator::gen_prologue ( )
virtual

Reimplemented from dds_generator.

Definition at line 138 of file itl_generator.cpp.

References be_global.

Referenced by do_included_files().

139 {
140  be_global->itl_ << Indent(this) << "{\n"
141  << Open(this)
142  << Indent(this) << "\"types\" :\n"
143  << Open(this)
144  << Indent(this) << "[\n";
145 }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_struct()

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

Implements dds_generator.

Definition at line 299 of file itl_generator.cpp.

References be_global.

Referenced by do_included_files().

302 {
303  if (!be_global->itl())
304  return true;
305 
306  const bool is_topic_type =
307  idl_global->is_dcps_type(node->name()) || be_global->is_topic_type(node);
308 
309  new_type();
310 
311  be_global->itl_ << Open(this)
312  << Indent(this) << "{\n"
313  << Open(this)
314  << Indent(this) << "\"kind\" : \"alias\",\n"
315  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
316 
317  // Check if this is defined as a primary data type
318  << Indent(this) << "\"note\" : { \"is_dcps_data_type\" : "
319  << (is_topic_type ? "true" : "false")
320  << " },\n"
321 
322  << Indent(this) << "\"type\" :\n"
323  << Open(this)
324  << Indent(this) << "{\n"
325  << Open(this)
326  << Indent(this) << "\"kind\" : \"record\",\n"
327  << Indent(this) << "\"fields\" :\n"
328  << Open(this)
329  << Indent(this) << "[\n";
330 
331  bool comma_flag = false;
332  for (std::vector<AST_Field*>::const_iterator pos = fields.begin(), limit = fields.end();
333  pos != limit;
334  ++pos) {
335  AST_Field* field = *pos;
336  if (comma_flag) {
337  be_global->itl_ << Indent(this) << ",\n";
338  }
339  be_global->itl_ << Open(this)
340  << Indent(this) << "{\n"
341  << Open(this)
342  << Indent(this) << "\"name\" : \"" << field->local_name()->get_string() << "\",\n"
343  << Indent(this) << "\"type\" : " << InlineType(field->field_type()) << "\n"
344  << Close(this)
345  << Indent(this) << "}\n"
346  << Close(this);
347  comma_flag = true;
348  }
349 
350  be_global->itl_ << Indent(this) << "]\n"
351  << Close(this)
352  << Close(this)
353  << Indent(this) << "}\n"
354  << Close(this)
355  << Close(this)
356  << Indent(this) << "}\n"
357  << Close(this);
358 
359 
360  return true;
361 }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_typedef()

bool itl_generator::gen_typedef ( AST_Typedef *  ,
UTL_ScopedName *  ,
AST_Type *  base,
const char *  repoid 
)
virtual

Implements dds_generator.

Definition at line 202 of file itl_generator.cpp.

References be_global.

Referenced by do_included_files().

205 {
206  new_type();
207 
208  switch (base->node_type()) {
209  case AST_Decl::NT_sequence:
210  {
211  AST_Sequence *seq = dynamic_cast<AST_Sequence*>(base);
212  be_global->itl_ << Open(this)
213  << Indent(this) << "{\n"
214  << Open(this)
215  << Indent(this) << "\"kind\" : \"alias\",\n"
216  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
217  << Indent(this) << "\"type\" :\n"
218  << Open(this)
219  << Indent(this) << "{\n"
220  << Open(this)
221  << Indent(this) << "\"kind\" : \"sequence\",\n";
222  if (!seq->unbounded()) {
223  be_global->itl_ << Indent(this) << "\"capacity\" : " << seq->max_size()->ev()->u.ulval << ",\n";
224  }
225  be_global->itl_ << Indent(this) << "\"type\" : " << InlineType(seq->base_type()) << "\n"
226  << Close(this)
227  << Indent(this) << "}\n"
228  << Close(this)
229  << Close(this)
230  << Indent(this) << "}\n"
231  << Close(this);
232  break;
233  }
234  case AST_Decl::NT_array:
235  {
236  AST_Array* arr = dynamic_cast<AST_Array*>(base);
237  be_global->itl_ << Open(this)
238  << Indent(this) << "{\n"
239  << Open(this)
240  << Indent(this) << "\"kind\" : \"alias\",\n"
241  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
242  << Indent(this) << "\"type\" :\n"
243  << Open(this)
244  << Indent(this) << "{\n"
245  << Open(this)
246  << Indent(this) << "\"kind\" : \"sequence\",\n"
247  << Indent(this) << "\"type\" : " << InlineType(arr->base_type()) << ",\n"
248  << Indent(this) << "\"size\" : [";
249  ACE_CDR::ULong dims = arr->n_dims();
250  for (size_t i = 0; i < dims; ++i) {
251  if (i > 0)
252  be_global->itl_ << ", ";
253  be_global->itl_ << arr->dims()[i]->ev()->u.ulval;
254  }
255  be_global->itl_ << "]\n"
256  << Close(this)
257  << Indent(this) << "}\n"
258  << Close(this)
259  << Close(this)
260  << Indent(this) << "}\n"
261  << Close(this);
262  break;
263  }
264  case AST_Decl::NT_fixed:
265  {
266  AST_Fixed* fixed = dynamic_cast<AST_Fixed*>(base);
267  unsigned digits = fixed->digits()->ev()->u.ulval;
268  unsigned scale = fixed->scale()->ev()->u.ulval;
269  be_global->itl_
270  << Open(this) << Indent(this) << "{\n" << Open(this)
271  << Indent(this) << "\"kind\" : \"alias\",\n"
272  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
273  << Indent(this) << "\"type\" : { "
274  << "\"kind\" : \"fixed\", "
275  << "\"digits\" : " << digits << ", "
276  << "\"scale\" : " << scale << ", "
277  << "\"base\" : 10 }\n"
278  << Close(this) << Indent(this) << "}\n" << Close(this);
279  break;
280  }
281  default:
282  {
283  be_global->itl_ << Open(this)
284  << Indent(this) << "{\n"
285  << Open(this)
286  << Indent(this) << "\"kind\" : \"alias\",\n"
287  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
288  << Indent(this) << "\"type\" : " << InlineType(base) << "\n"
289  << Close(this)
290  << Indent(this) << "}\n"
291  << Close(this);
292 
293  return true;
294  }
295  }
296  return true;
297 }
ACE_UINT32 ULong
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ gen_union()

bool itl_generator::gen_union ( AST_Union *  node,
UTL_ScopedName *  ,
const std::vector< AST_UnionBranch *> &  cases,
AST_Type *  _d,
const char *  repoid 
)
virtual

Implements dds_generator.

Definition at line 364 of file itl_generator.cpp.

References be_global.

Referenced by do_included_files().

368 {
369  new_type();
370 
371  be_global->itl_ << Open(this)
372  << Indent(this) << "{\n"
373  << Open(this)
374  << Indent(this) << "\"kind\" : \"alias\",\n"
375  << Indent(this) << "\"name\" : \"" << repoid << "\",\n"
376  << Indent(this) << "\"type\" :\n"
377  << Open(this)
378  << Indent(this) << "{\n"
379  << Open(this)
380  << Indent(this) << "\"kind\" : \"union\",\n"
381  << Indent(this) << "\"discriminator\" : " << InlineType(_d) << ",\n"
382  << Indent(this) << "\"note\" : { \"is_dcps_data_type\" : "
383  << (be_global->is_topic_type(node) ? "true" : "false")
384  << " },\n"
385  << Indent(this) << "\"fields\" :\n"
386  << Open(this)
387  << Indent(this) << "[\n";
388 
389  for (std::vector<AST_UnionBranch*>::const_iterator pos = cases.begin(), limit = cases.end();
390  pos != limit;
391  ++pos) {
392  if (pos != cases.begin())
393  be_global->itl_ << Indent(this) << ",\n";
394 
395  AST_UnionBranch *branch = *pos;
396 
397  be_global->itl_ << Open(this)
398  << Indent(this) << "{\n"
399  << Open(this)
400  << Indent(this) << "\"name\" : \"" << branch->local_name()->get_string() << "\",\n"
401  << Indent(this) << "\"type\" : " << InlineType(branch->field_type()) << ",\n"
402 
403  << Indent(this) << "\"labels\" : [";
404 
405 
406  unsigned long count = branch->label_list_length();
407  for (unsigned long i = 0; i < count; i++)
408  {
409  if (i > 0)
410  be_global->itl_ << ", ";
411  AST_UnionLabel *label = branch->label(i);
412  if (label->label_kind() == AST_UnionLabel::UL_default)
413  {
414  continue;
415  }
416  be_global->itl_ << "\"" << label->label_val()->n()->last_component()->get_string() << "\"";
417  }
418 
419  be_global->itl_ << "]\n"
420  << Close(this)
421  << Indent(this) << "}\n"
422  << Close(this);
423  }
424 
425  be_global->itl_ << Indent(this) << "]\n"
426  << Close(this)
427  << Close(this)
428  << Indent(this) << "}\n"
429  << Close(this)
430  << Close(this)
431  << Indent(this) << "}\n"
432  << Close(this);
433 
434  return true;
435 }
BE_GlobalData * be_global
Definition: be_global.cpp:43

◆ new_type()

void itl_generator::new_type ( )
private

Definition at line 155 of file itl_generator.cpp.

References be_global.

156 {
157  if (count_ > 0)
158  be_global->itl_ << Indent(this) << ",\n";
159  ++count_;
160 }
BE_GlobalData * be_global
Definition: be_global.cpp:43

Member Data Documentation

◆ count_

size_t itl_generator::count_
private

Definition at line 65 of file itl_generator.h.

◆ level_

int itl_generator::level_

Definition at line 62 of file itl_generator.h.

Referenced by operator<<().


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