Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_component_scope.cpp
blobbf3f4090c9336f8565b24b3ecfb634b82aadb750
2 //=============================================================================
3 /**
4 * @file be_visitor_component_scope.cpp
6 * Abstract visitor providing ancestor scope visitation.
8 * @author Jeff Parsons
9 */
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"
18 #include "be_uses.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),
29 node_ (nullptr),
30 os_ (*ctx->stream ()),
31 export_macro_ (be_global->svnt_export_macro ()),
32 in_ext_port_ (false)
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 (
49 int
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 () += '_';
67 int status =
68 this->visit_porttype_scope (node->port_type ());
70 if (status == -1)
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")),
76 -1);
79 /// Reset port prefix string.
80 this->ctx_->port_prefix () = "";
81 this->in_ext_port_ = false;
82 return 0;
85 int
86 be_visitor_component_scope::visit_mirror_port (
87 be_mirror_port *node)
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 () += '_';
100 int status =
101 this->visit_porttype_scope_mirror (node->port_type ());
103 if (status == -1)
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")),
110 -1);
113 /// Reset port prefix string.
114 this->ctx_->port_prefix () = "";
115 return 0;
119 be_visitor_component_scope::visit_component_scope (
120 be_component *node)
122 if (node == nullptr)
124 return 0;
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")),
136 -1);
139 return this->visit_component_scope (node->base_component ());
143 be_visitor_component_scope::visit_porttype_scope (
144 be_porttype *node)
146 return this->visit_scope (node);
150 be_visitor_component_scope::visit_porttype_scope_mirror (
151 be_porttype *node)
153 for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
154 !si.is_done ();
155 si.next ())
157 be_decl *d = dynamic_cast<be_decl*> (si.item ());
159 switch (d->node_type ())
161 case AST_Decl::NT_provides:
163 be_provides *p =
164 dynamic_cast<be_provides*> (d);
166 be_uses mirror_node (p->name (),
167 p->provides_type (),
168 false);
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")),
176 -1);
179 mirror_node.destroy ();
180 break;
182 case AST_Decl::NT_uses:
184 be_uses *u =
185 dynamic_cast<be_uses*> (d);
187 be_provides mirror_node (u->name (),
188 u->uses_type ());
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")),
196 -1);
199 mirror_node.destroy ();
200 break;
202 default:
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"),
209 d->full_name ()),
210 -1);
213 break;
217 return 0;
220 void
221 be_visitor_component_scope::node (be_component *c)
223 this->node_ = c;
226 void
227 be_visitor_component_scope::gen_svnt_entrypoint_decl ()
229 os_ << be_nl_2
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
235 << "::CIAO::"
236 << be_global->ciao_container_type ()
237 << "_Container_ptr c," << be_nl
238 << "const char * ins_name);" << be_uidt;
241 void
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 == "" ? "" : "::");
250 os_ << be_nl_2
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
259 << "{" << be_idt_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
265 << "{" << 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
274 << " 0," << be_nl
275 << " c)," << be_uidt_nl
276 << " 0);" << be_nl_2
277 << "return retval;" << be_uidt_nl
278 << "}";
281 void
282 be_visitor_component_scope::gen_exec_entrypoint_decl ()
284 os_ << be_nl_2
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 ()
290 << "_Impl ();";
293 void
294 be_visitor_component_scope::gen_exec_entrypoint_defn ()
296 os_ << be_nl_2
297 << "extern \"C\" " << export_macro_.c_str ()
298 << " ::Components::EnterpriseComponent_ptr" << be_nl
299 << "create_" << node_->flat_name ()
300 << "_Impl ()" << be_nl
301 << "{" << be_idt_nl
302 << "::Components::EnterpriseComponent_ptr retval ="
303 << be_idt_nl
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
311 << "}";