summaryrefslogtreecommitdiff
path: root/CError.c
blob: 51794639e303b6bc35e1b9f0ba7bfb55e4134cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#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) {

}