Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_home / home_exs.cpp
blob634b9cb3ae0a9798acba9b98cedd887c149bc750
2 //=============================================================================
3 /**
4 * @file home_exs.cpp
6 * Visitor generating code for homes in the exec impl source.
8 * @author Jeff Parsons
9 */
10 //=============================================================================
12 #include "home.h"
14 be_visitor_home_exs::be_visitor_home_exs (be_visitor_context *ctx)
15 : be_visitor_scope (ctx),
16 node_ (nullptr),
17 comp_ (nullptr),
18 os_ (*ctx->stream ()),
19 comment_start_border_ ("/**"),
20 comment_end_border_ (" */"),
21 your_code_here_ ("/* Your code here. */"),
22 export_macro_ (be_global->exec_export_macro ())
26 be_visitor_home_exs::~be_visitor_home_exs ()
30 int
31 be_visitor_home_exs::visit_home (be_home *node)
33 if (node->imported ())
35 return 0;
38 node_ = node;
39 comp_ = node_->managed_component ();
41 /// Use 'CIAO_' + component's flat name.
42 os_ << be_nl_2
43 << "namespace CIAO_" << comp_->flat_name () << "_Impl" << be_nl
44 << "{" << be_idt;
46 if (this->gen_exec_class () == -1)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 ACE_TEXT ("be_visitor_home_exs::")
50 ACE_TEXT ("visit_home - ")
51 ACE_TEXT ("gen_servant_class() failed\n")),
52 -1);
55 this->gen_entrypoint ();
57 os_ << be_uidt_nl
58 << "}";
60 return 0;
63 int
64 be_visitor_home_exs::visit_operation (be_operation *node)
66 be_visitor_operation_exs v (this->ctx_);
67 v.scope (node_);
68 return v.visit_operation (node);
71 int
72 be_visitor_home_exs::visit_attribute (be_attribute *node)
74 be_visitor_attribute v (this->ctx_);
75 v.op_scope (node_);
76 return v.visit_attribute (node);
79 int
80 be_visitor_home_exs::visit_factory (be_factory *node)
82 AST_Decl *scope = ScopeAsDecl (comp_->defined_in ());
83 ACE_CString sname_str (scope->full_name ());
84 const char *sname = sname_str.c_str ();
85 const char *lname = comp_->local_name ()->get_string ();
86 const char *global = (sname_str == "" ? "" : "::");
88 os_ << be_nl_2
89 << "::Components::EnterpriseComponent_ptr" << be_nl
90 << node_->original_local_name ()->get_string ()
91 << "_exec_i::" << node->local_name ();
93 be_visitor_operation_arglist visitor (this->ctx_);
94 visitor.unused (true);
96 if (visitor.visit_factory (node) == -1)
98 ACE_ERROR_RETURN ((LM_ERROR,
99 ACE_TEXT ("be_visitor_home_exs::")
100 ACE_TEXT ("visit_factory - ")
101 ACE_TEXT ("codegen for arglist failed\n")),
102 -1);
105 os_ << be_nl
106 << "{" << be_idt_nl
107 << your_code_here_ << be_nl
108 << "return " << global << sname << "::CCM_"
109 << lname << "::_nil ();" << be_uidt_nl
110 << "}";
112 return 0;
116 be_visitor_home_exs::gen_exec_class ()
118 // No '_cxx_' prefix.
119 const char *lname =
120 node_->original_local_name ()->get_string ();
122 os_ << be_nl
123 << comment_start_border_ << be_nl
124 << " * Home Executor Implementation Class: "
125 << lname << "_exec_i" << be_nl
126 << comment_end_border_;
128 os_ << be_nl_2
129 << lname << "_exec_i::" << lname << "_exec_i ()" << be_nl
130 << "{" << be_nl
131 << "}";
133 os_ << be_nl_2
134 << lname << "_exec_i::~" << lname << "_exec_i ()" << be_nl
135 << "{" << be_nl
136 << "}";
138 be_home *h = node_;
140 while (h != nullptr)
142 if (this->visit_scope (h) != 0)
144 ACE_ERROR_RETURN ((LM_ERROR,
145 ACE_TEXT ("be_visitor_home_exs::")
146 ACE_TEXT ("gen_exec_class - ")
147 ACE_TEXT ("codegen for scope ")
148 ACE_TEXT ("failed\n")),
149 -1);
152 for (long i = 0; i < h->n_inherits (); ++i)
154 // A closure of all the supported interfaces is stored
155 // in the base class 'pd_inherits_flat' member.
156 be_interface *bi =
157 dynamic_cast<be_interface*> (h->inherits ()[i]);
159 bi->get_insert_queue ().reset ();
160 bi->get_del_queue ().reset ();
161 bi->get_insert_queue ().enqueue_tail (bi);
163 Home_Exec_Op_Attr_Generator op_attr_gen (this);
165 int status =
166 bi->traverse_inheritance_graph (op_attr_gen,
167 &os_,
168 false,
169 false);
171 if (status == -1)
173 ACE_ERROR_RETURN ((LM_ERROR,
174 ACE_TEXT ("be_visitor_home_exs::")
175 ACE_TEXT ("gen_exec_class - ")
176 ACE_TEXT ("traverse_inheritance_graph() ")
177 ACE_TEXT ("failed for %s\n"),
178 bi->full_name ()),
179 -1);
183 h = dynamic_cast<be_home*> (h->base_home ());
186 os_ << be_nl_2
187 << "// Implicit operations.";
189 os_ << be_nl_2
190 << "::Components::EnterpriseComponent_ptr" << be_nl
191 << lname << "_exec_i::create ()" << be_nl
192 << "{" << be_idt_nl
193 << "::Components::EnterpriseComponent_ptr retval ="
194 << be_idt_nl
195 << "::Components::EnterpriseComponent::_nil ();"
196 << be_uidt_nl << be_nl
197 << "ACE_NEW_THROW_EX (" << be_idt_nl
198 << "retval," << be_nl
199 << comp_->original_local_name ()->get_string ()
200 << "_exec_i," << be_nl
201 << "::CORBA::NO_MEMORY ());"
202 << be_uidt_nl << be_nl
203 << "return retval;" << be_uidt_nl
204 << "}";
206 return 0;
209 void
210 be_visitor_home_exs::gen_entrypoint ()
212 os_ << be_nl_2
213 << "extern \"C\" " << export_macro_.c_str ()
214 << " ::Components::HomeExecutorBase_ptr" << be_nl
215 << "create_" << node_->flat_name ()
216 << "_Impl ()" << be_nl
217 << "{" << be_idt_nl
218 << "::Components::HomeExecutorBase_ptr retval =" << be_idt_nl
219 << "::Components::HomeExecutorBase::_nil ();"
220 << be_uidt_nl << be_nl
221 << "ACE_NEW_NORETURN (" << be_idt_nl
222 << "retval," << be_nl
223 << node_->original_local_name ()->get_string ()
224 << "_exec_i);" << be_uidt_nl << be_nl
225 << "return retval;" << be_uidt_nl
226 << "}";
229 Home_Exec_Op_Attr_Generator::Home_Exec_Op_Attr_Generator (
230 be_visitor_scope * visitor)
231 : visitor_ (visitor)
236 Home_Exec_Op_Attr_Generator::emit (be_interface * /* derived_interface */,
237 TAO_OutStream * /* os */,
238 be_interface * base_interface)
240 return visitor_->visit_scope (base_interface);