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, see
17 <http://www.gnu.org/licenses/>. */
19 static unsigned long int plural_eval (const struct expression
*pexp
,
23 static unsigned long int
26 const struct expression
*pexp
;
32 switch (pexp
->operation
)
45 /* pexp->operation must be lnot. */
46 unsigned long int arg
= plural_eval (pexp
->val
.args
[0], n
);
51 unsigned long int leftarg
= plural_eval (pexp
->val
.args
[0], n
);
52 if (pexp
->operation
== lor
)
53 return leftarg
|| plural_eval (pexp
->val
.args
[1], n
);
54 else if (pexp
->operation
== land
)
55 return leftarg
&& plural_eval (pexp
->val
.args
[1], n
);
58 unsigned long int rightarg
= plural_eval (pexp
->val
.args
[1], n
);
60 switch (pexp
->operation
)
63 return leftarg
* rightarg
;
65 return leftarg
/ rightarg
;
67 return leftarg
% rightarg
;
69 return leftarg
+ rightarg
;
71 return leftarg
- rightarg
;
73 return leftarg
< rightarg
;
75 return leftarg
> rightarg
;
77 return leftarg
<= rightarg
;
78 case greater_or_equal
:
79 return leftarg
>= rightarg
;
81 return leftarg
== rightarg
;
83 return leftarg
!= rightarg
;
93 /* pexp->operation must be qmop. */
94 unsigned long int boolarg
= plural_eval (pexp
->val
.args
[0], n
);
95 return plural_eval (pexp
->val
.args
[boolarg
? 1 : 2], n
);