mirror of
https://github.com/cc65/cc65.git
synced 2025-01-26 02:30:17 +00:00
On errors and warnings, output additional information using extra line info
supplied using the .dbg statements. git-svn-id: svn://svn.cc65.org/cc65/trunk@4937 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
036282aced
commit
9023d0c6f2
120
src/ca65/error.c
120
src/ca65/error.c
@ -63,6 +63,87 @@ unsigned WarningCount = 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Helper functions */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void FormatVMsg (StrBuf* S, const FilePos* Pos, const char* Desc,
|
||||||
|
const char* Format, va_list ap)
|
||||||
|
/* Format an error/warning message into S. A trailing newline and a NUL
|
||||||
|
* terminator will be added to S.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Format the actual message */
|
||||||
|
StrBuf Msg = STATIC_STRBUF_INITIALIZER;
|
||||||
|
SB_VPrintf (&Msg, Format, ap);
|
||||||
|
SB_Terminate (&Msg);
|
||||||
|
|
||||||
|
/* Format the message header */
|
||||||
|
SB_Printf (S, "%s(%lu): %s: ",
|
||||||
|
SB_GetConstBuf (GetFileName (Pos->Name)),
|
||||||
|
Pos->Line,
|
||||||
|
Desc);
|
||||||
|
|
||||||
|
/* Append the message to the message header */
|
||||||
|
SB_Append (S, &Msg);
|
||||||
|
|
||||||
|
/* Delete the formatted message */
|
||||||
|
SB_Done (&Msg);
|
||||||
|
|
||||||
|
/* Add a new line and terminate the generated message */
|
||||||
|
SB_AppendChar (S, '\n');
|
||||||
|
SB_Terminate (S);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void FormatMsg (StrBuf* S, const FilePos* Pos, const char* Desc,
|
||||||
|
const char* Format, ...)
|
||||||
|
/* Format an error/warning message into S. A trailing newline and a NUL
|
||||||
|
* terminator will be added to S.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start (ap, Format);
|
||||||
|
FormatVMsg (S, Pos, Desc, Format, ap);
|
||||||
|
va_end (ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void AddNotifications (const Collection* LineInfos)
|
||||||
|
/* Output additional notifications for an error or warning */
|
||||||
|
{
|
||||||
|
StrBuf Msg = STATIC_STRBUF_INITIALIZER;
|
||||||
|
|
||||||
|
/* The basic line info is always in slot zero. It has been used to
|
||||||
|
* output the actual error or warning. The following slots may contain
|
||||||
|
* more information. Check them and additional notifications if they're
|
||||||
|
* present.
|
||||||
|
*/
|
||||||
|
unsigned I;
|
||||||
|
for (I = 1; I < CollCount (LineInfos); ++I) {
|
||||||
|
/* Get next line info */
|
||||||
|
const LineInfo* LI = CollConstAt (LineInfos, I);
|
||||||
|
/* Check the type and output an appropriate note */
|
||||||
|
unsigned Type = GetLineInfoType (LI);
|
||||||
|
if (Type == LI_TYPE_EXT) {
|
||||||
|
FormatMsg (&Msg, GetSourcePos (LI), "Note",
|
||||||
|
"Assembler code generated from this line");
|
||||||
|
fputs (SB_GetConstBuf (&Msg), stderr);
|
||||||
|
|
||||||
|
} else if (Type == LI_TYPE_MACRO) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SB_Done (&Msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Warnings */
|
/* Warnings */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@ -74,17 +155,12 @@ void WarningMsg (const FilePos* Pos, unsigned Level, const char* Format, va_list
|
|||||||
{
|
{
|
||||||
if (Level <= WarnLevel) {
|
if (Level <= WarnLevel) {
|
||||||
|
|
||||||
StrBuf S = STATIC_STRBUF_INITIALIZER;
|
StrBuf Msg = STATIC_STRBUF_INITIALIZER;
|
||||||
SB_VPrintf (&S, Format, ap);
|
FormatVMsg (&Msg, Pos, "Warning", Format, ap);
|
||||||
SB_Terminate (&S);
|
fputs (SB_GetConstBuf (&Msg), stderr);
|
||||||
|
SB_Done (&Msg);
|
||||||
|
|
||||||
fprintf (stderr, "%s(%lu): Warning: %s\n",
|
|
||||||
SB_GetConstBuf (GetFileName (Pos->Name)),
|
|
||||||
Pos->Line,
|
|
||||||
SB_GetConstBuf (&S));
|
|
||||||
++WarningCount;
|
++WarningCount;
|
||||||
|
|
||||||
SB_Done (&S);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +191,8 @@ void PWarning (const FilePos* Pos, unsigned Level, const char* Format, ...)
|
|||||||
void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format, ...)
|
void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format, ...)
|
||||||
/* Print warning message using the given line infos */
|
/* Print warning message using the given line infos */
|
||||||
{
|
{
|
||||||
|
if (Level <= WarnLevel) {
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
/* The first entry in the collection is that of the actual source pos */
|
/* The first entry in the collection is that of the actual source pos */
|
||||||
@ -122,8 +200,12 @@ void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format,
|
|||||||
|
|
||||||
/* Output a warning for this position */
|
/* Output a warning for this position */
|
||||||
va_start (ap, Format);
|
va_start (ap, Format);
|
||||||
WarningMsg (&LI->Pos, Level, Format, ap);
|
WarningMsg (GetSourcePos (LI), Level, Format, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
||||||
|
/* Add additional notifications if necessary */
|
||||||
|
AddNotifications (LineInfos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -137,17 +219,12 @@ void LIWarning (const Collection* LineInfos, unsigned Level, const char* Format,
|
|||||||
void ErrorMsg (const FilePos* Pos, const char* Format, va_list ap)
|
void ErrorMsg (const FilePos* Pos, const char* Format, va_list ap)
|
||||||
/* Print an error message */
|
/* Print an error message */
|
||||||
{
|
{
|
||||||
StrBuf S = STATIC_STRBUF_INITIALIZER;
|
StrBuf Msg = STATIC_STRBUF_INITIALIZER;
|
||||||
SB_VPrintf (&S, Format, ap);
|
FormatVMsg (&Msg, Pos, "Error", Format, ap);
|
||||||
SB_Terminate (&S);
|
fputs (SB_GetConstBuf (&Msg), stderr);
|
||||||
|
SB_Done (&Msg);
|
||||||
|
|
||||||
fprintf (stderr, "%s(%lu): Error: %s\n",
|
|
||||||
SB_GetConstBuf (GetFileName (Pos->Name)),
|
|
||||||
Pos->Line,
|
|
||||||
SB_GetConstBuf (&S));
|
|
||||||
++ErrorCount;
|
++ErrorCount;
|
||||||
|
|
||||||
SB_Done (&S);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -184,8 +261,11 @@ void LIError (const Collection* LineInfos, const char* Format, ...)
|
|||||||
|
|
||||||
/* Output an error for this position */
|
/* Output an error for this position */
|
||||||
va_start (ap, Format);
|
va_start (ap, Format);
|
||||||
ErrorMsg (&LI->Pos, Format, ap);
|
ErrorMsg (GetSourcePos (LI), Format, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
||||||
|
/* Add additional notifications if necessary */
|
||||||
|
AddNotifications (LineInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,15 +223,6 @@ void ClearLineInfo (unsigned Slot)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
LineInfo* GetLineInfo (unsigned Slot)
|
|
||||||
/* Get the line info from the given slot */
|
|
||||||
{
|
|
||||||
PRECONDITION (Slot < UsedSlots);
|
|
||||||
return CurLineInfo[Slot].Info;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GetFullLineInfo (Collection* LineInfos)
|
void GetFullLineInfo (Collection* LineInfos)
|
||||||
/* Return full line infos, that is line infos for all slots in LineInfos. The
|
/* Return full line infos, that is line infos for all slots in LineInfos. The
|
||||||
* function does also increase the usage counter for all line infos returned.
|
* function does also increase the usage counter for all line infos returned.
|
||||||
|
@ -65,8 +65,8 @@ enum {
|
|||||||
enum {
|
enum {
|
||||||
LI_MASK_COUNT = 0x00FF, /* Mask to extract the count */
|
LI_MASK_COUNT = 0x00FF, /* Mask to extract the count */
|
||||||
|
|
||||||
LI_TYPE_EXT = 0x0100, /* Externally supplied line info */
|
LI_TYPE_ASM = 0x0100, /* Normal assembler source */
|
||||||
LI_TYPE_ASM = 0x0200, /* Normal assembler source */
|
LI_TYPE_EXT = 0x0200, /* Externally supplied line info */
|
||||||
LI_TYPE_MACRO = 0x0300, /* Macro expansion */
|
LI_TYPE_MACRO = 0x0300, /* Macro expansion */
|
||||||
LI_MASK_TYPE = 0x7F00, /* Mask to extract the type */
|
LI_MASK_TYPE = 0x7F00, /* Mask to extract the type */
|
||||||
};
|
};
|
||||||
@ -107,9 +107,6 @@ void GenLineInfo (unsigned Slot, const FilePos* Pos);
|
|||||||
void ClearLineInfo (unsigned Slot);
|
void ClearLineInfo (unsigned Slot);
|
||||||
/* Clear the line info in the given slot */
|
/* Clear the line info in the given slot */
|
||||||
|
|
||||||
LineInfo* GetLineInfo (unsigned Slot);
|
|
||||||
/* Get the line info from the given slot */
|
|
||||||
|
|
||||||
void GetFullLineInfo (Collection* LineInfos);
|
void GetFullLineInfo (Collection* LineInfos);
|
||||||
/* Return full line infos, that is line infos for all slots in LineInfos. The
|
/* Return full line infos, that is line infos for all slots in LineInfos. The
|
||||||
* function does also increase the usage counter for all line infos returned.
|
* function does also increase the usage counter for all line infos returned.
|
||||||
@ -125,6 +122,26 @@ LineInfo* ReleaseLineInfo (LineInfo* LI);
|
|||||||
* function will gracefully accept NULL pointers and do nothing in this case.
|
* function will gracefully accept NULL pointers and do nothing in this case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE const FilePos* GetSourcePos (const LineInfo* LI)
|
||||||
|
/* Return the source file position from the given line info */
|
||||||
|
{
|
||||||
|
return &LI->Pos;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetSourcePos(LI) (&(LI)->Pos)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_INLINE)
|
||||||
|
INLINE unsigned GetLineInfoType (const LineInfo* LI)
|
||||||
|
/* Return the type of a line info */
|
||||||
|
{
|
||||||
|
return (LI->Type & LI_MASK_TYPE);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define GetLineInfoType(LI) ((LI)->Type & LI_MASK_TYPE)
|
||||||
|
#endif
|
||||||
|
|
||||||
void WriteLineInfo (const Collection* LineInfos);
|
void WriteLineInfo (const Collection* LineInfos);
|
||||||
/* Write a list of line infos to the object file. MakeLineInfoIndex has to
|
/* Write a list of line infos to the object file. MakeLineInfoIndex has to
|
||||||
* be called before!
|
* be called before!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user