Fix scope bugs

This commit is contained in:
Augusto Gunsch 2020-12-21 16:49:37 -03:00
parent cbf7879794
commit c3df97b04b
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
5 changed files with 36 additions and 15 deletions

View File

@ -274,53 +274,65 @@ OBJ* getbynamelist(SCOPE* s, STRINGLIST* names, char** retname) {
// Scope adding
void addclassvardec(SCOPE* s, CLASSVARDEC* v) {
ensurenoduplicates(s, v->base->names, v->base->debug);
v->next = s->classvardecs;
s->classvardecs = v;
CLASSVARDEC* new = copy(v, sizeof(CLASSVARDEC));
new->next = s->classvardecs;
s->classvardecs = new;
}
void addvardec(SCOPE* s, VARDEC* v) {
ensurenoduplicates(s, v->names, v->debug);
v->next = s->vardecs;
s->vardecs = v;
VARDEC* new = copy(v, sizeof(VARDEC));
new->next = s->vardecs;
s->vardecs = new;
}
void addsubdec(SCOPE* s, SUBDEC* sd) {
ensurenoduplicate(s, sd->name, sd->debug);
sd->next = s->subroutines;
s->subroutines = sd;
SUBDEC* new = copy(sd, sizeof(SUBDEC));
new->next = s->subroutines;
s->subroutines = new;
}
void addclass(SCOPE* s, CLASS* c) {
ensurenoduplicate(s, c->name, c->debug);
c->next = s->classes;
s->classes = c;
CLASS* new = copy(c, sizeof(CLASS));
new->next = s->classes;
s->classes = new;
}
// Group adding
void addclassvardecs(SCOPE* s, CLASSVARDEC* vs) {
CLASSVARDEC* next;
while(vs != NULL) {
next = vs->next;
addclassvardec(s, vs);
vs = vs->next;
vs = next;
}
}
void addvardecs(SCOPE* s, VARDEC* vs) {
VARDEC* next;
while(vs != NULL) {
next = vs->next;
addvardec(s, vs);
vs = vs->next;
vs = next;
}
}
void addsubdecs(SCOPE* s, SUBDEC* ss) {
SUBDEC* next;
while(ss != NULL) {
next = ss->next;
addsubdec(s, ss);
ss = ss->next;
ss = next;
}
}
void addclasses(SCOPE* s, CLASS* c) {
CLASS* next;
while(c != NULL) {
next = c->next;
addclass(s, c);
c = c->next;
c = next;
}
}

View File

@ -127,7 +127,7 @@ LINEBLOCK* compilecallln(CLASS* c, SUBROUTCALL* call) {
// temporary ignore list for OS functions
char* ignoresubdecs[] = {
"printInt", "void"
"printInt", "void", "peek", "int"
};
int ignorecount = sizeof(ignoresubdecs) / sizeof(char*);

View File

@ -106,6 +106,7 @@ TERM* parsetermnullified(PARSER* p) {
t->type = unaryopterm;
next(p);
t->expression = parseterm(p);
t->expression->next = NULL;
} else if(!strcmp(p->current->token, "(")) {
next(p);
t->type = innerexpression;
@ -148,7 +149,7 @@ TERM* parseexpressionnullified(PARSER* p) {
while(isop(p->current)) {
current->op = p->current->token[0];
next(p);
nextt = parsetermnullified(p);
nextt = parseterm(p);
current->next = nextt;
current = nextt;
}
@ -466,6 +467,7 @@ PARAMETER* parseparameters(PARSER* p) {
PARAMETER* head = parseparameter(p);
PARAMETER* current = head;
while(!strcmp(p->current->token, ",")) {
next(p);
current->next = parseparameter(p);
current = current->next;
}
@ -518,7 +520,7 @@ SUBDEC* parsesubroutdec(PARSER* p) {
SUBDEC* parsesubroutdecs(PARSER* p) {
SUBDEC* head = parsesubroutdec(p);
SUBDEC* current= head;
SUBDEC* current = head;
SUBDEC* next;
while(next = parsesubroutdec(p), next != NULL) {
current->next = next;

6
util.c
View File

@ -13,6 +13,12 @@ char* ezheapstr(char* str) {
return heapstr(str, strlen(str));
}
void* copy(void* v, int sz) {
void* copy = malloc(sz);
memcpy(copy, v, sz);
return copy;
}
int countplaces(int n) {
int places = 1;
int divisor = 1;

1
util.h
View File

@ -14,6 +14,7 @@ char* heapstr(char* str, int len);
char* ezheapstr(char* str);
int countplaces(int n);
char* itoa(int i);
void* copy(void* v, int sz);
void printstrlist(STRINGLIST* strlist, FILE* stream);
void freestrlist(STRINGLIST* strlist);