1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-01 13:41:34 +00:00

Using tracked individual string buffers instead of a shared static string buffer for full type names.

This commit is contained in:
acqn 2020-08-02 21:51:32 +08:00 committed by Oliver Schmidt
parent 4ccf10f3fa
commit 52051f444e
5 changed files with 77 additions and 10 deletions

View File

@ -273,15 +273,12 @@ const char* GetBasicTypeName (const Type* T)
const char* GetFullTypeName (const Type* T)
/* Return the full name string of the given type.
** Note: This may use a static buffer that could be overwritten by other calls.
*/
/* Return the full name string of the given type */
{
static struct StrBuf Buf = STATIC_STRBUF_INITIALIZER;
SB_Clear (&Buf);
GetFullTypeNameBuf (&Buf, T);
struct StrBuf* Buf = NewDiagnosticStrBuf ();
GetFullTypeNameBuf (Buf, T);
return SB_GetConstBuf (&Buf);
return SB_GetConstBuf (Buf);
}

View File

@ -219,9 +219,7 @@ const char* GetBasicTypeName (const Type* T);
*/
const char* GetFullTypeName (const Type* T);
/* Return the full name string of the given type.
** Note: This may use a static buffer that could be overwritten by other calls.
*/
/* Return the full name string of the given type */
struct StrBuf* GetFullTypeNameBuf (struct StrBuf* S, const Type* T);
/* Return the full name string of the given type */

View File

@ -38,7 +38,9 @@
#include <stdarg.h>
/* common */
#include "coll.h"
#include "print.h"
#include "strbuf.h"
/* cc65 */
#include "global.h"
@ -92,6 +94,8 @@ static WarnMapEntry WarnMap[] = {
{ &WarnUnusedVar, "unused-var" },
};
Collection DiagnosticStrBufs;
/*****************************************************************************/
@ -323,3 +327,50 @@ void ErrorReport (void)
{
Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);
}
/*****************************************************************************/
/* Tracked StrBufs */
/*****************************************************************************/
void InitDiagnosticStrBufs (void)
/* Init tracking string buffers used for diagnostics */
{
InitCollection (&DiagnosticStrBufs);
}
void DoneDiagnosticStrBufs (void)
/* Done with tracked string buffers used for diagnostics */
{
ClearDiagnosticStrBufs ();
DoneCollection (&DiagnosticStrBufs);
}
void ClearDiagnosticStrBufs (void)
/* Free all tracked string buffers */
{
unsigned I;
for (I = 0; I < CollCount (&DiagnosticStrBufs); ++I) {
SB_Done (CollAtUnchecked (&DiagnosticStrBufs, I));
}
CollDeleteAll (&DiagnosticStrBufs);
}
struct StrBuf* NewDiagnosticStrBuf (void)
/* Get a new tracked string buffer */
{
StrBuf *Buf = NewStrBuf ();
CollAppend (&DiagnosticStrBufs, Buf);
return Buf;
}

View File

@ -72,6 +72,9 @@ extern IntStack WarnUnusedLabel; /* - unused labels */
extern IntStack WarnUnusedParam; /* - unused parameters */
extern IntStack WarnUnusedVar; /* - unused variables */
/* Forward */
struct StrBuf;
/*****************************************************************************/
@ -115,6 +118,18 @@ void ListWarnings (FILE* F);
void ErrorReport (void);
/* Report errors (called at end of compile) */
void InitDiagnosticStrBufs (void);
/* Init tracking string buffers used for diagnostics */
void DoneDiagnosticStrBufs (void);
/* Done with tracked string buffers used for diagnostics */
void ClearDiagnosticStrBufs (void);
/* Free all tracked string buffers */
struct StrBuf* NewDiagnosticStrBuf (void);
/* Get a new tracked string buffer */
/* End of error.h */

View File

@ -1060,6 +1060,9 @@ int main (int argc, char* argv[])
IS_Set (&Standard, STD_DEFAULT);
}
/* Track string buffer allocation */
InitDiagnosticStrBufs ();
/* Go! */
Compile (InputFile);
@ -1083,6 +1086,9 @@ int main (int argc, char* argv[])
CreateDependencies ();
}
/* Done with tracked string buffer allocation */
DoneDiagnosticStrBufs ();
/* Return an apropriate exit code */
return (ErrorCount > 0)? EXIT_FAILURE : EXIT_SUCCESS;
}