OpenDDS  Snapshot(2023/04/28-20:55)
typeobject_generator.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef typeobject_generator_H
9 #define typeobject_generator_H
10 
11 #include "dds_generator.h"
13 
15 public:
17  : produce_output_(false)
19  , index_(0)
20  , get_type_map_declared_(false)
21  , typeid_encoding_(0)
22  {}
23 
24  void gen_epilogue();
25 
26  bool gen_enum(AST_Enum* node, UTL_ScopedName* name,
27  const std::vector<AST_EnumVal*>& contents, const char* repoid);
28 
29  bool gen_struct(AST_Structure* node, UTL_ScopedName* name,
30  const std::vector<AST_Field*>& fields,
31  AST_Type::SIZE_TYPE size, const char* repoid);
32 
33  bool gen_typedef(AST_Typedef* node, UTL_ScopedName* name, AST_Type* type, const char* repoid);
34 
35  bool gen_union(AST_Union* node, UTL_ScopedName* name,
36  const std::vector<AST_UnionBranch*>& branches,
37  AST_Type* type, const char* repoid);
38 
39  static std::string tag_type(UTL_ScopedName* name);
40 
41  void produce_output(bool flag)
42  {
43  produce_output_ = flag;
44  }
45 
46  void produce_xtypes_complete(bool flag)
47  {
49  }
50 
52 
53 private:
54 
55  struct Element {
56  AST_Type* type;
57  size_t index;
58  size_t lowlink;
59  bool on_stack;
60  std::string name;
61 
62  bool operator<(const Element& other) const
63  {
64  return name < other.name;
65  }
66  };
67 
68  void consider(Element& v, AST_Type* type, const std::string& anonymous_name);
69  void strong_connect(AST_Type* type, const std::string& anonymous_name);
70  void generate_type_identifier(AST_Type* type, bool force_type_object);
71 
72  // Generate minimal and complete type objects and type identifiers for the corresponding types.
73  void generate_struct_type_identifier(AST_Type* type);
74  void generate_union_type_identifier(AST_Type* type);
75  void generate_enum_type_identifier(AST_Type* type);
76  void generate_array_type_identifier(AST_Type* type, bool force_type_object);
77  void generate_sequence_type_identifier(AST_Type* type, bool force_type_object);
78  void generate_alias_type_identifier(AST_Type* type);
79  void generate_primitive_type_identifier(AST_Type* type);
80  void update_maps(AST_Type* type,
81  const OpenDDS::XTypes::TypeObject& minimal_to,
82  const OpenDDS::XTypes::TypeObject& complete_to);
83  void set_builtin_member_annotations(AST_Decl* member,
85 
88  bool generate(AST_Type* node, UTL_ScopedName* name);
89  void declare_get_type_map();
90 
91  // Both fields must be constructed when an object is created.
92  struct TypeObjectPair {
95  };
96 
97  typedef std::map<AST_Type*, TypeObjectPair> TypeObjectMap;
98  TypeObjectMap type_object_map_;
99 
100  // Both fields must be constructed when an object is created.
104  };
105 
106  typedef std::map<AST_Type*, TypeIdentifierPair> HashTypeIdentifierMap;
107  HashTypeIdentifierMap hash_type_identifier_map_;
108 
109  typedef std::map<AST_Type*, OpenDDS::XTypes::TypeIdentifier> FullyDescriptiveTypeIdentifierMap;
110  FullyDescriptiveTypeIdentifierMap fully_desc_type_identifier_map_;
111 
112  OpenDDS::XTypes::TypeMap minimal_type_map_;
113  OpenDDS::XTypes::TypeMap complete_type_map_;
114 
117  size_t index_;
118  typedef std::vector<AST_Type*> Stack;
119  Stack stack_;
120  std::map<AST_Type*, Element> element_;
123 };
124 
125 #endif
FullyDescriptiveTypeIdentifierMap fully_desc_type_identifier_map_
std::vector< AST_Type * > Stack
OpenDDS::XTypes::TypeMap minimal_type_map_
bool generate(AST_Type *node, UTL_ScopedName *name)
void strong_connect(AST_Type *type, const std::string &anonymous_name)
std::map< AST_Type *, Element > element_
void generate_enum_type_identifier(AST_Type *type)
static std::string tag_type(UTL_ScopedName *name)
bool gen_enum(AST_Enum *node, UTL_ScopedName *name, const std::vector< AST_EnumVal *> &contents, const char *repoid)
void generate_primitive_type_identifier(AST_Type *type)
bool gen_struct(AST_Structure *node, UTL_ScopedName *name, const std::vector< AST_Field *> &fields, AST_Type::SIZE_TYPE size, const char *repoid)
void generate_union_type_identifier(AST_Type *type)
std::map< AST_Type *, TypeObjectPair > TypeObjectMap
void produce_output(bool flag)
void update_maps(AST_Type *type, const OpenDDS::XTypes::TypeObject &minimal_to, const OpenDDS::XTypes::TypeObject &complete_to)
OpenDDS::XTypes::TypeObject minimal
OpenDDS::XTypes::TypeObject complete
bool gen_union(AST_Union *node, UTL_ScopedName *name, const std::vector< AST_UnionBranch *> &branches, AST_Type *type, const char *repoid)
void set_builtin_member_annotations(AST_Decl *member, OpenDDS::XTypes::Optional< OpenDDS::XTypes::AppliedBuiltinMemberAnnotations > &annotations)
std::map< AST_Type *, TypeIdentifierPair > HashTypeIdentifierMap
void generate_array_type_identifier(AST_Type *type, bool force_type_object)
void consider(Element &v, AST_Type *type, const std::string &anonymous_name)
HashTypeIdentifierMap hash_type_identifier_map_
void generate_sequence_type_identifier(AST_Type *type, bool force_type_object)
const char *const name
Definition: debug.cpp:60
bool gen_typedef(AST_Typedef *node, UTL_ScopedName *name, AST_Type *type, const char *repoid)
OpenDDS::XTypes::TypeIdentifier get_minimal_type_identifier(AST_Type *type)
OpenDDS::XTypes::TypeIdentifier get_complete_type_identifier(AST_Type *type)
OpenDDS::XTypes::TypeMap complete_type_map_
void generate_alias_type_identifier(AST_Type *type)
bool operator<(const Element &other) const
TypeObjectMap type_object_map_
void generate_type_identifier(AST_Type *type, bool force_type_object)
OpenDDS::XTypes::TypeIdentifier minimal
void produce_xtypes_complete(bool flag)
OpenDDS::XTypes::TypeIdentifier complete
void generate_struct_type_identifier(AST_Type *type)
OpenDDS::DCPS::Encoding * typeid_encoding_
std::map< AST_Type *, OpenDDS::XTypes::TypeIdentifier > FullyDescriptiveTypeIdentifierMap