diff --git a/src/cc65/error.c b/src/cc65/error.c index f0e023969..e99465c87 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -108,6 +108,36 @@ Collection DiagnosticStrBufs; +/*****************************************************************************/ +/* Helpers */ +/*****************************************************************************/ + + + +static const char* GetDiagnosticFileName (void) +/* Get the source file name where the diagnostic info refers to */ +{ + if (CurTok.LI) { + return GetInputName (CurTok.LI); + } else { + return GetCurrentFile (); + } +} + + + +static unsigned GetDiagnosticLineNum (void) +/* Get the source line number where the diagnostic info refers to */ +{ + if (CurTok.LI) { + return GetInputLine (CurTok.LI); + } else { + return GetCurrentLine (); + } +} + + + /*****************************************************************************/ /* Handling of fatal errors */ /*****************************************************************************/ @@ -119,17 +149,7 @@ void Fatal (const char* Format, ...) { 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: ", FileName, LineNum); + fprintf (stderr, "%s:%u: Fatal: ", GetDiagnosticFileName (), GetDiagnosticLineNum ()); va_start (ap, Format); vfprintf (stderr, Format, ap); @@ -145,22 +165,12 @@ void Fatal (const char* Format, ...) void Internal (const char* Format, ...) -/* Print a message about an internal compiler error and die. */ +/* 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", - FileName, LineNum); + GetDiagnosticFileName (), GetDiagnosticLineNum ()); va_start (ap, Format); vfprintf (stderr, Format, ap); @@ -184,7 +194,7 @@ void Internal (const char* Format, ...) static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va_list ap) -/* Print an error message - internal function*/ +/* Print an error message - internal function */ { fprintf (stderr, "%s:%u: Error: ", Filename, LineNo); vfprintf (stderr, Msg, ap); @@ -206,7 +216,7 @@ void Error (const char* Format, ...) { va_list ap; va_start (ap, Format); - IntError (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap); + IntError (GetDiagnosticFileName (), GetDiagnosticLineNum (), Format, ap); va_end (ap); } @@ -224,7 +234,7 @@ void LIError (const LineInfo* LI, const char* Format, ...) void PPError (const char* Format, ...) -/* Print an error message. For use within the preprocessor. */ +/* Print an error message. For use within the preprocessor */ { va_list ap; va_start (ap, Format); @@ -241,7 +251,7 @@ void PPError (const char* Format, ...) static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg, va_list ap) -/* Print warning message - internal function. */ +/* Print a warning message - internal function */ { if (IS_Get (&WarningsAreErrors)) { @@ -265,11 +275,11 @@ static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg, void Warning (const char* Format, ...) -/* Print warning message. */ +/* Print a warning message */ { va_list ap; va_start (ap, Format); - IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap); + IntWarning (GetDiagnosticFileName (), GetDiagnosticLineNum (), Format, ap); va_end (ap); } @@ -287,7 +297,7 @@ void LIWarning (const LineInfo* LI, const char* Format, ...) void PPWarning (const char* Format, ...) -/* Print warning message. For use within the preprocessor. */ +/* Print a warning message. For use within the preprocessor */ { va_list ap; va_start (ap, Format); @@ -326,6 +336,55 @@ void ListWarnings (FILE* F) +/*****************************************************************************/ +/* Handling of other infos */ +/*****************************************************************************/ + + + +static void IntNote (const char* Filename, unsigned LineNo, const char* Msg, va_list ap) +/* Print a note message - internal function */ +{ + fprintf (stderr, "%s:%u: Note: ", Filename, LineNo); + vfprintf (stderr, Msg, ap); + fprintf (stderr, "\n"); +} + + + +void Note (const char* Format, ...) +/* Print a note message */ +{ + va_list ap; + va_start (ap, Format); + IntNote (GetDiagnosticFileName (), GetDiagnosticLineNum (), Format, ap); + va_end (ap); +} + + + +void LINote (const LineInfo* LI, const char* Format, ...) +/* Print a note message with the line info given explicitly */ +{ + va_list ap; + va_start (ap, Format); + IntNote (GetInputName (LI), GetInputLine (LI), Format, ap); + va_end (ap); +} + + + +void PPNote (const char* Format, ...) +/* Print a note message. For use within the preprocessor */ +{ + va_list ap; + va_start (ap, Format); + IntNote (GetCurrentFile(), GetCurrentLine(), Format, ap); + va_end (ap); +} + + + /*****************************************************************************/ /* Code */ /*****************************************************************************/ diff --git a/src/cc65/error.h b/src/cc65/error.h index c4420c434..7fcb03467 100644 --- a/src/cc65/error.h +++ b/src/cc65/error.h @@ -92,7 +92,7 @@ void Fatal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2) /* Print a message about a fatal error and die */ void Internal (const char* Format, ...) attribute ((noreturn, format (printf, 1, 2))); -/* Print a message about an internal compiler error and die. */ +/* Print a message about an internal compiler error and die */ void Error (const char* Format, ...) attribute ((format (printf, 1, 2))); /* Print an error message */ @@ -101,16 +101,16 @@ void LIError (const LineInfo* LI, const char* Format, ...) attribute ((format (p /* Print an error message with the line info given explicitly */ void PPError (const char* Format, ...) attribute ((format (printf, 1, 2))); -/* Print an error message. For use within the preprocessor. */ +/* Print an error message. For use within the preprocessor */ void Warning (const char* Format, ...) attribute ((format (printf, 1, 2))); -/* Print warning message. */ +/* Print a warning message */ void LIWarning (const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 2, 3))); /* Print a warning message with the line info given explicitly */ void PPWarning (const char* Format, ...) attribute ((format (printf, 1, 2))); -/* Print warning message. For use within the preprocessor. */ +/* Print a warning message. For use within the preprocessor */ IntStack* FindWarning (const char* Name); /* Search for a warning in the WarnMap table and return a pointer to the @@ -120,6 +120,15 @@ IntStack* FindWarning (const char* Name); void ListWarnings (FILE* F); /* Print a list of warning types/names to the given file */ +void Note (const char* Format, ...) attribute ((format (printf, 1, 2))); +/* Print a note message */ + +void LINote (const LineInfo* LI, const char* Format, ...) attribute ((format (printf, 2, 3))); +/* Print a note message with the line info given explicitly */ + +void PPNote (const char* Format, ...) attribute ((format (printf, 1, 2))); +/* Print a note message. For use within the preprocessor */ + void ErrorReport (void); /* Report errors (called at end of compile) */ diff --git a/src/cc65/global.c b/src/cc65/global.c index 8b9838dc5..b2c3ef0a0 100644 --- a/src/cc65/global.c +++ b/src/cc65/global.c @@ -49,6 +49,7 @@ unsigned char DebugInfo = 0; /* Add debug info to the obj */ unsigned char PreprocessOnly = 0; /* Just preprocess the input */ unsigned char DebugOptOutput = 0; /* Output debug stuff */ unsigned RegisterSpace = 6; /* Space available for register vars */ +unsigned AllowNewComments = 0; /* Allow new style comments in C89 mode */ /* Stackable options */ IntStack WritableStrings = INTSTACK(0); /* Literal strings are r/w */ diff --git a/src/cc65/global.h b/src/cc65/global.h index 266035346..ba7105130 100644 --- a/src/cc65/global.h +++ b/src/cc65/global.h @@ -57,6 +57,7 @@ extern unsigned char DebugInfo; /* Add debug info to the obj */ extern unsigned char PreprocessOnly; /* Just preprocess the input */ extern unsigned char DebugOptOutput; /* Output debug stuff */ extern unsigned RegisterSpace; /* Space available for register vars */ +extern unsigned AllowNewComments; /* Allow new style comments in C89 mode */ /* Stackable options */ extern IntStack WritableStrings; /* Literal strings are r/w */ diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index b0478ce2a..83ed362c8 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -784,7 +784,7 @@ static void IntPragma (StrBuf* B, IntStack* Stack, long Low, long High) static void MakeMessage (const char* Message) { - fprintf (stderr, "%s:%u: Note: %s\n", GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Message); + Note ("%s", Message); } diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index 99a8af116..b920f644a 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -916,8 +916,10 @@ static void NewStyleComment (void) /* Remove a new style C comment from line. */ { /* Diagnose if this is unsupported */ - if (IS_Get (&Standard) < STD_C99) { + if (IS_Get (&Standard) < STD_C99 && !AllowNewComments) { PPError ("C++ style comments are not allowed in C89"); + PPNote ("(this will be reported only once per input file)"); + AllowNewComments = 1; } /* Beware: Because line continuation chars are handled when reading @@ -3246,6 +3248,9 @@ void PreprocessBegin (void) /* Remember to update source file location in preprocess-only mode */ FileChanged = 1; + + /* Enable diagnostics on new style comments in C89 mode */ + AllowNewComments = 0; } diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 4d293ac3c..e5741ea1d 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -707,6 +707,7 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags if (SCType == SC_TYPEDEF) { if (IsDistinctRedef (E_Type, T, TC_IDENTICAL, TCF_MASK_QUAL)) { Error ("Conflicting types for typedef '%s'", Entry->Name); + Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type)); Entry = 0; } } else { @@ -733,7 +734,7 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags /* New type must be compatible with the composite prototype */ if (IsDistinctRedef (E_Type, T, TC_EQUAL, TCF_MASK_QUAL)) { Error ("Conflicting function types for '%s'", Entry->Name); - TypeCompatibilityDiagnostic (T, E_Type, 0, "'%s' vs '%s'"); + Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type)); Entry = 0; } else { /* Refine the existing composite prototype with this new @@ -765,6 +766,7 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags IsDistinctRedef (E_Type + 1, T + 1, TC_IDENTICAL, TCF_MASK_QUAL)) { /* Conflicting element types */ Error ("Conflicting array types for '%s[]'", Entry->Name); + Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type)); Entry = 0; } else { /* Check if we have a size in the existing definition */ @@ -782,6 +784,7 @@ static int HandleSymRedefinition (SymEntry* Entry, const Type* T, unsigned Flags Entry = 0; } else if (IsDistinctRedef (E_Type, T, TC_EQUAL, TCF_MASK_QUAL)) { Error ("Conflicting types for '%s'", Entry->Name); + Note ("'%s' vs '%s'", GetFullTypeName (T), GetFullTypeName (E_Type)); Entry = 0; } else if (E_SCType == SC_ENUMERATOR) { /* Enumerators aren't allowed to be redeclared at all, even if