mirror of
https://github.com/cc65/cc65.git
synced 2025-01-27 09:33:42 +00:00
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:
parent
1174e5dbe3
commit
04c9e1e3c7
@ -94,6 +94,7 @@ static char* ErrMsg [ERR_COUNT-1] = {
|
||||
"Too few arguments in function call",
|
||||
"Macro argument count mismatch",
|
||||
"Duplicate macro parameter: %s",
|
||||
"Macro redefinition is not identical",
|
||||
"Variable identifier expected",
|
||||
"Integer expression expected",
|
||||
"Constant expression expected",
|
||||
|
@ -70,7 +70,7 @@ enum Warnings {
|
||||
};
|
||||
|
||||
/* Error numbers */
|
||||
enum Errors {
|
||||
enum Errors {
|
||||
ERR_NONE, /* No error */
|
||||
ERR_INVALID_CHAR,
|
||||
ERR_UNEXPECTED_NEWLINE,
|
||||
@ -94,6 +94,7 @@ enum Errors {
|
||||
ERR_TOO_FEW_FUNC_ARGS,
|
||||
ERR_MACRO_ARGCOUNT,
|
||||
ERR_DUPLICATE_MACRO_ARG,
|
||||
ERR_MACRO_REDEF,
|
||||
ERR_VAR_IDENT_EXPECTED,
|
||||
ERR_INT_EXPR_EXPECTED,
|
||||
ERR_CONST_EXPR_EXPECTED,
|
||||
|
@ -36,9 +36,11 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../common/hashstr.h"
|
||||
#include "../common/xmalloc.h"
|
||||
|
||||
/* common */
|
||||
#include "hashstr.h"
|
||||
#include "xmalloc.h"
|
||||
|
||||
/* cc65 */
|
||||
#include "error.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)
|
||||
/* 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);
|
||||
/* 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);
|
||||
/* Print macro statistics to the given text file. */
|
||||
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "attrib.h"
|
||||
#include "check.h"
|
||||
#include "xmalloc.h"
|
||||
#include "xsprintf.h"
|
||||
|
||||
/* cc65 */
|
||||
#include "asmlabel.h"
|
||||
|
@ -355,6 +355,7 @@ static void addmac (void)
|
||||
ident Ident;
|
||||
char Buf[LINESIZE];
|
||||
Macro* M;
|
||||
Macro* Existing;
|
||||
|
||||
/* Read the macro name */
|
||||
SkipBlank ();
|
||||
@ -362,6 +363,9 @@ static void addmac (void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get an existing macro definition with this name */
|
||||
Existing = FindMacro (Ident);
|
||||
|
||||
/* Create a new macro definition */
|
||||
M = NewMacro (Ident);
|
||||
|
||||
@ -411,6 +415,15 @@ static void addmac (void)
|
||||
|
||||
/* Create a copy of the replacement */
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user