summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_array.cpp
blob: 091095c71c9ffebb860d11f2babee7518f93072d (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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    be_array.cpp
//
// = DESCRIPTION
//    Extension of class AST_Array that provides additional means for C++
//    mapping.
//
// = AUTHOR
//    Copyright 1994-1995 by Sun Microsystems, Inc.
//    and
//    Aniruddha Gokhale
//
// ============================================================================

#include	"idl.h"
#include	"idl_extern.h"
#include	"be.h"

/*
 * BE_Array
 */
be_array::be_array (void)
{
}

be_array::be_array (UTL_ScopedName *n, unsigned long ndims, UTL_ExprList *dims)
  : AST_Array (n, ndims, dims),
    AST_Decl (AST_Decl::NT_array, n, NULL)
{
  be_type *bt;

  // Macro to avoid "warning: unused parameter" type warning.
  ACE_UNUSED_ARG (bt);

  // if we are inside of a union, we change our local name to have an
  // underscore before us
  AST_Decl *d = ScopeAsDecl (this->defined_in ());
  if (d && (d->node_type () == AST_Decl::NT_union))
    {
      static char namebuf [200];
      UTL_ScopedName *myname;

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

      // make a copy of our parent's name
      myname = (UTL_ScopedName *)d->name ()->copy ();
      ACE_OS::sprintf (namebuf, "_%s", this->local_name ()->get_string ());
      myname->nconc (new UTL_ScopedName (new Identifier (ACE_OS::strdup
                                                         (namebuf), 1, 0,
                                                         I_FALSE), NULL));
      this->set_name (myname);
    }

  // computes the repoID
  compute_repoID ();

  // computes the fully scoped name
  compute_fullname ();

  // computes the fully scoped typecode name
  compute_tc_name ();

  // compute the flattened fully scoped name
  compute_flatname ();

}

// Code generation

int
be_array::gen_client_header (void)
{
  TAO_OutStream *ch; // output stream
  unsigned long i;   // loop index
  TAO_NL  nl;        // end line
  be_type *bt;       // our base type
  be_decl *d;        // enclosing scope
  be_state *s;       // state based code gen object

  // Macro to avoid "warning: unused parameter" type warning.
  ACE_UNUSED_ARG (d);

  if (!this->cli_hdr_gen_) // not already generated
    {
      // retrieve a singleton instance of the code generator
      TAO_CodeGen *cg = TAO_CODEGEN::instance ();
      cg->push (TAO_CodeGen::TAO_ARRAY_DEFN_CH); // set current code gen state

      ch = cg->client_header (); // retrieve client hdr stream
      cg->outstream (ch); // set client hdr as the current stream
      cg->node (this);    // pass ourselves for type gen

      s = cg->make_state (); // get the state-based code generation object

      bt = be_type::narrow_from_decl (this->base_type ());

      // generate our base type
      if (!s || !bt || (s->gen_code (bt, this) == -1))
        {
          ACE_ERROR ((LM_ERROR, "be_array: type generation failed\n"));
          return -1;
        }

      // print our name
      *ch << " " <<  this->local_name ();
      // print our dimensions
      for (i = 0; i < this->n_dims (); i++)
        {
          AST_Expression *expr = this->dims ()[i]; // retrieve the ith
                                                   // dimension value
          if ((expr == NULL) || ((expr != NULL) && (expr->ev () == NULL)))
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimensions\n\n"));
              return -1;
            }
          if (expr->ev ()->et == AST_Expression::EV_ulong)
            {
              *ch << "[" << ((int)expr->ev ()->u.ulval) << "]";
            }
          else
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimension value\n"));
              return -1;
            }
        }
      *ch << ";" << nl;

      // if our base type is VARIABLE length, then we are variable length too
      this->size_type (bt->size_type ());

      cg->pop ();

      cg->push (TAO_CodeGen::TAO_ARRAY_OTHER_CH); // rest of the array defn
      s = cg->make_state ();

      *ch << "typedef ";

      // now generate the slice definition
      if (!s || !bt || (s->gen_code (bt, this) == -1))
        {
          ACE_ERROR ((LM_ERROR, "be_array: type generation failed\n"));
          return -1;
        }

      *ch << " " <<  this->local_name () << "_slice";
      // print dimensions except first one
      for (i = 1; i < this->n_dims (); i++)
        {
          // no error checking. Assumption is that everything is valid since we
          // already checked it before.
          AST_Expression *expr = this->dims ()[i]; // retrieve the ith
                                                   // dimension value
          *ch << "[" << ((int)expr->ev ()->u.ulval) << "]";
        }
      *ch << ";" << nl;

      // memory management functions
      // first find if we are inside a scope
      if (this->is_nested ()) // we were defined inside a scope. Hence the
        // memory management
        // functions become static members of the enclosing class
        *ch << "static ";
      *ch <<  this->local_name () << "_slice *" << this->local_name () <<
        "_alloc (void);" << nl;
      if (this->is_nested ())
        *ch << "static ";
      *ch <<  this->local_name () << "_slice *" << this->local_name () <<
        "_dup (const " << this->local_name () << "_slice *);" << nl;
      if (this->is_nested ())
        *ch << "static ";
      *ch << "void " << this->local_name () << "_free (" << this->local_name ()
          << "_slice *);\n\n";

      // generate the _var, _out, and _forany definition
      this->gen_var_defn ();
      this->gen_out_defn ();
      this->gen_forany_defn ();

      // Generate the typecode decl
      // All names in the root scope have length 2 (for the root and
      // ourself). The children have length greater than 2. Thus, if our name
      // length is 2 or less, we are outermost and our typecode decl must be
      // extern, else we are defined static inside the enclosing scope.
      if (this->is_nested ())
        {
          // we have a scoped name
          ch->indent ();
          *ch << "static CORBA::TypeCode_ptr " << this->tc_name
            ()->last_component () << ";\n\n";
        }
      else
        {
          // we are in the ROOT scope
          ch->indent ();
          *ch << "extern CORBA::TypeCode_ptr " << this->tc_name
            ()->last_component () << ";\n\n";
        }
      this->cli_hdr_gen_ = I_TRUE;
      cg->pop ();
    }
  return 0;
}

int
be_array::gen_client_stubs (void)
{
  TAO_OutStream *cs; // output stream
  TAO_NL  nl;        // end line


  if (!this->cli_stub_gen_)
    {
      // retrieve a singleton instance of the code generator
      TAO_CodeGen *cg = TAO_CODEGEN::instance ();
      cg->push (TAO_CodeGen::TAO_SEQUENCE_BODY_CS); // set current code gen state

      cs = cg->client_stubs ();
      // pass info
      cg->outstream (cs);
      cg->node (this);
      // generate the typecode information here
      cs->indent (); // start from current indentation level
      *cs << "static const CORBA::Long _oc_" << this->flatname () << "[] =" <<
        nl;
      *cs << "{\n";
      cs->incr_indent (0);
      if (this->gen_encapsulation () == -1)
        {
          ACE_ERROR ((LM_ERROR, "be_array:Error generating encapsulation\n\n"));
          return -1;
        }
      cs->decr_indent ();
      *cs << "};" << nl;

      *cs << "static CORBA::TypeCode _tc__tc_" << this->flatname () <<
        " (CORBA::tk_sequence, sizeof (_oc_" <<  this->flatname () <<
        "), (unsigned char *) &_oc_" << this->flatname () <<
        ", CORBA::B_FALSE);" << nl;
      *cs << "CORBA::TypeCode_ptr " << this->tc_name () << " = &_tc__tc_" <<
        this->flatname () << ";\n\n";

      cg->pop ();
      this->cli_stub_gen_ = I_TRUE;

    }
  return 0;
}

int
be_array::gen_server_header (void)
{
  return 0;
}

int
be_array::gen_server_skeletons (void)
{
  return 0;
}

// Generates the client-side inline information
int
be_array::gen_client_inline (void)
{
  if (!this->cli_inline_gen_)
    {
      TAO_OutStream *ci; // output stream
      unsigned long i;   // loop index
      TAO_NL  nl;        // end line
      be_type *bt;       // our base type
      be_decl *d;        // enclosing scope
      be_state *s;       // state based code gen obj

      // Macro to avoid "warning: unused parameter" type warning.
      ACE_UNUSED_ARG (d);

      // retrieve a singleton instance of the code generator
      TAO_CodeGen *cg = TAO_CODEGEN::instance ();

      ci = cg->client_inline ();
      cg->outstream (ci);
      cg->node (this);
      cg->push (TAO_CodeGen::TAO_ARRAY_DEFN_CI);
      s = cg->make_state ();

      // retrieve our base type
      bt = be_type::narrow_from_decl (this->base_type ());

      // first define the _alloc, _dup and _free methods
      // If we are defined inside some scope, these methods become static
      // members of the enclosing scope

      ci->indent (); // start from current indentation

      // alloc method
      *ci << "ACE_INLINE " << this->name () << "_slice *" << nl;
      *ci << this->name () << "_alloc (void)" << nl;
      *ci << "{\n";
      ci->incr_indent ();
      *ci << "new ";
      if (s->gen_code (bt, this) == -1)
        return -1;

      ci->decr_indent ();
      *ci << "}\n\n";

      // dup method
      *ci << "ACE_INLINE " << this->name () << "_slice *" << nl;
      *ci << this->name () << "_dup (" << this->name () << "_slice * s)" << nl;
      *ci << "{\n";
      ci->incr_indent ();
      *ci << this->name () << "_slice *temp;" << nl;
      *ci << "temp = " << this->name () << "_alloc ();" << nl;
      *ci << "// copy each individual elements" << nl;
      for (i = 0; i < this->n_dims (); i++)
        {
          AST_Expression *expr = this->dims ()[i]; // retrieve the ith
                                                   // dimension value
          if ((expr == NULL) || ((expr != NULL) && (expr->ev () == NULL)))
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimensions\n\n"));
              return -1;
            }
          if (expr->ev ()->et == AST_Expression::EV_ulong)
            {
              // generate a loop for each dimension
              *ci << "for (CORBA::ULong i" << i << " = 0; i" << i << " < " <<
                expr->ev ()->u.ulval << "; i" << i << "++)\n";
              ci->incr_indent ();
            }
          else
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimension value\n"));
              return -1;
            }
        }

      // the code below looks terribly complex. However, all it is trying to do
      // is to generate code of the form
      // temp [i0][i1].... =
      *ci << "temp ";
      for (i = 0; i < this->n_dims (); i++)
        {
          AST_Expression *expr = this->dims ()[i]; // retrieve the ith
                                                   // dimension value
          if ((expr == NULL) || ((expr != NULL) && (expr->ev () == NULL)))
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimensions\n\n"));
              return -1;
            }
          if (expr->ev ()->et == AST_Expression::EV_ulong)
            {
              *ci << "[" << ((int)expr->ev ()->u.ulval) << "]";
            }
          else
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimension value\n"));
              return -1;
            }
        }
      *ci << " = s";
      for (i = 0; i < this->n_dims (); i++)
        {
          AST_Expression *expr = this->dims ()[i]; // retrieve the ith
                                                   // dimension value
          if ((expr == NULL) || ((expr != NULL) && (expr->ev () == NULL)))
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimensions\n\n"));
              return -1;
            }
          if (expr->ev ()->et == AST_Expression::EV_ulong)
            {
              *ci << "[" << ((int)expr->ev ()->u.ulval) << "]";
            }
          else
            {
              ACE_ERROR ((LM_ERROR, "be_array: bad dimension value\n"));
              return -1;
            }
        }
      *ci << ";\n";
      for (i = 0; i < this->n_dims (); i++)
        {
          // decrement indentation as many times as the number of dimensions
          ci->decr_indent ();
        }

      ci->decr_indent ();
      *ci << "}\n\n";

      // free method
      *ci << this->name () << "_free (" << this->name () << "_slice *s)" << nl;
      *ci << "{\n";
      ci->incr_indent ();
      *ci << "delete [] s;\n";
      ci->decr_indent ();
      *ci << "}\n\n";

      // emit implementations of methods of the _var, _out, and _forany classes
      if (this->gen_var_impl () == -1)
        {
          ACE_ERROR ((LM_ERROR, "be_array: _var impl code gen failed\n"));
          return -1;
        }
      if (this->gen_out_impl () == -1)
        {
          ACE_ERROR ((LM_ERROR, "be_array: _out impl code gen failed\n"));
          return -1;
        }
      if (this->gen_forany_impl () == -1)
        {
          ACE_ERROR ((LM_ERROR, "be_array: _forany impl code gen failed\n"));
          return -1;
        }

      // generate client inline for base type
      if (bt->gen_client_inline () == -1)
        {
          ACE_ERROR ((LM_ERROR, "be_array: base type inline code gen failed\n"));
          return -1;
        }

      cg->pop ();
      this->cli_inline_gen_ = I_TRUE;
    }

  return 0;
}

// Generates the server-side inline
int
be_array::gen_server_inline (void)
{
  // nothing to be done
  return 0;
}

// generate the _var definition for ourself
int
be_array::gen_forany_defn (void)
{
  TAO_OutStream *ch; // output stream
  long i;            // loop index
  TAO_NL  nl;        // end line
  char namebuf [NAMEBUFSIZE];  // to hold the _out name

  // Macro to avoid "warning: unused parameter" type warning.
  ACE_UNUSED_ARG (i);

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

  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();

  ch = cg->client_header ();

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

  ch->indent (); // start with whatever was our current indent level
  *ch << "class " << namebuf << nl;
  *ch << "{" << nl;
  *ch << "public:\n";
  ch->incr_indent ();
  // default constr
  *ch << namebuf << " (void); // default constructor" << nl;
  // constr
  *ch << namebuf << " (" << local_name () << "_slice *);" << nl;
  // copy constructor
  *ch << namebuf << " (const " << namebuf <<
    " &); // copy constructor" << nl;
  // destructor
  *ch << "~" << namebuf << " (void); // destructor" << nl;
  *ch << nl;
  // assignment operator from a pointer
  *ch << namebuf << " &operator= (" << local_name () <<
    "_slice *, CORBA::Boolean nocopy=0);" << nl;
  // assignment from _var
  *ch << namebuf << " &operator= (const " << namebuf <<
    " &);" << nl;

  // overloaded [] operator
  *ch << namebuf << "_slice &operator[] (CORBA::ULong index);" << nl;
  *ch << "const " << namebuf <<
    "_slice &operator[] (CORBA::ULong index) const;" << nl;

  // cast operators
  *ch << "operator const " << local_name () << "_slice *&() (void) const;" << nl;
  *ch << "operator " << local_name () << "_slice *&() (void);" << nl;

  *ch << "// in, inout, out, _retn " << nl;
  // the return types of in, out, inout, and _retn are based on the parameter
  // passing rules and the base type
  if (this->size_type () == be_decl::FIXED)
    {
      *ch << "const " << local_name () << " in (void) const;" << nl;
      *ch << local_name () << " inout (void);" << nl;
      *ch << local_name () << " out (void);" << nl;
      *ch << local_name () << "_slice *_retn (void);" << nl;
    }
  else
    {
      *ch << "const " << local_name () << " in (void) const;" << nl;
      *ch << local_name () << " inout (void);" << nl;
      *ch << local_name () << "_slice *&out (void);" << nl;
      *ch << local_name () << " *_retn (void);" << nl;
    }
  *ch << "\n";
  ch->decr_indent ();
  *ch << "private:\n";
  ch->incr_indent ();
  *ch << local_name () << "_slice *ptr_;\n";
  ch->decr_indent ();
  *ch << "};\n\n";

  return 0;
}

int
be_array::gen_forany_impl (void)
{
  TAO_OutStream *ci; // output stream
  long i;            // loop index
  TAO_NL  nl;        // end line
  char fname [NAMEBUFSIZE];  // to hold the full and
  char lname [NAMEBUFSIZE];  // local _var names

  // Macro to avoid "warning: unused parameter" type warning.
  ACE_UNUSED_ARG (i);

  ACE_OS::memset (fname, '\0', NAMEBUFSIZE);
  ACE_OS::sprintf (fname, "%s_forany", this->fullname ());

  ACE_OS::memset (lname, '\0', NAMEBUFSIZE);
  ACE_OS::sprintf (lname, "%s_forany", local_name ()->get_string ());

  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();

  ci = cg->client_inline ();
  cg->outstream (ci);

  // generate the forany implementation in the inline file
  // Depending upon the data type, there are some differences which we account
  // for over here.

  ci->indent (); // start with whatever was our current indent level

  *ci << "// *************************************************************"
      << nl;
  *ci << "// Inline operations for class " << fname << nl;
  *ci << "// *************************************************************\n\n";

  // default constr
  *ci << "ACE_INLINE" << nl;
  *ci << fname << "::" << lname <<
    " (void) // default constructor" << nl;
  *ci << "\t" << ": ptr_ ((" << name () << "_slice *)0)" << nl;
  *ci << "{}\n\n";

  // constr from a _slice *
  ci->indent ();
  *ci << "ACE_INLINE" << nl;
  *ci << fname << "::" << lname << " (" << name () << "_slice *p)" << nl;
  *ci << "\t: ptr_ (p)" << nl;
  *ci << "{}\n\n";

  // copy constructor (deep copy)
  ci->indent ();
  *ci << "ACE_INLINE" << nl;
  *ci << fname << "::" << lname << " (const " << fname <<
    " &p) // copy constructor" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "this->ptr_ = " << this->name () << "_dup (p->ptr);\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  // destructor
  ci->indent ();
  *ci << "ACE_INLINE" << nl;
  *ci << fname << "::~" << lname << " (void) // destructor" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << this->name () << "_free (this->ptr_);\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  // assignment operator
  ci->indent ();
  *ci << "ACE_INLINE " << fname << " &" << nl;
  *ci << fname << "::operator= (" << this->name () <<
    "_slice p)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "// is what we own the same that is being assigned to us?" <<
    nl;
  *ci << "if (this->ptr_ != p)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "// delete our stuff and assume ownership of p" << nl;
  *ci << this->name () << "_free (this->ptr_);" << nl;
  *ci << "this->ptr_ = p;\n";
  ci->decr_indent ();
  *ci << "}" << nl;
  *ci << "return *this;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  // assignment operator from _var
  ci->indent ();
  *ci << "ACE_INLINE " << fname << " &" << nl;
  *ci << fname << "::operator= (const " << fname <<
    " &p)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "if (this != &p)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "// not assigning to ourselves" << nl;
  *ci << this->name () << "_free (this->ptr_); // free old stuff" << nl;
  *ci << "this->ptr_ = " << this->name () <<
    "_dup (p->ptr);// deep copy\n";
  ci->decr_indent ();
  *ci << "}" << nl;
  *ci << "return *this;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  // other extra methods - cast operators ()
  ci->indent ();
  *ci << "ACE_INLINE " << nl;
  *ci << fname << "::operator const " << name () <<
    "_slice &() const // cast" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  ci->indent ();
  *ci << "ACE_INLINE " << nl;
  *ci << fname << "::operator " << name () << "_slice &() // cast " << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  // two operator []s instead of ->
  ci->indent ();
  *ci << "ACE_INLINE const" << name () << "_slice &" << nl;
  *ci << fname << "::operator[] (CORBA::ULong index) const" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_[index];\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  ci->indent ();
  *ci << "ACE_INLINE " << name () << "_slice &" << nl;
  *ci << fname << "::operator[] (CORBA::ULong index)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_[index];\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  // in, inout, out, and _retn
  ci->indent ();
  *ci << "ACE_INLINE " << fname << nl;
  *ci << fname << "::in (void) const" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  ci->indent ();
  *ci << "ACE_INLINE " << fname << nl;
  *ci << fname << "::inout (void)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  ci->indent ();
  *ci << "ACE_INLINE " << fname << nl;
  *ci << fname << "::out (void)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->ptr_;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  ci->indent ();
  *ci << "ACE_INLINE " << name () << "_slice " << nl;
  *ci << fname << "::_retn (void)" << nl;
  *ci << "{\n";
  ci->incr_indent ();
  *ci << "return this->val;\n";
  ci->decr_indent ();
  *ci << "}\n\n";

  return 0;
}

int
be_array::gen_typecode (void)
{
  TAO_OutStream *cs; // output stream
  TAO_NL  nl;        // end line
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();

  cs = cg->client_stubs ();
  cs->indent (); // start from whatever indentation level we were at

  *cs << "CORBA::tk_array, // typecode kind" << nl;
  *cs << this->tc_size () << ", // encapsulation length\n";
  // now emit the encapsulation
  return this->gen_encapsulation ();
}

// generate encapsulation
// An encapsulation for ourselves will be necessary when we are part of some
// other IDL type and a typecode for that other type is being generated. This
// will comprise our typecode kind. IDL types with parameters will additionally
// have the encapsulation length and the entire typecode description

int
be_array::gen_encapsulation (void)
{
  TAO_OutStream *os; // output stream
  TAO_NL  nl;        // end line
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  be_type *bt; // base type

  os = cg->client_stubs ();
  os->indent (); // start from the current indentation level

  // XXXASG - byte order must be based on what m/c we are generating code -
  // TODO
  *os << "0, // byte order" << nl;

  // emit typecode of element type
  bt = be_type::narrow_from_decl (this->base_type ());
  if (!bt || (bt->gen_typecode () == -1))
    {
      ACE_ERROR ((LM_ERROR, "be_sequence::gen_typecode - bad base type\n"));
      return -1;
    }

  //  emit the length
  os->indent ();
  //  *os << this->max_size () << ",\n";
  return 0;
}

// compute typecode size
long
be_array::tc_size (void)
{
  // 4 bytes for enumeration, 4 bytes for storing encap length val, followed by the
  // actual encapsulation length
  return 4 + 4 + this->tc_encap_len ();
}

long
be_array::tc_encap_len (void)
{
  if (this->encap_len_ == -1) // not computed yet
    {
      be_type *bt; // base type

      this->encap_len_ = 4;  // holds the byte order flag
      // add the encapsulation length of our base type
      bt = be_type::narrow_from_decl (this->base_type ());
      if (!bt)
        {
          ACE_ERROR ((LM_ERROR,
                      "be_array::tc_encap_len - bad base type\n"));
          return 0;
        }
      this->encap_len_ += bt->tc_encap_len ();
      this->encap_len_ += 4; // to hold the array size

    }
  return this->encap_len_;
}

// Narrowing
IMPL_NARROW_METHODS2 (be_array, AST_Array, be_type)
IMPL_NARROW_FROM_DECL (be_array)