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

📄 decl.c

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

            if (lastst == id)
            {
                typesp = typesearch(lastid);
                if (!typesp || typesp->storage_class == sc_namespace || typesp
                    ->istemplate || typesp->istemplatevar)
                {
                    generror(ERR_INVALIDARGTOTYPEOF, 0, 0);
                    head = tail = maketype(bt_int, stdintsize);
                }
                else
                    head = tail = copytype(typesp->tp, 0);
                getsym();
            }
            else
            {
                if (castbegin(lastst))
                {
                    decl(table, 0); /* do cast declaration */
                    headptr = &head;
                    decl1(sc_type, 0);
                }
                else
                {
                    generror(ERR_INVALIDARGTOTYPEOF, 0, 0);
                    head = tail = maketype(bt_int, stdintsize);
                }
            }
            if (opened)
                needpunc(closepa, skm_declend);
            break;
    }
    exit: head->cflags |= flags;
    head->uflags |= UF_CANASSIGN;
    return cppflags;
}

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

SYM *makesym(enum e_sc sc)
{
    SYM *sp = xalloc(sizeof(SYM));
    sp->storage_class = sc;
    sp->mainsym = sp;
    sp->dontlist = sys_inc;
    return sp;
} 
    void overloadoperator(enum e_sc sc, SYM *sp)
    {
        char *q = lastid;
        int aftertype = 0;
        getsym(); /* past the operator keyword */
        if (castbegin(lastst))
        {
            aftertype = 1;
            decl(0, 0); /* do cast declaration */
            headptr = &head;
            decl1(sc_type, 0);
            if (head->type == bt_func || head->type == bt_ifunc)
            {
                backup(openpa);
            } 
            else
                goto error;
        }
        if (lastst >= id)
        {
            error: generror(ERR_OPERATOREXPECTED, 0, skm_declend);
            return ;
        }
        else
        {
            sp->value.i = lastst + IT_OV_THRESHOLD;
            sp->value.classdata.cppflags |= PF_OPERATOR;
            getsym(); /* past the operator */
            /* special case operator () and [] since they are two symbols */
            switch (sp->value.i)
            {
                case ov_ind:
                    if (lastst != closebr)
                        goto error;
                    if (aftertype)
                        goto error;
                    getsym();
                    decl2(sc, sp);
                    break;
                case ov_new:
                    sp->value.classdata.cppflags |= PF_STATIC;
                    if (aftertype)
                        goto error;
                    if (lastst == openbr)
                    {
                        sp->value.i = ov_newa;
                        getsym();
                        needpunc(closebr, 0);
                    }
                    decl2(sc, sp);
                    break;
                case ov_arg:
                    break;
                case ov_delete:
                    sp->value.classdata.cppflags |= PF_STATIC;
                    if (aftertype)
                        goto error;
                    if (lastst == openbr)
                    {
                        sp->value.i = ov_deletea;
                        getsym();
                        needpunc(closebr, 0);
                    }
                    decl2(sc, sp);
                    break;
                default:
                    if (aftertype)
                        goto error;
                    decl2(sc, sp);
                    break;
            }
            /* construct the function name */
            /*		if (prm_cmangle)
             *q++ = '_';
             */
            /* special case name for overloaded cast operators */

            if (sp->value.i == ov_arg)
            {
                int temp1 = head->type;
                int temp2 = head->btp->cflags;
                head->btp->cflags = 0;
                q[0] = '$';
                q[1] = 'o';
                cpponearg(q + 2, head->btp);
                head->btp->cflags = temp2;
            }
            else
                strcpy(q, cpp_funcname_tab[sp->value.i]);
            strcpy(declid, lastid);
        }

        return ;
    }
SYM *decl1(enum e_sc sc, SYM *sp)
/*
 * Modifiers that could occur BEFORE the name of the var
 */
{
    TYP *temp1,  *temp2,  *temp3,  *temp4,  *head1 =  *headptr;
    TYP **tempptr;
    SYM *typesp = 0;
    int ocppf;
    int special = FALSE;
    if (!sp)
        sp = makesym(sc);

    lp: switch (lastst)
    {
        case kw_inline:
            if (!prm_cplusplus)
            {
                lastst = id;
                goto getid;
            }
            cppflags |= PF_INLINE;
            getsym();
            goto lp;
            case kw_virtual:
                if (!prm_cplusplus)
                {
                    lastst = id;
                    goto getid;
                }
                cppflags |= PF_VIRTUAL;
                getsym();
                goto lp;
            case kw_static:
                cppflags |= PF_STATIC;
                getsym();
                goto lp;
            case kw_friend:
                if (!prm_cplusplus)
                {
                    lastst = id;
                    goto getid;
                }
                getsym();
                aFriend = TRUE;
                goto lp;
        case kw__seg:
            #ifdef i386
                segflag = TRUE;
                head1->cflags |= DF_SEG;
            #endif 
            getsym();
            goto lp;
        case kw__far:
            #ifdef i386
                if (prm_farkeyword)
                {
                    farflag = TRUE;
                    head1->cflags |= DF_FAR;
                }
            #endif 
        case kw__near:
            getsym();
            goto lp;
        case kw__interrupt:
            intflag = 1;
            sp->intflag = 1;
            /// head1->cflags |= DF_INT;
            getsym();
            goto lp;
        case kw__fault:
            intflag = 1;
            sp->faultflag = 1;
            // head1->cflags |= DF_FAULT;
            getsym();
            goto lp;
        case kw_const:
            head1->cflags |= DF_CONST;
            getsym();
            goto lp;
        case kw_restrict:
            if (head1->type != bt_pointer)
            {
                errlineno = lineno;
                generror(ERR_RESTRICTPTR, 0, 0);
            }
            head1->cflags |= DF_RESTRICT;
            getsym();
            goto lp;
        case kw__intrinsic:
            head1->cflags |= DF_INTRINS;
            getsym();
            goto lp;
        case kw_volatile:
            head1->cflags |= DF_VOL;
            getsym();
            goto lp;
        case kw__stdcall:
            isstdcall = TRUE;
            getsym();
            goto lp;
        case kw__indirect:
            if (prm_microlink)
                isindirect = TRUE;
            getsym();
            goto lp;
        case kw__pascal:
            ispascal = TRUE;
            getsym();
            goto lp;
        case kw_explicit:
            cppflags |= PF_EXPLICIT;
            getsym();
            goto lp;
        case kw__export:
            isexport = TRUE;
            getsym();
            goto lp;
        case kw__import:
            isimport = TRUE;
            importname = 0;
            getsym();
            if (lastst == openpa)
            {
                getsym();
                if (lastst == sconst)
                {
                    importname = litlate(laststr);
                    getsym();
                    needpunc(closepa, 0);
                }
                else
                    generror(ERR_NEEDCHAR, '"', 0);
            }
            goto lp;
        case kw__cdecl:
            iscdecl = TRUE;
            getsym();
            goto lp;
            case compl:
                getsym();
                if (lastst == id)
                {
                    getsym();
                    if (lastst == lt)
                    {
                        SYM *tcq = typequal;
                        typequal = 0;
                        typesp = typesearch(lastid);
                        typequal = tcq;
                        if (typesp)
                        {
                            typesp = lookupTemplateType(typesp,cppflags);
                            if (typesp)
                                goto joincompl;
                        }
                    }
                    else
                    {
                        if (typequal)
                            typesp = typequal;
                        else if (declclass)
                            typesp = declclass;
                        else
                            typesp = 0;
                        if (typesp && !strcmp(typesp->name, lastid))
                        {
                            joincompl: if (!defaulttype || currentfunc)
                                gensymerror(ERR_CANTHAVETYPE, declclass->name);
                            strcpy(declid, cpp_funcname_tab[CI_DESTRUCTOR]);
                            cppflags |= PF_DESTRUCTOR;
                            typesp->value.classdata.cppflags |= PF_HASDEST;
                            head = tail = maketype(bt_void, 0);
                            decl2(sc, sp);
                            break;
                        }
                    }
                }
                if (typesp)
                    gensymerror(ERR_BADESTRUCT, typesp->name);
                else
                    gensymerror(ERR_BADESTRUCT, lastid);
                break;
            case kw_operator:
                overloadoperator(sc, sp);
                break;
            case classsel:
                 /* shouldn't get here */
            case classselstar:
                break;
        case id:
            if (declid[0])
                generror(ERR_EXTRAIDENT,0,0);
            getid: strcpy(declid, lastid);
            getsym();

                if (prm_cplusplus)
                {
                    if (lastst == lt)
                    {
                        SYM *tcq = typequal;
                        special = TRUE;
                        typequal = 0;
                        if (!(typesp = typesearch(lastid)) || typesp
                            ->storage_class != sc_type || !typesp->istemplate)
                        {
                            generror(ERR_INVALIDTEMPLATE, 0, 0);
                            tplskm(skm_tempend);
                        }
                        else
                        {
                            typequal = tcq;
                            typesp = lookupTemplateType(typesp,cppflags);
                            if (typesp == typequal)
                            {
                                if (lastst == openpa)
                                {
                                    if (!defaulttype || currentfunc)
                                        gensymerror(ERR_CANTHAVETYPE, typequal 
                                            ? typequal->name: declclass->name);
                                    strcpy(declid,
                                        cpp_funcname_tab[CI_CONSTRUCTOR]);
                                    cppflags |= PF_CONSTRUCTOR;
                                    head = tail = maketype(bt_void, 0);
                                    decl2(sc, sp);
                                    break;
                                }
                            }
                            if (lastst != classsel && lastst != classselstar)
                            {
                                generror(ERR_INVALIDTEMPLATE, 0, 0);
                                tplskm(skm_tempend);
                            }
                            else
                                if (typesp && typesp->storage_class == sc_type)
                                    goto tempjn;
                        }
                    }
                    if (lastst == classsel || lastst == classselstar)
                    {
                        if ((typesp = typesearch(lastid)) && (typesp
                            ->storage_class == sc_type || typesp->storage_class
                            == sc_namespace))
                        {
                            tempjn: if (!special && typesp->istemplate)
                                gensymerror(ERR_NEEDSPECIAL, typesp->name);
                            typesp = parsetype(typesp, TRUE);
                            if (lastst == classsel && declclass)

⌨️ 快捷键说明

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