"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",
};
/* Error numbers */
-enum Errors {
+enum Errors {
ERR_NONE, /* No error */
ERR_INVALID_CHAR,
ERR_UNEXPECTED_NEWLINE,
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,
#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"
+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. */
{
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. */
#include "attrib.h"
#include "check.h"
#include "xmalloc.h"
+#include "xsprintf.h"
/* cc65 */
#include "asmlabel.h"
ident Ident;
char Buf[LINESIZE];
Macro* M;
+ Macro* Existing;
/* Read the macro name */
SkipBlank ();
return;
}
+ /* Get an existing macro definition with this name */
+ Existing = FindMacro (Ident);
+
/* Create a new macro definition */
M = NewMacro (Ident);
/* 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);
+ }
+ }
}