Fix segfault

This commit is contained in:
Augusto Gunsch 2021-01-09 15:31:59 -03:00
parent f674577437
commit 0339c25877
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
3 changed files with 6 additions and 8 deletions

View File

@ -11,7 +11,7 @@ char* memsegnames[] = { "local", "static", "argument", "this" };
// Error messages // Error messages
void doubledeclaration(const char* name, DEBUGINFO* d1, DEBUGINFO* d2); void doubledeclaration(const char* name, DEBUGINFO* d1, DEBUGINFO* d2);
void ensurenoduplicate(SCOPE* s, char* name); void ensurenoduplicate(SCOPE* s, DEBUGINFO* d, char* name);
// Getters // Getters
VAR* getvarinvars(VAR* vars, const char* name); VAR* getvarinvars(VAR* vars, const char* name);
@ -49,18 +49,18 @@ void invalidparent(SUBROUTCALL* call) {
exit(1); exit(1);
} }
void ensurenoduplicate(SCOPE* s, char* name) { void ensurenoduplicate(SCOPE* s, DEBUGINFO* d, char* name) {
VAR* v = getvar(s, name); VAR* v = getvar(s, name);
if(v != NULL) if(v != NULL)
doubledeclaration(name, s->currdebug, v->debug); doubledeclaration(name, d, v->debug);
CLASS* c = getclass(s, name); CLASS* c = getclass(s, name);
if(c != NULL) if(c != NULL)
doubledeclaration(name, s->currdebug, c->debug); doubledeclaration(name, d, c->debug);
SUBROUTDEC* sr = getsubroutdec(s, name); SUBROUTDEC* sr = getsubroutdec(s, name);
if(sr != NULL) if(sr != NULL)
doubledeclaration(name, s->currdebug, sr->debug); doubledeclaration(name, d, sr->debug);
} }
// Scope handling // Scope handling
@ -220,7 +220,7 @@ VAR* mkvar(char* type, char* name, bool primitive, DEBUGINFO* debug, MEMSEGMENT
} }
void addvar(SCOPE* s, VAR** dest, VAR* v) { void addvar(SCOPE* s, VAR** dest, VAR* v) {
ensurenoduplicate(s, v->name); ensurenoduplicate(s, v->debug, v->name);
if(!v->primitive) { if(!v->primitive) {
CLASS* type = getclass(s, v->type); CLASS* type = getclass(s, v->type);

View File

@ -22,7 +22,6 @@ typedef struct var {
typedef struct scope { typedef struct scope {
struct compiler* compiler; struct compiler* compiler;
DEBUGINFO* currdebug;
CLASS* currclass; CLASS* currclass;
CLASS* classes; CLASS* classes;

View File

@ -157,7 +157,6 @@ LINEBLOCK* compilelet(SCOPE* s, STATEMENT* st) {
} }
LINEBLOCK* compilestatement(SCOPE* s, STATEMENT* st) { LINEBLOCK* compilestatement(SCOPE* s, STATEMENT* st) {
s->currdebug = st->debug;
if(st->type == dostatement) return compilesubroutcall(s, st->dostatement); if(st->type == dostatement) return compilesubroutcall(s, st->dostatement);
if(st->type == returnstatement) return compileret(s, st); if(st->type == returnstatement) return compileret(s, st);
if(st->type == ifstatement) return compileif(s, st); if(st->type == ifstatement) return compileif(s, st);