]> git.sur5r.net Git - cc65/blobdiff - src/cc65/typeconv.c
Fixed two compiler warnings.
[cc65] / src / cc65 / typeconv.c
index 86c07ec884b5c966974fb77fea3efc01b5947bc3..ecde7349fbaac217d810ac5094d9f50f434dbb99 100644 (file)
@@ -128,7 +128,7 @@ static void DoConversion (ExprDesc* Expr, const Type* NewType)
             Expr->IVal &= (0xFFFFFFFFUL >> (32 - NewBits));
 
             /* If the new type is signed, sign extend the value */
-            if (!IsSignUnsigned (NewType)) {
+            if (IsSignSigned (NewType)) {
                 if (Expr->IVal & (0x01UL << (NewBits-1))) {
                     /* Beware: Use the safe shift routine here. */
                     Expr->IVal |= shl_l (~0UL, NewBits);
@@ -168,6 +168,16 @@ void TypeConversion (ExprDesc* Expr, Type* NewType)
  * impossible.
  */
 {
+#if 0
+    /* Debugging */
+    printf ("Expr:\n=======================================\n");
+    PrintExprDesc (stdout, Expr);
+    printf ("Type:\n=======================================\n");
+    PrintType (stdout, NewType);
+    printf ("\n");
+    PrintRawType (stdout, NewType);
+#endif
+
     /* First, do some type checking */
     if (IsTypeVoid (NewType) || IsTypeVoid (Expr->Type)) {
        /* If one of the sides are of type void, output a more apropriate
@@ -176,6 +186,11 @@ void TypeConversion (ExprDesc* Expr, Type* NewType)
                Error ("Illegal type");
     }
 
+    /* If Expr is a function, convert it to pointer to function */
+    if (IsTypeFunc(Expr->Type)) {
+        Expr->Type = PointerTo (Expr->Type);
+    }
+
     /* If both types are equal, no conversion is needed */
     if (TypeCmp (Expr->Type, NewType) >= TC_EQUAL) {
         /* We're already done */
@@ -219,7 +234,7 @@ void TypeConversion (ExprDesc* Expr, Type* NewType)
             */
            if (!IsTypeVoid (Indirect (NewType)) && !IsTypeVoid (Indirect (Expr->Type))) {
                /* Compare the types */
-               switch (TypeCmp (NewType, Expr->Type)) {
+                switch (TypeCmp (NewType, Expr->Type)) {
 
                    case TC_INCOMPATIBLE:
                        Error ("Incompatible pointer types");
@@ -240,16 +255,6 @@ void TypeConversion (ExprDesc* Expr, Type* NewType)
            if (!ED_IsConstAbsInt (Expr) || Expr->IVal != 0) {
                Warning ("Converting integer to pointer without a cast");
            }
-       } else if (IsTypeFuncPtr (NewType) && IsTypeFunc(Expr->Type)) {
-            /* Function -> Function pointer. First convert rhs to pointer */
-            Expr->Type = PointerTo (Expr->Type);
-
-           /* Assignment of function to function pointer is allowed, provided
-            * that both functions have the same parameter list.
-            */
-                   if (TypeCmp (NewType, Expr->Type) < TC_EQUAL) {
-               Error ("Incompatible types");
-           }
        } else {
            Error ("Incompatible types");
        }