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 AST_Decl::NodeType
const
81 AST_Constant::NT
= AST_Decl::NT_const
;
83 // Used in constructing AST_EnumVal nodes.
84 AST_Constant::AST_Constant (AST_Expression::ExprType t
,
85 AST_Decl::NodeType nt
,
91 pd_constant_value (v
),
97 // Used when constructing AST_Constant nodes.
98 AST_Constant::AST_Constant (AST_Expression::ExprType t
,
102 AST_Decl (AST_Decl::NT_const
,
104 pd_constant_value (v
),
108 // Avoids a truncation warning on MSVC when assigning a decimal
109 // literal to a float constant. Must also check that the input
110 // expression is of type double (indicates that we are being
111 // assigned from a literal). If v is of type float, it may be
112 // a constant-to-constant assignment - in any case the danger
113 // of truncation would not apply.
114 if (t
== AST_Expression::EV_float
&& v
->ev ()->et
== AST_Expression::EV_double
)
116 AST_Expression::AST_ExprValue
*ev
=
117 this->pd_constant_value
->ev ();
119 ev
->u
.fval
= (float) ev
->u
.dval
;
121 // Allows the enum value string name to be used in generating the
122 // rhs of the constant assignment.
123 else if (t
== AST_Expression::EV_enum
)
125 this->pd_constant_value
->ev ()->et
= t
;
129 AST_Constant::~AST_Constant (void)
133 // Redefinition of inherited virtual operations.
135 // Dump this AST_Constant node to the ostream o.
137 AST_Constant::dump (ACE_OSTREAM_TYPE
&o
)
139 this->dump_i (o
, "const ");
140 dump_i (o
, AST_Expression::exprtype_to_string (pd_et
));
141 this->dump_i (o
, " ");
143 this->local_name ()->dump (o
);
145 this->dump_i (o
, " = ");
147 this->pd_constant_value
->dump (o
);
151 AST_Constant::ast_accept (ast_visitor
*visitor
)
153 return visitor
->visit_constant (this);
157 AST_Constant::destroy (void)
159 if (this->pd_constant_value
!= 0)
161 this->pd_constant_value
->destroy ();
162 delete this->pd_constant_value
;
163 this->pd_constant_value
= 0;
166 this->AST_Decl::destroy ();
172 AST_Constant::constant_value (void)
174 return this->pd_constant_value
;
177 AST_Expression::ExprType
178 AST_Constant::et (void)
184 AST_Constant::ifr_added (void)
186 return this->ifr_added_
;
190 AST_Constant::ifr_added (bool val
)
192 this->ifr_added_
= val
;
196 AST_Constant::enum_full_name (void)
198 if (this->pd_et
== AST_Expression::EV_enum
)
200 UTL_Scope
* const s
= this->defined_in ();
201 AST_Decl
* const d
= s
->lookup_by_name (this->pd_constant_value
->n (),
203 return (d
? (ScopeAsDecl (d
->defined_in ()))->name () : 0);
211 IMPL_NARROW_FROM_DECL(AST_Constant
)