summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_union/union_ci.cpp
blob: c545f646a65f9f615c903a606cfbaf4e86e8c5c0 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    union_ci.cpp
//
// = DESCRIPTION
//    Visitor generating code for Union in the client inline file
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include "be.h"
#include "be_visitor_union.h"

ACE_RCSID (be_visitor_union, 
           union_ci, 
           "$Id$")


// ******************************************************
// For client inline.
// ******************************************************

be_visitor_union_ci::be_visitor_union_ci (be_visitor_context *ctx)
  : be_visitor_union (ctx)
{
}

be_visitor_union_ci::~be_visitor_union_ci (void)
{
}

int be_visitor_union_ci::visit_union (be_union *node)
{
  be_visitor_context ctx (*this->ctx_);
  ctx.node (node);

  if (!node->cli_inline_gen () && !node->imported ())
    {
      TAO_OutStream *os = this->ctx_->stream ();

      *os << "// *************************************************************"
          << be_nl;
      *os << "// Inline operations for union " << node->name () << be_nl;
      *os << "// *************************************************************\n\n";

      // the discriminant type may have to be defined here if it was an enum
      // declaration inside of the union statement.

      be_type *bt = be_type::narrow_from_decl (node->disc_type ());

      if (!bt)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_union_ci::"
                             "visit_union - "
                             "bad discriminant type\n"), 
                            -1);
        }

      ctx.state (TAO_CodeGen::TAO_UNION_DISCTYPEDEFN_CI);
                                                         
      be_visitor_union_discriminant_ci visitor (&ctx);

      if (bt->accept (&visitor) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_union_ci::"
                             "visit union - "
                             "codegen for discrminant failed\n"), 
                            -1);
        }

      // Now generate the implementation of the access methods for the
      // union. For this set our state.
      this->ctx_->state (TAO_CodeGen::TAO_UNION_PUBLIC_CI);

      if (this->visit_scope (node) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_union_ci::"
                             "visit_union - "
                             "codegen for scope failed\n"), 
                            -1);
        }

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

      if (node->gen_var_impl () == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_union_ci::"
                             "visit_union - "
                             "codegen for _var failed\n"), 
                            -1);
        }

      os->gen_endif ();

      // Generate the ifdefined macro for the array type then generate the
      // _out impl
      os->gen_ifdef_macro (node->flat_name (), "_out");

      if (node->size_type () == be_decl::VARIABLE
          && node->gen_out_impl () == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_union_ci::"
                             "visit_union - "
                             "codegen for _out failed\n"), 
                            -1);
        }

      os->gen_endif ();

      node->cli_inline_gen (I_TRUE);
    }

  return 0;
}