Skip to content

Instantly share code, notes, and snippets.

@AmyrAhmady
Created December 31, 2019 14:29
Show Gist options
  • Save AmyrAhmady/c9df32e6a38f1af9f7b5abaa1298e8ca to your computer and use it in GitHub Desktop.
Save AmyrAhmady/c9df32e6a38f1af9f7b5abaa1298e8ca to your computer and use it in GitHub Desktop.
better
int main()
{
if (firstname != NULL)
{
assert(strlen(firstname) <= sNAMEMAX);
strcpy(symbolname, firstname); /* save symbol name */
tag = firsttag;
}
else
{
tag = (firsttag >= 0) ? firsttag : pc_addtag(NULL);
tok = lex(&val, &str);
assert(!fpublic);
if (tok == tNATIVE || (tok == tPUBLIC && stock))
error(42); /* invalid combination of class specifiers */
if (tok == tOPERATOR)
{
opertok = operatorname(symbolname);
if (opertok == 0)
return TRUE; /* error message already given */
check_operatortag(opertok, tag, symbolname);
}
else
{
if (tok != tSYMBOL && freading)
{
error(20, str); /* invalid symbol name */
return FALSE;
} /* if */
assert(strlen(str) <= sNAMEMAX);
strcpy(symbolname, str);
} /* if */
} /* if */
/* check whether this is a function or a variable declaration */
if (!matchtoken('('))
return FALSE;
/* so it is a function, proceed */
funcline = fline; /* save line at which the function is defined */
if (symbolname[0] == PUBLIC_CHAR)
{
fpublic = TRUE; /* implicitly public function */
if (stock)
error(42); /* invalid combination of class specifiers */
} /* if */
sym = fetchfunc(symbolname, tag); /* get a pointer to the function entry */
if (sym == NULL || (sym->usage & uNATIVE) != 0)
return TRUE; /* it was recognized as a function declaration, but not as a
valid one */
if (fpublic)
sym->usage |= uPUBLIC;
if (fstatic)
sym->fnumber = filenum;
check_reparse(sym);
/* we want public functions to be explicitly prototyped, as they are called
* from the outside
*/
if (fpublic && (sym->usage & uFORWARD) == 0)
error(235, symbolname);
/* declare all arguments */
argcnt = declargs(sym, TRUE);
opererror = !operatoradjust(opertok, sym, symbolname, tag);
if (strcmp(symbolname, uMAINFUNC) == 0 || strcmp(symbolname, uENTRYFUNC) == 0)
{
if (argcnt > 0)
error(5); /* "main()" and "entry()" functions may not have any arguments */
sym->usage |= uREAD; /* "main()" is the program's entry point: always used */
} /* if */
state_id = getstates(symbolname);
if (state_id > 0 && (opertok != 0 || strcmp(symbolname, uMAINFUNC) == 0))
error(82); /* operators may not have states, main() may neither */
attachstatelist(sym, state_id);
/* "declargs()" found the ")"; if a ";" appears after this, it was a
* prototype */
if (matchtoken(';'))
{
sym->usage |= uFORWARD;
if (!sc_needsemicolon)
error(218); /* old style prototypes used with optional semicolumns */
delete_symbols(&loctab, 0, TRUE, TRUE); /* prototype is done; forget everything */
return TRUE;
} /* if */
/* so it is not a prototype, proceed */
/* if this is a function that is not referred to (this can only be detected
* in the second stage), shut code generation off */
if (sc_status == statWRITE && (sym->usage & uREAD) == 0 && !fpublic)
{
sc_status = statSKIP;
cidx = code_idx;
glbdecl = glb_declared;
} /* if */
if ((sym->flags & flgDEPRECATED) != 0)
{
char* ptr = (sym->documentation != NULL) ? sym->documentation : "";
error(234, symbolname, ptr); /* deprecated (probably a public function) */
} /* if */
if (pc_naked)
{
sym->flags |= flagNAKED;
pc_naked = FALSE;
} /* if */
begcseg();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment