summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_operation/argument_marshal.cpp
blob: 756964eacbd0448634c8afd0cc3efff37046c952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    argument_marshal.cpp
//
// = DESCRIPTION
//    Visitor to pass arguments to the CDR operators. This one helps in
//    generating the && and the , at the right place. This one is for the
//    skeleton side.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include        "idl.h"
#include        "idl_extern.h"
#include        "be.h"

#include "be_visitor_operation.h"

ACE_RCSID(be_visitor_operation, argument_marshal, "$Id$")


// ************************************************************
// operation visitor to handle the passing of arguments to the CDR operators
// ************************************************************

be_compiled_visitor_operation_argument_marshal::
be_compiled_visitor_operation_argument_marshal (be_visitor_context
                                               *ctx)
  : be_visitor_operation_argument (ctx),
    last_arg_printed_ (be_compiled_visitor_operation_argument_marshal::TAO_ARG_NONE)
{
}

be_compiled_visitor_operation_argument_marshal::
~be_compiled_visitor_operation_argument_marshal (void)
{
}

int
be_compiled_visitor_operation_argument_marshal::pre_process (be_decl *bd)
{
  TAO_OutStream *os = this->ctx_->stream ();

  be_argument *arg = be_argument::narrow_from_decl (bd);

  if (!arg)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) "
                         "be_compiled_visitor_operation_argument_marshal"
                         "::post_process - "
                         "Bad argument node\n"),
                        -1);
    }
  switch (arg->direction ())
    {
    case AST_Argument::dir_IN:
      if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_INPUT)
        {
          if (this->last_arg_printed_ !=
              be_compiled_visitor_operation_argument_marshal::TAO_ARG_NONE)
            *os << " &&\n";
        }
      else if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT)
        {
          // nothing
        }
      break;
    case AST_Argument::dir_INOUT:
      if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_INPUT)
        {
          if (this->last_arg_printed_ !=
              be_compiled_visitor_operation_argument_marshal::TAO_ARG_NONE)
            *os << " &&\n";
        }
      else if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT)
        {
          if (this->last_arg_printed_ !=
              be_compiled_visitor_operation_argument_marshal::TAO_ARG_NONE)
            *os << " &&\n";
        }
      break;
    case AST_Argument::dir_OUT:
      if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_INPUT)
        {
          // nothing
        }
      else if (this->ctx_->sub_state () == TAO_CodeGen::TAO_CDR_OUTPUT)
        {
          if (this->last_arg_printed_ !=
              be_compiled_visitor_operation_argument_marshal::TAO_ARG_NONE)
            *os << " &&\n";
        }
      break;
    }

  return 0;
}

int
be_compiled_visitor_operation_argument_marshal::post_process (be_decl *bd)
{
  be_argument *arg = be_argument::narrow_from_decl (bd);

  if (!arg)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) "
                         "be_compiled_visitor_operation_argument_marshal"
                         "::post_process - "
                         "Bad argument node\n"),
                        -1);
    }
  switch (this->ctx_->sub_state ())
    {
    case TAO_CodeGen::TAO_CDR_INPUT:
      switch (arg->direction ())
        {
        case AST_Argument::dir_IN:
          // only these arguments get printed
          this->last_arg_printed_ =
            be_compiled_visitor_operation_argument_marshal::TAO_ARG_IN;
          break;
        case AST_Argument::dir_INOUT:
          // only these arguments get printed
          this->last_arg_printed_ =
            be_compiled_visitor_operation_argument_marshal::TAO_ARG_INOUT;
          break;
        case AST_Argument::dir_OUT:
          // these arguments don't get printed for the << operator on the stub
          break;
        }
      break;
    case TAO_CodeGen::TAO_CDR_OUTPUT:
      switch (arg->direction ())
        {
        case AST_Argument::dir_IN:
          // these arguments don't get printed for the >> on the stub
          break;
        case AST_Argument::dir_INOUT:
          // only these arguments get printed
          this->last_arg_printed_ =
            be_compiled_visitor_operation_argument_marshal::TAO_ARG_INOUT;
          break;
        case AST_Argument::dir_OUT:
          // only these arguments get printed
          this->last_arg_printed_ =
            be_compiled_visitor_operation_argument_marshal::TAO_ARG_OUT;
          break;
        }
      break;
    default:
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) "
                         "be_compiled_visitor_operation_argument_marshal"
                         "::post_process - "
                         "Bad sub state\n"),
                        -1);
    }
  return 0;
}

// ****************************************************************

be_visitor_compiled_args_decl::be_visitor_compiled_args_decl (be_visitor_context *ctx)
  :  be_visitor_scope (ctx)
{
}

int
be_visitor_compiled_args_decl::visit_operation (be_operation *node)
{
  return this->visit_scope (node);
}

int
be_visitor_compiled_args_decl::visit_argument (be_argument *node)
{
  this->ctx_->node (node); // save the argument node

  // retrieve the type of the argument
  be_type *bt = be_type::narrow_from_decl (node->field_type ());

  return bt->accept (this);
}

// visit array
int
be_visitor_compiled_args_decl::visit_array (be_array *node)
{
  TAO_OutStream *os = this->ctx_->stream ();

  // retrieve the field node
  be_argument *f = this->ctx_->be_node_as_argument ();
  if (f == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_compiled_args_decl::"
                         "visit_array - "
                         "cannot retrieve argument node\n"
                         ), -1);
    }

  // for anonymous arrays, the type name has a _ prepended. We compute
  // the full_name with or without the underscore and use it later on.
  char fname [NAMEBUFSIZE];  // to hold the full and

  ACE_OS::memset (fname, '\0', NAMEBUFSIZE);
  if (!this->ctx_->alias () // not a typedef
      && node->is_child (this->ctx_->scope ()))
    {
      // for anonymous arrays ...
      // we have to generate a name for us that has an underscope
      // prepended to our local name. This needs to be inserted after
      // the parents's name

      if (node->is_nested ())
        {
          be_decl *parent =
            be_scope::narrow_from_scope (node->defined_in ())->decl ();
          ACE_OS::sprintf (fname, "%s::_%s", parent->full_name (),
                           node->local_name ()->get_string ());
        }
      else
        {
          ACE_OS::sprintf (fname, "_%s", node->full_name ());
        }
    }
  else
    {
      // typedefed node
      ACE_OS::sprintf (fname, "%s", node->full_name ());
    }

  if (f->direction () != AST_Argument::dir_IN)
    {
      *os << fname << "_forany "
          << "_tao_argument_" << f->local_name () << " ("
          << be_idt << be_idt_nl
          << f->local_name ()
          << be_uidt_nl << ");" << be_uidt_nl;
    }
  return 0;
}

// visit typedef type
int
be_visitor_compiled_args_decl::visit_typedef (be_typedef *node)
{
  this->ctx_->alias (node);

  // the node to be visited in the base primitve type that gets typedefed
  be_type *bt = node->primitive_base_type ();
  if (!bt || (bt->accept (this) == -1))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_compiled_args_decl::"
                         "visit_typedef - "
                         "Bad primitive type\n"
                         ), -1);
    }

  this->ctx_->alias (0);
  return 0;
}