summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_valuetype/valuetype_init_ch.cpp
blob: ffa84c7497ced0b6a6b65ef9cbc1e045173f2b60 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    valuetype_init_ch.cpp
//
// = DESCRIPTION
//    Visitor generating code for Valuetypes factory in the client header
//    (see IDL to C++ mapping). Based on ptc/00-01-02.
//
// = AUTHOR
//   Boris Kolpackov <bosk@ipmce.ru>
//
//
// ============================================================================

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

#include "be_visitor_valuetype.h"

ACE_RCSID(be_visitor_valuetype, valuetype_init_ch, "$Id$")

be_visitor_valuetype_init_ch::be_visitor_valuetype_init_ch (
    be_visitor_context *ctx
  )
  : be_visitor_valuetype_init (ctx)
{
}

be_visitor_valuetype_init_ch::~be_visitor_valuetype_init_ch (void)
{
}

int
be_visitor_valuetype_init_ch::visit_valuetype (be_valuetype *node)
{

  if (node->is_abstract_valuetype ())
  {
    return 0;
  }

  // There are three possible situations.
  // (1) If there is no initializers but at least one operation.
  //     In this case we don't need to bother about factory.
  //
  // (2) There are no (operations or initializers) (i.e. only state
  //     members) then we need a concrete type-specific factory
  //     class whose create_for_unmarshal creates OBV_ class.
  //
  // (3) There is at least one operation and at least one initializer.
  //     In this case we need to generate abstract factory class.

  FactoryStyle factory_style = determine_factory_style (node);

  if(factory_style == FS_NO_FACTORY) // nothing to do
    {
      return 0; // bail out
    }

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

  // Generate the ifdef macro for the _init class.
  os.gen_ifdef_macro (node->flat_name (), "_init");


  //@@ If I'm generating concrete class I need a RefCounter
  os << "class " << be_global->stub_export_macro ()
     << " " << node->local_name ()
     << "_init : public virtual CORBA_ValueFactoryBase" << be_nl;

  // generate the body
  os << "{" << be_nl
     << "public:" << be_idt_nl;

  if(factory_style == FS_CONCRETE_FACTORY)
    {
      // public ctor
      os << node->local_name () << "_init ();" << be_nl;
    }

  // virtual public dtor
  os << "virtual ~" << node->local_name () << "_init ();" << be_nl;


  // custom methods
  os << be_nl;

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

  os << be_nl;

  // generate _downcast method
  os << "static " << node->local_name () << "_init* "
     << "_downcast (CORBA_ValueFactoryBase* );" << be_nl;

  if(factory_style == FS_CONCRETE_FACTORY)
    {
      //@@ Boris: create_for_unmarshal is still public...
      // generate create_for_unmarshal
      os << be_nl
         << "virtual CORBA_ValueBase* "
         << "create_for_unmarshal" << " "
         << "(void);" << be_nl;
    }

  os << be_nl;

    // propriate extensions
  os << "// TAO-specific extensions"
     << be_uidt_nl
     << "public:" << be_idt_nl;

  os << "virtual const char* tao_repository_id (void);\n";

  if(factory_style == FS_ABSTRACT_FACTORY)
    {
      // protected ctor
      os << be_uidt_nl
         << "protected:" << be_idt_nl;

      os << node->local_name () << "_init ();";

    }

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

  // Generate the endif macro.
  os.gen_endif ();

  return 0;
}

int
be_visitor_valuetype_init_ch::visit_factory (be_factory *node)
{

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

  be_valuetype *vt =
    be_valuetype::narrow_from_decl (this->ctx_->scope ());


  // STEP I: Generate preambule.
  os << "virtual " << vt->local_name () << "* ";

  // STEP 2: Generate the operation name.
  os << node->local_name ();

  // STEP 3: Generate the argument list with the appropriate mapping. For these
  // we grab a visitor that generates the parameter listing.
  be_visitor_context ctx (*this->ctx_);
  ctx.state (TAO_CodeGen::TAO_VALUETYPE_INIT_ARGLIST_CH);
  be_visitor* visitor = tao_cg->make_visitor (&ctx);

  if (!visitor)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_valuetype_init_ch::"
                         "visit_factory - "
                         "Bad visitor to argument list\n"),
                        -1);
    }

  if (node->accept (visitor) == -1)
    {
      delete visitor;
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_valuetype_init_arglist__ch::"
                         "visit_operation - "
                         "codegen for argument list failed\n"),
                        -1);
    }

  delete visitor;

  // make pure virtual
  os << " = 0;" << be_nl;

  return 0;
}