1 /* Plural expression evaluation.
2 Copyright (C) 2000, 2001, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 static unsigned long int plural_eval (const struct expression
*pexp
,
24 static unsigned long int
27 const struct expression
*pexp
;
33 switch (pexp
->operation
)
46 /* pexp->operation must be lnot. */
47 unsigned long int arg
= plural_eval (pexp
->val
.args
[0], n
);
52 unsigned long int leftarg
= plural_eval (pexp
->val
.args
[0], n
);
53 if (pexp
->operation
== lor
)
54 return leftarg
|| plural_eval (pexp
->val
.args
[1], n
);
55 else if (pexp
->operation
== land
)
56 return leftarg
&& plural_eval (pexp
->val
.args
[1], n
);
59 unsigned long int rightarg
= plural_eval (pexp
->val
.args
[1], n
);
61 switch (pexp
->operation
)
64 return leftarg
* rightarg
;
66 return leftarg
/ rightarg
;
68 return leftarg
% rightarg
;
70 return leftarg
+ rightarg
;
72 return leftarg
- rightarg
;
74 return leftarg
< rightarg
;
76 return leftarg
> rightarg
;
78 return leftarg
<= rightarg
;
79 case greater_or_equal
:
80 return leftarg
>= rightarg
;
82 return leftarg
== rightarg
;
84 return leftarg
!= rightarg
;
94 /* pexp->operation must be qmop. */
95 unsigned long int boolarg
= plural_eval (pexp
->val
.args
[0], n
);
96 return plural_eval (pexp
->val
.args
[boolarg
? 1 : 2], n
);