Extend warning 247 to other arithmetic and comparison operators
This commit is contained in:
parent
c9ad518d52
commit
d4cb7cccb2
@ -61,6 +61,8 @@ static int dbltest(void (*oper)(),value *lval1,value *lval2);
|
|||||||
static int commutative(void (*oper)());
|
static int commutative(void (*oper)());
|
||||||
static int constant(value *lval);
|
static int constant(value *lval);
|
||||||
|
|
||||||
|
static const char str_w247unary[]="a \"bool:\" value";
|
||||||
|
static const char str_w247binary[]="\"bool:\" values";
|
||||||
static char lastsymbol[sNAMEMAX+1]; /* name of last function/variable */
|
static char lastsymbol[sNAMEMAX+1]; /* name of last function/variable */
|
||||||
static int bitwise_opercount; /* count of bitwise operators in an expression */
|
static int bitwise_opercount; /* count of bitwise operators in an expression */
|
||||||
static int decl_heap=0;
|
static int decl_heap=0;
|
||||||
@ -646,9 +648,29 @@ static void plnge2(void (*oper)(void),
|
|||||||
lval1->ident=iEXPRESSION;
|
lval1->ident=iEXPRESSION;
|
||||||
lval1->constval=0;
|
lval1->constval=0;
|
||||||
} else {
|
} else {
|
||||||
if ((oper==ob_sal || oper==os_sar || oper==ou_sar)
|
if (lval1->tag==BOOLTAG && lval2->tag==BOOLTAG
|
||||||
&& (lval2->ident==iCONSTEXPR && (lval2->constval<0 || lval2->constval>=PAWN_CELL_SIZE)))
|
&& oper!=ob_or && oper!=ob_xor && oper!=ob_and && oper!=ob_eq && oper!=ob_ne) {
|
||||||
|
static const void (*opers[])(void) = {
|
||||||
|
os_mult,os_div,os_mod,ob_add,ob_sub,ob_sal,
|
||||||
|
os_sar,ou_sar,os_le,os_ge,os_lt,os_gt
|
||||||
|
};
|
||||||
|
static const char* opnames[] = {
|
||||||
|
"*","/","%","+","-","<<",
|
||||||
|
">>",">>>","<=",">=","<",">"
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
assert_static(arraysize(opers)==arraysize(opnames)); /* make sure the array sizes match */
|
||||||
|
assert_static(arraysize(op1)==17); /* in case a new operator is added into the compiler,
|
||||||
|
* arrays "opers" and "opnames" might need to be updated */
|
||||||
|
for (i=0; i<arraysize(opers); i++)
|
||||||
|
if (oper==opers[i])
|
||||||
|
break;
|
||||||
|
assert(i<arraysize(opers));
|
||||||
|
error(247,opnames[i],str_w247binary); /* use of operator on \"bool:\" values */
|
||||||
|
} else if ((oper==ob_sal || oper==os_sar || oper==ou_sar)
|
||||||
|
&& (lval2->ident==iCONSTEXPR && (lval2->constval<0 || lval2->constval>=PAWN_CELL_SIZE))) {
|
||||||
error(241); /* negative or too big shift count */
|
error(241); /* negative or too big shift count */
|
||||||
|
} /* if */
|
||||||
if (lval1->ident==iCONSTEXPR && lval2->ident==iCONSTEXPR) {
|
if (lval1->ident==iCONSTEXPR && lval2->ident==iCONSTEXPR) {
|
||||||
/* only constant expression if both constant */
|
/* only constant expression if both constant */
|
||||||
stgdel(lval_stgidx,lval_cidx); /* scratch generated code and calculate */
|
stgdel(lval_stgidx,lval_cidx); /* scratch generated code and calculate */
|
||||||
@ -1284,8 +1306,11 @@ static int hier2(value *lval)
|
|||||||
assert(lval->sym!=NULL);
|
assert(lval->sym!=NULL);
|
||||||
if ((lval->sym->usage & uCONST)!=0)
|
if ((lval->sym->usage & uCONST)!=0)
|
||||||
return error(22); /* assignment to const argument */
|
return error(22); /* assignment to const argument */
|
||||||
if (!check_userop(user_inc,lval->tag,0,1,lval,&lval->tag))
|
if (!check_userop(user_inc,lval->tag,0,1,lval,&lval->tag)) {
|
||||||
|
if (lval->tag==BOOLTAG)
|
||||||
|
error(247,"++",str_w247unary); /* use of operator "++" on a "bool:" value */
|
||||||
inc(lval); /* increase variable first */
|
inc(lval); /* increase variable first */
|
||||||
|
} /* if */
|
||||||
rvalue(lval); /* and read the result into PRI */
|
rvalue(lval); /* and read the result into PRI */
|
||||||
pc_sideeffect=TRUE;
|
pc_sideeffect=TRUE;
|
||||||
return FALSE; /* result is no longer lvalue */
|
return FALSE; /* result is no longer lvalue */
|
||||||
@ -1295,8 +1320,11 @@ static int hier2(value *lval)
|
|||||||
assert(lval->sym!=NULL);
|
assert(lval->sym!=NULL);
|
||||||
if ((lval->sym->usage & uCONST)!=0)
|
if ((lval->sym->usage & uCONST)!=0)
|
||||||
return error(22); /* assignment to const argument */
|
return error(22); /* assignment to const argument */
|
||||||
if (!check_userop(user_dec,lval->tag,0,1,lval,&lval->tag))
|
if (!check_userop(user_dec,lval->tag,0,1,lval,&lval->tag)) {
|
||||||
|
if (lval->tag==BOOLTAG)
|
||||||
|
error(247,"--",str_w247unary); /* use of operator "--" on a "bool:" value */
|
||||||
dec(lval); /* decrease variable first */
|
dec(lval); /* decrease variable first */
|
||||||
|
} /* if */
|
||||||
rvalue(lval); /* and read the result into PRI */
|
rvalue(lval); /* and read the result into PRI */
|
||||||
pc_sideeffect=TRUE;
|
pc_sideeffect=TRUE;
|
||||||
return FALSE; /* result is no longer lvalue */
|
return FALSE; /* result is no longer lvalue */
|
||||||
@ -1308,7 +1336,7 @@ static int hier2(value *lval)
|
|||||||
if (lval->ident==iVARIABLE || lval->ident==iARRAYCELL)
|
if (lval->ident==iVARIABLE || lval->ident==iARRAYCELL)
|
||||||
lval->ident=iEXPRESSION;
|
lval->ident=iEXPRESSION;
|
||||||
if (lval->tag==BOOLTAG)
|
if (lval->tag==BOOLTAG)
|
||||||
error(makelong(247,3),"!"); /* use of operator "~" on a "bool:" value always results in "true" */
|
error(makelong(247,3),"~",str_w247unary,"!"); /* use of operator "~" on a "bool:" value; did you mean to use operator "!"? */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
case '!': /* ! (logical negate) */
|
case '!': /* ! (logical negate) */
|
||||||
if (hier2(lval))
|
if (hier2(lval))
|
||||||
@ -1353,6 +1381,8 @@ static int hier2(value *lval)
|
|||||||
lval->constval=-lval->constval;
|
lval->constval=-lval->constval;
|
||||||
if (lval->ident==iVARIABLE || lval->ident==iARRAYCELL)
|
if (lval->ident==iVARIABLE || lval->ident==iARRAYCELL)
|
||||||
lval->ident=iEXPRESSION;
|
lval->ident=iEXPRESSION;
|
||||||
|
if (lval->tag==BOOLTAG)
|
||||||
|
error(makelong(247,3),"-",str_w247unary,"!"); /* use of operator "-" on a "bool:" value; did you mean to use operator "!"? */
|
||||||
} /* if */
|
} /* if */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
case tLABEL: /* tagname override */
|
case tLABEL: /* tagname override */
|
||||||
@ -1678,8 +1708,11 @@ static int hier2(value *lval)
|
|||||||
rvalue(lval); /* read current value into PRI */
|
rvalue(lval); /* read current value into PRI */
|
||||||
if (saveresult)
|
if (saveresult)
|
||||||
swap1(); /* save PRI on the stack, restore address in PRI */
|
swap1(); /* save PRI on the stack, restore address in PRI */
|
||||||
if (!check_userop(user_inc,lval->tag,0,1,lval,&lval->tag))
|
if (!check_userop(user_inc,lval->tag,0,1,lval,&lval->tag)) {
|
||||||
|
if (lval->tag==BOOLTAG)
|
||||||
|
error(247,"++",str_w247unary); /* use of operator "++" on a "bool:" value */
|
||||||
inc(lval); /* increase variable afterwards */
|
inc(lval); /* increase variable afterwards */
|
||||||
|
} /* if */
|
||||||
if (saveresult)
|
if (saveresult)
|
||||||
popreg(sPRI); /* restore PRI (result of rvalue()) */
|
popreg(sPRI); /* restore PRI (result of rvalue()) */
|
||||||
pc_sideeffect=TRUE;
|
pc_sideeffect=TRUE;
|
||||||
@ -1696,8 +1729,11 @@ static int hier2(value *lval)
|
|||||||
rvalue(lval); /* read current value into PRI */
|
rvalue(lval); /* read current value into PRI */
|
||||||
if (saveresult)
|
if (saveresult)
|
||||||
swap1(); /* save PRI on the stack, restore address in PRI */
|
swap1(); /* save PRI on the stack, restore address in PRI */
|
||||||
if (!check_userop(user_dec,lval->tag,0,1,lval,&lval->tag))
|
if (!check_userop(user_dec,lval->tag,0,1,lval,&lval->tag)) {
|
||||||
|
if (lval->tag==BOOLTAG)
|
||||||
|
error(247,"--",str_w247unary); /* use of operator "--" on a "bool:" value */
|
||||||
dec(lval); /* decrease variable afterwards */
|
dec(lval); /* decrease variable afterwards */
|
||||||
|
} /* if */
|
||||||
if (saveresult)
|
if (saveresult)
|
||||||
popreg(sPRI); /* restore PRI (result of rvalue()) */
|
popreg(sPRI); /* restore PRI (result of rvalue()) */
|
||||||
pc_sideeffect=TRUE;
|
pc_sideeffect=TRUE;
|
||||||
|
@ -205,14 +205,14 @@ static char *warnmsg[] = {
|
|||||||
/*244*/ "enum element \"%s\" not handled in switch\n",
|
/*244*/ "enum element \"%s\" not handled in switch\n",
|
||||||
/*245*/ "enum increment \"%s %d\" has no effect on zero value (symbol \"%s\")\n",
|
/*245*/ "enum increment \"%s %d\" has no effect on zero value (symbol \"%s\")\n",
|
||||||
/*246*/ "multiplication overflow in enum element declaration (symbol \"%s\")\n",
|
/*246*/ "multiplication overflow in enum element declaration (symbol \"%s\")\n",
|
||||||
/*247*/ "use of operator \"~\" on a \"bool:\" value always results in \"true\"\n",
|
/*247*/ "use of operator \"%s\" on %s\n",
|
||||||
/*248*/ "possible misuse of comma operator\n"
|
/*248*/ "possible misuse of comma operator\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *noticemsg[] = {
|
static char *noticemsg[] = {
|
||||||
/*001*/ "; did you mean \"%s\"?\n",
|
/*001*/ "; did you mean \"%s\"?\n",
|
||||||
/*002*/ "; state variable out of scope\n",
|
/*002*/ "; state variable out of scope\n",
|
||||||
/*003*/ "; did you mean operator \"%s\"?\n"
|
/*003*/ "; did you mean to use operator \"%s\"?\n"
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NUM_WARNINGS arraysize(warnmsg)
|
#define NUM_WARNINGS arraysize(warnmsg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user