2 //=============================================================================
4 * @file be_component.cpp
6 * Extension of class AST_Component that provides additional means for C++
7 * mapping of an interface.
11 //=============================================================================
13 #include "be_component.h"
14 #include "be_visitor.h"
15 #include "be_helper.h"
17 #include "ast_mirror_port.h"
19 #include "ast_provides.h"
20 #include "ast_attribute.h"
22 #include "global_extern.h"
25 be_component::be_component (UTL_ScopedName
*n
,
26 AST_Component
*base_component
,
29 AST_Interface
**supports_flat
,
33 AST_Decl (AST_Decl::NT_component
,
35 AST_Type (AST_Decl::NT_component
,
37 UTL_Scope (AST_Decl::NT_component
),
51 be_scope (AST_Decl::NT_component
),
52 be_decl (AST_Decl::NT_component
,
54 be_type (AST_Decl::NT_component
,
64 n_remote_provides_ (0UL),
67 has_uses_multiple_ (false),
72 this->size_type (AST_Type::VARIABLE
);
73 this->has_constructor (true);
76 be_component::~be_component ()
81 be_component::base_component () const
83 return dynamic_cast<be_component
*> (this->AST_Component::base_component ());
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
);
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));
110 be_component::be_add_structure (AST_Structure
*t
)
112 return this->fe_add_structure (t
);
116 be_component::be_add_typedef (AST_Typedef
*t
)
118 return this->fe_add_typedef (t
);
122 be_component::n_provides () const
124 return this->n_provides_
;
128 be_component::n_remote_provides () const
130 return this->n_remote_provides_
;
134 be_component::n_uses () const
136 return this->n_uses_
;
140 be_component::n_remote_uses () const
142 return this->n_remote_uses_
;
146 be_component::has_uses_multiple () const
148 return this->has_uses_multiple_
;
152 be_component::n_publishes () const
154 return this->n_publishes_
;
158 be_component::n_consumes () const
160 return this->n_consumes_
;
164 be_component::n_emits () const
166 return this->n_emits_
;
170 be_component::scan (UTL_Scope
*s
)
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
);
189 AST_Decl
*d
= i
.item ();
191 switch (d
->node_type ())
193 case AST_Decl::NT_provides
:
195 p
= dynamic_cast<AST_Provides
*> (d
);
197 if (!p
->provides_type ()->is_local ())
199 ++this->n_remote_provides_
;
203 case AST_Decl::NT_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_
;
218 case AST_Decl::NT_publishes
:
219 ++this->n_publishes_
;
221 case AST_Decl::NT_consumes
:
224 case AST_Decl::NT_emits
:
227 case AST_Decl::NT_ext_port
:
228 ep
= dynamic_cast<AST_Extended_Port
*> (d
);
229 this->scan (ep
->port_type ());
231 case AST_Decl::NT_mirror_port
:
232 mp
= dynamic_cast<AST_Mirror_Port
*> (d
);
233 this->mirror_scan (mp
->port_type ());
235 case AST_Decl::NT_attr
:
236 a
= dynamic_cast<AST_Attribute
*> (d
);
240 my_nt
= this->node_type ();
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
)
252 this->has_rw_attributes_
= true;
261 AST_Component
*c
= dynamic_cast<AST_Component
*> (s
);
262 AST_Interface
*iface
= 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
]));
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 ();
304 *os
<< "Components::CCMObject";
307 long nsupports
= this->n_inherits ();
313 AST_Type
**supp_list
= this->supports ();
315 for (long i
= 0; i
< nsupports
; ++i
)
318 << "public virtual ::"
319 << supp_list
[i
]->name ();
329 be_component::gen_skel_inheritance (TAO_OutStream
*os
)
331 AST_Component
*base
= this->base_component ();
335 *os
<< "public virtual POA_" << base
->name ();
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 ())
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
;
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
);
388 AST_Decl
*d
= i
.item ();
390 switch (d
->node_type ())
392 case AST_Decl::NT_provides
:
394 p
= dynamic_cast<AST_Provides
*> (d
);
396 if (!p
->provides_type ()->is_local ())
398 ++this->n_remote_uses_
;
402 case AST_Decl::NT_uses
:
404 u
= dynamic_cast<AST_Uses
*> (d
);
406 if (!u
->uses_type ()->is_local ())
408 ++this->n_remote_provides_
;
412 case AST_Decl::NT_attr
:
413 a
= dynamic_cast<AST_Attribute
*> (d
);
417 this->has_rw_attributes_
= true;