summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be_include/be_visitor_typecode/typecode_defn.h
blob: d9674eef9f34c69935649dcc9fd2b1b5953680ba (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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// -*- C++ -*-
//
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    typecode_defn.h
//
// = DESCRIPTION
//    Concrete visitor for the generation of TypeCodes.
//    This one generates the definitions.
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#ifndef _BE_VISITOR_TYPECODE_TYPECODE_DEFN_H_
#define _BE_VISITOR_TYPECODE_TYPECODE_DEFN_H_

#include "ace/CDR_Base.h"
#include "ace/Containers_T.h"
#include "be_visitor_decl.h"
#include "be_visitor_scope.h"

const int TAO_BE_VISITOR_TYPECODE_DEFN_MAX_STACK_SIZE = 1024;

class AST_Structure;

class be_visitor_typecode_defn : public be_visitor_scope
{
  //
  // = TITLE
  //    be_visitor_typecode_defn
  //
  // = DESCRIPTION
  //    This is a concrete visitor for generating TypeCode definitions
  //

public:
  be_visitor_typecode_defn (be_visitor_context *ctx);
  // constructor

  ~be_visitor_typecode_defn (void);
  // destructor

  //virtual int visit_members (AST_Structure *node);
  // for use with structs, exceptions, and unions.

//   virtual int visit_members (be_valuetype *node);
  // for use with valuetypes.

  virtual int visit_type (be_type *node);
  // visit a generic be_type node

  // =visit methods on all types. They call the generic visit_type

  virtual int visit_array (be_array *node);
  // visit a array

//   virtual int visit_enum (be_enum *node);
  // visit an enum

  virtual int visit_exception (be_exception *node);
  // visit an enum

//   virtual int visit_interface (be_interface *node);
  // visit interface

  virtual int visit_interface_fwd (be_interface_fwd *node);
  // visit interface

  virtual int visit_component (be_component *node);
  // visit component

  virtual int visit_predefined_type (be_predefined_type *node);
  // visit predefined types

  virtual int visit_sequence (be_sequence *node);
  // visit a sequence

  virtual int visit_string (be_string *node);
  // visit a structure

//   virtual int visit_structure (be_structure *node);
  // visit a structure

  virtual int visit_union (be_union *node);
  // visit a union

//   virtual int visit_valuetype (be_valuetype *node);
//   // visit a valuetype

//   virtual int visit_eventtype (be_eventtype *node);
//   // visit a valuetype


  // = visit methods for the scope elements

//   virtual int visit_enum_val (be_enum_val *node);
//   // visit the enumeration values

  virtual int visit_field (be_field *node);
  // visit the field (struct and exception member)

  virtual int visit_union_branch (be_union_branch *node);
  // visit the union member

  // = special methods

  virtual int gen_nested_namespace_begin (be_module *node);
  // generate the nested namespace begins

  virtual int gen_nested_namespace_end (be_module *node);
  // generate the nested namespace ends

  // = methods for generating typecodes

  int gen_typecode (be_array *node);

//   int gen_typecode (be_enum *node);

  int gen_typecode (be_exception *node);

//   int gen_typecode (be_interface *node);

  int gen_typecode (be_interface_fwd *node);

  int gen_typecode (be_predefined_type *node);

  int gen_typecode (be_sequence *node);

  int gen_typecode (be_string *node);

//   int gen_typecode (be_structure *node);

//   int gen_typecode (be_typedef *node);

  int gen_typecode (be_union *node);

//   int gen_typecode (be_valuetype *node);

  // = methods to generate encapsulations for typecodes

  int gen_encapsulation (be_array *node);

//   int gen_encapsulation (be_enum *node);

//   int gen_encapsulation (be_enum_val *node);

  int gen_encapsulation (be_exception *node);

  int gen_encapsulation (be_field *node);

//   int gen_encapsulation (be_interface *node);

  int gen_encapsulation (be_interface_fwd *node);

  int gen_encapsulation (be_predefined_type *node);

  int gen_encapsulation (be_sequence *node);

  int gen_encapsulation (be_string *node);

//   int gen_encapsulation (be_structure *node);

  int gen_encapsulation (be_typedef *node);

  int gen_encapsulation (be_union *node);

  int gen_encapsulation (be_union_branch *node);

//   int gen_encapsulation (be_valuetype *node);

  // = methods for computing typecode sizes

  ACE_CDR::Long compute_tc_size (be_array *node);

//   ACE_CDR::Long compute_tc_size (be_enum *node);

  ACE_CDR::Long compute_tc_size (be_exception *node);

//   ACE_CDR::Long compute_tc_size (be_interface *node);

  ACE_CDR::Long compute_tc_size (be_interface_fwd *node);

  ACE_CDR::Long compute_tc_size (be_predefined_type *node);

  ACE_CDR::Long compute_tc_size (be_sequence *node);

  ACE_CDR::Long compute_tc_size (be_string *node);

//   ACE_CDR::Long compute_tc_size (be_structure *node);

  ACE_CDR::Long compute_tc_size (be_typedef *node);

  ACE_CDR::Long compute_tc_size (be_union *node);

//   ACE_CDR::Long compute_tc_size (be_valuetype *node);

  // methods for computing the encapsulation length

  ACE_CDR::Long compute_encap_length (be_array *node);

//   ACE_CDR::Long compute_encap_length (be_enum *node);

//   ACE_CDR::Long compute_encap_length (be_enum_val *node);

  ACE_CDR::Long compute_encap_length (be_exception *node);

  ACE_CDR::Long compute_encap_length (be_field *node);

//   ACE_CDR::Long compute_encap_length (be_interface *node);

  ACE_CDR::Long compute_encap_length (be_interface_fwd *node);

  ACE_CDR::Long compute_encap_length (be_predefined_type *node);

  ACE_CDR::Long compute_encap_length (be_sequence *node);

  ACE_CDR::Long compute_encap_length (be_string *node);

//   ACE_CDR::Long compute_encap_length (be_structure *node);

  ACE_CDR::Long compute_encap_length (be_typedef *node);

  ACE_CDR::Long compute_encap_length (be_union *node);

  ACE_CDR::Long compute_encap_length (be_union_branch *node);

//   ACE_CDR::Long compute_encap_length (be_valuetype *node);

  // helpers to generate the repoID and name

  void gen_repoID (be_decl *node);

  void gen_name (be_decl *node);

  // helpers to generate encap len of the repoID and name

  ACE_CDR::ULong repoID_encap_len (be_decl *node);

  ACE_CDR::ULong name_encap_len (be_decl *node);

  // helper to get an array of long from a name

  int tc_name2long (const char *name,
                    ACE_CDR::ULong *&larr,
                    ACE_CDR::ULong &arrlen);

  // processing for scopes

  virtual int post_process (be_decl *);
  // do any processing after every element except the last one of the scope is
  // processed

  // data structure for handling recursive and repeated typecodes

  struct QNode
  {
    be_type *node;
    ACE_CDR::Long offset;
  };

protected:

  /// Generate the TypeCode_ptr.
  /**
   * Generate actual TypeCode instance/definition, not the supporting
   * code, e.g.  "static CORBA::TypeCode_ptr const Foo_ptr = ...".
   */
  int gen_typecode_ptr (be_type * node);

private:

  //
  friend class Scoped_Compute_Queue_Guard;

  ACE_CDR::Long computed_tc_size_;
  // the tc size of the node under consideration

  ACE_CDR::Long computed_encap_len_;
  // the encap length of the node under consideration

  ACE_CDR::Long computed_scope_encap_len_;
  // the encap length of the scope of the node under consideration

  // the following are used for recursive and repeated typecodes

  ACE_CDR::Long tc_offset_;
  // current computed length of the typecode

  ACE_Unbounded_Queue <QNode*> tc_queue_;
  // queue to keep nodes

  ACE_Unbounded_Queue <QNode*> compute_queue_;
  // queue to keep nodes

  ACE_CDR::Long scope_stack_ [TAO_BE_VISITOR_TYPECODE_DEFN_MAX_STACK_SIZE];
  // stores scope lens during computation

  // scope related routines

  int index_;

  int push (ACE_CDR::Long);

  int pop (ACE_CDR::Long &);

  // queue related routines

  const QNode *queue_insert (ACE_Unbounded_Queue <QNode*> &,
                             be_type *node, ACE_CDR::Long offset);

  const QNode *queue_lookup (ACE_Unbounded_Queue <QNode*> &, be_type *node);

  void queue_reset (ACE_Unbounded_Queue <QNode*> &);

};

#endif /* _BE_VISITOR_TYPECODE_TYPECODE_DEFN_H_ */