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_
;
169 IMPL_NARROW_FROM_DECL (be_component
)
170 IMPL_NARROW_FROM_SCOPE (be_component
)
173 be_component::scan (UTL_Scope
*s
)
180 AST_Extended_Port
*ep
= 0;
181 AST_Mirror_Port
*mp
= 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
);
192 AST_Decl
*d
= i
.item ();
194 switch (d
->node_type ())
196 case AST_Decl::NT_provides
:
198 p
= dynamic_cast<AST_Provides
*> (d
);
200 if (!p
->provides_type ()->is_local ())
202 ++this->n_remote_provides_
;
206 case AST_Decl::NT_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_
;
221 case AST_Decl::NT_publishes
:
222 ++this->n_publishes_
;
224 case AST_Decl::NT_consumes
:
227 case AST_Decl::NT_emits
:
230 case AST_Decl::NT_ext_port
:
231 ep
= dynamic_cast<AST_Extended_Port
*> (d
);
232 this->scan (ep
->port_type ());
234 case AST_Decl::NT_mirror_port
:
235 mp
= dynamic_cast<AST_Mirror_Port
*> (d
);
236 this->mirror_scan (mp
->port_type ());
238 case AST_Decl::NT_attr
:
239 a
= dynamic_cast<AST_Attribute
*> (d
);;
243 my_nt
= this->node_type ();
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
)
255 this->has_rw_attributes_
= true;
264 AST_Component
*c
= dynamic_cast<AST_Component
*> (s
);
265 AST_Interface
*iface
= 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
]));
293 be_component::gen_stub_inheritance (TAO_OutStream
*os
)
295 this->analyze_parentage ();
297 *os
<< "public virtual ::";
299 AST_Component
*parent
= this->base_component ();
303 *os
<< parent
->name ();
307 *os
<< "Components::CCMObject";
310 long nsupports
= this->n_inherits ();
316 AST_Type
**supp_list
= this->supports ();
318 for (long i
= 0; i
< nsupports
; ++i
)
321 << "public virtual ::"
322 << supp_list
[i
]->name ();
332 be_component::gen_skel_inheritance (TAO_OutStream
*os
)
334 AST_Component
*base
= this->base_component ();
338 *os
<< "public virtual POA_" << base
->name ();
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 ())
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
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
380 << "\"IDL:omg.org/Components/CCMObject:1.0\"" << be_uidt_nl
381 << ") == 0" << be_uidt
<< be_uidt_nl
;
387 be_component::mirror_scan (AST_PortType
*pt
)
391 AST_Attribute
*a
= 0;
393 for (UTL_ScopeActiveIterator
i (pt
, UTL_Scope::IK_decls
);
397 AST_Decl
*d
= i
.item ();
399 switch (d
->node_type ())
401 case AST_Decl::NT_provides
:
403 p
= dynamic_cast<AST_Provides
*> (d
);
405 if (!p
->provides_type ()->is_local ())
407 ++this->n_remote_uses_
;
411 case AST_Decl::NT_uses
:
413 u
= dynamic_cast<AST_Uses
*> (d
);
415 if (!u
->uses_type ()->is_local ())
417 ++this->n_remote_provides_
;
421 case AST_Decl::NT_attr
:
422 a
= dynamic_cast<AST_Attribute
*> (d
);;
426 this->has_rw_attributes_
= true;