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 / operation_svs.cpp
blobc2587a06fafcad40d1cf2ae79498f6eb98f0300c
2 //=============================================================================
3 /**
4 * @file operation_svs.cpp
6 * Visitor generating code for Operation in the CIAO servants file.
8 * @author Jeff Parsons
9 */
10 //=============================================================================
12 #include "operation.h"
13 #include "be_visitor_operation/operation_svs.h"
15 be_visitor_operation_svs::be_visitor_operation_svs (
16 be_visitor_context *ctx)
17 : be_visitor_scope (ctx),
18 scope_ (nullptr)
22 be_visitor_operation_svs::~be_visitor_operation_svs ()
26 int
27 be_visitor_operation_svs::visit_operation (be_operation *node)
29 this->ctx_->node (node);
31 os_ << be_nl_2;
34 if (this->ctx_->state () == TAO_CodeGen::TAO_ROOT_SVTS)
36 os_ << "template <typename BASE, typename EXEC, typename CONTEXT>"
37 << be_nl;
39 // Retrieve the operation return type.
40 be_type *bt = dynamic_cast<be_type*> (node->return_type ());
42 if (bt == nullptr)
44 ACE_ERROR_RETURN ((LM_ERROR,
45 "be_visitor_operation_svs::"
46 "visit_operation - "
47 "Bad return type\n"),
48 -1);
51 // Generate the return type mapping (same as in the header file)
52 be_visitor_context ctx = *this->ctx_;
53 be_visitor_operation_rettype rt_visitor (&ctx);
55 if (bt->accept (&rt_visitor) == -1)
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "be_visitor_operation_svs::"
59 "visit_operation - "
60 "codegen for return type failed\n"),
61 -1);
64 // Generate the operation name, avoiding possible _cxx_ prefix.
65 // USE STATE con the context!!!!!!!
66 if (this->ctx_->state () == TAO_CodeGen::TAO_ROOT_SVTS)
68 os_ << be_nl
69 << scope_->original_local_name ()->get_string ()
70 << "_Servant_T<BASE, EXEC, CONTEXT>";
72 else
74 os_ << be_nl
75 << scope_->original_local_name ()->get_string ()
76 << "_Servant";
79 os_ << "::" << node->local_name ();
81 // Generate the argument list with the appropriate mapping (same as
82 // in the header file)
83 ctx = *this->ctx_;
84 be_visitor_operation_arglist al_visitor (&ctx);
86 if (node->accept (&al_visitor) == -1)
88 ACE_ERROR_RETURN ((LM_ERROR,
89 "be_visitor_operation_svs::"
90 "visit_operation - "
91 "codegen for argument list failed\n"),
92 -1);
95 return this->gen_op_body (node);
98 int
99 be_visitor_operation_svs::gen_op_body (be_operation *node)
101 os_ << be_nl
102 << "{" << be_idt_nl;
104 ACE_CString sname_str (ScopeAsDecl (scope_->defined_in ())->full_name ());
105 const char *global = (sname_str == "" ? "" : "::");
107 if (this->ctx_->state () == TAO_CodeGen::TAO_ROOT_SVTS)
109 os_ << "typename EXEC::_var_type executor = " << be_idt_nl
110 << "EXEC::_duplicate (this->executor_.in ());" << be_uidt;
112 else
114 os_ << "::" << sname_str << global << "CCM_" << scope_->original_local_name ()
115 << "_var executor = " << be_idt_nl
116 << "::" << sname_str << global << "CCM_" << scope_->original_local_name ()
117 << "::_duplicate (this->executor_.in ());" << be_uidt;
120 os_ << be_nl_2
121 << "if (::CORBA::is_nil (executor.in ()))"
122 << be_idt_nl
123 << "{"<< be_idt_nl
124 << "throw ::CORBA::INV_OBJREF ();" << be_uidt_nl
125 << "}" << be_uidt_nl << be_nl;
127 bool const vrt = node->void_return_type ();
129 if (!vrt)
131 os_ << "return ";
134 os_ << "executor->" << node->local_name () << " (";
136 if (node->argument_count () == 0)
138 os_ << ");";
140 else
142 os_ << be_idt_nl;
144 if (this->visit_scope (node) == -1)
146 ACE_ERROR_RETURN ((LM_ERROR,
147 ACE_TEXT ("be_visitor_operation_svs")
148 ACE_TEXT ("::gen_op_body - ")
149 ACE_TEXT ("visit_scope() failed\n")),
150 -1);
154 os_ << be_uidt_nl
155 << "}";
157 return 0;
161 be_visitor_operation_svs::visit_argument (be_argument *node)
163 os_ << node->local_name ();
165 return 0;
169 be_visitor_operation_svs::post_process (be_decl *bd)
171 if (this->last_node (bd))
173 os_ << ");" << be_uidt;
175 else
177 os_ << "," << be_nl;
180 return 0;
183 void
184 be_visitor_operation_svs::scope (be_decl *node)
186 this->scope_ = node;