2 //=============================================================================
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
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 (
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 ()
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
);
41 ACE_ERROR_RETURN ((LM_ERROR
,
43 "be_visitor_operation_argument_marshal"
45 "Bad argument node\n"),
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
)
58 else if (this->ctx_
->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT
)
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
)
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
)
77 case AST_Argument::dir_OUT
:
78 if (this->ctx_
->sub_state () == TAO_CodeGen::TAO_CDR_INPUT
)
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
)
95 be_visitor_operation_argument_marshal::post_process (be_decl
*bd
)
97 be_argument
*arg
= dynamic_cast<be_argument
*> (bd
);
101 ACE_ERROR_RETURN ((LM_ERROR
,
103 "be_visitor_operation_argument_marshal"
105 "Bad argument node\n"),
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
;
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
;
124 case AST_Argument::dir_OUT
:
125 // these arguments don't get printed for the << operator on the stub
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
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
;
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
;
148 ACE_ERROR_RETURN ((LM_ERROR
,
150 "be_visitor_operation_argument_marshal"
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);
185 be_visitor_args_decl::visit_array (be_array
*node
)
187 TAO_OutStream
*os
= this->ctx_
->stream ();
189 // retrieve the field node
191 dynamic_cast<be_argument
*> (this->ctx_
->node ());
195 ACE_ERROR_RETURN ((LM_ERROR
,
196 "(%N:%l) be_visitor_args_decl::"
198 "cannot retrieve argument node\n"),
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
,
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 ())
221 dynamic_cast<be_scope
*> (node
->defined_in ())->decl ();
223 ACE_OS::sprintf (fname
,
225 parent
->full_name (),
226 node
->local_name ()->get_string ());
230 ACE_OS::sprintf (fname
,
238 ACE_OS::sprintf (fname
,
243 if (f
->direction () != AST_Argument::dir_IN
)
245 *os
<< fname
<< "_forany "
246 << "_tao_argument_" << f
->local_name () << " ("
247 << be_idt
<< be_idt_nl
249 << be_uidt_nl
<< ");" << be_uidt_nl
;
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::"
270 "Bad primitive type\n"
275 this->ctx_
->alias (nullptr);