Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_home / home_exh.cpp
blobc0953bcfbb74b2fe4509b53cc04afcb8155efdc7
2 //=============================================================================
3 /**
4 * @file home_exh.cpp
6 * Visitor generating code for homes in the exec impl header.
8 * @author Jeff Parsons
9 */
10 //=============================================================================
12 #include "home.h"
14 be_visitor_home_exh::be_visitor_home_exh (be_visitor_context *ctx)
15 : be_visitor_scope (ctx),
16 node_ (nullptr),
17 comp_ (nullptr),
18 os_ (*ctx->stream ()),
19 export_macro_ (be_global->exec_export_macro ())
23 be_visitor_home_exh::~be_visitor_home_exh ()
27 int
28 be_visitor_home_exh::visit_home (be_home *node)
30 if (node->imported ())
32 return 0;
35 node_ = node;
36 comp_ = node_->managed_component ();
38 /// Use 'CIAO_' + component's flat name.
39 os_ << be_nl_2
40 << "namespace CIAO_" << comp_->flat_name () << "_Impl" << be_nl
41 << "{" << be_idt;
43 if (this->gen_exec_class () == -1)
45 ACE_ERROR_RETURN ((LM_ERROR,
46 ACE_TEXT ("be_visitor_home_exh::")
47 ACE_TEXT ("visit_home - ")
48 ACE_TEXT ("gen_servant_class() failed\n")),
49 -1);
52 this->gen_entrypoint ();
54 os_ << be_uidt_nl
55 << "}";
57 return 0;
60 int
61 be_visitor_home_exh::visit_operation (be_operation *node)
63 be_visitor_operation_ch v (this->ctx_);
64 return v.visit_operation (node);
67 int
68 be_visitor_home_exh::visit_attribute (be_attribute *node)
70 be_visitor_attribute v (this->ctx_);
71 return v.visit_attribute (node);
74 int
75 be_visitor_home_exh::visit_factory (be_factory *node)
77 os_ << be_nl_2
78 << "/// @copydoc " << node->full_name () << be_nl
79 << "virtual ::Components::EnterpriseComponent_ptr" << be_nl
80 << node->local_name ();
82 // We can reuse this visitor.
83 be_visitor_valuetype_init_arglist_ch v (this->ctx_);
85 if (v.visit_factory (node) != 0)
87 ACE_ERROR_RETURN ((LM_ERROR,
88 ACE_TEXT ("be_visitor_home_exh::")
89 ACE_TEXT ("visit_factory - ")
90 ACE_TEXT ("codegen for argument ")
91 ACE_TEXT ("list failed\n")),
92 -1);
95 os_ << ";";
97 return 0;
101 be_visitor_home_exh::gen_exec_class ()
103 // We don't want a '_cxx_' prefix here.
104 const char *lname =
105 node_->original_local_name ()->get_string ();
107 os_ << be_nl
108 << "/**" << be_nl
109 << " * Home Executor Implementation Class: "
110 << lname << "_exec_i" << be_nl
111 << " */" << be_nl
112 << "class " << export_macro_.c_str () << " " << lname
113 << "_exec_i" << be_idt_nl
114 << ": public virtual " << lname << "_Exec," << be_idt_nl
115 << "public virtual ::CORBA::LocalObject"
116 << be_uidt << be_uidt_nl
117 << "{" << be_nl
118 << "public:" << be_idt;
120 os_ << be_nl
121 << "/// Constructor" << be_nl
122 << lname << "_exec_i ();";
124 os_ << be_nl_2
125 << "/// Destructor" << be_nl
126 << "virtual ~" << lname << "_exec_i ();";
128 be_home *h = node_;
130 while (h != nullptr)
132 if (this->visit_scope (h) != 0)
134 ACE_ERROR_RETURN ((LM_ERROR,
135 ACE_TEXT ("be_visitor_home_exh::")
136 ACE_TEXT ("gen_exec_class - ")
137 ACE_TEXT ("visit_scope() failed\n")),
138 -1);
141 for (long i = 0; i < h->n_inherits (); ++i)
143 // A closure of all the supported interfaces is stored
144 // in the base class 'pd_inherits_flat' member.
145 be_interface *bi =
146 dynamic_cast<be_interface*> (h->inherits ()[i]);
148 int status =
149 bi->traverse_inheritance_graph (
150 be_visitor_home_exh::op_attr_decl_helper,
151 &os_);
153 if (status == -1)
155 ACE_ERROR_RETURN ((LM_ERROR,
156 ACE_TEXT ("be_visitor_home_exh::")
157 ACE_TEXT ("gen_exec_class - ")
158 ACE_TEXT ("traverse_inheritance_graph() ")
159 ACE_TEXT ("failed on %s\n"),
160 bi->full_name ()),
161 -1);
165 h = dynamic_cast<be_home*> (h->base_home ());
168 os_ << be_nl_2
169 << "/// Factory method";
171 os_ << be_nl
172 << "virtual ::Components::EnterpriseComponent_ptr create ();";
174 os_ << be_uidt_nl
175 << "};";
177 return 0;
180 void
181 be_visitor_home_exh::gen_entrypoint ()
183 os_ << be_nl_2
184 << "/// Factory method for " << node_->full_name () << be_nl
185 << "extern \"C\" " << export_macro_.c_str ()
186 << " ::Components::HomeExecutorBase_ptr" << be_nl
187 << "create_" << node_->flat_name ()
188 << "_Impl ();";
192 be_visitor_home_exh::op_attr_decl_helper (be_interface * /* derived */,
193 be_interface *ancestor,
194 TAO_OutStream *os)
196 /// We're in a static method, so we have to instantiate a temporary
197 /// visitor and context.
198 be_visitor_context ctx;
199 ctx.state (TAO_CodeGen::TAO_ROOT_EXH);
200 ctx.stream (os);
201 be_visitor_home_exh visitor (&ctx);
203 /// Since this visitor overriddes only visit_operation() and
204 /// visit_attribute(), we can get away with this for the declarations.
205 return visitor.visit_scope (ancestor);