📄 error.c
字号:
/*
* simple skim for a token with no nesting
*/
{
int i;
for (i=0;;i++) {
if (lastst == skimlist[i] || lastst == eof)
break;
if (skimlist[i] == 0) {
getsym();
i = 0;
}
}
}
/*
* the following routines do token skimming and keep track of parenthesis
* and brace nesting levels as well
*/
BALANCE *newbalance(BALANCE *bal)
{
BALANCE *rv = xalloc(sizeof(BALANCE));
rv->back = bal;
rv->count = 0;
if (lastst == openpa)
rv->type = BAL_PAREN;
else
rv->type = BAL_BRACKET;
return(rv);
}
void setbalance(BALANCE **bal)
{
if (*bal == 0)
if (lastst = openpa || lastst == closepa)
*bal = newbalance(*bal);
else
return;
switch (lastst) {
case closepa:
while (*bal && (*bal)->type != BAL_PAREN) {
(*bal) = (*bal)->back;
}
if (!((*bal)->type)--)
(*bal) = (*bal)->back;
else return;
case closebr:
while (*bal && (*bal)->type != BAL_BRACKET) {
(*bal) = (*bal)->back;
}
if (!((*bal)->type)--)
(*bal) = (*bal)->back;
case openpa:
if ((*bal)->type != BAL_PAREN)
*bal = newbalance(*bal);
(*bal)->count++;
break;
case openbr:
if ((*bal)->type != BAL_BRACKET)
*bal = newbalance(*bal);
(*bal)->count++;
break;
}
return;
}
void expskim(int *skimlist)
{
BALANCE *bal = 0;
int i = 0;
for (i = 0; ; i++) {
if (lastst == openpa || lastst == openbr) {
setbalance(&bal);
getsym();
}
else
if (lastst == eof)
break;
else
if (lastst == skimlist[i])
if (lastst == closepa || lastst == openpa) {
if (!bal)
break;
setbalance(&bal);
getsym();
}
else
break;
else
if (skimlist[i] == 0) {
i = 0;
getsym();
}
}
}
void basicerror(int n, void *data)
/*
* standard routine for putting out an error
*/
{
char buf[100];
ERRORS *nexterr;
int errlvl,errored = 0;;
global_flag++;
nexterr = xalloc(sizeof(ERRORS));
global_flag--;
nexterr->errornumber = n;
nexterr->link = 0;
nexterr->data = data;
if (errlist == 0)
errlist = errtail = nexterr;
else {
errtail->link = nexterr;
errtail = nexterr;
}
errlvl = printerr(buf, nexterr);
if (curerr == 0)
curerr = nexterr;
if (!errlvl) {
errline = lineno;
fprintf(stdout,"Error %s(%d): %s",errfile,errlineno,buf);
if (prm_errfile)
fprintf(errFile,"Error %s(%d): %s",errfile,errlineno,buf);
errored++;
total_errors++;
}
else if (prm_warning && !nowarn[n] && (errline != lineno)) {
errored++;
fprintf(stdout,"Warning %s(%d): %s",errfile,errlineno,buf);
if (prm_errfile)
fprintf(errFile,"Warning %s(%d): %s",errfile,errlineno,buf);
}
if (errored) {
if (currentfunc) {
unmangle(buf,currentfunc->name);
fprintf(stdout," in function '%s'",buf);
if (prm_errfile)
fprintf(errFile," in function '%s'",buf);
}
fputc('\n',stdout);
if (prm_errfile)
fputc('\n',errFile);
}
if (total_errors > prm_maxerr) {
fatal("Too many errors");
}
}
void Error(char *string)
/*
* some of the library functions required a generic error function
*
* we are remapping it to the C/C++ error routines
*/
{
basicerror(ERR_INTERP,(void *)string);
}
void generror(int n, int data, int *skimlist)
/*
* most errors come here
*/
{
basicerror(n,(void *)data);
if (skimlist)
basicskim(skimlist);
}
void gensymerror(int n, char *data)
/*
* errors come here if the error has a symbol name
*/
{
char buf[100];
if (data)
unmangle(buf,data);
else
buf[0] = 0;
global_flag++;
basicerror(n,(void *)litlate(buf));
global_flag--;
}
/*
* the next two functions are for reporting full C++ functions with
* the argument list types
*/
void genfuncerror(int n, char*func, char *data)
{
char buf[100],buf1[100],buf2[100];
unmangle(buf1,func);
if (data) {
unmangle(buf2,data);
buf[0] = '\'';
buf[1] = 0;
strcat(buf,buf2);
strcat(buf,"' ");
}
else
buf[0] = 0;
strcat(buf,"in call to function ");
strcat(buf,"'");
strcat(buf,buf1);
strcat(buf,"'");
global_flag++;
basicerror(n,(void *)litlate(buf));
global_flag--;
}
void genfunc2error(int n, char*func, char *func2)
{
char buf[100],buf1[100],buf2[100];
unmangle(buf1,func);
unmangle(buf2,func2);
buf[0] = '\'';
buf[1] = 0;
strcpy(buf,buf2);
strcat(buf,"'");
strcat(buf," and ");
strcat(buf,"'");
strcat(buf,buf1);
strcat(buf,"'");
global_flag++;
basicerror(n,(void *)litlate(buf));
global_flag--;
}
/*
* C++ errors for class names and type checking
*/
void genclasserror(int n, char *struc, char *elem)
{
char buf[100],buf1[100],buf2[100];
unmangle(buf1,elem);
unmangle(buf2,struc);
buf[0] = '\'';
buf[1] = 0;
strcpy(buf,buf2);
strcat(buf,"::");
strcat(buf,buf1);
strcat(buf,"'");
global_flag++;
basicerror(n,(void *)litlate(buf));
global_flag--;
}
void genmismatcherror(TYP *tp1, TYP *tp2)
{
#ifdef CPLUSPLUS
char buf[100],buf1[100],buf2[100];
typenum(buf1,tp1);
typenum(buf2,tp2);
buf[0] = '\'';
buf[1] = 0;
strcat(buf,buf1);
strcat(buf,"'");
strcat(buf," to ");
strcat(buf,"'");
strcat(buf,buf2);
strcat(buf,"'");
global_flag++;
basicerror(ERR_CPPMISMATCH,(void *)litlate(buf));
global_flag--;
#endif
}
/*
* various utilities for special case errors
*/
void expecttoken(int n, int *skimlist)
{
if (skimlist)
generror(ERR_PUNCT, n, skimlist);
else
generror(ERR_INSERT, n, 0);
}
void generrorexp(int n, int data, int *skimlist)
{
basicerror(n,(void *)data);
if (skimlist)
expskim(skimlist);
}
void gensymerrorexp(int n, char *data)
{
global_flag++;
basicerror(n,(void *)litlate(data));
global_flag--;
}
void expecttokenexp(int n, int *skimlist)
{
if (skimlist)
generrorexp(ERR_PUNCT, n, skimlist);
else
generrorexp(ERR_INSERT, n, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -