OpenDDS  Snapshot(2023/04/28-20:55)
be_global.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 OPENDDS_IDL_BE_GLOBAL_H
9 #define OPENDDS_IDL_BE_GLOBAL_H
10 
11 #include "annotations.h"
12 
14 
15 #include <utl_scoped_name.h>
16 #include <idl_defines.h>
17 #ifndef TAO_IDL_HAS_ANNOTATIONS
18 # error "Annotation support in tao_idl is required, please use a newer version of TAO"
19 #endif
20 
21 #include <ace/SString.h>
22 
23 #include <string>
24 #include <sstream>
25 #include <set>
26 
27 #if !defined (ACE_LACKS_PRAGMA_ONCE)
28 # pragma once
29 #endif /* ACE_LACKS_PRAGMA_ONCE */
30 
31 class AST_Generator;
32 class AST_Decl;
33 class UTL_Scope;
34 class AST_Structure;
35 class AST_Field;
36 class AST_Union;
37 class AST_Annotation_Decl;
38 
39 // Defines a class containing all back end global data.
40 
41 class BE_GlobalData {
42 public:
43  // = TITLE
44  // BE_GlobalData
45  //
46  // = DESCRIPTION
47  // Storage of global data specific to the compiler back end
48  //
49  BE_GlobalData();
50 
51  virtual ~BE_GlobalData();
52 
53  // Data accessors.
54 
55  const char* holding_scope_name() const;
56 
57  void destroy();
58  // Cleanup function.
59 
60  const char* filename() const;
61  void filename(const char* fname);
62 
64  // Command line passed to ACE_Process::spawn. Different
65  // implementations in IDL and IFR backends.
66 
67  void parse_args(long& i, char** av);
68  // Parse args that affect the backend.
69 
70  void open_streams(const char* filename);
71 
72  std::ostringstream header_, impl_, idl_, itl_, facets_header_, facets_impl_,
73  lang_header_;
74  ACE_CString header_name_, impl_name_, idl_name_, itl_name_,
75  facets_header_name_, facets_impl_name_, lang_header_name_,
76  output_dir_, tao_inc_pre_;
77 
78  ///print message to all open streams
79  void multicast(const char* message);
80 
81  enum stream_enum_t {
82  STREAM_H, STREAM_CPP, STREAM_IDL, STREAM_ITL,
83  STREAM_FACETS_H, STREAM_FACETS_CPP,
84  STREAM_LANG_H,
85  STREAM_COUNT
86  };
87 
88  void reset_includes();
89 
90  void add_include(const char* file, stream_enum_t which = STREAM_H);
91  void conditional_include(const char* file, stream_enum_t which, const char* condition);
92 
93  /// Called to indicate that OpenDDS marshaling (serialization) code for the
94  /// current file will depend on marshaling code generated for the indicated
95  /// file. For example, if the current file is A.idl and it contains a struct
96  /// which has a field of type B, defined in B.idl, the full path to B.idl is
97  /// passed to this function.
98  void add_referenced(const char* file);
99 
100  void set_inc_paths(const char* cmdline);
101  void add_inc_path(const char* path);
102 
103  std::string get_include_block(stream_enum_t which);
104 
105  ACE_CString export_macro() const;
106  void export_macro(const ACE_CString& str);
107 
108  ACE_CString export_include() const;
109  void export_include(const ACE_CString& str);
110 
111  ACE_CString versioning_name() const;
112  void versioning_name(const ACE_CString& str);
113 
114  ACE_CString versioning_begin() const;
115  void versioning_begin(const ACE_CString& str);
116 
117  ACE_CString versioning_end() const;
118  void versioning_end(const ACE_CString& str);
119 
120  ACE_CString pch_include() const;
121  void pch_include(const ACE_CString& str);
122 
123  const std::set<std::pair<std::string, std::string> >& cpp_includes() const;
124  void add_cpp_include(const std::string& str);
125 
126  bool java() const;
127  void java(bool b);
128 
129  bool no_default_gen() const;
130  void no_default_gen(bool b);
131 
132  bool filename_only_includes() const;
133  void filename_only_includes(bool b);
134 
135  bool itl() const;
136  void itl(bool b);
137 
138  bool value_reader_writer() const;
139  void value_reader_writer(bool b);
140 
141  bool face_ts() const;
142  void face_ts(bool b);
143 
144  bool xtypes_complete() const;
145  void xtypes_complete(bool b);
146 
147  bool old_typeobject_encoding() const { return old_typeobject_encoding_; }
148  void old_typeobject_encoding(bool b) { old_typeobject_encoding_ = b; }
149 
150  bool old_typeobject_member_order() const { return old_typeobject_member_order_; }
151  void old_typeobject_member_order(bool b) { old_typeobject_member_order_ = b; }
152 
153  ACE_CString java_arg() const;
154  void java_arg(const ACE_CString& str);
155 
156  enum LanguageMapping {
157  LANGMAP_NONE, ///< Don't generate, let tao_idl handle it
158  LANGMAP_FACE_CXX, ///< Generate C++ language mapping from FACE spec
159  LANGMAP_SP_CXX, ///< Generate C++ language mapping for Safety Profile
160  LANGMAP_CXX11, ///< Generate OMG IDL-to-C++11
161  };
162 
163  LanguageMapping language_mapping() const;
164  void language_mapping(LanguageMapping lm);
165 
166  ACE_CString sequence_suffix() const;
167  void sequence_suffix(const ACE_CString& str);
168 
169  bool suppress_idl() const { return suppress_idl_; }
170  bool suppress_typecode() const { return suppress_typecode_; }
171  bool suppress_xtypes() const { return suppress_xtypes_; }
172 
173  static bool writeFile(const char* fileName, const std::string& content);
174 
175  /**
176  * Based on annotations and global_default_nested_, determine if a type is a
177  * topic type and needs type support.
178  *
179  * Does not check for specific types of types (struct vs array).
180  */
181  bool is_topic_type(AST_Decl* node);
182 
183  /**
184  * Nested property of the root module. Assuming there are no annotations, all
185  * potential topic types inherit this value. True by default unless
186  * --no-default-nested was passed.
187  */
188  bool root_default_nested() const;
189 
190  /**
191  * If node has the key annotation, this sets value to the key annotation
192  * value and returns true, else this sets value to false and returns false.
193  */
194  bool check_key(AST_Decl* node, bool& value) const;
195 
196  /**
197  * Check if the discriminator in a union has been declared a key.
198  */
199  bool union_discriminator_is_key(AST_Union* node);
200 
201  /**
202  * Give a warning that looks like one from tao_idl
203  */
204  void warning(const char* msg, const char* filename = 0, unsigned lineno = 0);
205 
206  /**
207  * Give an error that looks like one from tao_idl
208  */
209  void error(const char* msg, const char* filename = 0, unsigned lineno = 0);
210 
211  /**
212  * Wrapper around built-in annotations, see annotations.h
213  */
214  Annotations builtin_annotations_;
215 
216  /**
217  * If true, warn about #pragma DCPS_DATA_TYPE
218  */
219  bool warn_about_dcps_data_type();
220 
221  ExtensibilityKind extensibility(AST_Decl* node, ExtensibilityKind default_extensibility, bool& has_annotation) const;
222  ExtensibilityKind extensibility(AST_Decl* node, ExtensibilityKind default_extensibility) const;
223  ExtensibilityKind extensibility(AST_Decl* node) const;
224  AutoidKind autoid(AST_Decl* node) const;
225  bool id(AST_Decl* node, ACE_CDR::ULong& value) const;
226  bool hashid(AST_Decl* node, std::string& value) const;
227  bool is_optional(AST_Decl* node) const;
228  bool is_must_understand(AST_Decl* node) const;
229  bool is_effectively_must_understand(AST_Decl* node) const;
230  bool is_key(AST_Decl* node) const;
231  bool is_external(AST_Decl* node) const;
232  bool is_plain(AST_Decl* node) const;
233 
234  TryConstructFailAction try_construct(AST_Decl* node) const;
235  TryConstructFailAction sequence_element_try_construct(AST_Sequence* node);
236  TryConstructFailAction array_element_try_construct(AST_Array* node);
237  TryConstructFailAction union_discriminator_try_construct(AST_Union* node);
238 
239  OpenDDS::DataRepresentation data_representations(AST_Decl* node) const;
240 
241  OpenDDS::XTypes::MemberId compute_id(AST_Structure* stru, AST_Field* field, AutoidKind auto_id,
242  OpenDDS::XTypes::MemberId& member_id);
243  OpenDDS::XTypes::MemberId get_id(AST_Field* field);
244 
245  bool is_nested(AST_Decl* node);
246 
247  bool default_enum_extensibility_zero() const
248  {
249  return default_enum_extensibility_zero_;
250  }
251 
252  bool dynamic_data_adapter(AST_Decl* node) const;
253 
254  bool special_serialization(AST_Decl* node, std::string& template_name) const;
255 
256 private:
257  /// Name of the IDL file we are processing.
258  const char* filename_;
259 
260  bool java_, suppress_idl_, suppress_typecode_, suppress_xtypes_,
261  no_default_gen_, generate_itl_,
262  generate_value_reader_writer_,
263  generate_xtypes_complete_, face_ts_;
264 
265  bool filename_only_includes_;
266 
267  ACE_CString export_macro_, export_include_,
268  versioning_name_, versioning_begin_, versioning_end_,
269  pch_include_, java_arg_, sequence_suffix_;
270  std::set<std::pair<std::string, std::string> > cpp_includes_;
271 
272  LanguageMapping language_mapping_;
273 
274  bool root_default_nested_;
275  bool warn_about_dcps_data_type_;
276  ExtensibilityKind default_extensibility_;
277  bool default_enum_extensibility_zero_;
278  OpenDDS::DataRepresentation default_data_representation_;
279  AutoidKind root_default_autoid_;
280  TryConstructFailAction default_try_construct_;
281  std::set<std::string> platforms_;
282  typedef std::map<AST_Field*, OpenDDS::XTypes::MemberId> MemberIdMap;
283  MemberIdMap member_id_map_;
284  typedef std::map<OpenDDS::XTypes::MemberId, AST_Field*> MemberIdCollisionMap;
285  typedef std::map<AST_Structure*, MemberIdCollisionMap> GlobalMemberIdCollisionMap;
286  GlobalMemberIdCollisionMap member_id_collision_map_;
287  bool old_typeobject_encoding_;
288  bool old_typeobject_member_order_;
289 
290  bool is_default_nested(UTL_Scope* scope);
291  AutoidKind scoped_autoid(UTL_Scope* scope) const;
292 };
293 
295 public:
296 
297  BE_Comment_Guard(const char* type, const char* name);
298  ~BE_Comment_Guard();
299 
300 private:
301  const char *type_, *name_;
302 };
303 
304 #endif /* OPENDDS_IDL_BE_GLOBAL_H */
const char * filename(void) const
Definition: be_global.cpp:86
ACE_CDR::ULong MemberId
Definition: TypeObject.h:910
const LogLevel::Value value
Definition: debug.cpp:61
void parse_args(long &i, char **av)
Definition: be_global.cpp:338
TryConstructFailAction
Definition: annotations.h:316
ExtensibilityKind
Definition: annotations.h:278
char * filename_
virtual ~BE_GlobalData(void)
Definition: be_global.cpp:76
ACE_UINT32 ULong
const char *const name
Definition: debug.cpp:60
void destroy(void)
Definition: be_global.cpp:81
ACE_CString spawn_options(void)
Definition: be_global.cpp:325
const char * type_
Definition: be_global.h:301
AutoidKind
Definition: annotations.h:217
BE_GlobalData(void)
Definition: be_global.cpp:46