Check for macro redefinitions that are not identical and flag them as an
error. git-svn-id: svn://svn.cc65.org/cc65/trunk@357 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -94,6 +94,7 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
|||||||
"Too few arguments in function call",
|
"Too few arguments in function call",
|
||||||
"Macro argument count mismatch",
|
"Macro argument count mismatch",
|
||||||
"Duplicate macro parameter: %s",
|
"Duplicate macro parameter: %s",
|
||||||
|
"Macro redefinition is not identical",
|
||||||
"Variable identifier expected",
|
"Variable identifier expected",
|
||||||
"Integer expression expected",
|
"Integer expression expected",
|
||||||
"Constant expression expected",
|
"Constant expression expected",
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ enum Warnings {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Error numbers */
|
/* Error numbers */
|
||||||
enum Errors {
|
enum Errors {
|
||||||
ERR_NONE, /* No error */
|
ERR_NONE, /* No error */
|
||||||
ERR_INVALID_CHAR,
|
ERR_INVALID_CHAR,
|
||||||
ERR_UNEXPECTED_NEWLINE,
|
ERR_UNEXPECTED_NEWLINE,
|
||||||
@@ -94,6 +94,7 @@ enum Errors {
|
|||||||
ERR_TOO_FEW_FUNC_ARGS,
|
ERR_TOO_FEW_FUNC_ARGS,
|
||||||
ERR_MACRO_ARGCOUNT,
|
ERR_MACRO_ARGCOUNT,
|
||||||
ERR_DUPLICATE_MACRO_ARG,
|
ERR_DUPLICATE_MACRO_ARG,
|
||||||
|
ERR_MACRO_REDEF,
|
||||||
ERR_VAR_IDENT_EXPECTED,
|
ERR_VAR_IDENT_EXPECTED,
|
||||||
ERR_INT_EXPR_EXPECTED,
|
ERR_INT_EXPR_EXPECTED,
|
||||||
ERR_CONST_EXPR_EXPECTED,
|
ERR_CONST_EXPR_EXPECTED,
|
||||||
|
|||||||
@@ -36,9 +36,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "../common/hashstr.h"
|
/* common */
|
||||||
#include "../common/xmalloc.h"
|
#include "hashstr.h"
|
||||||
|
#include "xmalloc.h"
|
||||||
|
|
||||||
|
/* cc65 */
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "macrotab.h"
|
#include "macrotab.h"
|
||||||
|
|
||||||
@@ -304,6 +306,29 @@ void AddMacroArg (Macro* M, const char* Arg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int MacroCmp (const Macro* M1, const Macro* M2)
|
||||||
|
/* Compare two macros and return zero if both are identical. */
|
||||||
|
{
|
||||||
|
int I;
|
||||||
|
|
||||||
|
/* Argument count must be identical */
|
||||||
|
if (M1->ArgCount != M2->ArgCount) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compare the arguments */
|
||||||
|
for (I = 0; I < M1->ArgCount; ++I) {
|
||||||
|
if (strcmp (M1->FormalArgs[I], M2->FormalArgs[I]) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compare the replacement */
|
||||||
|
return strcmp (M1->Replacement, M2->Replacement);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PrintMacroStats (FILE* F)
|
void PrintMacroStats (FILE* F)
|
||||||
/* Print macro statistics to the given text file. */
|
/* Print macro statistics to the given text file. */
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -109,6 +109,9 @@ const char* FindMacroArg (Macro* M, const char* Arg);
|
|||||||
void AddMacroArg (Macro* M, const char* Arg);
|
void AddMacroArg (Macro* M, const char* Arg);
|
||||||
/* Add a formal macro argument. */
|
/* Add a formal macro argument. */
|
||||||
|
|
||||||
|
int MacroCmp (const Macro* M1, const Macro* M2);
|
||||||
|
/* Compare two macros and return zero if both are identical. */
|
||||||
|
|
||||||
void PrintMacroStats (FILE* F);
|
void PrintMacroStats (FILE* F);
|
||||||
/* Print macro statistics to the given text file. */
|
/* Print macro statistics to the given text file. */
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "attrib.h"
|
#include "attrib.h"
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
#include "xsprintf.h"
|
||||||
|
|
||||||
/* cc65 */
|
/* cc65 */
|
||||||
#include "asmlabel.h"
|
#include "asmlabel.h"
|
||||||
|
|||||||
@@ -355,6 +355,7 @@ static void addmac (void)
|
|||||||
ident Ident;
|
ident Ident;
|
||||||
char Buf[LINESIZE];
|
char Buf[LINESIZE];
|
||||||
Macro* M;
|
Macro* M;
|
||||||
|
Macro* Existing;
|
||||||
|
|
||||||
/* Read the macro name */
|
/* Read the macro name */
|
||||||
SkipBlank ();
|
SkipBlank ();
|
||||||
@@ -362,6 +363,9 @@ static void addmac (void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get an existing macro definition with this name */
|
||||||
|
Existing = FindMacro (Ident);
|
||||||
|
|
||||||
/* Create a new macro definition */
|
/* Create a new macro definition */
|
||||||
M = NewMacro (Ident);
|
M = NewMacro (Ident);
|
||||||
|
|
||||||
@@ -411,6 +415,15 @@ static void addmac (void)
|
|||||||
|
|
||||||
/* Create a copy of the replacement */
|
/* Create a copy of the replacement */
|
||||||
M->Replacement = xstrdup (Buf);
|
M->Replacement = xstrdup (Buf);
|
||||||
|
|
||||||
|
/* If we have an existing macro, check if the redefinition is identical.
|
||||||
|
* Print a diagnostic if not.
|
||||||
|
*/
|
||||||
|
if (Existing) {
|
||||||
|
if (MacroCmp (M, Existing) != 0) {
|
||||||
|
PPError (ERR_MACRO_REDEF);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user