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

📄 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 (typequal != declclass)
                                {
                                    gensymerror(ERR_NOTYPEQUAL, lastid);
                                    basicskim(skm_declend);
                                    break;
                                }
                                else
                                {
                                    typequal = 0;
                                }
                            }
                            if (lastst == id)
                            {
                                strcpy(declid, lastid);
                                getsym();
                            }
                        }
                        else
                        {
                            gensymerror(ERR_NOTNSORTYPQUAL, lastid);
                            basicskim(skm_declend);
                            break;
                        }
                    }
                    if (lastst != classselstar && (((typequal && (!declclass ||
                        typequal == declclass)) || declclass && !typequal)))
                    {
                        if (typequal && !strcmp(lastid, typequal->name) ||
                            declclass && !strcmp(lastid, declclass->name))
                        {
                            if (lastst == id)
                                getsym();
                            if (lastst == openpa)
                            {
                                if (!defaulttype || currentfunc)
                                    gensymerror(ERR_CANTHAVETYPE, typequal ?
                                        typequal->name: declclass->name);
                                strcpy(declid, cpp_funcname_tab[CI_CONSTRUCTOR])
                                    ;
                                cppflags |= PF_CONSTRUCTOR;
                                if (declclass)
                                    declclass->value.classdata.cppflags |=
                                        PF_HASCONS;
                                head = tail = maketype(bt_void, 0);
                                decl2(sc, sp);
                                break;
                            }
                            goto lp;
                        }
                    }
                    if (lastst == classselstar)
                    {
                        getsym();
                        if (!typequal || typequal->tp->type != bt_class &&
                            typequal->tp->type != bt_struct)
                        {
                            generror(ERR_TYPEQUALEXP, 0, 0);
                        }
                        else
                        {
                            if (lastst != id)
                                generror(ERR_IDEXPECT, 0, 0);
                            else
                            {
                                strcpy(declid, lastid);
                                getsym();
                                memberptr = TRUE;
                                temp1 = maketype(bt_memberptr, stdmemberptrsize)
                                    ;
                                temp1->btp = head;
                                temp1->sp = typequal;
                                *headptr = temp1;
                                typequal = 0;
                            }
                        }
                        if (lastst == id)
                        {
                            strcpy(declid, lastid);
                            getsym();
                        }
                    }
                    else
                    if (lastst == kw_operator)
                    {
                        overloadoperator(sc, sp);
                        break;
                    }
                    else
                        if (typesp && typesp->storage_class == sc_type)
                    if (!strcmp(typesp->name, lastid))
                    {
                        if (!defaulttype || currentfunc)
                                gensymerror(ERR_CANTHAVETYPE, typesp->name);
                        strcpy(declid, cpp_funcname_tab[CI_CONSTRUCTOR]);
                        decl2(sc, sp);
                        break;
                    }
                    else
                        generror(ERR_IDEXPECT, 0, 0);

                }
            decl2(sc, sp);
            break;
        case colon:
            sprintf(declid, "_$$NULLNAME%d", nullnamecount++);
            decl2(sc, sp);
            break;
        case and:
                if (prm_cplusplus)
                {
                    getsym();
                    temp1 = maketype(bt_ref, stdaddrsize);
                    temp1->btp = head1;
                    *headptr = temp1;
                    if (tail == NULL)
                        tail = head1;
                    decl1(sc, sp);
                }
                else
            {
                decl2(sc, sp);
            }
            break;
        case star:
            head1->uflags &= ~UF_CANASSIGN;
            #ifdef i386
                if (farflag)
                    temp1 = maketype(bt_farpointer, stdaddrsize + stdshortsize);
                else if (segflag)
                    temp1 = maketype(bt_segpointer, stdshortsize);
                else
            #endif 
                temp1 = maketype(bt_pointer, stdaddrsize);
            farflag = segflag = 0;
            temp1->btp = head1;
            *headptr = temp1;
            head1->uflags |= UF_CANASSIGN;
            if (tail == NULL)
                tail = head1;
            getsym();
            decl1(sc, sp);
            break;
        case openpa:
            if (nodeclfunc)
                break;
            getsym();
            if (declclass && head->type == bt_consplaceholder)
            {
                if (!defaulttype || currentfunc)
                    gensymerror(ERR_CANTHAVETYPE, declclass->name);
                strcpy(declid, cpp_funcname_tab[CI_CONSTRUCTOR]);
                cppflags |= PF_CONSTRUCTOR;
                declclass->value.classdata.cppflags |= PF_HASCONS;
                head = tail = maketype(bt_void, 0);
                backup(openpa);
            }
            else if (lastst == and && prm_cplusplus)
            {
                getsym();
                decl1(sc, sp);
                needpunc(closepa, 0);
                decl2(sc, sp);
                temp1 = maketype(bt_ref, stdaddrsize);
                temp1->btp =  *headptr;
                *headptr = temp1;
                if (tail == NULL)
                    tail = head1;
            }
            else if (lastst == star || lastst == kw_const || lastst ==
                kw_volatile || lastst == kw__far || lastst == kw__stdcall ||
                lastst == kw__pascal || lastst == kw__cdecl || lastst ==
                kw__seg)
            {
                temp1 = head1;
                temp2 = tail;
                decl1(sc, sp);
                if ((*headptr)->btp)
                {
                    for (temp1 =  *headptr; temp1->btp && temp1->btp != head1;
                        temp1 = temp1->btp)
                        ;
                    headptr = &temp1->btp;
                }
                else
                    if (head->type == bt_memberptr)
                        headptr = &head->btp;
                    else
                        headptr = &head;
                needpunc(closepa, 0);
            }
            else if (prm_cplusplus && lastst == id && (typesp = typesearch
                (lastid)))
            {
                getsym();
                if (lastst == lt)
                {
                    if (!(typesp = typesearch(lastid)) || typesp->storage_class
                        != sc_type || !typesp->istemplate)
                    {
                        generror(ERR_INVALIDTEMPLATE, 0, &skm_tempend);
                        tplskm(skm_tempend);
                    }
                    else
                    {
                        typesp = lookupTemplateType(typesp,cppflags);
                        if (lastst != classsel && lastst != classselstar)
                        {
                            generror(ERR_INVALIDTEMPLATE, 0, 0);
                            tplskm(skm_tempend);
                        }
                    }
                }
                typesp = parsetype(typesp, TRUE);
                if (lastst == id)
                {
                    decl1(sc, sp);
                    needpunc(closepa, &skm_declend);
                    if (head->type == bt_func)
                    {
                        if (prm_cplusplus && lastst == colon || lastst == begin
                            || castbegin(lastst) || lastst == kw_register ||
                            lastst == kw_const || lastst == kw_volatile ||
                            lastst == kw_restrict)
                            head->type = bt_ifunc;
                    }
                    break;
                }
                else if (lastst != classselstar)
                {
                    generror(ERR_EXPMEMBERPTRFUNC, 0, skm_declend);
                    break;
                }
                else
                {
                    getsym();
                    if (lastst == id)
                    {
                        strcpy(declid, lastid);
                        getsym();
                    }
                    else
                        declid[0] = 0;
                    memberptr = TRUE;
                    temp1 = maketype(bt_memberptr, stdmemberptrsize);
                    temp1->btp = head; 
                        // will be overwritten if they define the thing right
                    temp1->sp = typequal;
                    *headptr = temp1;
                    decl1(sc, sp);
                    if ((*headptr)->btp)
                    {
                        for (temp1 =  *headptr; temp1->btp && temp1->btp !=
                            head1; temp1 = temp1->btp)
                            ;
                        headptr = &temp1->btp;
                    }
                    else
                        if (head->type == bt_memberptr)
                            headptr = &head->btp;
                        else
                            headptr = &head;
                    typequal = 0;
                    needpunc(closepa, skm_declend);
                }
            }
            else if (lastst == id && !castbegin(lastst))
            {
                decl1(sc, sp);
                needpunc(closepa, skm_declend);
                goto lp;
                break;
            }
            else
            {
                backup(openpa);
            }
            decl2(sc, sp);
            break;
        default:
            if (inprototype)
                decl2(sc, sp);
            break;
    }
    return sp;
}

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

    /* Some overloaded functions require a member of type class */
    int isclassarg(SYM *sp)
    {
        SYM *head = sp->tp->lst.head;
        while (head && head != (SYM*) - 1)
        {
            TYP *tp = head->tp;
            while (tp->type == bt_ref)
                tp = tp->btp;
            if (isstructured(tp) || tp->type == bt_templateplaceholder)
                return TRUE;
            head = head->next;
        }
        return FALSE;
    }
    /* Depending on the type of function being overloaded, there are
     * different error checks to be performed
     */
    void CheckOverloadedArgs(SYM *sp)
    {
        int argcount = 0;
        SYM *head = sp->tp->lst.head;
        while (head && head != (SYM*) - 1)
        {
            argcount++;
            head = head->next;
        }
        switch (sp->value.i)
        {
            case ov_new:
            case ov_newa:

                if (!sp->tp->lst.head || sp->tp->lst.head->tp->type !=
                    bt_unsigned)
                    generror(ERR_SIZE_T_NEW, 0, 0);
                //            else
                //               if (sp->tp->btp->type != bt_pointer && sp->tp->type != bt_farpointer &&sp->tp->btp->type != bt_segpointer || sp->tp->btp->btp->type != bt_void)
                //                  generror(ERR_VOIDSTAR_NEW,0,0);
                break;
            case ov_delete:
            case ov_deletea:
                //     if (argcount != 1)
                //           gensymerror(ERR_DECL1ARG,sp->name);
                //        else
                if (!sp->tp->lst.head || sp->tp->lst.head->tp->type !=
                    bt_pointer && sp->tp->lst.head->tp->type != bt_farpointer
                    && sp->tp->btp->type != bt_segpointer || sp->tp->lst.head
                    ->tp->btp->type != bt_void)
                    generror(ERR_VOIDSTAR_DELETE, 0, 0);
                else
                    if (sp->tp->btp->type != bt_void)
                        generror(ERR_VOID_DELETE, 0, 0);
                break;
            case ov_div:
            case ov_shl:
            case ov_shr:
            case ov_mod:
            case ov_lor:
            case ov_land:
            case ov_or:
            case ov_xor:
            case ov_equ:
            case ov_neq:
            case ov_lt:
            case ov_le:
            case ov_gt:
            case ov_ge:
            case ov_asn:
            case ov_aasadd:
            case ov_assub:
            case ov_asmul:
            case ov_asdiv:
            case ov_asmod:
            case ov_asshl:
            case ov_asshr:
            case ov_asand:
            case ov_asor:
            case ov_asxor:
                if (typequal || declclass)
                {
                    if (argcount != 1)
                        gensymerror(ERR_DECL1ARG, sp->name);
                }
                else
                    if (argcount != 2)
                        gensymerror(ERR_DECL2ARG, sp->name);
                    else
                        if (!isclassarg(sp))
                            gensymerror(ERR_OPERATORMUSTCLASS, sp->name);
                break;

            case ov_and:
            case ov_mul:
            case ov_add:
            case ov_sub:
                if (typequal || declclass)
                {
                    if (argcount > 1)
                        gensymerror(ERR_DECL1ARG, sp->name);
                }
                else

⌨️ 快捷键说明

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