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

📄 init.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 5 页
字号:
                case dd_fcomplex:
                    genfloat(decldata->val.f[0]);
                    genfloat(decldata->val.f[1]);
                    nbytes += stdfloatsize * 2;
                    break;
                case dd_rcomplex:
                    gendouble(decldata->val.f[0]);
                    gendouble(decldata->val.f[1]);
                    nbytes += stddoublesize * 2;
                    break;
                case dd_lrcomplex:
                    genlongdouble(decldata->val.f[0]);
                    genlongdouble(decldata->val.f[1]);
                    nbytes += stdldoublesize * 2;
                    break;
                case dd_pcname:
                    genpcref(decldata->val.sp, decldata->offset);
                    nbytes += stdaddrsize;
                    break;
                case dd_dataname:
                    genref(decldata->val.sp, decldata->offset);
                    nbytes += stdaddrsize;
                    break;
                case dd_storage:
                    genstorage(decldata->val.i);
                    nbytes += decldata->val.i;
                    break;
                case dd_label:
                    gen_labref(decldata->val.i);
                    nbytes += stdaddrsize;
                    break;
                case dd_farpointer:
                    genlong(decldata->val.i &0xffffffff);
                    #if sizeof(ULLONG_TYPE) == 4
                        genword(0);
                    #else 
                        genword(decldata->val.i >> 32);
                    #endif 
                    nbytes += stdaddrsize + stdshortsize;
                    break;
            }
            decldata = decldata->link;
        }
    }
    else
    {
        if (sp->tp->size == 0) 
            gensymerror(ERR_ZEROSTORAGE, sp->name);
        else
            genstorage(nbytes += sp->tp->size);
    }
    nl();
    return nbytes;
}

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

static long gen(SYM *sp)
{
    if (sp->storage_class == sc_global)
    {
        globaldef(sp);
    }
    if (sp->staticlabel)
        put_staticlabel(sp->value.i);
    else
        gen_strlab(sp);
    return gen2(sp);
}

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

    void cppinitinsert(ENODE *node)
    /*
     * insert an initialization function on the list
     */
    {
        if (!cpprefhead)
        {
            cpprefhead = node;
            cppreftail = &cpprefhead;
        }
        else
        {
            *cppreftail = makenode(en_void,  *cppreftail, node);
            cppreftail = &(*cppreftail)->v.p[1];
        }
    }
    void cpprundowninsert(ENODE *node)
    {
        if (cpprefrundown)
            cpprefrundown = makenode(en_void, node, cpprefrundown);
        else
            cpprefrundown = node;
    }
    void cppinitassign(ENODE *node)
    {
        ENODE *node1 = makenode(en_a_ref, makenode(en_nacon, locsp, 0), 0);
        if (node->nodetype == en_void || node->nodetype == en_dvoid)
        {
            ENODE **n2 = actualexpr(&node);
            if (n2)
                (*n2)->v.p[0] = makenode(en_assign, node1, (*n2)->v.p[0]);
            else
            {
                DIAG("cppinitassign: can't find actual node");
            }
            node1 = node;
        }
        else
        {
            node1 = makenode(en_assign, node1, node);
        }
        cppinitinsert(node1);
    }
void insert_decl_sp(SYM *sp)
{
    struct declares *p;
    SYM *spx = sp->parentclass;
    if (sp->indecltable)
    {
        return ;
    } 
    while (spx)
    {
        if (spx->istemplate)
            return ;
        spx = spx->parentclass;
    }
    p = xalloc(sizeof(struct declares));
    p->sp = sp;
    p->link = 0;
    if (virtualdata)
    {
        if (virtualdecl)
            virtualdecltail = virtualdecltail->link = p;
        else
            virtualdecl = virtualdecltail = p;
    } 
    else if (declarations)
        decltail = decltail->link = p;
    else
        decltail = declarations = p;
    sp->indecltable = TRUE;
    if (sp->parentclass)
    {
        LIST *l = xalloc(sizeof(LIST));
        l->data = sp;
        l->link = localfuncs;
        localfuncs = l;
    }

}

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

void ReshuffleDeclsp(SYM *sp)
{
    struct declares **p = &declarations;
    while (*p)
        if ((*p)->sp == sp)
            break;
        else
            p = &(*p)->link;
    if (*p)
    {
        struct declares *r =  *p;
        if (decltail == r)
            return ;
        *p = (*p)->link;
        r->link = 0;
        decltail = decltail->link = r;
    } 
}

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

void insertSpace(SYM *sp, int *bytes)
{
    if (bytes)
    {
        int align = alignment(sc_global, sp->tp);
        int val;
        if (!align)
            align = 1;
        val = align - (*bytes % align);
        if (val != align)
        {
            *bytes += val;
        }
        sp->offset =  *bytes;
        *bytes += sp->tp->size;
    }
}

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

int doinit(SYM *sp)
/*
 * Handle static variable initialize
 */
{
    int nbytes = 0,  *bytes = 0;
    int alreadyassigned = sp->indecltable, alreadyinitted = sp->init != 0;
    int reshuffle;
    begin_nesting = 0;
        if (currentTemplate)
        {
            expskim(skm_semicolon, FALSE);
            endinit();
            return sp->tp->size;
        }
        if (sp->value.classdata.gdeclare)
            sp = sp->value.classdata.gdeclare;
    if (currentfunc && (currentfunc->value.classdata.cppflags &PF_INLINE))
        if (!(sp->tp->cflags &DF_CONST) || (sp->tp->cflags &DF_VOL))
            if (prm_cplusplus)
                currentfunc->value.classdata.cppflags &= ~PF_INLINE;
            else
                generror(ERR_INLINENOSTATIC, 0, 0);

    typequal = 0;
    sp->tp->uflags |= UF_DEFINED;
    allocated = FALSE;
    baseoffs = 0;
    totbits = 0;
    curbitsize =  - 1;
    bits =  - 1;
    locsp = sp;
    sptr = &sp->init;
    reshuffle = sp->indecltable && !sp->init;
    if (!(sp->tp->cflags &DF_CONST) || (sp->tp->cflags &DF_VOL) ||
        !scalarnonfloat(sp->tp) || sp->storage_class != sc_static)
        insert_decl_sp(sp);
    {
        TYP *tp;
            int opened = FALSE;
            if (prm_cplusplus && lastst == openpa)
            {
                opened = TRUE;
                lastst = assign;
            }
        tp = sp->tp;
        if (tp->type == bt_pointer && !(tp->val_flag &VARARRAY))
            tp = tp->btp;
        if (tp->type == bt_pointer && (tp->val_flag &VARARRAY))
        {
            if (tp == sp->tp)
                generror(ERR_VLABLOCKSCOPE, 0, 0);
            else if (sp->storage_class != sc_static)
                generror(ERR_VMSTATIC, 0, 0);
            cppinitinsert(createVarArray(sp, tp, TRUE, tp == sp->tp));
            if (lastst == assign)
            {
                gensymerror(ERR_NOINIT, sp->name);
                endinit();
                return sp->tp->size;
            }
        }
        if (lastst == assign)
        {
            getsym();
            if (sp->init)
                gensymerror(ERR_MULTIPLEINIT, sp->name);
            if (sp->absflag)
            {
                generror(ERR_NOINIT, 0, skm_declend);
                return nbytes;
            }
            nbytes = inittype(sp->tp);
            *sptr = 0;
        }
        if (reshuffle && sp->init)
            ReshuffleDeclsp(sp);
            if (opened)
                needpunc(closepa, skm_declclosepa);
    }
    endinit();
    if (virtualdata)
        return nbytes;
    /* Have to calculate position and debug output info now
     * because of local statics
     */
    if (!(sp->tp->cflags &DF_CONST) || sp->tp->cflags &DF_VOL ||
        !scalarnonfloat(sp->tp) || sp->storage_class != sc_static)
    {
        if (!alreadyassigned || sp->init && !alreadyinitted)
        {
            if ((sp->tp->cflags &DF_CONST) && !(sp->tp->cflags &DF_VOL))
                bytes = &constbytes;
            else if ((sp->init || !prm_bss) && !sp->absflag)
                bytes = &databytes;
            else
                if (!sp->init && !sp->absflag)
                    bytes = &bssbytes;
            insertSpace(sp, bytes);
        }
    }
    if (structlevel)
    {
        if (sp->init)
            gensymerror(ERR_NOINIT, sp->name);
    }
    else if ((sp->tp->cflags &DF_CONST) && !sp->init && sp->storage_class !=
        sc_external && !sp->mainsym->constructed)
        generror(ERR_CONSTMUSTINIT, 0, 0);
    return nbytes;
}

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

int inittype(TYP *tp)
/*
 * Init for basic types
 */
{
    int nbytes;
    begin_nesting++;
    switch (tp->type)
    {

        case bt_float:
            nbytes = initfloat(FALSE);
            break;
        case bt_longdouble:
            nbytes = initlongdouble(FALSE);
            break;
        case bt_double:
            nbytes = initdouble(FALSE);
            break;
        case bt_fimaginary:
            nbytes = initfloat(TRUE);
            break;
        case bt_rimaginary:
            nbytes = initdouble(TRUE);
            break;
        case bt_lrimaginary:
            nbytes = initlongdouble(TRUE);
            break;
        case bt_fcomplex:
            nbytes = initfcomplex();
            break;
        case bt_rcomplex:
            nbytes = initrcomplex();
            break;
        case bt_lrcomplex:
            nbytes = initlrcomplex();
            break;
        case bt_bool:
			nbytes = initbool();
			break;
        case bt_char:
            nbytes = initchar();
            break;
        case bt_unsignedchar:
            nbytes = inituchar();
            break;
        case bt_unsignedshort:
            nbytes = initushort();
            break;
        case bt_short:
        case bt_segpointer:
            nbytes = initshort();
            break;
        case bt_farpointer:
            nbytes = initfarpointer();
            break;
        case bt_pointer:
            if (tp->btp->type == bt_func)
            {
                nbytes = initpointerfunc();
                break;
            }
            else if (tp->val_flag)
            // VARARRY doesn't get this far
                nbytes = initarray(tp);
            else
                nbytes = initpointer();
            break;
            case bt_ref:
                nbytes = initref(tp);
                break;
        case bt_unsigned:
            nbytes = inituint();
			break;
        case bt_unsignedlong:
            nbytes = initulong();
            break;
        case bt_enum:
            nbytes = initenum();
            break;
        case bt_int:
        case bt_matchall:
            nbytes = initint();
            break;
        case bt_long:
            nbytes = initlong();
            break;
        case bt_longlong:
            nbytes = initlonglong();
            break;
        case bt_unsignedlonglong:
            nbytes = initulonglong();
            break;
        case bt_struct:
            nbytes = initstruct(tp);
            break;
        case bt_union:
            nbytes = initunion(tp);
            break;
            case bt_memberptr:
                nbytes = initmemberptr(tp, tp->sp);
                break;
        default:
            gensymerror(ERR_NOINIT, locsp->name);
            nbytes = 0;
    }
    baseoffs += nbytes;
    begin_nesting--;
    return nbytes;
}

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

int initarray(TYP *tp)
/*
 * Init for arrays
 */
{
    struct decldata **osptr = sptr, **sizearray;
    int nbytes, maxsize = -1;
    int index=0,size;
    int canpad = FALSE;
    char *p;
    int has_begin = FALSE ;
    nbytes = 0;
    if (lastst == begin) {
        has_begin = TRUE ;
        getsym();
    }
    if ((tp->btp->type == bt_char || tp->btp->type == bt_unsignedchar) &&
        lastst == sconst 
        || (tp->btp->type == bt_short || tp->btp->type == bt_unsignedshort) &&
        lastst == lsconst)

⌨️ 快捷键说明

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