summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_argument/paramlist.cpp
blob: 2fa4e527ac71d9ba334b862ac45f6f909eef1785 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    paramlist.cpp
//
// = DESCRIPTION
//    Visitor that generates the Dyanmic::ParameterList
//
// = AUTHOR
//    Kirthika Parameswaran  <kirthika@cs.wustl.edu>
//    Ossama Othman <ossama@uci.edu>
//
// ============================================================================

ACE_RCSID (be_visitor_argument,
           paramlist,
           "$Id$")


// ************************************************************
// be_visitor_args_paramlist for parameter list in method declarations and
// definitions
// ************************************************************

be_visitor_args_paramlist::be_visitor_args_paramlist (be_visitor_context *ctx)
  : be_visitor_args (ctx)
{
}

be_visitor_args_paramlist::~be_visitor_args_paramlist (void)
{
}

int be_visitor_args_paramlist::visit_argument (be_argument *node)
{
  // Get output stream.
  TAO_OutStream *os = this->ctx_->stream ();

  // Save the argument node.
  this->ctx_->node (node);

  // We do not put "out" arguments into the arglist.
  if (this->direction () ==  AST_Argument::dir_OUT)
    {
      return 0;
    }

  // Retrieve the type.
  be_type *bt = be_type::narrow_from_decl (node->field_type ());

  // If node is typedef'd, we must strip it off.
  if (bt->node_type () == AST_Decl::NT_typedef)
    {
      be_typedef *td = be_typedef::narrow_from_decl (bt);
      bt = td->primitive_base_type ();
    }

  if (!bt)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_args_arglist::"
                         "visit_argument - "
                         "Bad argument type\n"),
                        -1);
    }

  // Generate valuetype check: this hack is needed as there is no
  // available way to check for valuetype type.
  // Any operators for valuetypes arent there so we dont add it to the
  // paramlist.
  if (bt->node_type () == AST_Decl::NT_interface)
    {
      be_valuetype *vt = be_valuetype::narrow_from_decl (node->field_type ());

      // @@ NOTE: If this check is removed, and insertion operators
      //          for valuetypes are implemented, don't forget to also
      //          remove the same valuetype check in
      //          be_visitor_operation::count_non_out_parameters().

      // If it is a valuetype just return.
      if (vt)
        {
          return 0;
        }
    }

  // Amazed by the zillion os operators below? Its just to combat
  // side effects functions like type_name() have on the os stream.
  // This was causing a problem with the stubs not been generated accurately
  // on Linux using egcs.
  if (bt->node_type () == AST_Decl::NT_array)
    {
      *os << this->type_name (bt, "_forany");
      *os << " _tao_forany_" << node->local_name () << " (";
      *os << this->type_name (bt, "_dup");
      *os << " (";
      // This is to placate some compilers which have
      // trouble with IN args that are multidimensional arrays.
      //if (node->n_dims () > 1) cant do this here since dont have a be_array node
      if (this->direction () != AST_Argument::dir_IN)
        *os << "(const ::" << bt->name () << "_slice *) ";
      *os << "this->";
      *os << node->local_name () << "_));" << be_nl;
      *os << "(*parameter_list)[len].argument <<= _tao_forany_" ;
      *os << node->local_name () << ";" << be_nl;
    }
  else
    {
      *os << "(*parameter_list)[len].argument <<= ";
      // Insertion into an Any has some special cases which need to be
      // dealt with.

      switch (bt->node_type ())
        {
        case AST_Decl::NT_pre_defined:
        case AST_Decl::NT_string:
        case AST_Decl::NT_wstring:
          if (bt->accept (this) == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "be_visitor_args_paramlist::"
                                 "visit_argument - "
                                 "cannot accept visitor\n"),
                                -1);
            }
          break;

        default:
          *os << " this->" << node->local_name () << "_;";

        }
    }

   *os << be_nl;

  // Set the appropriate mode for each parameter.
  switch (node->direction ())
    {
    case AST_Argument::dir_IN:
      *os << "(*parameter_list)[len].mode = CORBA::PARAM_IN;" << be_nl;
      break;
    case AST_Argument::dir_INOUT:
      *os << "(*parameter_list)[len].mode = CORBA::PARAM_INOUT;" << be_nl;
      break;
    case AST_Argument::dir_OUT:
      *os << "(*parameter_list)[len].mode = CORBA::PARAM_OUT;" << be_nl;
      break;
    default:
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_args_paramlist::"
                         "visit_argument - "
                         "Bad context\n"),
                        -1);
    }

  *os << "len++;" << be_nl;


  return 0;
}

int
be_visitor_args_paramlist::visit_string (be_string *node)
{
  // Get output stream.
  TAO_OutStream *os = this->ctx_->stream ();

  // Get the argument.
  be_argument *arg = this->ctx_->be_node_as_argument ();

  // We need to make a distinction between bounded and unbounded strings.
  if (node->max_size ()->ev ()->u.ulval != 0)
    {
      // Bounded strings.
      if (node->width () == (long) sizeof (char))
        {
          *os << "CORBA::Any::from_string ((char *)";
        }
      else
        {
          *os << "CORBA::Any::from_wstring ((CORBA::WChar *)";
        }

      *os << arg->local_name () << "_, "
          << node->max_size ()->ev ()->u.ulval
          << ");";
    }
  else
    {
      *os << arg->local_name () <<"_;";
    }

  return 0;
}

int
be_visitor_args_paramlist::visit_predefined_type (be_predefined_type *node)
{
  // Get output stream.
  TAO_OutStream *os = this->ctx_->stream ();

  // Get the argument.
  be_argument *arg = this->ctx_->be_node_as_argument ();

  switch (node->pt ())
    {
    case AST_PredefinedType::PT_boolean:
      *os << "CORBA::Any::from_boolean (this->";
      *os << arg->local_name () << "_);";
      break;
    case AST_PredefinedType::PT_char:
      *os << "CORBA::Any::from_char (this->";
      *os << arg->local_name () << "_);";
      break;
    case AST_PredefinedType::PT_wchar:
      *os << "CORBA::Any::from_wchar (this->";
      *os << arg->local_name () << "_);";
      break;
    case AST_PredefinedType::PT_octet:
      *os << "CORBA::Any::from_octet (this->";
      *os << arg->local_name () << "_);";
      break;
    default:
      *os << arg->local_name () << "_;";
      break;
    }

  return 0;
}