Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_operation / amh_sh.cpp
blobc877e53187dd11e6bf1ad8a8a1f38e2331d8a5c8
2 //=============================================================================
3 /**
4 * @file amh_sh.cpp
6 * Visitor generating AMH skeleton code for Operation node in the
7 * skeleton header.
9 * @author Mayur Deshpande <mayur@ics.uci.edu>
11 //=============================================================================
13 #include "operation.h"
15 be_visitor_amh_operation_sh::be_visitor_amh_operation_sh (
16 be_visitor_context *ctx)
17 : be_visitor_operation (ctx)
21 be_visitor_amh_operation_sh::~be_visitor_amh_operation_sh ()
25 int
26 be_visitor_amh_operation_sh::visit_operation (be_operation *node)
28 /// If there is an argument of type "native", return immediately.
29 if (node->has_native ())
31 return 0;
34 /// These are not for the server side.
35 if (node->is_sendc_ami ())
37 return 0;
40 // Output stream.
41 TAO_OutStream *os = this->ctx_->stream ();
42 this->ctx_->node (node);
44 this->generate_shared_prologue (node, os, "");
46 be_visitor_context ctx (*this->ctx_);
47 be_visitor_args_arglist arglist_visitor (&ctx);
48 arglist_visitor.set_fixed_direction (AST_Argument::dir_IN);
49 ctx.scope (node);
51 for (UTL_ScopeActiveIterator i (node, UTL_Scope::IK_decls);
52 !i.is_done ();
53 i.next ())
55 be_argument *argument =
56 dynamic_cast<be_argument*> (i.item ());
58 if (argument == nullptr
59 || argument->direction () == AST_Argument::dir_OUT)
61 continue;
64 *os << "," << be_nl;
66 if (arglist_visitor.visit_argument (argument) == -1)
68 ACE_ERROR_RETURN ((LM_ERROR,
69 "(%N:%l) be_visitor_amh_operation_sh::"
70 "visit_operation - "
71 "codegen for upcall args failed\n"),
72 -1);
76 *os << be_uidt_nl
77 << ") = 0;" << be_uidt_nl;
79 return 0;
82 int
83 be_visitor_amh_operation_sh::visit_attribute (be_attribute *node)
85 TAO_OutStream *os = this->ctx_->stream ();
86 this->generate_shared_prologue (node, os, "_get_");
88 *os << be_uidt_nl
89 << ") = 0;" << be_uidt_nl;
91 if (node->readonly ())
93 return 0;
96 this->generate_shared_prologue (node, os, "_set_");
98 *os << "," << be_nl;
100 be_argument the_argument (AST_Argument::dir_IN,
101 node->field_type (),
102 node->name ());
103 be_visitor_context ctx (*this->ctx_);
104 be_visitor_args_arglist visitor (&ctx);
106 int status = visitor.visit_argument (&the_argument);
108 the_argument.destroy ();
110 if (-1 == status)
112 return -1;
115 *os << be_uidt_nl << ") = 0;" << be_uidt_nl;
117 return 0;
120 void
121 be_visitor_amh_operation_sh::generate_shared_prologue (
122 be_decl *node,
123 TAO_OutStream *os,
124 const char *skel_prefix)
126 TAO_INSERT_COMMENT (os);
128 *os << "static void " << skel_prefix
129 << this->ctx_->port_prefix ().c_str ()
130 << node->local_name ()
131 << "_skel (" << be_idt << be_idt_nl
132 << "TAO_ServerRequest &_tao_req," << be_nl
133 << "TAO::Portable_Server::Servant_Upcall *_tao_obj," << be_nl
134 << "TAO_ServantBase *_tao_servant_upcall"
135 << ");" << be_uidt_nl << be_uidt_nl;
137 // We need the interface node in which this operation was defined. However,
138 // if this operation node was an attribute node in disguise, we get this
139 // information from the context
140 be_interface *intf =
141 dynamic_cast<be_interface*> (node->defined_in ());
143 if (this->ctx_->attribute () != nullptr)
145 intf = dynamic_cast<be_interface*> (
146 this->ctx_->attribute()->defined_in ()
150 if (intf == nullptr)
152 ACE_ERROR ((LM_ERROR,
153 "(%N:%l) be_visitor_amh_operation_sh::"
154 "visit_operation - "
155 "bad interface scope\n"));
156 return;
159 // Step 1 : Generate return type: always void
160 *os << "virtual void ";
162 // Step 2: Generate the method name
163 *os << node->local_name() << " (" << be_idt << be_idt_nl;
165 // STEP 3: Generate the argument list with the appropriate
166 // mapping. For these we grab a visitor that generates the
167 // parameter listing. We also generate the ResponseHandler
168 // argument 'on the fly' and add it to the argument list
170 char *buf;
171 // @@ TODO this must be kept consistent with the code in
172 // be_visitor_interface/amh_sh.cpp
173 intf->compute_full_name ("AMH_", "ResponseHandler_ptr", buf);
175 *os << buf << " _tao_rh";
176 // buf was allocated by ACE_OS::strdup, so we must use free instead
177 // of delete.
178 ACE_OS::free (buf);
179 buf = nullptr;