From 12dbe8b21daf907b558482821965642d0e1c7c2b Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Sat, 9 Jan 2021 15:31:59 -0300 Subject: [PATCH] Fix segfault --- compiler/compiler-scopes.c | 12 ++++++------ compiler/compiler-scopes.h | 1 - compiler/compiler-statements.c | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/compiler-scopes.c b/compiler/compiler-scopes.c index 863b492..ee8b96c 100644 --- a/compiler/compiler-scopes.c +++ b/compiler/compiler-scopes.c @@ -10,7 +10,7 @@ char* memsegnames[] = { "local", "static", "argument", "this" }; // Error messages void doubledeclaration(const char* name, DEBUGINFO* d1, DEBUGINFO* d2); -void ensurenoduplicate(SCOPE* s, char* name); +void ensurenoduplicate(SCOPE* s, DEBUGINFO* d, char* name); // Getters VAR* getvarinvars(VAR* vars, const char* name); @@ -48,18 +48,18 @@ void invalidparent(SUBROUTCALL* call) { exit(1); } -void ensurenoduplicate(SCOPE* s, char* name) { +void ensurenoduplicate(SCOPE* s, DEBUGINFO* d, char* name) { VAR* v = getvar(s, name); if(v != NULL) - doubledeclaration(name, s->currdebug, v->debug); + doubledeclaration(name, d, v->debug); CLASS* c = getclass(s, name); if(c != NULL) - doubledeclaration(name, s->currdebug, c->debug); + doubledeclaration(name, d, c->debug); SUBROUTDEC* sr = getsubroutdec(s, name); if(sr != NULL) - doubledeclaration(name, s->currdebug, sr->debug); + doubledeclaration(name, d, sr->debug); } // Scope handling @@ -215,7 +215,7 @@ VAR* mkvar(char* type, char* name, bool primitive, DEBUGINFO* debug, MEMSEGMENT } void addvar(SCOPE* s, VAR** dest, VAR* v) { - ensurenoduplicate(s, v->name); + ensurenoduplicate(s, v->debug, v->name); if(!v->primitive) { CLASS* type = getclass(s, v->type); diff --git a/compiler/compiler-scopes.h b/compiler/compiler-scopes.h index fa3055c..2eaa2bb 100644 --- a/compiler/compiler-scopes.h +++ b/compiler/compiler-scopes.h @@ -22,7 +22,6 @@ typedef struct var { typedef struct scope { struct compiler* compiler; - DEBUGINFO* currdebug; CLASS* currclass; CLASS* classes; diff --git a/compiler/compiler-statements.c b/compiler/compiler-statements.c index db2cc29..2f3ebe4 100644 --- a/compiler/compiler-statements.c +++ b/compiler/compiler-statements.c @@ -157,7 +157,6 @@ LINEBLOCK* compilelet(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 == returnstatement) return compileret(s, st); if(st->type == ifstatement) return compileif(s, st);