summaryrefslogtreecommitdiff
path: root/TAO/tests/IDL_Test/union.idl
blob: 0ea237b65e2fa1e8a348b93300b2a22493bb5180 (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

//=============================================================================
/**
 *  @file    union.idl
 *
 *  This file contains examples of IDL code that has
 *  caused problems in the past for the TAO IDL
 *  compiler. This test is to make sure the problems
 *  stay fixed.
 *
 *
 *  @author Jeff Parsons <parsons@cs.wustl.edu> and TAO users.
 */
//=============================================================================


// Implicit default case

enum DataType
{
  dtEmpty,
  dtLong,
  dtShort
};

union Data switch (DataType)
{
  case dtLong: long longData;
  case dtShort: short shortData;
  // by default, empty union
};

// Explicit default case

module Necessary
{
  // It is important to have a module, in which
  // the following union is declared.

  typedef long Result;

  enum Kind
    {
      e_Result,
      e_Unused
    };

  union WhichResult switch (Kind )
    {
      case e_Result: Result  m_Result;
      default: long m_Unused;
    };
};

// Union with negative cases
// At the moment, the SunCC preprocessor separates the negative
// sign from the number.  This causes problems for the scanner/lexer
// used by tao_idl.
#if !defined (__SUNPRO_CC) || (__SUNPRO_CC > 0x5140)
union foo switch (short)
{
  case -3:
  case  4:
  case -1: string foo_str_member;
  default: long   foo_iface_member;
  case  0: long   foo_iface_member2;
};
#endif // !__SUNPRO_CC || __SUNPRO_CC > 0x5120

// Make sure that CORBA_Any::to_* is used everywhere.
module UnionDiscTest
{
  union BooleanUnion switch (boolean)
    {
      case TRUE: string value;
    };

  union CharUnion switch (char)
    {
      case 'a': string value;
    };
};

module AllBoolUnions
{
  union OneBranchT switch (boolean) { case TRUE: octet val; };
  union OneBranchF switch (boolean) { case FALSE: octet val; };
  union OneBranchD switch (boolean) { default: octet val; };
  union OneBranchTF switch (boolean) { case TRUE: case FALSE: octet val; };
  union OneBranchFT switch (boolean) { case FALSE: case TRUE: octet val; };
  union OneBranchTD switch (boolean) { case TRUE: default: octet val; };
  union OneBranchDT switch (boolean) { default: case TRUE: octet val; };
  union OneBranchFD switch (boolean) { case FALSE: default : octet val; };
  union OneBranchDF switch (boolean) { default: case FALSE: octet val; };
  union TwoBranchesTF switch (boolean) { case TRUE: octet val1; case FALSE: char val2; };
  union TwoBranchesFT switch (boolean) { case FALSE: octet val1; case TRUE: char val2; };
  union TwoBranchesTD switch (boolean) { case TRUE: octet val1; default: char val2; };
  union TwoBranchesDT switch (boolean) { default: octet val1; case TRUE: char val2; };
  union TwoBranchesFD switch (boolean) { case FALSE: octet val1; default: char val2; };
  union TwoBranchesDF switch (boolean) { default: octet val1; case FALSE: char val2; };
};

// Nested unions

enum disc1
{
  one,
  two
};

enum disc2
{
  a,
  b
};

enum disc_outer
{
  out1,
  out2
};

union inner1 switch (disc1)
{
  case one: short s;
  case two: long l;
};

union inner2 switch (disc2)
{
  case a: char c;
  case b: long lng;
};

union outer switch (disc_outer)
{
  case out1: inner1 first;
  case out2: inner2 second;
};

module UnionTest3
{
   enum ValChoice
     {
       intVal,
       realVal
     };

   union ValType switch(ValChoice)
     {
       case intVal: long integerValue;
       case realVal: double realValue;
     };

   struct UpType
     {
       ValType high;
       ValType low;
     };

   struct DownType
     {
       ValType high;
       ValType low;
     };

   enum IndChoice
     {
       up_Level,
       down_Level
     };

   union IndType switch(IndChoice)
     {
       case up_Level: UpType up;
       case down_Level: DownType down;
     };
};

// Make sure inner union is generated in header file with
// proper scoping (or lack thereof) in its name, depending
// on the platform.
enum XType
{
  X_A
};

enum ZType
{
  Z_A
};

union X switch (XType)
{
  case X_A:
    struct Y
      {
        union Z switch (ZType)
        {
          case Z_A: long a;
        } u;
      } a;
};

// Example involving union members with multiple case labels.
enum FieldType
{
    FTYPE_CHAR,
    FTYPE_VARCHAR,
    FTYPE_DEFCHAR
};

union FieldValue switch (FieldType)
{
    case FTYPE_CHAR:
    case FTYPE_VARCHAR:
       string strValue;
    default:
       string defstr;
};


struct Field
{
  FieldValue value;
};

// A fix to the IDL compiler's typecode generation created
// a problem with unions that have more than one member,
// where any member except the last is itself a scoped type.
// This is the simplest example that will reproduce the problem,
// if it ever reappears.
enum TestOneEnum
{
  TALL,
  SCHORT
};

enum TestTwoEnum
{
  LIGHT,
  DARK
};

union TestUnion switch (short)
{
  case 1: TestOneEnum oneEnum;
  case 2: TestTwoEnum twoEnum;
};

typedef long U41[2][3];
typedef long U42[2];

union U85 switch (long) {
  case 1: U41 b_85_1;
  case 2: U42 b_85_2;
};

typedef string UString[2];
union U86 switch (long) {
  case 1: string b_86_1;
  case 2: long b_86_2;
};
union U88 switch (long) {
  case 1: UString b_86_1;
  case 2: long b_86_2;
};

struct UBar {
  long foo;
};
typedef UBar UBarArray[2];

union U87 switch (long) {
  case 1: UBar b_87_1;
  case 2: long b_87_2;
};
union U89 switch (long) {
  case 1: UBarArray b_87_1;
  case 2: long b_87_2;
};

enum U90
{
  U90_1,
  U90_2
};

typedef U90 U90Array[2];

union U91 switch (long) {
  case 1: U90Array b_91_1;
  case 2: long b_92_2;
};

union U92 switch (long) {
  case 1: UBar b_92_1;
  case 2: long b_92_2;
  default: UBar b_92_3;
};

union U93 switch (long) {
  case 1: UBarArray b_93_1;
  case 2: long b_93_2;
  default: UBarArray b_93_3;
};

union U94 switch (long) {
  case 1: U90Array b_94_1;
  case 2: long b_94_2;
  default: U90Array b_94_3;
};