summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_operation/operation.cpp
blob: a63791945aada1e61f2ea7618302701cb497492a (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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
//
// $Id$
//

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

ACE_RCSID (be_visitor_operation,
           operation,
           "$Id$")

// ************************************************************
// Generic Operation visitor
// ************************************************************

be_visitor_operation::be_visitor_operation (be_visitor_context *ctx)
  : be_visitor_scope (ctx),
    operation_name_ (0)
{
}

be_visitor_operation::~be_visitor_operation (void)
{
  delete [] operation_name_;
}

// Is the operation return type void?
int
be_visitor_operation::void_return_type (be_type *bt)
{
  if (bt->node_type () == AST_Decl::NT_pre_defined)
    {
      AST_PredefinedType::PredefinedType pdt =
        be_predefined_type::narrow_from_decl (bt)->pt ();

      if (pdt == AST_PredefinedType::PT_void)
        {
          return 1;
        }
    }

  return 0;
}

int
be_visitor_operation::has_param_type (be_operation *node,
                                      AST_Argument::Direction dir)
{
  return (node->count_arguments_with_direction (dir) != 0);
}

size_t
be_visitor_operation::count_non_out_parameters (be_operation *node)
{
  // @@ Once the valuetype issue discussed below is fixed we can
  //    replace this routine with:
  //
  // return node->count_arguments_with_direction (AST_Argument::dir_IN
  //                                              | AST_Argument::dir_INOUT);
  //
  size_t count = 0;

  // Initialize an iterator to iterate thru our scope.
  for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next ())
    {
      be_argument *bd =
        be_argument::narrow_from_decl (si.item ());

      // We do not generate insertion operators for valuetypes
      // yet. Do not include them in the count.
      be_valuetype *vt =
        be_valuetype::narrow_from_decl (bd->field_type ());

      if (bd && (bd->direction () != AST_Argument::dir_OUT) && !vt)
        {
          ++count;
        }
    }

  return count;
}

int
be_visitor_operation::is_amh_exception_holder (be_interface *node)
{
  int is_an_amh_exception_holder = 0;
  const char *amh_underbar = "AMH_";
  const char *node_name = node->local_name ();

  if( amh_underbar[0] == node_name[0] &&
      amh_underbar[1] == node_name[1] &&
      amh_underbar[2] == node_name[2] &&
      amh_underbar[3] == node_name[3]
      ) // node name starts with "AMH_"
    {
      //ACE_DEBUG ((LM_DEBUG, "Passed first test of amh_excepholder \n"));
      const char *last_E = ACE_OS::strrchr (node->full_name (), 'E');
      if (last_E != 0
          && ACE_OS::strcmp (last_E, "ExceptionHolder") == 0)
        {
          //ACE_DEBUG ((LM_DEBUG, "be_visitor_operation: Passed second test of amh_excepholder \n"));
          is_an_amh_exception_holder = 1;
        }
    }

  return is_an_amh_exception_holder;
}

// Method to generate the throw specs for exceptions that are thrown by the
// operation.
int
be_visitor_operation::gen_throw_spec (be_operation *node)
{
  TAO_OutStream *os = this->ctx_->stream (); // grab the out stream

  const char *throw_spec_open = "throw (";
  const char *throw_spec_close = ")";

  if (!be_global->use_raw_throw ())
    {
      throw_spec_open = "ACE_THROW_SPEC ((";
      throw_spec_close = "))";
    }

  UTL_Scope *scope = node->defined_in ();
  be_interface *iface = be_interface::narrow_from_scope (scope);

  /***************************************************************************/
  // 2.6
  // Generate the Right Throw Spec if it is an AMH ExceptionHolder
  /***************************************************************************/
  // Check if this is (IF and it's not VT) or (it is an AMH ExceptionHolder).
  if (iface != 0)
    {
      int is_amh_exception_holder = this->is_amh_exception_holder (iface);
      AST_Decl::NodeType nt = iface->node_type ();

      if (nt != AST_Decl::NT_valuetype || is_amh_exception_holder)
        {
          *os << be_nl << throw_spec_open;
          *os << be_idt_nl << "CORBA::SystemException";

          if (node->exceptions ())
            {
              // Initialize an iterator to iterate thru the exception list.
              for (UTL_ExceptlistActiveIterator ei (node->exceptions ());
                   !ei.is_done ();
                   ei.next ())
                {
                  be_exception *excp =
                    be_exception::narrow_from_decl (ei.item ());

                  if (excp == 0)
                    {
                      ACE_ERROR_RETURN ((LM_ERROR,
                                         "(%N:%l) be_visitor_operation"
                                         "gen_throw_spec - "
                                         "bad exception node\n"),
                                        -1);

                    }

                  *os << be_nl << ", ";
                  *os << excp->name ();
                }
            }

          *os << be_uidt_nl << throw_spec_close << be_uidt;
        }
    }
  /*******************************************************************************/
  return 0;
}

int
be_visitor_operation::gen_environment_decl (int argument_emitted,
                                            be_operation *node)
{
  // Generate the CORBA::Environment parameter for the alternative mapping.
  if (be_global->exception_support ())
    {
      return 0;
    }

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

  // Use ACE_ENV_SINGLE_ARG_DECL or ACE_ENV_ARG_DECL depending on
  // whether the operation node has parameters.
  const char *env_decl = "ACE_ENV_SINGLE_ARG_DECL";

  if (this->ctx_->sub_state ()
        == TAO_CodeGen::TAO_AMH_RESPONSE_HANDLER_OPERATION
      && node->argument_count () == 0)
    {
      // Response handler operations don't use the environment arg
      // unless there are other args in the operation.
      env_decl = "ACE_ENV_SINGLE_ARG_DECL";
      this->ctx_->sub_state (TAO_CodeGen::TAO_SUB_STATE_UNKNOWN);
    }
  else if (argument_emitted || node->argument_count () > 0)
    {
      env_decl = "ACE_ENV_ARG_DECL";
    }

  TAO_CodeGen::CG_STATE cgs = this->ctx_->state ();

  if (node->argument_count () > 0
      || cgs == TAO_CodeGen::TAO_OPERATION_ARGLIST_BASE_PROXY_IMPL_CH
      || cgs == TAO_CodeGen::TAO_OPERATION_ARGLIST_PROXY_IMPL_XH
      || cgs == TAO_CodeGen::TAO_OPERATION_ARGLIST_PROXY_IMPL_XS)
    {
      *os << be_nl;
    }

  switch (this->ctx_->state ())
    {
    case TAO_CodeGen::TAO_OPERATION_ARGLIST_CH:
    case TAO_CodeGen::TAO_OPERATION_ARGLIST_COLLOCATED_SH:
    case TAO_CodeGen::TAO_OPERATION_ARGLIST_SH:
      // Last argument is always CORBA::Environment.
      *os << env_decl << "_WITH_DEFAULTS";
      break;
    default:
      *os << env_decl;
      break;
    }

  return 0;
}

// Method that returns the appropriate CORBA::Environment variable.
const char *
be_visitor_operation::gen_environment_var (void)
{
  static const char *ace_try_env_decl = "ACE_DECLARE_NEW_CORBA_ENV;";
  static const char *null_env_decl = "";

  // Check if we are generating stubs/skeletons for
  // true C++ exception support.
  if (be_global->exception_support ())
    {
      return ace_try_env_decl;
    }
  else
    {
      return null_env_decl;
    }
}

int
be_visitor_operation::gen_raise_exception (be_type *return_type,
                                           const char *exception_name,
                                           const char *exception_arguments)
{
  TAO_OutStream *os = this->ctx_->stream ();

  if (be_global->use_raw_throw ())
    {
      *os << "throw "
          << exception_name << "(" << exception_arguments << ");\n";
      return 0;
    }

  int is_void =
    return_type == 0 || this->void_return_type (return_type);

  if (is_void)
    {
      *os << "ACE_THROW (";
    }
  else
    {
      *os << "ACE_THROW_RETURN (";
    }

  *os << exception_name << " (" << exception_arguments << ")";

  if (is_void)
    {
      *os << ");";

      return 0;
    }

  *os << ",";

  // Non-void return type.
  be_visitor_context ctx (*this->ctx_);
  be_visitor_operation_rettype_return_cs visitor (&ctx);

  if (return_type->accept (&visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation::"
                         "gen_raise_exception - "
                         "codegen for return var failed\n"),
                        -1);
    }

  *os << ");";

  return 0;
}

int
be_visitor_operation::gen_check_exception (be_type *return_type)
{
  TAO_OutStream *os = this->ctx_->stream ();

  if (return_type == 0 || this->void_return_type (return_type))
    {
      *os << "ACE_CHECK;" << be_nl;
      return 0;
    }

  // Non-void return type....
  *os << "ACE_CHECK_RETURN (";
  be_visitor_context ctx (*this->ctx_);
  be_visitor_operation_rettype_return_cs visitor (&ctx);

  if (return_type->accept (&visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation::"
                         "gen_check_exception - "
                         "codegen for return var failed\n"),
                        -1);
    }

  *os << ");" << be_nl;
  return 0;
}

int
be_visitor_operation::gen_check_interceptor_exception (be_type *return_type)
{
  TAO_OutStream *os = this->ctx_->stream ();

  if (return_type == 0 || this->void_return_type (return_type))
    {
      *os << "TAO_INTERCEPTOR_CHECK;\n";
      return 0;
    }

  // Non-void return type.
  *os << "TAO_INTERCEPTOR_CHECK_RETURN (";
  be_visitor_context ctx (*this->ctx_);
  be_visitor_operation_rettype_return_cs visitor (&ctx);

  if (return_type->accept (&visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation::"
                         "gen_check_exception - "
                         "codegen for return var failed\n"),
                        -1);
    }

  *os << ");\n";
  return 0;
}

int
be_visitor_operation::gen_stub_operation_body (
    be_operation *node,
    be_type *return_type
  )
{
  be_interface *intf = this->ctx_->attribute ()
    ? be_interface::narrow_from_scope (this->ctx_->attribute ()->defined_in ())
    : be_interface::narrow_from_scope (node->defined_in ());

  if (!intf)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_thru_poa_collocated_ss::"
                         "visit_operation - "
                         "bad interface scope\n"),
                        -1);
    }

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

  *os << be_nl << "{" << be_idt_nl;

  if (node->has_native ()) // native exists => no stub
    {
      if (this->gen_raise_exception (return_type,
                                     "CORBA::MARSHAL",
                                     "") == -1)
        {
          ACE_ERROR_RETURN ((
              LM_ERROR,
              "(%N:%l) be_visitor_operation_cs::"
              "visit_operation - "
              "codegen for native exception failed\n"
            ),
            -1
          );
        }

      *os << be_uidt_nl << "}";

      return 0;
    }

  if (!node->is_abstract ())
    {
      // If the object is lazily evaluated the proxy brker might well
      // be null.  Initialize it now.
      *os << "if (!this->is_evaluated ())" << be_idt_nl
          << "{" << be_idt_nl
          << "ACE_NESTED_CLASS (CORBA, Object)::tao_object_initialize (this);"
          << be_uidt_nl
          << "}" << be_uidt_nl << be_nl
          << "if (this->the" << intf->base_proxy_broker_name () << "_ == 0)"
          << be_idt_nl
          << "{" << be_idt_nl
          << intf->flat_name () << "_setup_collocation (" 
          << be_idt << be_idt_nl
          << "this->ACE_NESTED_CLASS (CORBA, Object)::_is_collocated ()"
          << be_uidt_nl
          << ");" << be_uidt << be_uidt_nl
          << "}" << be_uidt_nl << be_nl;
    }

  const char *env = this->gen_environment_var ();

  if (ACE_OS::strcmp ("", env) != 0)
    {
      *os << env << be_nl;
    }

  // Declare return type helper class.

  *os << "TAO::Arg_Traits<";

  this->gen_arg_template_param_name (return_type, os);

  *os << ">::stub_ret_val _tao_retval;";

  // Declare the argument helper classes.

  AST_Argument *arg = 0;

  for (UTL_ScopeActiveIterator arg_decl_iter (node, UTL_Scope::IK_decls);
       ! arg_decl_iter.is_done ();
       arg_decl_iter.next ())
    {
      arg = AST_Argument::narrow_from_decl (arg_decl_iter.item ());

      *os << be_nl
          << "TAO::Arg_Traits<";

      this->gen_arg_template_param_name (arg->field_type (), os);

      *os << ">::";

      switch (arg->direction ())
        {
          case AST_Argument::dir_IN:
            *os << "in";
            break;
          case AST_Argument::dir_INOUT:
            *os << "inout";
            break;
          case AST_Argument::dir_OUT:
            *os << "out";
          default:
            break;
        }

      *os << "_arg_val _tao_" << arg->local_name () << " ("
          << arg->local_name () << ");";
    }

  *os << be_nl << be_nl
      << "TAO::Argument *_tao_signature [] =" << be_idt_nl
      << "{" << be_idt_nl
      << "&_tao_retval";

  for (UTL_ScopeActiveIterator arg_list_iter (node, UTL_Scope::IK_decls);
       ! arg_list_iter.is_done ();
       arg_list_iter.next ())
    {
      arg = AST_Argument::narrow_from_decl (arg_list_iter.item ());

      *os << "," << be_nl
          << "&_tao_" << arg->local_name ();
    }

  *os << be_uidt_nl
      << "};" << be_uidt;

  *os << be_nl << be_nl
      << "TAO::Invocation_Adapter _tao_call (" << be_idt << be_idt_nl
      << "this," << be_nl
      << "_tao_signature," << be_nl
      << node->argument_count () + 1 << "," << be_nl
      << "\"" << node->local_name () << "\"," << be_nl
      << ACE_OS::strlen (node->local_name ()->get_string ()) << "," << be_nl
      << "this->the" << intf->base_proxy_broker_name () << "_";

  if (node->flags () == AST_Operation::OP_oneway)
    {
      *os << "," << be_nl
          << "TAO::TAO_ONEWAY_INVOCATION";
    }

  if (be_global->ami_call_back ())
    {
      *os << "," << be_nl
          << "TAO::TAO_ASYNCHRONOUS_CALLBACK_INVOCATION";
    }

  *os << be_uidt_nl
      << ");" << be_uidt;

  *os << be_nl << be_nl;

  // Since oneways cannot raise user exceptions, we have that
  // case covered as well.
  if (node->exceptions ())
    {
      *os << "_tao_call.invoke (" << be_idt << be_idt_nl
          << "_tao_" << node->flat_name ()
          << "_exceptiondata," << be_nl
          << node->exceptions ()->length () << be_nl
          << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
          << ");" << be_uidt;
    }
  else
    {
      *os << "_tao_call.invoke (0, 0 ACE_ENV_ARG_PARAMETER);";
    }

  *os << be_nl;

  if (this->void_return_type (return_type))
    {
      *os << "ACE_CHECK;";
    }
  else
    {
      *os << "ACE_CHECK_RETURN (_tao_retval.excp ());";
    }

  if (!this->void_return_type (return_type))
    {
      *os << be_nl << be_nl
          << "return _tao_retval.retn ();";
    }

  *os << be_uidt_nl << "}";

  return 0;
}

int
be_visitor_operation::gen_pre_stub_info (
    be_operation *node
  )
{
  be_visitor_context ctx = *this->ctx_;
  be_visitor_operation_exceptlist_cs visitor (&ctx);

  if (node->accept (&visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) "
                         "be_visitor_operation_cs::"
                         "gen_pre_stub_info - "
                         "Exceptionlist generation error\n"),
                        -1);
    }

  return 0;
}

int
be_visitor_operation::gen_marshal_and_invoke (
    be_operation *node,
    be_type *bt
  )
{
  TAO_OutStream *os = this->ctx_->stream ();
  be_visitor_context ctx;
  const char *target = "_collocated_tao_target_";

  if (node->defined_in ()->is_abstract ())
    {
      target = "this";
    }


  os->indent ();

  *os << be_nl;

  // Create the GIOP_Invocation and grab the outgoing CDR stream.
  switch (node->flags ())
    {
    case AST_Operation::OP_oneway:
      *os << "TAO_GIOP_Oneway_Invocation _tao_call ";
      break;
    default:
      *os << "TAO_GIOP_Twoway_Invocation _tao_call ";
    }

  // Do we have "_set_" or "_get_" prepended?
  size_t ext = this->ctx_->attribute () ? 5 : 0;

  // Do we have any arguments in the operation that needs marshalling
  int flag =
    node->count_arguments_with_direction (AST_Argument::dir_IN
                                          | AST_Argument::dir_INOUT);

  *os << "(" << be_idt << be_idt_nl
      << "istub," << be_nl
      << this->compute_operation_name (node)
      << "," << be_nl
      << ACE_OS::strlen (node->original_local_name ()->get_string ()) + ext
      << "," << be_nl
      << flag
      << "," <<be_nl
      << "istub->orb_core ()" << be_uidt_nl
      << ");" << be_uidt_nl;

  *os << be_nl
      << "int _invoke_status;" << be_nl;

  // Generate code to obtain the client request interceptors from the
  // ORB.
  *os << "\n#if (TAO_HAS_INTERCEPTORS == 1)" << be_nl;
  *os << "TAO_ClientRequestInterceptor_Adapter _tao_vfr ("
      << be_idt << be_idt_nl
      << "istub->orb_core ()->client_request_interceptors ()," << be_nl
      << "&_tao_call," << be_nl
      << "_invoke_status"
      << be_uidt_nl
      << ");" << be_uidt_nl;

  *os << "\n#endif  /* TAO_HAS_INTERCEPTORS */" << be_nl;

  // The connection retry loop.
  *os << be_nl
      << "for (;;)" << be_idt_nl
      << "{" << be_idt_nl
      << "_invoke_status = TAO_INVOKE_EXCEPTION;" << be_nl;


  *os << "\n#if TAO_HAS_INTERCEPTORS == 1" << be_nl;

  *os << "TAO_ClientRequestInfo_" << node->flat_name ();

  // We need the interface node in which this operation was defined. However,
  // if this operation node was an attribute node in disguise, we get this
  // information from the context and add a "_get"/"_set" to the flat
  // name to get around the problem of overloaded methods which are
  // generated for attributes.
  if (this->ctx_->attribute ())
    {
      bt = be_type::narrow_from_decl (node->return_type ());

      if (!bt)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_interceptors_ch::"
                             "visit_operation - "
                             "Bad return type\n"),
                            -1);
        }

      // Grab the right visitor to generate the return type if its not
      // void it means it is not the accessor.
      if (!this->void_return_type (bt))
        {
          *os << "_get";
        }
      else
        {
          *os << "_set";
        }
    }

  *os << " _tao_ri (" << be_idt << be_idt_nl
      << "&_tao_call," << be_nl
      << target;

  // Generate the formal argument fields which are passed
  // to the RequestInfo object.
  ctx = *this->ctx_;
  ctx.state (TAO_CodeGen::TAO_OPERATION_INTERCEPTORS_INFO_ARGLIST_CS);
  be_visitor_operation_interceptors_arglist iia_visitor (&ctx);

  if (node->accept (&iia_visitor) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_remote_proxy_impl_cs::"
                         "visit_operation - "
                         "codegen for arglist failed\n"),
                        -1);
    }

  *os << be_uidt_nl << ");" << be_uidt_nl;

  if (this->gen_check_exception (bt) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_remote_proxy_impl_cs::"
                         "gen_marshal_and_invoke - "
                         "codegen for checking exception failed\n"),
                        -1);
    }

  *os << "\n#endif /* TAO_HAS_INTERCEPTORS */" << be_nl;

 // Prepare the request header.
  *os << be_nl << "CORBA::Short _tao_response_flag = ";

  switch (node->flags ())
    {
    case AST_Operation::OP_oneway:
      *os << "_tao_call.sync_scope ();" << be_nl
          << "TAO_INTERCEPTOR (_tao_ri.response_expected (0));" << be_nl;
      break;
    default:
      *os << "TAO_TWOWAY_RESPONSE_FLAG;" << be_nl
          << "TAO_INTERCEPTOR (_tao_ri.response_expected (1));" << be_nl;
    }

  *os << "\n#if TAO_HAS_INTERCEPTORS == 1" << be_nl;

  *os << be_nl << "ACE_TRY" << be_idt_nl
      << "{" << be_idt_nl;

  // Invoke send_request() interception point.
  // This is done before the Invocation::start() call so that a
  // connection can be avoided if send_request() throws an exception,
  // i.e. this is an optimization.
  *os << "_tao_vfr.send_request (" << be_idt << be_idt_nl
      << "&_tao_ri" << be_nl
      << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
      << ");" << be_uidt_nl
      << "ACE_TRY_CHECK;" << be_nl;

  // _invoke_status is potentially set (via a reference) in
  // TAO_ClientRequestInterceptor_Adapter::send_request() so check its
  // value.  If a location forward or transport retry occured, then we
  // need to restart the loop so that the ClientRequestInfo object is
  // setup for the re-issued request.
  //
  // Note that since we're invoking the send_request() interception
  // point before the Invocation::start() call, i.e. before a
  // connection is ever made, we're actually able to forward requests
  // for oneways via the PortableInterceptor::ForwardRequest exception
  // too!
  *os  << be_nl
       << "if (_invoke_status == TAO_INVOKE_RESTART)" << be_idt_nl
       << "{" << be_idt_nl
       << "_tao_call.restart_flag (1);" << be_uidt_nl
       << "}" << be_uidt_nl
       << "else" << be_idt_nl
       << "{" << be_idt_nl;

  *os << "\n#endif /* TAO_HAS_INTERCEPTORS */" << be_nl;


  *os << be_nl
      << "_tao_call.start (ACE_ENV_SINGLE_ARG_PARAMETER);" << be_nl;

  // Check if there is an exception.
  if (this->gen_check_interceptor_exception (bt) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_remote_proxy_impl_cs::"
                         "gen_marshal_and_invoke - "
                         "codegen for checking exception failed\n"),
                        -1);
    }

 *os << be_nl
      << "_tao_call.prepare_header (" << be_idt << be_idt_nl
      << "ACE_static_cast (CORBA::Octet, _tao_response_flag)" << be_nl
      << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
      << ");" << be_uidt_nl;

  // Check if there is an exception.
  if (this->gen_check_interceptor_exception (bt) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_remote_proxy_impl_cs::"
                         "gen_marshal_and_invoke - "
                         "codegen for checking exception failed\n"),
                        -1);
    }

  // Now make sure that we have some in and inout parameters. Otherwise, there
  // is nothing to be marshaled in.
  if (this->has_param_type (node, AST_Argument::dir_IN) ||
      this->has_param_type (node, AST_Argument::dir_INOUT))
    {
      *os << be_nl
          << "TAO_OutputCDR &_tao_out = _tao_call.out_stream ();"
          << be_nl << be_nl
          << "if (!(" << be_idt << be_idt_nl;

      // Marshal each in and inout argument.
      ctx = *this->ctx_;
      ctx.state (TAO_CodeGen::TAO_OPERATION_ARG_INVOKE_CS);
      ctx.sub_state (TAO_CodeGen::TAO_CDR_OUTPUT);
      be_visitor_operation_argument_invoke oai_visitor (&ctx);

      if (node->accept (&oai_visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_cs::"
                             "gen_marshal_and_invoke - "
                             "codegen for return var in "
                             "do_static_call failed\n"),
                            -1);
        }

      *os << be_nl
          << "))" << be_uidt_nl
          << "{" << be_idt_nl;

      // If marshaling fails, raise exception (codesetting has various minors)
      *os << "TAO_OutputCDR::throw_stub_exception (errno "
          << "ACE_ENV_ARG_PARAMETER); "
          << be_nl;

      if (this->gen_check_interceptor_exception (bt) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_cs::"
                             "gen_marshal_and_invoke - "
                             "codegen for checking exception failed\n"),
                            -1);
        }

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

  *os << "_invoke_status =" << be_idt_nl;

  if (node->flags () == AST_Operation::OP_oneway)
    {
      // Oneway operation.
      *os << "_tao_call.invoke (ACE_ENV_SINGLE_ARG_PARAMETER);";
    }
  else
    {
      if (node->exceptions ())
        {
          *os << "_tao_call.invoke (_tao_" << node->flat_name ()
              << "_exceptiondata, "
              << node->exceptions ()->length ()
              << " ACE_ENV_ARG_PARAMETER);";
        }
      else
        {
          *os << "_tao_call.invoke (0, 0 ACE_ENV_ARG_PARAMETER);";
        }
    }

  *os << be_uidt_nl;

  // Check if there is an exception.
  if (this->gen_check_interceptor_exception (bt) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_cs::"
                         "gen_marshal_and_invoke - "
                         "codegen for checking exception failed\n"),
                        -1);
    }

  *os << be_nl
      << "if (_invoke_status == TAO_INVOKE_EXCEPTION)" << be_idt_nl
      << "{" << be_idt_nl;

  // Unlisted user exception received by client.
  int status = this->gen_raise_interceptor_exception (
                         bt,
                         "CORBA::UNKNOWN",
                         "CORBA::OMGVMCID | 1, CORBA::COMPLETED_YES"
                       );

  if (status == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_cs::"
                         "gen_marshal_and invoke - "
                         "codegen for return var failed\n"),
                        -1);
    }

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

  // Note that we no longer turn this code generation off if it's a
  // one way operation since the sync scope policy may actually allow
  // things such as LOCATION_FORWARD replies to be propagated back to
  // the client (e.g. SYNC_WITH_TARGET).

  *os << "else if (_invoke_status == TAO_INVOKE_RESTART)" << be_idt_nl
      << "{" << be_idt_nl
      << "_tao_call.restart_flag (1);" << be_nl
      << "TAO_INTERCEPTOR (" << be_idt << be_idt_nl
      << "_tao_ri.reply_status (_invoke_status);" << be_nl
      << "_tao_vfr.receive_other (" << be_idt << be_idt_nl
      << "&_tao_ri" << be_nl
      << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
      << ");" << be_uidt_nl
      << "ACE_TRY_CHECK;" << be_uidt_nl
      << ")" << be_uidt << be_uidt_nl
      << "}" << be_uidt_nl
      << "else" << be_idt_nl
      << "{" << be_idt;

  // If we reach here, we are ready to proceed.
  // the code below this is for twoway operations only.

  if (!this->void_return_type (bt)
      || this->has_param_type (node, AST_Argument::dir_INOUT)
      || this->has_param_type (node, AST_Argument::dir_OUT))

    {
      // Do any post_invoke stuff that might be necessary.
      ctx = *this->ctx_;
      ctx.state (TAO_CodeGen::TAO_OPERATION_ARG_POST_INVOKE_CS);
      ctx.sub_state (TAO_CodeGen::TAO_CDR_INPUT);
      be_visitor_operation_argument oapi_visitor (&ctx);

      if (node->accept (&oapi_visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_cs::"
                             "gen_marshal_and_invoke - "
                             "codegen for args in post do_static_call\n"),
                            -1);
        }

      // Generate any temporary variables to demarshal the arguments.
      be_visitor_args_decl vis1 (&ctx);

      if (node->accept (&vis1) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_cs::"
                             "gen_pre_stub_info - "
                             "codegen for pre args failed\n"),
                            -1);
        }

      if (!this->void_return_type (bt))
        {
          // Generate any temporary variables to demarshal the return value.
          be_visitor_operation_rettype_post_invoke_cs vis2 (&ctx);

          if (bt->accept (&vis2) == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "(%N:%l) be_visitor_operation_cs::"
                                 "gen_pre_stub_info - "
                                 "codegen rettype [post invoke] failed\n"),
                                -1);
            }
        }

      // Check if there was a user exception, else demarshal the
      // return val (if any) and parameters (if any) that came with
      // the response message.
      *os << be_nl << be_nl
          << "TAO_InputCDR &_tao_in = _tao_call.inp_stream ();"
          << be_nl ;

      //  Added so codeset translators may be used to decode reply
      *os << "_tao_call.transport()->assign_translators (&_tao_in,0);"
          << be_nl << be_nl;

      // reply
      *os << "if (!(" << be_idt << be_idt;

      if (!this->void_return_type (bt))
        {
          // Demarshal the return value.
          ctx = *this->ctx_;
          ctx.sub_state (TAO_CodeGen::TAO_CDR_INPUT);
          be_visitor_operation_rettype_marshal_ss ori_visitor (&ctx);

          if (node->accept (&ori_visitor) == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "(%N:%l) be_visitor_operation_cs::"
                                 "gen_marshal_and_invoke - "
                                 "codegen for return var failed\n"),
                                -1);
            }
        }

      if (this->has_param_type (node, AST_Argument::dir_INOUT)
          || this->has_param_type (node, AST_Argument::dir_OUT))
        {
          if (!this->void_return_type (bt))
            {
              *os << " &&" << be_nl;
            }

          // Demarshal each out and inout argument.
          ctx = *this->ctx_;
          ctx.state (TAO_CodeGen::TAO_OPERATION_ARG_INVOKE_CS);
          ctx.sub_state (TAO_CodeGen::TAO_CDR_INPUT);
          be_visitor_operation_argument_invoke oai_visitor (&ctx);

          if (node->accept (&oai_visitor) == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "(%N:%l) be_visitor_operation_cs::"
                                 "gen_marshal_and_invoke - "
                                 "codegen for return var failed\n"),
                                -1);
            }
        }

      *os << be_nl
          << "))" << be_uidt_nl
          << "{" << be_idt_nl;

      // If marshaling fails, raise exception (codesetting has various minors)
      *os << "TAO_InputCDR::throw_stub_exception (errno "
          << "ACE_ENV_ARG_PARAMETER); "
          << be_nl;
      if (this->gen_check_interceptor_exception (bt) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_cs::"
                             "gen_marshal_and_invoke - "
                             "codegen for checking exception failed\n"),
                            -1);
        }

      *os << be_nl;

      if (status == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_operation_cs::"
                             "gen_marshal_and invoke - "
                             "codegen for return var failed\n"),
                            -1);
        }

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

  *os << "\n#if TAO_HAS_INTERCEPTORS == 1"  << be_nl;

  // Populate the ClientRequestInfo object with result, if any, of the
  // invocation.
  if (!this->void_return_type (bt))
    {
      // Here's what we are going to do to have a uniform way of getting the
      // return value updated for the Request Info:
      // declare a operation_retval type object and assign the
      // _tao_retval._retn () to it.
      // We pass this to the result updation method (note: it hasnt
      // got destroyed)
      // We then put it back into the original _tao_retval
      // object.
      // And finally the _retn () is returned from the operation w.o
      // causing any problems.

      // Generate the return type mapping (same as in the header file)
      ctx = *this->ctx_;
      be_visitor_operation_rettype oro_visitor (&ctx);

      if (bt->accept (&oro_visitor) == -1)
        {
          ACE_ERROR_RETURN ((
              LM_ERROR,
              "(%N:%l) be_visitor_operation_remote_proxy_impl_cs::"
              "visit_operation - "
              "codegen for return type failed\n"
            ),
            -1
          );
        }

      if (bt->size_type () == AST_Type::VARIABLE
          || bt->node_type () == AST_Decl::NT_array)
        {
          *os << " _tao_retval_info =" << be_idt_nl
              << "_tao_retval._retn ();" << be_uidt_nl
              << "_tao_ri.result (_tao_retval_info);" << be_nl
              << "_tao_retval = _tao_retval_info;" << be_nl;
        }
      else
        {
          *os << " _tao_retval_info =" << be_idt_nl
              << "_tao_retval;" << be_uidt_nl
              << "_tao_ri.result (_tao_retval_info);" << be_nl;
        }
    }

  // Oneway operations don't have receive_reply() interception since
  // once the request goes over the wire, its the end of the story!
  // However, we still need to call an ending interception point
  // (receive_other()) to satisfy the General Flow Rules.
  if (node->flags () != AST_Operation::OP_oneway)
    {
      // If we get this far (in the generated code) then we
      // successfully completed the request, i.e. no connection retry
      // will occur, nor will a LOCATION_FORWARD.
      // Invoke receive_reply() interception point.
      *os << be_nl
          << "_tao_ri.reply_status (_invoke_status);" << be_nl
          << "_tao_vfr.receive_reply (" << be_idt << be_idt_nl
          << "&_tao_ri" << be_nl
          << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
          << ");" << be_uidt_nl;
    }
  else if (node->flags () == AST_Operation::OP_oneway)
    {
      // Invoke receive_other() interception point.
      *os << be_nl
          << "_tao_ri.reply_status (_invoke_status);" << be_nl
          << "_tao_vfr.receive_other (" << be_idt_nl
          << "&_tao_ri" << be_nl
          << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
          << ");" << be_nl;
    }

  *os << "ACE_TRY_CHECK;"
      << be_uidt_nl;

  *os << "\n#endif  /* TAO_HAS_INTERCEPTORS */" << be_nl;

  *os << "}" << be_uidt << be_uidt_nl;  // End inner "else" block.

  // Note that we do NOT catch the PortableInterceptor::ForwardRequest
  // exception here.  It is caught in the
  // TAO_ClientRequestInterceptor_Adapter class.  This is necessary to
  // prevent applications from being able to throw the exception in an
  // effort to get an easy (but illegal) way to forward a request.

  *os << "\n#if TAO_HAS_INTERCEPTORS == 1"  << be_nl
      << "}" << be_uidt << be_uidt_nl // End outer "else" block.
      << "}" << be_uidt_nl
      << "ACE_CATCHANY" << be_idt_nl
      << "{" << be_idt_nl;

  // Update the exception field of the ClientRequestInfo.
  *os << "_tao_ri.exception (&ACE_ANY_EXCEPTION);"<< be_nl;

  *os << "_tao_vfr.receive_exception (" << be_idt << be_idt_nl
      << "&_tao_ri" << be_nl
      << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
      << ");" << be_uidt_nl
      << "ACE_TRY_CHECK;" << be_nl;

  // The receive_exception() interception point may have thrown a
  // PortableInterceptor::ForwardRequest exception.  In that event,
  // the connection retry loop must be restarted so do not rethrow the
  // caught exception.
  *os << be_nl
      << "const PortableInterceptor::ReplyStatus _tao_status =" << be_idt_nl
      << "_tao_ri.reply_status (ACE_ENV_SINGLE_ARG_PARAMETER);" << be_uidt_nl
      << "ACE_TRY_CHECK;" << be_nl;

  *os << be_nl
      << "if (_tao_status == PortableInterceptor::SYSTEM_EXCEPTION" << be_nl
      << "    || _tao_status == PortableInterceptor::USER_EXCEPTION)"
      << be_idt_nl
      << "{" << be_idt_nl;

  if (be_global->use_raw_throw ())
    {
      *os << "throw;";
    }
  else
    {
      *os << "ACE_RE_THROW;";
    }

  *os << be_uidt_nl
      << "}" << be_uidt << be_uidt_nl;

  *os << "}" << be_uidt_nl;

  // Convert non-CORBA C++ exceptions to CORBA::UNKNOWN.
  *os << "\n# if defined (ACE_HAS_EXCEPTIONS) \\\n"
      << "     && defined (ACE_HAS_BROKEN_UNEXPECTED_EXCEPTIONS)" << be_nl
      << "ACE_CATCHALL" << be_idt_nl
      << "{" << be_idt_nl
      << "CORBA::UNKNOWN ex;" << be_nl
      << be_nl
      << "_tao_ri.exception (&ex);"<< be_nl
      << "_tao_vfr.receive_exception (" << be_idt << be_idt_nl
      << "&_tao_ri" << be_nl
      << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
      << ");" << be_uidt_nl
      << "ACE_TRY_CHECK;" << be_nl;

  // The receive_exception() interception point may have thrown a
  // PortableInterceptor::ForwardRequest exception.  In that event,
  // the connection retry loop must be restarted so do not throw the
  // CORBA::UNKNOWN exception to convert the unhandled C++ exception.
  *os << be_nl
      << "const PortableInterceptor::ReplyStatus _tao_status =" << be_idt_nl
      << "_tao_ri.reply_status (ACE_ENV_SINGLE_ARG_PARAMETER);" << be_uidt_nl
      << "ACE_TRY_CHECK;" << be_nl;

  *os << be_nl
      << "if (_tao_status == PortableInterceptor::SYSTEM_EXCEPTION)"
      << be_idt_nl;

  if (be_global->use_raw_throw ())
    {
      *os << "throw ";
    }
  else
    {
      *os << "ACE_TRY_THROW ";
    }

  *os << "(ex);" << be_uidt << be_uidt_nl
      << "}" << be_uidt
      << "\n# endif  /* ACE_HAS_EXCEPTIONS"
      << " && ACE_HAS_BROKEN_UNEXPECTED_EXCEPTIONS */" << be_nl << be_nl;

  *os << "ACE_ENDTRY;" << be_nl;

  if (this->gen_check_exception (bt) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_cs::"
                         "gen_marshal_and_invoke - "
                         "codegen for checking exception failed\n"),
                        -1);
    }

  // The receive_exception() or receive_other() interception point may
  // have thrown a PortableInterceptor::ForwardRequest exception.  In
  // that event, the connection retry loop must be restarted.  Note
  // that the _invoke_status variable is not set by the interceptor
  // support code, so we must explicitly check the status in the
  // ClientRequestInfo object.
  *os << be_nl
      << "const PortableInterceptor::ReplyStatus _tao_status =" << be_idt_nl
      << "_tao_ri.reply_status (ACE_ENV_SINGLE_ARG_PARAMETER);" << be_uidt_nl;

  if (this->gen_check_exception (bt) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_operation_cs::"
                         "gen_marshal_and_invoke - "
                         "codegen for checking exception failed\n"),
                        -1);
    }

  *os << be_nl
      << "if (_tao_status != PortableInterceptor::LOCATION_FORWARD" << be_nl
      << "    && _tao_status != PortableInterceptor::TRANSPORT_RETRY)"
      << be_idt_nl;
  // Continue to below break statement."
  *os << "\n#endif  /* TAO_HAS_INTERCEPTORS */" << be_nl;

  *os << be_nl
      << "if (_invoke_status != TAO_INVOKE_RESTART)" << be_idt_nl
      << "break;" << be_uidt << be_uidt << be_uidt_nl
      << "}" << be_uidt;

  return 0;
}

int
be_visitor_operation::gen_raise_interceptor_exception (
    be_type *bt,
    const char *excep,
    const char *completion_status
  )
{
  TAO_OutStream *os = this->ctx_->stream ();

  if (this->void_return_type (bt))
    {
      if (be_global->use_raw_throw ())
        {
          *os << "throw " << excep << "(" << completion_status << ");";
        }
      else
        {
          *os << "TAO_INTERCEPTOR_THROW (" << be_idt << be_idt_nl
              << excep << " (" << be_idt << be_idt_nl
              << completion_status << be_uidt_nl
              << ")" << be_uidt << be_uidt_nl
              << ");" << be_uidt;
        }
    }
  else
    {
      if (bt->size_type () == AST_Type::VARIABLE
          || bt->base_node_type () == AST_Decl::NT_array)
        {
          *os << "TAO_INTERCEPTOR_THROW_RETURN (" << be_idt << be_idt_nl
              << excep << " (" << be_idt << be_idt_nl
              << completion_status << be_uidt_nl
              << ")," << be_uidt_nl
              <<  "0" << be_uidt_nl
              << ");" << be_uidt;
        }
      else
        {
          *os << "TAO_INTERCEPTOR_THROW_RETURN (" << be_idt << be_idt_nl
              << excep << " (" << be_idt << be_idt_nl
              << completion_status << be_uidt_nl
              << ")," << be_uidt_nl
              <<  "_tao_retval" << be_uidt_nl
              << ");" << be_uidt;
        }
    }

  return 0;
}

const char*
be_visitor_operation::compute_operation_name (
    be_operation *node
  )
{
  if (this->operation_name_ == 0)
    {
      // Length for two double quotes and the null termination char.
      size_t len = 3;

      if (this->ctx_->attribute ())
        {
          // "Added length for "_set_" or "_get_".
          len += 5;
        }

      len += ACE_OS::strlen (node->original_local_name ()->get_string ());

      ACE_NEW_RETURN (this->operation_name_,
                      char [len],
                      0);

      ACE_OS::strcpy (this->operation_name_, "\"");

      if (this->ctx_->attribute ())
        {
          // Now check if we are a "get" or "set" operation.
          if (node->nmembers () == 1)
            {
              ACE_OS::strcat (this->operation_name_, "_set_");
            }
          else
            {
              ACE_OS::strcat (this->operation_name_, "_get_");
            }
        }

      ACE_OS::strcat (this->operation_name_,
                      node->original_local_name ()->get_string ());
      ACE_OS::strcat (this->operation_name_, "\"");
    }

  return this->operation_name_;
}

void
be_visitor_operation::gen_arg_template_param_name (AST_Type *bt,
                                                   TAO_OutStream *os)
{
  AST_Decl::NodeType nt = bt->node_type ();

  if (nt == AST_Decl::NT_typedef)
    {
      be_typedef *td = be_typedef::narrow_from_decl (bt);
      this->ctx_->alias (td);
      this->gen_arg_template_param_name (td->primitive_base_type (),
                                         os);
      this->ctx_->alias (0);
      return;
    }

  if (nt == AST_Decl::NT_string)
    {
      AST_String *s = AST_String::narrow_from_decl (bt);
      unsigned long bound = s->max_size ()->ev ()->u.ulval;
      AST_Typedef *alias = this->ctx_->alias ();

      if (bound > 0)
        {
          *os << "TAO::" << alias->local_name () << "_" << bound;
          return;
        }
    }

  if (nt == AST_Decl::NT_pre_defined)
    {
      AST_PredefinedType *pdt = AST_PredefinedType::narrow_from_decl (bt);

      switch (pdt->pt ())
        {
          case AST_PredefinedType::PT_boolean:
            *os << "ACE_InputCDR::to_boolean";
            return;
          case AST_PredefinedType::PT_octet:
            *os << "ACE_InputCDR::to_octet";
            return;
          case AST_PredefinedType::PT_char:
            *os << "ACE_InputCDR::to_char";
            return;
          case AST_PredefinedType::PT_wchar:
            *os << "ACE_InputCDR::to_wchar";
            return;
          default:
            break;
        }
    }

  *os << bt->name ();
}