Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / TAO_IDL / be_include / be_interface.h
blob7edeb963495d9934390807a09f5bdcb396de9f00
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 (void);
55 // Methods, which access the strategy.
57 /// Return the local name.
58 const char *local_name (void);
60 /// Retrieve the fully scoped skel class name.
61 const char *full_skel_name (void);
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 (void);
72 /// retrieve the fully qualified name of the direct proxy
73 /// implementation.
74 virtual const char *full_direct_proxy_impl_name (void);
76 /// Return the client scope that encloses the interface.
77 virtual const char *client_enclosing_scope (void);
79 /// Return the "flattened" scope that encloses
80 /// the interface.
81 virtual const char *flat_client_enclosing_scope (void);
83 /// Return the server scope that encloses the interface.
84 virtual const char *server_enclosing_scope (void);
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 (void);
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 (void);
153 /// Set a new value.
154 void in_mult_inheritance (int mi);
156 /// Applies to interfaces, components, and homes.
157 bool has_rw_attributes (void) 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 (void);
165 // Visiting.
166 virtual int accept (be_visitor *visitor);
168 // Narrowing.
170 DEF_NARROW_FROM_DECL (be_interface);
171 DEF_NARROW_FROM_SCOPE (be_interface);
173 /// Helper method passed to the template method that generates code for the
174 /// is_a method.
175 static int is_a_helper (be_interface *,
176 be_interface *,
177 TAO_OutStream *os);
179 /// Helper method passed to the template method to generate code for the
180 /// operation table.
181 static int ami_handler_gen_optable_helper (be_interface *,
182 be_interface *,
183 TAO_OutStream *os);
185 /// Helper method passed to the template method to invoke ctors of all the
186 /// base classes.
187 static int copy_ctor_helper (be_interface *,
188 be_interface *,
189 TAO_OutStream *os);
191 /// Helper method to determine if the interface node is involved in some kind
192 /// of multiple inheritance or not. Required on the skeleton side.
193 static int in_mult_inheritance_helper (be_interface *,
194 be_interface *,
195 TAO_OutStream *os);
197 static int gen_def_ctors_helper (be_interface *node,
198 be_interface *base,
199 TAO_OutStream *os);
201 // Helper method to generate a call to the default
202 // constructors of all the base classes.
204 /// Helper method to initialize the obj_ member of each generated abstract
205 /// base class.
206 static int gen_abstract_init_helper (be_interface *node,
207 be_interface *base,
208 TAO_OutStream *os);
210 /// Helper method passed to traverse_inheritance_graph(),
211 /// collects supported operations and attributes.
212 static int op_attr_decl_helper (be_interface *node,
213 be_interface *base,
214 TAO_OutStream *os);
216 /// Generate the operation table including entries for inherited interfaces.
217 int gen_operation_table (const char *flat_name,
218 const char *skeleton_class_name);
220 /// generate the operation table entries.
221 int gen_optable_entries (be_interface *derived_interface,
222 const char *full_skeleton_name,
223 TAO_OutStream *os);
225 /// If we are local, regenerate non-local base class operations as
226 /// pure virtual.
227 int convert_parent_ops (be_visitor *visitor);
229 /// Overridden from class be_type.
230 virtual void gen_ostream_operator (TAO_OutStream *os,
231 bool use_underscore);
233 /// Overridden from class be_type.
234 virtual void gen_member_ostream_operator (TAO_OutStream *os,
235 const char *instance_name,
236 bool use_underscore,
237 bool accessor = false);
239 /// Sets the original interface from which this one was created,
240 /// applies only to implied IDL.
241 void original_interface (be_interface *original_interface);
243 /// Returns the original interface from which this one was created,
244 /// applies only to implied IDL
245 be_interface *original_interface (void);
247 /// Is EventConsumerBase our parent?
248 bool is_event_consumer (void);
251 * Common code for facet generation, whether we are
252 * navigating from the component port or forcing
253 * facet generation for all interfaces.
255 void gen_facet_idl (TAO_OutStream &os);
257 /// Used with ami4ccm.
258 int gen_ami4ccm_idl (TAO_OutStream *os);
260 bool is_ami_rh (void) const;
261 void is_ami_rh (bool val);
263 bool is_ami4ccm_rh (void) const;
264 void is_ami4ccm_rh (bool val);
266 /// Accessors for the member.
267 bool dds_connector_traits_done (void) const;
268 void dds_connector_traits_done (bool val);
270 /// Generate the "public virtual" entries in the stub header.
271 virtual void gen_stub_inheritance (TAO_OutStream *os);
273 /// Generate the "public virtual" entries in the skel header.
274 virtual void gen_skel_inheritance (TAO_OutStream *os);
276 /// Generate the string compares for ancestors in _is_a().
277 virtual int gen_is_a_ancestors (TAO_OutStream *os);
279 protected:
281 * CDreate a new string made by the concatenation
282 * of "str" and "suffix" and using the
283 * "separator" to concatenate the two.
285 char *create_with_prefix_suffix (const char *prefix,
286 const char *str,
287 const char *suffix,
288 const char *separator = "");
290 protected:
291 enum Suffix_Code
293 PROXY_IMPL = 0
296 enum Tag_Code
298 DIRECT = 0,
299 GC_PREFIX = 1 // Prefix used for the generated class
300 // This prefix is used to avoid name conflicts
301 // with the user classes.
304 static const char *suffix_table_[];
305 static const char *tag_table_[];
307 // Proxy Implementation names.
308 char *direct_proxy_impl_name_;
310 char *full_direct_proxy_impl_name_;
312 char *client_scope_;
313 char *flat_client_scope_;
315 char *server_scope_;
316 char *flat_server_scope_;
318 private:
319 /// Output the header (type declaration and %%) to the gperf's input
320 /// file.
321 void gen_gperf_input_header (TAO_OutStream *ss);
324 * Run GPERF and get the correct lookup and other operations
325 * depending on which strategy we are using. Returns 0 on sucess, -1
326 * on error.
328 int gen_gperf_things (const char *flat_name);
330 /// Outputs the class definition for the perfect hashing. This class
331 /// will inherit from the TAO_Perfect_Hash_OpTable.
332 void gen_perfect_hash_class_definition (const char *flat_name);
334 /// Outputs the class definition for the binary search . This class
335 /// will inherit from the TAO_Binary_Search_OpTable.
336 void gen_binary_search_class_definition (const char *flat_name);
338 /// Outputs the class definition for the linear search. This class
339 /// will inherit from the TAO_Linear_Search.
340 void gen_linear_search_class_definition (const char *flat_name);
342 /// This calls the GPERF program and gets the correct operation
343 /// lookup methods for the current OpLookup strategy.
344 int gen_gperf_lookup_methods (const char *flat_name);
346 /// Create an instance of this perfect hash table.
347 void gen_perfect_hash_instance (const char *flat_name);
349 /// Create an instance of the binary search optable.
350 void gen_binary_search_instance (const char *flat_name);
352 /// Create an instance of the linear search optable.
353 void gen_linear_search_instance (const char *flat_name);
356 * Called from traverse_inheritance_graph(), since base
357 * components and base homes are inserted before the actual
358 * traversal, it must be done tail-recursively to get the
359 * chain of parents in the correct order when generating
360 * copy constructors etc.
362 void enqueue_base_component_r (AST_Component *node);
363 void enqueue_base_home_r (AST_Home *node);
365 protected:
366 /// Have these been done already?
367 bool var_out_seq_decls_gen_;
369 protected:
370 /// Number of static skeletons in the operation table.
371 int skel_count_;
373 /// Am I directly or indirectly involved in a multiple inheritance. If the
374 /// value is -1 => not computed yet.
375 int in_mult_inheritance_;
377 /// The original interface from which this one was created,
378 /// applies only to implied IDL
379 be_interface *original_interface_;
381 /// Are we an AMH reply handler?
382 bool is_amh_rh_;
384 /// Are we an AMI reply handler?
385 bool is_ami_rh_;
387 /// Are we an AMI4CCM reply handler?
388 bool is_ami4ccm_rh_;
390 char *full_skel_name_;
392 char *full_coll_name_;
394 char *local_coll_name_;
396 char *relative_skel_name_;
398 /// Current cached collocated name.
399 int cached_type_;
401 /// Used to suppress generation of some CCM servant methods/
402 bool has_rw_attributes_;
404 /// Flag to ensure that DDS connector impl traits members
405 /// are generated only once per port interface.
406 bool dds_connector_traits_done_;
410 * @class TAO_IDL_Inheritance_Hierarcy_Worker
412 * @brief Implement the 'external form' of the iterator pattern for
413 * the interface inheritance hierarchy.
415 * Many components in the IDL compiler need to traverse the
416 * inheritance hierarchy for a particular interface, and generate code
417 * for each base class. The code to perform the traversal is
418 * encapsulated in be_interface, and this class defines the interface
419 * (in the C++ sense) that other IDL components must use to perform
420 * the work on each element on the hierarchy.
422 * This class is a relatively recent addition to the IDL compiler,
423 * originally just a pointer to function was used to customize the
424 * traversal algorithm. The class was added because we need to pass
425 * some state to some of the code emitters, thus a function is not
426 * good enough.
428 class TAO_IDL_BE_Export TAO_IDL_Inheritance_Hierarchy_Worker
430 public:
431 /// Destructor
433 * This is a no-op, simply put here to keep compilers happy.
435 virtual ~TAO_IDL_Inheritance_Hierarchy_Worker (void);
437 /// Define the method invoked during the inheritance traversal
439 * This method is invoked for each base interface in the hierarchy.
441 * @param derived_interface Pointer to the most derived interface in
442 * the hierarchy, it remains constant during the complete traversal.
444 * @param output_stream The output stream that should be used to
445 * emit code.
447 * @param base_interface Pointer to the base interface in the
448 * hierarchy, it changes on each iteration.
450 * @return 0 if there was no error, -1 if there was one.
452 virtual int emit (be_interface *derived_interface,
453 TAO_OutStream *output_stream,
454 be_interface *base_interface) = 0;
457 class be_code_emitter_wrapper
458 : public TAO_IDL_Inheritance_Hierarchy_Worker
460 public:
461 be_code_emitter_wrapper (be_interface::tao_code_emitter emitter);
463 virtual int emit (be_interface *derived_interface,
464 TAO_OutStream *output_stream,
465 be_interface *base_interface);
467 private:
468 be_interface::tao_code_emitter emitter_;
471 #endif // if !defined