1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <idlc/astexpression.hxx>
22 #include <idlc/astconstant.hxx>
23 #include <idlc/astscope.hxx>
24 #include <idlc/errorhandler.hxx>
28 #include <memory> // auto_ptr<>
35 using namespace ::rtl
;
37 AstExpression::AstExpression(ExprComb c
, AstExpression
*pExpr1
, AstExpression
*pExpr2
)
42 , m_pSymbolicName(NULL
)
44 fillDefinitionDetails();
48 AstExpression::AstExpression(sal_Int32 l
)
49 : m_combOperator(EC_none
)
53 , m_pSymbolicName(NULL
)
55 fillDefinitionDetails();
57 m_exprValue
= new AstExprValue();
58 m_exprValue
->et
= ET_long
;
59 m_exprValue
->u
.lval
= l
;
62 AstExpression::AstExpression(sal_Int32 l
, ExprType et
)
63 : m_combOperator(EC_none
)
67 , m_pSymbolicName(NULL
)
69 fillDefinitionDetails();
71 m_exprValue
= new AstExprValue();
73 m_exprValue
->u
.lval
= l
;
76 AstExpression::AstExpression(sal_Int64 h
)
77 : m_combOperator(EC_none
)
81 , m_pSymbolicName(NULL
)
83 fillDefinitionDetails();
85 m_exprValue
= new AstExprValue();
86 m_exprValue
->et
= ET_hyper
;
87 m_exprValue
->u
.hval
= h
;
90 AstExpression::AstExpression(sal_uInt64 uh
)
91 : m_combOperator(EC_none
)
95 , m_pSymbolicName(NULL
)
97 fillDefinitionDetails();
99 m_exprValue
= new AstExprValue();
100 m_exprValue
->et
= ET_uhyper
;
101 m_exprValue
->u
.uhval
= uh
;
104 AstExpression::AstExpression(double d
)
105 : m_combOperator(EC_none
)
109 , m_pSymbolicName(NULL
)
111 fillDefinitionDetails();
113 m_exprValue
= new AstExprValue();
114 m_exprValue
->et
= ET_double
;
115 m_exprValue
->u
.dval
= d
;
118 AstExpression::AstExpression(::rtl::OString
* scopedName
)
119 : m_combOperator(EC_symbol
)
123 , m_pSymbolicName(scopedName
)
125 fillDefinitionDetails();
128 AstExpression::~AstExpression()
136 if ( m_pSymbolicName
)
137 delete m_pSymbolicName
;
141 * Perform the coercion from the given AstExprValue to the requested
142 * ExprType. Return an AstExprValue if successful, NULL if failed.
143 * must be done for hyper, uhyper
145 static AstExprValue
*
146 coerce_value(AstExprValue
*ev
, ExprType t
)
159 if (ev
->u
.usval
> SAL_MAX_INT16
)
161 ev
->u
.sval
= (sal_Int16
)ev
->u
.usval
;
165 if (ev
->u
.lval
< SAL_MIN_INT16
|| ev
->u
.lval
> SAL_MAX_INT16
)
167 ev
->u
.sval
= (sal_Int16
)ev
->u
.lval
;
171 if (ev
->u
.ulval
> SAL_MAX_INT16
)
173 ev
->u
.sval
= (sal_Int16
)ev
->u
.ulval
;
177 if (ev
->u
.hval
< SAL_MIN_INT16
|| ev
->u
.hval
> SAL_MAX_INT16
)
179 ev
->u
.sval
= (sal_Int16
)ev
->u
.hval
;
183 if (ev
->u
.uhval
> SAL_MAX_INT16
)
185 ev
->u
.sval
= (sal_Int16
)ev
->u
.uhval
;
189 ev
->u
.sval
= (sal_Int16
)ev
->u
.bval
;
193 if (ev
->u
.fval
< SAL_MIN_INT16
|| ev
->u
.fval
> SAL_MAX_INT16
)
195 ev
->u
.sval
= (sal_Int16
)ev
->u
.fval
;
199 if (ev
->u
.dval
< SAL_MIN_INT16
|| ev
->u
.dval
> SAL_MAX_INT16
)
201 ev
->u
.sval
= (sal_Int16
)ev
->u
.dval
;
205 ev
->u
.sval
= (sal_Int16
)ev
->u
.byval
;
218 ev
->u
.usval
= (sal_uInt16
)ev
->u
.sval
;
224 if (ev
->u
.lval
< 0 || ev
->u
.lval
> SAL_MAX_UINT16
)
226 ev
->u
.usval
= (sal_uInt16
)ev
->u
.lval
;
230 if (ev
->u
.ulval
> SAL_MAX_UINT16
)
232 ev
->u
.usval
= (sal_uInt16
)ev
->u
.ulval
;
236 if (ev
->u
.hval
< 0 || ev
->u
.hval
> SAL_MAX_UINT16
)
238 ev
->u
.usval
= (sal_uInt16
)ev
->u
.hval
;
242 if (ev
->u
.uhval
> SAL_MAX_UINT16
)
244 ev
->u
.usval
= (sal_uInt16
)ev
->u
.uhval
;
248 ev
->u
.usval
= (sal_uInt16
)ev
->u
.bval
;
252 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT16
)
254 ev
->u
.usval
= (sal_uInt16
)ev
->u
.fval
;
258 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT16
)
260 ev
->u
.usval
= (sal_uInt16
)ev
->u
.dval
;
264 ev
->u
.usval
= (sal_uInt16
)ev
->u
.byval
;
275 ev
->u
.lval
= (sal_Int32
)ev
->u
.sval
;
279 ev
->u
.lval
= (sal_Int32
)ev
->u
.usval
;
285 if (ev
->u
.ulval
> SAL_MAX_INT32
)
287 ev
->u
.lval
= (sal_Int32
)ev
->u
.ulval
;
291 if (ev
->u
.hval
< SAL_MIN_INT32
|| ev
->u
.hval
> SAL_MAX_INT32
)
293 ev
->u
.lval
= (sal_Int32
)ev
->u
.hval
;
297 if (ev
->u
.uhval
> SAL_MAX_INT32
)
299 ev
->u
.lval
= (sal_Int32
)ev
->u
.uhval
;
303 ev
->u
.lval
= (sal_Int32
)ev
->u
.bval
;
307 if (ev
->u
.fval
< SAL_MIN_INT32
|| ev
->u
.fval
> SAL_MAX_INT32
)
309 ev
->u
.lval
= (sal_Int32
)ev
->u
.fval
;
313 if (ev
->u
.dval
< SAL_MIN_INT32
|| ev
->u
.dval
> SAL_MAX_INT32
)
315 ev
->u
.lval
= (sal_Int32
)ev
->u
.dval
;
319 ev
->u
.lval
= (sal_Int32
) ev
->u
.byval
;
332 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.sval
;
336 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.usval
;
342 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.lval
;
348 if (ev
->u
.hval
< 0 || ev
->u
.hval
> SAL_MAX_UINT32
)
350 ev
->u
.lval
= (sal_uInt32
)ev
->u
.hval
;
354 if (ev
->u
.uhval
> SAL_MAX_UINT32
)
356 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.uhval
;
360 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.bval
;
364 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT32
)
366 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.fval
;
370 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT32
)
372 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.dval
;
376 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.byval
;
387 ev
->u
.hval
= (sal_Int64
)ev
->u
.sval
;
391 ev
->u
.hval
= (sal_Int64
)ev
->u
.usval
;
395 ev
->u
.hval
= (sal_Int64
)ev
->u
.lval
;
399 ev
->u
.hval
= (sal_Int64
)ev
->u
.ulval
;
405 if (ev
->u
.uhval
> SAL_MAX_INT64
)
407 ev
->u
.hval
= (sal_Int64
)ev
->u
.uhval
;
411 ev
->u
.hval
= (sal_Int64
)ev
->u
.bval
;
415 if (ev
->u
.fval
< SAL_MIN_INT64
|| ev
->u
.fval
> SAL_MAX_INT64
)
417 ev
->u
.hval
= (sal_Int64
)ev
->u
.fval
;
421 if (ev
->u
.dval
< SAL_MIN_INT64
|| ev
->u
.dval
> SAL_MAX_INT64
)
423 ev
->u
.hval
= (sal_Int64
)ev
->u
.dval
;
427 ev
->u
.hval
= (sal_Int64
)ev
->u
.byval
;
440 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.sval
;
444 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.usval
;
450 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.lval
;
454 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.ulval
;
460 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.hval
;
466 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.bval
;
470 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT64
)
472 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.fval
;
476 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT64
)
478 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.dval
;
482 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.byval
;
493 ev
->u
.bval
= ev
->u
.sval
!= 0;
497 ev
->u
.bval
= ev
->u
.usval
!= 0;
501 ev
->u
.bval
= ev
->u
.lval
!= 0;
505 ev
->u
.bval
= ev
->u
.ulval
!= 0;
509 ev
->u
.bval
= ev
->u
.hval
!= 0;
513 ev
->u
.bval
= ev
->u
.uhval
!= 0;
519 ev
->u
.bval
= ev
->u
.fval
!= 0.0;
523 ev
->u
.bval
= ev
->u
.dval
!= 0.0;
527 ev
->u
.bval
= ev
->u
.byval
!= 0;
538 ev
->u
.fval
= (float)ev
->u
.sval
;
542 ev
->u
.fval
= (float)ev
->u
.usval
;
546 ev
->u
.fval
= (float)ev
->u
.lval
;
550 ev
->u
.fval
= (float)ev
->u
.ulval
;
554 ev
->u
.fval
= (float)ev
->u
.hval
;
558 if ((float)ev
->u
.ulval
> FLT_MAX
)
560 ev
->u
.fval
= (float)ev
->u
.ulval
;
564 ev
->u
.fval
= ev
->u
.bval
? 1.0f
: 0.0f
;
570 if ((float)ev
->u
.dval
> FLT_MAX
|| (float)ev
->u
.dval
< -FLT_MAX
)
572 ev
->u
.fval
= (float)ev
->u
.dval
;
576 ev
->u
.fval
= (float)ev
->u
.byval
;
587 ev
->u
.dval
= (double)ev
->u
.sval
;
591 ev
->u
.dval
= (double)ev
->u
.usval
;
595 ev
->u
.dval
= (double)ev
->u
.lval
;
599 ev
->u
.dval
= (double)ev
->u
.ulval
;
603 ev
->u
.dval
= (double)ev
->u
.hval
;
607 if ((double)ev
->u
.dval
> FLT_MAX
|| (double)ev
->u
.dval
< -FLT_MAX
)
609 ev
->u
.dval
= (double)ev
->u
.ulval
;
613 ev
->u
.dval
= ev
->u
.bval
? 1.0 : 0.0;
617 ev
->u
.dval
= (double)ev
->u
.fval
;
623 ev
->u
.dval
= (double)ev
->u
.byval
;
634 if (ev
->u
.sval
< SAL_MIN_INT8
|| ev
->u
.sval
> SAL_MAX_UINT8
)
636 ev
->u
.byval
= (sal_uChar
)ev
->u
.sval
;
640 if (ev
->u
.usval
> SAL_MAX_UINT8
)
642 ev
->u
.byval
= (sal_uChar
)ev
->u
.usval
;
646 if (ev
->u
.lval
< SAL_MIN_INT8
|| ev
->u
.lval
> SAL_MAX_UINT8
)
648 ev
->u
.byval
= (sal_uChar
) ev
->u
.lval
;
652 if (ev
->u
.ulval
> SAL_MAX_UINT8
)
654 ev
->u
.byval
= (sal_uChar
) ev
->u
.ulval
;
658 if (ev
->u
.hval
< SAL_MIN_INT8
|| ev
->u
.hval
> SAL_MAX_UINT8
)
660 ev
->u
.byval
= (sal_uChar
) ev
->u
.hval
;
664 if (ev
->u
.uhval
> SAL_MAX_UINT8
)
666 ev
->u
.byval
= (sal_uChar
) ev
->u
.uhval
;
670 ev
->u
.byval
= ev
->u
.bval
? 1 : 0;
674 if (ev
->u
.fval
< SAL_MIN_INT8
|| ev
->u
.fval
> SAL_MAX_UINT8
)
676 ev
->u
.byval
= (sal_uChar
) ev
->u
.fval
;
680 if (ev
->u
.dval
< SAL_MIN_INT8
|| ev
->u
.dval
> SAL_MAX_UINT8
)
682 ev
->u
.byval
= (sal_uChar
) ev
->u
.dval
;
698 * Evaluate the expression with the evaluation kind requested. Supported
699 * evaluation kinds are
700 * - EK_const: The expression must evaluate to a constant
701 * - EK_positive_int: The expression must further evaluate to a
704 static AstExprValue
*
705 eval_kind(AstExprValue
*ev
, EvalKind ek
)
709 if (ek
== EK_positive_int
)
710 return coerce_value(ev
, ET_ulong
);
715 AstExprValue
* AstExpression::coerce(ExprType t
, sal_Bool bAssign
)
720 * Is it already of the right type?
722 if (m_exprValue
!= NULL
&& m_exprValue
->et
== t
)
727 * First, evaluate it, then try to coerce result type
728 * If already evaluated, return the result
730 m_exprValue
= eval_internal(EK_const
);
731 if (m_exprValue
== NULL
)
735 * Create a copy to contain coercion result
737 copy
= new AstExprValue
;
739 copy
->et
= m_exprValue
->et
;
740 switch (m_exprValue
->et
)
743 copy
->u
.sval
= m_exprValue
->u
.sval
;
746 copy
->u
.usval
= m_exprValue
->u
.usval
;
749 copy
->u
.lval
= m_exprValue
->u
.lval
;
752 copy
->u
.ulval
= m_exprValue
->u
.ulval
;
755 copy
->u
.hval
= m_exprValue
->u
.hval
;
758 copy
->u
.uhval
= m_exprValue
->u
.uhval
;
761 copy
->u
.bval
= m_exprValue
->u
.bval
;
764 copy
->u
.fval
= m_exprValue
->u
.fval
;
767 copy
->u
.dval
= m_exprValue
->u
.dval
;
770 copy
->u
.byval
= m_exprValue
->u
.byval
;
777 AstExprValue
* const coerced(coerce_value(copy
, t
));
782 m_exprValue
= coerced
;
787 void AstExpression::evaluate(EvalKind ek
)
789 m_exprValue
= eval_internal(ek
);
790 m_exprValue
= eval_kind(m_exprValue
, ek
);
793 sal_Bool
AstExpression::operator==(AstExpression
*pExpr
)
795 sal_Bool bRet
= sal_False
;
796 if (m_combOperator
!= pExpr
->getCombOperator())
799 pExpr
->evaluate(EK_const
);
800 if (m_exprValue
== NULL
|| pExpr
->getExprValue() == NULL
)
802 if (m_exprValue
->et
!= pExpr
->getExprValue()->et
)
804 switch (m_exprValue
->et
)
807 bRet
= (m_exprValue
->u
.sval
== pExpr
->getExprValue()->u
.sval
) ? sal_True
: sal_False
;
810 bRet
= (m_exprValue
->u
.usval
== pExpr
->getExprValue()->u
.usval
) ? sal_True
: sal_False
;
813 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
816 bRet
= (m_exprValue
->u
.ulval
== pExpr
->getExprValue()->u
.ulval
) ? sal_True
: sal_False
;
819 bRet
= (m_exprValue
->u
.hval
== pExpr
->getExprValue()->u
.hval
) ? sal_True
: sal_False
;
822 bRet
= (m_exprValue
->u
.uhval
== pExpr
->getExprValue()->u
.uhval
) ? sal_True
: sal_False
;
825 bRet
= (m_exprValue
->u
.fval
== pExpr
->getExprValue()->u
.fval
) ? sal_True
: sal_False
;
828 bRet
= (m_exprValue
->u
.dval
== pExpr
->getExprValue()->u
.dval
) ? sal_True
: sal_False
;
831 bRet
= (m_exprValue
->u
.byval
== pExpr
->getExprValue()->u
.byval
) ? sal_True
: sal_False
;
834 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
845 sal_Bool
AstExpression::compare(AstExpression
*pExpr
)
847 bool bRet
= sal_False
;
848 if (m_combOperator
!= pExpr
->getCombOperator())
851 pExpr
->evaluate(EK_const
);
852 if (m_exprValue
== NULL
|| pExpr
->getExprValue() == NULL
)
854 if (m_exprValue
->et
!= pExpr
->getExprValue()->et
)
856 switch (m_exprValue
->et
)
859 bRet
= (m_exprValue
->u
.sval
== pExpr
->getExprValue()->u
.sval
) ? sal_True
: sal_False
;
862 bRet
= (m_exprValue
->u
.usval
== pExpr
->getExprValue()->u
.usval
) ? sal_True
: sal_False
;
865 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
868 bRet
= (m_exprValue
->u
.ulval
== pExpr
->getExprValue()->u
.ulval
) ? sal_True
: sal_False
;
871 bRet
= (m_exprValue
->u
.hval
== pExpr
->getExprValue()->u
.hval
) ? sal_True
: sal_False
;
874 bRet
= (m_exprValue
->u
.uhval
== pExpr
->getExprValue()->u
.uhval
) ? sal_True
: sal_False
;
877 bRet
= (m_exprValue
->u
.fval
== pExpr
->getExprValue()->u
.fval
) ? sal_True
: sal_False
;
880 bRet
= (m_exprValue
->u
.dval
== pExpr
->getExprValue()->u
.dval
) ? sal_True
: sal_False
;
883 bRet
= (m_exprValue
->u
.byval
== pExpr
->getExprValue()->u
.byval
) ? sal_True
: sal_False
;
886 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
896 void AstExpression::fillDefinitionDetails()
898 m_pScope
= idlc()->scopes()->depth() > 0 ? idlc()->scopes()->top() : NULL
;
899 m_lineNo
= idlc()->getLineNumber();
900 m_fileName
= idlc()->getFileName();
903 AstExprValue
* AstExpression::eval_internal(EvalKind ek
)
908 if ( m_exprValue
!= NULL
)
909 return eval_kind(m_exprValue
, ek
);
911 * OK, must evaluate operator
913 switch (m_combOperator
)
920 m_exprValue
= eval_bin_op(ek
);
921 return eval_kind(m_exprValue
, ek
);
927 m_exprValue
= eval_bit_op(ek
);
928 return eval_kind(m_exprValue
, ek
);
932 m_exprValue
= eval_un_op(ek
);
933 return eval_kind(m_exprValue
, ek
);
935 m_exprValue
= eval_symbol(ek
);
936 return eval_kind(m_exprValue
, ek
);
944 AstExprValue
* AstExpression::eval_bin_op(EvalKind ek
)
946 ExprType eType
= ET_double
;
948 if ( m_combOperator
== EC_mod
)
951 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
953 if (m_subExpr1
== NULL
|| m_subExpr2
== NULL
)
955 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
956 if (m_subExpr1
->getExprValue() == NULL
)
958 m_subExpr1
->setExprValue(m_subExpr1
->coerce(eType
));
959 if (m_subExpr1
->getExprValue() == NULL
)
961 m_subExpr2
->setExprValue(m_subExpr2
->eval_internal(ek
));
962 if (m_subExpr2
->getExprValue() == NULL
)
964 m_subExpr2
->setExprValue(m_subExpr2
->coerce(eType
));
965 if (m_subExpr2
->getExprValue() == NULL
)
968 std::auto_ptr
< AstExprValue
> retval(new AstExprValue());
971 switch (m_combOperator
)
974 if (m_subExpr2
->getExprValue()->u
.hval
== 0)
976 retval
->u
.hval
= m_subExpr1
->getExprValue()->u
.hval
% m_subExpr2
->getExprValue()->u
.hval
;
979 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
+ m_subExpr2
->getExprValue()->u
.dval
;
982 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
- m_subExpr2
->getExprValue()->u
.dval
;
985 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
* m_subExpr2
->getExprValue()->u
.dval
;
988 if (m_subExpr2
->getExprValue()->u
.dval
== 0.0)
990 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
/ m_subExpr2
->getExprValue()->u
.dval
;
996 return retval
.release();
999 AstExprValue
* AstExpression::eval_bit_op(EvalKind ek
)
1001 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
1003 if (m_subExpr1
== NULL
|| m_subExpr2
== NULL
)
1005 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
1006 if (m_subExpr1
->getExprValue() == NULL
)
1008 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_long
));
1009 if (m_subExpr1
->getExprValue() == NULL
)
1011 m_subExpr2
->setExprValue(m_subExpr2
->eval_internal(ek
));
1012 if (m_subExpr2
->getExprValue() == NULL
)
1014 m_subExpr2
->setExprValue(m_subExpr2
->coerce(ET_long
));
1015 if (m_subExpr2
->getExprValue() == NULL
)
1018 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1019 std::auto_ptr
< AstExprValue
> retval(new AstExprValue());
1020 SAL_WNODEPRECATED_DECLARATIONS_POP
1021 retval
->et
= ET_long
;
1023 switch (m_combOperator
)
1026 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
| m_subExpr2
->getExprValue()->u
.lval
;
1029 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
^ m_subExpr2
->getExprValue()->u
.lval
;
1032 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
& m_subExpr2
->getExprValue()->u
.lval
;
1035 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
<< m_subExpr2
->getExprValue()->u
.lval
;
1038 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
>> m_subExpr2
->getExprValue()->u
.lval
;
1044 return retval
.release();
1047 AstExprValue
* AstExpression::eval_un_op(EvalKind ek
)
1049 if (m_exprValue
!= NULL
)
1052 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
1054 if (m_subExpr1
== NULL
)
1056 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
1057 if (m_subExpr1
->getExprValue() == NULL
)
1059 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_double
));
1060 if (m_subExpr1
->getExprValue() == NULL
)
1063 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1064 std::auto_ptr
< AstExprValue
> retval(new AstExprValue());
1065 SAL_WNODEPRECATED_DECLARATIONS_POP
1066 retval
->et
= ET_double
;
1068 switch (m_combOperator
)
1071 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
;
1074 retval
->u
.lval
= -(m_subExpr1
->getExprValue()->u
.lval
);
1077 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_long
));
1078 if (m_subExpr1
->getExprValue() == NULL
)
1080 retval
->u
.lval
= ~m_subExpr1
->getExprValue()->u
.lval
;
1086 return retval
.release();
1089 AstExprValue
* AstExpression::eval_symbol(EvalKind ek
)
1091 AstScope
*pScope
= 0;
1092 AstDeclaration
*pDecl
;
1093 AstConstant
*pConst
;
1096 * Is there a symbol stored?
1098 if (m_pSymbolicName
== NULL
)
1100 idlc()->error()->evalError(this);
1104 * Get current scope for lookup
1106 if (idlc()->scopes()->depth() > 0)
1107 pScope
= idlc()->scopes()->topNonNull();
1110 idlc()->error()->lookupError(*m_pSymbolicName
);
1116 pDecl
= pScope
->lookupByName(*m_pSymbolicName
);
1119 idlc()->error()->lookupError(*m_pSymbolicName
);
1125 if (pDecl
->getNodeType() != NT_const
&&
1126 pDecl
->getNodeType() != NT_enum_val
)
1128 idlc()->error()->constantExpected(pDecl
, *m_pSymbolicName
);
1131 if (!idlc()->error()->checkPublished(pDecl
))
1136 * OK, now evaluate the constant we just got, to produce its value
1138 pConst
= static_cast< AstConstant
* >(pDecl
);
1141 return pConst
->getConstValue()->eval_internal(ek
);
1144 OString
AstExpression::toString()
1147 if ( m_combOperator
== EC_symbol
)
1148 return *m_pSymbolicName
;
1152 switch (m_exprValue
->et
)
1155 return OString::valueOf((sal_Int32
)m_exprValue
->u
.sval
);
1157 return OString::valueOf((sal_Int32
)m_exprValue
->u
.usval
);
1159 return OString::valueOf(m_exprValue
->u
.lval
);
1161 return OString::valueOf((sal_Int32
)m_exprValue
->u
.ulval
);
1163 return OString::valueOf(m_exprValue
->u
.hval
);
1165 return OString::valueOf((sal_Int64
)m_exprValue
->u
.uhval
);
1167 return OString::valueOf(m_exprValue
->u
.fval
);
1169 return OString::valueOf(m_exprValue
->u
.dval
);
1171 return OString::valueOf((sal_Int32
)m_exprValue
->u
.byval
);
1173 if ( m_exprValue
->u
.lval
== 0)
1174 return OString("FALSE");
1176 return OString("TRUE");
1183 switch (m_combOperator
)
1186 exprStr
+= OString("+");
1189 exprStr
+= OString("-");
1192 exprStr
+= OString("~");
1198 exprStr
+= m_subExpr1
->toString();
1199 switch (m_combOperator
)
1202 exprStr
+= OString(" + ");
1205 exprStr
+= OString(" - ");
1208 exprStr
+= OString(" * ");
1211 exprStr
+= OString(" / ");
1214 exprStr
+= OString(" % ");
1217 exprStr
+= OString(" | ");
1220 exprStr
+= OString(" ^ ");
1223 exprStr
+= OString(" & ");
1226 exprStr
+= OString(" << ");
1229 exprStr
+= OString(" >> ");
1236 exprStr
+= m_subExpr2
->toString();
1241 // Convert the type of an AST_Expression to a char *
1242 const sal_Char
* SAL_CALL
exprTypeToString(ExprType t
)
1249 return "unsigned short";
1253 return "unsigned long";
1257 return "unsigned hyper";
1283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */