10 #define UNSMARK 0x1000
18 /* conversion types */
26 /* operator priority, arity, and conversion type, indexed by tokentype */
220 }, /* ARCHITECTURE */
223 int evalop(struct pri
);
224 struct value
tokval(Token
*);
225 struct value vals
[NSTAK
], *vp
;
226 enum toktype ops
[NSTAK
], *op
;
229 * Evaluate an #if #elif #ifdef #ifndef line. trp->tp points to the keyword.
232 eval(Tokenrow
* trp
, int kw
)
239 if (kw
== KIFDEF
|| kw
== KIFNDEF
)
241 if (trp
->lp
- trp
->bp
!= 4 || trp
->tp
->type
!= NAME
)
243 error(ERROR
, "Syntax error in #ifdef/#ifndef");
246 np
= lookup(trp
->tp
, 0);
247 return (kw
== KIFDEF
) == (np
&& np
->flag
& (ISDEFINED
| ISMAC
));
249 ntok
= trp
->tp
- trp
->bp
;
250 kwdefined
->val
= KDEFINED
; /* activate special meaning of
252 expandrow(trp
, "<if>");
253 kwdefined
->val
= NAME
;
257 for (rnd
= 0, tp
= trp
->bp
+ ntok
; tp
< trp
->lp
; tp
++)
294 if (tp
->type
== MINUS
)
296 if (tp
->type
== STAR
|| tp
->type
== AND
)
298 error(ERROR
, "Illegal operator * or & in #if/#elsif");
325 if (evalop(priority
[tp
->type
]) != 0)
340 if (evalop(priority
[RP
]) != 0)
342 if (op
<= ops
|| op
[-1] != LP
)
350 if ((tp
+ 1) < trp
->lp
)
352 np
= lookup(tp
+ 1, 0);
353 if (np
&& (np
->val
== KMACHINE
))
358 *op
++ = ARCHITECTURE
;
365 error(ERROR
, "Bad operator (%t) in #if/#elsif", tp
);
371 if (evalop(priority
[END
]) != 0)
373 if (op
!= &ops
[1] || vp
!= &vals
[1])
375 error(ERROR
, "Botch in #if/#elsif");
378 if (vals
[0].type
== UND
)
379 error(ERROR
, "Undefined expression value");
382 error(ERROR
, "Syntax error in #if/#elsif");
387 evalop(struct pri pri
)
390 struct value v2
= { 0, UND
};
396 while (pri
.pri
< priority
[op
[-1]].pri
)
399 if (priority
[oper
].arity
== 2)
406 /*lint -e574 -e644 */
407 switch (priority
[oper
].ctype
)
411 error(WARNING
, "Syntax error in #if/#endif");
415 if (v1
.type
== UNS
|| v2
.type
== UNS
)
419 if (v1
.type
== UND
|| v2
.type
== UND
)
421 if (priority
[oper
].ctype
== RELAT
&& rtype
== UNS
)
428 if (v1
.type
== UND
|| v2
.type
== UND
)
465 rv1
= (unsigned long)rv1
<= (unsigned long)rv2
;
468 rv1
= (unsigned long)rv1
>= (unsigned long)rv2
;
471 rv1
= (unsigned long)rv1
< (unsigned long)rv2
;
474 rv1
= (unsigned long)rv1
> (unsigned long)rv2
;
480 rv1
= (unsigned long) rv1
<< rv2
;
486 rv1
= (unsigned long) rv1
>> rv2
;
554 rv1
/= (unsigned long) rv2
;
565 rv1
%= (unsigned long) rv2
;
571 error(ERROR
, "Bad ?: in #if/endif");
575 if ((--vp
)->val
== 0)
587 error(ERROR
, "Eval botch (unknown operator)");
590 /*lint +e574 +e644 */
617 if ((np
= lookup(tp
, 0)) != NULL
&& np
->flag
& (ISDEFINED
| ISMAC
))
622 if ((np
= lookup(tp
, 0)) != NULL
&& np
->flag
& (ISARCHITECTURE
))
635 if (p
[1] == 'x' || p
[1] == 'X')
644 if ((i
= digit(*p
)) < 0)
648 "Bad digit in number %t", tp
);
652 if (n
>= 0x80000000 && base
!= 10)
656 if (*p
== 'u' || *p
== 'U')
659 if (*p
== 'l' || *p
== 'L')
664 "Bad number %t in #if/#elsif", tp
);
678 error(WARNING
, "Wide char constant value undefined");
684 if ((i
= digit(*p
)) >= 0 && i
<= 7)
688 if ((i
= digit(*p
)) >= 0 && i
<= 7)
693 if ((i
= digit(*p
)) >= 0 && i
<= 7)
705 while ((i
= digit(*p
)) >= 0 && i
<= 15)
715 = "b\bf\fn\nr\rt\tv\v''\"\"??\\\\";
718 for (j
= 0; j
< sizeof(cvcon
); j
+= 2)
727 if (j
>= sizeof(cvcon
))
729 "Undefined escape in character constant");
734 error(ERROR
, "Empty character constant");
738 error(WARNING
, "Multibyte character constant undefined");
741 error(WARNING
, "Character constant taken as not signed");
746 error(ERROR
, "String in #if/#elsif");
755 if ('0' <= i
&& i
<= '9')
758 if ('a' <= i
&& i
<= 'f')
761 if ('A' <= i
&& i
<= 'F')