]> git.sur5r.net Git - cc65/blobdiff - src/cc65/typecmp.c
Fixed a bug
[cc65] / src / cc65 / typecmp.c
index 46eda0baf334931c6b75a8199520cb69b13b82e4..5b2be8500acace006370c70264b71f1eab8118ea 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -33,6 +33,9 @@
 
 
 
+#include <string.h>
+
+/* cc65 */
 #include "funcdesc.h"
 #include "symtab.h"
 #include "typecmp.h"
@@ -55,6 +58,38 @@ static void SetResult (typecmp_t* Result, typecmp_t Val)
 
 
 
+static int EqualFuncParams (SymTable* Tab1, SymTable* Tab2)
+/* Compare two function symbol tables regarding function parameters. Return 1
+ * if they are equal and 0 otherwise.
+ */
+{
+    /* Compare the parameter lists */
+    SymEntry* Sym1 = Tab1->SymHead;
+    SymEntry* Sym2 = Tab2->SymHead;
+
+    /* Compare the fields */
+    while (Sym1 && (Sym1->Flags & SC_PARAM) && Sym2 && (Sym2->Flags & SC_PARAM)) {
+
+       /* Compare this field */
+               if (TypeCmp (Sym1->Type, Sym2->Type) < TC_EQUAL) {
+           /* Field types not equal */
+           return 0;
+       }
+
+       /* Get the pointers to the next fields */
+       Sym1 = Sym1->NextSym;
+       Sym2 = Sym2->NextSym;
+    }
+
+    /* Check both pointers against NULL or a non parameter to compare the
+     * field count
+     */
+    return (Sym1 == 0 || (Sym1->Flags & SC_PARAM) == 0) &&
+          (Sym2 == 0 || (Sym2->Flags & SC_PARAM) == 0);
+}
+
+
+
 static int EqualSymTables (SymTable* Tab1, SymTable* Tab2)
 /* Compare two symbol tables. Return 1 if they are equal and 0 otherwise */
 {
@@ -65,7 +100,15 @@ static int EqualSymTables (SymTable* Tab1, SymTable* Tab2)
     /* Compare the fields */
     while (Sym1 && Sym2) {
 
-       /* Compare this field */
+       /* Compare the names of this field */
+        if (!HasAnonName (Sym1) || !HasAnonName (Sym2)) {
+            if (strcmp (Sym1->Name, Sym2->Name) != 0) {
+                /* Names are not identical */
+                return 0;
+            }
+        }
+
+        /* Compare the types of this field */
                if (TypeCmp (Sym1->Type, Sym2->Type) < TC_EQUAL) {
            /* Field types not equal */
            return 0;
@@ -106,7 +149,7 @@ static void DoCompare (const type* lhs, const type* rhs, typecmp_t* Result)
                type LeftType, RightType;
        type LeftSign, RightSign;
        type LeftQual, RightQual;
-       unsigned LeftCount, RightCount;
+       long LeftCount, RightCount;
 
                /* Check if the end of the type string is reached */
                if (*rhs == T_END) {
@@ -216,7 +259,7 @@ static void DoCompare (const type* lhs, const type* rhs, typecmp_t* Result)
                            }
 
                            /* Compare the parameter lists */
-                           if (EqualSymTables (F1->SymTab, F2->SymTab) == 0 ||
+                           if (EqualFuncParams (F1->SymTab, F2->SymTab) == 0 ||
                                EqualSymTables (F1->TagTab, F2->TagTab) == 0) {
                                /* One of the tables is not identical */
                        SetResult (Result, TC_INCOMPATIBLE);
@@ -231,9 +274,11 @@ static void DoCompare (const type* lhs, const type* rhs, typecmp_t* Result)
 
            case T_TYPE_ARRAY:
                /* Check member count */
-               LeftCount  = Decode (lhs+1);
-               RightCount = Decode (rhs+1);
-               if (LeftCount != 0 && RightCount != 0 && LeftCount != RightCount) {
+               LeftCount  = GetElementCount (lhs);
+               RightCount = GetElementCount (rhs);
+                       if (LeftCount  != UNSPECIFIED &&
+                    RightCount != UNSPECIFIED &&
+                    LeftCount  != RightCount) {
                    /* Member count given but different */
                    SetResult (Result, TC_INCOMPATIBLE);
                    return;
@@ -251,6 +296,15 @@ static void DoCompare (const type* lhs, const type* rhs, typecmp_t* Result)
                Sym1 = DecodePtr (lhs+1);
                Sym2 = DecodePtr (rhs+1);
 
+                /* If one symbol has a name, the names must be identical */
+                if (!HasAnonName (Sym1) || !HasAnonName (Sym2)) {
+                    if (strcmp (Sym1->Name, Sym2->Name) != 0) {
+                        /* Names are not identical */
+                        SetResult (Result, TC_INCOMPATIBLE);
+                        return;
+                    }
+                }
+
                /* Get the field tables from the struct entry */
                Tab1 = Sym1->V.S.SymTab;
                Tab2 = Sym2->V.S.SymTab;