Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / TAO_IDL / be / be_component.cpp
blobab9406ecdbdb8e3f14a6cefc44093c33c3f8160c
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 void
170 be_component::scan (UTL_Scope *s)
172 if (s == nullptr)
174 return;
177 AST_Extended_Port *ep = nullptr;
178 AST_Mirror_Port *mp = nullptr;
179 AST_Uses *u = nullptr;
180 AST_Provides *p = nullptr;
181 AST_Attribute *a = nullptr;
182 AST_Decl::NodeType my_nt;
183 AST_Decl::NodeType scope_nt;
185 for (UTL_ScopeActiveIterator i (s, UTL_Scope::IK_both);
186 !i.is_done ();
187 i.next ())
189 AST_Decl *d = i.item ();
191 switch (d->node_type ())
193 case AST_Decl::NT_provides:
194 ++this->n_provides_;
195 p = dynamic_cast<AST_Provides*> (d);
197 if (!p->provides_type ()->is_local ())
199 ++this->n_remote_provides_;
202 continue;
203 case AST_Decl::NT_uses:
204 ++this->n_uses_;
205 u = dynamic_cast<AST_Uses*> (d);
207 if (u->is_multiple ())
209 this->has_uses_multiple_ = true;
212 if (!u->uses_type ()->is_local ())
214 ++this->n_remote_uses_;
217 continue;
218 case AST_Decl::NT_publishes:
219 ++this->n_publishes_;
220 continue;
221 case AST_Decl::NT_consumes:
222 ++this->n_consumes_;
223 continue;
224 case AST_Decl::NT_emits:
225 ++this->n_emits_;
226 continue;
227 case AST_Decl::NT_ext_port:
228 ep = dynamic_cast<AST_Extended_Port*> (d);
229 this->scan (ep->port_type ());
230 continue;
231 case AST_Decl::NT_mirror_port:
232 mp = dynamic_cast<AST_Mirror_Port*> (d);
233 this->mirror_scan (mp->port_type ());
234 continue;
235 case AST_Decl::NT_attr:
236 a = dynamic_cast<AST_Attribute*> (d);
238 if (!a->readonly ())
240 my_nt = this->node_type ();
241 scope_nt =
242 ScopeAsDecl (a->defined_in ())->node_type ();
244 /// Attributes coming from a porttype appear
245 /// only on connectors.
246 if (my_nt == AST_Decl::NT_component
247 && scope_nt == AST_Decl::NT_porttype)
249 continue;
252 this->has_rw_attributes_ = true;
255 continue;
256 default:
257 continue;
261 AST_Component *c = dynamic_cast<AST_Component*> (s);
262 AST_Interface *iface = nullptr;
264 if (c != nullptr)
266 for (long i = 0; i < c->n_supports (); ++i)
268 // See if the supported interfaces (if any) have attributes.
269 // If CORBA::Object is supported, DeclAsScope will evaluate
270 // to 0 and the call to scan() will return immediately.
271 this->scan (DeclAsScope (c->supports ()[i]));
274 // Check the base component. If there is none, the arg to scan()
275 // will be 0 and the call will return immediately.
276 this->scan (c->base_component ());
278 else if ((iface = dynamic_cast<AST_Interface*> (s)) != nullptr)
280 for (long i = 0; i < iface->n_inherits (); ++i)
282 // Will pick up a chain of inheritance,
283 // no need to use inherits_flat().
284 this->scan (DeclAsScope (iface->inherits ()[i]));
289 void
290 be_component::gen_stub_inheritance (TAO_OutStream *os)
292 this->analyze_parentage ();
294 *os << "public virtual ::";
296 AST_Component *parent = this->base_component ();
298 if (parent != nullptr)
300 *os << parent->name ();
302 else
304 *os << "Components::CCMObject";
307 long nsupports = this->n_inherits ();
309 if (nsupports > 0)
311 *os << be_idt;
313 AST_Type **supp_list = this->supports ();
315 for (long i = 0; i < nsupports; ++i)
317 *os << "," << be_nl
318 << "public virtual ::"
319 << supp_list[i]->name ();
322 *os << be_uidt;
325 *os << be_uidt;
328 void
329 be_component::gen_skel_inheritance (TAO_OutStream *os)
331 AST_Component *base = this->base_component ();
333 if (base != nullptr)
335 *os << "public virtual POA_" << base->name ();
337 else
339 *os << "public virtual POA_Components::CCMObject";
342 long nsupports = this->n_inherits ();
343 AST_Type **supports = this->supports ();
344 AST_Type *supported = nullptr;
346 for (long i = 0; i < nsupports; ++i)
348 supported = supports[i];
350 if (supported->is_abstract ())
352 continue;
355 *os << "," << be_nl;
356 *os << "public virtual POA_" << supported->name ();
361 be_component::gen_is_a_ancestors (TAO_OutStream *os)
363 AST_Component *ancestor = this;
365 while (ancestor != nullptr)
367 *os << "std::strcmp (value, \"" << ancestor->repoID () << "\") == 0 ||" << be_nl;
369 ancestor = ancestor->base_component ();
372 *os << "std::strcmp (value, \"IDL:omg.org/Components/CCMObject:1.0\") == 0" << be_nl;
374 return 0;
377 void
378 be_component::mirror_scan (AST_PortType *pt)
380 AST_Uses *u = nullptr;
381 AST_Provides *p = nullptr;
382 AST_Attribute *a = nullptr;
384 for (UTL_ScopeActiveIterator i (pt, UTL_Scope::IK_decls);
385 !i.is_done ();
386 i.next ())
388 AST_Decl *d = i.item ();
390 switch (d->node_type ())
392 case AST_Decl::NT_provides:
393 ++this->n_uses_;
394 p = dynamic_cast<AST_Provides*> (d);
396 if (!p->provides_type ()->is_local ())
398 ++this->n_remote_uses_;
401 continue;
402 case AST_Decl::NT_uses:
403 ++this->n_provides_;
404 u = dynamic_cast<AST_Uses*> (d);
406 if (!u->uses_type ()->is_local ())
408 ++this->n_remote_provides_;
411 continue;
412 case AST_Decl::NT_attr:
413 a = dynamic_cast<AST_Attribute*> (d);
415 if (!a->readonly ())
417 this->has_rw_attributes_ = true;
420 continue;
421 default:
422 continue;