summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_exception/exception_cs.cpp
blob: 83a07eaf1ef55b976de949cba23b3a3b80f2df77 (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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    exception_cs.cpp
//
// = DESCRIPTION
//    Visitor generating code for Exception in the stubs file
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include "be_visitor_typecode/typecode_defn.h"

ACE_RCSID (be_visitor_exception,
           exception_cs,
           "$Id$")

// ***************************************************************************
// For client stubs.
// ***************************************************************************

be_visitor_exception_cs::be_visitor_exception_cs (be_visitor_context *ctx)
  : be_visitor_exception (ctx)
{
}

be_visitor_exception_cs::~be_visitor_exception_cs (void)
{
}

// Visit the Exception_Cs node and its scope.
int be_visitor_exception_cs::visit_exception (be_exception *node)
{
  if (node->cli_stub_gen () || node->imported ())
    {
      return 0;
    }

  TAO_OutStream *os = this->ctx_->stream ();

  os->indent ();

  // Generate stub code  required of any anonymous types of members.
  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_exception::"
                         "visit_exception -"
                         "code for stub failed\n"),
                        -1);
    }

  *os << be_nl << be_nl << "// TAO_IDL - Generated from " << be_nl
      << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;

  // Default constructor.
  *os << node->name () << "::" << node->local_name ()
      << " (void)" << be_idt_nl;
  *os << ": CORBA::UserException (" << be_idt << be_idt << be_idt_nl
      << "\"" << node->repoID () << "\"," << be_nl
      << "\"" << node->local_name () << "\"" << be_uidt_nl
      << ")" << be_uidt << be_uidt << be_uidt_nl;
  *os << "{" << be_nl;
  *os << "}" << be_nl << be_nl;

  // Destructor.
  *os << node->name () << "::~" << node->local_name ()
      << " (void)" << be_nl;
  *os << "{" << be_nl;
  *os << "}" << be_nl << be_nl;

  // Copy constructor.
  *os << node->name () << "::" << node->local_name () << " (const ::"
      << node->name () << " &_tao_excp)" << be_idt_nl;
  *os << ": CORBA::UserException (" << be_idt << be_idt << be_idt_nl
      << "_tao_excp._rep_id ()," << be_nl
      << "_tao_excp._name ()" << be_uidt_nl
      << ")" << be_uidt << be_uidt << be_uidt_nl;
  *os << "{";

  be_visitor_context ctx (*this->ctx_);

  if (node->nmembers () > 0)
    {
      *os << be_idt;

      // Assign each individual member.
      be_visitor_exception_ctor_assign visitor (&ctx);

      if (node->accept (&visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_exception_cs::"
                             "visit_exception -"
                             "codegen for scope failed\n"),
                            -1);
        }
    }

  *os << be_uidt_nl
      << "}" << be_nl << be_nl;

  // Assignment operator.
  *os << node->name () << "&" << be_nl;
  *os << node->name () << "::operator= (const ::"
      << node->name () << " &_tao_excp)" << be_nl
      << "{" << be_idt_nl
      << "this->ACE_NESTED_CLASS (CORBA, UserException)::operator= "
      << "(_tao_excp);";

  // Assign each individual member.
  ctx = *this->ctx_;
  be_visitor_exception_ctor_assign visitor (&ctx);

  if (node->accept (&visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_exception_cs::"
                         "visit_exception -"
                         "codegen for scope failed\n"),
                        -1);
    }

  *os << be_nl
      << "return *this;" << be_uidt_nl
      << "}" << be_nl << be_nl;

  if (be_global->any_support ())
    {
      *os << "void "
          << node->name ()
          << "::_tao_any_destructor (void *_tao_void_pointer)" << be_nl
          << "{" << be_idt_nl
          << node->local_name () << " *_tao_tmp_pointer =" << be_idt_nl
          << "static_cast<"
          << node->local_name () << "*> (_tao_void_pointer);" << be_uidt_nl
          << "delete _tao_tmp_pointer;" << be_uidt_nl
          << "}" << be_nl << be_nl;
    }

  *os << node->name () << " *" << be_nl;
  *os << node->name () << "::_downcast (CORBA::Exception *_tao_excp)" << be_nl;
  *os << "{" << be_idt_nl;
  *os << "if (!ACE_OS::strcmp (\"" << node->repoID ()
      << "\", _tao_excp->_rep_id ()))" << be_idt_nl;
  *os << "{" << be_idt_nl;
  *os << "return dynamic_cast<" << node->local_name ()
      << " *> (_tao_excp);" << be_uidt_nl;
  *os << "}" << be_uidt_nl;
  *os << "else" << be_idt_nl;
  *os << "{" << be_idt_nl;
  *os << "return 0;" << be_uidt_nl;
  *os << "}" << be_uidt << be_uidt_nl;
  *os << "}" << be_nl << be_nl;

  // Generate the _alloc method.
  *os << "CORBA::Exception *" << node->name ()
      << "::_alloc (void)" << be_nl;
  *os << "{" << be_idt_nl;
  *os << "CORBA::Exception *retval = 0;" << be_nl
      << "ACE_NEW_RETURN (retval, ::" << node->name ()
      << ", 0);" << be_nl
      << "return retval;" << be_uidt_nl;
  *os << "}" << be_nl << be_nl;

  *os << "CORBA::Exception *" << be_nl
      << node->name () << "::_tao_duplicate (void) const" << be_nl
      << "{" << be_idt_nl
      << "CORBA::Exception *result;" << be_nl
      << "ACE_NEW_RETURN (" << be_idt << be_idt_nl
      << "result," << be_nl
      << "::" << node->name () << " (*this)," << be_nl
      << "0" << be_uidt_nl
      << ");" << be_uidt_nl
      << "return result;" << be_uidt_nl
      << "}" << be_nl << be_nl;

  *os << "void " << node->name () << "::_raise (void) const" << be_nl
      << "{" << be_idt_nl
      << "TAO_RAISE (*this);" << be_uidt_nl
      << "}" << be_nl << be_nl;

  *os << "void " << node->name ()
      << "::_tao_encode (" << be_idt << be_idt_nl;

  if (!node->is_local ())
    {
      *os << "TAO_OutputCDR &cdr" << be_nl
          << "ACE_ENV_ARG_DECL" << be_uidt_nl
          << ") const" << be_uidt_nl
          << "{" << be_idt_nl
          << "if (cdr << *this)" << be_idt_nl
          << "{" << be_idt_nl
          << "return;" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl;

      if (be_global->use_raw_throw ())
        {
          *os << "throw CORBA::MARSHAL ();" << be_uidt_nl;
        }
      else
        {
          *os << "ACE_THROW (CORBA::MARSHAL ());" << be_uidt_nl;
        }

      *os << "}" << be_nl << be_nl;
    }
  else
    {
      *os << "TAO_OutputCDR &" << be_nl
          << "ACE_ENV_ARG_DECL" << be_uidt_nl
          << ") const" << be_uidt_nl
          << "{" << be_idt_nl;

      if (be_global->use_raw_throw ())
        {
          *os << "throw CORBA::MARSHAL ();" << be_uidt_nl;
        }
      else
        {
          *os << "ACE_THROW (CORBA::MARSHAL ());" << be_uidt_nl;
        }

      *os << "}" << be_nl << be_nl;
    }

  *os << "void " << node->name ()
      << "::_tao_decode (" << be_idt << be_idt_nl;

  if (!node->is_local ())
    {
      *os << "TAO_InputCDR &cdr" << be_nl
          << "ACE_ENV_ARG_DECL" << be_uidt_nl
          << ")" << be_uidt_nl
          << "{" << be_idt_nl
          << "if (cdr >> *this)" << be_idt_nl
          << "{" << be_idt_nl
          << "return;" << be_uidt_nl
          << "}" << be_uidt_nl << be_nl;

      if (be_global->use_raw_throw ())
        {
          *os << "throw CORBA::MARSHAL ();" << be_uidt_nl;
        }
      else
        {
          *os << "ACE_THROW (CORBA::MARSHAL ());" << be_uidt_nl;
        }

      *os << "}" << be_nl << be_nl;
    }
  else
    {
      *os << "TAO_InputCDR &" << be_nl
          << "ACE_ENV_ARG_DECL" << be_uidt_nl
          << ")" << be_uidt_nl
          << "{" << be_idt_nl;

      if (be_global->use_raw_throw ())
        {
          *os << "throw CORBA::MARSHAL ();" << be_uidt_nl;
        }
      else
        {
          *os << "ACE_THROW (CORBA::MARSHAL ());" << be_uidt_nl;
        }

      *os << "}" << be_nl << be_nl;
    }

  // Constructor taking all members. It exists only if there are any
  // members.
  if (node->member_count () > 0)
    {
      // Generate the signature.
      ctx = *this->ctx_;
      ctx.state (TAO_CodeGen::TAO_EXCEPTION_CTOR_CS);
      be_visitor_exception_ctor ec_visitor (&ctx);

      if (node->accept (&ec_visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_exception::"
                             "visit_exception - "
                             "codegen for ctor failed\n"),
                            -1);
        }

      *os << be_idt_nl
          << ": CORBA::UserException ("
          << be_idt << be_idt << be_idt_nl
          << "\"" << node->repoID () << "\"," << be_nl
          << "\"" << node->local_name () << "\"" << be_uidt_nl
          << ")" << be_uidt << be_uidt << be_uidt_nl;
      *os << "{" << be_idt;

      // Assign each individual member. We need yet another state.
      ctx = *this->ctx_;

      // Indicate that the special ctor is being generated.
      ctx.exception (1);

      be_visitor_exception_ctor_assign eca_visitor (&ctx);

      if (node->accept (&eca_visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_exception_cs::"
                             "visit_exception -"
                             "codegen for scope failed\n"),
                            -1);
        }

      *os << be_uidt_nl << "}" << be_nl << be_nl;
    }

  if (be_global->tc_support ())
    {
      *os << "// TAO extension - the virtual _type method." << be_nl;
      *os << "CORBA::TypeCode_ptr " << node->name ()
          << "::_type (void) const" << be_nl;
      *os << "{" << be_idt_nl;
      *os << "return ::" << node->tc_name () << ";" << be_uidt_nl;
      *os << "}";
    }

  if (be_global->tc_support ())
    {
      ctx = *this->ctx_;
      ctx.sub_state (TAO_CodeGen::TAO_TC_DEFN_TYPECODE);
      be_visitor_typecode_defn visitor (&ctx);

      if (node->accept (&visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_exception_cs::"
                             "visit_exception - "
                             "TypeCode definition failed\n"),
                            -1);
        }
    }

  node->cli_stub_gen (I_TRUE);
  return 0;
}