summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_root.cpp
blob: 4fbe89ebf3a3d41aecf97e3fce5501dfd3e33dea (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
// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    be_root.cpp
//
// = DESCRIPTION
//    Extension of class AST_Root that provides additional means for C++
//    mapping.
//
// = AUTHOR
//    Copyright 1994-1995 by Sun Microsystems, Inc.
//    and
//    Aniruddha Gokhale
//
// ============================================================================

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

// Default Constructor
be_root::be_root (void)
{
}

// Constructor used to build the root of the abstract syntax tree (AST)
be_root::be_root (UTL_ScopedName *n, UTL_StrList *p)
  : AST_Root (n, p),
    AST_Decl (AST_Decl::NT_root, n, p),
    UTL_Scope (AST_Decl::NT_root)

{
}

// =====================================================
//           CODE GENERATION METHODS
// =====================================================

// Starting point for the code generation. Called inside BE_produce ()
int be_root::gen_idl2cplusplus_mapping (void)
{
  // this is the main starting point from which the files are generated. We
  // delegate the task of code generation to a special Code Generation
  // object. This allows a number of different front ends to access the services
  // of a single code generator

  // C++ mapping involves producing 6 files. These include the client and
  // server side headers, the client and server side inlines, as well as client
  // stubs and server skeletons.
  if (this->gen_client_header () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error generating client header file: %s\n",
		  idl_global->be_get_client_hdr_fname ()));
      return -1;
    }
  if (this->gen_client_inline () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error generating client inline file: %s\n",
		  idl_global->be_get_client_inline_fname ()));
      return -1;
    }
  if (this->gen_client_stubs () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error generating client stubs file: %s\n",
		  idl_global->be_get_client_stub_fname ()));
      return -1;
    }
  if (this->gen_server_header () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error generating server header file: %s\n",
		  idl_global->be_get_server_hdr_fname ()));
      return -1;
    }
  if (this->gen_server_inline () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error generating server inline file: %s\n",
		  idl_global->be_get_server_inline_fname ()));
      return -1;
    }
  if (this->gen_server_skeletons () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error generating server skeleton file: %s\n",
		  idl_global->be_get_server_skeleton_fname ()));
      return -1;
    }

  return 0;
}

// generate client header
int be_root::gen_client_header (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_ROOT_CH); // set the code generation state

  // open the client-side header file
  if (cg->client_header (idl_global->be_get_client_hdr_fname ()) == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error opening client header\n"));
      return -1;
    }
  // delegate the task of code generation to the scope
  if (be_scope::gen_client_header () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: code generation for scope failed\n"));
      return -1;
    }
  cg->pop ();

  // at this point, we must be in the initial state
  ACE_ASSERT (cg->state () == TAO_CodeGen::TAO_INITIAL);

  (void) cg->end_client_header (); // generate the last #endif
  return 0;
}

// Generates the client-side stubs for the root
int be_root::gen_client_stubs (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_ROOT_CS); // set the code generation state

  // open the client-side stub file
  if (cg->client_stubs (idl_global->be_get_client_stub_fname ()) == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error opening client stubs file\n"));
      return -1;
    }
  // delegate the task of code generation to the scope
  if (be_scope::gen_client_stubs () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: code generation for scope failed\n"));
      return -1;
    }
  cg->pop ();

  // at this point, we must be in the initial state
  //  ACE_ASSERT (cg->state () == TAO_CodeGen::TAO_INITIAL);

  return 0;
}

// Generates the client-side inlines for the root
int be_root::gen_client_inline (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_ROOT_CI); // set the code generation state

  // open the client-side inline file
  if (cg->client_inline (idl_global->be_get_client_inline_fname ()) == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error opening client inline file\n"));
      return -1;
    }
  // delegate the task of code generation to the scope
  if (be_scope::gen_client_inline () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: code generation for scope failed\n"));
      return -1;
    }
  cg->pop ();

  // at this point, we must be in the initial state
  //  ACE_ASSERT (cg->state () == TAO_CodeGen::TAO_INITIAL);

  return 0;
}

// Generates the server-side header information for the root
int be_root::gen_server_header (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_ROOT_SH); // set the code generation state

  // open the server-side header file
  if (cg->server_header (idl_global->be_get_server_hdr_fname ()) == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error opening server header\n"));
      return -1;
    }
  // delegate the task of code generation to the scope
  if (be_scope::gen_server_header () == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "be_root: server code generation for scope failed\n"));
      return -1;
    }

  cg->pop ();

  // at this point, we must be in the initial state
  //  ACE_ASSERT (cg->state () == TAO_CodeGen::TAO_INITIAL);

  (void) cg->end_server_header (); // generate the last #endif statement
  return 0;
}

// Generates the server-side skeletons for the root
int be_root::gen_server_skeletons (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_ROOT_SS); // set the code generation state

  // open the server-side skeleton file
  if (cg->server_skeletons (idl_global->be_get_server_skeleton_fname ()) == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error opening server skeletons file\n"));
      return -1;
    }
  // delegate the task of code generation to the scope
  if (be_scope::gen_server_skeletons () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: code generation for scope failed\n"));
      return -1;
    }
  cg->pop ();

  // at this point, we must be in the initial state
  //  ACE_ASSERT (cg->state () == TAO_CodeGen::TAO_INITIAL);

  return 0;
}

// Generates the server-side inlines for the root
int be_root::gen_server_inline (void)
{
  // retrieve a singleton instance of the code generator
  TAO_CodeGen *cg = TAO_CODEGEN::instance ();
  cg->push (TAO_CodeGen::TAO_ROOT_SI); // set the code generation state

  // open the server-side inline file
  if (cg->server_inline (idl_global->be_get_server_inline_fname ()) == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: Error opening server inline file\n"));
      return -1;
    }
  // delegate the task of code generation to the scope
  if (be_scope::gen_server_inline () == -1)
    {
      ACE_ERROR ((LM_ERROR, "be_root: code generation for scope failed\n"));
      return -1;
    }
  cg->pop ();

  // at this point, we must be in the initial state
  //  ACE_ASSERT (cg->state () == TAO_CodeGen::TAO_INITIAL);

  return 0;
}

// We had to provide these since the AST_Root::fe_* method was setting the
// names of these three to "local type"

/*
 * Add this AST_Sequence to the locally defined types in this scope
 */
AST_Sequence *
be_root::fe_add_sequence (AST_Sequence *t)
{
  if (t == NULL)
    return NULL;

  add_to_local_types(t);
  return t;
}

/*
 * Add this AST_String to the locally defined types in this scope
 */
AST_String *
be_root::fe_add_string (AST_String *t)
{
  if (t == NULL)
    return NULL;

  add_to_local_types (t);

  return t;
}

/*
 * Add this AST_Array to the locally defined types in this scope
 */
AST_Array *
be_root::fe_add_array (AST_Array *t)
{
  if (t == NULL)
    return NULL;

  add_to_local_types (t);

  return t;
}

/*
 * Narrowing methods
 */
IMPL_NARROW_METHODS3 (be_root, AST_Root, be_scope, be_decl)
IMPL_NARROW_FROM_DECL (be_root)
IMPL_NARROW_FROM_SCOPE (be_root)