1 // This may look like C, but it's really -*- C++ -*-
6 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
7 States of America. All Rights Reserved.
9 This product is protected by copyright and distributed under the following
10 license restricting its use.
12 The Interface Definition Language Compiler Front End (CFE) is made
13 available for your use provided that you include this license and copyright
14 notice on all media and documentation and the software program in which
15 this product is incorporated in whole or part. You may copy and extend
16 functionality (but may not remove functionality) of the Interface
17 Definition Language CFE without charge, but you are not authorized to
18 license or distribute it to anyone else except as part of a product or
19 program developed by you or with the express written consent of Sun
20 Microsystems, Inc. ("Sun").
22 The names of Sun Microsystems, Inc. and any of its subsidiaries or
23 affiliates may not be used in advertising or publicity pertaining to
24 distribution of Interface Definition Language CFE as permitted herein.
26 This license is effective until terminated by Sun for failure to comply
27 with this license. Upon termination, you shall destroy or return all code
28 and documentation for the Interface Definition Language CFE.
30 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
31 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
32 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
33 DEALING, USAGE OR TRADE PRACTICE.
35 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
36 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
37 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
39 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
40 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
41 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
43 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
44 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
45 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
47 Use, duplication, or disclosure by the government is subject to
48 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
49 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
52 Sun, Sun Microsystems and the Sun logo are trademarks or registered
53 trademarks of Sun Microsystems, Inc.
57 Mountain View, California 94043
61 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
62 trademarks or registered trademarks of Sun Microsystems, Inc.
66 #ifndef _AST_EXPRESSION_AST_EXPRESSION_HH
67 #define _AST_EXPRESSION_AST_EXPRESSION_HH
69 #include "ace/CDR_Stream.h"
70 #include "utl_scoped_name.h"
76 class AST_Param_Holder
;
79 // Representation of expression values.
81 // An expression (and maybe its value, if computed).
82 class TAO_IDL_FE_Export AST_Expression
85 // Enum to define all the different operators to combine expressions.
98 , EC_u_plus
// unary '+'
99 , EC_u_minus
// unary '-'
101 , EC_none
// No operator (missing).
102 , EC_symbol
// A symbol (function or constant name).
105 // Enum to define the different kinds of evaluation possible
106 // Extend this for more kinds of evaluation as required.
109 EK_const
// Must evaluate to constant.
110 , EK_positive_int
// Must evaluate to positive integer.
111 // @@ (JP) I added these to get the ~ operator to work with all the
112 // relevant aritmetic types, but eventually, we should get rid of
128 // Enum to define expression type.
131 EV_int8
// Signed Byte Sized Integer
132 , EV_uint8
// Unsigned Byte Sized Integer
133 , EV_short
// Expression value is short.
134 , EV_ushort
// Expression value is unsigned short.
135 , EV_long
// Expression value is long.
136 , EV_ulong
// Expression value is unsigned long.
137 , EV_longlong
// Expression value is long long.
138 , EV_ulonglong
// Expression value is unsigned long long.
139 , EV_float
// Expression value is 32-bit float.
140 , EV_double
// Expression value is 64-bit float.
141 , EV_longdouble
// Expression value is 128-bit float.
142 , EV_char
// Expression value is char.
143 , EV_wchar
// Expression value is wide char.
144 , EV_octet
// Expression value is unsigned char.
145 , EV_bool
// Expression value is boolean.
146 , EV_string
// Expression value is char *.
147 , EV_wstring
// Expression value is wide string.
148 , EV_enum
// Expression value is from an enum.
150 // CORBA::Any and CORBA::Object are constructed in the parser first as
151 // expression values, then looked up by name to get the
152 // AST_PredefinedType entry. This is so the grammar non-terminals
153 // integer_type, float_type, bool_type, etc. can also be expression
154 // values in order to serve double duty -- as productions of const_type
155 // and also (along with object_type) as productions of base_type_spec,
156 // as found in the OMG IDL grammar specification.
157 , EV_any
// Used for CORBA::Any operation parameters
158 , EV_object
// Used for CORBA::Object parameters
161 , EV_void
// Expression value is void (absent).
162 , EV_none
// Expression value is missing.
165 static ExprType
eval_kind_to_expr_type (EvalKind eval_kind
);
167 // Structure to describe value of constant expression and its type.
170 AST_ExprValue (void);
174 ACE_CDR::Short sval
; // Contains short expression value.
175 ACE_CDR::UShort usval
; // Contains unsigned short expr value.
176 ACE_CDR::Long lval
; // Contains long expression value.
177 ACE_CDR::ULong ulval
; // Contains unsigned long expr value.
178 ACE_CDR::Boolean bval
; // Contains boolean expression value.
179 ACE_CDR::LongLong llval
; // Contains long long expr value.
180 ACE_CDR::ULongLong ullval
; // Contains unsigned long long expr value.
181 ACE_CDR::Float fval
; // Contains 32-bit float expr value.
182 ACE_CDR::Double dval
; // Contains 64-bit float expr value.
183 ACE_CDR::Char cval
; // Contains char expression value.
184 ACE_CDR::WChar wcval
; // Contains wchar expression value.
185 ACE_CDR::Octet oval
; // Contains octet expr value.
186 UTL_String
*strval
; // Contains String * expr value.
187 char *wstrval
; // Contains wide string expr value.
188 ACE_CDR::ULong eval
; // Contains enumeration value.
189 ACE_CDR::Fixed fixedval
; // Contains IDL fixed value.
190 ACE_CDR::Int8 int8val
; // Signed Byte Sized Integer
191 ACE_CDR::UInt8 uint8val
; // Unsigned Byte Sized Integer
201 AST_Expression (AST_Expression
*v
,
204 AST_Expression (ExprComb c
,
208 AST_Expression (ACE_CDR::Short s
);
210 AST_Expression (ACE_CDR::UShort us
);
212 AST_Expression (ACE_CDR::Long l
);
214 AST_Expression (ACE_CDR::LongLong ll
);
216 AST_Expression (ACE_CDR::Boolean b
);
218 AST_Expression (ACE_CDR::ULong ul
);
220 AST_Expression (ACE_CDR::ULongLong ull
);
222 AST_Expression (ACE_CDR::ULong
,
225 AST_Expression (ACE_CDR::Float f
);
227 AST_Expression (ACE_CDR::Double d
);
229 AST_Expression (ACE_CDR::Char c
);
231 AST_Expression (ACE_OutputCDR::from_wchar wc
);
233 AST_Expression (ACE_CDR::Octet o
);
235 AST_Expression (UTL_String
*s
);
237 AST_Expression (char *s
);
239 AST_Expression (UTL_ScopedName
*n
);
241 AST_Expression (const ACE_CDR::Fixed
&f
);
244 virtual ~AST_Expression (void);
247 UTL_Scope
*defined_in (void);
248 void set_defined_in (UTL_Scope
*d
);
251 void set_line (long l
);
253 UTL_String
*file_name (void);
254 void set_file_name (UTL_String
*f
);
258 AST_ExprValue
*ev (void);
259 void set_ev (AST_ExprValue
*new_ev
);
261 AST_Expression
*v1 (void);
262 void set_v1 (AST_Expression
*e
);
264 AST_Expression
*v2 (void);
265 void set_v2 (AST_Expression
*e
);
267 UTL_ScopedName
*n (void);
268 void set_n (UTL_ScopedName
*new_n
);
271 virtual void dump (ACE_OSTREAM_TYPE
&o
);
274 virtual int ast_accept (ast_visitor
*visitor
);
277 virtual void destroy (void);
281 // Evaluation and value coercion.
283 AST_ExprValue
*coerce (ExprType t
);
285 // Top-level method, called only from yy_parse.
286 AST_ExprValue
*check_and_coerce (ExprType t
,
289 // Evaluate then store value inside this AST_Expression.
290 void evaluate (EvalKind ek
);
292 /// Compare two AST_Expressions.
294 bool operator== (AST_Expression
*vc
);
295 bool compare (AST_Expression
*vc
);
298 // Accessor for the member.
299 AST_Decl
*get_tdef (void) const;
301 // Accessor for the member.
302 AST_Param_Holder
*param_holder (void) const;
304 static const char *exprtype_to_string (ExprType t
);
306 /// Pointer to enum of this value if applicable
308 AST_Enum
*enum_parent ();
309 void enum_parent (AST_Enum
*node
);
313 // Evaluate different sets of operators.
314 AST_ExprValue
*eval_bin_op (EvalKind ek
);
316 AST_ExprValue
*eval_mod_op (EvalKind ek
);
318 AST_ExprValue
*eval_bit_op (EvalKind ek
);
320 AST_ExprValue
*eval_un_op (EvalKind ek
);
322 AST_ExprValue
*eval_symbol (EvalKind ek
);
324 bool type_mismatch (ExprType et
);
327 UTL_Scope
*pd_defined_in
;
333 UTL_String
*pd_file_name
;
334 // What file defined in.
339 AST_ExprValue
*pd_ev
;
342 AST_Expression
*pd_v1
;
343 // 1st sub-expression.
345 AST_Expression
*pd_v2
;
346 // 2nd sub-expression.
348 UTL_ScopedName
*pd_n
;
349 // Symbolic name (if any).
352 // Propagates aliased constant type.
354 AST_Param_Holder
*param_holder_
;
355 // Non-zero if we were created from a reference template param.
357 // Fill out the lineno, filename and definition scope details.
358 void fill_definition_details (void);
360 // Internal evaluation.
361 virtual AST_ExprValue
*eval_internal (EvalKind ek
);
363 /// Pointer to enum of this value if applicable
364 AST_Enum
*enum_parent_
;
367 #endif // _AST_EXPR_VAL_AST_EXPR_VAL_HH