Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be_include / be_codegen.h
blobabfa4b7cb1d3d891d1a4a949537fb3e692d82f09
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file be_codegen.h
7 * The Code generator class
9 * @author Aniruddha Gokhale
11 //=============================================================================
13 #ifndef TAO_BE_CODEGEN_H
14 #define TAO_BE_CODEGEN_H
16 #include "ace/Singleton.h"
17 #include "ace/Synch_Traits.h"
18 #include "ace/Unbounded_Queue.h"
20 #include "TAO_IDL_BE_Export.h"
22 class TAO_OutStream;
23 class be_visitor_context;
24 class be_visitor;
25 class be_decl;
27 /**
28 * @class TAO_CodeGen
30 * @brief TAO_CodeGen
32 * Holds global parameters for the Back End and
33 * generates the C++ mapping.
35 class TAO_IDL_BE_Export TAO_CodeGen
37 public:
39 // Define all the code generation states.
40 // The first letter C/S of the suffix stands for client/server-side
41 // The second letter H/I/S stands for header/inline/impl file.
42 // These are used to denote the state or the context of code
43 // generation we are in and serves to produce the right kind of
44 // visitor for us.
46 enum CG_STATE
48 // Initial state.
49 TAO_INITIAL,
51 // Rest of the state in alphabetical order of the types.
53 // Emitting code for arguments of an operation. No distinction between
54 // headers, inlines, stubs.
55 TAO_ARGUMENT_COLLOCATED_UPCALL_SS, // passing argument
56 // variable to upcall
58 // Emitting code for array defn.
59 TAO_ARRAY_CH,
61 // Emitting code for exceptions.
62 TAO_EXCEPTION_CTOR_CH,
63 TAO_EXCEPTION_CTOR_CS,
65 // Emitting code for the interface.
66 TAO_INTERFACE_CH,
67 TAO_INTERFACE_SMART_PROXY_CH,
68 TAO_INTERFACE_SMART_PROXY_CS,
70 TAO_INTERFACE_DIRECT_PROXY_IMPL_SH,
71 TAO_INTERFACE_DIRECT_PROXY_IMPL_SS,
73 // Emitting code for the AMH ResponseHandlers.
74 TAO_INTERFACE_AMH_RH_SH,
75 TAO_INTERFACE_AMH_RH_SS,
77 // Emitting code for the valuetype.
78 TAO_VALUETYPE_OBV_CH, // OBV_ class
80 // Emitting code for the module,
81 TAO_MODULE_OBV_CH, // for OBV_ (cmp. POA_ namespace)
82 TAO_MODULE_OBV_CI,
83 TAO_MODULE_OBV_CS,
85 // Emitting code for an operation.
86 TAO_OPERATION_CH, // in client header
87 TAO_OPERATION_CS, // in client stubs
89 TAO_OPERATION_ARGLIST_CH, // parameter list in op signature
90 TAO_OPERATION_ARGLIST_SH, // ... for server header
91 TAO_TIE_OPERATION_ARGLIST_SH, // ... for TIE class header
93 TAO_OPERATION_ARGLIST_PROXY_IMPL_XS,
95 TAO_OPERATION_ARGLIST_IH, // ... for implementation header
96 TAO_OPERATION_ARGLIST_IS, // ... for implementation header
97 TAO_OPERATION_ARGLIST_COLLOCATED_SH, // ... for collocated server
98 // variable to do_static_call
99 TAO_OPERATION_ARG_INVOKE_CS, // passing argument variable to do_static_call
100 // after do_static_call
101 TAO_OPERATION_ARG_DECL_SS, // argument decl in skeleton
102 TAO_OPERATION_ARG_DEMARSHAL_SS, // and argument variables to the
103 // variable
104 TAO_OPERATION_ARG_UPCALL_SS, // variables to upcall
105 TAO_OPERATION_COLLOCATED_ARG_UPCALL_SS, // variables to upcall for
106 // collocated op
108 TAO_OBV_OPERATION_ARGLIST_CH, // parameter list in obv op signature
109 TAO_OBV_OPERATION_ARGLIST_CS, // used only for AMH exceptions
110 TAO_OBV_OPERATION_ARGLIST_SH, // ... for server header
111 TAO_OBV_OPERATION_ARGLIST_IH, // ... for implementation header
112 TAO_OBV_OPERATION_ARGLIST_IS, // ... for implementation header
114 // Emitting code for root.
115 TAO_ROOT_CH,
116 TAO_ROOT_CI,
117 TAO_ROOT_CS,
118 TAO_ROOT_SH,
119 TAO_ROOT_SS,
120 TAO_ROOT_TIE_SH,
121 TAO_ROOT_TIE_SS,
122 TAO_ROOT_IH,
123 TAO_ROOT_IS,
124 TAO_ROOT_SVH,
125 TAO_ROOT_SVS,
126 TAO_ROOT_SVTH,
127 TAO_ROOT_SVTS,
128 TAO_ROOT_EXH,
129 TAO_ROOT_EXS,
130 TAO_ROOT_CNH,
131 TAO_ROOT_CNS,
132 TAO_ROOT_EX_IDL,
133 TAO_ROOT_ANY_OP_CH,
134 TAO_ROOT_ANY_OP_CS,
135 TAO_ROOT_CDR_OP_CH,
136 TAO_ROOT_CDR_OP_CS,
138 // Emitting code for sequence base type.
139 TAO_SEQUENCE_BASE_CH,
141 // For special sequnce elements.
142 TAO_SEQELEM_RETTYPE_CH,
144 // For sequence buffer types.
145 TAO_SEQUENCE_BUFFER_TYPE_CH,
147 // Emitting code for the public members of the union.
148 TAO_UNION_PUBLIC_CH,
149 TAO_UNION_PUBLIC_CI,
150 TAO_UNION_PUBLIC_CS,
151 TAO_UNION_PUBLIC_ASSIGN_CS,
152 TAO_UNION_PUBLIC_RESET_CS,
154 // Emitting code for private members of the union.
155 TAO_UNION_PRIVATE_CH
158 enum LOOKUP_STRATEGY
160 // Various lookup strategies.
161 TAO_LINEAR_SEARCH,
162 TAO_DYNAMIC_HASH,
163 TAO_PERFECT_HASH,
164 TAO_BINARY_SEARCH
167 enum CG_SUB_STATE
169 // Sub states.
171 // These are for the CDR operators.
172 TAO_CDR_INPUT,
173 TAO_CDR_OUTPUT,
174 TAO_CDR_SCOPE,
176 // These are for typecode generation.
177 TAO_TC_DEFN_TYPECODE, // top level typecode
178 TAO_TC_DEFN_TYPECODE_NESTED, // nested tc
180 TAO_TC_DEFN_ENCAPSULATION, // encapsulation
182 TAO_TC_DEFN_SCOPE, // scope
183 TAO_TC_DEFN_TC_SIZE, // tc size computation
184 TAO_TC_DEFN_ENCAP_LEN, // encap size computation
185 TAO_TC_DEFN_SCOPE_LEN, // scope size computation
187 // Means we are generating the copy constructor
188 TAO_UNION_COPY_CONSTRUCTOR,
190 // Generating the _var template parameter in sequence of arrays.
191 TAO_ARRAY_SEQ_CH_TEMPLATE_VAR,
193 // Generating an AMH response handler operation.
194 TAO_AMH_RESPONSE_HANDLER_OPERATION,
196 // Used to denote either error or don't care.
197 TAO_SUB_STATE_UNKNOWN
200 /// Constructor
201 TAO_CodeGen (void);
203 /// Destructor
204 ~TAO_CodeGen (void);
206 /// Set the client header stream.
207 int start_client_header (const char *fname);
209 /// Set the client inline stream.
210 int start_client_inline (const char *fname);
212 /// Set the client stub stream.
213 int start_client_stubs (const char *fname);
215 /// Set the server header stream.
216 int start_server_header (const char *fname);
218 /// Set the implementation header stream.
219 int start_implementation_header (const char *fname);
221 /// Set the implementation skeleton stream.
222 int start_implementation_skeleton (const char *fname);
224 /// Set the server template header stream.
225 int start_server_template_header (const char *fname);
227 /// Set the server skeletons stream.
228 int start_server_skeletons (const char *fname);
230 /// Set the server template skeletons stream.
231 int start_server_template_skeletons (const char *fname);
233 /// Set the anyop header stream.
234 int start_anyop_header (const char *fname);
236 /// Set the anyop source stream.
237 int start_anyop_source (const char *fname);
239 int start_ciao_svnt_header (const char *fname);
240 int start_ciao_svnt_source (const char *fname);
241 int start_ciao_svnt_template_header (const char *fname);
242 int start_ciao_svnt_template_source (const char *fname);
243 int start_ciao_exec_header (const char *fname);
244 int start_ciao_exec_source (const char *fname);
245 int start_ciao_exec_idl (const char *fname);
246 int start_ciao_conn_header (const char *fname);
247 int start_ciao_conn_source (const char *fname);
248 int start_ciao_ami_conn_idl (const char *fname);
250 /// Generate code at the end such as the <<= and >>= operators along
251 /// with the ending #endif statement.
252 int end_client_header (void);
254 /// Generate necessary code at end of client inline file.
255 void end_client_inline (void);
257 /// Generate necessary code at end of client stub file.
258 void end_client_stubs (void);
260 /// Put a last #endif in the server header.
261 int end_server_header (void);
263 /// Put a last #endif in the server header.
264 int end_implementation_header (const char *fname);
266 /// Put a last #endif in the server header.
267 int end_implementation_skeleton (const char *fname);
269 /// Put a last #endif in the server template header.
270 int end_server_template_header (void);
272 /// Put a last #endif in the server skeletons.
273 int end_server_template_skeletons (void);
275 /// Put a last #endif in the server skeletons.
276 int end_server_skeletons (void);
278 /// Put a last #endif in the anyop header.
279 int end_anyop_header (void);
281 /// Make sure we end with a newline.
282 int end_anyop_source (void);
284 int end_ciao_svnt_header (void);
285 int end_ciao_svnt_source (void);
286 int end_ciao_svnt_template_header (void);
287 int end_ciao_svnt_template_source (void);
288 int end_ciao_exec_header (void);
289 int end_ciao_exec_source (void);
290 int end_ciao_exec_idl (void);
291 int end_ciao_conn_header (void);
292 int end_ciao_conn_source (void);
293 int end_ciao_ami_conn_idl (void);
295 /// Get the client header stream.
296 TAO_OutStream *client_header (void);
298 /// Get the client stubs stream.
299 TAO_OutStream *client_stubs (void);
301 /// Get the client inline stream.
302 TAO_OutStream *client_inline (void);
304 /// get the server header stream.
305 TAO_OutStream *server_header (void);
307 /// Get the implementation header stream.
308 TAO_OutStream *implementation_header (void);
310 /// Get the implementation skeleton stream.
311 TAO_OutStream *implementation_skeleton (void);
313 /// Get the server header template stream.
314 TAO_OutStream *server_template_header (void);
316 /// Get the server skeletons stream.
317 TAO_OutStream *server_skeletons (void);
319 /// Get the server template skeletons stream.
320 TAO_OutStream *server_template_skeletons (void);
322 /// Get the server template inline stream.
323 TAO_OutStream *server_template_inline (void);
325 /// Get the anyop header stream.
326 TAO_OutStream *anyop_header (void);
328 /// Get the anyop source stream.
329 TAO_OutStream *anyop_source (void);
331 /// Get the CIAO servant header stream.
332 TAO_OutStream *ciao_svnt_header (void);
334 /// Get the CIAO servant source stream.
335 TAO_OutStream *ciao_svnt_source (void);
337 /// Get the CIAO template servant header stream.
338 TAO_OutStream *ciao_svnt_template_header (void);
340 /// Get the CIAO template servant source stream.
341 TAO_OutStream *ciao_svnt_template_source (void);
343 /// Get the CIAO executor impl header stream.
344 TAO_OutStream *ciao_exec_header (void);
346 /// Get the CIAO executor impl source stream.
347 TAO_OutStream *ciao_exec_source (void);
349 /// Get the CIAO executor IDL source stream.
350 TAO_OutStream *ciao_exec_idl (void);
352 /// Get the CIAO connector impl header stream.
353 TAO_OutStream *ciao_conn_header (void);
355 /// Get the CIAO connector impl source stream.
356 TAO_OutStream *ciao_conn_source (void);
358 /// Get the CIAO AMI connector IDL stream.
359 TAO_OutStream *ciao_ami_conn_idl (void);
361 /// Set the gperf input file stream.
362 void gperf_input_stream (TAO_OutStream *gperf_input);
364 /// Retrieve the gperf input stream being used.
365 TAO_OutStream *gperf_input_stream (void);
367 /// Set the gperf input file name.
368 void gperf_input_filename (char *filename);
371 * Retrieve the gperf input file name being used.
372 * Name of the temp file used to collect the input for gperf
373 * program. This is needed coz I do ACE_OS::open on this when I need
374 * ACE_HANDLE for the file instead FILE*.
376 char *gperf_input_filename (void);
378 /// Convert input string to all one case.
379 const char *upcase (const char *str);
380 const char *downcase (const char *str);
382 /// Pass along the #ident string, if any, from the IDL file.
383 void gen_ident_string (TAO_OutStream *stream) const;
385 /// Generates the export files selected on the command line.
386 void gen_export_files (void);
388 /// Generate file include, with optional empty comment to
389 /// short-circuit DOxygen.
390 void gen_standard_include (TAO_OutStream *stream,
391 const char *included_file,
392 bool add_comment = false);
394 /// Cleanup.
395 void destroy (void);
397 private:
398 void gen_ifndef_string (const char *fname,
399 TAO_OutStream *stream,
400 const char *prefix,
401 const char *suffix);
403 /// Utility methods for generating file includes.
404 void gen_stub_hdr_includes (void);
405 void gen_stub_src_includes (void);
406 void gen_skel_hdr_includes (void);
407 void gen_skel_src_includes (void);
408 void gen_seq_file_includes (void);
409 void gen_any_file_includes (TAO_OutStream * stream) ;
410 void gen_var_file_includes (void);
411 void gen_stub_arg_file_includes (TAO_OutStream * stream);
412 void gen_skel_arg_file_includes (TAO_OutStream * stream);
413 void gen_cond_file_include (bool condition_green,
414 const char *filepath,
415 TAO_OutStream *stream);
416 void gen_typecode_includes (TAO_OutStream * stream);
418 /// Used if one or both of the CIAO code gen flags are set.
419 void gen_svnt_hdr_includes (TAO_OutStream *stream);
420 void gen_svnt_src_includes (TAO_OutStream *stream);
421 void gen_svnt_tmpl_hdr_includes (TAO_OutStream *stream);
422 void gen_exec_hdr_includes (void);
423 void gen_exec_src_includes (void);
424 void gen_exec_idl_includes (void);
425 void gen_conn_hdr_includes (void);
426 void gen_conn_src_includes (void);
427 void gen_ami_conn_idl_includes (void);
429 bool is_system_file (const char * idl_name) const;
431 void gen_export_file (const char *filename,
432 const char *macro,
433 const char *msg,
434 bool for_skel = false);
436 void make_rand_extension (char * const t);
438 void gen_conn_ts_includes (ACE_Unbounded_Queue<char *> &ts_files);
440 private:
441 /// Client header stream.
442 TAO_OutStream *client_header_;
444 /// Client stub file stream
445 TAO_OutStream *client_stubs_;
447 /// Client side inline definitions.
448 TAO_OutStream *client_inline_;
450 /// Server header stream.
451 TAO_OutStream *server_header_;
453 /// Implementation header stream.
454 TAO_OutStream *implementation_header_;
456 /// Implementation skeleton stream.
457 TAO_OutStream *implementation_skeleton_;
459 /// Server header template stream.
460 TAO_OutStream *server_template_header_;
462 /// Server skeleton stream.
463 TAO_OutStream *server_skeletons_;
465 /// Server skeleton template stream.
466 TAO_OutStream *server_template_skeletons_;
468 /// Anyop header file.
469 TAO_OutStream *anyop_header_;
471 /// Anyop source file.
472 TAO_OutStream *anyop_source_;
474 /// TAO_OutStream to collect the input for gperf program.
475 TAO_OutStream *gperf_input_stream_;
477 /// Component servant header file.
478 TAO_OutStream *ciao_svnt_header_;
480 /// Component servant source file.
481 TAO_OutStream *ciao_svnt_source_;
483 /// Template component servant header file.
484 TAO_OutStream *ciao_svnt_template_header_;
486 /// Template component servant source file.
487 TAO_OutStream *ciao_svnt_template_source_;
489 /// Component executor impl header file.
490 TAO_OutStream *ciao_exec_header_;
492 /// Component executor impl source file.
493 TAO_OutStream *ciao_exec_source_;
495 /// Component executor impl source file.
496 TAO_OutStream *ciao_exec_idl_;
498 /// Component connector impl header file.
499 TAO_OutStream *ciao_conn_header_;
501 /// Component connector impl source file.
502 TAO_OutStream *ciao_conn_source_;
504 /// Component connector impl source file.
505 TAO_OutStream *ciao_ami_conn_idl_;
508 * Name of the temp file used to collect the input for gperf
509 * program. This is needed coz I do ACE_OS::open on this when I need
510 * ACE_HANDLE for the file instead FILE*.
512 char *gperf_input_filename_;
514 /// The enumerated value indicating the lookup strategy.
515 LOOKUP_STRATEGY strategy_;
518 typedef ACE_Singleton<TAO_CodeGen, ACE_SYNCH_RECURSIVE_MUTEX> TAO_CODEGEN;
519 // Singleton instance of the BE code generator.
521 extern TAO_IDL_BE_Export TAO_CodeGen *tao_cg;
522 // Code generator instance which is used everywhere.
524 #endif /* if !defined */