3 //=============================================================================
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
21 #include "be_codegen.h"
22 #include "ast_interface.h"
25 class TAO_IDL_Inheritance_Hierarchy_Worker
;
27 //class be_interface_strategy;
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
39 // Used to pass functions to the template method.
40 typedef int (*tao_code_emitter
) (be_interface
*,
44 be_interface (UTL_ScopedName
*n
,
47 AST_Interface
**ih_flat
,
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
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
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
,
93 /// Compute the collocation names.
94 void compute_coll_names (int type
,
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
,
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
,
142 bool abstract_paths_only
= false,
143 bool add_ccm_object
= true);
146 * Am I in some form of multiple inheritance
151 int in_mult_inheritance ();
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 ();
166 virtual int accept (be_visitor
*visitor
);
168 /// Helper method passed to the template method that generates code for the
170 static int is_a_helper (be_interface
*,
174 /// Helper method passed to the template method to generate code for the
176 static int ami_handler_gen_optable_helper (be_interface
*,
180 /// Helper method to determine if the interface node is involved in some kind
181 /// of multiple inheritance or not. Required on the skeleton side.
182 static int in_mult_inheritance_helper (be_interface
*,
186 static int gen_def_ctors_helper (be_interface
*node
,
190 // Helper method to generate a call to the default
191 // constructors of all the base classes.
193 /// Helper method to initialize the obj_ member of each generated abstract
195 static int gen_abstract_init_helper (be_interface
*node
,
199 /// Helper method passed to traverse_inheritance_graph(),
200 /// collects supported operations and attributes.
201 static int op_attr_decl_helper (be_interface
*node
,
205 /// Generate the operation table including entries for inherited interfaces.
206 int gen_operation_table (const char *flat_name
,
207 const char *skeleton_class_name
);
209 /// generate the operation table entries.
210 int gen_optable_entries (be_interface
*derived_interface
,
211 const char *full_skeleton_name
,
214 /// If we are local, regenerate non-local base class operations as
216 int convert_parent_ops (be_visitor
*visitor
);
218 /// Overridden from class be_type.
219 virtual void gen_ostream_operator (TAO_OutStream
*os
,
220 bool use_underscore
);
222 /// Overridden from class be_type.
223 virtual void gen_member_ostream_operator (TAO_OutStream
*os
,
224 const char *instance_name
,
226 bool accessor
= false);
228 /// Sets the original interface from which this one was created,
229 /// applies only to implied IDL.
230 void original_interface (be_interface
*original_interface
);
232 /// Returns the original interface from which this one was created,
233 /// applies only to implied IDL
234 be_interface
*original_interface ();
236 /// Is EventConsumerBase our parent?
237 bool is_event_consumer ();
240 * Common code for facet generation, whether we are
241 * navigating from the component port or forcing
242 * facet generation for all interfaces.
244 void gen_facet_idl (TAO_OutStream
&os
);
246 /// Used with ami4ccm.
247 int gen_ami4ccm_idl (TAO_OutStream
*os
);
249 bool is_ami_rh () const;
250 void is_ami_rh (bool val
);
252 bool is_ami4ccm_rh () const;
253 void is_ami4ccm_rh (bool val
);
255 /// Accessors for the member.
256 bool dds_connector_traits_done () const;
257 void dds_connector_traits_done (bool val
);
259 /// Generate the "public virtual" entries in the stub header.
260 virtual void gen_stub_inheritance (TAO_OutStream
*os
);
262 /// Generate the "public virtual" entries in the skel header.
263 virtual void gen_skel_inheritance (TAO_OutStream
*os
);
265 /// Generate the string compares for ancestors in _is_a().
266 virtual int gen_is_a_ancestors (TAO_OutStream
*os
);
270 * CDreate a new string made by the concatenation
271 * of "str" and "suffix" and using the
272 * "separator" to concatenate the two.
274 char *create_with_prefix_suffix (const char *prefix
,
277 const char *separator
= "");
288 GC_PREFIX
= 1 // Prefix used for the generated class
289 // This prefix is used to avoid name conflicts
290 // with the user classes.
293 static const char *suffix_table_
[];
294 static const char *tag_table_
[];
296 // Proxy Implementation names.
297 char *direct_proxy_impl_name_
;
299 char *full_direct_proxy_impl_name_
;
302 char *flat_client_scope_
;
305 char *flat_server_scope_
;
308 /// Output the header (type declaration and %%) to the gperf's input
310 void gen_gperf_input_header (TAO_OutStream
*ss
);
313 * Run GPERF and get the correct lookup and other operations
314 * depending on which strategy we are using. Returns 0 on sucess, -1
317 int gen_gperf_things (const char *flat_name
);
319 /// Outputs the class definition for the perfect hashing. This class
320 /// will inherit from the TAO_Perfect_Hash_OpTable.
321 void gen_perfect_hash_class_definition (const char *flat_name
);
323 /// Outputs the class definition for the binary search . This class
324 /// will inherit from the TAO_Binary_Search_OpTable.
325 void gen_binary_search_class_definition (const char *flat_name
);
327 /// Outputs the class definition for the linear search. This class
328 /// will inherit from the TAO_Linear_Search.
329 void gen_linear_search_class_definition (const char *flat_name
);
331 /// This calls the GPERF program and gets the correct operation
332 /// lookup methods for the current OpLookup strategy.
333 int gen_gperf_lookup_methods (const char *flat_name
);
335 /// Create an instance of this perfect hash table.
336 void gen_perfect_hash_instance (const char *flat_name
);
338 /// Create an instance of the binary search optable.
339 void gen_binary_search_instance (const char *flat_name
);
341 /// Create an instance of the linear search optable.
342 void gen_linear_search_instance (const char *flat_name
);
345 * Called from traverse_inheritance_graph(), since base
346 * components and base homes are inserted before the actual
347 * traversal, it must be done tail-recursively to get the
348 * chain of parents in the correct order when generating
349 * copy constructors etc.
351 void enqueue_base_component_r (AST_Component
*node
);
352 void enqueue_base_home_r (AST_Home
*node
);
355 /// Have these been done already?
356 bool var_out_seq_decls_gen_
;
359 /// Number of static skeletons in the operation table.
362 /// Am I directly or indirectly involved in a multiple inheritance. If the
363 /// value is -1 => not computed yet.
364 int in_mult_inheritance_
;
366 /// The original interface from which this one was created,
367 /// applies only to implied IDL
368 be_interface
*original_interface_
;
370 /// Are we an AMH reply handler?
373 /// Are we an AMI reply handler?
376 /// Are we an AMI4CCM reply handler?
379 char *full_skel_name_
;
381 char *full_coll_name_
;
383 char *local_coll_name_
;
385 char *relative_skel_name_
;
387 /// Current cached collocated name.
390 /// Used to suppress generation of some CCM servant methods/
391 bool has_rw_attributes_
;
393 /// Flag to ensure that DDS connector impl traits members
394 /// are generated only once per port interface.
395 bool dds_connector_traits_done_
;
399 * @class TAO_IDL_Inheritance_Hierarcy_Worker
401 * @brief Implement the 'external form' of the iterator pattern for
402 * the interface inheritance hierarchy.
404 * Many components in the IDL compiler need to traverse the
405 * inheritance hierarchy for a particular interface, and generate code
406 * for each base class. The code to perform the traversal is
407 * encapsulated in be_interface, and this class defines the interface
408 * (in the C++ sense) that other IDL components must use to perform
409 * the work on each element on the hierarchy.
411 * This class is a relatively recent addition to the IDL compiler,
412 * originally just a pointer to function was used to customize the
413 * traversal algorithm. The class was added because we need to pass
414 * some state to some of the code emitters, thus a function is not
417 class TAO_IDL_BE_Export TAO_IDL_Inheritance_Hierarchy_Worker
422 * This is a no-op, simply put here to keep compilers happy.
424 virtual ~TAO_IDL_Inheritance_Hierarchy_Worker ();
426 /// Define the method invoked during the inheritance traversal
428 * This method is invoked for each base interface in the hierarchy.
430 * @param derived_interface Pointer to the most derived interface in
431 * the hierarchy, it remains constant during the complete traversal.
433 * @param output_stream The output stream that should be used to
436 * @param base_interface Pointer to the base interface in the
437 * hierarchy, it changes on each iteration.
439 * @return 0 if there was no error, -1 if there was one.
441 virtual int emit (be_interface
*derived_interface
,
442 TAO_OutStream
*output_stream
,
443 be_interface
*base_interface
) = 0;
446 class be_code_emitter_wrapper
447 : public TAO_IDL_Inheritance_Hierarchy_Worker
450 be_code_emitter_wrapper (be_interface::tao_code_emitter emitter
);
452 virtual int emit (be_interface
*derived_interface
,
453 TAO_OutStream
*output_stream
,
454 be_interface
*base_interface
);
457 be_interface::tao_code_emitter emitter_
;
460 #endif // if !defined