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>
30 using namespace ::rtl
;
32 AstExpression::AstExpression(ExprComb c
, AstExpression
*pExpr1
, AstExpression
*pExpr2
)
37 , m_pSymbolicName(NULL
)
39 fillDefinitionDetails();
43 AstExpression::AstExpression(sal_Int32 l
)
44 : m_combOperator(EC_none
)
48 , m_pSymbolicName(NULL
)
50 fillDefinitionDetails();
52 m_exprValue
= new AstExprValue();
53 m_exprValue
->et
= ET_long
;
54 m_exprValue
->u
.lval
= l
;
57 AstExpression::AstExpression(sal_Int32 l
, ExprType et
)
58 : m_combOperator(EC_none
)
62 , m_pSymbolicName(NULL
)
64 fillDefinitionDetails();
66 m_exprValue
= new AstExprValue();
68 m_exprValue
->u
.lval
= l
;
71 AstExpression::AstExpression(sal_Int64 h
)
72 : m_combOperator(EC_none
)
76 , m_pSymbolicName(NULL
)
78 fillDefinitionDetails();
80 m_exprValue
= new AstExprValue();
81 m_exprValue
->et
= ET_hyper
;
82 m_exprValue
->u
.hval
= h
;
85 AstExpression::AstExpression(sal_uInt64 uh
)
86 : m_combOperator(EC_none
)
90 , m_pSymbolicName(NULL
)
92 fillDefinitionDetails();
94 m_exprValue
= new AstExprValue();
95 m_exprValue
->et
= ET_uhyper
;
96 m_exprValue
->u
.uhval
= uh
;
99 AstExpression::AstExpression(double d
)
100 : m_combOperator(EC_none
)
104 , m_pSymbolicName(NULL
)
106 fillDefinitionDetails();
108 m_exprValue
= new AstExprValue();
109 m_exprValue
->et
= ET_double
;
110 m_exprValue
->u
.dval
= d
;
113 AstExpression::AstExpression(OString
* scopedName
)
114 : m_combOperator(EC_symbol
)
118 , m_pSymbolicName(scopedName
)
120 fillDefinitionDetails();
123 AstExpression::~AstExpression()
131 if ( m_pSymbolicName
)
132 delete m_pSymbolicName
;
136 * Perform the coercion from the given AstExprValue to the requested
137 * ExprType. Return an AstExprValue if successful, NULL if failed.
138 * must be done for hyper, uhyper
140 static AstExprValue
*
141 coerce_value(AstExprValue
*ev
, ExprType t
)
154 if (ev
->u
.usval
> SAL_MAX_INT16
)
156 ev
->u
.sval
= (sal_Int16
)ev
->u
.usval
;
160 if (ev
->u
.lval
< SAL_MIN_INT16
|| ev
->u
.lval
> SAL_MAX_INT16
)
162 ev
->u
.sval
= (sal_Int16
)ev
->u
.lval
;
166 if (ev
->u
.ulval
> SAL_MAX_INT16
)
168 ev
->u
.sval
= (sal_Int16
)ev
->u
.ulval
;
172 if (ev
->u
.hval
< SAL_MIN_INT16
|| ev
->u
.hval
> SAL_MAX_INT16
)
174 ev
->u
.sval
= (sal_Int16
)ev
->u
.hval
;
178 if (ev
->u
.uhval
> SAL_MAX_INT16
)
180 ev
->u
.sval
= (sal_Int16
)ev
->u
.uhval
;
184 ev
->u
.sval
= (sal_Int16
)ev
->u
.bval
;
188 if (ev
->u
.fval
< SAL_MIN_INT16
|| ev
->u
.fval
> SAL_MAX_INT16
)
190 ev
->u
.sval
= (sal_Int16
)ev
->u
.fval
;
194 if (ev
->u
.dval
< SAL_MIN_INT16
|| ev
->u
.dval
> SAL_MAX_INT16
)
196 ev
->u
.sval
= (sal_Int16
)ev
->u
.dval
;
200 ev
->u
.sval
= (sal_Int16
)ev
->u
.byval
;
213 ev
->u
.usval
= (sal_uInt16
)ev
->u
.sval
;
219 if (ev
->u
.lval
< 0 || ev
->u
.lval
> SAL_MAX_UINT16
)
221 ev
->u
.usval
= (sal_uInt16
)ev
->u
.lval
;
225 if (ev
->u
.ulval
> SAL_MAX_UINT16
)
227 ev
->u
.usval
= (sal_uInt16
)ev
->u
.ulval
;
231 if (ev
->u
.hval
< 0 || ev
->u
.hval
> SAL_MAX_UINT16
)
233 ev
->u
.usval
= (sal_uInt16
)ev
->u
.hval
;
237 if (ev
->u
.uhval
> SAL_MAX_UINT16
)
239 ev
->u
.usval
= (sal_uInt16
)ev
->u
.uhval
;
243 ev
->u
.usval
= (sal_uInt16
)ev
->u
.bval
;
247 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT16
)
249 ev
->u
.usval
= (sal_uInt16
)ev
->u
.fval
;
253 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT16
)
255 ev
->u
.usval
= (sal_uInt16
)ev
->u
.dval
;
259 ev
->u
.usval
= (sal_uInt16
)ev
->u
.byval
;
270 ev
->u
.lval
= (sal_Int32
)ev
->u
.sval
;
274 ev
->u
.lval
= (sal_Int32
)ev
->u
.usval
;
280 if (ev
->u
.ulval
> SAL_MAX_INT32
)
282 ev
->u
.lval
= (sal_Int32
)ev
->u
.ulval
;
286 if (ev
->u
.hval
< SAL_MIN_INT32
|| ev
->u
.hval
> SAL_MAX_INT32
)
288 ev
->u
.lval
= (sal_Int32
)ev
->u
.hval
;
292 if (ev
->u
.uhval
> SAL_MAX_INT32
)
294 ev
->u
.lval
= (sal_Int32
)ev
->u
.uhval
;
298 ev
->u
.lval
= (sal_Int32
)ev
->u
.bval
;
302 if (ev
->u
.fval
< SAL_MIN_INT32
|| ev
->u
.fval
> SAL_MAX_INT32
)
304 ev
->u
.lval
= (sal_Int32
)ev
->u
.fval
;
308 if (ev
->u
.dval
< SAL_MIN_INT32
|| ev
->u
.dval
> SAL_MAX_INT32
)
310 ev
->u
.lval
= (sal_Int32
)ev
->u
.dval
;
314 ev
->u
.lval
= (sal_Int32
) ev
->u
.byval
;
327 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.sval
;
331 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.usval
;
337 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.lval
;
343 if (ev
->u
.hval
< 0 || ev
->u
.hval
> SAL_MAX_UINT32
)
345 ev
->u
.lval
= (sal_uInt32
)ev
->u
.hval
;
349 if (ev
->u
.uhval
> SAL_MAX_UINT32
)
351 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.uhval
;
355 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.bval
;
359 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT32
)
361 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.fval
;
365 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT32
)
367 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.dval
;
371 ev
->u
.ulval
= (sal_uInt32
)ev
->u
.byval
;
382 ev
->u
.hval
= (sal_Int64
)ev
->u
.sval
;
386 ev
->u
.hval
= (sal_Int64
)ev
->u
.usval
;
390 ev
->u
.hval
= (sal_Int64
)ev
->u
.lval
;
394 ev
->u
.hval
= (sal_Int64
)ev
->u
.ulval
;
400 if (ev
->u
.uhval
> SAL_MAX_INT64
)
402 ev
->u
.hval
= (sal_Int64
)ev
->u
.uhval
;
406 ev
->u
.hval
= (sal_Int64
)ev
->u
.bval
;
410 if (ev
->u
.fval
< SAL_MIN_INT64
|| ev
->u
.fval
> SAL_MAX_INT64
)
412 ev
->u
.hval
= (sal_Int64
)ev
->u
.fval
;
416 if (ev
->u
.dval
< SAL_MIN_INT64
|| ev
->u
.dval
> SAL_MAX_INT64
)
418 ev
->u
.hval
= (sal_Int64
)ev
->u
.dval
;
422 ev
->u
.hval
= (sal_Int64
)ev
->u
.byval
;
435 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.sval
;
439 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.usval
;
445 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.lval
;
449 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.ulval
;
455 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.hval
;
461 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.bval
;
465 if (ev
->u
.fval
< 0.0 || ev
->u
.fval
> SAL_MAX_UINT64
)
467 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.fval
;
471 if (ev
->u
.dval
< 0.0 || ev
->u
.dval
> SAL_MAX_UINT64
)
473 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.dval
;
477 ev
->u
.uhval
= (sal_uInt64
)ev
->u
.byval
;
488 ev
->u
.bval
= ev
->u
.sval
!= 0;
492 ev
->u
.bval
= ev
->u
.usval
!= 0;
496 ev
->u
.bval
= ev
->u
.lval
!= 0;
500 ev
->u
.bval
= ev
->u
.ulval
!= 0;
504 ev
->u
.bval
= ev
->u
.hval
!= 0;
508 ev
->u
.bval
= ev
->u
.uhval
!= 0;
514 ev
->u
.bval
= ev
->u
.fval
!= 0.0;
518 ev
->u
.bval
= ev
->u
.dval
!= 0.0;
522 ev
->u
.bval
= ev
->u
.byval
!= 0;
533 ev
->u
.fval
= (float)ev
->u
.sval
;
537 ev
->u
.fval
= (float)ev
->u
.usval
;
541 ev
->u
.fval
= (float)ev
->u
.lval
;
545 ev
->u
.fval
= (float)ev
->u
.ulval
;
549 ev
->u
.fval
= (float)ev
->u
.hval
;
553 if ((float)ev
->u
.ulval
> FLT_MAX
)
555 ev
->u
.fval
= (float)ev
->u
.ulval
;
559 ev
->u
.fval
= ev
->u
.bval
? 1.0f
: 0.0f
;
565 if ((float)ev
->u
.dval
> FLT_MAX
|| (float)ev
->u
.dval
< -FLT_MAX
)
567 ev
->u
.fval
= (float)ev
->u
.dval
;
571 ev
->u
.fval
= (float)ev
->u
.byval
;
582 ev
->u
.dval
= (double)ev
->u
.sval
;
586 ev
->u
.dval
= (double)ev
->u
.usval
;
590 ev
->u
.dval
= (double)ev
->u
.lval
;
594 ev
->u
.dval
= (double)ev
->u
.ulval
;
598 ev
->u
.dval
= (double)ev
->u
.hval
;
602 if ((double)ev
->u
.dval
> FLT_MAX
|| (double)ev
->u
.dval
< -FLT_MAX
)
604 ev
->u
.dval
= (double)ev
->u
.ulval
;
608 ev
->u
.dval
= ev
->u
.bval
? 1.0 : 0.0;
612 ev
->u
.dval
= (double)ev
->u
.fval
;
618 ev
->u
.dval
= (double)ev
->u
.byval
;
629 if (ev
->u
.sval
< SAL_MIN_INT8
|| ev
->u
.sval
> SAL_MAX_UINT8
)
631 ev
->u
.byval
= (unsigned char)ev
->u
.sval
;
635 if (ev
->u
.usval
> SAL_MAX_UINT8
)
637 ev
->u
.byval
= (unsigned char)ev
->u
.usval
;
641 if (ev
->u
.lval
< SAL_MIN_INT8
|| ev
->u
.lval
> SAL_MAX_UINT8
)
643 ev
->u
.byval
= (unsigned char) ev
->u
.lval
;
647 if (ev
->u
.ulval
> SAL_MAX_UINT8
)
649 ev
->u
.byval
= (unsigned char) ev
->u
.ulval
;
653 if (ev
->u
.hval
< SAL_MIN_INT8
|| ev
->u
.hval
> SAL_MAX_UINT8
)
655 ev
->u
.byval
= (unsigned char) ev
->u
.hval
;
659 if (ev
->u
.uhval
> SAL_MAX_UINT8
)
661 ev
->u
.byval
= (unsigned char) ev
->u
.uhval
;
665 ev
->u
.byval
= ev
->u
.bval
? 1 : 0;
669 if (ev
->u
.fval
< SAL_MIN_INT8
|| ev
->u
.fval
> SAL_MAX_UINT8
)
671 ev
->u
.byval
= (unsigned char) ev
->u
.fval
;
675 if (ev
->u
.dval
< SAL_MIN_INT8
|| ev
->u
.dval
> SAL_MAX_UINT8
)
677 ev
->u
.byval
= (unsigned char) ev
->u
.dval
;
693 * Evaluate the expression with the evaluation kind requested. Supported
694 * evaluation kinds are
695 * - EK_const: The expression must evaluate to a constant
696 * - EK_positive_int: The expression must further evaluate to a
699 static AstExprValue
*
700 eval_kind(AstExprValue
*ev
, EvalKind ek
)
704 if (ek
== EK_positive_int
)
705 return coerce_value(ev
, ET_ulong
);
710 AstExprValue
* AstExpression::coerce(ExprType t
, bool bAssign
)
715 * Is it already of the right type?
717 if (m_exprValue
!= NULL
&& m_exprValue
->et
== t
)
722 * First, evaluate it, then try to coerce result type
723 * If already evaluated, return the result
725 m_exprValue
= eval_internal(EK_const
);
726 if (m_exprValue
== NULL
)
730 * Create a copy to contain coercion result
732 copy
= new AstExprValue
;
734 copy
->et
= m_exprValue
->et
;
735 switch (m_exprValue
->et
)
738 copy
->u
.sval
= m_exprValue
->u
.sval
;
741 copy
->u
.usval
= m_exprValue
->u
.usval
;
744 copy
->u
.lval
= m_exprValue
->u
.lval
;
747 copy
->u
.ulval
= m_exprValue
->u
.ulval
;
750 copy
->u
.hval
= m_exprValue
->u
.hval
;
753 copy
->u
.uhval
= m_exprValue
->u
.uhval
;
756 copy
->u
.bval
= m_exprValue
->u
.bval
;
759 copy
->u
.fval
= m_exprValue
->u
.fval
;
762 copy
->u
.dval
= m_exprValue
->u
.dval
;
765 copy
->u
.byval
= m_exprValue
->u
.byval
;
772 AstExprValue
* const coerced(coerce_value(copy
, t
));
777 m_exprValue
= coerced
;
782 void AstExpression::evaluate(EvalKind ek
)
784 m_exprValue
= eval_internal(ek
);
785 m_exprValue
= eval_kind(m_exprValue
, ek
);
788 bool AstExpression::operator==(AstExpression
*pExpr
)
791 if (m_combOperator
!= pExpr
->getCombOperator())
794 pExpr
->evaluate(EK_const
);
795 if (m_exprValue
== NULL
|| pExpr
->getExprValue() == NULL
)
797 if (m_exprValue
->et
!= pExpr
->getExprValue()->et
)
799 switch (m_exprValue
->et
)
802 bRet
= (m_exprValue
->u
.sval
== pExpr
->getExprValue()->u
.sval
) ? sal_True
: sal_False
;
805 bRet
= (m_exprValue
->u
.usval
== pExpr
->getExprValue()->u
.usval
) ? sal_True
: sal_False
;
808 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
811 bRet
= (m_exprValue
->u
.ulval
== pExpr
->getExprValue()->u
.ulval
) ? sal_True
: sal_False
;
814 bRet
= (m_exprValue
->u
.hval
== pExpr
->getExprValue()->u
.hval
) ? sal_True
: sal_False
;
817 bRet
= (m_exprValue
->u
.uhval
== pExpr
->getExprValue()->u
.uhval
) ? sal_True
: sal_False
;
820 bRet
= (m_exprValue
->u
.fval
== pExpr
->getExprValue()->u
.fval
) ? sal_True
: sal_False
;
823 bRet
= (m_exprValue
->u
.dval
== pExpr
->getExprValue()->u
.dval
) ? sal_True
: sal_False
;
826 bRet
= (m_exprValue
->u
.byval
== pExpr
->getExprValue()->u
.byval
) ? sal_True
: sal_False
;
829 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
840 bool AstExpression::compare(AstExpression
*pExpr
)
843 if (m_combOperator
!= pExpr
->getCombOperator())
846 pExpr
->evaluate(EK_const
);
847 if (m_exprValue
== NULL
|| pExpr
->getExprValue() == NULL
)
849 if (m_exprValue
->et
!= pExpr
->getExprValue()->et
)
851 switch (m_exprValue
->et
)
854 bRet
= (m_exprValue
->u
.sval
== pExpr
->getExprValue()->u
.sval
) ? sal_True
: sal_False
;
857 bRet
= (m_exprValue
->u
.usval
== pExpr
->getExprValue()->u
.usval
) ? sal_True
: sal_False
;
860 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
863 bRet
= (m_exprValue
->u
.ulval
== pExpr
->getExprValue()->u
.ulval
) ? sal_True
: sal_False
;
866 bRet
= (m_exprValue
->u
.hval
== pExpr
->getExprValue()->u
.hval
) ? sal_True
: sal_False
;
869 bRet
= (m_exprValue
->u
.uhval
== pExpr
->getExprValue()->u
.uhval
) ? sal_True
: sal_False
;
872 bRet
= (m_exprValue
->u
.fval
== pExpr
->getExprValue()->u
.fval
) ? sal_True
: sal_False
;
875 bRet
= (m_exprValue
->u
.dval
== pExpr
->getExprValue()->u
.dval
) ? sal_True
: sal_False
;
878 bRet
= (m_exprValue
->u
.byval
== pExpr
->getExprValue()->u
.byval
) ? sal_True
: sal_False
;
881 bRet
= (m_exprValue
->u
.lval
== pExpr
->getExprValue()->u
.lval
) ? sal_True
: sal_False
;
891 void AstExpression::fillDefinitionDetails()
893 m_pScope
= idlc()->scopes()->depth() > 0 ? idlc()->scopes()->top() : NULL
;
894 m_lineNo
= idlc()->getLineNumber();
895 m_fileName
= idlc()->getFileName();
898 AstExprValue
* AstExpression::eval_internal(EvalKind ek
)
903 if ( m_exprValue
!= NULL
)
904 return eval_kind(m_exprValue
, ek
);
906 * OK, must evaluate operator
908 switch (m_combOperator
)
915 m_exprValue
= eval_bin_op(ek
);
916 return eval_kind(m_exprValue
, ek
);
922 m_exprValue
= eval_bit_op(ek
);
923 return eval_kind(m_exprValue
, ek
);
927 m_exprValue
= eval_un_op(ek
);
928 return eval_kind(m_exprValue
, ek
);
930 m_exprValue
= eval_symbol(ek
);
931 return eval_kind(m_exprValue
, ek
);
939 AstExprValue
* AstExpression::eval_bin_op(EvalKind ek
)
941 ExprType eType
= ET_double
;
943 if ( m_combOperator
== EC_mod
)
946 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
948 if (m_subExpr1
== NULL
|| m_subExpr2
== NULL
)
950 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
951 if (m_subExpr1
->getExprValue() == NULL
)
953 m_subExpr1
->setExprValue(m_subExpr1
->coerce(eType
));
954 if (m_subExpr1
->getExprValue() == NULL
)
956 m_subExpr2
->setExprValue(m_subExpr2
->eval_internal(ek
));
957 if (m_subExpr2
->getExprValue() == NULL
)
959 m_subExpr2
->setExprValue(m_subExpr2
->coerce(eType
));
960 if (m_subExpr2
->getExprValue() == NULL
)
963 std::auto_ptr
< AstExprValue
> retval(new AstExprValue());
966 switch (m_combOperator
)
969 if (m_subExpr2
->getExprValue()->u
.hval
== 0)
971 retval
->u
.hval
= m_subExpr1
->getExprValue()->u
.hval
% m_subExpr2
->getExprValue()->u
.hval
;
974 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
+ m_subExpr2
->getExprValue()->u
.dval
;
977 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
- m_subExpr2
->getExprValue()->u
.dval
;
980 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
* m_subExpr2
->getExprValue()->u
.dval
;
983 if (m_subExpr2
->getExprValue()->u
.dval
== 0.0)
985 retval
->u
.dval
= m_subExpr1
->getExprValue()->u
.dval
/ m_subExpr2
->getExprValue()->u
.dval
;
991 return retval
.release();
994 AstExprValue
* AstExpression::eval_bit_op(EvalKind ek
)
996 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
998 if (m_subExpr1
== NULL
|| m_subExpr2
== NULL
)
1000 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
1001 if (m_subExpr1
->getExprValue() == NULL
)
1003 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_long
));
1004 if (m_subExpr1
->getExprValue() == NULL
)
1006 m_subExpr2
->setExprValue(m_subExpr2
->eval_internal(ek
));
1007 if (m_subExpr2
->getExprValue() == NULL
)
1009 m_subExpr2
->setExprValue(m_subExpr2
->coerce(ET_long
));
1010 if (m_subExpr2
->getExprValue() == NULL
)
1013 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1014 std::auto_ptr
< AstExprValue
> retval(new AstExprValue());
1015 SAL_WNODEPRECATED_DECLARATIONS_POP
1016 retval
->et
= ET_long
;
1018 switch (m_combOperator
)
1021 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
| m_subExpr2
->getExprValue()->u
.lval
;
1024 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
^ m_subExpr2
->getExprValue()->u
.lval
;
1027 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
& m_subExpr2
->getExprValue()->u
.lval
;
1030 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
<< m_subExpr2
->getExprValue()->u
.lval
;
1033 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
>> m_subExpr2
->getExprValue()->u
.lval
;
1039 return retval
.release();
1042 AstExprValue
* AstExpression::eval_un_op(EvalKind ek
)
1044 if (m_exprValue
!= NULL
)
1047 if (ek
!= EK_const
&& ek
!= EK_positive_int
)
1049 if (m_subExpr1
== NULL
)
1051 m_subExpr1
->setExprValue(m_subExpr1
->eval_internal(ek
));
1052 if (m_subExpr1
->getExprValue() == NULL
)
1054 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_double
));
1055 if (m_subExpr1
->getExprValue() == NULL
)
1058 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1059 std::auto_ptr
< AstExprValue
> retval(new AstExprValue());
1060 SAL_WNODEPRECATED_DECLARATIONS_POP
1061 retval
->et
= ET_double
;
1063 switch (m_combOperator
)
1066 retval
->u
.lval
= m_subExpr1
->getExprValue()->u
.lval
;
1069 retval
->u
.lval
= -(m_subExpr1
->getExprValue()->u
.lval
);
1072 m_subExpr1
->setExprValue(m_subExpr1
->coerce(ET_long
));
1073 if (m_subExpr1
->getExprValue() == NULL
)
1075 retval
->u
.lval
= ~m_subExpr1
->getExprValue()->u
.lval
;
1081 return retval
.release();
1084 AstExprValue
* AstExpression::eval_symbol(EvalKind ek
)
1086 AstScope
*pScope
= 0;
1087 AstDeclaration
*pDecl
;
1088 AstConstant
*pConst
;
1091 * Is there a symbol stored?
1093 if (m_pSymbolicName
== NULL
)
1095 idlc()->error()->evalError(this);
1099 * Get current scope for lookup
1101 if (idlc()->scopes()->depth() > 0)
1102 pScope
= idlc()->scopes()->topNonNull();
1105 idlc()->error()->lookupError(*m_pSymbolicName
);
1111 pDecl
= pScope
->lookupByName(*m_pSymbolicName
);
1114 idlc()->error()->lookupError(*m_pSymbolicName
);
1120 if (pDecl
->getNodeType() != NT_const
&&
1121 pDecl
->getNodeType() != NT_enum_val
)
1123 idlc()->error()->constantExpected(pDecl
, *m_pSymbolicName
);
1126 if (!idlc()->error()->checkPublished(pDecl
))
1131 * OK, now evaluate the constant we just got, to produce its value
1133 pConst
= static_cast< AstConstant
* >(pDecl
);
1134 return pConst
->getConstValue()->eval_internal(ek
);
1137 OString
AstExpression::toString()
1140 if ( m_combOperator
== EC_symbol
)
1141 return m_pSymbolicName
? *m_pSymbolicName
: OString("<Undefined Name>");
1145 switch (m_exprValue
->et
)
1148 return OString::number(m_exprValue
->u
.sval
);
1150 return OString::number(m_exprValue
->u
.usval
);
1152 return OString::number(m_exprValue
->u
.lval
);
1154 return OString::number(m_exprValue
->u
.ulval
);
1156 return OString::number(m_exprValue
->u
.hval
);
1158 return OString::number(m_exprValue
->u
.uhval
);
1160 return OString::number(m_exprValue
->u
.fval
);
1162 return OString::number(m_exprValue
->u
.dval
);
1164 return OString::number(m_exprValue
->u
.byval
);
1166 if ( m_exprValue
->u
.lval
== 0)
1167 return OString("FALSE");
1169 return OString("TRUE");
1176 switch (m_combOperator
)
1179 exprStr
+= OString("+");
1182 exprStr
+= OString("-");
1185 exprStr
+= OString("~");
1191 exprStr
+= m_subExpr1
->toString();
1192 switch (m_combOperator
)
1195 exprStr
+= OString(" + ");
1198 exprStr
+= OString(" - ");
1201 exprStr
+= OString(" * ");
1204 exprStr
+= OString(" / ");
1207 exprStr
+= OString(" % ");
1210 exprStr
+= OString(" | ");
1213 exprStr
+= OString(" ^ ");
1216 exprStr
+= OString(" & ");
1219 exprStr
+= OString(" << ");
1222 exprStr
+= OString(" >> ");
1229 exprStr
+= m_subExpr2
->toString();
1234 // Convert the type of an AST_Expression to a char *
1235 const sal_Char
* SAL_CALL
exprTypeToString(ExprType t
)
1242 return "unsigned short";
1246 return "unsigned long";
1250 return "unsigned hyper";
1276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */