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_Expression nodes denote IDL expressions used in the IDL input.
67 #include "ast_expression.h"
68 #include "ast_constant.h"
69 #include "ast_typedef.h"
70 #include "ast_param_holder.h"
71 #include "ast_visitor.h"
72 #include "ast_generator.h"
73 #include "ast_enum_val.h"
76 #include "utl_scope.h"
77 #include "utl_string.h"
79 #include "nr_extern.h"
80 #include "global_extern.h"
83 #include "ace/OS_NS_stdio.h"
84 // FUZZ: disable check_for_streams_include
85 #include "ace/streams.h"
87 AST_Expression::ExprType
88 AST_Expression::eval_kind_to_expr_type (AST_Expression::EvalKind eval_kind
)
101 case EK_positive_int
:
109 case EK_floating_point
:
118 idl_global
->err ()->misc_error ("eval_kind_to_expr_type can't handle EK_const");
122 idl_global
->err ()->misc_error ("eval_kind_to_expr_type unhandled EvalKind");
126 // Helper function to fill out the details of where this expression
129 AST_Expression::fill_definition_details ()
131 this->pd_defined_in
= idl_global
->scopes ().depth () > 0
132 ? idl_global
->scopes ().top ()
134 this->pd_line
= idl_global
->lineno ();
135 this->pd_file_name
= idl_global
->filename ();
136 enum_parent (nullptr);
139 // An AST_Expression denoting a symbolic name.
140 AST_Expression::AST_Expression (UTL_ScopedName
*nm
)
147 param_holder_ (nullptr)
149 this->fill_definition_details ();
152 idl_global
->scopes ().top_non_null ()->lookup_by_name (nm
,
155 if (d
->node_type () == AST_Decl::NT_param_holder
)
157 this->param_holder_
=
158 dynamic_cast<AST_Param_Holder
*> (d
);
162 // An AST_Expression denoting a type coercion from another AST_Expression.
163 AST_Expression::AST_Expression (AST_Expression
*v
,
171 param_holder_ (nullptr)
173 AST_Param_Holder
*ph
= v
->param_holder_
;
174 this->fill_definition_details ();
175 enum_parent (v
->enum_parent ());
177 // If we are here because one string constant has
178 // another one as its rhs, we must copy the UTL_String
179 // so both can be destroyed at cleanup.
182 ACE_NEW (this->pd_ev
,
185 ACE_NEW (this->pd_ev
->u
.strval
,
186 UTL_String (v
->pd_ev
->u
.strval
, true));
188 this->pd_ev
->et
= EV_string
;
190 else if (EV_wstring
== t
)
192 ACE_NEW (this->pd_ev
,
195 this->pd_ev
->u
.wstrval
= ACE::strnew (v
->pd_ev
->u
.wstrval
);
196 this->pd_ev
->et
= EV_string
;
202 this->pd_ev
= v
->coerce (t
);
204 if (this->pd_ev
== nullptr)
206 idl_global
->err ()->coercion_error (v
, t
);
211 // The param info member isn't managed by this type,
212 // so we can just pass the pointer to the new expr.
213 this->param_holder_
=
214 idl_global
->gen ()->create_param_holder (
216 const_cast<FE_Utils::T_Param_Info
*> (ph
->info ()));
219 if (nullptr != v
->pd_n
)
222 dynamic_cast<UTL_ScopedName
*> (v
->pd_n
->copy ());
227 // An AST_Expression denoting a binary expression combination from
228 // two other AST_Expressions.
229 AST_Expression::AST_Expression (ExprComb c
,
238 param_holder_ (nullptr)
240 this->fill_definition_details ();
243 // An AST_Expression denoting a short integer.
244 AST_Expression::AST_Expression (ACE_CDR::Short sv
)
251 param_holder_ (nullptr)
253 this->fill_definition_details ();
255 ACE_NEW (this->pd_ev
,
258 this->pd_ev
->et
= EV_short
;
259 this->pd_ev
->u
.sval
= sv
;
262 // An AST_Expression denoting an unsigned short integer.
263 AST_Expression::AST_Expression (ACE_CDR::UShort usv
)
270 param_holder_ (nullptr)
272 this->fill_definition_details ();
274 ACE_NEW (this->pd_ev
,
277 this->pd_ev
->et
= EV_ushort
;
278 this->pd_ev
->u
.usval
= usv
;
281 // An AST_Expression denoting a long integer.
282 AST_Expression::AST_Expression (ACE_CDR::Long lv
)
289 param_holder_ (nullptr)
291 this->fill_definition_details ();
293 ACE_NEW (this->pd_ev
,
296 this->pd_ev
->et
= EV_long
;
297 this->pd_ev
->u
.lval
= lv
;
300 // An AST_Expression denoting a long integer.
301 AST_Expression::AST_Expression (ACE_CDR::LongLong llv
)
308 param_holder_ (nullptr)
310 this->fill_definition_details ();
312 ACE_NEW (this->pd_ev
,
315 this->pd_ev
->et
= EV_longlong
;
316 this->pd_ev
->u
.llval
= llv
;
319 // An AST_Expression denoting a boolean.
320 AST_Expression::AST_Expression (ACE_CDR::Boolean b
)
327 param_holder_ (nullptr)
329 this->fill_definition_details ();
331 ACE_NEW (this->pd_ev
,
334 this->pd_ev
->et
= EV_bool
;
335 this->pd_ev
->u
.bval
= b
;
338 // An AST_Expression denoting an unsigned long integer.
339 AST_Expression::AST_Expression (ACE_CDR::ULong ulv
)
346 param_holder_ (nullptr)
348 this->fill_definition_details ();
350 ACE_NEW (this->pd_ev
,
353 this->pd_ev
->et
= EV_ulong
;
354 this->pd_ev
->u
.ulval
= ulv
;
357 // An AST_Expression denoting an unsigned long long integer.
358 AST_Expression::AST_Expression (ACE_CDR::ULongLong ulv
)
365 param_holder_ (nullptr)
367 this->fill_definition_details ();
369 ACE_NEW (this->pd_ev
,
372 this->pd_ev
->et
= EV_ulonglong
;
373 this->pd_ev
->u
.ullval
= ulv
;
376 // An AST_Expression denoting an unsigned long integer.
377 AST_Expression::AST_Expression (ACE_CDR::ULong ulv
,
385 param_holder_ (nullptr)
387 this->fill_definition_details ();
389 ACE_NEW (this->pd_ev
,
393 this->pd_ev
->u
.ullval
= ulv
;
396 // An AST_Expression denoting a 32-bit floating point number.
397 AST_Expression::AST_Expression (ACE_CDR::Float fv
)
404 param_holder_ (nullptr)
406 this->fill_definition_details ();
408 ACE_NEW (this->pd_ev
,
411 this->pd_ev
->et
= EV_float
;
412 this->pd_ev
->u
.fval
= fv
;
415 // An AST_Expression denoting a 64-bit floating point number.
416 AST_Expression::AST_Expression (ACE_CDR::Double dv
)
423 param_holder_ (nullptr)
425 this->fill_definition_details ();
427 ACE_NEW (this->pd_ev
,
430 this->pd_ev
->et
= EV_double
;
431 this->pd_ev
->u
.dval
= dv
;
434 // An AST_Expression denoting a character.
435 AST_Expression::AST_Expression (ACE_CDR::Char cv
)
442 param_holder_ (nullptr)
444 this->fill_definition_details ();
446 ACE_NEW (this->pd_ev
,
449 this->pd_ev
->et
= EV_char
;
450 this->pd_ev
->u
.cval
= cv
;
453 // An AST_Expression denoting a wide character.
454 AST_Expression::AST_Expression (ACE_OutputCDR::from_wchar wcv
)
461 param_holder_ (nullptr)
463 this->fill_definition_details ();
465 ACE_NEW (this->pd_ev
,
468 this->pd_ev
->et
= EV_wchar
;
469 this->pd_ev
->u
.wcval
= wcv
.val_
;
472 // An AST_Expression denoting an octet (unsigned char).
473 AST_Expression::AST_Expression (ACE_CDR::Octet ov
)
480 param_holder_ (nullptr)
482 this->fill_definition_details ();
484 ACE_NEW (this->pd_ev
,
487 this->pd_ev
->et
= EV_octet
;
488 this->pd_ev
->u
.oval
= ov
;
491 // An AST_Expression denoting a string (char * encapsulated as a String).
492 AST_Expression::AST_Expression (UTL_String
*sv
)
499 param_holder_ (nullptr)
501 this->fill_definition_details ();
503 ACE_NEW (this->pd_ev
,
506 UTL_String
*new_str
= nullptr;
508 UTL_String (sv
, true));
510 this->pd_ev
->u
.strval
= new_str
;
511 this->pd_ev
->et
= EV_string
;
514 // An AST_Expression denoting a wide string.
515 AST_Expression::AST_Expression (char *sv
)
522 param_holder_ (nullptr)
524 this->fill_definition_details ();
526 ACE_NEW (this->pd_ev
,
529 this->pd_ev
->et
= EV_wstring
;
530 this->pd_ev
->u
.wstrval
= ACE::strnew (sv
);
533 AST_Expression::AST_Expression (const ACE_CDR::Fixed
&f
)
540 param_holder_ (nullptr)
542 this->fill_definition_details ();
544 ACE_NEW (this->pd_ev
,
547 this->pd_ev
->et
= EV_fixed
;
548 this->pd_ev
->u
.fixedval
= f
;
551 AST_Expression::~AST_Expression ()
556 AST_Expression::AST_ExprValue::AST_ExprValue ()
559 this->et
= AST_Expression::EV_none
;
562 // Static operations.
564 // Perform the coercion from the given AST_ExprValue to the requested
565 // ExprType. Return an AST_ExprValue if successful, 0 if failed.
566 static AST_Expression::AST_ExprValue
*
567 coerce_value (AST_Expression::AST_ExprValue
*ev
,
568 AST_Expression::ExprType t
)
580 // Avoid Coverity issue with "Assignment of overlapping memory" by using a
581 // temporary value and setting ev->u at the end if there wasn't an error.
582 AST_Expression::AST_ExprValue::Value tmp
;
585 case AST_Expression::EV_short
:
588 case AST_Expression::EV_ushort
:
589 if (ev
->u
.usval
> (ACE_CDR::UShort
) ACE_INT16_MAX
)
594 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.usval
;
596 case AST_Expression::EV_long
:
597 if (ev
->u
.lval
> (ACE_CDR::Long
) ACE_INT16_MAX
598 || ev
->u
.lval
< (ACE_CDR::Long
) ACE_INT16_MIN
)
603 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.lval
;
605 case AST_Expression::EV_ulong
:
606 if (ev
->u
.ulval
> (ACE_CDR::ULong
) ACE_INT16_MAX
)
611 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.ulval
;
613 case AST_Expression::EV_longlong
:
614 if (ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_INT16_MAX
615 || ev
->u
.llval
< (ACE_CDR::LongLong
) ACE_INT16_MIN
)
620 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.llval
;
622 case AST_Expression::EV_ulonglong
:
623 if ((ev
->u
.ullval
& ACE_INT16_MAX
) != ev
->u
.ullval
)
628 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.ullval
;
630 case AST_Expression::EV_bool
:
631 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.bval
;
633 case AST_Expression::EV_float
:
634 if (ev
->u
.fval
> (ACE_CDR::Float
) ACE_INT16_MAX
635 || ev
->u
.fval
< (ACE_CDR::Float
) ACE_INT16_MIN
)
640 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.fval
;
642 case AST_Expression::EV_double
:
643 if (ev
->u
.dval
> (ACE_CDR::Double
) ACE_INT16_MAX
644 || ev
->u
.dval
< (ACE_CDR::Double
) ACE_INT16_MIN
)
649 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.dval
;
651 case AST_Expression::EV_char
:
652 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.cval
;
654 case AST_Expression::EV_wchar
:
655 if (ev
->u
.wcval
> (ACE_CDR::WChar
) ACE_INT16_MAX
)
660 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.wcval
;
662 case AST_Expression::EV_octet
:
663 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.oval
;
665 case AST_Expression::EV_int8
:
666 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.int8val
;
668 case AST_Expression::EV_uint8
:
669 tmp
.sval
= (ACE_CDR::Short
) ev
->u
.uint8val
;
676 case AST_Expression::EV_ushort
:
679 case AST_Expression::EV_short
:
685 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.sval
;
687 case AST_Expression::EV_long
:
688 if (ev
->u
.lval
> (ACE_CDR::Long
) ACE_UINT16_MAX
694 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.lval
;
696 case AST_Expression::EV_ulong
:
697 if (ev
->u
.ulval
> (ACE_CDR::ULong
) ACE_UINT16_MAX
)
702 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.ulval
;
704 case AST_Expression::EV_longlong
:
705 if (ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_UINT16_MAX
711 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.llval
;
713 case AST_Expression::EV_ulonglong
:
714 if ((ev
->u
.ullval
& ACE_UINT16_MAX
) != ev
->u
.ullval
)
719 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.ullval
;
721 case AST_Expression::EV_bool
:
722 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.bval
;
724 case AST_Expression::EV_float
:
726 || ev
->u
.fval
> (ACE_CDR::Float
) ACE_UINT16_MAX
)
731 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.fval
;
733 case AST_Expression::EV_double
:
735 || ev
->u
.dval
> (ACE_CDR::Double
) ACE_UINT16_MAX
)
740 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.dval
;
742 case AST_Expression::EV_char
:
743 if ((signed char) ev
->u
.cval
< 0)
748 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.cval
;
750 case AST_Expression::EV_wchar
:
751 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.wcval
;
753 case AST_Expression::EV_octet
:
754 tmp
.usval
= (ACE_CDR::UShort
) ev
->u
.oval
;
756 case AST_Expression::EV_int8
:
757 if (ev
->u
.int8val
< 0) return nullptr;
758 tmp
.usval
= static_cast<ACE_CDR::UShort
> (ev
->u
.int8val
);
760 case AST_Expression::EV_uint8
:
761 tmp
.usval
= static_cast<ACE_CDR::UShort
> (ev
->u
.uint8val
);
768 case AST_Expression::EV_long
:
771 case AST_Expression::EV_short
:
772 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.sval
;
774 case AST_Expression::EV_ushort
:
775 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.usval
;
777 case AST_Expression::EV_ulong
:
778 if (ev
->u
.ulval
> (ACE_CDR::ULong
) ACE_INT32_MAX
)
783 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.ulval
;
785 case AST_Expression::EV_longlong
:
786 if (ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_INT32_MAX
787 || ev
->u
.llval
< (ACE_CDR::LongLong
) ACE_INT32_MIN
)
791 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.llval
;
793 case AST_Expression::EV_ulonglong
:
794 if ((ev
->u
.ullval
& ACE_INT32_MAX
) != ev
->u
.ullval
)
799 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.ullval
;
801 case AST_Expression::EV_bool
:
802 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.bval
;
804 case AST_Expression::EV_float
:
805 if (ev
->u
.fval
> (ACE_CDR::Float
) ACE_INT32_MAX
806 || ev
->u
.fval
< (ACE_CDR::Float
) ACE_INT32_MIN
)
811 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.fval
;
813 case AST_Expression::EV_double
:
814 if (ev
->u
.dval
> (ACE_CDR::Double
) ACE_INT32_MAX
815 || ev
->u
.dval
< (ACE_CDR::Double
) ACE_INT32_MIN
)
820 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.dval
;
822 case AST_Expression::EV_char
:
823 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.cval
;
825 case AST_Expression::EV_wchar
:
826 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.wcval
;
828 case AST_Expression::EV_octet
:
829 tmp
.lval
= (ACE_CDR::Long
) ev
->u
.oval
;
831 case AST_Expression::EV_int8
:
832 tmp
.lval
= static_cast<ACE_CDR::Long
> (ev
->u
.int8val
);
834 case AST_Expression::EV_uint8
:
835 tmp
.lval
= static_cast<ACE_CDR::Long
> (ev
->u
.uint8val
);
842 case AST_Expression::EV_ulong
:
845 case AST_Expression::EV_short
:
851 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.sval
;
853 case AST_Expression::EV_ushort
:
854 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.usval
;
856 case AST_Expression::EV_long
:
862 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.lval
;
864 case AST_Expression::EV_longlong
:
865 if (ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_UINT32_MAX
871 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.llval
;
873 case AST_Expression::EV_ulonglong
:
874 if ((ev
->u
.ullval
& ACE_UINT32_MAX
) != ev
->u
.ullval
)
878 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.ullval
;
880 case AST_Expression::EV_bool
:
881 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.bval
;
883 case AST_Expression::EV_float
:
885 || ev
->u
.fval
> (ACE_CDR::Float
) ACE_UINT32_MAX
)
890 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.fval
;
892 case AST_Expression::EV_double
:
894 || ev
->u
.dval
> (ACE_CDR::Double
) ACE_UINT32_MAX
)
899 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.dval
;
901 case AST_Expression::EV_char
:
902 if ((signed char) ev
->u
.cval
< 0)
907 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.cval
;
909 case AST_Expression::EV_wchar
:
910 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.wcval
;
912 case AST_Expression::EV_octet
:
913 tmp
.ulval
= (ACE_CDR::ULong
) ev
->u
.oval
;
915 case AST_Expression::EV_int8
:
916 if (ev
->u
.int8val
< 0) return nullptr;
917 tmp
.ulval
= static_cast<ACE_CDR::ULong
> (ev
->u
.int8val
);
919 case AST_Expression::EV_uint8
:
920 tmp
.ulval
= static_cast<ACE_CDR::ULong
> (ev
->u
.uint8val
);
927 case AST_Expression::EV_longlong
:
930 case AST_Expression::EV_short
:
931 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.sval
;
933 case AST_Expression::EV_ushort
:
934 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.usval
;
936 case AST_Expression::EV_long
:
937 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.lval
;
939 case AST_Expression::EV_ulong
:
940 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.ulval
;
942 case AST_Expression::EV_ulonglong
:
943 if (ev
->u
.ullval
> ACE_INT64_MAX
)
948 tmp
.llval
= static_cast<ACE_CDR::LongLong
> (ev
->u
.ullval
);
950 case AST_Expression::EV_bool
:
951 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.bval
;
953 case AST_Expression::EV_float
:
954 if (ev
->u
.fval
> (ACE_CDR::Float
) ACE_INT64_MAX
955 || ev
->u
.fval
< (ACE_CDR::Float
) ACE_INT64_MIN
)
960 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.fval
;
962 case AST_Expression::EV_double
:
963 if (ev
->u
.dval
> (ACE_CDR::Double
) ACE_INT64_MAX
964 || ev
->u
.dval
< (ACE_CDR::Double
) ACE_INT64_MIN
)
969 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.dval
;
971 case AST_Expression::EV_char
:
972 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.cval
;
974 case AST_Expression::EV_wchar
:
975 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.wcval
;
977 case AST_Expression::EV_octet
:
978 tmp
.llval
= (ACE_CDR::LongLong
) ev
->u
.oval
;
980 case AST_Expression::EV_int8
:
981 tmp
.llval
= static_cast<ACE_CDR::LongLong
> (ev
->u
.int8val
);
983 case AST_Expression::EV_uint8
:
984 tmp
.llval
= static_cast<ACE_CDR::LongLong
> (ev
->u
.int8val
);
991 case AST_Expression::EV_ulonglong
:
994 case AST_Expression::EV_short
:
1000 tmp
.ullval
= ev
->u
.sval
;
1002 case AST_Expression::EV_ushort
:
1003 tmp
.ullval
= ev
->u
.usval
;
1005 case AST_Expression::EV_long
:
1011 tmp
.ullval
= ev
->u
.lval
;
1013 case AST_Expression::EV_ulong
:
1014 tmp
.ullval
= ev
->u
.ulval
;
1016 case AST_Expression::EV_longlong
:
1017 if (ev
->u
.llval
< 0)
1022 tmp
.ullval
= static_cast<ACE_CDR::LongLong
> (ev
->u
.llval
);
1024 case AST_Expression::EV_bool
:
1025 tmp
.ullval
= ev
->u
.bval
;
1027 case AST_Expression::EV_float
:
1028 if (ev
->u
.fval
< 0.0
1029 || ev
->u
.fval
> (ACE_CDR::Float
) ACE_UINT64_MAX
)
1034 tmp
.ullval
= static_cast<ACE_CDR::ULongLong
> (ev
->u
.fval
);
1036 case AST_Expression::EV_double
:
1037 if (ev
->u
.dval
< 0.0
1038 || ev
->u
.dval
> (ACE_CDR::Double
) ACE_UINT64_MAX
)
1043 tmp
.ullval
= static_cast<ACE_CDR::ULongLong
> (ev
->u
.dval
);
1045 case AST_Expression::EV_char
:
1046 if ((signed char) ev
->u
.cval
< 0)
1051 tmp
.ullval
= ev
->u
.cval
;
1053 case AST_Expression::EV_wchar
:
1054 tmp
.ullval
= ev
->u
.wcval
;
1056 case AST_Expression::EV_octet
:
1057 tmp
.ullval
= ev
->u
.oval
;
1059 case AST_Expression::EV_int8
:
1060 if (ev
->u
.int8val
< 0) return nullptr;
1061 tmp
.ullval
= static_cast<ACE_CDR::ULongLong
> (ev
->u
.int8val
);
1063 case AST_Expression::EV_uint8
:
1064 tmp
.ullval
= static_cast<ACE_CDR::ULongLong
> (ev
->u
.uint8val
);
1071 case AST_Expression::EV_bool
:
1074 case AST_Expression::EV_short
:
1075 tmp
.bval
= (ev
->u
.sval
== 0) ? false : true;
1077 case AST_Expression::EV_ushort
:
1078 tmp
.bval
= (ev
->u
.usval
== 0) ? false : true;
1080 case AST_Expression::EV_long
:
1081 tmp
.bval
= (ev
->u
.lval
== 0) ? false : true;
1083 case AST_Expression::EV_ulong
:
1084 tmp
.bval
= (ev
->u
.ulval
== 0) ? false : true;
1086 case AST_Expression::EV_longlong
:
1087 tmp
.bval
= (ev
->u
.llval
== 0) ? false : true;
1089 case AST_Expression::EV_ulonglong
:
1090 tmp
.bval
= (ev
->u
.ullval
== 0) ? false : true;
1092 case AST_Expression::EV_float
:
1093 tmp
.bval
= ACE::is_equal (ev
->u
.fval
, 0.0f
) ? false : true;
1095 case AST_Expression::EV_double
:
1096 tmp
.bval
= ACE::is_equal (ev
->u
.dval
, 0.0) ? false : true;
1098 case AST_Expression::EV_char
:
1099 tmp
.bval
= (ev
->u
.cval
== 0) ? false : true;
1101 case AST_Expression::EV_wchar
:
1102 tmp
.bval
= (ev
->u
.wcval
== 0) ? false : true;
1104 case AST_Expression::EV_octet
:
1105 tmp
.bval
= (ev
->u
.oval
== 0) ? false : true;
1107 case AST_Expression::EV_int8
:
1108 tmp
.bval
= ev
->u
.int8val
? true : false;
1110 case AST_Expression::EV_uint8
:
1111 tmp
.bval
= ev
->u
.uint8val
? true : false;
1118 case AST_Expression::EV_float
:
1121 case AST_Expression::EV_short
:
1122 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.sval
;
1124 case AST_Expression::EV_ushort
:
1125 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.usval
;
1127 case AST_Expression::EV_long
:
1128 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.lval
;
1130 case AST_Expression::EV_ulong
:
1131 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.ulval
;
1133 case AST_Expression::EV_longlong
:
1134 if (ev
->u
.llval
> ACE_FLT_MAX
1135 || ev
->u
.llval
< ACE_FLT_LOWEST
)
1139 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.llval
;
1141 case AST_Expression::EV_ulonglong
:
1142 tmp
.fval
= (ACE_CDR::Float
) ((ACE_CDR::LongLong
) ev
->u
.ullval
);
1144 case AST_Expression::EV_bool
:
1145 tmp
.fval
= ev
->u
.bval
? 1.0f
: 0.0f
;
1147 case AST_Expression::EV_double
:
1148 if (ev
->u
.dval
> ACE_FLT_MAX
1149 || ev
->u
.dval
< ACE_FLT_LOWEST
)
1154 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.dval
;
1156 case AST_Expression::EV_char
:
1157 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.cval
;
1159 case AST_Expression::EV_wchar
:
1160 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.wcval
;
1162 case AST_Expression::EV_octet
:
1163 tmp
.fval
= (ACE_CDR::Float
) ev
->u
.oval
;
1165 case AST_Expression::EV_int8
:
1166 tmp
.fval
= static_cast<ACE_CDR::Float
> (ev
->u
.int8val
);
1168 case AST_Expression::EV_uint8
:
1169 tmp
.fval
= static_cast<ACE_CDR::Float
> (ev
->u
.uint8val
);
1176 case AST_Expression::EV_double
:
1179 case AST_Expression::EV_short
:
1180 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.sval
;
1182 case AST_Expression::EV_ushort
:
1183 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.usval
;
1185 case AST_Expression::EV_long
:
1186 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.lval
;
1188 case AST_Expression::EV_ulong
:
1189 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.ulval
;
1191 case AST_Expression::EV_longlong
:
1192 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.llval
;
1194 case AST_Expression::EV_ulonglong
:
1195 // Some compilers don't implement unsigned 64-bit to double
1196 // conversions, so we are stuck with the signed 64-bit max value.
1197 if (ev
->u
.ullval
> ACE_INT64_MAX
)
1202 tmp
.dval
= (ACE_CDR::Double
) ((ACE_CDR::LongLong
) ev
->u
.ullval
);
1204 case AST_Expression::EV_bool
:
1205 tmp
.dval
= ev
->u
.bval
? 1.0 : 0.0;
1207 case AST_Expression::EV_float
:
1208 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.fval
;
1210 case AST_Expression::EV_char
:
1211 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.cval
;
1213 case AST_Expression::EV_wchar
:
1214 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.wcval
;
1216 case AST_Expression::EV_octet
:
1217 tmp
.dval
= (ACE_CDR::Double
) ev
->u
.oval
;
1219 case AST_Expression::EV_int8
:
1220 tmp
.dval
= static_cast<ACE_CDR::Double
> (ev
->u
.int8val
);
1222 case AST_Expression::EV_uint8
:
1223 tmp
.dval
= static_cast<ACE_CDR::Double
> (ev
->u
.uint8val
);
1230 case AST_Expression::EV_int8
:
1231 case AST_Expression::EV_char
:
1234 case AST_Expression::EV_short
:
1235 if (ev
->u
.sval
> (ACE_CDR::Short
) ACE_CHAR_MAX
1236 || ev
->u
.sval
< (ACE_CDR::Short
) ACE_CHAR_MIN
)
1241 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.sval
;
1243 case AST_Expression::EV_ushort
:
1244 if (ev
->u
.usval
> (ACE_CDR::UShort
) ACE_CHAR_MAX
)
1249 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.usval
;
1251 case AST_Expression::EV_long
:
1252 if (ev
->u
.lval
> (ACE_CDR::Long
) ACE_CHAR_MAX
1253 || ev
->u
.lval
< (ACE_CDR::Long
) ACE_CHAR_MIN
)
1258 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.lval
;
1260 case AST_Expression::EV_ulong
:
1261 if (ev
->u
.ulval
> (ACE_CDR::ULong
) ACE_CHAR_MAX
)
1266 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.ulval
;
1268 case AST_Expression::EV_longlong
:
1269 if (ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_CHAR_MAX
1270 || ev
->u
.llval
< (ACE_CDR::LongLong
) ACE_CHAR_MIN
)
1275 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.llval
;
1277 case AST_Expression::EV_ulonglong
:
1278 if ((ev
->u
.ullval
& ACE_CHAR_MAX
) != ev
->u
.ullval
)
1283 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.ullval
;
1285 case AST_Expression::EV_bool
:
1286 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.bval
;
1288 case AST_Expression::EV_float
:
1289 if (ev
->u
.fval
> (ACE_CDR::Float
) ACE_CHAR_MAX
1290 || ev
->u
.fval
< (ACE_CDR::Float
) ACE_CHAR_MIN
)
1295 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.fval
;
1297 case AST_Expression::EV_double
:
1298 if (ev
->u
.dval
> (ACE_CDR::Double
) ACE_CHAR_MAX
1299 || ev
->u
.dval
< (ACE_CDR::Double
) ACE_CHAR_MIN
)
1304 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.dval
;
1306 case AST_Expression::EV_wchar
:
1307 if (ev
->u
.wcval
> (ACE_CDR::WChar
) ACE_CHAR_MAX
)
1312 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.wcval
;
1314 case AST_Expression::EV_uint8
:
1315 case AST_Expression::EV_octet
:
1316 if (ev
->u
.oval
> (unsigned char) ACE_CHAR_MAX
)
1321 tmp
.cval
= (ACE_CDR::Char
) ev
->u
.oval
;
1323 case AST_Expression::EV_int8
:
1324 case AST_Expression::EV_char
:
1332 case AST_Expression::EV_wchar
:
1335 case AST_Expression::EV_short
:
1341 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.sval
;
1343 case AST_Expression::EV_ushort
:
1344 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.usval
;
1346 case AST_Expression::EV_long
:
1348 || ev
->u
.lval
> ACE_WCHAR_MAX
)
1353 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.lval
;
1355 case AST_Expression::EV_ulong
:
1356 if (ev
->u
.ulval
> ACE_WCHAR_MAX
)
1361 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.ulval
;
1363 case AST_Expression::EV_longlong
:
1364 if (ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_WCHAR_MAX
1370 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.llval
;
1372 case AST_Expression::EV_ulonglong
:
1373 if ((ev
->u
.ullval
& ACE_WCHAR_MAX
) != ev
->u
.ullval
)
1378 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.ullval
;
1380 case AST_Expression::EV_bool
:
1381 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.bval
;
1383 case AST_Expression::EV_float
:
1384 if (ev
->u
.fval
> (ACE_CDR::Float
) ACE_WCHAR_MAX
1390 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.fval
;
1392 case AST_Expression::EV_double
:
1393 if (ev
->u
.dval
> (ACE_CDR::Double
) ACE_WCHAR_MAX
1399 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.dval
;
1401 case AST_Expression::EV_char
:
1402 case AST_Expression::EV_int8
:
1403 if ((signed char) ev
->u
.cval
< 0)
1408 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.cval
;
1410 case AST_Expression::EV_octet
:
1411 tmp
.wcval
= (ACE_CDR::WChar
) ev
->u
.oval
;
1413 case AST_Expression::EV_uint8
:
1414 tmp
.wcval
= static_cast<ACE_CDR::WChar
> (ev
->u
.uint8val
);
1421 case AST_Expression::EV_uint8
:
1422 case AST_Expression::EV_octet
:
1425 case AST_Expression::EV_short
:
1427 || ev
->u
.sval
> (ACE_CDR::Short
) ACE_OCTET_MAX
)
1432 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.sval
;
1434 case AST_Expression::EV_ushort
:
1435 if (ev
->u
.usval
> (ACE_CDR::UShort
) ACE_OCTET_MAX
)
1440 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.usval
;
1442 case AST_Expression::EV_long
:
1444 || ev
->u
.lval
> (ACE_CDR::Long
) ACE_OCTET_MAX
)
1449 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.lval
;
1451 case AST_Expression::EV_ulong
:
1452 if (ev
->u
.ulval
> (ACE_CDR::ULong
) ACE_OCTET_MAX
)
1457 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.ulval
;
1459 case AST_Expression::EV_longlong
:
1461 || ev
->u
.llval
> (ACE_CDR::LongLong
) ACE_OCTET_MAX
)
1466 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.llval
;
1468 case AST_Expression::EV_ulonglong
:
1469 if ((ev
->u
.ullval
& ACE_OCTET_MAX
) != ev
->u
.ullval
)
1474 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.ullval
;
1476 case AST_Expression::EV_bool
:
1477 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.bval
? 1 : 0;
1479 case AST_Expression::EV_float
:
1480 if (ev
->u
.fval
< 0.0
1481 || ev
->u
.fval
> (ACE_CDR::Float
) ACE_OCTET_MAX
)
1486 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.fval
;
1488 case AST_Expression::EV_double
:
1489 if (ev
->u
.dval
< 0.0
1490 || ev
->u
.dval
> (ACE_CDR::Double
) ACE_OCTET_MAX
)
1495 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.dval
;
1497 case AST_Expression::EV_int8
:
1498 case AST_Expression::EV_char
:
1499 if ((signed char) ev
->u
.cval
< 0)
1504 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.cval
;
1506 case AST_Expression::EV_wchar
:
1507 if (ev
->u
.wcval
> (ACE_CDR::WChar
) ACE_OCTET_MAX
)
1512 tmp
.oval
= (ACE_CDR::Octet
) ev
->u
.wcval
;
1514 case AST_Expression::EV_uint8
:
1515 case AST_Expression::EV_octet
:
1523 case AST_Expression::EV_enum
:
1526 case AST_Expression::EV_ulong
:
1540 // Integer literals may not be assigned to floating point constants,
1543 incompatible_types (AST_Expression::ExprType t1
,
1544 AST_Expression::ExprType t2
)
1548 case AST_Expression::EV_short
:
1549 case AST_Expression::EV_ushort
:
1550 case AST_Expression::EV_long
:
1551 case AST_Expression::EV_ulong
:
1552 case AST_Expression::EV_longlong
:
1553 case AST_Expression::EV_ulonglong
:
1554 case AST_Expression::EV_octet
:
1555 case AST_Expression::EV_bool
:
1556 case AST_Expression::EV_int8
:
1557 case AST_Expression::EV_uint8
:
1560 case AST_Expression::EV_short
:
1561 case AST_Expression::EV_ushort
:
1562 case AST_Expression::EV_long
:
1563 case AST_Expression::EV_ulong
:
1564 case AST_Expression::EV_longlong
:
1565 case AST_Expression::EV_ulonglong
:
1566 case AST_Expression::EV_octet
:
1567 case AST_Expression::EV_bool
:
1568 case AST_Expression::EV_int8
:
1569 case AST_Expression::EV_uint8
:
1574 case AST_Expression::EV_float
:
1575 case AST_Expression::EV_double
:
1576 case AST_Expression::EV_longdouble
:
1579 case AST_Expression::EV_float
:
1580 case AST_Expression::EV_double
:
1581 case AST_Expression::EV_longdouble
:
1586 case AST_Expression::EV_fixed
:
1587 return t2
!= AST_Expression::EV_fixed
;
1593 // Evaluate the expression wrt the evaluation kind requested. Supported
1594 // evaluation kinds are
1595 // - EK_const: The expression must evaluate to a constant
1596 // - EK_positive_int: The expression must further evaluate to a
1599 // @@(JP) This just maps one enum to another. It's a temporary fix,
1600 // but AST_Expression::EvalKind should go eventually.
1601 static AST_Expression::AST_ExprValue
*
1602 eval_kind (AST_Expression::AST_ExprValue
*ev
, AST_Expression::EvalKind ek
)
1604 // Make a copy to simplify the memory management logic.
1605 AST_Expression::AST_ExprValue
*newval
= nullptr;
1606 ACE_NEW_RETURN (newval
,
1607 AST_Expression::AST_ExprValue
,
1615 AST_Expression::AST_ExprValue
*retval
= nullptr;
1619 case AST_Expression::EK_const
:
1622 case AST_Expression::EK_positive_int
:
1623 retval
= coerce_value (newval
, AST_Expression::EV_ulong
);
1625 case AST_Expression::EK_short
:
1626 retval
= coerce_value (newval
, AST_Expression::EV_short
);
1628 case AST_Expression::EK_ushort
:
1629 retval
= coerce_value (newval
, AST_Expression::EV_ushort
);
1631 case AST_Expression::EK_long
:
1632 retval
= coerce_value (newval
, AST_Expression::EV_long
);
1634 case AST_Expression::EK_ulong
:
1635 retval
= coerce_value (newval
, AST_Expression::EV_ulong
);
1637 case AST_Expression::EK_longlong
:
1638 retval
= coerce_value (newval
, AST_Expression::EV_longlong
);
1640 case AST_Expression::EK_ulonglong
:
1641 retval
= coerce_value (newval
, AST_Expression::EV_ulonglong
);
1643 case AST_Expression::EK_octet
:
1644 retval
= coerce_value (newval
, AST_Expression::EV_octet
);
1646 case AST_Expression::EK_bool
:
1647 retval
= coerce_value (newval
, AST_Expression::EV_bool
);
1649 case AST_Expression::EK_fixed_point
:
1650 retval
= coerce_value (newval
, AST_Expression::EV_fixed
);
1652 case AST_Expression::EK_int8
:
1653 retval
= coerce_value (newval
, AST_Expression::EV_int8
);
1655 case AST_Expression::EK_uint8
:
1656 retval
= coerce_value (newval
, AST_Expression::EV_uint8
);
1658 case AST_Expression::EK_floating_point
:
1659 retval
= coerce_value (newval
, AST_Expression::EV_double
);
1663 // Sometimes the call above to coerce_value() will return an
1664 // evaluated newval, other times 0. But a heap-allocated
1665 // ExprValue is not always passed to coerce_value(), so we
1666 // have to manage it here, where we know it is always a 'new'.
1667 if (retval
!= newval
)
1676 // Private operations.
1678 // @@@ (JP) CORBA 2.6 and earlier say that in a constant expression,
1679 // each subexpression must fall within the range of the assigned type.
1680 // However, this may be hard for the compiler in some cases (must
1681 // evaluate all grouping possibilities). So there is an outstanding
1682 // issue, #1139, and the best guess is that it will ultimately be
1683 // decided that only the final value must fall within the range of
1684 // the assigned type. So there are no checks here, only in coerce().
1686 // Apply binary operators to an AST_Expression after evaluating
1687 // its sub-expressions.
1688 // Operations supported: '+', '-', '*', '/'
1689 template <typename Type
>
1691 do_eval_bin_op (AST_Expression::ExprComb op
, Type a
, Type b
, Type
&result
)
1695 case AST_Expression::EC_add
:
1698 case AST_Expression::EC_minus
:
1701 case AST_Expression::EC_mul
:
1704 case AST_Expression::EC_div
:
1705 if (!b
) return false;
1715 template <typename Type
>
1717 do_eval_bin_op_float (AST_Expression::ExprComb op
, Type a
, Type b
, Type
&result
)
1719 if (op
== AST_Expression::EC_div
)
1724 return do_eval_bin_op (op
, a
, b
, result
);
1727 AST_Expression::AST_ExprValue
*
1728 AST_Expression::eval_bin_op (AST_Expression::EvalKind ek
)
1730 AST_ExprValue
*retval
= nullptr;
1732 if (this->pd_v1
== nullptr || this->pd_v2
== nullptr)
1737 this->pd_v1
->set_ev (this->pd_v1
->eval_internal (ek
));
1738 this->pd_v2
->set_ev (this->pd_v2
->eval_internal (ek
));
1740 if (this->pd_v1
->ev () == nullptr || this->pd_v2
->ev () == nullptr)
1745 ExprType
const expr_type
= ek
== EK_const
?
1746 pd_v1
->ev()->et
: eval_kind_to_expr_type (ek
);
1747 if (expr_type
== EV_none
) return nullptr;
1749 ACE_NEW_RETURN (retval
,
1753 pd_v1
->set_ev (pd_v1
->coerce (expr_type
));
1754 pd_v2
->set_ev (pd_v2
->coerce (expr_type
));
1755 retval
->et
= expr_type
;
1757 bool success
= false;
1761 success
= do_eval_bin_op
<ACE_CDR::Int8
> (pd_ec
,
1762 pd_v1
->ev ()->u
.int8val
, pd_v2
->ev ()->u
.int8val
, retval
->u
.int8val
);
1766 success
= do_eval_bin_op
<ACE_CDR::UInt8
> (pd_ec
,
1767 pd_v1
->ev ()->u
.uint8val
, pd_v2
->ev ()->u
.uint8val
, retval
->u
.uint8val
);
1771 success
= do_eval_bin_op
<ACE_CDR::Short
> (pd_ec
,
1772 pd_v1
->ev ()->u
.sval
, pd_v2
->ev ()->u
.sval
, retval
->u
.sval
);
1776 success
= do_eval_bin_op
<ACE_CDR::UShort
> (pd_ec
,
1777 pd_v1
->ev ()->u
.usval
, pd_v2
->ev ()->u
.usval
, retval
->u
.usval
);
1781 success
= do_eval_bin_op
<ACE_CDR::Long
> (pd_ec
,
1782 pd_v1
->ev ()->u
.lval
, pd_v2
->ev ()->u
.lval
, retval
->u
.lval
);
1786 success
= do_eval_bin_op
<ACE_CDR::ULong
> (pd_ec
,
1787 pd_v1
->ev ()->u
.ulval
, pd_v2
->ev ()->u
.ulval
, retval
->u
.ulval
);
1791 success
= do_eval_bin_op
<ACE_CDR::LongLong
> (pd_ec
,
1792 pd_v1
->ev ()->u
.llval
, pd_v2
->ev ()->u
.llval
, retval
->u
.llval
);
1796 success
= do_eval_bin_op
<ACE_CDR::ULongLong
> (pd_ec
,
1797 pd_v1
->ev ()->u
.ullval
, pd_v2
->ev ()->u
.ullval
, retval
->u
.ullval
);
1801 success
= do_eval_bin_op
<ACE_CDR::Octet
> (pd_ec
,
1802 pd_v1
->ev ()->u
.oval
, pd_v2
->ev ()->u
.oval
, retval
->u
.oval
);
1806 success
= do_eval_bin_op_float
<ACE_CDR::Double
> (pd_ec
,
1807 pd_v1
->ev ()->u
.dval
, pd_v2
->ev ()->u
.dval
, retval
->u
.dval
);
1811 success
= do_eval_bin_op
<ACE_CDR::Fixed
> (pd_ec
,
1812 pd_v1
->ev ()->u
.fixedval
, pd_v2
->ev ()->u
.fixedval
, retval
->u
.fixedval
);
1828 template <typename Type
>
1830 do_eval_mod_op (Type a
, Type b
, Type
&result
)
1839 // Apply binary operators to an AST_Expression after evaluating
1840 // its sub-expressions.
1841 // Operations supported: '%'
1842 AST_Expression::AST_ExprValue
*
1843 AST_Expression::eval_mod_op (AST_Expression::EvalKind ek
)
1845 AST_ExprValue
*retval
= nullptr;
1847 if (this->pd_v1
== nullptr || this->pd_v2
== nullptr)
1852 this->pd_v1
->set_ev (this->pd_v1
->eval_internal (ek
));
1853 this->pd_v2
->set_ev (this->pd_v2
->eval_internal (ek
));
1855 if (this->pd_v1
->ev () == nullptr || this->pd_v2
->ev () == nullptr)
1860 ExprType
const expr_type
= ek
== EK_const
?
1861 pd_v1
->ev()->et
: eval_kind_to_expr_type (ek
);
1862 if (expr_type
== EV_none
) return nullptr;
1864 ACE_NEW_RETURN (retval
,
1868 pd_v1
->set_ev (pd_v1
->coerce (expr_type
));
1869 pd_v2
->set_ev (pd_v2
->coerce (expr_type
));
1870 retval
->et
= expr_type
;
1872 bool success
= false;
1876 success
= do_eval_mod_op
<ACE_CDR::Int8
> (
1877 pd_v1
->ev ()->u
.int8val
, pd_v2
->ev ()->u
.int8val
, retval
->u
.int8val
);
1881 success
= do_eval_mod_op
<ACE_CDR::UInt8
> (
1882 pd_v1
->ev ()->u
.uint8val
, pd_v2
->ev ()->u
.uint8val
, retval
->u
.uint8val
);
1886 success
= do_eval_mod_op
<ACE_CDR::Short
> (
1887 pd_v1
->ev ()->u
.sval
, pd_v2
->ev ()->u
.sval
, retval
->u
.sval
);
1891 success
= do_eval_mod_op
<ACE_CDR::UShort
> (
1892 pd_v1
->ev ()->u
.usval
, pd_v2
->ev ()->u
.usval
, retval
->u
.usval
);
1896 success
= do_eval_mod_op
<ACE_CDR::Long
> (
1897 pd_v1
->ev ()->u
.lval
, pd_v2
->ev ()->u
.lval
, retval
->u
.lval
);
1901 success
= do_eval_mod_op
<ACE_CDR::ULong
> (
1902 pd_v1
->ev ()->u
.ulval
, pd_v2
->ev ()->u
.ulval
, retval
->u
.ulval
);
1906 success
= do_eval_mod_op
<ACE_CDR::LongLong
> (
1907 pd_v1
->ev ()->u
.llval
, pd_v2
->ev ()->u
.llval
, retval
->u
.llval
);
1911 success
= do_eval_mod_op
<ACE_CDR::ULongLong
> (
1912 pd_v1
->ev ()->u
.ullval
, pd_v2
->ev ()->u
.ullval
, retval
->u
.ullval
);
1916 success
= do_eval_mod_op
<ACE_CDR::Octet
> (
1917 pd_v1
->ev ()->u
.oval
, pd_v2
->ev ()->u
.oval
, retval
->u
.oval
);
1921 success
= do_eval_mod_op
<ACE_CDR::Boolean
> (
1922 pd_v1
->ev ()->u
.bval
, pd_v2
->ev ()->u
.bval
, retval
->u
.bval
);
1938 // Apply bitwise operations to an AST_Expression after evaluating
1939 // its sub-expressions.
1940 // Operations supported: '%', '|', '&', '^', '<<', '>>'
1942 template <typename Type
>
1944 do_eval_bit_op_no_shift (AST_Expression::ExprComb op
, Type a
, Type b
, Type
&result
)
1948 case AST_Expression::EC_or
:
1951 case AST_Expression::EC_xor
:
1954 case AST_Expression::EC_and
:
1964 template <typename Type
>
1966 do_eval_bit_op (AST_Expression::ExprComb op
, Type a
, Type b
, Type
&result
)
1970 case AST_Expression::EC_left
:
1973 case AST_Expression::EC_right
:
1977 return do_eval_bit_op_no_shift (op
, a
, b
, result
);
1983 AST_Expression::AST_ExprValue
*
1984 AST_Expression::eval_bit_op (AST_Expression::EvalKind ek
)
1986 AST_Expression::AST_ExprValue
*retval
= nullptr;
1988 if (this->pd_v1
== nullptr || this->pd_v2
== nullptr)
1993 this->pd_v1
->set_ev (this->pd_v1
->eval_internal (ek
));
1994 this->pd_v2
->set_ev (this->pd_v2
->eval_internal (ek
));
1996 if (this->pd_v1
->ev () == nullptr || this->pd_v2
->ev () == nullptr)
2001 ExprType
const expr_type
= eval_kind_to_expr_type (ek
);
2002 if (expr_type
== EV_none
) return nullptr;
2004 ACE_NEW_RETURN (retval
,
2008 pd_v1
->set_ev (pd_v1
->coerce (expr_type
));
2009 pd_v2
->set_ev (pd_v2
->coerce (expr_type
));
2010 retval
->et
= expr_type
;
2012 bool success
= false;
2016 success
= do_eval_bit_op
<ACE_CDR::Int8
> (pd_ec
,
2017 pd_v1
->ev ()->u
.int8val
, pd_v2
->ev ()->u
.int8val
, retval
->u
.int8val
);
2021 success
= do_eval_bit_op
<ACE_CDR::UInt8
> (pd_ec
,
2022 pd_v1
->ev ()->u
.uint8val
, pd_v2
->ev ()->u
.uint8val
, retval
->u
.uint8val
);
2026 success
= do_eval_bit_op
<ACE_CDR::Short
> (pd_ec
,
2027 pd_v1
->ev ()->u
.sval
, pd_v2
->ev ()->u
.sval
, retval
->u
.sval
);
2031 success
= do_eval_bit_op
<ACE_CDR::UShort
> (pd_ec
,
2032 pd_v1
->ev ()->u
.usval
, pd_v2
->ev ()->u
.usval
, retval
->u
.usval
);
2036 success
= do_eval_bit_op
<ACE_CDR::Long
> (pd_ec
,
2037 pd_v1
->ev ()->u
.lval
, pd_v2
->ev ()->u
.lval
, retval
->u
.lval
);
2041 success
= do_eval_bit_op
<ACE_CDR::ULong
> (pd_ec
,
2042 pd_v1
->ev ()->u
.ulval
, pd_v2
->ev ()->u
.ulval
, retval
->u
.ulval
);
2046 success
= do_eval_bit_op
<ACE_CDR::LongLong
> (pd_ec
,
2047 pd_v1
->ev ()->u
.llval
, pd_v2
->ev ()->u
.llval
, retval
->u
.llval
);
2051 success
= do_eval_bit_op
<ACE_CDR::ULongLong
> (pd_ec
,
2052 pd_v1
->ev ()->u
.ullval
, pd_v2
->ev ()->u
.ullval
, retval
->u
.ullval
);
2056 success
= do_eval_bit_op
<ACE_CDR::Octet
> (pd_ec
,
2057 pd_v1
->ev ()->u
.oval
, pd_v2
->ev ()->u
.oval
, retval
->u
.oval
);
2061 success
= do_eval_bit_op_no_shift
<ACE_CDR::Boolean
> (pd_ec
,
2062 pd_v1
->ev ()->u
.bval
, pd_v2
->ev ()->u
.bval
, retval
->u
.bval
);
2078 // Apply unary operators to an AST_Expression after evaluating its
2080 // Operations supported: '-', '+', '~'
2081 AST_Expression::AST_ExprValue
*
2082 AST_Expression::eval_un_op (AST_Expression::EvalKind ek
)
2084 AST_ExprValue
*retval
= nullptr;
2086 if (this->pd_ev
!= nullptr)
2091 if (this->pd_v1
== nullptr)
2096 this->pd_v1
->set_ev (this->pd_v1
->eval_internal (ek
));
2098 if (this->pd_v1
->ev () == nullptr)
2103 ACE_NEW_RETURN (retval
,
2107 if (this->pd_v1
->ev ()->et
== EV_fixed
)
2109 retval
->et
= EV_fixed
;
2110 switch (this->pd_ec
)
2113 retval
->u
.fixedval
= this->pd_v1
->ev ()->u
.fixedval
;
2116 retval
->u
.fixedval
= -this->pd_v1
->ev ()->u
.fixedval
;
2125 retval
->et
= EV_double
;
2127 switch (this->pd_ec
)
2130 this->pd_v1
->set_ev (this->pd_v1
->coerce (EV_double
));
2132 if (this->pd_v1
->ev () == nullptr)
2139 retval
->u
.dval
= this->pd_v1
->ev ()->u
.dval
;
2142 this->pd_v1
->set_ev (this->pd_v1
->coerce (EV_double
));
2144 if (this->pd_v1
->ev () == nullptr)
2151 retval
->u
.dval
= -(this->pd_v1
->ev ()->u
.dval
);
2154 if (this->pd_v1
->ev () == nullptr)
2161 switch (this->pd_v1
->ev ()->et
)
2164 retval
->u
.sval
= ~this->pd_v1
->ev ()->u
.sval
;
2167 retval
->u
.usval
= ~this->pd_v1
->ev ()->u
.usval
;
2170 retval
->u
.lval
= ~this->pd_v1
->ev ()->u
.lval
;
2173 retval
->u
.ulval
= ~this->pd_v1
->ev ()->u
.ulval
;
2176 retval
->u
.llval
= ~this->pd_v1
->ev ()->u
.llval
;
2179 retval
->u
.ullval
= ~this->pd_v1
->ev ()->u
.ullval
;
2182 retval
->u
.oval
= ~this->pd_v1
->ev ()->u
.oval
;
2185 retval
->u
.int8val
= ~pd_v1
->ev ()->u
.int8val
;
2188 retval
->u
.uint8val
= ~pd_v1
->ev ()->u
.uint8val
;
2195 retval
->et
= pd_v1
->ev ()->et
;
2207 // Evaluate a symbolic AST_Expression by looking up the named
2209 AST_Expression::AST_ExprValue
*
2210 AST_Expression::eval_symbol (AST_Expression::EvalKind ek
)
2212 UTL_Scope
*s
= nullptr;
2213 AST_Decl
*d
= nullptr;
2214 AST_Constant
*c
= nullptr;
2216 // Is there a symbol stored?
2217 if (this->pd_n
== nullptr)
2219 idl_global
->err ()->eval_error (this);
2223 // Get current scope for lookup.
2224 if (idl_global
->scopes ().depth () > 0)
2226 s
= idl_global
->scopes ().top_non_null ();
2231 idl_global
->err ()->lookup_error (this->pd_n
);
2235 // If we are a template parameter placeholder, just skip the
2236 // rest - nothing needs to be evaluated until instantiation
2238 if (this->param_holder_
!= nullptr)
2244 d
= s
->lookup_by_name (this->pd_n
,
2249 idl_global
->err ()->lookup_error (this->pd_n
);
2253 // Is it a constant?
2254 if (d
->node_type () != AST_Decl::NT_const
2255 && d
->node_type () != AST_Decl::NT_enum_val
)
2257 idl_global
->err ()->constant_expected (this->pd_n
,
2262 if (d
->node_type () == AST_Decl::NT_enum_val
)
2264 AST_EnumVal
*enumval
= dynamic_cast<AST_EnumVal
*> (d
);
2265 enum_parent (enumval
->enum_parent ());
2268 // OK, now evaluate the constant we just got, to produce its value.
2269 c
= dynamic_cast<AST_Constant
*> (d
);
2276 return c
->constant_value ()->eval_internal (ek
);
2280 AST_Expression::type_mismatch (AST_Expression::ExprType t
)
2282 if (this->pd_ev
!= nullptr)
2284 return incompatible_types (this->pd_ev
->et
, t
);
2287 bool v1_mismatch
= false;
2288 bool v2_mismatch
= false;
2290 if (this->pd_v1
!= nullptr)
2292 v1_mismatch
= this->pd_v1
->type_mismatch (t
);
2295 if (this->pd_v2
!= nullptr)
2297 v2_mismatch
= this->pd_v2
->type_mismatch (t
);
2300 return v1_mismatch
| v2_mismatch
;
2303 // Coerce "this" to the ExprType required. Returns a copy of the
2304 // original ExprValue with the coercion applied, if successful, or
2306 AST_Expression::AST_ExprValue
*
2307 AST_Expression::check_and_coerce (AST_Expression::ExprType t
,
2312 AST_Decl
*enum_val
=
2313 idl_global
->scopes ().top_non_null ()->lookup_by_name (this->pd_n
,
2316 if (enum_val
!= nullptr)
2318 AST_Decl
*enum_decl
= ScopeAsDecl (enum_val
->defined_in ());
2320 if (d
->node_type () == AST_Decl::NT_typedef
)
2322 AST_Typedef
*td
= dynamic_cast<AST_Typedef
*> (d
);
2323 d
= td
->primitive_base_type ();
2328 idl_global
->err ()->incompatible_type_error (this);
2334 if (this->type_mismatch (t
))
2336 idl_global
->err ()->incompatible_type_error (this);
2340 if (d
!= nullptr && d
->node_type () == AST_Decl::NT_typedef
)
2345 return this->coerce (t
);
2348 // Coerce "this" to the ExprType required. Returns a copy of the
2349 // original ExprValue with the coercion applied, if successful, or
2351 AST_Expression::AST_ExprValue
*
2352 AST_Expression::coerce (AST_Expression::ExprType t
)
2354 AST_ExprValue
*tmp
= nullptr;
2356 // First, evaluate it, then try to coerce result type.
2357 // If already evaluated, return the result.
2361 tmp
= this->eval_internal (EK_int8
);
2364 tmp
= this->eval_internal (EK_uint8
);
2367 tmp
= this->eval_internal (EK_short
);
2370 tmp
= this->eval_internal (EK_ushort
);
2373 tmp
= this->eval_internal (EK_long
);
2376 tmp
= this->eval_internal (EK_ulong
);
2379 tmp
= this->eval_internal (EK_longlong
);
2382 tmp
= this->eval_internal (EK_ulonglong
);
2385 tmp
= this->eval_internal (EK_octet
);
2388 tmp
= this->eval_internal (EK_bool
);
2391 tmp
= this->eval_internal (EK_fixed_point
);
2396 tmp
= eval_internal (EK_floating_point
);
2406 tmp
= eval_internal (EK_const
);
2421 // Create a copy to contain coercion result.
2422 AST_ExprValue
*copy
= nullptr;
2423 ACE_NEW_RETURN (copy
,
2427 copy
->et
= this->pd_ev
->et
;
2429 switch (this->pd_ev
->et
)
2438 copy
->u
.ulval
= this->pd_ev
->u
.ulval
;
2441 copy
->u
.sval
= this->pd_ev
->u
.sval
;
2444 copy
->u
.usval
= this->pd_ev
->u
.usval
;
2447 copy
->u
.lval
= this->pd_ev
->u
.lval
;
2450 copy
->u
.ulval
= this->pd_ev
->u
.ulval
;
2453 copy
->u
.llval
= this->pd_ev
->u
.llval
;
2456 copy
->u
.ullval
= this->pd_ev
->u
.ullval
;
2459 copy
->u
.bval
= this->pd_ev
->u
.bval
;
2462 copy
->u
.fval
= this->pd_ev
->u
.fval
;
2465 copy
->u
.dval
= this->pd_ev
->u
.dval
;
2468 copy
->u
.cval
= this->pd_ev
->u
.cval
;
2471 copy
->u
.wcval
= this->pd_ev
->u
.wcval
;
2474 copy
->u
.oval
= this->pd_ev
->u
.oval
;
2477 copy
->u
.strval
= this->pd_ev
->u
.strval
;
2480 copy
->u
.wstrval
= this->pd_ev
->u
.wstrval
;
2483 copy
->u
.fixedval
= this->pd_ev
->u
.fixedval
;
2486 copy
->u
.int8val
= this->pd_ev
->u
.int8val
;
2489 copy
->u
.uint8val
= this->pd_ev
->u
.uint8val
;
2496 if (this->pd_ev
->et
== t
)
2502 AST_ExprValue
*ev
= coerce_value (copy
, t
);
2506 // coerce_value() will either return 'copy' or
2507 // return 0 without freeing 'copy'. It's
2508 // deleted here instead of putting a zillion
2509 // delete statments inside coerce_value().
2518 // Eval used internally.
2519 AST_Expression::AST_ExprValue
*
2520 AST_Expression::eval_internal (AST_Expression::EvalKind ek
)
2522 // Already evaluated?
2523 if (this->pd_ev
!= nullptr)
2525 return eval_kind (this->pd_ev
,
2529 // OK, must evaluate operator.
2530 switch (this->pd_ec
)
2536 this->pd_ev
= this->eval_bin_op (ek
);
2537 return eval_kind (this->pd_ev
,
2540 this->pd_ev
= this->eval_mod_op (ek
);
2541 return eval_kind (this->pd_ev
,
2548 this->pd_ev
= this->eval_bit_op (ek
);
2549 return eval_kind (this->pd_ev
,
2554 this->pd_ev
= this->eval_un_op (ek
);
2555 return eval_kind (this->pd_ev
,
2558 this->pd_ev
= this->eval_symbol (ek
);
2559 return eval_kind (this->pd_ev
,
2568 // Public operations.
2570 // Evaluate "this", assigning the value to the pd_ev field.
2572 AST_Expression::evaluate (EvalKind ek
)
2574 AST_ExprValue
*tmp
= eval_kind (this->pd_ev
, ek
);
2578 // Artifact of expressions doing double duty for all template
2579 // args. At this point, we have knowledge that we must be an
2580 // enum constant, so we set the expression type here, rather
2581 // than at the point of creation.
2582 if (ek
== AST_Expression::EK_const
&& this->pd_n
!= nullptr)
2584 this->pd_ev
->et
= AST_Expression::EV_enum
;
2588 // Expression equality comparison operator.
2590 AST_Expression::operator== (AST_Expression
*vc
)
2592 return compare (vc
);
2596 AST_Expression::compare (AST_Expression
*vc
)
2598 if (this->pd_ec
!= vc
->ec ())
2603 this->evaluate (EK_const
);
2604 vc
->evaluate (EK_const
);
2606 if (pd_ev
== nullptr || vc
->ev () == nullptr)
2611 if (this->pd_ev
->et
!= vc
->ev ()->et
)
2619 return this->pd_ev
->u
.sval
== vc
->ev ()->u
.sval
;
2621 return this->pd_ev
->u
.usval
== vc
->ev ()->u
.usval
;
2623 return this->pd_ev
->u
.lval
== vc
->ev ()->u
.lval
;
2625 return this->pd_ev
->u
.ulval
== vc
->ev ()->u
.ulval
;
2627 return ACE::is_equal (this->pd_ev
->u
.fval
, vc
->ev ()->u
.fval
);
2629 return ACE::is_equal (this->pd_ev
->u
.dval
, vc
->ev ()->u
.dval
);
2631 return this->pd_ev
->u
.cval
== vc
->ev ()->u
.cval
;
2633 return this->pd_ev
->u
.wcval
== vc
->ev ()->u
.wcval
;
2635 return this->pd_ev
->u
.oval
== vc
->ev ()->u
.oval
;
2637 return this->pd_ev
->u
.lval
== vc
->ev ()->u
.lval
;
2639 return !ACE_OS::strcmp (pd_ev
->u
.strval
->get_string (),
2640 vc
->ev ()->u
.strval
->get_string ());
2642 return !ACE_OS::strcmp (pd_ev
->u
.wstrval
, vc
->ev ()->u
.wstrval
);
2644 return pd_ev
->u
.llval
== vc
->ev ()->u
.llval
;
2646 return pd_ev
->u
.ullval
== vc
->ev ()->u
.ullval
;
2648 return pd_ev
->u
.fixedval
== vc
->ev ()->u
.fixedval
;
2650 return pd_ev
->u
.eval
== vc
->ev ()->u
.eval
;
2652 return pd_ev
->u
.int8val
== vc
->ev ()->u
.int8val
;
2654 return pd_ev
->u
.uint8val
== vc
->ev ()->u
.uint8val
;
2661 AST_Expression::get_tdef () const
2667 AST_Expression::param_holder () const
2669 return this->param_holder_
;
2672 // Helper functions for expression dumpers.
2674 // Dump this binary AST_Expression node to the ostream o.
2676 dump_binary_expr (ACE_OSTREAM_TYPE
&o
,
2686 o
<< " " << s
<< " ";
2694 // Dump this unary AST_Expression node to the ostream o.
2696 dump_unary_expr (ACE_OSTREAM_TYPE
&o
,
2704 // Dump the supplied AST_ExprValue to the ostream o.
2706 dump_expr_val (ACE_OSTREAM_TYPE
&o
, AST_Expression::AST_ExprValue
*ev
)
2710 case AST_Expression::EV_short
:
2713 case AST_Expression::EV_ushort
:
2716 case AST_Expression::EV_long
:
2719 case AST_Expression::EV_ulong
:
2720 case AST_Expression::EV_enum
:
2723 case AST_Expression::EV_float
:
2726 case AST_Expression::EV_double
:
2729 case AST_Expression::EV_char
:
2732 case AST_Expression::EV_wchar
:
2735 case AST_Expression::EV_octet
:
2737 std::ios
saved (nullptr);
2739 o
<< "0x" << std::hex
<< std::setw (2) << std::setfill ('0') << unsigned (ev
->u
.oval
);
2743 case AST_Expression::EV_bool
:
2744 o
<< (ev
->u
.bval
== true ? "TRUE" : "FALSE");
2746 case AST_Expression::EV_string
:
2747 if (ev
->u
.strval
!= nullptr)
2749 ev
->u
.strval
->dump (o
);
2753 o
<< "(null string)";
2756 case AST_Expression::EV_longlong
:
2759 case AST_Expression::EV_ulonglong
:
2762 case AST_Expression::EV_fixed
:
2763 o
<< ev
->u
.fixedval
;
2765 case AST_Expression::EV_int8
:
2766 o
<< static_cast<short> (ev
->u
.int8val
);
2768 case AST_Expression::EV_uint8
:
2769 o
<< static_cast<unsigned short> (ev
->u
.uint8val
);
2771 case AST_Expression::EV_longdouble
:
2772 case AST_Expression::EV_wstring
:
2773 case AST_Expression::EV_any
:
2774 case AST_Expression::EV_object
:
2775 case AST_Expression::EV_void
:
2776 case AST_Expression::EV_none
:
2780 o
<< "(Can not dump type " << AST_Expression::exprtype_to_string (ev
->et
) << ")";
2783 // Dump an AST_Expression node to the ostream o.
2785 AST_Expression::dump (ACE_OSTREAM_TYPE
&o
)
2787 // See if it was a constant or was evaluated already.
2788 if (this->pd_ev
!= nullptr)
2790 dump_expr_val (o
, this->pd_ev
);
2794 // OK, must print out an expression.
2795 switch (this->pd_ec
)
2797 // Binary expressions:
2799 dump_binary_expr (o
,
2805 dump_binary_expr (o
,
2811 dump_binary_expr (o
,
2817 dump_binary_expr (o
,
2823 dump_binary_expr (o
,
2829 dump_binary_expr (o
,
2835 dump_binary_expr (o
,
2841 dump_binary_expr (o
,
2847 dump_binary_expr (o
,
2853 dump_binary_expr (o
,
2858 // Unary expressions.
2874 // Unevaluated symbol.
2877 this->pd_n
->dump (o
);
2879 o
<< ACE_TEXT ("(nil symbolic name)");
2882 o
<< ACE_TEXT ("(none)");
2885 o
<< ACE_TEXT ("unsupported dump mode for expression with ec == ")
2886 << (int) this->pd_ec
;
2892 AST_Expression::ast_accept (ast_visitor
*visitor
)
2894 return visitor
->visit_expression (this);
2898 AST_Expression::destroy ()
2900 if (nullptr != this->pd_ev
)
2902 if (EV_string
== this->pd_ev
->et
)
2904 this->pd_ev
->u
.strval
->destroy ();
2905 delete this->pd_ev
->u
.strval
;
2906 this->pd_ev
->u
.strval
= nullptr;
2908 else if (EV_wstring
== this->pd_ev
->et
)
2910 ACE::strdelete (this->pd_ev
->u
.wstrval
);
2911 this->pd_ev
->u
.wstrval
= nullptr;
2915 this->pd_ev
= nullptr;
2917 if (this->pd_v1
!= nullptr)
2919 this->pd_v1
->destroy ();
2922 this->pd_v1
= nullptr;
2924 if (this->pd_v2
!= nullptr)
2926 this->pd_v2
->destroy ();
2929 this->pd_v2
= nullptr;
2931 if (this->pd_n
!= nullptr)
2933 this->pd_n
->destroy ();
2936 this->pd_n
= nullptr;
2938 if (this->param_holder_
!= nullptr)
2940 this->param_holder_
->destroy ();
2941 delete this->param_holder_
;
2942 this->param_holder_
= nullptr;
2949 AST_Expression::defined_in ()
2951 return this->pd_defined_in
;
2955 AST_Expression::set_defined_in (UTL_Scope
*d
)
2957 this->pd_defined_in
= d
;
2961 AST_Expression::line ()
2963 return this->pd_line
;
2967 AST_Expression::set_line (long l
)
2973 AST_Expression::file_name ()
2975 return this->pd_file_name
;
2979 AST_Expression::set_file_name (UTL_String
*f
)
2981 this->pd_file_name
= f
;
2984 AST_Expression::ExprComb
2985 AST_Expression::ec ()
2990 AST_Expression::AST_ExprValue
*
2991 AST_Expression::ev ()
2997 AST_Expression::set_ev (AST_Expression::AST_ExprValue
*new_ev
)
3000 this->pd_ev
= new_ev
;
3004 AST_Expression::v1 ()
3010 AST_Expression::set_v1 (AST_Expression
*e
)
3016 AST_Expression::v2 ()
3022 AST_Expression::set_v2 (AST_Expression
*e
)
3028 AST_Expression::n ()
3034 AST_Expression::set_n (UTL_ScopedName
*new_n
)
3040 AST_Expression::exprtype_to_string (ExprType t
)
3043 case AST_Expression::EV_short
:
3045 case AST_Expression::EV_ushort
:
3046 return "unsigned short";
3047 case AST_Expression::EV_long
:
3049 case AST_Expression::EV_ulong
:
3050 return "unsigned long";
3051 case AST_Expression::EV_float
:
3053 case AST_Expression::EV_double
:
3055 case AST_Expression::EV_char
:
3057 case AST_Expression::EV_octet
:
3059 case AST_Expression::EV_bool
:
3061 case AST_Expression::EV_string
:
3063 case AST_Expression::EV_enum
:
3065 case AST_Expression::EV_void
:
3067 case AST_Expression::EV_none
:
3069 case AST_Expression::EV_wchar
:
3071 case AST_Expression::EV_longlong
:
3073 case AST_Expression::EV_ulonglong
:
3075 case AST_Expression::EV_longdouble
:
3076 return "longdouble";
3077 case AST_Expression::EV_wstring
:
3079 case AST_Expression::EV_any
:
3081 case AST_Expression::EV_object
:
3083 case AST_Expression::EV_fixed
:
3085 case AST_Expression::EV_uint8
:
3087 case AST_Expression::EV_int8
:
3091 return "<UNKNOWN TYPE>";
3095 AST_Expression::enum_parent ()
3097 return enum_parent_
;
3101 AST_Expression::enum_parent (AST_Enum
*node
)
3103 enum_parent_
= node
;