Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_interface / interface_sh.cpp
blob97dbc792614c058ec5b7c1865a16561ea1518d3c
2 //=============================================================================
3 /**
4 * @file interface_sh.cpp
6 * Visitor generating code for Interfaces in the server header
8 * @author Aniruddha Gokhale
9 */
10 //=============================================================================
12 #include "interface.h"
14 be_visitor_interface_sh::be_visitor_interface_sh (be_visitor_context *ctx)
15 : be_visitor_interface (ctx)
19 be_visitor_interface_sh::~be_visitor_interface_sh ()
23 int
24 be_visitor_interface_sh::visit_interface (be_interface *node)
26 if (node->srv_hdr_gen ()
27 || node->imported ()
28 || node->is_abstract ())
30 return 0;
33 // If this node is a AMH-RH node, then generate code for it
34 if (node->is_local ())
36 if (this->is_amh_rh_node (node))
38 // Create amh_rh_visitors.
39 be_visitor_amh_rh_interface_sh amh_rh_intf (this->ctx_);
40 amh_rh_intf.visit_interface (node);
43 return 0;
46 if (this->generate_amh_classes (node) == -1)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 ACE_TEXT ("be_visitor_interface_sh::")
50 ACE_TEXT ("visit_interface - ")
51 ACE_TEXT ("codegen for AMH classes failed\n")),
52 -1);
55 TAO_OutStream *os = this->ctx_->stream ();
56 ACE_CString class_name;
58 // We shall have a POA_ prefix only if we are at the topmost level.
59 if (!node->is_nested ())
61 // We are outermost.
62 class_name += "POA_";
63 class_name += node->local_name ();
65 else
67 class_name += node->local_name ();
70 *os << be_nl_2;
72 TAO_INSERT_COMMENT (os);
74 // Generate the skeleton class name.
75 *os << be_nl_2
76 << "class " << class_name.c_str () << ";" << be_nl;
78 // Generate the _ptr declaration.
79 *os << "typedef " << class_name.c_str () << " *"
80 << class_name.c_str () << "_ptr;";
83 if (be_global->gen_direct_collocation ())
85 *os << be_nl_2
86 << "class " << node->direct_proxy_impl_name ()
87 << ";";
90 // Now generate the class definition.
91 *os << be_nl_2
92 << "class " << be_global->skel_export_macro ()
93 << " " << class_name.c_str () << be_idt_nl
94 << ": " << be_idt;
96 node->gen_skel_inheritance (os);
98 *os << be_uidt << be_uidt_nl
99 << "{" << be_nl
100 << "protected:" << be_idt_nl;
102 // Default constructor.
103 *os << class_name.c_str () << " ();"
104 << be_uidt_nl << be_nl
105 << "public:" << be_idt_nl;
107 // Some useful typedefs.
108 *os << "/// Useful for template programming." << be_nl
109 << "typedef ::" << node->name () << " _stub_type;"
110 << be_nl
111 << "typedef ::" << node->name () << "_ptr _stub_ptr_type;"
112 << be_nl
113 << "typedef ::" << node->name () << "_var _stub_var_type;"
114 << be_nl_2;
116 // Copy constructor and destructor.
117 *os << class_name.c_str () << " (const "
118 << class_name.c_str () << "& rhs) = default;" << be_nl
119 << "virtual ~" << class_name.c_str () << " () = default;" << be_nl_2;
121 // _is_a
122 *os << "virtual ::CORBA::Boolean _is_a (const char* logical_type_id);" << be_nl_2;
124 // Add the dispatch method.
125 *os << "virtual void _dispatch (" << be_idt << be_idt_nl
126 << "TAO_ServerRequest & req," << be_nl
127 << "TAO::Portable_Server::Servant_Upcall *servant_upcall);" << be_uidt
128 << be_uidt_nl << be_nl;
130 this->this_method (node);
132 // The _interface_repository_id method.
133 *os << be_nl
134 << "virtual const char* _interface_repository_id "
135 << "() const;";
137 // Generate code for elements in the scope (e.g., operations).
138 if (this->visit_scope (node) == -1)
140 ACE_ERROR_RETURN ((LM_ERROR,
141 ACE_TEXT ("be_visitor_interface_sh::")
142 ACE_TEXT ("visit_interface - ")
143 ACE_TEXT ("codegen for scope failed\n")),
144 -1);
147 *os << be_uidt_nl << "};";
149 be_visitor_context ctx (*this->ctx_);
151 // Generate the collocated class.
152 ctx = *this->ctx_;
154 if (be_global->gen_direct_collocation ())
156 ctx.state (TAO_CodeGen::TAO_INTERFACE_DIRECT_PROXY_IMPL_SH);
157 be_visitor_interface_direct_proxy_impl_sh idpi_visitor (&ctx);
159 if (node->accept (&idpi_visitor) == -1)
161 ACE_ERROR_RETURN ((LM_ERROR,
162 ACE_TEXT ("be_visitor_interface_sh::")
163 ACE_TEXT ("visit_interface - ")
164 ACE_TEXT ("codegen for direct ")
165 ACE_TEXT ("collocated class failed\n")),
166 -1);
170 return 0;
174 be_visitor_interface_sh::visit_component (be_component *node)
176 return this->visit_interface (node);
180 be_visitor_interface_sh::visit_connector (be_connector *node)
182 return this->visit_interface (node);
186 be_visitor_interface_sh::gen_abstract_ops_helper (
187 be_interface *node,
188 be_interface *base,
189 TAO_OutStream *os)
191 if (!base->is_abstract ())
193 return 0;
196 AST_Decl *d = nullptr;
197 be_visitor_context ctx;
198 ctx.stream (os);
199 ctx.state (TAO_CodeGen::TAO_ROOT_SH);
201 for (UTL_ScopeActiveIterator si (base, UTL_Scope::IK_decls);
202 !si.is_done ();
203 si.next ())
205 d = si.item ();
207 if (d == nullptr)
209 ACE_ERROR_RETURN ((LM_ERROR,
210 ACE_TEXT ("be_visitor_interface_sh::")
211 ACE_TEXT ("gen_abstract_ops_helper - ")
212 ACE_TEXT ("bad node in this scope\n")),
213 -1);
216 UTL_ScopedName item_new_name (d->local_name (),
217 nullptr);
219 if (d->node_type () == AST_Decl::NT_op)
221 be_operation *op = dynamic_cast<be_operation*> (d);
222 be_visitor_operation_sh op_visitor (&ctx);
223 op_visitor.visit_operation (op);
225 else if (d->node_type () == AST_Decl::NT_attr)
227 AST_Attribute *attr = dynamic_cast<AST_Attribute*> (d);
228 be_attribute new_attr (attr->readonly (),
229 attr->field_type (),
230 &item_new_name,
231 attr->is_local (),
232 attr->is_abstract ());
233 new_attr.set_defined_in (node);
235 UTL_ExceptList *get_exceptions = attr->get_get_exceptions ();
237 if (nullptr != get_exceptions)
239 new_attr.be_add_get_exceptions (get_exceptions->copy ());
242 UTL_ExceptList *set_exceptions = attr->get_set_exceptions ();
244 if (nullptr != set_exceptions)
246 new_attr.be_add_set_exceptions (set_exceptions->copy ());
249 be_visitor_attribute attr_visitor (&ctx);
250 attr_visitor.visit_attribute (&new_attr);
251 ctx.attribute (nullptr);
252 new_attr.destroy ();
256 return 0;
259 void
260 be_visitor_interface_sh::this_method (be_interface *node)
262 TAO_OutStream *os = this->ctx_->stream ();
264 // Print out the _this() method.
265 *os << "::" << node->full_name () << " *_this ();"
266 << be_nl;
270 be_visitor_interface_sh::generate_amh_classes (be_interface *node)
272 // We have to check for any abstract ancestor until AMH is integrated
273 // with abstract interfaces. If the node itself is abstract, this
274 // visitor would not be created.
275 if (be_global->gen_amh_classes () && !node->has_mixed_parentage ())
277 be_visitor_amh_interface_sh amh_intf (this->ctx_);
278 return amh_intf.visit_interface (node);
281 return 0;