Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / TAO_IDL / be_include / be_interface.h
blob55b5bb397368d2fc4799918fd31035fcb2c0de03
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file be_interface.h
7 * Extension of class AST_Interface that provides additional means for C++
8 * mapping of an interface.
10 * @author Copyright 1994-1995 by Sun Microsystems
11 * @author Inc. and Aniruddha Gokhale
12 * @author Michael Kircher
14 //=============================================================================
16 #ifndef TAO_BE_INTERFACE_H
17 #define TAO_BE_INTERFACE_H
19 #include "be_scope.h"
20 #include "be_type.h"
21 #include "be_codegen.h"
22 #include "ast_interface.h"
24 class TAO_OutStream;
25 class TAO_IDL_Inheritance_Hierarchy_Worker;
26 class be_visitor;
27 //class be_interface_strategy;
29 class UTL_ExceptList;
31 /**
32 * The back end extension of the AST_Interface class
34 class be_interface : public virtual AST_Interface,
35 public virtual be_scope,
36 public virtual be_type
38 public:
39 // Used to pass functions to the template method.
40 typedef int (*tao_code_emitter) (be_interface *,
41 be_interface *,
42 TAO_OutStream *);
44 be_interface (UTL_ScopedName *n,
45 AST_Type **ih,
46 long nih,
47 AST_Interface **ih_flat,
48 long nih_flat,
49 bool local,
50 bool abstract);
52 /// Destructor.
53 ~be_interface ();
55 // Methods, which access the strategy.
57 /// Return the local name.
58 const char *local_name ();
60 /// Retrieve the fully scoped skel class name.
61 const char *full_skel_name ();
63 /// Retrieve the fully qualified collocated class name.
64 const char *full_coll_name (int);
66 /// Retrieve the fully qualified collocated class name.
67 const char *local_coll_name (int);
69 /// retrieve the name of the direct proxy implementation.
70 virtual const char *direct_proxy_impl_name ();
72 /// retrieve the fully qualified name of the direct proxy
73 /// implementation.
74 virtual const char *full_direct_proxy_impl_name ();
76 /// Return the client scope that encloses the interface.
77 virtual const char *client_enclosing_scope ();
79 /// Return the "flattened" scope that encloses
80 /// the interface.
81 virtual const char *flat_client_enclosing_scope ();
83 /// Return the server scope that encloses the interface.
84 virtual const char *server_enclosing_scope ();
86 /// Retrieve skeleton name.
87 const char *relative_skel_name (const char *skel_name);
89 /// Build up the skeleton name.
90 void compute_full_skel_name (const char *prefix,
91 char *&skel_name);
93 /// Compute the collocation names.
94 void compute_coll_names (int type,
95 const char *prefix,
96 const char *suffix);
98 static const char *relative_name (const char *localname,
99 const char *othername);
101 /// Call the default constructors of all the base classes.
102 virtual void gen_def_ctors (TAO_OutStream* os);
104 /// Generated the global hooks used for non-defined forward
105 /// declared interfaces, and the constructor from stub object.
106 virtual void gen_stub_ctor (TAO_OutStream* os);
108 /// Generate the declarations used by the template _var, _out
109 /// classes for interfaces, and by sequence template classes.
110 void gen_var_out_seq_decls ();
112 // Each interface (to fix names "T") also defines two help classes,
113 // the "collocated" class inherits from T, but delegates on the
114 // skeleton for T (usually POA_T or POA_ModuleName::T), in other
115 // words it is a Bridge from T to its implementation.
116 // The class is nested inside the skeleton class.
118 // The "stub" is a class defined on the client scope, it actually
119 // defines the stubs (all operations in T are pure virtual).
120 // @@ TODO currently the stub class is not implemented.
123 /// Iterate over the inheritance hierarchy and call the
124 /// worker->emit() method for each interface on it.
125 /// CCMObject is traversed only for components regardless
126 /// of the flag, it is there to disable this traversal for
127 /// component servant and executor code generation.
128 int traverse_inheritance_graph (
129 TAO_IDL_Inheritance_Hierarchy_Worker &worker,
130 TAO_OutStream *os,
131 bool abstract_paths_only = false,
132 bool add_ccm_object = true);
134 /// Wrap the @c gen parameter and call the generic version of
135 /// traverse_inheritance_graph().
136 /// CCMObject is traversed only for components regardless
137 /// of the flag, it is there to disable this traversal for
138 /// component servant and executor code generation.
139 int traverse_inheritance_graph (
140 tao_code_emitter gen,
141 TAO_OutStream *os,
142 bool abstract_paths_only = false,
143 bool add_ccm_object = true);
146 * Am I in some form of multiple inheritance
147 * -1 => error
148 * 0 => no
149 * 1 => yes
151 int in_mult_inheritance ();
153 /// Set a new value.
154 void in_mult_inheritance (int mi);
156 /// Applies to interfaces, components, and homes.
157 bool has_rw_attributes () const;
159 /// Pass along BE-specific member values when redefining a fwd decl.
160 virtual void redefine (AST_Interface *from);
162 /// Cleanup function.
163 virtual void destroy ();
165 // Visiting.
166 virtual int accept (be_visitor *visitor);
168 /// Helper method passed to the template method that generates code for the
169 /// is_a method.
170 static int is_a_helper (be_interface *,
171 be_interface *,
172 TAO_OutStream *os);
174 /// Helper method passed to the template method to generate code for the
175 /// operation table.
176 static int ami_handler_gen_optable_helper (be_interface *,
177 be_interface *,
178 TAO_OutStream *os);
180 /// Helper method passed to the template method to invoke ctors of all the
181 /// base classes.
182 static int copy_ctor_helper (be_interface *,
183 be_interface *,
184 TAO_OutStream *os);
186 /// Helper method to determine if the interface node is involved in some kind
187 /// of multiple inheritance or not. Required on the skeleton side.
188 static int in_mult_inheritance_helper (be_interface *,
189 be_interface *,
190 TAO_OutStream *os);
192 static int gen_def_ctors_helper (be_interface *node,
193 be_interface *base,
194 TAO_OutStream *os);
196 // Helper method to generate a call to the default
197 // constructors of all the base classes.
199 /// Helper method to initialize the obj_ member of each generated abstract
200 /// base class.
201 static int gen_abstract_init_helper (be_interface *node,
202 be_interface *base,
203 TAO_OutStream *os);
205 /// Helper method passed to traverse_inheritance_graph(),
206 /// collects supported operations and attributes.
207 static int op_attr_decl_helper (be_interface *node,
208 be_interface *base,
209 TAO_OutStream *os);
211 /// Generate the operation table including entries for inherited interfaces.
212 int gen_operation_table (const char *flat_name,
213 const char *skeleton_class_name);
215 /// generate the operation table entries.
216 int gen_optable_entries (be_interface *derived_interface,
217 const char *full_skeleton_name,
218 TAO_OutStream *os);
220 /// If we are local, regenerate non-local base class operations as
221 /// pure virtual.
222 int convert_parent_ops (be_visitor *visitor);
224 /// Overridden from class be_type.
225 virtual void gen_ostream_operator (TAO_OutStream *os,
226 bool use_underscore);
228 /// Overridden from class be_type.
229 virtual void gen_member_ostream_operator (TAO_OutStream *os,
230 const char *instance_name,
231 bool use_underscore,
232 bool accessor = false);
234 /// Sets the original interface from which this one was created,
235 /// applies only to implied IDL.
236 void original_interface (be_interface *original_interface);
238 /// Returns the original interface from which this one was created,
239 /// applies only to implied IDL
240 be_interface *original_interface ();
242 /// Is EventConsumerBase our parent?
243 bool is_event_consumer ();
246 * Common code for facet generation, whether we are
247 * navigating from the component port or forcing
248 * facet generation for all interfaces.
250 void gen_facet_idl (TAO_OutStream &os);
252 /// Used with ami4ccm.
253 int gen_ami4ccm_idl (TAO_OutStream *os);
255 bool is_ami_rh () const;
256 void is_ami_rh (bool val);
258 bool is_ami4ccm_rh () const;
259 void is_ami4ccm_rh (bool val);
261 /// Accessors for the member.
262 bool dds_connector_traits_done () const;
263 void dds_connector_traits_done (bool val);
265 /// Generate the "public virtual" entries in the stub header.
266 virtual void gen_stub_inheritance (TAO_OutStream *os);
268 /// Generate the "public virtual" entries in the skel header.
269 virtual void gen_skel_inheritance (TAO_OutStream *os);
271 /// Generate the string compares for ancestors in _is_a().
272 virtual int gen_is_a_ancestors (TAO_OutStream *os);
274 protected:
276 * CDreate a new string made by the concatenation
277 * of "str" and "suffix" and using the
278 * "separator" to concatenate the two.
280 char *create_with_prefix_suffix (const char *prefix,
281 const char *str,
282 const char *suffix,
283 const char *separator = "");
285 protected:
286 enum Suffix_Code
288 PROXY_IMPL = 0
291 enum Tag_Code
293 DIRECT = 0,
294 GC_PREFIX = 1 // Prefix used for the generated class
295 // This prefix is used to avoid name conflicts
296 // with the user classes.
299 static const char *suffix_table_[];
300 static const char *tag_table_[];
302 // Proxy Implementation names.
303 char *direct_proxy_impl_name_;
305 char *full_direct_proxy_impl_name_;
307 char *client_scope_;
308 char *flat_client_scope_;
310 char *server_scope_;
311 char *flat_server_scope_;
313 private:
314 /// Output the header (type declaration and %%) to the gperf's input
315 /// file.
316 void gen_gperf_input_header (TAO_OutStream *ss);
319 * Run GPERF and get the correct lookup and other operations
320 * depending on which strategy we are using. Returns 0 on sucess, -1
321 * on error.
323 int gen_gperf_things (const char *flat_name);
325 /// Outputs the class definition for the perfect hashing. This class
326 /// will inherit from the TAO_Perfect_Hash_OpTable.
327 void gen_perfect_hash_class_definition (const char *flat_name);
329 /// Outputs the class definition for the binary search . This class
330 /// will inherit from the TAO_Binary_Search_OpTable.
331 void gen_binary_search_class_definition (const char *flat_name);
333 /// Outputs the class definition for the linear search. This class
334 /// will inherit from the TAO_Linear_Search.
335 void gen_linear_search_class_definition (const char *flat_name);
337 /// This calls the GPERF program and gets the correct operation
338 /// lookup methods for the current OpLookup strategy.
339 int gen_gperf_lookup_methods (const char *flat_name);
341 /// Create an instance of this perfect hash table.
342 void gen_perfect_hash_instance (const char *flat_name);
344 /// Create an instance of the binary search optable.
345 void gen_binary_search_instance (const char *flat_name);
347 /// Create an instance of the linear search optable.
348 void gen_linear_search_instance (const char *flat_name);
351 * Called from traverse_inheritance_graph(), since base
352 * components and base homes are inserted before the actual
353 * traversal, it must be done tail-recursively to get the
354 * chain of parents in the correct order when generating
355 * copy constructors etc.
357 void enqueue_base_component_r (AST_Component *node);
358 void enqueue_base_home_r (AST_Home *node);
360 protected:
361 /// Have these been done already?
362 bool var_out_seq_decls_gen_;
364 protected:
365 /// Number of static skeletons in the operation table.
366 int skel_count_;
368 /// Am I directly or indirectly involved in a multiple inheritance. If the
369 /// value is -1 => not computed yet.
370 int in_mult_inheritance_;
372 /// The original interface from which this one was created,
373 /// applies only to implied IDL
374 be_interface *original_interface_;
376 /// Are we an AMH reply handler?
377 bool is_amh_rh_;
379 /// Are we an AMI reply handler?
380 bool is_ami_rh_;
382 /// Are we an AMI4CCM reply handler?
383 bool is_ami4ccm_rh_;
385 char *full_skel_name_;
387 char *full_coll_name_;
389 char *local_coll_name_;
391 char *relative_skel_name_;
393 /// Current cached collocated name.
394 int cached_type_;
396 /// Used to suppress generation of some CCM servant methods/
397 bool has_rw_attributes_;
399 /// Flag to ensure that DDS connector impl traits members
400 /// are generated only once per port interface.
401 bool dds_connector_traits_done_;
405 * @class TAO_IDL_Inheritance_Hierarcy_Worker
407 * @brief Implement the 'external form' of the iterator pattern for
408 * the interface inheritance hierarchy.
410 * Many components in the IDL compiler need to traverse the
411 * inheritance hierarchy for a particular interface, and generate code
412 * for each base class. The code to perform the traversal is
413 * encapsulated in be_interface, and this class defines the interface
414 * (in the C++ sense) that other IDL components must use to perform
415 * the work on each element on the hierarchy.
417 * This class is a relatively recent addition to the IDL compiler,
418 * originally just a pointer to function was used to customize the
419 * traversal algorithm. The class was added because we need to pass
420 * some state to some of the code emitters, thus a function is not
421 * good enough.
423 class TAO_IDL_BE_Export TAO_IDL_Inheritance_Hierarchy_Worker
425 public:
426 /// Destructor
428 * This is a no-op, simply put here to keep compilers happy.
430 virtual ~TAO_IDL_Inheritance_Hierarchy_Worker ();
432 /// Define the method invoked during the inheritance traversal
434 * This method is invoked for each base interface in the hierarchy.
436 * @param derived_interface Pointer to the most derived interface in
437 * the hierarchy, it remains constant during the complete traversal.
439 * @param output_stream The output stream that should be used to
440 * emit code.
442 * @param base_interface Pointer to the base interface in the
443 * hierarchy, it changes on each iteration.
445 * @return 0 if there was no error, -1 if there was one.
447 virtual int emit (be_interface *derived_interface,
448 TAO_OutStream *output_stream,
449 be_interface *base_interface) = 0;
452 class be_code_emitter_wrapper
453 : public TAO_IDL_Inheritance_Hierarchy_Worker
455 public:
456 be_code_emitter_wrapper (be_interface::tao_code_emitter emitter);
458 virtual int emit (be_interface *derived_interface,
459 TAO_OutStream *output_stream,
460 be_interface *base_interface);
462 private:
463 be_interface::tao_code_emitter emitter_;
466 #endif // if !defined