summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_interface/ami4ccm_rh_ex_idl.cpp
blob: 4947b6291e4350e5598ad3c34aeb7e28d5d709a1 (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

//=============================================================================
/**
 *  @file    ami4ccm_rh_ex_idl.cpp
 *
 *  Visitor generating code for AMI4CCM Interfaces in the executor IDL
 *
 *  @author Jeff Parsons
 */
//=============================================================================

#include "interface.h"

be_visitor_ami4ccm_rh_ex_idl::be_visitor_ami4ccm_rh_ex_idl (
      be_visitor_context *ctx)
  : be_visitor_scope (ctx),
    os_ (*ctx->stream ()),
    seen_in_or_inout_arg_ (false)
{
}

be_visitor_ami4ccm_rh_ex_idl::~be_visitor_ami4ccm_rh_ex_idl ()
{
}

int
be_visitor_ami4ccm_rh_ex_idl::visit_interface (be_interface *node)
{
  os_ << be_nl
      << "// TAO_IDL - Generated from" << be_nl
      << "// " << __FILE__ << ":" << __LINE__;

  os_ << be_nl_2
      << "local interface AMI4CCM_"
      << node->original_local_name ()
      << "ReplyHandler" << be_idt_nl
      << ": ";

  long n_parents = node->n_inherits ();

  if (n_parents == 0)
    {
      os_ << "::CCM_AMI::ReplyHandler";
    }
  else
    {
      os_ << be_idt;

      for (long i = 0; i < n_parents; ++i)
        {
          if (i != 0)
            {
              os_ << "," << be_nl;
            }

          AST_Type *parent = node->inherits ()[i];

          AST_Decl *d = ScopeAsDecl (parent->defined_in ());

          bool global = (d->node_type () == AST_Decl::NT_root);

          os_ << (global ? "" : "::") << d->full_name ()
              << "::AMI4CCM_" << parent->original_local_name ()
              << "ReplyHandler";
        }

      os_ << be_uidt;
    }

  os_ << be_uidt_nl
      << "{" << be_idt;

  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_ami4ccm_rh_ex_idl")
                         ACE_TEXT ("::visit_interface - ")
                         ACE_TEXT ("visit_scope() failed\n")),
                        -1);
    }

  os_ << be_uidt_nl
      << "};";

  return 0;
}

int
be_visitor_ami4ccm_rh_ex_idl::visit_operation (be_operation *node)
{
  if (node->flags () == AST_Operation::OP_oneway)
    {
      // We do nothing for oneways!
      return 0;
    }

  if (node->is_sendc_ami ())
    {
      return 0;
    }

  os_ << be_nl
      << "void " << node->original_local_name ()
      << " (" << be_idt;

  if (!node->void_return_type ())
    {
      be_type *t =
        dynamic_cast<be_type*> (node->return_type ());

      os_ << be_nl
          << "in "
          << IdentifierHelper::type_name (t, this)
          << " ami_return_val";
    }

  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_ami4ccm_rh_ex_idl")
                         ACE_TEXT ("::visit_operation - ")
                         ACE_TEXT ("visit_scope() failed\n")),
                        -1);
    }

  os_ << ");" << be_uidt;

  os_ << be_nl
      << "void " << node->original_local_name ()
      << "_excep (" << be_idt_nl
      << "in ::CCM_AMI::ExceptionHolder excep_holder);" << be_uidt;

  /// Reset for next operation traversal.
  this->seen_in_or_inout_arg_ = false;

  return 0;
}

int
be_visitor_ami4ccm_rh_ex_idl::visit_attribute (be_attribute *node)
{
  this->gen_attr_rh_ops (false, node);

  if (!node->readonly ())
    {
      this->gen_attr_rh_ops (true, node);
    }

  return 0;
}

int
be_visitor_ami4ccm_rh_ex_idl::visit_argument (be_argument *node)
{
  if (node->direction () == AST_Argument::dir_IN)
    {
      return 0;
    }

  be_type *t =
    dynamic_cast<be_type*> (node->field_type ());

  os_ << be_nl
      << "in ";

  os_ << IdentifierHelper::type_name (t, this);

  os_ << " " << node->original_local_name ();

  return 0;
}

int
be_visitor_ami4ccm_rh_ex_idl::visit_string (be_string *node)
{
  os_ << (node->width () > 1 ? "w" : "") << "string";

  ACE_CDR::ULong bound = node->max_size ()->ev ()->u.ulval;

  if (bound > 0)
    {
      os_ << "<" << bound << ">";
    }

  return 0;
}

int
be_visitor_ami4ccm_rh_ex_idl::visit_sequence (be_sequence *node)
{
  // Keep output statements separate because of side effects.
  os_ << "sequence<";
  os_ << IdentifierHelper::type_name (node->base_type (), this);

  if (!node->unbounded ())
    {
      os_ << ", " << node->max_size ()->ev ()->u.ulval;
    }

  os_ << "> ";

  return 0;
}

int
be_visitor_ami4ccm_rh_ex_idl::pre_process (be_decl *node)
{
  be_operation *op =
    dynamic_cast<be_operation*> (this->ctx_->scope ());

  if (op == nullptr)
    {
      return 0;
    }

  bool void_ret_type = op->void_return_type ();

  be_argument *arg = dynamic_cast<be_argument*> (node);

  if (arg == nullptr)
    {
      return 0;
    }

  if (arg->direction () == AST_Argument::dir_IN)
    {
      return 0;
    }

  if (!this->seen_in_or_inout_arg_)
    {
      this->seen_in_or_inout_arg_ = true;

      if (void_ret_type)
        {
          /// If we are here, we are generating the first
          /// parameter in the RH operation, so we don't
          /// want a leading comma.
          return 0;
        }
    }

  /// If we are here after all the above checks, we
  /// always want to generate a leading comma.
  os_ << ",";

  return 0;
}

void
be_visitor_ami4ccm_rh_ex_idl::gen_attr_rh_ops (bool is_set_op,
                                               be_attribute *node)
{
  os_ << be_nl
      << "void " << (is_set_op ? "set_" : "get_")
      << node->original_local_name () << " (";

  if (!is_set_op)
    {
      be_type *t =
        dynamic_cast<be_type*> (node->field_type ());

      os_ << be_idt_nl << "in ";

      os_ << IdentifierHelper::type_name (t, this);

      os_ << " " << node->original_local_name () << be_uidt;
    }

  os_ << ");"
      << be_nl
      << "void " << (is_set_op ? "set_" : "get_")
      << node->original_local_name () << "_excep (" << be_idt_nl
      << "in CCM_AMI::ExceptionHolder excep_holder);" << be_uidt;
}