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
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 ************************************************************************/
39 #define UNSMARK 0x1000
47 /* conversion types */
55 /* operator priority, arity, and conversion type, indexed by tokentype */
249 }, /* ARCHITECTURE */
252 int evalop(struct pri
);
253 struct value
tokval(Token
*);
254 struct value vals
[NSTAK
], *vp
;
255 enum toktype ops
[NSTAK
], *op
;
258 * Evaluate an #if #elif #ifdef #ifndef line. trp->tp points to the keyword.
261 eval(Tokenrow
* trp
, int kw
)
268 if (kw
== KIFDEF
|| kw
== KIFNDEF
)
270 if (trp
->lp
- trp
->bp
!= 4 || trp
->tp
->type
!= NAME
)
272 error(ERROR
, "Syntax error in #ifdef/#ifndef");
275 np
= lookup(trp
->tp
, 0);
276 return (kw
== KIFDEF
) == (np
&& np
->flag
& (ISDEFINED
| ISMAC
));
278 ntok
= trp
->tp
- trp
->bp
;
279 kwdefined
->val
= KDEFINED
; /* activate special meaning of
281 expandrow(trp
, "<if>");
282 kwdefined
->val
= NAME
;
286 for (rand
= 0, tp
= trp
->bp
+ ntok
; tp
< trp
->lp
; tp
++)
323 if (tp
->type
== MINUS
)
325 if (tp
->type
== STAR
|| tp
->type
== AND
)
327 error(ERROR
, "Illegal operator * or & in #if/#elsif");
354 if (evalop(priority
[tp
->type
]) != 0)
369 if (evalop(priority
[RP
]) != 0)
371 if (op
<= ops
|| op
[-1] != LP
)
379 if ((tp
+ 1) < trp
->lp
)
381 np
= lookup(tp
+ 1, 0);
382 if (np
&& (np
->val
== KMACHINE
))
387 *op
++ = ARCHITECTURE
;
394 error(ERROR
, "Bad operator (%t) in #if/#elsif", tp
);
400 if (evalop(priority
[END
]) != 0)
402 if (op
!= &ops
[1] || vp
!= &vals
[1])
404 error(ERROR
, "Botch in #if/#elsif");
407 if (vals
[0].type
== UND
)
408 error(ERROR
, "Undefined expression value");
411 error(ERROR
, "Syntax error in #if/#elsif");
416 evalop(struct pri pri
)
418 struct value v1
, v2
= { 0, 0 };
424 while (pri
.pri
< priority
[op
[-1]].pri
)
427 if (priority
[oper
].arity
== 2)
434 /*lint -e574 -e644 */
435 switch (priority
[oper
].ctype
)
439 error(WARNING
, "Syntax error in #if/#endif");
443 if (v1
.type
== UNS
|| v2
.type
== UNS
)
447 if (v1
.type
== UND
|| v2
.type
== UND
)
449 if (priority
[oper
].ctype
== RELAT
&& rtype
== UNS
)
456 if (v1
.type
== UND
|| v2
.type
== UND
)
493 rv1
= (unsigned long)rv1
<= (unsigned long)rv2
;
496 rv1
= (unsigned long)rv1
>= (unsigned long)rv2
;
499 rv1
= (unsigned long)rv1
< (unsigned long)rv2
;
502 rv1
= (unsigned long)rv1
> (unsigned long)rv2
;
508 rv1
= (unsigned long) rv1
<< rv2
;
514 rv1
= (unsigned long) rv1
>> rv2
;
582 rv1
/= (unsigned long) rv2
;
593 rv1
%= (unsigned long) rv2
;
599 error(ERROR
, "Bad ?: in #if/endif");
603 if ((--vp
)->val
== 0)
615 error(ERROR
, "Eval botch (unknown operator)");
618 /*lint +e574 +e644 */
645 if ((np
= lookup(tp
, 0)) != NULL
&& np
->flag
& (ISDEFINED
| ISMAC
))
650 if ((np
= lookup(tp
, 0)) != NULL
&& np
->flag
& (ISARCHITECTURE
))
663 if (p
[1] == 'x' || p
[1] == 'X')
672 if ((i
= digit(*p
)) < 0)
676 "Bad digit in number %t", tp
);
680 if (n
>= 0x80000000 && base
!= 10)
684 if (*p
== 'u' || *p
== 'U')
687 if (*p
== 'l' || *p
== 'L')
692 "Bad number %t in #if/#elsif", tp
);
706 error(WARNING
, "Wide char constant value undefined");
712 if ((i
= digit(*p
)) >= 0 && i
<= 7)
716 if ((i
= digit(*p
)) >= 0 && i
<= 7)
721 if ((i
= digit(*p
)) >= 0 && i
<= 7)
733 while ((i
= digit(*p
)) >= 0 && i
<= 15)
743 = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
745 for (i
= 0; i
< (int)sizeof(cvcon
); i
+= 2)
754 if (i
>= (int)sizeof(cvcon
))
756 "Undefined escape in character constant");
761 error(ERROR
, "Empty character constant");
765 error(WARNING
, "Multibyte character constant undefined");
768 error(WARNING
, "Character constant taken as not signed");
773 error(ERROR
, "String in #if/#elsif");
782 if ('0' <= i
&& i
<= '9')
785 if ('a' <= i
&& i
<= 'f')
788 if ('A' <= i
&& i
<= 'F')