⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 4 页
字号:
                return ;
        }
        getsym();
    }
}

/*
 * 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 if (lastst == openbr)
        rv->type = BAL_BRACKET;
    else
        rv->type = BAL_BEGIN;
    return (rv);
}

//-------------------------------------------------------------------------

void setbalance(BALANCE **bal)
{
    switch (lastst)
    {
        case end:
            while (*bal && (*bal)->type != BAL_BEGIN)
            {
                (*bal) = (*bal)->back;
            }
            if (*bal && !(--(*bal)->count))
                (*bal) = (*bal)->back;
            break;
        case closepa:
            while (*bal && (*bal)->type != BAL_PAREN)
            {
                (*bal) = (*bal)->back;
            }
            if (*bal && !(--(*bal)->count))
                (*bal) = (*bal)->back;
            break;
        case closebr:
            while (*bal && (*bal)->type != BAL_BRACKET)
            {
                (*bal) = (*bal)->back;
            }
            if (*bal && !(--(*bal)->count))
                (*bal) = (*bal)->back;
            break;
        case begin:
            if (! *bal || (*bal)->type != BAL_BEGIN)
                *bal = newbalance(*bal);
            (*bal)->count++;
            break;
        case openpa:
            if (! *bal || (*bal)->type != BAL_PAREN)
                *bal = newbalance(*bal);
            (*bal)->count++;
            break;

        case openbr:
            if (! *bal || (*bal)->type != BAL_BRACKET)
                *bal = newbalance(*bal);
            (*bal)->count++;
            break;
    }
}

//-------------------------------------------------------------------------

void expskim(int *skimlist, int tpl)
{
    BALANCE *bal = 0;
    int i;
    while (TRUE)
    {
        setbalance(&bal);
        if (lastst == eof)
            break;
        if (!bal)
        {
            for (i = 0; skimlist[i]; i++)
                if (lastst == skimlist[i])
                    return ;
        }
        getsym();
    }

}

//-------------------------------------------------------------------------

void tplskm(int *skmlist)
{
    expskim(skmlist, TRUE);
}

//-------------------------------------------------------------------------

void basicerror(int n, void *data)
/*
 * standard routine for putting out an error
 */
{
    char buf[256];
    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 &1))
    {
        errline = errlineno;
        if (!prm_quieterrors)
            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 != errlineno) && 
        (prm_extwarning || !(errlvl &2)))
    {
        errored++;
        if (!prm_quieterrors)
            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)
        {
            char *p = buf;
            if (currentfunc->value.classdata.parentns)
            {
                p = currentfunc->value.classdata.parentns->sp->name;
                p += prm_cmangle &&  *p == '_';
                sprintf(buf, "%s::", p);
                p = buf + strlen(buf);
            }
            unmangle(p, currentfunc->name);
            if (!prm_quieterrors)
                fprintf(stdout, " in function '%s'", buf);
            if (prm_errfile)
                fprintf(errFile, " in function '%s'", buf);
        }
        if (!prm_quieterrors)
            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)
        expskim(skimlist, FALSE);
}

//-------------------------------------------------------------------------

void gensymerror(int n, char *data)
/*
 * errors come here if the error has a symbol name
 */
{
    char buf[256];
    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[256], buf1[256], buf2[256];
    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[256], buf1[256], buf2[256];
    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 *name)
{
    char buf[256], buf1[256];
    unmangle(buf1, name);
    buf[0] = '\'';
    buf[1] = 0;
    strcat(buf, buf1);
    strcat(buf, "'");
    global_flag++;
    basicerror(n, (void*)litlate(buf));
    global_flag--;
}

//-------------------------------------------------------------------------

void genclass2error(int n, char *struc, char *elem)
{
    char buf[256], buf1[256], buf2[256];
    unmangle(buf1, elem);
    unmangle(buf2, struc);
    buf[0] = '\'';
    buf[1] = 0;
    strcat(buf, buf2);
    strcat(buf, "::");
    strcat(buf, buf1);
    strcat(buf, "'");
    global_flag++;
    basicerror(n, (void*)litlate(buf));
    global_flag--;
}

//-------------------------------------------------------------------------

void genmismatcherror(TYP *tp1, TYP *tp2)
{
        char buf[256], buf1[256], buf2[256];
        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--;
}

//-------------------------------------------------------------------------

void doubleerr(int n, char *s1, char *s2)
{
    char buf1[256], buf2[256];
    char **data = xalloc(sizeof(char*) * 2);
    unmangle(buf1, s1);
    unmangle(buf2, s2);
    data[0] = litlate(buf1);
    data[1] = litlate(buf2);
    global_flag++;
    basicerror(n, (void*)data);
    global_flag--;
}

/*
 * 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);
        getsym();
    }
}

//-------------------------------------------------------------------------

void generrorexp(int n, int data, int *skimlist)
{
    basicerror(n, (void*)data);
    if (skimlist)
        expskim(skimlist, FALSE);
    else
        getsym();
}

//-------------------------------------------------------------------------

void gensymerrorexp(int n, char *data)
{
    char buf1[256];
    global_flag++;
    if (data)
        unmangle(buf1, data);
    basicerror(n, (void*)litlate(buf1));
    global_flag--;
}

//-------------------------------------------------------------------------

void expecttokenexp(int n, int *skimlist)
{
    if (skimlist)
        generrorexp(ERR_PUNCT, n, skimlist);
    else
    {
        generrorexp(ERR_INSERT, n, 0);
        getsym();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -