Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / be / be_visitor_operation / argument_marshal.cpp
blob57693c39b6f39664e1c057a839abda43980d6540
2 //=============================================================================
3 /**
4 * @file argument_marshal.cpp
6 * Visitor to pass arguments to the CDR operators. This one helps in
7 * generating the && and the , at the right place. This one is for the
8 * skeleton side.
10 * @author Aniruddha Gokhale
12 //=============================================================================
14 #include "operation.h"
16 // ************************************************************
17 // operation visitor to handle the passing of arguments to the CDR operators
18 // ************************************************************
20 be_visitor_operation_argument_marshal::be_visitor_operation_argument_marshal (
21 be_visitor_context
22 *ctx)
23 : be_visitor_operation_argument (ctx),
24 last_arg_printed_ (be_visitor_operation_argument_marshal::TAO_ARG_NONE)
28 be_visitor_operation_argument_marshal::~be_visitor_operation_argument_marshal ()
32 int
33 be_visitor_operation_argument_marshal::pre_process (be_decl *bd)
35 TAO_OutStream *os = this->ctx_->stream ();
37 be_argument *arg = dynamic_cast<be_argument*> (bd);
39 if (!arg)
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "(%N:%l) "
43 "be_visitor_operation_argument_marshal"
44 "::pre_process - "
45 "Bad argument node\n"),
46 -1);
49 switch (arg->direction ())
51 case AST_Argument::dir_IN:
52 if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_INPUT)
54 if (this->last_arg_printed_ !=
55 be_visitor_operation_argument_marshal::TAO_ARG_NONE)
56 *os << " &&";
58 else if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT)
60 // nothing
62 break;
63 case AST_Argument::dir_INOUT:
64 if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_INPUT)
66 if (this->last_arg_printed_ !=
67 be_visitor_operation_argument_marshal::TAO_ARG_NONE)
68 *os << " &&";
70 else if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT)
72 if (this->last_arg_printed_ !=
73 be_visitor_operation_argument_marshal::TAO_ARG_NONE)
74 *os << " &&";
76 break;
77 case AST_Argument::dir_OUT:
78 if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_INPUT)
80 // nothing
82 else if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT)
84 if (this->last_arg_printed_ !=
85 be_visitor_operation_argument_marshal::TAO_ARG_NONE)
86 *os << " &&";
88 break;
91 return 0;
94 int
95 be_visitor_operation_argument_marshal::post_process (be_decl *bd)
97 be_argument *arg = dynamic_cast<be_argument*> (bd);
99 if (!arg)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "(%N:%l) "
103 "be_visitor_operation_argument_marshal"
104 "::post_process - "
105 "Bad argument node\n"),
106 -1);
109 switch (this->ctx_->sub_state ())
111 case TAO_CodeGen::TAO_CDR_INPUT:
112 switch (arg->direction ())
114 case AST_Argument::dir_IN:
115 // only these arguments get printed
116 this->last_arg_printed_ =
117 be_visitor_operation_argument_marshal::TAO_ARG_IN;
118 break;
119 case AST_Argument::dir_INOUT:
120 // only these arguments get printed
121 this->last_arg_printed_ =
122 be_visitor_operation_argument_marshal::TAO_ARG_INOUT;
123 break;
124 case AST_Argument::dir_OUT:
125 // these arguments don't get printed for the << operator on the stub
126 break;
128 break;
129 case TAO_CodeGen::TAO_CDR_OUTPUT:
130 switch (arg->direction ())
132 case AST_Argument::dir_IN:
133 // these arguments don't get printed for the >> on the stub
134 break;
135 case AST_Argument::dir_INOUT:
136 // only these arguments get printed
137 this->last_arg_printed_ =
138 be_visitor_operation_argument_marshal::TAO_ARG_INOUT;
139 break;
140 case AST_Argument::dir_OUT:
141 // only these arguments get printed
142 this->last_arg_printed_ =
143 be_visitor_operation_argument_marshal::TAO_ARG_OUT;
144 break;
146 break;
147 default:
148 ACE_ERROR_RETURN ((LM_ERROR,
149 "(%N:%l) "
150 "be_visitor_operation_argument_marshal"
151 "::post_process - "
152 "Bad sub state\n"),
153 -1);
156 return 0;
159 // ****************************************************************
161 be_visitor_args_decl::be_visitor_args_decl (be_visitor_context *ctx)
162 : be_visitor_scope (ctx)
167 be_visitor_args_decl::visit_operation (be_operation *node)
169 return this->visit_scope (node);
173 be_visitor_args_decl::visit_argument (be_argument *node)
175 this->ctx_->node (node); // save the argument node
177 // retrieve the type of the argument
178 be_type *bt = dynamic_cast<be_type*> (node->field_type ());
180 return bt->accept (this);
183 // visit array
185 be_visitor_args_decl::visit_array (be_array *node)
187 TAO_OutStream *os = this->ctx_->stream ();
189 // retrieve the field node
190 be_argument *f =
191 dynamic_cast<be_argument*> (this->ctx_->node ());
193 if (f == nullptr)
195 ACE_ERROR_RETURN ((LM_ERROR,
196 "(%N:%l) be_visitor_args_decl::"
197 "visit_array - "
198 "cannot retrieve argument node\n"),
199 -1);
202 // for anonymous arrays, the type name has a _ prepended. We compute
203 // the full_name with or without the underscore and use it later on.
204 char fname [NAMEBUFSIZE]; // to hold the full and
206 ACE_OS::memset (fname,
207 '\0',
208 NAMEBUFSIZE);
210 if (!this->ctx_->alias () // not a typedef
211 && node->is_child (this->ctx_->scope ()->decl ()))
213 // For anonymous arrays ...
214 // We have to generate a name for us that has an underscope
215 // prepended to our local name. This needs to be inserted after
216 // the parents's name.
218 if (node->is_nested ())
220 be_decl *parent =
221 dynamic_cast<be_scope*> (node->defined_in ())->decl ();
223 ACE_OS::sprintf (fname,
224 "%s::_%s",
225 parent->full_name (),
226 node->local_name ()->get_string ());
228 else
230 ACE_OS::sprintf (fname,
231 "_%s",
232 node->full_name ());
235 else
237 // Typedefed node.
238 ACE_OS::sprintf (fname,
239 "%s",
240 node->full_name ());
243 if (f->direction () != AST_Argument::dir_IN)
245 *os << fname << "_forany "
246 << "_tao_argument_" << f->local_name () << " ("
247 << be_idt << be_idt_nl
248 << f->local_name ()
249 << be_uidt_nl << ");" << be_uidt_nl;
252 return 0;
255 // visit typedef type
257 be_visitor_args_decl::visit_typedef (be_typedef *node)
259 this->ctx_->alias (node);
261 // The node to be visited in the base primitve
262 // type that gets typedefed.
263 be_type *bt = node->primitive_base_type ();
265 if (!bt || (bt->accept (this) == -1))
267 ACE_ERROR_RETURN ((LM_ERROR,
268 "(%N:%l) be_visitor_args_decl::"
269 "visit_typedef - "
270 "Bad primitive type\n"
272 -1);
275 this->ctx_->alias (nullptr);
276 return 0;