Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / IDL_Test / union.idl
blob4aea781b9f6bca914414dbbf96b68e5b0f69ebb4
2 //=============================================================================
3 /**
4 * @file union.idl
6 * This file contains examples of IDL code that has
7 * caused problems in the past for the TAO IDL
8 * compiler. This test is to make sure the problems
9 * stay fixed.
12 * @author Jeff Parsons <parsons@cs.wustl.edu> and TAO users.
14 //=============================================================================
17 // Implicit default case
19 enum DataType
21 dtEmpty,
22 dtLong,
23 dtShort
26 union Data switch (DataType)
28 case dtLong: long longData;
29 case dtShort: short shortData;
30 // by default, empty union
33 // Explicit default case
35 module Necessary
37 // It is important to have a module, in which
38 // the following union is declared.
40 typedef long Result;
42 enum Kind
44 e_Result,
45 e_Unused
48 union WhichResult switch (Kind )
50 case e_Result: Result m_Result;
51 default: long m_Unused;
55 // Union with negative cases
56 // At the moment, the SunCC preprocessor separates the negative
57 // sign from the number. This causes problems for the scanner/lexer
58 // used by tao_idl.
59 #if !defined (__SUNPRO_CC) || (__SUNPRO_CC > 0x5140)
60 union foo switch (short)
62 case -3:
63 case 4:
64 case -1: string foo_str_member;
65 default: long foo_iface_member;
66 case 0: long foo_iface_member2;
68 #endif // !__SUNPRO_CC || __SUNPRO_CC > 0x5120
70 // Make sure that CORBA_Any::to_* is used everywhere.
71 module UnionDiscTest
73 union BooleanUnion switch (boolean)
75 case TRUE: string value;
78 union CharUnion switch (char)
80 case 'a': string value;
84 module AllBoolUnions
86 union OneBranchT switch (boolean) { case TRUE: octet val; };
87 union OneBranchF switch (boolean) { case FALSE: octet val; };
88 union OneBranchD switch (boolean) { default: octet val; };
89 union OneBranchTF switch (boolean) { case TRUE: case FALSE: octet val; };
90 union OneBranchFT switch (boolean) { case FALSE: case TRUE: octet val; };
91 union OneBranchTD switch (boolean) { case TRUE: default: octet val; };
92 union OneBranchDT switch (boolean) { default: case TRUE: octet val; };
93 union OneBranchFD switch (boolean) { case FALSE: default : octet val; };
94 union OneBranchDF switch (boolean) { default: case FALSE: octet val; };
95 union TwoBranchesTF switch (boolean) { case TRUE: octet val1; case FALSE: char val2; };
96 union TwoBranchesFT switch (boolean) { case FALSE: octet val1; case TRUE: char val2; };
97 union TwoBranchesTD switch (boolean) { case TRUE: octet val1; default: char val2; };
98 union TwoBranchesDT switch (boolean) { default: octet val1; case TRUE: char val2; };
99 union TwoBranchesFD switch (boolean) { case FALSE: octet val1; default: char val2; };
100 union TwoBranchesDF switch (boolean) { default: octet val1; case FALSE: char val2; };
103 // Nested unions
105 enum disc1
107 one,
111 enum disc2
117 enum disc_outer
119 out1,
120 out2
123 union inner1 switch (disc1)
125 case one: short s;
126 case two: long l;
129 union inner2 switch (disc2)
131 case a: char c;
132 case b: long lng;
135 union outer switch (disc_outer)
137 case out1: inner1 first;
138 case out2: inner2 second;
141 module UnionTest3
143 enum ValChoice
145 intVal,
146 realVal
149 union ValType switch(ValChoice)
151 case intVal: long integerValue;
152 case realVal: double realValue;
155 struct UpType
157 ValType high;
158 ValType low;
161 struct DownType
163 ValType high;
164 ValType low;
167 enum IndChoice
169 up_Level,
170 down_Level
173 union IndType switch(IndChoice)
175 case up_Level: UpType up;
176 case down_Level: DownType down;
180 // Make sure inner union is generated in header file with
181 // proper scoping (or lack thereof) in its name, depending
182 // on the platform.
183 enum XType
188 enum ZType
193 union X switch (XType)
195 case X_A:
196 struct Y
198 union Z switch (ZType)
200 case Z_A: long a;
201 } u;
202 } a;
205 // Example involving union members with multiple case labels.
206 enum FieldType
208 FTYPE_CHAR,
209 FTYPE_VARCHAR,
210 FTYPE_DEFCHAR
213 union FieldValue switch (FieldType)
215 case FTYPE_CHAR:
216 case FTYPE_VARCHAR:
217 string strValue;
218 default:
219 string defstr;
223 struct Field
225 FieldValue value;
228 // Tricky case of lookup for a recursive union. When defined
229 // inside another datatype like this, the union is referenced
230 // inside itself before the closing brace is seen, but not
231 // declared yet.
232 struct Element
234 union ValueUnion switch (short)
236 case 0:
237 long lvalue;
238 case 1:
239 sequence<ValueUnion> VUValue;
240 } Value;
243 // A fix to the IDL compiler's typecode generation created
244 // a problem with unions that have more than one member,
245 // where any member except the last is itself a scoped type.
246 // This is the simplest example that will reproduce the problem,
247 // if it ever reappears.
248 enum TestOneEnum
250 TALL,
251 SCHORT
254 enum TestTwoEnum
256 LIGHT,
257 DARK
260 union TestUnion switch (short)
262 case 1: TestOneEnum oneEnum;
263 case 2: TestTwoEnum twoEnum;
266 // Test for various kinds of declarations inside a union,
267 // similar to the example in enum_in_struct.idl.
269 typedef long NamedLongArray[10];
271 union decl_heavy_union switch (short)
273 case 1:
274 enum which
276 ZERO,
277 ONE,
279 } m_which;
280 case 2:
281 enum en
286 } m_en_arr[10];
287 case 3:
288 struct st
290 long a;
291 char b;
292 } m_st_arr[10];
293 case 4:
294 union un switch (long)
296 case 1: long a;
297 case 2: char b;
298 } m_un_arr[10];
299 // The following caused compile problems once
300 // when generating ostream ops
301 case 5:
302 NamedLongArray m_named_long_array;
303 case 6:
304 long m_anon_long_array[10];