Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / TAO_IDL / include / ast_expression.h
blob7774320cd19d5bb1d44b8baa997ebc4707836379
1 /*
3 COPYRIGHT
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
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California 94043
58 NOTE:
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 #ifndef _AST_EXPRESSION_AST_EXPRESSION_HH
66 #define _AST_EXPRESSION_AST_EXPRESSION_HH
68 #include "ace/CDR_Stream.h"
69 #include "utl_scoped_name.h"
71 class UTL_String;
72 class UTL_Scope;
73 class ast_visitor;
74 class AST_Decl;
75 class AST_Param_Holder;
76 class AST_Enum;
78 // Representation of expression values.
80 // An expression (and maybe its value, if computed).
81 class TAO_IDL_FE_Export AST_Expression
83 public:
84 // Enum to define all the different operators to combine expressions.
85 enum ExprComb
87 EC_add // '+'
88 , EC_minus // '-'
89 , EC_mul // '*'
90 , EC_div // '/'
91 , EC_mod // '%'
92 , EC_or // '|'
93 , EC_xor // '^'
94 , EC_and // '&'
95 , EC_left // '<<'
96 , EC_right // '>>'
97 , EC_u_plus // unary '+'
98 , EC_u_minus // unary '-'
99 , EC_bit_neg // '~'
100 , EC_none // No operator (missing).
101 , EC_symbol // A symbol (function or constant name).
104 // Enum to define the different kinds of evaluation possible
105 // Extend this for more kinds of evaluation as required.
106 enum EvalKind
108 EK_const // Must evaluate to constant.
109 , EK_positive_int // Must evaluate to positive integer.
110 // @@ (JP) I added these to get the ~ operator to work with all the
111 // relevant aritmetic types, but eventually, we should get rid of
112 // this whole enum.
113 , EK_bool
114 , EK_short
115 , EK_ushort
116 , EK_long
117 , EK_ulong
118 , EK_longlong
119 , EK_ulonglong
120 , EK_octet
121 , EK_floating_point
122 , EK_fixed_point
123 , EK_int8
124 , EK_uint8
127 // Enum to define expression type.
128 enum ExprType
130 EV_int8 // Signed Byte Sized Integer
131 , EV_uint8 // Unsigned Byte Sized Integer
132 , EV_short // Expression value is short.
133 , EV_ushort // Expression value is unsigned short.
134 , EV_long // Expression value is long.
135 , EV_ulong // Expression value is unsigned long.
136 , EV_longlong // Expression value is long long.
137 , EV_ulonglong // Expression value is unsigned long long.
138 , EV_float // Expression value is 32-bit float.
139 , EV_double // Expression value is 64-bit float.
140 , EV_longdouble // Expression value is 128-bit float.
141 , EV_char // Expression value is char.
142 , EV_wchar // Expression value is wide char.
143 , EV_octet // Expression value is unsigned char.
144 , EV_bool // Expression value is boolean.
145 , EV_string // Expression value is char *.
146 , EV_wstring // Expression value is wide string.
147 , EV_enum // Expression value is from an enum.
149 // CORBA::Any and CORBA::Object are constructed in the parser first as
150 // expression values, then looked up by name to get the
151 // AST_PredefinedType entry. This is so the grammar non-terminals
152 // integer_type, float_type, bool_type, etc. can also be expression
153 // values in order to serve double duty -- as productions of const_type
154 // and also (along with object_type) as productions of base_type_spec,
155 // as found in the OMG IDL grammar specification.
156 , EV_any // Used for CORBA::Any operation parameters
157 , EV_object // Used for CORBA::Object parameters
159 , EV_fixed
160 , EV_void // Expression value is void (absent).
161 , EV_none // Expression value is missing.
164 static ExprType eval_kind_to_expr_type (EvalKind eval_kind);
166 // Structure to describe value of constant expression and its type.
167 struct AST_ExprValue
169 AST_ExprValue ();
171 union Value
173 ACE_CDR::Short sval; // Contains short expression value.
174 ACE_CDR::UShort usval; // Contains unsigned short expr value.
175 ACE_CDR::Long lval; // Contains long expression value.
176 ACE_CDR::ULong ulval; // Contains unsigned long expr value.
177 ACE_CDR::Boolean bval; // Contains boolean expression value.
178 ACE_CDR::LongLong llval; // Contains long long expr value.
179 ACE_CDR::ULongLong ullval; // Contains unsigned long long expr value.
180 ACE_CDR::Float fval; // Contains 32-bit float expr value.
181 ACE_CDR::Double dval; // Contains 64-bit float expr value.
182 ACE_CDR::Char cval; // Contains char expression value.
183 ACE_CDR::WChar wcval; // Contains wchar expression value.
184 ACE_CDR::Octet oval; // Contains octet expr value.
185 UTL_String *strval; // Contains String * expr value.
186 char *wstrval; // Contains wide string expr value.
187 ACE_CDR::ULong eval; // Contains enumeration value.
188 ACE_CDR::Fixed fixedval; // Contains IDL fixed value.
189 ACE_CDR::Int8 int8val; // Signed Byte Sized Integer
190 ACE_CDR::UInt8 uint8val; // Unsigned Byte Sized Integer
193 ExprType et;
194 Value u;
197 // Operations.
199 // Constructor(s).
200 AST_Expression (AST_Expression *v,
201 ExprType t);
203 AST_Expression (ExprComb c,
204 AST_Expression *v1,
205 AST_Expression *v2);
207 AST_Expression (ACE_CDR::Short s);
209 AST_Expression (ACE_CDR::UShort us);
211 AST_Expression (ACE_CDR::Long l);
213 AST_Expression (ACE_CDR::LongLong ll);
215 AST_Expression (ACE_CDR::Boolean b);
217 AST_Expression (ACE_CDR::ULong ul);
219 AST_Expression (ACE_CDR::ULongLong ull);
221 AST_Expression (ACE_CDR::ULong,
222 ExprType t);
224 AST_Expression (ACE_CDR::Float f);
226 AST_Expression (ACE_CDR::Double d);
228 AST_Expression (ACE_CDR::Char c);
230 AST_Expression (ACE_OutputCDR::from_wchar wc);
232 AST_Expression (ACE_CDR::Octet o);
234 AST_Expression (UTL_String *s);
236 AST_Expression (char *s);
238 AST_Expression (UTL_ScopedName *n);
240 AST_Expression (const ACE_CDR::Fixed &f);
242 // Destructor.
243 virtual ~AST_Expression ();
245 // Data Accessors.
246 UTL_Scope *defined_in ();
247 void set_defined_in (UTL_Scope *d);
249 long line ();
250 void set_line (long l);
252 UTL_String *file_name ();
253 void set_file_name (UTL_String *f);
255 ExprComb ec ();
257 AST_ExprValue *ev ();
258 void set_ev (AST_ExprValue *new_ev);
260 AST_Expression *v1 ();
261 void set_v1 (AST_Expression *e);
263 AST_Expression *v2 ();
264 void set_v2 (AST_Expression *e);
266 UTL_ScopedName *n ();
267 void set_n (UTL_ScopedName *new_n);
269 // AST Dumping.
270 virtual void dump (ACE_OSTREAM_TYPE &o);
272 // Visiting.
273 virtual int ast_accept (ast_visitor *visitor);
275 // Cleanup.
276 virtual void destroy ();
278 // Other operations.
280 // Evaluation and value coercion.
282 AST_ExprValue *coerce (ExprType t);
284 // Top-level method, called only from yy_parse.
285 AST_ExprValue *check_and_coerce (ExprType t,
286 AST_Decl *d);
288 // Evaluate then store value inside this AST_Expression.
289 void evaluate (EvalKind ek);
291 /// Compare two AST_Expressions.
292 ///{
293 bool operator== (AST_Expression *vc);
294 bool compare (AST_Expression *vc);
295 ///}
297 // Accessor for the member.
298 AST_Decl *get_tdef () const;
300 // Accessor for the member.
301 AST_Param_Holder *param_holder () const;
303 static const char *exprtype_to_string (ExprType t);
305 /// Pointer to enum of this value if applicable
306 ///{
307 AST_Enum *enum_parent ();
308 void enum_parent (AST_Enum *node);
309 ///}
311 protected:
312 // Evaluate different sets of operators.
313 AST_ExprValue *eval_bin_op (EvalKind ek);
315 AST_ExprValue *eval_mod_op (EvalKind ek);
317 AST_ExprValue *eval_bit_op (EvalKind ek);
319 AST_ExprValue *eval_un_op (EvalKind ek);
321 AST_ExprValue *eval_symbol (EvalKind ek);
323 bool type_mismatch (ExprType et);
325 private:
326 UTL_Scope *pd_defined_in;
327 // Scope.
329 long pd_line;
330 // Line defined in.
332 UTL_String *pd_file_name;
333 // What file defined in.
335 ExprComb pd_ec;
336 // What combinator.
338 AST_ExprValue *pd_ev;
339 // Computed value.
341 AST_Expression *pd_v1;
342 // 1st sub-expression.
344 AST_Expression *pd_v2;
345 // 2nd sub-expression.
347 UTL_ScopedName *pd_n;
348 // Symbolic name (if any).
350 AST_Decl *tdef;
351 // Propagates aliased constant type.
353 AST_Param_Holder *param_holder_;
354 // Non-zero if we were created from a reference template param.
356 // Fill out the lineno, filename and definition scope details.
357 void fill_definition_details ();
359 // Internal evaluation.
360 virtual AST_ExprValue *eval_internal (EvalKind ek);
362 /// Pointer to enum of this value if applicable
363 AST_Enum *enum_parent_;
366 #endif // _AST_EXPR_VAL_AST_EXPR_VAL_HH