2 //=============================================================================
4 * @file be_union_branch.cpp
6 * Extension of class AST_UnionBranch that provides additional means for C++
9 * @author Copyright 1994-1995 by Sun Microsystems
10 * @author Inc. and Aniruddha Gokhale
12 //=============================================================================
14 #include "be_union_branch.h"
18 #include "be_visitor.h"
19 #include "be_helper.h"
20 #include "ast_union_label.h"
21 #include "ace/Log_Msg.h"
23 be_union_branch::be_union_branch (UTL_LabelList
*ll
,
26 : COMMON_Base (ft
->is_local (),
28 AST_Decl (AST_Decl::NT_union_branch
,
30 AST_Field (AST_Decl::NT_union_branch
,
36 be_decl (AST_Decl::NT_union_branch
,
44 be_union_branch::gen_label_value (TAO_OutStream
*os
, unsigned long index
)
46 AST_Expression
*e
= this->label (index
)->label_val ();
48 if (e
->ec () != AST_Expression::EC_symbol
)
50 // Easy, just a number...
55 // If the enum is not in the global scope we have to prefix it.
57 dynamic_cast<be_union
*> (this->defined_in ());
65 dynamic_cast<be_type
*> (u
->disc_type ());
72 // Check if discriminator is a typedef of an integer. If so, and the
73 // first IF block in this function didn't catch it, then we
74 // are a constant of this type. We can't generate the constant's name,
75 // we must generate the underlying integer value for the
77 if (dt
->node_type () == AST_Decl::NT_pre_defined
)
83 // Find where was the enum defined, if it was defined in the globa
84 // scope, then it is easy to generate the enum values....
86 dynamic_cast<be_scope
*> (dt
->defined_in ());
94 // But if it was generated inside a module or something similar then
95 // we must prefix the enum value with something...
96 be_decl
* decl
= scope
->decl ();
98 *os
<< decl
->full_name () << "::" << e
->n ()->last_component ();
104 be_union_branch::gen_default_label_value (TAO_OutStream
*os
,
107 be_union::DefaultValue dv
;
109 if (bu
->default_value (dv
) == -1)
111 ACE_ERROR_RETURN ((LM_ERROR
,
112 "(%N:%l) be_visitor_union_branch::"
113 "gen_default_label_value - "
114 "computing default value failed\n"),
118 switch (bu
->udisc_type ())
120 case AST_Expression::EV_short
:
121 *os
<< dv
.u
.short_val
;
123 case AST_Expression::EV_ushort
:
124 case AST_Expression::EV_wchar
:
125 *os
<< dv
.u
.ushort_val
;
127 case AST_Expression::EV_long
:
128 *os
<< dv
.u
.long_val
;
130 case AST_Expression::EV_ulong
:
131 *os
<< dv
.u
.ulong_val
;
133 case AST_Expression::EV_octet
:
134 case AST_Expression::EV_char
:
135 case AST_Expression::EV_int8
:
136 case AST_Expression::EV_uint8
:
137 os
->print ("'\\%o'", dv
.u
.char_val
);
139 case AST_Expression::EV_bool
:
140 *os
<< (dv
.u
.bool_val
== 0 ? "false" : "true");
142 case AST_Expression::EV_enum
:
143 // The discriminant is an enum. Some compilers will
144 // not accept a numeric value assigned to this
145 // discriminant, so we must generate the string name.
147 AST_ConcreteType
*act
= bu
->disc_type ();
148 be_enum
*be
= dynamic_cast<be_enum
*> (act
);
150 UTL_ScopedName
*sn
= be
->value_to_name (dv
.u
.enum_val
);
153 // The function value_to_name() takes care of adding
154 // any necessary scoping to the output.
155 *os
<< be
->value_to_name (dv
.u
.enum_val
);
159 // Since CORBA defines enums to be 32bits, use -1 as the
160 // out-of-bounds value for the _default() function.
161 *os
<< "(" << be
->name () << ") -1";
165 case AST_Expression::EV_longlong
:
166 *os
<< dv
.u
.longlong_val
;
168 case AST_Expression::EV_ulonglong
:
169 *os
<< dv
.u
.ulonglong_val
;
172 // Error caught earlier.
173 ACE_ERROR_RETURN ((LM_ERROR
,
174 "(%N:%l) be_visitor_union_branch::"
175 "gen_default_label_value - "
176 "bad or unimplemented discriminant type\n"),
184 be_union_branch::accept (be_visitor
*visitor
)
186 return visitor
->visit_union_branch (this);
190 be_union_branch::destroy ()
192 this->be_decl::destroy ();
193 this->AST_UnionBranch::destroy ();