summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/IFR_Service/ifr_adding_visitor_operation.cpp
blob: 1a3972ea18c24583b73db64aaa1b3f89ae8c65d1 (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
276
277
278
279
/* -*- c++ -*- */
// $Id$

#include "ast_argument.h"
#include "ast_exception.h"
#include "ast_expression.h"
#include "ast_operation.h"
#include "utl_identifier.h"
#include "utl_string.h"

#include "ifr_adding_visitor_operation.h"
#include "utl_exceptlist.h"
#include "utl_strlist.h"
#include "nr_extern.h"

ACE_RCSID (IFR_Service,
           ifr_adding_visitor_operation,
           "$Id$")

ifr_adding_visitor_operation::ifr_adding_visitor_operation (AST_Decl *scope)
  : ifr_adding_visitor (scope),
    index_ (0)
{
}

ifr_adding_visitor_operation::~ifr_adding_visitor_operation (void)
{
}

int
ifr_adding_visitor_operation::visit_operation (AST_Operation *node)
{
  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // If this operation is already in the repository (for example, if
      // we are processing the IDL file a second time inadvertently), we
      // just return 0. The IDL file must be legal, otherwise the IDL
      // compiler front end would have told us.

      CORBA::Contained_var prev_def =
        be_global->repository ()->lookup_id (node->repoID ()
                                             ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (!CORBA::is_nil (prev_def.in ()))
        {
          return 0;
        }

      // Build the parameter list. Our overridden version of visit_argument
      // will look up each parameter and add its repository entry to
      // our params_ member.

      CORBA::ULong length = static_cast<CORBA::ULong> (node->argument_count ());

      this->params_.length (length);

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

      this->index_ = 0;

      // Build the exception list.

      UTL_ExceptList *excepts = node->exceptions ();

      if (excepts != 0)
        {
          length = static_cast<CORBA::ULong> (excepts->length ());
        }
      else
        {
          length = 0;
        }

      CORBA::ExceptionDefSeq exceptions (length);
      exceptions.length (length);

      AST_Exception *ex = 0;
      CORBA::ULong i = 0;

      for (UTL_ExceptlistActiveIterator ex_iter (excepts);
           !ex_iter.is_done ();
           ex_iter.next (), ++i)
        {
          ex = ex_iter.item ();

          prev_def =
            be_global->repository ()->lookup_id (ex->repoID ()
                                                 ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;

          exceptions[i] = 
            CORBA::ExceptionDef::_narrow (prev_def.in ()
                                          ACE_ENV_ARG_PARAMETER);
          ACE_TRY_CHECK;
        }

      // Build the context list.

      UTL_StrList *ctx_list = node->context ();

      if (ctx_list != 0)
        {
          length = static_cast<CORBA::ULong> (ctx_list->length ());
        }
      else
        {
          length = 0;
        }

      CORBA::ContextIdSeq contexts (length);
      contexts.length (length);

      UTL_StrlistActiveIterator ctx_iter (ctx_list);
      UTL_String *str = 0;
      i = 0;

      while (!ctx_iter.is_done ())
        {
          str = ctx_iter.item ();

          contexts[i++] = str->get_string ();

          ctx_iter.next ();
        }

      // Get the return type.

      AST_Type *return_type = node->return_type ();

      // Updates ir_current_.
      this->get_referenced_type (return_type
                                 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Is the operation oneway?
      CORBA::OperationMode mode = node->flags () == AST_Operation::OP_oneway
                                 ? CORBA::OP_ONEWAY
                                 : CORBA::OP_NORMAL;

      // Create the repository entry.

      CORBA::Container_ptr current_scope =
        CORBA::Container::_nil ();

      if (be_global->ifr_scopes ().top (current_scope) == 0)
        {
          AST_Decl *op_scope = ScopeAsDecl (node->defined_in ());
          AST_Decl::NodeType nt = op_scope->node_type ();

          if (nt == AST_Decl::NT_interface)
            {
              CORBA::InterfaceDef_var iface =
                CORBA::InterfaceDef::_narrow (current_scope
                                              ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;

              CORBA::OperationDef_var new_def =
                iface->create_operation (node->repoID (),
                                         node->local_name ()->get_string (),
                                         node->version (),
                                         this->ir_current_.in (),
                                         mode,
                                         this->params_,
                                         exceptions,
                                         contexts
                                         ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;
            }
          else
            {
              CORBA::ValueDef_var vtype =
                CORBA::ValueDef::_narrow (current_scope
                                          ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;

              CORBA::OperationDef_var new_def =
                vtype->create_operation (node->repoID (),
                                         node->local_name ()->get_string (),
                                         node->version (),
                                         this->ir_current_.in (),
                                         mode,
                                         this->params_,
                                         exceptions,
                                         contexts
                                         ACE_ENV_ARG_PARAMETER);
              ACE_TRY_CHECK;
            }
        }
      else
        {
          ACE_ERROR_RETURN ((
              LM_ERROR,
              ACE_TEXT ("(%N:%l) ifr_adding_visitor_operation::")
              ACE_TEXT ("visit_operation -")
              ACE_TEXT (" scope stack is empty\n")
            ),
            -1
          );
        }
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (
          ACE_ANY_EXCEPTION,
          ACE_TEXT ("ifr_adding_visitor_operation::visit_operation")
        );

      return -1;
    }
  ACE_ENDTRY;

  return 0;
}

int
ifr_adding_visitor_operation::visit_argument (AST_Argument *node)
{
  // Get the parameter's name.
  this->params_[this->index_].name = node->local_name ()->get_string ();

  AST_Type *arg_type = node->field_type ();

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // Updates ir_current_.
      this->get_referenced_type (arg_type
                                 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      this->params_[this->index_].type_def =
        CORBA::IDLType::_duplicate (this->ir_current_.in ());


      switch (node->direction ())
      {
        case AST_Argument::dir_IN:
          this->params_[this->index_].mode = CORBA::PARAM_IN;
          break;
        case AST_Argument::dir_OUT:
          this->params_[this->index_].mode = CORBA::PARAM_OUT;
          break;
        case AST_Argument::dir_INOUT:
          this->params_[this->index_].mode = CORBA::PARAM_INOUT;
          break;
      }

      // IfR method create_operation does not use this - it just needs
      // to be non-zero for marshaling.
      this->params_[this->index_].type =
        CORBA::TypeCode::_duplicate (CORBA::_tc_void);

      ++this->index_;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (
          ACE_ANY_EXCEPTION,
          ACE_TEXT ("ifr_adding_visitor_operation::visit_argument")
        );

      return -1;
    }
  ACE_ENDTRY;

  return 0;
}