#include <stdlib.h>
#include <stdarg.h>
+/* common */
+#include "print.h"
+
+/* cc65 */
#include "global.h"
#include "input.h"
+#include "lineinfo.h"
#include "scanner.h"
#include "stmt.h"
#include "error.h"
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-/* Error messages sorted by ErrTypes */
-static char* ErrMsg [ERR_COUNT-1] = {
- "Syntax error",
- "`\"' expected",
- "`:' expected",
- "`;' expected",
- "`,' expected",
- "`(' expected",
- "`)' expected",
- "`[' expected",
- "`]' expected",
- "`{' expected",
- "`}' expected",
- "Identifier expected",
- "Type expected",
- "Incompatible types",
- "Incompatible pointer types",
- "Too many arguments in function call",
- "Too few arguments in function call",
- "Duplicate macro parameter: %s",
- "Variable identifier expected",
- "Integer expression expected",
- "Constant expression expected",
- "No active loop",
- "Redefinition of `%s'",
- "Conflicting types for `%s'",
- "String literal expected",
- "`while' expected",
- "Function must return a value",
- "Function cannot return a value",
- "Unexpected `continue'",
- "Undefined symbol: `%s'",
- "Undefined label: `%s'",
- "Too many local variables",
- "Too many initializers",
- "Cannot initialize incomplete type",
- "Cannot subscript",
- "Operation not allowed with this type of argument",
- "Struct expected",
- "Struct/union has no field named `%s'",
- "Struct pointer expected",
- "lvalue expected",
- "Expression expected",
- "Preprocessor expression expected",
- "Illegal type",
- "Illegal function call",
- "Illegal indirection",
- "Illegal address",
- "Illegal hex digit",
- "Illegal character constant",
- "Illegal modifier",
- "Illegal type qualifier",
- "Illegal storage class",
- "Illegal attribute",
- "Illegal segment name: `%s'",
- "Division by zero",
- "Modulo operation with zero",
- "Range error",
- "Symbol is already different kind",
- "Too many lexical levels",
- "Parameter name omitted",
- "Old style function decl used as prototype",
- "Declaration for parameter `%s' but no such parameter",
- "Cannot take address of a register variable",
- "Illegal size of data type",
- "__fastcall__ is not allowed for C functions",
- "Variable has unknown size",
- "Unknown identifier: `%s'",
- "Duplicate qualifier: `%s'",
- "Assignment to const",
- "Pointer types differ in type qualifiers",
-};
-
-
-
/* Count of errors/warnings */
unsigned ErrorCount = 0;
unsigned WarningCount = 0;
vfprintf (stderr, Msg, ap);
fprintf (stderr, "\n");
- if (Verbose) {
- fprintf (stderr, "Line: %s\n", line);
- }
+ Print (stderr, 1, "Line: %s\n", line);
++WarningCount;
}
}
{
va_list ap;
va_start (ap, Format);
- IntWarning (GetCurrentFile(), curpos, Format, ap);
+ IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
va_end (ap);
}
vfprintf (stderr, Msg, ap);
fprintf (stderr, "\n");
- if (Verbose) {
- fprintf (stderr, "Line: %s\n", line);
- }
+ Print (stderr, 1, "Line: %s\n", line);
++ErrorCount;
if (ErrorCount > 10) {
Fatal ("Too many errors");
-void Error (unsigned ErrNum, ...)
-/* Print an error message */
-{
- va_list ap;
- va_start (ap, ErrNum);
- IntError (GetCurrentFile(), curpos, ErrMsg [ErrNum-1], ap);
- va_end (ap);
-}
-
-
-
-void MError (const char* Format, ...)
+void Error (const char* Format, ...)
/* Print an error message */
{
va_list ap;
va_start (ap, Format);
- IntError (GetCurrentFile(), curpos, Format, ap);
+ IntError (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
va_end (ap);
}
/* Print a message about a fatal error and die */
{
va_list ap;
+
+ const char* FileName;
+ unsigned LineNum;
+ if (CurTok.LI) {
+ FileName = GetInputName (CurTok.LI);
+ LineNum = GetInputLine (CurTok.LI);
+ } else {
+ FileName = GetCurrentFile ();
+ LineNum = GetCurrentLine ();
+ }
- fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos);
+ fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
va_start (ap, Format);
vfprintf (stderr, Format, ap);
va_end (ap);
fprintf (stderr, "\n");
- if (Verbose) {
- fprintf (stderr, "Line: %s\n", line);
- }
+ Print (stderr, 1, "Line: %s\n", line);
exit (EXIT_FAILURE);
}
{
va_list ap;
+ const char* FileName;
+ unsigned LineNum;
+ if (CurTok.LI) {
+ FileName = GetInputName (CurTok.LI);
+ LineNum = GetInputLine (CurTok.LI);
+ } else {
+ FileName = GetCurrentFile ();
+ LineNum = GetCurrentLine ();
+ }
+
fprintf (stderr, "%s(%u): Internal compiler error:\n",
- GetCurrentFile(), curpos);
+ FileName, LineNum);
va_start (ap, Format);
vfprintf (stderr, Format, ap);
void ErrorReport (void)
/* Report errors (called at end of compile) */
{
- if (ErrorCount == 0 && Verbose) {
+ if (ErrorCount == 0 && Verbosity > 0) {
printf ("No errors.\n");
}
}
+