mirror of
https://github.com/cc65/cc65.git
synced 2025-01-10 19:29:45 +00:00
Fixed an error in struct compare. For one, the behaviour was not standard
compliant, because struct tags were not compare, second, this lead to an endless loop of recursive calls for a special case of wrong C code. git-svn-id: svn://svn.cc65.org/cc65/trunk@1523 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
ca1386e9d4
commit
8ef3447248
@ -34,13 +34,25 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* cc65 */
|
||||
#include "anonname.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
static const char AnonTag[] = "$anon";
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
@ -51,9 +63,17 @@ char* AnonName (char* Buf, const char* Spec)
|
||||
*/
|
||||
{
|
||||
static unsigned ACount = 0;
|
||||
sprintf (Buf, "$anon-%s-%04X", Spec, ++ACount);
|
||||
sprintf (Buf, "%s-%s-%04X", AnonTag, Spec, ++ACount);
|
||||
return Buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int IsAnonName (const char* Name)
|
||||
/* Check if the given symbol name is that of an anonymous symbol */
|
||||
{
|
||||
return (strncmp (Name, AnonTag, sizeof (AnonTag) - 1) == 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -49,6 +49,9 @@ char* AnonName (char* Buf, const char* Spec);
|
||||
* to be IDENTSIZE characters long. A pointer to the buffer is returned.
|
||||
*/
|
||||
|
||||
int IsAnonName (const char* Name);
|
||||
/* Check if the given symbol name is that of an anonymous symbol */
|
||||
|
||||
|
||||
|
||||
/* End of anonname.h */
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* cc65 */
|
||||
#include "anonname.h"
|
||||
#include "symentry.h"
|
||||
|
||||
|
||||
@ -174,3 +175,11 @@ void ChangeAsmName (SymEntry* Entry, const char* NewAsmName)
|
||||
|
||||
|
||||
|
||||
int HasAnonName (const SymEntry* Entry)
|
||||
/* Return true if the symbol entry has an anonymous name */
|
||||
{
|
||||
return IsAnonName (Entry->Name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -154,6 +154,9 @@ void ChangeSymType (SymEntry* Entry, type* Type);
|
||||
void ChangeAsmName (SymEntry* Entry, const char* NewAsmName);
|
||||
/* Change the assembler name of the symbol */
|
||||
|
||||
int HasAnonName (const SymEntry* Entry);
|
||||
/* Return true if the symbol entry has an anonymous name */
|
||||
|
||||
|
||||
|
||||
/* End of symentry.h */
|
||||
|
@ -33,6 +33,9 @@
|
||||
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* cc65 */
|
||||
#include "funcdesc.h"
|
||||
#include "symtab.h"
|
||||
#include "typecmp.h"
|
||||
@ -97,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;
|
||||
@ -283,6 +294,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user