/* the parameter type must be at least castable */
if (compareType (defParm->type, actParm->ftype) == 0) {
- werror (W_INCOMPAT_CAST);
+ werror (E_INCOMPAT_TYPES);
fprintf (stderr, "type --> '");
printTypeChain (actParm->ftype, stderr);
fprintf (stderr, "' ");
{
sym_link *ltc = (tree->right ? RTYPE (tree) : LTYPE (tree));
COPYTYPE (TTYPE (tree), TETYPE (tree), ltc);
- if (!tree->initMode && IS_CONSTANT (TETYPE (tree)))
+ if (!tree->initMode) {
+ if ((IS_SPEC(TETYPE(tree)) && IS_CONSTANT (TETYPE (tree))) ||
+ (IS_PTR(TTYPE(tree)) && DCL_PTR_CONST(TTYPE(tree)))) {
werror (E_CODE_WRITE, "++/--");
+ }
+ }
if (tree->right)
RLVAL (tree) = 1;
/* make sure the type is complete and sane */
checkTypeSanity(LETYPE(tree), "(cast)");
-#if 1
+#if 0
/* if the right is a literal replace the tree */
if (IS_LITERAL (RETYPE (tree))) {
if (!IS_PTR (LTYPE (tree))) {
fprintf (stderr, "'\n");
}
- /* extra checks for pointer types */
- if (IS_PTR (LTYPE (tree)) && IS_PTR (RTYPE (tree)) &&
- !IS_GENPTR (LTYPE (tree)))
- {
- if (DCL_TYPE (LTYPE (tree)) != DCL_TYPE (RTYPE (tree)))
- werror (W_PTR_ASSIGN);
- }
-
TETYPE (tree) = getSpec (TTYPE (tree) =
LTYPE (tree));
RRVAL (tree) = 1;
LLVAL (tree) = 1;
if (!tree->initMode ) {
- if (IS_CONSTANT (LETYPE (tree))) {
- werror (E_CODE_WRITE, " ");
- }
+ if ((IS_SPEC(LETYPE(tree)) && IS_CONSTANT (LETYPE (tree))) ||
+ (IS_PTR(LTYPE(tree)) && DCL_PTR_CONST(LTYPE(tree)))) {
+ werror (E_CODE_WRITE, " ");
+ }
}
if (LRVAL (tree))
{
return operandFromValue (valCastLiteral (type,
operandLitValue (op)));
- /* if casting to some pointer type &&
- the destination is not a generic pointer
- then give a warning : (only for implicit casts) */
- if (IS_PTR (optype) && implicit &&
- (DCL_TYPE (optype) != DCL_TYPE (type)) &&
- !IS_GENPTR (type))
- {
- werror (W_INCOMPAT_CAST);
- fprintf (stderr, "from type '");
- printTypeChain (optype, stderr);
- fprintf (stderr, "' to type '");
- printTypeChain (type, stderr);
- fprintf (stderr, "'\n");
+
+ /* if casting to/from pointers, do some checking */
+ if (IS_PTR(type)) { // to a pointer
+ if (!IS_PTR(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)) {
+ // no way to set the storage
+ if (IS_LITERAL(optype)) {
+ werror(E_LITERAL_GENERIC);
+ } else {
+ werror(E_NONPTR2_GENPTR);
+ }
+ } else if (implicit) {
+ werror(W_INTEGRAL2PTR_NOCAST);
+ }
+ }
+ } else { // shouldn't do that with float, array or structure
+ werror(E_INCOMPAT_TYPES);
+ }
+ } 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);
+ }
+ }
}
+ } else { // to a non pointer
+ if (IS_PTR(optype)) { // from a pointer
+ if (implicit) { // sneaky
+ if (IS_INTEGRAL(type)) {
+ werror(W_PTR2INTEGRAL_NOCAST);
+ } else { // shouldn't do that with float, array or structure
+ werror(E_INCOMPAT_TYPES);
+ }
+ }
+ }
+ }
/* if they are the same size create an assignment */
if (getSize (type) == getSize (optype) &&
"Pre-Processor %s" },
{ E_DUP_FAILED, ERROR_LEVEL_ERROR,
"_dup call failed" },
-{ W_INCOMPAT_CAST, ERROR_LEVEL_WARNING,
- "pointer being cast to incompatible type " },
+{ E_INCOMPAT_TYPES, ERROR_LEVEL_ERROR,
+ "incompatible types" },
{ W_LOOP_ELIMINATE, ERROR_LEVEL_WARNING,
"'while' loop with 'zero' constant.loop eliminated" },
{ W_NO_SIDE_EFFECTS, ERROR_LEVEL_WARNING,
"unknown size for operand" },
{ W_LONG_UNSUPPORTED, ERROR_LEVEL_WARNING,
"'%s' 'long' not supported , declared as 'int' ." },
-{ W_LITERAL_GENERIC, ERROR_LEVEL_WARNING,
- "illegal cast of LITERAL value to 'generic' pointer: assuming 'xdata' pointer" },
+{ E_LITERAL_GENERIC, ERROR_LEVEL_ERROR,
+ //"illegal cast of LITERAL value to 'generic' pointer: assuming 'xdata' pointer" },
+ "illegal cast of LITERAL value to 'generic' pointer" },
{ E_SFR_ADDR_RANGE, ERROR_LEVEL_ERROR,
"%s '%s' address out of range" },
{ E_BITVAR_STORAGE, ERROR_LEVEL_ERROR,
"constant is out of range %s" },
{ W_CODE_UNREACH, ERROR_LEVEL_PEDANTIC,
"unreachable code %s(%d)" },
-{ W_NONPTR2_GENPTR, ERROR_LEVEL_WARNING,
- "non-pointer type cast to _generic pointer" },
+{ E_NONPTR2_GENPTR, ERROR_LEVEL_ERROR,
+ "non-pointer type cast to generic pointer" },
{ W_POSSBUG, ERROR_LEVEL_WARNING,
"possible code generation error at line %d,\n"
" send source to sandeep.dutta@usa.net" },
-{ W_PTR_ASSIGN, ERROR_LEVEL_WARNING,
+{ E_INCOMPAT_PTYPES, ERROR_LEVEL_WARNING,
"pointer types incompatible " },
{ W_UNKNOWN_MODEL, ERROR_LEVEL_WARNING,
"unknown memory model at %s : %d" },
"Only one short option can be specified at a time. Rest of %s ignored." },
{ E_VOID_VALUE_USED, ERROR_LEVEL_ERROR,
"void value not ignored as it ought to be" },
+{ W_INTEGRAL2PTR_NOCAST, ERROR_LEVEL_WARNING,
+ "converting integral to pointer without a cast" },
+{ W_PTR2INTEGRAL_NOCAST, ERROR_LEVEL_WARNING,
+ "converting pointer to integral without a cast" },
};
/*
#define E_EXTERN_INIT 75 /* extern variable initialised */
#define E_PRE_PROC_FAILED 76 /* preprocessor failed */
#define E_DUP_FAILED 77 /* file DUP failed */
-#define W_INCOMPAT_CAST 78 /* incompatible pointer casting */
+#define E_INCOMPAT_TYPES 78 /* incompatible types casting */
#define W_LOOP_ELIMINATE 79 /* loop eliminated */
#define W_NO_SIDE_EFFECTS 80 /* expression has no side effects */
#define W_CONST_TOO_LARGE 81 /* constant out of range */
#define W_NO_REFERENCE 85 /* no reference to local variable */
#define E_OP_UNKNOWN_SIZE 86 /* unknown size for operand */
#define W_LONG_UNSUPPORTED 87 /* 'long' not supported yet */
-#define W_LITERAL_GENERIC 88 /* literal being cast to generic pointer */
+#define E_LITERAL_GENERIC 88 /* literal being cast to generic pointer */
#define E_SFR_ADDR_RANGE 89 /* sfr address out of range */
#define E_BITVAR_STORAGE 90 /* storage given for 'bit' variable */
#define E_EXTERN_MISMATCH 91 /* extern declaration mismatches */
#define E_CAST_ZERO 124 /* casting to from size zero */
#define W_CONST_RANGE 125 /* constant too large */
#define W_CODE_UNREACH 126 /* unreachable code */
-#define W_NONPTR2_GENPTR 127 /* non pointer cast to generic pointer */
+#define E_NONPTR2_GENPTR 127 /* non pointer cast to generic pointer */
#define W_POSSBUG 128 /* possible code generation error */
-#define W_PTR_ASSIGN 129 /* incampatible pointer assignment */
+#define E_INCOMPAT_PTYPES 129 /* incampatible pointer assignment */
#define W_UNKNOWN_MODEL 130 /* Unknown memory model */
#define E_UNKNOWN_TARGET 131 /* target not defined */
#define W_INDIR_BANKED 132 /* Indirect call to a banked fun */
#define E_CANNOT_USE_GENERIC_POINTER 151
#define W_EXCESS_SHORT_OPTIONS 152
#define E_VOID_VALUE_USED 153
+#define W_INTEGRAL2PTR_NOCAST 154
+#define W_PTR2INTEGRAL_NOCAST 155
/** Describes the maximum error level that will be logged. Any level
* includes all of the levels listed after it.