2 //=============================================================================
4 * @file be_visitor_component_scope.cpp
6 * Abstract visitor providing ancestor scope visitation.
10 //=============================================================================
12 #include "be_visitor_component_scope.h"
13 #include "be_visitor_context.h"
15 #include "be_mirror_port.h"
16 #include "be_component.h"
17 #include "be_provides.h"
20 #include "be_helper.h"
21 #include "be_extern.h"
23 #include "utl_identifier.h"
24 #include "nr_extern.h"
26 be_visitor_component_scope::be_visitor_component_scope (
27 be_visitor_context
*ctx
)
28 : be_visitor_scope (ctx
),
30 os_ (*ctx
->stream ()),
31 export_macro_ (be_global
->svnt_export_macro ()),
34 /// All existing CIAO examples set the servant export values in the CIDL
35 /// compiler to equal the IDL compiler's skel export values. Below is a
36 /// partial effort to decouple them, should be completely decoupled
37 /// sometime. See comment in codegen.cpp, line 1173.
38 if (export_macro_
== "")
40 export_macro_
= be_global
->skel_export_macro ();
44 be_visitor_component_scope::~be_visitor_component_scope (
50 be_visitor_component_scope::visit_extended_port (
51 be_extended_port
*node
)
53 this->in_ext_port_
= true;
54 this->ctx_
->interface (this->node_
);
56 AST_Decl::NodeType nt
=
57 ScopeAsDecl (node
->defined_in ())->node_type ();
59 /// Skip if we are defined inside a porttype.
60 /// Depends on nested ports not being allowed.
61 if (nt
== AST_Decl::NT_component
|| nt
== AST_Decl::NT_connector
)
63 this->ctx_
->port_prefix () = node
->local_name ()->get_string ();
64 this->ctx_
->port_prefix () += '_';
68 this->visit_porttype_scope (node
->port_type ());
72 ACE_ERROR_RETURN ((LM_ERROR
,
73 ACE_TEXT ("be_visitor_component_scope")
74 ACE_TEXT ("::visit_extended_port - ")
75 ACE_TEXT ("visit_porttype_scope failed\n")),
79 /// Reset port prefix string.
80 this->ctx_
->port_prefix () = "";
81 this->in_ext_port_
= false;
86 be_visitor_component_scope::visit_mirror_port (
89 AST_Decl::NodeType nt
=
90 ScopeAsDecl (node
->defined_in ())->node_type ();
92 /// Skip if we are defined inside a porttype.
93 /// Depends on nested ports not being allowed.
94 if (nt
== AST_Decl::NT_component
|| nt
== AST_Decl::NT_connector
)
96 this->ctx_
->port_prefix () = node
->local_name ()->get_string ();
97 this->ctx_
->port_prefix () += '_';
101 this->visit_porttype_scope_mirror (node
->port_type ());
105 ACE_ERROR_RETURN ((LM_ERROR
,
106 ACE_TEXT ("be_visitor_component_scope")
107 ACE_TEXT ("::visit_mirror_port - ")
108 ACE_TEXT ("visit_porttype_scope")
109 ACE_TEXT ("_mirror failed\n")),
113 /// Reset port prefix string.
114 this->ctx_
->port_prefix () = "";
119 be_visitor_component_scope::visit_component_scope (
127 this->ctx_
->interface (node
);
129 if (this->visit_scope (node
) == -1)
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 ACE_TEXT ("be_visitor_component_scope")
133 ACE_TEXT ("::visit_component_scope - ")
134 ACE_TEXT ("visit_scope() ")
135 ACE_TEXT ("failed\n")),
139 return this->visit_component_scope (node
->base_component ());
143 be_visitor_component_scope::visit_porttype_scope (
146 return this->visit_scope (node
);
150 be_visitor_component_scope::visit_porttype_scope_mirror (
153 for (UTL_ScopeActiveIterator
si (node
, UTL_Scope::IK_decls
);
157 be_decl
*d
= dynamic_cast<be_decl
*> (si
.item ());
159 switch (d
->node_type ())
161 case AST_Decl::NT_provides
:
164 dynamic_cast<be_provides
*> (d
);
166 be_uses
mirror_node (p
->name (),
170 if (this->visit_uses (&mirror_node
) == -1)
172 ACE_ERROR_RETURN ((LM_ERROR
,
173 ACE_TEXT ("be_visitor_component_scope")
174 ACE_TEXT ("::visit_porttype_mirror - ")
175 ACE_TEXT ("visit_uses() failed\n")),
179 mirror_node
.destroy ();
182 case AST_Decl::NT_uses
:
185 dynamic_cast<be_uses
*> (d
);
187 be_provides
mirror_node (u
->name (),
190 if (this->visit_provides (&mirror_node
) == -1)
192 ACE_ERROR_RETURN ((LM_ERROR
,
193 ACE_TEXT ("be_visitor_component_scope")
194 ACE_TEXT ("::visit_porttype_mirror - ")
195 ACE_TEXT ("visit_provides() failed\n")),
199 mirror_node
.destroy ();
203 if (d
->accept (this) == -1)
205 ACE_ERROR_RETURN ((LM_ERROR
,
206 ACE_TEXT ("be_visitor_component_scope")
207 ACE_TEXT ("::visit_porttype_mirror - ")
208 ACE_TEXT ("%s->accept() failed\n"),
221 be_visitor_component_scope::node (be_component
*c
)
227 be_visitor_component_scope::gen_svnt_entrypoint_decl ()
230 << "extern \"C\" " << export_macro_
.c_str ()
231 << " ::PortableServer::Servant" << be_nl
232 << "create_" << node_
->flat_name ()
233 << "_Servant (" << be_idt_nl
234 << "::Components::EnterpriseComponent_ptr p," << be_nl
236 << be_global
->ciao_container_type ()
237 << "_Container_ptr c," << be_nl
238 << "const char * ins_name);" << be_uidt
;
242 be_visitor_component_scope::gen_svnt_entrypoint_defn ()
244 ACE_CString
sname_str (
245 ScopeAsDecl (node_
->defined_in ())->full_name ());
246 const char *sname
= sname_str
.c_str ();
247 const char *lname
= node_
->local_name ();
248 const char *global
= (sname_str
== "" ? "" : "::");
251 << "extern \"C\" " << export_macro_
.c_str ()
252 << " ::PortableServer::Servant" << be_nl
253 << "create_" << node_
->flat_name ()
254 << "_Servant (" << be_idt_nl
255 << "::Components::EnterpriseComponent_ptr p," << be_nl
256 << "::CIAO::" << be_global
->ciao_container_type ()
257 << "_Container_ptr c," << be_nl
258 << "const char * ins_name)" << be_uidt_nl
260 << global
<< sname
<< "::CCM_" << lname
261 << "_var x =" << be_idt_nl
262 << global
<< sname
<< "::CCM_" << lname
263 << "::_narrow (p);" << be_uidt_nl
<< be_nl
264 << "if (::CORBA::is_nil (x.in ()))" << be_idt_nl
266 << "return 0;" << be_uidt_nl
267 << "}" << be_uidt_nl
<< be_nl
268 << "::PortableServer::Servant retval = 0;" << be_nl
269 << "ACE_NEW_RETURN (retval," << be_nl
270 << " " << lname
<< "_Servant (" << be_idt_nl
271 << " x.in ()," << be_nl
272 << " ::Components::CCMHome::_nil ()," << be_nl
273 << " ins_name," << be_nl
275 << " c)," << be_uidt_nl
277 << "return retval;" << be_uidt_nl
282 be_visitor_component_scope::gen_exec_entrypoint_decl ()
285 << "/// Factory method and library entry point used by the middleware" << be_nl
286 << "/// @return new component instance" << be_nl
287 << "extern \"C\" " << export_macro_
.c_str ()
288 << " ::Components::EnterpriseComponent_ptr" << be_nl
289 << "create_" << node_
->flat_name ()
294 be_visitor_component_scope::gen_exec_entrypoint_defn ()
297 << "extern \"C\" " << export_macro_
.c_str ()
298 << " ::Components::EnterpriseComponent_ptr" << be_nl
299 << "create_" << node_
->flat_name ()
300 << "_Impl ()" << be_nl
302 << "::Components::EnterpriseComponent_ptr retval ="
304 << "::Components::EnterpriseComponent::_nil ();"
305 << be_uidt
<< be_nl_2
306 << "ACE_NEW_NORETURN (" << be_idt_nl
307 << "retval," << be_nl
308 << node_
->local_name () << "_exec_i);"
309 << be_uidt
<< be_nl_2
310 << "return retval;" << be_uidt_nl