X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Ferror.c;h=cba0a479e97ecb2dca7979037abf8696655a93c7;hb=73dfa23c987d8a7f1154801b85c171f9e01dcd58;hp=95db80a45b140e081be74082d8697d53f2034142;hpb=221ef5a9c20b89c26535c59612dbe6f4b515e856;p=cc65 diff --git a/src/cc65/error.c b/src/cc65/error.c index 95db80a45..cba0a479e 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -37,8 +37,13 @@ #include #include +/* common */ +#include "print.h" + +/* cc65 */ #include "global.h" #include "input.h" +#include "lineinfo.h" #include "scanner.h" #include "stmt.h" #include "error.h" @@ -46,86 +51,11 @@ /*****************************************************************************/ -/* 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; @@ -146,9 +76,7 @@ static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va vfprintf (stderr, Msg, ap); fprintf (stderr, "\n"); - if (Verbose) { - fprintf (stderr, "Line: %s\n", line); - } + Print (stderr, 1, "Line: %s\n", line); ++WarningCount; } } @@ -160,7 +88,7 @@ void Warning (const char* Format, ...) { va_list ap; va_start (ap, Format); - IntWarning (GetCurrentFile(), curpos, Format, ap); + IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap); va_end (ap); } @@ -184,9 +112,7 @@ static void IntError (const char* Filename, unsigned Line, const char* Msg, va_l 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"); @@ -195,23 +121,12 @@ static void IntError (const char* Filename, unsigned Line, const char* Msg, va_l -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); } @@ -233,28 +148,46 @@ void Fatal (const char* Format, ...) { va_list ap; - fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos); + 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: ", 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); } -void Internal (char* Format, ...) +void Internal (const char* Format, ...) /* Print a message about an internal compiler 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): Internal compiler error:\n", - GetCurrentFile(), curpos); + FileName, LineNum); va_start (ap, Format); vfprintf (stderr, Format, ap); @@ -263,14 +196,14 @@ void Internal (char* Format, ...) /* Use abort to create a core dump */ abort (); -} +} void ErrorReport (void) /* Report errors (called at end of compile) */ { - if (ErrorCount == 0 && Verbose) { + if (ErrorCount == 0 && Verbosity > 0) { printf ("No errors.\n"); } } @@ -278,3 +211,4 @@ void ErrorReport (void) +