5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
56 Mountain View, California 94043
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 // AST_Constant nodes denote IDL constant declarations.
66 // AST_Constants have a value (an AST_Expression) and a value type
67 // (a value from the enum AST_Expression::ExprType).
68 // AST_Constant has two constructors, one for use in creating constants
69 // and the other for use in creating enumerators (see the class
72 #include "ast_constant.h"
73 #include "utl_identifier.h"
74 #include "ast_visitor.h"
75 #include "ast_generator.h"
76 #include "nr_extern.h"
80 // Convert a value from the enum AST_Expression::ExprType to a char *.
82 AST_Constant::exprtype_to_string (AST_Expression::ExprType et
)
86 case AST_Expression::EV_short
:
88 case AST_Expression::EV_ushort
:
90 case AST_Expression::EV_long
:
92 case AST_Expression::EV_ulong
:
94 case AST_Expression::EV_float
:
96 case AST_Expression::EV_double
:
98 case AST_Expression::EV_char
:
100 case AST_Expression::EV_octet
:
102 case AST_Expression::EV_bool
:
104 case AST_Expression::EV_string
:
106 case AST_Expression::EV_ulonglong
:
108 case AST_Expression::EV_longlong
:
110 case AST_Expression::EV_wchar
:
112 case AST_Expression::EV_wstring
:
114 case AST_Expression::EV_longdouble
:
116 case AST_Expression::EV_fixed
:
125 AST_Decl::NodeType
const
126 AST_Constant::NT
= AST_Decl::NT_const
;
128 // Used in constructing AST_EnumVal nodes.
129 AST_Constant::AST_Constant (AST_Expression::ExprType t
,
130 AST_Decl::NodeType nt
,
136 pd_constant_value (v
),
142 // Used when constructing AST_Constant nodes.
143 AST_Constant::AST_Constant (AST_Expression::ExprType t
,
147 AST_Decl (AST_Decl::NT_const
,
149 pd_constant_value (v
),
153 // Avoids a truncation warning on MSVC when assigning a decimal
154 // literal to a float constant. Must also check that the input
155 // expression is of type double (indicates that we are being
156 // assigned from a literal). If v is of type float, it may be
157 // a constant-to-constant assignment - in any case the danger
158 // of truncation would not apply.
159 if (t
== AST_Expression::EV_float
&& v
->ev ()->et
== AST_Expression::EV_double
)
161 AST_Expression::AST_ExprValue
*ev
=
162 this->pd_constant_value
->ev ();
164 ev
->u
.fval
= (float) ev
->u
.dval
;
166 // Allows the enum value string name to be used in generating the
167 // rhs of the constant assignment.
168 else if (t
== AST_Expression::EV_enum
)
170 this->pd_constant_value
->ev ()->et
= t
;
174 AST_Constant::~AST_Constant (void)
178 // Redefinition of inherited virtual operations.
180 // Dump this AST_Constant node to the ostream o.
182 AST_Constant::dump (ACE_OSTREAM_TYPE
&o
)
184 this->dump_i (o
, "const ");
185 this->dump_i (o
, this->exprtype_to_string ());
186 this->dump_i (o
, " ");
188 this->local_name ()->dump (o
);
190 this->dump_i (o
, " = ");
192 this->pd_constant_value
->dump (o
);
196 AST_Constant::ast_accept (ast_visitor
*visitor
)
198 return visitor
->visit_constant (this);
202 AST_Constant::destroy (void)
204 if (this->pd_constant_value
!= 0)
206 this->pd_constant_value
->destroy ();
207 delete this->pd_constant_value
;
208 this->pd_constant_value
= 0;
211 this->AST_Decl::destroy ();
217 AST_Constant::constant_value (void)
219 return this->pd_constant_value
;
222 AST_Expression::ExprType
223 AST_Constant::et (void)
229 AST_Constant::ifr_added (void)
231 return this->ifr_added_
;
235 AST_Constant::ifr_added (bool val
)
237 this->ifr_added_
= val
;
241 AST_Constant::exprtype_to_string (void)
245 case AST_Expression::EV_short
:
246 return "CORBA::Short";
247 case AST_Expression::EV_ushort
:
248 return "CORBA::UShort";
249 case AST_Expression::EV_long
:
250 return "CORBA::Long";
251 case AST_Expression::EV_ulong
:
252 return "CORBA::ULong";
253 case AST_Expression::EV_float
:
254 return "CORBA::Float";
255 case AST_Expression::EV_double
:
256 return "CORBA::Double";
257 case AST_Expression::EV_char
:
258 return "CORBA::Char";
259 case AST_Expression::EV_octet
:
260 return "CORBA::Octet";
261 case AST_Expression::EV_bool
:
262 return "CORBA::Boolean";
263 case AST_Expression::EV_string
:
264 return "char *const";
265 case AST_Expression::EV_void
:
267 case AST_Expression::EV_none
:
269 case AST_Expression::EV_longlong
:
270 return "CORBA::LongLong";
271 case AST_Expression::EV_ulonglong
:
272 return "CORBA::ULongLong";
273 case AST_Expression::EV_wchar
:
274 return "CORBA::WChar";
275 case AST_Expression::EV_wstring
:
276 return "CORBA::WChar *const";
277 case AST_Expression::EV_fixed
:
287 AST_Constant::enum_full_name (void)
289 if (this->pd_et
== AST_Expression::EV_enum
)
291 UTL_Scope
* const s
= this->defined_in ();
292 AST_Decl
* const d
= s
->lookup_by_name (this->pd_constant_value
->n (),
294 return (d
? (ScopeAsDecl (d
->defined_in ()))->name () : 0);
302 IMPL_NARROW_FROM_DECL(AST_Constant
)