summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_sequence/sequence_ch.cpp
blob: 3f1a1da8d8b29e2002ee0cb40c8711a6f37d12e1 (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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    sequence_ch.cpp
//
// = DESCRIPTION
//    Visitor generating code for Sequence in the client header
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

ACE_RCSID (be_visitor_sequence, 
           sequence_ch, 
           "$Id$")

// Root visitor for client header.
be_visitor_sequence_ch::be_visitor_sequence_ch (be_visitor_context *ctx)
  : be_visitor_decl (ctx)
{
}

be_visitor_sequence_ch::~be_visitor_sequence_ch (void)
{
}

int
be_visitor_sequence_ch::gen_base_sequence_class (be_sequence *node)
{
  TAO_OutStream *os = this->ctx_->stream ();
  be_type *bt = be_type::narrow_from_decl (node->base_type ());

  if (bt == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "Bad element type\n"), 
                        -1);
    }

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

  os->gen_ifdef_AHETI ();

  // This is the instantiation branch.
  *os << node->instance_name ();

  os->gen_else_AHETI ();

  // Generate the appropriate sequence type.
  switch (node->managed_type ())
    {
    case be_sequence::MNG_OBJREF:
      if (node->unbounded ())
        {
          *os << "TAO_Unbounded_Object_Sequence<";
        }
      else
        {
          *os << "TAO_Bounded_Object_Sequence<";
        }

      break;
    case be_sequence::MNG_PSEUDO:
      if (node->unbounded ())
        {
          *os << "TAO_Unbounded_Pseudo_Sequence<";
        }
      else
        {
          *os << "TAO_Bounded_Pseudo_Sequence<";
        }

      break;
    case be_sequence::MNG_VALUE:
      if (node->unbounded ())
        {
          *os << "TAO_Unbounded_Valuetype_Sequence<";
        }
      else
        {
          *os << "TAO_Bounded_Valuetype_Sequence<";
        }

      break;
    case be_sequence::MNG_STRING:
      if (node->unbounded ())
        {
          *os << "TAO_Unbounded_String_Sequence";
        }
      else
        {
          *os << "TAO_Bounded_String_Sequence";
        }

      break;
    case be_sequence::MNG_WSTRING:
      if (node->unbounded ())
        {
          *os << "TAO_Unbounded_WString_Sequence";
        }
      else
        {
          *os << "TAO_Bounded_WString_Sequence";
        }

      break;
    default: // Not a managed type.
      if (bt->base_node_type () == AST_Decl::NT_array)
        {
          if (node->unbounded ())
            {
              *os << "TAO_Unbounded_Array_Sequence<";
            }
          else
            {
              *os << "TAO_Bounded_Array_Sequence<";
            }
        }
      else
        {
          if (node->unbounded ())
            {
              *os << "TAO_Unbounded_Sequence<";
            }
          else
            {
              *os << "TAO_Bounded_Sequence<";
            }
        }

      break;
    }

  be_visitor_context ctx (*this->ctx_);

  be_visitor_sequence_base_template_args visitor (&ctx,
                                                  node);

  ctx.state (TAO_CodeGen::TAO_SEQUENCE_BASE_CH);

  if (bt->accept (&visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "base type visit failed\n"),
                        -1);
    }

  // Find out if the sequence is of a managed type and if
  // it is bounded or not.
  if (node->managed_type () == be_sequence::MNG_STRING
      || node->managed_type () == be_sequence::MNG_WSTRING)
    {
      if (!node->unbounded ())
        {
          *os << "<" << node->max_size () << ">";
        }
    }
  else
    {
      // If we are a sequence of arrays, the template includes
      // a _var parameter.
      if (bt->base_node_type () == AST_Decl::NT_array)
        {
          *os << ", ";

          // So the call to nested_type_name will have "_var" suffix.
          ctx.sub_state (TAO_CodeGen::TAO_ARRAY_SEQ_CH_TEMPLATE_VAR);

          if (bt->accept (&visitor) == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "(%N:%l) be_visitor_sequence_ch::"
                                 "visit_sequence - "
                                 "base type visit failed\n"),
                                -1);
            }

          ctx.sub_state (TAO_CodeGen::TAO_SUB_STATE_UNKNOWN);
        }

      if (node->unbounded ())
        {
          *os << ">";
        }
      else
        {
          *os << ", " << node->max_size () << ">";
        }
    }

  os->gen_endif_AHETI ();

  return 0;
}


int
be_visitor_sequence_ch::instantiate_sequence (be_sequence *node)
{
  be_type *bt = be_type::narrow_from_decl (node->base_type ());

  if (bt == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "gen_instantiate_template_name - "
                         "Bad element type\n"), 
                        -1);
    }

  // Generate the appropriate sequence type.
  switch (node->managed_type ())
    {
    case be_sequence::MNG_PSEUDO:
    case be_sequence::MNG_OBJREF:
    case be_sequence::MNG_VALUE:
      if (node->unbounded ())
        {
          this->gen_unbounded_obj_sequence (node);
        }
      else
        {
          this->gen_bounded_obj_sequence (node);
        }

      break;
    case be_sequence::MNG_STRING: // Sequence of strings.
      if (!node->unbounded ())
        {
          this->gen_bounded_str_sequence (node);
        }

      break;
    case be_sequence::MNG_WSTRING: // Sequence of wstrings.
      if (!node->unbounded ())
        {
          this->gen_bounded_wstr_sequence (node);
        }

      break;
    default: // Not a managed type.
      if (node->unbounded ())
	      {
	        // TAO provides extensions for octet sequences, first find out
	        // if the base type is an octet (or an alias for octet)
	        be_predefined_type *predef = 0;

	        if (bt->base_node_type () == AST_Type::NT_pre_defined)
	          {
	            be_typedef* alias =
		            be_typedef::narrow_from_decl (bt);

	            if (alias == 0)
		            {
		              predef =
		                be_predefined_type::narrow_from_decl (bt);
		            }
	            else
		            {
		              predef =
                    be_predefined_type::narrow_from_decl (
                        alias->primitive_base_type ()
                      );
		            }
	          }
	        if (predef != 0)
	          {
	            if (predef->pt() != AST_PredefinedType::PT_octet)
                {
		              this->gen_unbounded_sequence (node);
                }
	          }
	        else
            {
	            this->gen_unbounded_sequence (node);
            }
	      }
      else
        {
          this->gen_bounded_sequence (node);
        }

      break;
    } // End of switch.

  return 0;
}


int be_visitor_sequence_ch::visit_sequence (be_sequence *node)
{
  be_type *bt = 0;
  TAO_OutStream *os = this->ctx_->stream ();

  if (node->defined_in () == 0)
    {
      // The node is a nested sequence, and has had no scope defined.
      node->set_defined_in (DeclAsScope (this->ctx_->scope ()));
    }

  // First create a name for ourselves.
  if (node->create_name (this->ctx_->tdef ()) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "failed creating name\n"), -1);
    }

  if (node->cli_hdr_gen () || node->imported ())
    {
      return 0;
    }

  // Instantiation.

  if (this->instantiate_sequence (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "codegen. for the primitive type sequence\n"), 
                        -1);
    }

  // End of instantiation.

  // Generate the ifdefined macro for the sequence type.
  os->gen_ifdef_macro (node->flat_name ());

  // Retrieve the base type since we may need to do some code
  // generation for the base type.
  bt = be_type::narrow_from_decl (node->base_type ());

  if (bt == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "Bad element type\n"), -1);
    }

  *os << "class " << node->local_name () << ";" << be_nl;

  // No _var class for anonymous sequences.
  if (this->ctx_->tdef () != 0)
    {
      *os << "class " << node->local_name () << "_var;" << be_nl;
    }

  *os << be_nl;

  *os << "// *************************************************************"
      << be_nl
      << "// " << node->local_name () << be_nl
      << "// *************************************************************"
      << be_nl << be_nl;

  // Generate a typedef to a parametrized sequence.
  *os << "class " << be_global->stub_export_macro ()
      << " " << node->local_name () << " : public ";

  if (this->gen_base_sequence_class (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "codegen for base sequence class\n"),
                        -1);
    }

  *os << "{" << be_nl
      << "public:" << be_idt_nl
      << node->local_name () << " (void); // default ctor" << be_nl;

  // For unbounded sequences, we have a different set of constructors.
  if (node->unbounded ())
    {
      *os << node->local_name () << " (CORBA::ULong max); // uses max size"
          << be_nl;
    }

  *os << node->local_name () << " (" << be_idt << be_idt_nl;

  if (node->unbounded ())
    {
      // Unbounded seq takes this extra parameter.
      *os << "CORBA::ULong max, " << be_nl;
    }

  *os << "CORBA::ULong length, " << be_nl;

  // Generate the base type for the buffer.
  be_visitor_context ctx (*this->ctx_);
  ctx.state (TAO_CodeGen::TAO_SEQUENCE_BUFFER_TYPE_CH);
  be_visitor_sequence_buffer_type bt_visitor (&ctx);

  if (bt->accept (&bt_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "visit_sequence - "
                         "base type visit failed\n"),
                        -1);
    }

  *os << " *buffer, " << be_nl
      << "CORBA::Boolean release = 0" << be_uidt_nl
      << ");" << be_uidt_nl;
  *os << node->local_name () << " (const " << node->local_name ()
      << " &); // copy ctor" << be_nl;
  *os << "~" << node->local_name () << " (void);" << be_nl
      << "static void _tao_any_destructor (void*);" << be_nl;

  // Generate the _var_type typedef (only if we are not anonymous),
  // but we must protect against certain versions of g++.
  if (this->ctx_->tdef () != 0)
    {
      *os << "\n#if !defined(__GNUC__) || !defined (ACE_HAS_GNUG_PRE_2_8)"
          << be_nl;
      *os << "typedef " << node->local_name () << "_var _var_type;\n"
          << "#endif /* ! __GNUC__ || g++ >= 2.8 */" << be_nl << be_nl;
    }

  // TAO provides extensions for octet sequences, first find out if
  // the base type is an octet (or an alias for octet).
  be_predefined_type *predef = 0;

  if (bt->base_node_type () == AST_Type::NT_pre_defined)
    {
      be_typedef* alias =
	    be_typedef::narrow_from_decl (bt);

      if (alias == 0)
	      {
	        predef = be_predefined_type::narrow_from_decl (bt);
	      }
      else
	      {
	        predef =
            be_predefined_type::narrow_from_decl (
                alias->primitive_base_type ()
              );
	      }
    }

  // Now generate the extension...
  if (predef != 0 && predef->pt () == AST_PredefinedType::PT_octet
      && node->unbounded ())
    {
      *os << "\n#if (TAO_NO_COPY_OCTET_SEQUENCES == 1)" << be_nl
	        << node->local_name () << " (" << be_idt << be_idt_nl
	        << "CORBA::ULong length," << be_nl
	        << "const ACE_Message_Block* mb" << be_uidt_nl
	        << ")" << be_uidt_nl
	        << "  : " << node->instance_name ()
	        << " (length, mb) {}" << "\n"
	        << "#endif /* TAO_NO_COPY_OCTET_SEQUENCE == 1 */" << be_nl;
    }

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

  os->gen_endif (); // Endif macro.

  // No _var or _out class for an anonymous (non-typedef'd) sequence.
  if (this->ctx_->tdef () != 0)
    {
      // Generate the ifdefined macro for the var type.
      os->gen_ifdef_macro (node->flat_name (), "_var");

      // Generate the var and out types.
      if (this->gen_var_defn (node) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_sequence_ch::"
                             "visit_sequence - "
                             "codegen for _var failed\n"), 
                            -1);
        }

      os->gen_endif ();

      // Generate the ifdefined macro for the _out type.
      os->gen_ifdef_macro (node->flat_name (), "_out");

      if (this->gen_out_defn (node) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_sequence_ch::"
                             "visit_sequence - "
                             "codegen for _out failed\n"),
                            -1);
        }

      os->gen_endif ();
    }

  node->cli_hdr_gen (1);

  return 0;
}

// Generate the _var definition for ourself.
int
be_visitor_sequence_ch::gen_var_defn (be_sequence *node)
{
  TAO_OutStream *os = this->ctx_->stream ();
  char namebuf [NAMEBUFSIZE];

  ACE_OS::memset (namebuf,
                  '\0',
                  NAMEBUFSIZE);

  ACE_OS::sprintf (namebuf,
                   "%s_var",
                   node->local_name ()->get_string ());

  *os << "// *************************************************************"
      << be_nl;
  *os << "// class " << node->name () << "_var" << be_nl;
  *os << "// *************************************************************"
      << be_nl << be_nl;

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

  if (!bt)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "gen_var_defn - "
                         "Bad base type\n"),
                        -1);
    }

  // Generate the var definition (always in the client header).
  // Depending upon the data type, there are some differences which we account
  // for over here.

  *os << "class " << be_global->stub_export_macro ()
      << " " << namebuf << be_nl;
  *os << "{" << be_nl;
  *os << "public:" << be_idt_nl;

  // Default constuctor.
  *os << namebuf << " (void);" << be_nl;

  // Constuctor.
  *os << namebuf << " (" << node->local_name () << " *);" << be_nl;

  // Copy constructor.
  *os << namebuf << " (const " << namebuf <<  " &);" << be_nl;

  // Fixed-size base types only.
  if (bt->size_type () == be_decl::FIXED)
    {
      *os << "// Fixed-size base types only." << be_nl;
      *os << namebuf << " (const " << node->local_name ()
          << " &);" << be_nl;
    }

  // Destructor.
  *os << "~" << namebuf << " (void);" << be_nl;
  *os << be_nl;

  // Assignment operator from a pointer.
  *os << namebuf << " &operator= ("
      << node->local_name () << " *);" << be_nl;

  // Assignment from _var.
  *os << namebuf << " &operator= (const " << namebuf << " &);" << be_nl;

  // Fixed-size base types only.
  if (bt->size_type () == be_decl::FIXED)
    {
      *os << "// Fixed-size base types only." << be_nl;
      *os << namebuf << " &operator= (const " << node->local_name ()
          << " &);" << be_nl;
    }

  // Arrow operator.
  *os << node->local_name () << " *operator-> (void);" << be_nl;
  *os << "const " << node->local_name ()
      << " *operator-> (void) const;" << be_nl;
  *os << be_nl;

  // Other extra types (cast operators, [] operator, and others).

  // Cast operator.
  *os << "operator const " << node->local_name () << " &() const;" << be_nl;
  *os << "operator " << node->local_name () << " &();" << be_nl;
  *os << "operator " << node->local_name () << " &() const;" << be_nl;

  if (bt->size_type () == be_decl::VARIABLE)
    {
      *os << "operator " << node->local_name ()
          << " *&(); // variable-size base types only" << be_nl;
    }

  *os << be_nl;

  // Overloaded [] operators.
  be_visitor_context ctx (*this->ctx_);
  ctx.state (TAO_CodeGen::TAO_SEQELEM_RETTYPE_CH);
  be_visitor_sequence_elemtype sr_visitor (&ctx);

  if (bt->accept (&sr_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_sequence::"
                         "gen_var_defn - "
                         "[] ret type gen failed\n"),
                        -1);
    }

  *os << " operator[] (CORBA::ULong index);" << be_nl;

  AST_Decl::NodeType nt = bt->base_node_type ();
  AST_PredefinedType::PredefinedType pdt = AST_PredefinedType::PT_void;

  if (nt == AST_Decl::NT_pre_defined)
    {
      AST_PredefinedType *p = 0;
      be_typedef *btd = be_typedef::narrow_from_decl (bt);

      if (btd == 0)
        {
          p = AST_PredefinedType::narrow_from_decl (bt);
        }
      else
        {
          p = AST_PredefinedType::narrow_from_decl (
                  btd->primitive_base_type ()
                );
        }

      pdt = p->pt ();
    }

  // @@ (JP) Problems with constant instantiations of TAO_Object_Manager,
  // TAO_Pseudo_Object_Manager, TAO_SeqElem_WString_Manager and
  // TAO_SeqElem_String_Manager make these impossible right now [BUGID:676].
  if (nt != AST_Decl::NT_string
      && nt != AST_Decl::NT_wstring
      && nt != AST_Decl::NT_interface
      && nt != AST_Decl::NT_interface_fwd
      && nt != AST_Decl::NT_array
      && pdt != AST_PredefinedType::PT_pseudo)
    {
      *os << "const ";

      if (bt->accept (&sr_visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_sequence::"
                             "gen_var_defn - "
                             "[] ret type gen failed\n"),
                            -1);
        }

      *os << " operator[] (CORBA::ULong index) const;" << be_nl;
    }

  *os << be_nl;

  *os << "// in, inout, out, _retn " << be_nl;

  // The return types of in, out, inout, and _retn are based on the parameter.
  // passing rules and the base type.
  *os << "const " << node->local_name () << " &in (void) const;" << be_nl;
  *os << node->local_name () << " &inout (void);" << be_nl;
  *os << node->local_name () << " *&out (void);" << be_nl;
  *os << node->local_name () << " *_retn (void);" << be_nl;

  // Generate an additional member function that
  // returns the underlying pointer.
  *os << node->local_name () << " *ptr (void) const;" << be_uidt_nl << be_nl;

  // Generate the private section.
  *os << "private:" << be_idt_nl;
  *os << node->local_name () << " *ptr_;" << be_uidt_nl;

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

  return 0;
}

// Generate the _out definition.
int
be_visitor_sequence_ch::gen_out_defn (be_sequence *node)
{
  TAO_OutStream *os = this->ctx_->stream ();
  char namebuf [NAMEBUFSIZE];

  ACE_OS::memset (namebuf,
                  '\0',
                  NAMEBUFSIZE);
  ACE_OS::sprintf (namebuf,
                   "%s_out",
                   node->local_name ()->get_string ());

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

  if (bt == 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_sequence_ch::"
                         "gen_out_defn - "
                         "Bad base type\n"),
                        -1);
    }

  // Generate the out definition (always in the client header).
  *os << "class " << be_global->stub_export_macro () << " "
      << namebuf << be_nl;
  *os << "{" << be_nl;
  *os << "public:" << be_idt_nl;

  // No default constructor.

  // Constructor from a pointer.
  *os << namebuf << " (" << node->local_name () << " *&);" << be_nl;

  // Constructor from a _var &.
  *os << namebuf << " (" << node->local_name () << "_var &);" << be_nl;

  // Constructor from a _out &.
  *os << namebuf << " (const " << namebuf << " &);" << be_nl;

  // Assignment operator from a _out &.
  *os << namebuf << " &operator= (const " << namebuf << " &);" << be_nl;

  // Assignment operator from a pointer &, cast operator, ptr fn, operator
  // -> and any other extra operators.

  // Assignment.
  *os << namebuf << " &operator= (" << node->local_name () << " *);" << be_nl;

  // operator ().
  *os << "operator " << node->local_name () << " *&();" << be_nl;

  // ptr function.
  *os << node->local_name () << " *&ptr (void);" << be_nl;

  // operator ->.
  *os << node->local_name () << " *operator-> (void);" << be_nl;

  // Overloaded [] operator only for sequence. The const version is not
  // required
  be_visitor_context ctx (*this->ctx_);
  ctx.state (TAO_CodeGen::TAO_SEQELEM_RETTYPE_CH);
  be_visitor_sequence_elemtype sr_visitor (&ctx);

  if (bt->accept (&sr_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_sequence::"
                         "gen_var_defn - "
                         "[] ret type gen failed\n"),
                        -1);
    }

  *os << " operator[] (CORBA::ULong index);" << be_uidt_nl << be_nl;
  *os << "private:" << be_idt_nl;
  *os << node->local_name () << " *&ptr_;" << be_nl;
  *os << "// Assignment from T_var not allowed." << be_nl;
  *os << "void operator= (const " << node->local_name ()
      << "_var &);" << be_uidt_nl;
  *os << "};" << be_nl << be_nl;

  return 0;
}