summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_home/home_exh.cpp
blob: b9bc66cac489e3fbf9df5872a60c2649eb467ea3 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO_IDL_BE
//
// = FILENAME
//    home_exh.cpp
//
// = DESCRIPTION
//    Visitor generating code for homes in the exec impl header.
//
// = AUTHOR
//    Jeff Parsons
//
// ============================================================================

ACE_RCSID (be_visitor_home,
           home_exh,
           "$Id$")

// ******************************************************
// Home visitor for exec impl header
// ******************************************************

be_visitor_home_exh::be_visitor_home_exh (be_visitor_context *ctx)
  : be_visitor_scope (ctx),
    node_ (0),
    comp_ (0),
    os_ (*ctx->stream ()),
    export_macro_ (be_global->exec_export_macro ())
{
}

be_visitor_home_exh::~be_visitor_home_exh (void)
{
}

int
be_visitor_home_exh::visit_home (be_home *node)
{
  if (node->imported ())
    {
      return 0;
    }
    
  node_ = node;
  comp_ = node_->managed_component ();
  
  /// CIDL-generated namespace used 'CIDL_' + composition name.
  /// Now we use 'CIAO_' + component's flat name.
  os_ << be_nl << be_nl
      << "namespace CIAO_" << comp_->flat_name () << "_Impl" << be_nl
      << "{" << be_idt;
    
  if (this->gen_exec_class () == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_home_exh::")
                         ACE_TEXT ("visit_home - ")
                         ACE_TEXT ("gen_servant_class() failed\n")),
                        -1);
    }
     
  this->gen_entrypoint ();

  os_ << be_uidt_nl
      << "}";
     
  return 0;
}

int
be_visitor_home_exh::visit_operation (be_operation *node)
{
  be_visitor_operation_ch v (this->ctx_);
  return v.visit_operation (node);
}

int
be_visitor_home_exh::visit_attribute (be_attribute *node)
{
  be_visitor_attribute v (this->ctx_);
  return v.visit_attribute (node);
}

int
be_visitor_home_exh::gen_exec_class (void)
{
  // We don't want a '_cxx_' prefix here.
  const char *lname =
    node_->original_local_name ()->get_string ();
  
  os_ << be_nl
      << "class " << export_macro_.c_str () << " " << lname
      << "_exec_i" << be_idt_nl
      << ": public virtual " << lname << "_Exec," << be_idt_nl
      << "public virtual ::CORBA::LocalObject"
      << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt;
      
  os_ << be_nl
      << lname << "_exec_i (void);";
      
  os_ << be_nl << be_nl
      << "virtual ~" << lname << "_exec_i (void);";
      
  this->gen_ops_attrs ();
 
  this->gen_factories ();
  
  this->gen_finders ();
  
  os_ << be_nl << be_nl
      << "// Implicit operations.";
      
  os_ << be_nl << be_nl
      << "virtual ::Components::EnterpriseComponent_ptr" << be_nl
      << "create (void);";

  os_ << be_uidt_nl
      << "};";
     
  return 0;
}

int
be_visitor_home_exh::gen_ops_attrs (void)
{
  os_ << be_nl << be_nl
      << "// All operations and attributes.";
      
  int status =
    node_->traverse_inheritance_graph (
      be_visitor_home_exh::op_attr_decl_helper,
      &os_);
      
  if (status == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_home_exh::")
                         ACE_TEXT ("gen_ops_attrs - ")
                         ACE_TEXT ("traverse_inheritance_graph() ")
                         ACE_TEXT ("failed\n")),
                        -1);
    }
    
  return 0;
}

int
be_visitor_home_exh::gen_factories (void)
{
  os_ << be_nl << be_nl
      << "// Factory operations.";
  
  return this->gen_factories_r (node_);
}

int
be_visitor_home_exh::gen_factories_r (AST_Home *node)
{
  if (node == 0)
    {
      return 0;
    }
    
  if (this->gen_init_ops_i (node->factories ()) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_home_exh::")
                         ACE_TEXT ("gen_factories_r - ")
                         ACE_TEXT ("gen_init_ops_i() failed\n")),
                        -1);
    }
    
  AST_Home *base = node->base_home ();
  
  return this->gen_factories_r (base);
}

int
be_visitor_home_exh::gen_finders (void)
{
  os_ << be_nl << be_nl
      << "// Finder operations.";
  
  return this->gen_finders_r (node_);
}

int
be_visitor_home_exh::gen_finders_r (AST_Home *node)
{
  if (node == 0)
    {
      return 0;
    }
    
  if (this->gen_init_ops_i (node->finders ()) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_home_exh::")
                         ACE_TEXT ("gen_finders_r - ")
                         ACE_TEXT ("gen_init_ops_i() failed\n")),
                        -1);
    }
    
  AST_Home *base = node->base_home ();
  
  return this->gen_finders_r (base);
}

int
be_visitor_home_exh::gen_init_ops_i (AST_Home::INIT_LIST & list)
{
  AST_Operation **op = 0;
  
  for (AST_Home::INIT_LIST::ITERATOR i = list.begin ();
       !i.done ();
       i.advance ())
    {
      i.next (op);
      be_operation *bop = be_operation::narrow_from_decl (*op);
      
      /// Return type for home exec factories and finders is not
      /// the same as for the corresponding home servant, so we
      /// generate the return type and op name by hand, then finish
      /// the operation traversal with an arglist visitor.
      os_ << be_nl << be_nl
          << "::Components::EnterpriseComponent_ptr" << be_nl
          << bop->local_name ();
          
      be_visitor_operation_arglist visitor (this->ctx_);
      
      if (visitor.visit_operation (bop) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_home_exh::")
                             ACE_TEXT ("gen_init_ops_i - ")
                             ACE_TEXT ("visit_operation() failed\n")),
                            -1);
        }
        
      os_ << ";";
    }
    
  return 0;
}

void
be_visitor_home_exh::gen_entrypoint (void)
{
  os_ << be_nl << be_nl
      << "extern \"C\" " << export_macro_.c_str ()
      << " ::Components::HomeExecutorBase_ptr" << be_nl
      << "create_" << node_->flat_name ()
      << "_Impl (void);"; 
}

int
be_visitor_home_exh::op_attr_decl_helper (be_interface * /* derived */,
                                          be_interface *ancestor,
                                          TAO_OutStream *os)
{
  /// We're in a static method, so we have to instantiate a temporary
  /// visitor and context.
  be_visitor_context ctx;
  ctx.state (TAO_CodeGen::TAO_ROOT_EXH);
  ctx.stream (os);
  be_visitor_home_exh visitor (&ctx);
  
  /// Since this visitor overriddes only visit_operation() and 
  /// visit_attribute(), we can get away with this for the declarations.
  return visitor.visit_scope (ancestor);
}