Remove redundant void from tao_idl
[ACE_TAO.git] / TAO / TAO_IDL / be / be_component.cpp
blob687191325e491a5aa92feec2967d82bcee807a96
2 //=============================================================================
3 /**
4 * @file be_component.cpp
6 * Extension of class AST_Component that provides additional means for C++
7 * mapping of an interface.
9 * @author Jeff Parsons
11 //=============================================================================
13 #include "be_component.h"
14 #include "be_visitor.h"
15 #include "be_helper.h"
17 #include "ast_mirror_port.h"
18 #include "ast_uses.h"
19 #include "ast_provides.h"
20 #include "ast_attribute.h"
22 #include "global_extern.h"
23 #include "utl_err.h"
25 be_component::be_component (UTL_ScopedName *n,
26 AST_Component *base_component,
27 AST_Type **supports,
28 long n_supports,
29 AST_Interface **supports_flat,
30 long n_supports_flat)
31 : COMMON_Base (false,
32 false),
33 AST_Decl (AST_Decl::NT_component,
34 n),
35 AST_Type (AST_Decl::NT_component,
36 n),
37 UTL_Scope (AST_Decl::NT_component),
38 AST_Interface (n,
39 supports,
40 n_supports,
41 supports_flat,
42 n_supports_flat,
43 false,
44 false),
45 AST_Component (n,
46 base_component,
47 supports,
48 n_supports,
49 supports_flat,
50 n_supports_flat),
51 be_scope (AST_Decl::NT_component),
52 be_decl (AST_Decl::NT_component,
53 n),
54 be_type (AST_Decl::NT_component,
55 n),
56 be_interface (n,
57 supports,
58 n_supports,
59 supports_flat,
60 n_supports_flat,
61 false,
62 false),
63 n_provides_ (0UL),
64 n_remote_provides_ (0UL),
65 n_uses_ (0UL),
66 n_remote_uses_ (0UL),
67 has_uses_multiple_ (false),
68 n_publishes_ (0UL),
69 n_consumes_ (0UL),
70 n_emits_ (0UL)
72 this->size_type (AST_Type::VARIABLE);
73 this->has_constructor (true);
76 be_component::~be_component ()
80 be_component *
81 be_component::base_component () const
83 return dynamic_cast<be_component*> (this->AST_Component::base_component ());
86 void
87 be_component::redefine (AST_Interface *from)
89 be_component *bc = dynamic_cast<be_component*> (from);
90 this->var_out_seq_decls_gen_ = bc->var_out_seq_decls_gen_;
91 AST_Component::redefine (from);
94 void
95 be_component::destroy ()
97 this->be_interface::destroy ();
98 this->AST_Component::destroy ();
102 be_component::accept (be_visitor *visitor)
104 return (idl_global->ignore_idl3 ()
106 : visitor->visit_component (this));
109 AST_Structure *
110 be_component::be_add_structure (AST_Structure *t)
112 return this->fe_add_structure (t);
115 AST_Typedef *
116 be_component::be_add_typedef (AST_Typedef *t)
118 return this->fe_add_typedef (t);
121 ACE_CDR::ULong
122 be_component::n_provides () const
124 return this->n_provides_;
127 ACE_CDR::ULong
128 be_component::n_remote_provides () const
130 return this->n_remote_provides_;
133 ACE_CDR::ULong
134 be_component::n_uses () const
136 return this->n_uses_;
139 ACE_CDR::ULong
140 be_component::n_remote_uses () const
142 return this->n_remote_uses_;
145 bool
146 be_component::has_uses_multiple () const
148 return this->has_uses_multiple_;
151 ACE_CDR::ULong
152 be_component::n_publishes () const
154 return this->n_publishes_;
157 ACE_CDR::ULong
158 be_component::n_consumes () const
160 return this->n_consumes_;
163 ACE_CDR::ULong
164 be_component::n_emits () const
166 return this->n_emits_;
169 IMPL_NARROW_FROM_DECL (be_component)
170 IMPL_NARROW_FROM_SCOPE (be_component)
172 void
173 be_component::scan (UTL_Scope *s)
175 if (s == 0)
177 return;
180 AST_Extended_Port *ep = 0;
181 AST_Mirror_Port *mp = 0;
182 AST_Uses *u = 0;
183 AST_Provides *p = 0;
184 AST_Attribute *a = 0;
185 AST_Decl::NodeType my_nt;
186 AST_Decl::NodeType scope_nt;
188 for (UTL_ScopeActiveIterator i (s, UTL_Scope::IK_both);
189 !i.is_done ();
190 i.next ())
192 AST_Decl *d = i.item ();
194 switch (d->node_type ())
196 case AST_Decl::NT_provides:
197 ++this->n_provides_;
198 p = dynamic_cast<AST_Provides*> (d);
200 if (!p->provides_type ()->is_local ())
202 ++this->n_remote_provides_;
205 continue;
206 case AST_Decl::NT_uses:
207 ++this->n_uses_;
208 u = dynamic_cast<AST_Uses*> (d);
210 if (u->is_multiple ())
212 this->has_uses_multiple_ = true;
215 if (!u->uses_type ()->is_local ())
217 ++this->n_remote_uses_;
220 continue;
221 case AST_Decl::NT_publishes:
222 ++this->n_publishes_;
223 continue;
224 case AST_Decl::NT_consumes:
225 ++this->n_consumes_;
226 continue;
227 case AST_Decl::NT_emits:
228 ++this->n_emits_;
229 continue;
230 case AST_Decl::NT_ext_port:
231 ep = dynamic_cast<AST_Extended_Port*> (d);
232 this->scan (ep->port_type ());
233 continue;
234 case AST_Decl::NT_mirror_port:
235 mp = dynamic_cast<AST_Mirror_Port*> (d);
236 this->mirror_scan (mp->port_type ());
237 continue;
238 case AST_Decl::NT_attr:
239 a = dynamic_cast<AST_Attribute*> (d);;
241 if (!a->readonly ())
243 my_nt = this->node_type ();
244 scope_nt =
245 ScopeAsDecl (a->defined_in ())->node_type ();
247 /// Attributes coming from a porttype appear
248 /// only on connectors.
249 if (my_nt == AST_Decl::NT_component
250 && scope_nt == AST_Decl::NT_porttype)
252 continue;
255 this->has_rw_attributes_ = true;
258 continue;
259 default:
260 continue;
264 AST_Component *c = dynamic_cast<AST_Component*> (s);
265 AST_Interface *iface = 0;
267 if (c != 0)
269 for (long i = 0; i < c->n_supports (); ++i)
271 // See if the supported interfaces (if any) have attributes.
272 // If CORBA::Object is supported, DeclAsScope will evaluate
273 // to 0 and the call to scan() will return immediately.
274 this->scan (DeclAsScope (c->supports ()[i]));
277 // Check the base component. If there is none, the arg to scan()
278 // will be 0 and the call will return immediately.
279 this->scan (c->base_component ());
281 else if ((iface = dynamic_cast<AST_Interface*> (s)) != 0)
283 for (long i = 0; i < iface->n_inherits (); ++i)
285 // Will pick up a chain of inheritance,
286 // no need to use inherits_flat().
287 this->scan (DeclAsScope (iface->inherits ()[i]));
292 void
293 be_component::gen_stub_inheritance (TAO_OutStream *os)
295 this->analyze_parentage ();
297 *os << "public virtual ::";
299 AST_Component *parent = this->base_component ();
301 if (parent != 0)
303 *os << parent->name ();
305 else
307 *os << "Components::CCMObject";
310 long nsupports = this->n_inherits ();
312 if (nsupports > 0)
314 *os << be_idt;
316 AST_Type **supp_list = this->supports ();
318 for (long i = 0; i < nsupports; ++i)
320 *os << "," << be_nl
321 << "public virtual ::"
322 << supp_list[i]->name ();
325 *os << be_uidt;
328 *os << be_uidt;
331 void
332 be_component::gen_skel_inheritance (TAO_OutStream *os)
334 AST_Component *base = this->base_component ();
336 if (base != 0)
338 *os << "public virtual POA_" << base->name ();
340 else
342 *os << "public virtual POA_Components::CCMObject";
345 long nsupports = this->n_inherits ();
346 AST_Type **supports = this->supports ();
347 AST_Type *supported = 0;
349 for (long i = 0; i < nsupports; ++i)
351 supported = supports[i];
353 if (supported->is_abstract ())
355 continue;
358 *os << "," << be_nl;
359 *os << "public virtual POA_" << supported->name ();
364 be_component::gen_is_a_ancestors (TAO_OutStream *os)
366 AST_Component *ancestor = this;
368 while (ancestor != 0)
370 *os << "ACE_OS::strcmp (" << be_idt << be_idt_nl
371 << "value," << be_nl
372 << "\"" << ancestor->repoID () << "\"" << be_uidt_nl
373 << ") == 0 ||" << be_uidt_nl;
375 ancestor = ancestor->base_component ();
378 *os << "ACE_OS::strcmp (" << be_idt << be_idt_nl
379 << "value," << be_nl
380 << "\"IDL:omg.org/Components/CCMObject:1.0\"" << be_uidt_nl
381 << ") == 0" << be_uidt << be_uidt_nl;
383 return 0;
386 void
387 be_component::mirror_scan (AST_PortType *pt)
389 AST_Uses *u = 0;
390 AST_Provides *p = 0;
391 AST_Attribute *a = 0;
393 for (UTL_ScopeActiveIterator i (pt, UTL_Scope::IK_decls);
394 !i.is_done ();
395 i.next ())
397 AST_Decl *d = i.item ();
399 switch (d->node_type ())
401 case AST_Decl::NT_provides:
402 ++this->n_uses_;
403 p = dynamic_cast<AST_Provides*> (d);
405 if (!p->provides_type ()->is_local ())
407 ++this->n_remote_uses_;
410 continue;
411 case AST_Decl::NT_uses:
412 ++this->n_provides_;
413 u = dynamic_cast<AST_Uses*> (d);
415 if (!u->uses_type ()->is_local ())
417 ++this->n_remote_provides_;
420 continue;
421 case AST_Decl::NT_attr:
422 a = dynamic_cast<AST_Attribute*> (d);;
424 if (!a->readonly ())
426 this->has_rw_attributes_ = true;
429 continue;
430 default:
431 continue;