1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
13 #define UNSMARK 0x1000
21 /* conversion types */
29 /* operator priority, arity, and conversion type, indexed by tokentype */
223 }, /* ARCHITECTURE */
226 int evalop(struct pri
);
227 struct value
tokval(Token
*);
228 struct value vals
[NSTAK
], *vp
;
229 enum toktype ops
[NSTAK
], *op
;
232 * Evaluate an #if #elif #ifdef #ifndef line. trp->tp points to the keyword.
235 eval(Tokenrow
* trp
, int kw
)
243 if (kw
== KIFDEF
|| kw
== KIFNDEF
)
245 if (trp
->lp
- trp
->bp
!= 4 || trp
->tp
->type
!= NAME
)
247 error(ERROR
, "Syntax error in #ifdef/#ifndef");
250 np
= lookup(trp
->tp
, 0);
251 return (kw
== KIFDEF
) == (np
&& np
->flag
& (ISDEFINED
| ISMAC
));
253 ntok
= trp
->tp
- trp
->bp
;
254 kwdefined
->val
= KDEFINED
; /* activate special meaning of
256 expandrow(trp
, "<if>");
257 kwdefined
->val
= NAME
;
261 for (rnd
= 0, tp
= trp
->bp
+ ntok
; tp
< trp
->lp
; tp
++)
298 if (tp
->type
== MINUS
)
300 if (tp
->type
== STAR
|| tp
->type
== AND
)
302 error(ERROR
, "Illegal operator * or & in #if/#elsif");
329 if (evalop(priority
[tp
->type
]) != 0)
344 if (evalop(priority
[RP
]) != 0)
346 if (op
<= ops
|| op
[-1] != LP
)
354 if ((tp
+ 1) < trp
->lp
)
356 np
= lookup(tp
+ 1, 0);
357 if (np
&& (np
->val
== KMACHINE
))
362 *op
++ = ARCHITECTURE
;
369 error(ERROR
, "Bad operator (%t) in #if/#elsif", tp
);
375 if (evalop(priority
[END
]) != 0)
377 if (op
!= &ops
[1] || vp
!= &vals
[1])
379 error(ERROR
, "Botch in #if/#elsif");
382 if (vals
[0].type
== UND
)
383 error(ERROR
, "Undefined expression value");
386 error(ERROR
, "Syntax error in #if/#elsif");
391 evalop(struct pri pri
)
394 struct value v2
= { 0, UND
};
400 while (pri
.pri
< priority
[op
[-1]].pri
)
403 if (priority
[oper
].arity
== 2)
410 /*lint -e574 -e644 */
411 switch (priority
[oper
].ctype
)
415 error(WARNING
, "Syntax error in #if/#endif");
419 if (v1
.type
== UNS
|| v2
.type
== UNS
)
423 if (v1
.type
== UND
|| v2
.type
== UND
)
425 if (priority
[oper
].ctype
== RELAT
&& rtype
== UNS
)
432 if (v1
.type
== UND
|| v2
.type
== UND
)
469 rv1
= (unsigned long)rv1
<= (unsigned long)rv2
;
472 rv1
= (unsigned long)rv1
>= (unsigned long)rv2
;
475 rv1
= (unsigned long)rv1
< (unsigned long)rv2
;
478 rv1
= (unsigned long)rv1
> (unsigned long)rv2
;
484 rv1
= (unsigned long) rv1
<< rv2
;
490 rv1
= (unsigned long) rv1
>> rv2
;
558 rv1
/= (unsigned long) rv2
;
569 rv1
%= (unsigned long) rv2
;
575 error(ERROR
, "Bad ?: in #if/endif");
579 if ((--vp
)->val
== 0)
591 error(ERROR
, "Eval botch (unknown operator)");
594 /*lint +e574 +e644 */
621 if ((np
= lookup(tp
, 0)) != NULL
&& np
->flag
& (ISDEFINED
| ISMAC
))
626 if ((np
= lookup(tp
, 0)) != NULL
&& np
->flag
& (ISARCHITECTURE
))
639 if (p
[1] == 'x' || p
[1] == 'X')
648 if ((i
= digit(*p
)) < 0)
652 "Bad digit in number %t", tp
);
656 if (n
>= 0x80000000 && base
!= 10)
660 if (*p
== 'u' || *p
== 'U')
663 if (*p
== 'l' || *p
== 'L')
668 "Bad number %t in #if/#elsif", tp
);
682 error(WARNING
, "Wide char constant value undefined");
688 if ((i
= digit(*p
)) >= 0 && i
<= 7)
692 if ((i
= digit(*p
)) >= 0 && i
<= 7)
697 if ((i
= digit(*p
)) >= 0 && i
<= 7)
709 while ((i
= digit(*p
)) >= 0 && i
<= 15)
718 static char cvcon
[] = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
719 static size_t cvlen
= sizeof(cvcon
) - 1;
722 for (j
= 0; j
< cvlen
; j
+= 2)
733 "Undefined escape in character constant");
738 error(ERROR
, "Empty character constant");
742 error(WARNING
, "Multibyte character constant undefined");
745 error(WARNING
, "Character constant taken as not signed");
750 error(ERROR
, "String in #if/#elsif");
759 if ('0' <= i
&& i
<= '9')
762 if ('a' <= i
&& i
<= 'f')
765 if ('A' <= i
&& i
<= 'F')
772 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */