Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_component / context_svth.cpp
blob7ae81441c30fc11fc70c256b51299dfe2fb43ae8
2 //=============================================================================
3 /**
4 * @file context_svth.cpp
6 * Visitor generating code for a context class in the
7 * servant header.
9 * @author Jeff Parsons
11 //=============================================================================
13 #include "component.h"
15 be_visitor_context_svth::be_visitor_context_svth (be_visitor_context *ctx)
16 : be_visitor_component_scope (ctx)
20 be_visitor_context_svth::~be_visitor_context_svth ()
24 int
25 be_visitor_context_svth::visit_component (be_component *node)
27 // This visitor is spawned by be_visitor_component_svh,
28 // which already does a check for imported node, so none
29 // is needed here.
30 node_ = node;
32 AST_Decl *scope = ScopeAsDecl (node->defined_in ());
33 ACE_CString sname_str (scope->full_name ());
34 const char *sname = sname_str.c_str ();
36 // No '_cxx_' prefix.
37 const char *lname =
38 node->original_local_name ()->get_string ();
40 const char *global = (sname_str == "" ? "" : "::");
42 os_ << be_nl
43 << "class " << lname << "_Servant;"
44 << be_nl_2;
47 os_ << "template <typename CONTAINER_TYPE, typename BASE>" << be_nl;
49 os_ << "class " << lname << "_Context_T" << be_idt_nl;
50 // Spec: no multiple inheritance allowed for components.
51 AST_Component * base = node->base_component ();
52 if (base)
54 const char *lbase_name =
55 base->original_local_name ()->get_string ();
57 os_ << ": public " << global << "CIAO_" << base->flat_name ()
58 << "_Impl::" << lbase_name << "_Context_T<CONTAINER_TYPE, BASE>";
60 else
62 os_ << ": public BASE";
66 os_ << be_uidt_nl
67 << "{" << be_nl
68 << "public:" << be_idt_nl;
70 os_ << "/// Allow the servant to access our state." << be_nl
71 << "friend class " << lname << "_Servant;"
72 << be_nl_2;
74 // os_ << "/// Some useful typedefs." << be_nl
75 // << "typedef" << be_nl
76 // << "::CIAO::" << be_global->ciao_container_type ()
77 // << "_Context_Impl_T<" << be_idt << be_idt_nl
78 // << global << sname << "::CCM_"
79 // << lname << "_Context," << be_nl
80 // << "::" << node->name () << ">" << be_uidt_nl
81 // << "base_type;" << be_uidt_nl << be_nl;
83 // os_ << "typedef base_type::context_type context_type;" << be_nl
84 // << "typedef base_type::component_type component_type;"
85 // << be_nl;
87 AST_Decl::NodeType nt = this->node_->node_type ();
88 bool const is_connector = (nt == AST_Decl::NT_connector);
89 bool no_events = false;
91 if (!is_connector)
93 no_events =
94 (node->n_consumes () == 0UL
95 && node->n_emits () == 0UL
96 && node->n_publishes () == 0UL);
99 bool const de_facto = (is_connector || no_events);
101 os_ << "typedef ::CIAO::"
102 << (de_facto ? "Connector_" : "")
103 << "Servant_Impl_Base svnt_base_type;" << be_nl_2;
105 os_ << lname << "_Context_T (" << be_idt_nl
106 << "::Components::CCMHome_ptr h," << be_nl
107 << "typename CONTAINER_TYPE::_ptr_type c," << be_nl
108 << "PortableServer::Servant sv," << be_nl
109 << "const char *id);" << be_uidt << be_nl_2;
111 os_ << "virtual ~" << lname << "_Context_T ();";
113 os_ << be_nl_2
114 << "/** @name Operations and members for " << lname
115 << " receptacles and event sources,"
116 << be_nl
117 << " * defined in " << global << sname
118 << "::CCM_" << lname << "_Context." << be_nl << " */"
119 << be_nl
120 << "//@{";
122 if (this->visit_scope (node) == -1)
124 ACE_ERROR_RETURN ((LM_ERROR,
125 ACE_TEXT ("be_visitor_context_svth")
126 ACE_TEXT ("::visit_component - ")
127 ACE_TEXT ("visit_component_scope() ")
128 ACE_TEXT ("failed\n")),
129 -1);
132 os_ << be_nl
133 << "//@}"
134 << be_uidt_nl
135 << "};";
137 return 0;
141 be_visitor_context_svth::visit_connector (be_connector *node)
143 return this->visit_component (node);
147 be_visitor_context_svth::visit_uses (be_uses *node)
149 ACE_CString prefix (this->ctx_->port_prefix ());
150 prefix += node->local_name ()->get_string ();
151 const char *port_name = prefix.c_str ();
153 const char *obj_name = node->uses_type ()->full_name ();
154 bool const is_multiple = node->is_multiple ();
156 os_ << be_uidt_nl << be_nl
157 << "public:" << be_idt_nl
158 << "virtual ";
160 if (is_multiple)
162 os_ << "::" << node_->full_name () << "::"
163 << port_name << "Connections *" << be_nl
164 << "get_connections_" << port_name << " ();";
166 else
168 os_ << "::" << obj_name << "_ptr" << be_nl
169 << "get_connection_" << port_name << " ();";
172 os_ << be_nl << be_uidt_nl
173 << "protected:" << be_idt_nl
174 << "virtual "
175 << (is_multiple ? "::Components::Cookie *" : "void")
176 << be_nl
177 << "connect_" << port_name << " ("
178 << "::" << obj_name << "_ptr);"
179 << be_nl_2;
181 os_ << "virtual ::" << obj_name << "_ptr" << be_nl
182 << "disconnect_" << port_name << " (";
184 if (is_multiple)
186 os_ << "::Components::Cookie * ck);";
188 else
190 os_ << ");";
193 os_ << be_uidt_nl << be_nl
194 << "private:" << be_idt_nl;
196 if (is_multiple)
198 os_ << "/// Multiplex " << port_name << " connection." << be_nl
199 << "typedef std::map<ptrdiff_t," << be_nl
200 << " ::"
201 << obj_name << "_var>" << be_idt_nl
202 << tao_cg->upcase (port_name)
203 << "_TABLE;" << be_uidt_nl
204 << tao_cg->upcase (port_name) << "_TABLE "
205 << "ciao_uses_" << port_name << "_;" << be_nl
206 << "TAO_SYNCH_MUTEX " << port_name << "_lock_;";
208 else
210 os_ << "/// Simplex " << port_name << " connection." << be_nl
211 << "::" << obj_name << "_var" << be_nl
212 << "ciao_uses_" << port_name << "_;";
215 return 0;
219 be_visitor_context_svth::visit_publishes (be_publishes *node)
221 const char *obj_name = node->publishes_type ()->full_name ();
222 const char *port_name = node->local_name ()->get_string ();
224 os_ << be_uidt_nl << be_nl
225 << "public:" << be_idt_nl
226 << "virtual void" << be_nl
227 << "push_" << port_name << " (" << be_idt_nl
228 << "::" << obj_name << " * ev);" << be_uidt_nl;
230 os_ << be_uidt_nl
231 << "protected:" << be_idt_nl;
233 os_ << "virtual ::Components::Cookie *" << be_nl
234 << "subscribe_" << port_name << " (" << be_idt_nl
235 << "::" << obj_name << "Consumer_ptr c);" << be_uidt_nl;
237 os_ << be_nl
238 << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
239 << "unsubscribe_" << port_name << " (" << be_idt_nl
240 << "::Components::Cookie * ck);" << be_uidt;
242 os_ << be_uidt_nl << be_nl
243 << "protected:" << be_idt_nl;
245 os_ << "typedef std::map<ptrdiff_t," << be_nl
246 << " ::" << obj_name
247 << "Consumer_var>" << be_idt_nl
248 << tao_cg->upcase (port_name) << "_TABLE;" << be_uidt_nl
249 << tao_cg->upcase (port_name) << "_TABLE ciao_publishes_"
250 << port_name << "_;" << be_nl
251 << "TAO_SYNCH_MUTEX " << port_name << "_lock_;"
252 << be_nl_2;
254 return 0;
258 be_visitor_context_svth::visit_emits (be_emits *node)
260 const char *obj_name = node->emits_type ()->full_name ();
261 const char *port_name = node->local_name ()->get_string ();
263 os_ << be_uidt_nl << be_nl
264 << "public:" << be_idt_nl;
266 os_ << "virtual void" << be_nl
267 << "push_" << port_name << " (" << be_idt_nl
268 << "::" << obj_name << " * ev);" << be_uidt;
270 os_ << be_uidt_nl << be_nl
271 << "protected:" << be_idt_nl;
273 os_ << "virtual void" << be_nl
274 << "connect_" << port_name << " (" << be_idt_nl
275 << "::" << obj_name << "Consumer_ptr c);" << be_uidt;
277 os_ << be_nl_2
278 << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
279 << "disconnect_" << port_name << " ();";
281 os_ << be_uidt_nl << be_nl
282 << "protected:" << be_idt_nl
283 << "::" << obj_name << "Consumer_var" << be_nl
284 << "ciao_emits_" << port_name << "_consumer_;";
286 return 0;