Fix indentation, spacing, and style in declstruct().

This commit is contained in:
David Anderson 2014-07-20 11:46:02 -07:00
parent d2c7064e2b
commit 16177e9ecc

View File

@ -1754,218 +1754,182 @@ static void insert_docstring_separator(void)
*/ */
static void declstructvar(char *firstname,int fpublic, pstruct_t *pstruct) static void declstructvar(char *firstname,int fpublic, pstruct_t *pstruct)
{ {
char name[sNAMEMAX+1]; char name[sNAMEMAX+1];
int tok,i; int tok,i;
cell val; cell val;
char *str; char *str;
int cur_litidx = 0; int cur_litidx = 0;
cell *values, *found; cell *values, *found;
int usage; int usage;
symbol *mysym,*sym; symbol *mysym,*sym;
strcpy(name, firstname); strcpy(name, firstname);
values = (cell *)malloc(pstruct->argcount * sizeof(cell)); values = (cell *)malloc(pstruct->argcount * sizeof(cell));
found = (cell *)malloc(pstruct->argcount * sizeof(cell)); found = (cell *)malloc(pstruct->argcount * sizeof(cell));
memset(found, 0, sizeof(cell) * pstruct->argcount); 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. * Lastly, very lastly, we will insert a copy of this variable.
* This is soley to expose the pubvar. * This is soley to expose the pubvar.
*/ */
usage = uREAD|uCONST|uSTRUCT; usage = uREAD|uCONST|uSTRUCT;
if (fpublic) if (fpublic)
{ usage |= uPUBLIC;
usage |= uPUBLIC; mysym = NULL;
} for (sym=glbtab.next; sym!=NULL; sym=sym->next) {
mysym = NULL; if (strcmp(name, sym->name) == 0) {
for (sym=glbtab.next; sym!=NULL; sym=sym->next) if ((sym->usage & uSTRUCT) && sym->vclass == sGLOBAL) {
{ if (sym->usage & uDEFINE) {
if (strcmp(name, sym->name) == 0) error(21, name);
{ } else {
if ((sym->usage & uSTRUCT) && sym->vclass == sGLOBAL) if (sym->usage & uPUBLIC && !fpublic)
{ error(42);
if (sym->usage & uDEFINE) }
{ } else {
error(21, name); error(21, name);
} else { }
if (sym->usage & uPUBLIC && !fpublic) mysym = sym;
{ break;
error(42); }
} }
} if (!mysym)
} else { mysym=addsym(name, 0, iVARIABLE, sGLOBAL, pc_addtag(pstruct->name), usage);
error(21, name);
}
mysym = sym;
break;
}
}
if (!mysym)
{
mysym=addsym(name, 0, iVARIABLE, sGLOBAL, pc_addtag(pstruct->name), usage);
}
if (!matchtoken('=')) if (!matchtoken('=')) {
{ matchtoken(';');
matchtoken(';'); /* Mark it as undefined instead */
/* Mark it as undefined instead */ mysym->usage = uSTOCK|uSTRUCT;
mysym->usage = uSTOCK|uSTRUCT; free(found);
free(found); free(values);
free(values); return;
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 */
for (i=0; i<pstruct->argcount; i++) mysym->usage = usage;
{ needtoken('{');
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->addr = glb_declared * sizeof(cell); do {
glb_declared += pstruct->argcount; 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; i<pstruct->argcount; i++) for (i=0; i<pstruct->argcount; i++) {
{ if (!found[i]) {
litadd(values[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(); mysym->addr = glb_declared * sizeof(cell);
dumplits(); glb_declared += pstruct->argcount;
litidx=0;
free(found); for (i=0; i<pstruct->argcount; i++)
free(values); litadd(values[i]);
begdseg();
dumplits();
litidx=0;
free(found);
free(values);
} }
/* declglb - declare global symbols /* declglb - declare global symbols