MWCC/CError.c

320 lines
6.8 KiB
C
Raw Normal View History

2022-10-07 19:02:27 +00:00
#include "CError.h"
#include "CompilerTools.h"
// TODO MOVE ME
extern char *CMangler_GetOperator(StringNode *str);
extern jmp_buf errorreturn;
extern unsigned char cprep_nomem_exit;
extern unsigned char anyerrors;
extern unsigned char fatalerrors;
extern char string[256];
// TODO MOVE ME
Token *cerror_locktoken;
static Token *cerror_token;
static short cerror_errorcount;
static int cerror_lasterrorline;
// cerror_synchdata
// cerror_synchoffset
int CError_BreakPointcount;
void CError_Init() {
cerror_errorcount = 0;
cerror_lasterrorline = -1;
cerror_token = 0;
cerror_locktoken = 0;
}
void CError_SetErrorToken(Token *token) {
if (token && token->x4)
cerror_token = token;
}
void CError_SetNullErrorToken() {
cerror_token = (Token *) -1;
}
void CError_LockErrorPos(Token *token, Token **saved) {
*saved = cerror_locktoken;
if (token && token->x4)
cerror_locktoken = token;
}
void CError_UnlockErrorPos(Token **saved) {
cerror_locktoken = *saved;
}
void CError_ResetErrorSkip() {
cerror_lasterrorline = -1;
}
void CError_GetErrorString(char *buf, short code) {
// This feels dirty, surely this can't have been the solution...
int code_ = code;
#line 142
CError_ASSERT(code_ >= 100 && code_ < 393);
COS_GetString(buf, 10000, (short) (code_ - 99));
}
void CError_BufferInit(CErrorBuffer *eb, char *buf, long bufSize) {
eb->start = eb->end = buf;
eb->size = eb->remaining = bufSize - 1;
}
void CError_BufferGrow(CErrorBuffer *eb, long amount) {
char *newBuf;
newBuf = lalloc(eb->size + amount);
memcpy(newBuf, eb->start, eb->size);
eb->start = newBuf;
eb->end = newBuf + eb->size - eb->remaining;
eb->size += amount;
eb->remaining += amount;
}
void CError_BufferAppendChar(CErrorBuffer *eb, char ch) {
if (eb) {
if (!eb->remaining)
CError_BufferGrow(eb, 256);
*(eb->end++) = ch;
eb->remaining--;
}
}
void CError_BufferAppendString(CErrorBuffer *eb, const char *str) {
size_t len;
if (eb) {
len = strlen(str);
if (eb->remaining < len)
CError_BufferGrow(eb, len);
memcpy(eb->end, str, len);
eb->end += len;
eb->remaining -= len;
}
}
void CError_BufferTerminate(CErrorBuffer *eb) {
if (eb->remaining == 0)
CError_BufferGrow(eb, 1);
*eb->end = 0;
eb->remaining = 0;
}
void CError_BufferAppendQualifier(CErrorBuffer *eb, int quals) {
}
void CError_BufferAppendTemplArgExpr(CErrorBuffer *eb, void *targExpr) {
}
void CError_BufferAppendTemplArg(CErrorBuffer *eb, void *targ) {
}
void CError_BufferAppendTemplArgs(CErrorBuffer *eb, void *targs) {
}
void CError_BufferAppendNameSpace(CErrorBuffer *eb, void *ns) {
}
void CError_BufferAppendPType(CErrorBuffer *eb, void *ty) {
}
void CError_BufferAppendTemplDepType(CErrorBuffer *eb, void *ty) {
}
void CError_BufferAppendFuncArgs(CErrorBuffer *eb, void *args, unsigned char flag) {
}
void CError_BufferAppendType(CErrorBuffer *eb, void *ty, int quals) {
}
char *CError_GetTypeName(void *ty, int quals, unsigned char useGlobalHeap) {
CErrorBuffer eb;
char buf[256];
char *ptr;
CError_BufferInit(&eb, buf, sizeof(buf));
CError_BufferAppendType(&eb, ty, quals);
CError_BufferTerminate(&eb);
if (useGlobalHeap)
ptr = galloc(eb.size + 1);
else
ptr = lalloc(eb.size + 1);
return strcpy(ptr, eb.start);
}
void CError_AppendUnqualFunctionName(CErrorBuffer *eb, void *unk1, void *unk2, void *unk3) {
}
void CError_AppendFunctionName(CErrorBuffer *eb, void *unk1, void *unk2, void *unk3, void *unk4) {
}
void CError_AppendObjectName(CErrorBuffer *eb, void *obj) {
}
void CError_AppendMethodName(CErrorBuffer *eb, void *obj) {
}
char *CError_GetQualifiedName(void *ns, StringNode *name) {
CErrorBuffer eb;
char buf[256];
char *ptr;
CError_BufferInit(&eb, buf, sizeof(buf));
CError_BufferAppendNameSpace(&eb, ns);
CError_BufferAppendString(&eb, name->data);
CError_BufferTerminate(&eb);
ptr = lalloc(eb.size + 1);
return strcpy(ptr, eb.start);
}
char *CError_GetFunctionName(void *a, void *b, void *c) {
CErrorBuffer eb;
char buf[256];
char *ptr;
CError_BufferInit(&eb, buf, sizeof(buf));
CError_AppendFunctionName(&eb, a, b, 0, c);
CError_BufferTerminate(&eb);
ptr = lalloc(eb.size + 1);
return strcpy(ptr, eb.start);
}
char *CError_GetObjectName(void *obj) {
CErrorBuffer eb;
char buf[256];
char *ptr;
CError_BufferInit(&eb, buf, sizeof(buf));
CError_AppendObjectName(&eb, obj);
CError_BufferTerminate(&eb);
ptr = lalloc(eb.size + 1);
return strcpy(ptr, eb.start);
}
char *CError_GetNameString(void *obj, StringNode *operatorName) {
CErrorBuffer eb;
char buf[256];
char *ptr;
char *opStr;
CError_ASSERT(operatorName);
// TODO lolol
CError_BufferInit(&eb, buf, sizeof(buf));
CError_AppendObjectName(&eb, obj);
CError_BufferTerminate(&eb);
ptr = lalloc(eb.size + 1);
return strcpy(ptr, eb.start);
}
void CError_ErrorMessage(int errTable, char *buf, unsigned char flag1, unsigned char flag2) {
}
void CError_BufferAppendTemplateStack(CErrorBuffer *eb) {
}
void CError_ErrorMessageVA(short code, char *buf, va_list list, unsigned char flag1, unsigned char flag2) {
}
void CError_VAErrorMessage(short code, va_list list, unsigned char flag1, unsigned char flag2) {
char buf[256];
CError_GetErrorString(buf, code);
CError_ErrorMessageVA(code + 10000, buf, list, flag1, flag2);
}
void CError_Error(short code, ...) {
}
void CError_ErrorTerm(short code) {
CError_GetErrorString(string, code);
CError_ErrorMessage(code + 10000, string, 0, 0);
longjmp(errorreturn, 1);
}
void CError_ErrorSkip(short code, ...) {
// TODO trychain, tk
}
void CError_ErrorFuncCall(short code, void *aa, void *bb) {
}
void CError_OverloadedFunctionError2(void *aa, void *bb, void *cc) {
}
void CError_OverloadedFunctionError(void *aa, void *bb) {
}
void CError_AbstractClassError() {
// TODO CClass
}
void CError_Warning(short code, ...) {
// TODO lol
}
void CError_BreakPoint(const char *a, const char *b) {
if (!a || !strcmp(a, b))
CError_BreakPointcount++;
}
void CError_Internal(char *filename, int line) {
char tmp[128];
CompilerGetCString(5, tmp);
sprintf(string, tmp, filename, line);
CError_ErrorMessage(10001, string, 1, 0);
longjmp(errorreturn, 1);
CError_BreakPoint(0, 0);
}
void CError_ExpressionTooComplex() {
CompilerGetCString(6, string);
CError_ErrorMessage(10002, string, 1, 0);
longjmp(errorreturn, 1);
}
void CError_NoMem() {
cprep_nomem_exit = 1;
longjmp(errorreturn, 1);
}
void CError_UserBreak() {
CompilerGetCString(8, string);
longjmp(errorreturn, 1);
}
void CError_CannotOpen() {
// TODO
}
void CError_QualifierCheck(int quals) {
}