summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_typecode/value_typecode.cpp
blob: eecc25f598a5eb29a1cba8d71b9da3a8ec1995de (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file  value_typecode.cpp
 *
 *  $Id$
 *
 *  Structure TypeCode generation visitor.
 *
 *  @author  Ossama Othman <ossama@dre.vanderbilt.edu>
 */
//=============================================================================


#include <string>


TAO::be_visitor_value_typecode::be_visitor_value_typecode (
  be_visitor_context * ctx)
  : be_visitor_typecode_defn (ctx)
{
}

int
TAO::be_visitor_value_typecode::visit_valuetype (be_valuetype * node)
{
  TAO_OutStream & os = *this->ctx_->stream ();

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

  size_t const count =
    node->data_members_count ();

  /*
  if (count == 1 &&
      count == node->nmembers ()  // Verify no operations.
      && node->n_inherits () == 0)
    {
      // Generate a value box TypeCode.  It is more compact than a
      // valuetype TypeCode.

      UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);

      AST_Decl * const d = si.item ();

      ACE_ASSERT (d);

      AST_Field * const field = AST_Field::narrow_from_decl (d);

      ACE_ASSERT (field);

      be_type * const member_type =
        be_type::narrow_from_decl (field->field_type ());

      // Generate the TypeCode instantiation.
      os
        << "static TAO::TypeCode::Value_Box<char const *," << be_nl
        << "                                TAO::Null_RefCount_Policy> const"
        << be_idt_nl
        << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl
        << "\"" << node->repoID () << "\"," << be_nl
        << "\"" << node->original_local_name () << "\"," << be_nl
        << "&"  << member_type->tc_name () << ");" << be_uidt_nl
        << be_uidt_nl;
    }
  else
  */
    {
      std::string const fields_name (std::string ("_tao_fields_")
                                     + node->flat_name ());

      // Generate array containing struct field characteristics.
      os << "static TAO::TypeCode::Value_Field<char const *> const "
         << fields_name.c_str ();

      if (count == 0)
        {
          os << " * const = 0;" << be_nl;
        }
      else
        {
          os << "[] =" << be_idt_nl
             << "{" << be_idt_nl;

          if (this->visit_members (node) != 0)
            return -1;

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

      // Generate the TypeCode instantiation.

      os << be_nl
         << "static TAO::TypeCode::Value<char const *," << be_nl
         << "                            TAO::TypeCode::Value_Field<char const *> const *," << be_nl
         << "                            CORBA::tk_"
         << (dynamic_cast<be_eventtype *> (node) ? "event" : "value") << "," << be_nl
         << "                            TAO::Null_RefCount_Policy> const"
         << be_idt_nl
         << "_tao_tc_" << node->flat_name () << " (" << be_idt_nl
         << "\"" << node->repoID () << "\"," << be_nl
         << "\"" << node->original_local_name () << "\"," << be_nl;

      // ValueModifier
      //
      // TAO doesn't support CUSTOM or TRUNCATABLE valuetypes.  Go
      // with VM_NONE or VM_ABSTRACT.
      os << "CORBA::"
         << (node->is_abstract () ? "VM_ABSTRACT" : "VM_NONE") << "," << be_nl;

      // Concrete base type.
      AST_ValueType * const concrete_base =
        node->inherits_concrete ();

      if (concrete_base)
        {
          be_type * const base_type =
            be_type::narrow_from_decl (concrete_base);

          ACE_ASSERT (base_type);

          os << "&" << base_type->tc_name () << "," << be_nl;
        }
      else
        {
          // No concrete base.
          os << "&CORBA::tk_null," << be_nl;
        }

      // Fields
      os << "_tao_fields_" << node->flat_name () << "," << be_nl
         << count << ");" << be_uidt_nl
         << be_uidt_nl;
    }

  return
    this->gen_typecode_ptr (be_type::narrow_from_decl (node));
}

int
TAO::be_visitor_value_typecode::visit_members (be_valuetype * node)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  size_t const count =
    node->data_members_count ();

  size_t i = 0;

  for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next(), ++i)
    {
      AST_Decl * const d = si.item ();

      if (!d)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_value_typecode::visit_members - "
                             "bad node in this scope\n"), 0);
        }

      AST_Field * const field = AST_Field::narrow_from_decl (d);

      if (!field)
        {
          continue;
        }

      be_decl * const member_decl =
        be_decl::narrow_from_decl (field);

      be_type * const member_type =
        be_type::narrow_from_decl (field->field_type ());

      os << "{ "
         << "\"" << member_decl->original_local_name () << "\", "
         << "&"  << member_type->tc_name () << ", ";

      AST_Field::Visibility const vis = field->visibility ();

      switch (vis)
        {
        case AST_Field::vis_PUBLIC:
          os << "CORBA::PUBLIC_MEMBER";
          break;

        case AST_Field::vis_PRIVATE:
          os << "CORBA::PRIVATE_MEMBER";
          break;

        default:
          ACE_ERROR_RETURN ((LM_ERROR,
                             "(%N:%l) be_visitor_value_typecode::visit_members - "
                             "Unknown valuetype member visibility.\n"),
                            -1);
        };

      os << " }";


      if (i < count - 1)
        os << ",";

      os << be_nl;
    }

  return 0;
}