diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index 15f5f06c..82bf94e4 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -1754,218 +1754,182 @@ static void insert_docstring_separator(void) */ static void declstructvar(char *firstname,int fpublic, pstruct_t *pstruct) { - char name[sNAMEMAX+1]; - int tok,i; - cell val; - char *str; - int cur_litidx = 0; - cell *values, *found; - int usage; - symbol *mysym,*sym; + char name[sNAMEMAX+1]; + int tok,i; + cell val; + char *str; + int cur_litidx = 0; + cell *values, *found; + int usage; + symbol *mysym,*sym; - strcpy(name, firstname); + strcpy(name, firstname); - values = (cell *)malloc(pstruct->argcount * sizeof(cell)); - found = (cell *)malloc(pstruct->argcount * sizeof(cell)); - - memset(found, 0, sizeof(cell) * pstruct->argcount); + values = (cell *)malloc(pstruct->argcount * sizeof(cell)); + found = (cell *)malloc(pstruct->argcount * sizeof(cell)); + + memset(found, 0, sizeof(cell) * pstruct->argcount); - //:TODO: Make this work with stock + //:TODO: Make this work with stock - /** - * Lastly, very lastly, we will insert a copy of this variable. - * This is soley to expose the pubvar. - */ - usage = uREAD|uCONST|uSTRUCT; - if (fpublic) - { - usage |= uPUBLIC; - } - mysym = NULL; - for (sym=glbtab.next; sym!=NULL; sym=sym->next) - { - if (strcmp(name, sym->name) == 0) - { - if ((sym->usage & uSTRUCT) && sym->vclass == sGLOBAL) - { - if (sym->usage & uDEFINE) - { - error(21, name); - } else { - if (sym->usage & uPUBLIC && !fpublic) - { - error(42); - } - } - } else { - error(21, name); - } - mysym = sym; - break; - } - } - if (!mysym) - { - mysym=addsym(name, 0, iVARIABLE, sGLOBAL, pc_addtag(pstruct->name), usage); - } + /** + * Lastly, very lastly, we will insert a copy of this variable. + * This is soley to expose the pubvar. + */ + usage = uREAD|uCONST|uSTRUCT; + if (fpublic) + usage |= uPUBLIC; + mysym = NULL; + for (sym=glbtab.next; sym!=NULL; sym=sym->next) { + if (strcmp(name, sym->name) == 0) { + if ((sym->usage & uSTRUCT) && sym->vclass == sGLOBAL) { + if (sym->usage & uDEFINE) { + error(21, name); + } else { + if (sym->usage & uPUBLIC && !fpublic) + error(42); + } + } else { + error(21, name); + } + mysym = sym; + break; + } + } + if (!mysym) + mysym=addsym(name, 0, iVARIABLE, sGLOBAL, pc_addtag(pstruct->name), usage); - if (!matchtoken('=')) - { - matchtoken(';'); - /* Mark it as undefined instead */ - mysym->usage = uSTOCK|uSTRUCT; - free(found); - free(values); - return; - } else { - mysym->usage = usage; - } - needtoken('{'); - do - { - structarg_t *arg; - /* Detect early exit */ - if (matchtoken('}')) - { - lexpush(); - break; - } - tok=lex(&val,&str); - if (tok != tSYMBOL) - { - error(1, "-identifier-", str); - continue; - } - arg=pstructs_getarg(pstruct,str); - if (arg == NULL) - { - error(96, str, sym->name); - } - needtoken('='); - cur_litidx = litidx; - tok=lex(&val,&str); - if (!arg) - { - continue; - } - if (tok == tSTRING) - { - assert(litidx != 0); - if (arg->dimcount != 1) - { - error(48); - } else if (arg->tag != pc_tag_string) { - error(213); - } - values[arg->index] = glb_declared * sizeof(cell); - glb_declared += (litidx-cur_litidx); - found[arg->index] = 1; - } else if (tok == tNUMBER || tok == tRATIONAL) { - /* eat optional 'f' */ - matchtoken('f'); - if (arg->ident != iVARIABLE && arg->ident != iREFERENCE) - { - error(23); - } else { - if ((arg->tag == pc_addtag("Float") && tok == tNUMBER) || - (arg->tag == 0 && tok == tRATIONAL)) - { - error(213); - } - if (arg->ident == iVARIABLE) - { - values[arg->index] = val; - } else if (arg->ident == iREFERENCE) { - values[arg->index] = glb_declared * sizeof(cell); - glb_declared += 1; - litadd(val); - cur_litidx = litidx; - } - found[arg->index] = 1; - } - } else if (tok == tSYMBOL) { - for (sym=glbtab.next; sym!=NULL; sym=sym->next) - { - if (sym->vclass != sGLOBAL) - { - continue; - } - if (strcmp(sym->name, str) == 0) - { - if (arg->ident == iREFERENCE && sym->ident != iVARIABLE) - { - error(97, str); - } else if (arg->ident == iARRAY) { - if (sym->ident != iARRAY) - { - error(97, str); - } else { - /* :TODO: We should check dimension sizes here... */ - } - } else if (arg->ident == iREFARRAY) { - if (sym->ident != iARRAY) - { - error(97, str); - } - /* :TODO: Check dimension sizes! */ - } else { - error(97, str); - } - if (sym->tag != arg->tag) - { - error(213); - } - sym->usage |= uREAD; - values[arg->index] = sym->addr; - found[arg->index] = 1; - refer_symbol(sym, mysym); - break; - } - } - if (!sym) - { - error(17, str); - } - } else { - error(1, "-identifier-", str); - } - } while (matchtoken(',')); - needtoken('}'); - matchtoken(';'); /* eat up optional semicolon */ + if (!matchtoken('=')) { + matchtoken(';'); + /* Mark it as undefined instead */ + mysym->usage = uSTOCK|uSTRUCT; + free(found); + free(values); + return; + } - for (i=0; iargcount; i++) - { - if (!found[i]) - { - structarg_t *arg = pstruct->args[i]; - if (arg->ident == iREFARRAY) - { - values[arg->index] = glb_declared * sizeof(cell); - glb_declared += 1; - litadd(0); - cur_litidx = litidx; - } else if (arg->ident == iVARIABLE) { - values[arg->index] = 0; - } else { - /* :TODO: broken for iARRAY! (unused tho) */ - } - } - } + mysym->usage = usage; + needtoken('{'); - mysym->addr = glb_declared * sizeof(cell); - glb_declared += pstruct->argcount; + do { + structarg_t *arg; + /* Detect early exit */ + if (matchtoken('}')) { + lexpush(); + break; + } + tok=lex(&val,&str); + if (tok != tSYMBOL) { + error(1, "-identifier-", str); + continue; + } + arg=pstructs_getarg(pstruct,str); + if (arg == NULL) + error(96, str, sym->name); + needtoken('='); + cur_litidx = litidx; + tok=lex(&val,&str); + if (!arg) { + continue; + } + if (tok == tSTRING) { + assert(litidx != 0); + if (arg->dimcount != 1) + { + error(48); + } else if (arg->tag != pc_tag_string) { + error(213); + } + values[arg->index] = glb_declared * sizeof(cell); + glb_declared += (litidx-cur_litidx); + found[arg->index] = 1; + } else if (tok == tNUMBER || tok == tRATIONAL) { + /* eat optional 'f' */ + matchtoken('f'); + if (arg->ident != iVARIABLE && arg->ident != iREFERENCE) { + error(23); + } else { + if ((arg->tag == pc_addtag("Float") && tok == tNUMBER) || + (arg->tag == 0 && tok == tRATIONAL)) + { + error(213); + } + if (arg->ident == iVARIABLE) { + values[arg->index] = val; + } else if (arg->ident == iREFERENCE) { + values[arg->index] = glb_declared * sizeof(cell); + glb_declared += 1; + litadd(val); + cur_litidx = litidx; + } + found[arg->index] = 1; + } + } else if (tok == tSYMBOL) { + for (sym=glbtab.next; sym!=NULL; sym=sym->next) { + if (sym->vclass != sGLOBAL) + continue; + if (strcmp(sym->name, str) == 0) { + if (arg->ident == iREFERENCE && sym->ident != iVARIABLE) { + error(97, str); + } else if (arg->ident == iARRAY) { + if (sym->ident != iARRAY) { + error(97, str); + } else { + /* :TODO: We should check dimension sizes here... */ + } + } else if (arg->ident == iREFARRAY) { + if (sym->ident != iARRAY) + error(97, str); + /* :TODO: Check dimension sizes! */ + } else { + error(97, str); + } + if (sym->tag != arg->tag) + error(213); + sym->usage |= uREAD; + values[arg->index] = sym->addr; + found[arg->index] = 1; + refer_symbol(sym, mysym); + break; + } + } + if (!sym) + error(17, str); + } else { + error(1, "-identifier-", str); + } + } while (matchtoken(',')); + needtoken('}'); + matchtoken(';'); /* eat up optional semicolon */ - for (i=0; iargcount; i++) - { - litadd(values[i]); - } + for (i=0; iargcount; i++) { + if (!found[i]) { + structarg_t *arg = pstruct->args[i]; + if (arg->ident == iREFARRAY) { + values[arg->index] = glb_declared * sizeof(cell); + glb_declared += 1; + litadd(0); + cur_litidx = litidx; + } else if (arg->ident == iVARIABLE) { + values[arg->index] = 0; + } else { + /* :TODO: broken for iARRAY! (unused tho) */ + } + } + } - begdseg(); - dumplits(); - litidx=0; + mysym->addr = glb_declared * sizeof(cell); + glb_declared += pstruct->argcount; - free(found); - free(values); + for (i=0; iargcount; i++) + litadd(values[i]); + + begdseg(); + dumplits(); + litidx=0; + + free(found); + free(values); } /* declglb - declare global symbols