mirror of
https://github.com/frida/tinycc
synced 2024-11-28 02:29:38 +03:00
Factor out const condition detection
Creating condition_3way for this.
This commit is contained in:
parent
892c3d996f
commit
d4d3144e75
32
tccgen.c
32
tccgen.c
@ -4981,26 +4981,38 @@ static void expr_lor(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Assuming vtop is a value used in a conditional context
|
||||||
|
(i.e. compared with zero) return 0 if it's false, 1 if
|
||||||
|
true and -1 if it can't be statically determined. */
|
||||||
|
static int condition_3way(void)
|
||||||
|
{
|
||||||
|
int c = -1;
|
||||||
|
if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
|
||||||
|
(!(vtop->r & VT_SYM) ||
|
||||||
|
!(vtop->sym->type.t & VT_WEAK))) {
|
||||||
|
CType boolean;
|
||||||
|
boolean.t = VT_BOOL;
|
||||||
|
vdup();
|
||||||
|
gen_cast(&boolean);
|
||||||
|
c = vtop->c.i;
|
||||||
|
vpop();
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
static void expr_cond(void)
|
static void expr_cond(void)
|
||||||
{
|
{
|
||||||
int tt, u, r1, r2, rc, t1, t2, bt1, bt2, islv;
|
int tt, u, r1, r2, rc, t1, t2, bt1, bt2, islv;
|
||||||
|
int c;
|
||||||
SValue sv;
|
SValue sv;
|
||||||
CType type, type1, type2;
|
CType type, type1, type2;
|
||||||
|
|
||||||
expr_lor();
|
expr_lor();
|
||||||
if (tok == '?') {
|
if (tok == '?') {
|
||||||
next();
|
next();
|
||||||
if ((vtop->r & (VT_VALMASK | VT_LVAL)) == VT_CONST &&
|
c = condition_3way();
|
||||||
(!(vtop->r & VT_SYM) ||
|
if (c >= 0) {
|
||||||
!(vtop->sym->type.t & VT_WEAK))) {
|
|
||||||
int saved_nocode_wanted = nocode_wanted;
|
int saved_nocode_wanted = nocode_wanted;
|
||||||
CType boolean;
|
|
||||||
int c;
|
|
||||||
boolean.t = VT_BOOL;
|
|
||||||
vdup();
|
|
||||||
gen_cast(&boolean);
|
|
||||||
c = vtop->c.i;
|
|
||||||
vpop();
|
|
||||||
if (c) {
|
if (c) {
|
||||||
if (tok != ':' || !gnu_ext) {
|
if (tok != ':' || !gnu_ext) {
|
||||||
vpop();
|
vpop();
|
||||||
|
Loading…
Reference in New Issue
Block a user