#include <string.h>
#include <stdlib.h>
#include <errno.h>
-#include <ctype.h>
-#include "../common/xmalloc.h"
+/* common */
+#include "chartype.h"
+#include "print.h"
+#include "xmalloc.h"
+/* cc65 */
#include "codegen.h"
#include "error.h"
#include "expr.h"
while (CurC != '*' || NextC != '/') {
if (CurC == '\0') {
if (NextLine () == 0) {
- PPError (ERR_EOF_IN_COMMENT, StartingLine);
+ PPError ("End-of-file reached in comment starting at line %u",
+ StartingLine);
return;
}
} else {
if (CurC == '/' && NextC == '*') {
- PPWarning (WARN_NESTED_COMMENT);
+ PPWarning ("`/*' found inside a comment");
}
NextChar ();
}
/* Get macro symbol name. If error, print message and clear line. */
{
if (IsSym (Ident) == 0) {
- PPError (ERR_IDENT_EXPECTED);
+ PPError ("Identifier expected");
ClearLine ();
return 0;
} else {
keepch ('#');
keepstr (Ident);
}
- } else if (IsQuoteChar (CurC)) {
+ } else if (IsQuote (CurC)) {
mptr = CopyQuotedString (mptr);
} else {
*mptr++ = CurC;
/* Expect an argument list */
SkipBlank ();
if (CurC != '(') {
- PPError (ERR_ILLEGAL_MACRO_CALL);
+ PPError ("Illegal macro call");
return 0;
}
*B++ = CurC;
NextChar ();
++ParCount;
- } else if (IsQuoteChar (CurC)) {
+ } else if (IsQuote (CurC)) {
B = CopyQuotedString (B);
} else if (CurC == ',' || CurC == ')') {
if (ParCount == 0) {
/* Compare formal argument count with actual */
if (M->ArgCount != ArgCount) {
- PPError (ERR_MACRO_ARGCOUNT);
+ PPError ("Macro argument count mismatch");
/* Be sure to make enough empty arguments available */
while (ArgCount < M->ArgCount) {
M->ActualArgs [ArgCount++] = "";
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);
/* Check for a right paren and eat it if we find one */
if (CurC != ')') {
- PPError (ERR_RPAREN_EXPECTED);
+ PPError ("`)' expected");
ClearLine ();
return;
}
/* 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 ("Macro redefinition is not identical");
+ }
+ }
}
SkipBlank();
}
if (!IsIdent (CurC)) {
- PPError (ERR_IDENT_EXPECTED);
+ PPError ("Identifier expected");
*mptr++ = '0';
} else {
SymName (Ident);
if (HaveParen) {
SkipBlank();
if (CurC != ')') {
- PPError (ERR_RPAREN_EXPECTED);
+ PPError ("`)' expected");
} else {
NextChar ();
}
}
keepstr (Ident);
}
- } else if (IsQuoteChar (CurC)) {
+ } else if (IsQuote (CurC)) {
mptr = CopyQuotedString (mptr);
} else if (CurC == '/' && NextC == '*') {
keepch (' ');
} else {
keepstr (Ident);
}
- } else if (IsQuoteChar(CurC)) {
+ } else if (IsQuote (CurC)) {
mptr = CopyQuotedString (mptr);
} else {
*mptr++ = CurC;
break;
default:
- PPError (ERR_INCLUDE_LTERM_EXPECTED);
+ PPError ("`\"' or `<' expected");
goto Done;
}
NextChar ();
/* Check if we got a terminator */
if (CurC != RTerm) {
/* No terminator found */
- PPError (ERR_INCLUDE_RTERM_EXPECTED);
+ PPError ("Missing terminator or file name too long");
goto Done;
}
{
SkipBlank ();
if (CurC == '\0') {
- PPError (ERR_INVALID_USER_ERROR);
+ PPError ("Invalid #error directive");
} else {
- PPError (ERR_USER_ERROR, lptr);
+ PPError ("#error: %s", lptr);
}
/* clear rest of line */
continue;
}
if (!IsSym (Directive)) {
- PPError (ERR_CPP_DIRECTIVE_EXPECTED);
+ PPError ("Preprocessor directive expected");
ClearLine ();
} else {
switch (searchtok (Directive, pre_toks)) {
}
s_ifdef[i_ifdef] ^= 2;
} else {
- PPError (ERR_UNEXPECTED_CPP_ELSE);
+ PPError ("Unexpected `#else'");
}
break;
if (i_ifdef >= 0) {
Skip = s_ifdef[i_ifdef--] & 1;
} else {
- PPError (ERR_UNEXPECTED_CPP_ENDIF);
+ PPError ("Unexpected `#endif'");
}
break;
case PP_LINE:
/* Not allowed in strict ANSI mode */
if (ANSI) {
- PPError (ERR_CPP_DIRECTIVE_EXPECTED);
+ PPError ("Preprocessor directive expected");
ClearLine ();
}
break;
break;
default:
- PPError (ERR_CPP_DIRECTIVE_EXPECTED);
+ PPError ("Preprocessor directive expected");
ClearLine ();
}
}
}
if (NextLine () == 0) {
if (i_ifdef >= 0) {
- PPError (ERR_CPP_ENDIF_EXPECTED);
+ PPError ("`#endif' expected");
}
return;
}
Done:
xlateline ();
- if (Verbose > 1) {
- printf ("line: %s\n", line);
- }
+ Print (stdout, 2, "line: %s\n", line);
}