1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: astexpression.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_idlc.hxx"
33 #include <idlc/astexpression.hxx>
34 #include <idlc/astconstant.hxx>
35 #include <idlc/astscope.hxx>
36 #include <idlc/errorhandler.hxx>
46 using namespace ::rtl
;
48 AstExpression::AstExpression(ExprComb c
, AstExpression
*pExpr1
, AstExpression
*pExpr2
)
53 , m_pSymbolicName(NULL
)
55 fillDefinitionDetails();
59 AstExpression::AstExpression(sal_Int32 l
)
60 : m_combOperator(EC_none
)
64 , m_pSymbolicName(NULL
)
66 fillDefinitionDetails();
68 m_exprValue
= new AstExprValue();
69 m_exprValue
->et
= ET_long
;
70 m_exprValue
->u
.lval
= l
;
73 AstExpression::AstExpression(sal_Int32 l
, ExprType et
)
74 : m_combOperator(EC_none
)
78 , m_pSymbolicName(NULL
)
80 fillDefinitionDetails();
82 m_exprValue
= new AstExprValue();
84 m_exprValue
->u
.lval
= l
;
87 AstExpression::AstExpression(sal_Int64 h
)
88 : m_combOperator(EC_none
)
92 , m_pSymbolicName(NULL
)
94 fillDefinitionDetails();
96 m_exprValue
= new AstExprValue();
97 m_exprValue
->et
= ET_hyper
;
98 m_exprValue
->u
.hval
= h
;
101 AstExpression::AstExpression(sal_uInt64 uh
)
102 : m_combOperator(EC_none
)
106 , m_pSymbolicName(NULL
)
108 fillDefinitionDetails();
110 m_exprValue
= new AstExprValue();
111 m_exprValue
->et
= ET_uhyper
;
112 m_exprValue
->u
.uhval
= uh
;
115 AstExpression::AstExpression(double d
)
116 : m_combOperator(EC_none
)
120 , m_pSymbolicName(NULL
)
122 fillDefinitionDetails();
124 m_exprValue
= new AstExprValue();
125 m_exprValue
->et
= ET_double
;
126 m_exprValue
->u
.dval
= d
;
129 AstExpression::AstExpression(::rtl::OString
* scopedName
)
130 : m_combOperator(EC_symbol
)
134 , m_pSymbolicName(scopedName
)
136 fillDefinitionDetails();
139 AstExpression::~AstExpression()
147 if ( m_pSymbolicName
)
148 delete m_pSymbolicName
;
152 * Perform the coercion from the given AstExprValue to the requested
153 * ExprType. Return an AstExprValue if successful, NULL if failed.
154 * must be done for hyper, uhyper
156 static AstExprValue
*
157 coerce_value(AstExprValue
*ev
, ExprType t
)
170 if (ev
->u
.usval
> SAL_MAX_INT16
)
172 ev
->u
.sval
= (sal_Int16
)ev
->u
.usval
;
176 if (ev
->u
.lval
< SAL_MIN_INT16
|| ev
->u
.lval
> SAL_MAX_INT16
)
178 ev
->u
.sval
= (sal_Int16
)ev
->u
.lval
;
182 if (ev
->u
.ulval
> SAL_MAX_INT16
)
184 ev
->u
.sval
= (sal_Int16
)ev
->u
.ulval
;
188 if (ev
->u
.hval
< SAL_MIN_INT16
|| ev
->u
.hval
> SAL_MAX_INT16
)
190 ev
->u
.sval
= (sal_Int16
)ev
->u
.hval
;
194 if (ev
->u
.uhval
> SAL_MAX_INT16
)
196 ev
->u
.sval
= (sal_Int16
)ev
->u
.uhval
;
200 ev
->u
.sval
= (sal_Int16
)ev
->u
.bval
;
204 if (ev
->u
.fval
< SAL_MIN_INT16
|| ev
->u
.fval
> SAL_MAX_INT16
)
206 ev
->u
.sval
= (sal_Int16
)ev
->u
.fval
;
210 if (ev
->u
.dval
< SAL_MIN_INT16
|| ev
->u
.dval
> SAL_MAX_INT16
)
212 ev
->u
.sval
= (sal_Int16
)ev
->u
.dval
;
216 ev
->u
.sval
= (sal_Int16
)ev
->u
.byval
;
229 ev
->u
.usval
= (sal_uInt16
)ev
->u
.sval
;
235 if (ev
->u
.lval
< 0 || ev
->u
.lval
> SAL_MAX_UINT16
)
237 ev
->u
.usval
= (sal_uInt16
)ev
->u
.lval
;
241 if (ev
->u
.ulval
> SAL_MAX_UINT16
)
243 ev
->u
.usval
= (sal_uInt16
)ev
->u
.ulval
;
247 if (ev
->u
.hval
< 0 || ev
->u
.hval
> SAL_MAX_UINT16
)
249 ev
->u
.usval
= (sal_uInt16
)ev
->u
.hval
;
253 if (ev
->u
.uhval
> SAL_MAX_UINT16
)
255 ev
->u
.usval
= (sal_uInt16
)ev
->u
.uhval
;
259 ev
->u
.usval
= (sal_uInt16
)ev
->u
.bval
;
263 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT16
)
265 ev
->u
.usval
= (sal_uInt16
)ev
->u
.fval
;
269 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT16
)
271 ev
->u
.usval
= (sal_uInt16
)ev
->u
.dval
;
275 ev
->u
.usval
= (sal_uInt16
)ev
->u
.byval
;
286 ev
->u
.lval
= (sal_Int32
)ev
->u
.sval
;
290 ev
->u
.lval
= (sal_Int32
)ev
->u
.usval
;
296 if (ev
->u
.ulval
> SAL_MAX_INT32
)
298 ev
->u
.lval
= (sal_Int32
)ev
->u
.ulval
;
302 if (ev
->u
.hval
< SAL_MIN_INT32
|| ev
->u
.hval
> SAL_MAX_INT32
)
304 ev
->u
.lval
= (sal_Int32
)ev
->u
.hval
;
308 if (ev
->u
.uhval
> SAL_MAX_INT32
)
310 ev
->u
.lval
= (sal_Int32
)ev
->u
.uhval
;
314 ev
->u
.lval
= (sal_Int32
)ev
->u
.bval
;
318 if (ev
->u
.fval
< SAL_MIN_INT32
|| ev
->u
.fval
> SAL_MAX_INT32
)
320 ev
->u
.lval
= (sal_Int32
)ev
->u
.fval
;
324 if (ev
->u
.dval
< SAL_MIN_INT32
|| ev
->u
.dval
> SAL_MAX_INT32
)
326 ev
->u
.lval
= (sal_Int32
)ev
->u
.dval
;
330 ev
->u
.lval
= (sal_Int32
) ev
->u
.byval
;
343 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.sval
;
347 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.usval
;
353 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.lval
;
359 if (ev
->u
.hval
< 0 || ev
->u
.hval
> SAL_MAX_UINT32
)
361 ev
->u
.lval
= (sal_uInt32
)ev
->u
.hval
;
365 if (ev
->u
.uhval
> SAL_MAX_UINT32
)
367 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.uhval
;
371 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.bval
;
375 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT32
)
377 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.fval
;
381 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT32
)
383 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.dval
;
387 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.byval
;
398 ev
->u
.hval
= (sal_Int64
)ev
->u
.sval
;
402 ev
->u
.hval
= (sal_Int64
)ev
->u
.usval
;
406 ev
->u
.hval
= (sal_Int64
)ev
->u
.lval
;
410 ev
->u
.hval
= (sal_Int64
)ev
->u
.ulval
;
416 if (ev
->u
.uhval
> SAL_MAX_INT64
)
418 ev
->u
.hval
= (sal_Int64
)ev
->u
.uhval
;
422 ev
->u
.hval
= (sal_Int64
)ev
->u
.bval
;
426 if (ev
->u
.fval
< SAL_MIN_INT64
|| ev
->u
.fval
> SAL_MAX_INT64
)
428 ev
->u
.hval
= (sal_Int64
)ev
->u
.fval
;
432 if (ev
->u
.dval
< SAL_MIN_INT64
|| ev
->u
.dval
> SAL_MAX_INT64
)
434 ev
->u
.hval
= (sal_Int64
)ev
->u
.dval
;
438 ev
->u
.hval
= (sal_Int64
)ev
->u
.byval
;
451 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.sval
;
455 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.usval
;
461 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.lval
;
465 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.ulval
;
471 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.hval
;
477 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.bval
;
481 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT64
)
483 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.fval
;
487 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT64
)
489 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.dval
;
493 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.byval
;
504 ev
->u
.bval
= (ev
->u
.sval
== 0) ? sal_False
: sal_True
;
508 ev
->u
.bval
= (ev
->u
.usval
== 0) ? sal_False
: sal_True
;
512 ev
->u
.bval
= (ev
->u
.lval
== 0) ? sal_False
: sal_True
;
516 ev
->u
.bval
= (ev
->u
.ulval
== 0) ? sal_False
: sal_True
;
520 ev
->u
.bval
= (ev
->u
.hval
== 0) ? sal_False
: sal_True
;
524 ev
->u
.bval
= (ev
->u
.uhval
== 0) ? sal_False
: sal_True
;
530 ev
->u
.bval
= (ev
->u
.fval
== 0.0) ? sal_False
: sal_True
;
534 ev
->u
.bval
= (ev
->u
.dval
== 0.0) ? sal_False
: sal_True
;
538 ev
->u
.bval
= (ev
->u
.byval
== 0) ? sal_False
: sal_True
;
549 ev
->u
.fval
= (float)ev
->u
.sval
;
553 ev
->u
.fval
= (float)ev
->u
.usval
;
557 ev
->u
.fval
= (float)ev
->u
.lval
;
561 ev
->u
.fval
= (float)ev
->u
.ulval
;
565 ev
->u
.fval
= (float)ev
->u
.hval
;
569 if ((float)ev
->u
.ulval
> FLT_MAX
)
571 ev
->u
.fval
= (float)ev
->u
.ulval
;
575 ev
->u
.fval
= (ev
->u
.bval
== sal_True
) ? 1.0f
: 0.0f
;
581 if ((float)ev
->u
.dval
> FLT_MAX
|| (float)ev
->u
.dval
< -FLT_MAX
)
583 ev
->u
.fval
= (float)ev
->u
.dval
;
587 ev
->u
.fval
= (float)ev
->u
.byval
;
598 ev
->u
.dval
= (double)ev
->u
.sval
;
602 ev
->u
.dval
= (double)ev
->u
.usval
;
606 ev
->u
.dval
= (double)ev
->u
.lval
;
610 ev
->u
.dval
= (double)ev
->u
.ulval
;
614 ev
->u
.dval
= (double)ev
->u
.hval
;
618 if ((double)ev
->u
.dval
> FLT_MAX
|| (double)ev
->u
.dval
< -FLT_MAX
)
620 ev
->u
.dval
= (double)ev
->u
.ulval
;
624 ev
->u
.dval
= (ev
->u
.bval
== sal_True
) ? 1.0 : 0.0;
628 ev
->u
.dval
= (double)ev
->u
.fval
;
634 ev
->u
.dval
= (double)ev
->u
.byval
;
645 if (ev
->u
.sval
< SAL_MIN_INT8
|| ev
->u
.sval
> SAL_MAX_UINT8
)
647 ev
->u
.byval
= (sal_uChar
)ev
->u
.sval
;
651 if (ev
->u
.usval
> SAL_MAX_UINT8
)
653 ev
->u
.byval
= (sal_uChar
)ev
->u
.usval
;
657 if (ev
->u
.lval
< SAL_MIN_INT8
|| ev
->u
.lval
> SAL_MAX_UINT8
)
659 ev
->u
.byval
= (sal_uChar
) ev
->u
.lval
;
663 if (ev
->u
.ulval
> SAL_MAX_UINT8
)
665 ev
->u
.byval
= (sal_uChar
) ev
->u
.ulval
;
669 if (ev
->u
.hval
< SAL_MIN_INT8
|| ev
->u
.hval
> SAL_MAX_UINT8
)
671 ev
->u
.byval
= (sal_uChar
) ev
->u
.hval
;
675 if (ev
->u
.uhval
> SAL_MAX_UINT8
)
677 ev
->u
.byval
= (sal_uChar
) ev
->u
.uhval
;
681 ev
->u
.byval
= (ev
->u
.bval
== sal_False
) ? 1 : 0;
685 if (ev
->u
.fval
< SAL_MIN_INT8
|| ev
->u
.fval
> SAL_MAX_UINT8
)
687 ev
->u
.byval
= (sal_uChar
) ev
->u
.fval
;
691 if (ev
->u
.dval
< SAL_MIN_INT8
|| ev
->u
.dval
> SAL_MAX_UINT8
)
693 ev
->u
.byval
= (sal_uChar
) ev
->u
.dval
;
709 * Evaluate the expression with the evaluation kind requested. Supported
710 * evaluation kinds are
711 * - EK_const: The expression must evaluate to a constant
712 * - EK_positive_int: The expression must further evaluate to a
715 static AstExprValue
*
716 eval_kind(AstExprValue
*ev
, EvalKind ek
)
720 if (ek
== EK_positive_int
)
721 return coerce_value(ev
, ET_ulong
);
726 AstExprValue
* AstExpression::coerce(ExprType t
, sal_Bool bAssign
)
731 * Is it already of the right type?
733 if (m_exprValue
!= NULL
&& m_exprValue
->et
== t
)
738 * First, evaluate it, then try to coerce result type
739 * If already evaluated, return the result
741 m_exprValue
= eval_internal(EK_const
);
742 if (m_exprValue
== NULL
)
746 * Create a copy to contain coercion result
748 copy
= new AstExprValue
;
750 copy
->et
= m_exprValue
->et
;
751 switch (m_exprValue
->et
)
754 copy
->u
.sval
= m_exprValue
->u
.sval
;
757 copy
->u
.usval
= m_exprValue
->u
.usval
;
760 copy
->u
.lval
= m_exprValue
->u
.lval
;
763 copy
->u
.ulval
= m_exprValue
->u
.ulval
;
766 copy
->u
.hval
= m_exprValue
->u
.hval
;
769 copy
->u
.uhval
= m_exprValue
->u
.uhval
;
772 copy
->u
.bval
= m_exprValue
->u
.bval
;
775 copy
->u
.fval
= m_exprValue
->u
.fval
;
778 copy
->u
.dval
= m_exprValue
->u
.dval
;
781 copy
->u
.byval
= m_exprValue
->u
.byval
;
790 m_exprValue
= coerce_value(copy
, t
);
794 return coerce_value(copy
, t
);
797 void AstExpression::evaluate(EvalKind ek
)
799 m_exprValue
= eval_internal(ek
);
800 m_exprValue
= eval_kind(m_exprValue
, ek
);
803 sal_Bool
AstExpression::operator==(AstExpression
*pExpr
)
805 if (m_combOperator
!= pExpr
->getCombOperator())
808 pExpr
->evaluate(EK_const
);
809 if (m_exprValue
== NULL
|| pExpr
->getExprValue() == NULL
)
811 if (m_exprValue
->et
!= pExpr
->getExprValue()->et
)
813 switch (m_exprValue
->et
)
816 return (m_exprValue
->u
.sval
== pExpr
->getExprValue()->u
.sval
) ? sal_True
: sal_False
;
818 return (m_exprValue
->u
.usval
== pExpr
->getExprValue()->u
.usval
) ? sal_True
: sal_False
;
820 return (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
822 return (m_exprValue
->u
.ulval
== pExpr
->getExprValue()->u
.ulval
) ? sal_True
: sal_False
;
824 return (m_exprValue
->u
.hval
== pExpr
->getExprValue()->u
.hval
) ? sal_True
: sal_False
;
826 return (m_exprValue
->u
.uhval
== pExpr
->getExprValue()->u
.uhval
) ? sal_True
: sal_False
;
828 return (m_exprValue
->u
.fval
== pExpr
->getExprValue()->u
.fval
) ? sal_True
: sal_False
;
830 return (m_exprValue
->u
.dval
== pExpr
->getExprValue()->u
.dval
) ? sal_True
: sal_False
;
832 return (m_exprValue
->u
.byval
== pExpr
->getExprValue()->u
.byval
) ? sal_True
: sal_False
;
834 return (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
843 sal_Bool
AstExpression::compare(AstExpression
*pExpr
)
845 if (m_combOperator
!= pExpr
->getCombOperator())
848 pExpr
->evaluate(EK_const
);
849 if (m_exprValue
== NULL
|| pExpr
->getExprValue() == NULL
)
851 if (m_exprValue
->et
!= pExpr
->getExprValue()->et
)
853 switch (m_exprValue
->et
)
856 return (m_exprValue
->u
.sval
== pExpr
->getExprValue()->u
.sval
) ? sal_True
: sal_False
;
858 return (m_exprValue
->u
.usval
== pExpr
->getExprValue()->u
.usval
) ? sal_True
: sal_False
;
860 return (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
862 return (m_exprValue
->u
.ulval
== pExpr
->getExprValue()->u
.ulval
) ? sal_True
: sal_False
;
864 return (m_exprValue
->u
.hval
== pExpr
->getExprValue()->u
.hval
) ? sal_True
: sal_False
;
866 return (m_exprValue
->u
.uhval
== pExpr
->getExprValue()->u
.uhval
) ? sal_True
: sal_False
;
868 return (m_exprValue
->u
.fval
== pExpr
->getExprValue()->u
.fval
) ? sal_True
: sal_False
;
870 return (m_exprValue
->u
.dval
== pExpr
->getExprValue()->u
.dval
) ? sal_True
: sal_False
;
872 return (m_exprValue
->u
.byval
== pExpr
->getExprValue()->u
.byval
) ? sal_True
: sal_False
;
874 return (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
883 void AstExpression::fillDefinitionDetails()
885 m_pScope
= idlc()->scopes()->depth() > 0 ? idlc()->scopes()->top() : NULL
;
886 m_lineNo
= idlc()->getLineNumber();
887 m_fileName
= idlc()->getFileName();
890 AstExprValue
* AstExpression::eval_internal(EvalKind ek
)
895 if ( m_exprValue
!= NULL
)
896 return eval_kind(m_exprValue
, ek
);
898 * OK, must evaluate operator
900 switch (m_combOperator
)
907 m_exprValue
= eval_bin_op(ek
);
908 return eval_kind(m_exprValue
, ek
);
914 m_exprValue
= eval_bit_op(ek
);
915 return eval_kind(m_exprValue
, ek
);
919 m_exprValue
= eval_un_op(ek
);
920 return eval_kind(m_exprValue
, ek
);
922 m_exprValue
= eval_symbol(ek
);
923 return eval_kind(m_exprValue
, ek
);
931 AstExprValue
* AstExpression::eval_bin_op(EvalKind ek
)
933 AstExprValue
*retval
= NULL
;
934 ExprType eType
= ET_double
;
936 if ( m_combOperator
== EC_mod
)
939 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
941 if (m_subExpr1
== NULL
|| m_subExpr2
== NULL
)
943 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
944 if (m_subExpr1
->getExprValue() == NULL
)
946 m_subExpr1
->setExprValue(m_subExpr1
->coerce(eType
));
947 if (m_subExpr1
->getExprValue() == NULL
)
949 m_subExpr2
->setExprValue(m_subExpr2
->eval_internal(ek
));
950 if (m_subExpr2
->getExprValue() == NULL
)
952 m_subExpr2
->setExprValue(m_subExpr2
->coerce(eType
));
953 if (m_subExpr2
->getExprValue() == NULL
)
956 retval
= new AstExprValue();
959 switch (m_combOperator
)
962 if (m_subExpr2
->getExprValue()->u
.hval
== 0)
964 retval
->u
.hval
= m_subExpr1
->getExprValue()->u
.hval
% m_subExpr2
->getExprValue()->u
.hval
;
967 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
+ m_subExpr2
->getExprValue()->u
.dval
;
970 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
- m_subExpr2
->getExprValue()->u
.dval
;
973 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
* m_subExpr2
->getExprValue()->u
.dval
;
976 if (m_subExpr2
->getExprValue()->u
.dval
== 0.0)
978 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
/ m_subExpr2
->getExprValue()->u
.dval
;
987 AstExprValue
* AstExpression::eval_bit_op(EvalKind ek
)
989 AstExprValue
*retval
= NULL
;
991 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
993 if (m_subExpr1
== NULL
|| m_subExpr2
== NULL
)
995 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
996 if (m_subExpr1
->getExprValue() == NULL
)
998 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_long
));
999 if (m_subExpr1
->getExprValue() == NULL
)
1001 m_subExpr2
->setExprValue(m_subExpr2
->eval_internal(ek
));
1002 if (m_subExpr2
->getExprValue() == NULL
)
1004 m_subExpr2
->setExprValue(m_subExpr2
->coerce(ET_long
));
1005 if (m_subExpr2
->getExprValue() == NULL
)
1008 retval
= new AstExprValue
;
1009 retval
->et
= ET_long
;
1011 switch (m_combOperator
)
1014 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
| m_subExpr2
->getExprValue()->u
.lval
;
1017 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
^ m_subExpr2
->getExprValue()->u
.lval
;
1020 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
& m_subExpr2
->getExprValue()->u
.lval
;
1023 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
<< m_subExpr2
->getExprValue()->u
.lval
;
1026 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
>> m_subExpr2
->getExprValue()->u
.lval
;
1035 AstExprValue
* AstExpression::eval_un_op(EvalKind ek
)
1037 AstExprValue
*retval
= NULL
;
1039 if (m_exprValue
!= NULL
)
1042 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
1044 if (m_subExpr1
== NULL
)
1046 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
1047 if (m_subExpr1
->getExprValue() == NULL
)
1049 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_double
));
1050 if (m_subExpr1
->getExprValue() == NULL
)
1053 retval
= new AstExprValue();
1054 retval
->et
= ET_double
;
1056 switch (m_combOperator
)
1059 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
;
1062 retval
->u
.lval
= -(m_subExpr1
->getExprValue()->u
.lval
);
1065 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_long
));
1066 if (m_subExpr1
->getExprValue() == NULL
)
1068 retval
->u
.lval
= ~m_subExpr1
->getExprValue()->u
.lval
;
1077 AstExprValue
* AstExpression::eval_symbol(EvalKind ek
)
1079 AstScope
*pScope
= 0;
1080 AstDeclaration
*pDecl
;
1081 AstConstant
*pConst
;
1084 * Is there a symbol stored?
1086 if (m_pSymbolicName
== NULL
)
1088 idlc()->error()->evalError(this);
1092 * Get current scope for lookup
1094 if (idlc()->scopes()->depth() > 0)
1095 pScope
= idlc()->scopes()->topNonNull();
1098 idlc()->error()->lookupError(*m_pSymbolicName
);
1104 pDecl
= pScope
->lookupByName(*m_pSymbolicName
);
1107 idlc()->error()->lookupError(*m_pSymbolicName
);
1113 if (pDecl
->getNodeType() != NT_const
&&
1114 pDecl
->getNodeType() != NT_enum_val
)
1116 idlc()->error()->constantExpected(pDecl
, *m_pSymbolicName
);
1119 if (!idlc()->error()->checkPublished(pDecl
))
1124 * OK, now evaluate the constant we just got, to produce its value
1126 pConst
= static_cast< AstConstant
* >(pDecl
);
1129 return pConst
->getConstValue()->eval_internal(ek
);
1132 OString
AstExpression::toString()
1135 if ( m_combOperator
== EC_symbol
)
1136 return *m_pSymbolicName
;
1140 switch (m_exprValue
->et
)
1143 return OString::valueOf((sal_Int32
)m_exprValue
->u
.sval
);
1145 return OString::valueOf((sal_Int32
)m_exprValue
->u
.usval
);
1147 return OString::valueOf(m_exprValue
->u
.lval
);
1149 return OString::valueOf((sal_Int32
)m_exprValue
->u
.ulval
);
1151 return OString::valueOf(m_exprValue
->u
.hval
);
1153 return OString::valueOf((sal_Int64
)m_exprValue
->u
.uhval
);
1155 return OString::valueOf(m_exprValue
->u
.fval
);
1157 return OString::valueOf(m_exprValue
->u
.dval
);
1159 return OString::valueOf((sal_Int32
)m_exprValue
->u
.byval
);
1161 if ( m_exprValue
->u
.lval
== 0)
1162 return OString("FALSE");
1164 return OString("TRUE");
1171 switch (m_combOperator
)
1174 exprStr
+= OString("+");
1177 exprStr
+= OString("-");
1180 exprStr
+= OString("~");
1186 exprStr
+= m_subExpr1
->toString();
1187 switch (m_combOperator
)
1190 exprStr
+= OString(" + ");
1193 exprStr
+= OString(" - ");
1196 exprStr
+= OString(" * ");
1199 exprStr
+= OString(" / ");
1202 exprStr
+= OString(" % ");
1205 exprStr
+= OString(" | ");
1208 exprStr
+= OString(" ^ ");
1211 exprStr
+= OString(" & ");
1214 exprStr
+= OString(" << ");
1217 exprStr
+= OString(" >> ");
1224 exprStr
+= m_subExpr2
->toString();
1229 // Convert the type of an AST_Expression to a char *
1230 const sal_Char
* SAL_CALL
exprTypeToString(ExprType t
)
1237 return "unsigned short";
1241 return "unsigned long";
1245 return "unsigned hyper";