pedantic>1: "char c=200" is not allowed (evaluates to -56)
*/
-void checkConstantRange(sym_link *ltype, double v, char *msg, int pedantic) {
+void checkConstantRange(sym_link *ltype, value *val, char *msg, int pedantic) {
LONG_LONG max = (LONG_LONG) 1 << bitsForType(ltype);
char message[132]="";
int warnings=0;
int negative=0;
+ long v;
+
+ if (SPEC_LONG(val->type)) {
+ v=SPEC_CVAL(val->type).v_long;
+ } else {
+ v=SPEC_CVAL(val->type).v_int;
+ }
+
#if 0
// this could be a good idea
return;
}
- if (v<0) {
+ if (!SPEC_USIGN(val->type) && v<0) {
negative=1;
- // if not pedantic: -1 equals to 0xf..f
- if (SPEC_USIGN(ltype) && (!pedantic ? v!=-1 : 1)) {
+ if (SPEC_USIGN(ltype) && (pedantic>1)) {
warnings++;
}
v=-v;
{
operand *op;
- op = Safe_calloc (1, sizeof (operand));
+ op = Safe_alloc ( sizeof (operand));
op->key = 0;
return op;
{
iCode *ic;
- ic = Safe_calloc (1, sizeof (iCode));
+ ic = Safe_alloc ( sizeof (iCode));
ic->lineno = lineno;
ic->filename = filename;
break;
case LEFT_OP:
- retval = operandFromLit (((SPEC_USIGN(let) ?
+ retval = operandFromLit ((SPEC_USIGN(let) ?
(unsigned long) operandLitValue (left) :
(long) operandLitValue (left)) <<
(SPEC_USIGN(ret) ?
(unsigned long) operandLitValue (right) :
- (long) operandLitValue (right))));
+ (long) operandLitValue (right)));
break;
case RIGHT_OP:
- retval = operandFromLit (((SPEC_USIGN(let) ?
+ retval = operandFromLit ((SPEC_USIGN(let) ?
(unsigned long) operandLitValue (left) :
(long) operandLitValue (left)) >>
(SPEC_USIGN(ret) ?
(unsigned long) operandLitValue (right) :
- (long) operandLitValue (right))));
+ (long) operandLitValue (right)));
break;
case EQ_OP:
retval = operandFromLit (operandLitValue (left) ==
operandLitValue (right));
break;
case BITWISEAND:
- retval = operandFromLit ((unsigned long) operandLitValue (left) &
- (unsigned long) operandLitValue (right));
+ retval = operandFromLit ((long)operandLitValue(left) &
+ (long)operandLitValue(right));
break;
case '|':
- retval = operandFromLit ((unsigned long) operandLitValue (left) |
- (unsigned long) operandLitValue (right));
+ retval = operandFromLit ((long)operandLitValue (left) |
+ (long)operandLitValue (right));
break;
case '^':
- retval = operandFromLit ((unsigned long) operandLitValue (left) ^
- (unsigned long) operandLitValue (right));
+ retval = operandFromLit ((long)operandLitValue (left) ^
+ (long)operandLitValue (right));
break;
case AND_OP:
retval = operandFromLit (operandLitValue (left) &&
return 0;
}
-/*-----------------------------------------------------------------*/
-/* isiCodeEqual - comapres two iCodes are returns true if yes */
-/*-----------------------------------------------------------------*/
+/*-------------------------------------------------------------------*/
+/* isiCodeEqual - compares two iCodes are equal, returns true if yes */
+/*-------------------------------------------------------------------*/
int
isiCodeEqual (iCode * left, iCode * right)
{
if (!isSymbolEqual (IC_FALSE (left), IC_FALSE (right)))
return 0;
}
+
return 1;
}
return 0;
/* if casting to/from pointers, do some checking */
if (IS_PTR(type)) { // to a pointer
- if (!IS_PTR(optype) && !IS_FUNC(optype)) { // from a non pointer
+ if (!IS_PTR(optype) && !IS_FUNC(optype) && !IS_AGGREGATE(optype)) { // from a non pointer
if (IS_INTEGRAL(optype)) {
// maybe this is NULL, than it's ok.
if (!(IS_LITERAL(optype) && (SPEC_CVAL(optype).v_ulong ==0))) {
- if (IS_GENPTR(type)) {
+ if (!TARGET_IS_Z80 && !TARGET_IS_GBZ80 && IS_GENPTR(type)) {
// no way to set the storage
if (IS_LITERAL(optype)) {
werror(E_LITERAL_GENERIC);
} else {
// shouldn't do that with float, array or structure unless to void
if (!IS_VOID(getSpec(type)) &&
- !(IS_CODEPTR(type) && IS_FUNC(optype))) {
+ !(IS_CODEPTR(type) && IS_FUNC(type->next) && IS_FUNC(optype))) {
werror(E_INCOMPAT_TYPES);
errors++;
}
}
} else { // from a pointer to a pointer
- if (implicit) { // if not to generic, they have to match
- if ((!IS_GENPTR(type) && (DCL_TYPE(optype) != DCL_TYPE(type)))) {
- werror(E_INCOMPAT_PTYPES);
- errors++;
+ if (!TARGET_IS_Z80 && !TARGET_IS_GBZ80) {
+ // if not a pointer to a function
+ if (!(IS_CODEPTR(type) && IS_FUNC(type->next) && IS_FUNC(optype))) {
+ if (implicit) { // if not to generic, they have to match
+ if ((!IS_GENPTR(type) && (DCL_TYPE(optype) != DCL_TYPE(type)))) {
+ werror(E_INCOMPAT_PTYPES);
+ errors++;
+ }
+ }
}
}
}
if (IS_INTEGRAL (ltype) && IS_VALOP (right) && IS_LITERAL (rtype))
{
checkConstantRange(ltype,
- operandLitValue(right), "compare operation", 1);
+ OP_VALUE(right), "compare operation", 1);
}
ctype = usualBinaryConversions (&left, &right);
if (IS_INTEGRAL (ltype) && right->type == VALUE && IS_LITERAL (rtype))
{
checkConstantRange(ltype,
- operandLitValue(right), "= operation", 0);
+ OP_VALUE(right), "= operation", 0);
}
/* if the left & right type don't exactly match */
/*-----------------------------------------------------------------*/
void addLvaluereq(int lvl)
{
- lvalItem * lpItem = (lvalItem *)Safe_calloc (1, sizeof (lvalItem));
+ lvalItem * lpItem = (lvalItem *)Safe_alloc ( sizeof (lvalItem));
lpItem->req=1;
lpItem->lvl=lvl;
addSetHead(&lvaluereqSet,lpItem);
{
lvalItem * lpItem;
lpItem = getSet(&lvaluereqSet);
- if(lpItem) free(lpItem);
+ if(lpItem) Safe_free(lpItem);
}
/*-----------------------------------------------------------------*/
/* clearLvaluereq - clear lvalreq flag */