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

📄 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 页
字号:
                ep3 = ep->v.p[0];
                ep4 = ep->v.p[1];
                while (castvalue(ep3))
                    ep3 = ep3->v.p[0];
                while (castvalue(ep4))
                    ep4 = ep4->v.p[0];
                if (!arr(ep3))
                {
                    generror(ERR_NEEDCONST, 0, 0);
                }
                else
                {
                    if (lvalue(ep3))
                        ep3 = ep3->v.p[0];
                    if (arr(ep4))
                        generror(ERR_NEEDCONST, 0, 0);
                    else if (isintconst(ep4->nodetype))
                    {
                        makeref(ep3->nodetype == en_napccon ? 1 : 0, ((SYM*)
                            (ep3->v.sp)),  - ep4->v.i);
                    }
                    else if (isfloatconst(ep4->nodetype))
                    {
                        makeref(ep3->nodetype == en_napccon ? 1 : 0, ((SYM*)
                            (ep3->v.sp)),  - ep4->v.f);
                    }
                    else
                        generror(ERR_NEEDCONST, 0, 0);
                }
            }
            else
            {
                generror(ERR_NEEDCONST, 0, 0);
            }
        }
    }
    return done;
}

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

long cppint(int size)
{
    TYP *t1;
    ENODE *ep;
    LLONG_TYPE val = 0;
    int done = TRUE;
    allocated = TRUE;
        if (!prm_cplusplus)
    {
        done = intconstinit(0, &val);
    }
        else
        {
            int began = 0;
            done = FALSE;
            if (lastst == begin)
            {
                began++;
                getsym();
            }
            t1 = exprnc(&ep);
            opt4(&ep);
            if (began)
                needpunc(end, 0);
            if (!ep)
            {
                generror(ERR_ILLINIT, 0, 0);
                return 0;
            }
            if (isintconst(ep->nodetype))
                val = ep->v.i;
            else if (isfloatconst(ep->nodetype))
                val = ep->v.f;
            else
            {
                val = 0;
                if (!isscalar(t1) || !ep)
                    generror(ERR_NEEDCONST, 0, 0);
                else
                {
                    ENODE *node1;
                    int typ;
                    switch (size)
                    {
                        case  - 8: typ = en_ll_ref;
                        break;
                        case 8:
                            typ = en_ull_ref;
                            break;
                            case  - 4: typ = en_l_ref;
                            break;
                        case 4:
                            typ = en_ul_ref;
                            break;
                            case  - 2: typ = en_w_ref;
                            break;
                        case 2:
                            typ = en_uw_ref;
                            break;
                            case  - 1: typ = en_b_ref;
                            break;
                        case 1:
                            typ = en_ub_ref;
                            break;
                    }
                    cppinitassign(ep);
                    #ifdef XXXXX
                        node1 = makenode(typ, makenode(en_nacon, locsp, 0), 0);
                        node1 = makenode(en_assign, node1, ep);
                        cppinitinsert(node1);
                    #endif 
                }
            }
        }
    if (size < 0)
        size =  - size;
    #ifdef XXXXX
        switch (0 *size)
        {
            case 1:
                if ((unsigned)val < 0 || (unsigned)val > UCHAR_MAX)
                    generror(ERR_CONSTTOOLARGE, 0, 0);
                break;
                case  - 1: if (val < SCHAR_MIN || val > SCHAR_MAX)
                    generror(ERR_CONSTTOOLARGE, 0, 0);
                break;
            case 2:
                if ((unsigned)val < 0 || (unsigned)val > USHRT_MAX)
                    generror(ERR_CONSTTOOLARGE, 0, 0);
                break;
                case  - 2: if (val < SHRT_MIN || val > SHRT_MAX)
                    generror(ERR_CONSTTOOLARGE, 0, 0);
                break;
                case  - 4: 
                //         if (val < INT_MIN || val > INT_MAX)
                //           generror(ERR_CONSTTOOLARGE,0,0) ;
                break;
            case 4:
                //         if (val < 0 ||val > UINT_MAX)
                //            generror(ERR_CONSTTOOLARGE,0,0) ;
            case 8:
            case  - 8: default:
                break;
        }
    #endif 
    if (!done)
        return agbits(size, val);
    else
        return stdaddrsize;
}

/* Basic type subroutines */
int initfcomplex(void)
{
    struct decldata *q = xalloc(sizeof(struct decldata));
    TYP *tpx;
    ENODE *en=0;
    LLONG_TYPE val =0;
    tpx = exprnc(&en);
    opt4(&en);
    if (en) {
        if (isintconst(en->nodetype))
        {
            q->val.f[0] = en->v.i;
            q->val.f[1] = 0.0;
        }
        else if (isfloatconst(en->nodetype))
        {
            q->val.f[0] = en->v.f;
            q->val.f[1] = 0.0;
        }
        else if (isimaginaryconst(en->nodetype))
        {
            q->val.f[0] = 0.0;
            q->val.f[1] = en->v.f;
        }
        else if (iscomplexconst(en->nodetype))
        {
            q->val.f[0] = en->v.c.r;
            q->val.f[1] = en->v.c.i;
        }
        else if (prm_cplusplus)
        {
            cppinitassign(en);
            return 8;
        }
        else
            generror(ERR_ILLINIT, 0, 0);
    }
    *sptr = q;
    sptr = &(*sptr)->link;
    q->mode = dd_fcomplex;
    return (stdfloatsize * 2);
}

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

int initlrcomplex(void)
{
    struct decldata *q = xalloc(sizeof(struct decldata));
    TYP *tpx;
    ENODE *en=0;
    LLONG_TYPE val =0;
    tpx = exprnc(&en);
    opt4(&en);
    if (en) {
        if (isintconst(en->nodetype))
        {
            q->val.f[0] = en->v.i;
            q->val.f[1] = 0.0;
        }
        else if (isfloatconst(en->nodetype))
        {
            q->val.f[0] = en->v.f;
            q->val.f[1] = 0.0;
        }
        else if (isimaginaryconst(en->nodetype))
        {
            q->val.f[0] = 0.0;
            q->val.f[1] = en->v.f;
        }
        else if (iscomplexconst(en->nodetype))
        {
            q->val.f[0] = en->v.c.r;
            q->val.f[1] = en->v.c.i;
        }
        else if (prm_cplusplus)
        {
            cppinitassign(en);
            return 20;
        }
        else
            generror(ERR_ILLINIT, 0, 0);
    }
    *sptr = q;
    sptr = &(*sptr)->link;
    q->mode = dd_lrcomplex;
    return (stdldoublesize * 2);
}

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

int initrcomplex(void)
{
    struct decldata *q = xalloc(sizeof(struct decldata));
    TYP *tpx;
    ENODE *en=0;
    LLONG_TYPE val =0;
    tpx = exprnc(&en);
    opt4(&en);
    if (en) {
        if (isintconst(en->nodetype))
        {
            q->val.f[0] = en->v.i;
            q->val.f[1] = 0.0;
        }
        else if (isfloatconst(en->nodetype))
        {
            q->val.f[0] = en->v.f;
            q->val.f[1] = 0.0;
        }
        else if (isimaginaryconst(en->nodetype))
        {
            q->val.f[0] = 0.0;
            q->val.f[1] = en->v.f;
        }
        else if (iscomplexconst(en->nodetype))
        {
            q->val.f[0] = en->v.c.r;
            q->val.f[1] = en->v.c.i;
        }
        else if (prm_cplusplus)
        {
            cppinitassign(en);
            return 16;
        }
        else
            generror(ERR_ILLINIT, 0, 0);
    }
    *sptr = q;
    sptr = &(*sptr)->link;
    q->mode = dd_rcomplex;
    return (stddoublesize * 2);
}

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

int initfloat(int imaginary)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    long double rval = cppfloat(6,imaginary);
#if sizeof(LLONG_TYPE) == 8
    if (rval != INFINITY)
#endif
        if (rval > FLT_MAX)
        {
            generror(ERR_FPCON,0,0);
            rval = FLT_MAX;
        }
        else if (rval < - FLT_MAX) 
        {
            generror(ERR_FPCON,0,0);
            rval = -FLT_MAX;
        }
    q->val.f[0] = rval;
    sptr = &(*sptr)->link;
    q->mode = dd_float;
    return (stdfloatsize);
}

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

int initlongdouble(int imaginary)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    q->val.f[0] = cppfloat(10,imaginary);
    sptr = &(*sptr)->link;
    q->mode = dd_ldouble;
    return (stdldoublesize);
}

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

int initdouble(int imaginary)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
    long double rval = cppfloat(8,imaginary);
#if sizeof(LLONG_TYPE) == 8
    if (rval != INFINITY)
#endif
        if (rval > DBL_MAX)
        {
            generror(ERR_FPCON,0,0);
            rval = DBL_MAX;
        }
        else if (rval < - DBL_MAX) 
        {
            generror(ERR_FPCON,0,0);
            rval = -DBL_MAX;
        }
    q->val.f[0] = rval;
    sptr = &(*sptr)->link;
    q->mode = dd_double;
    return (stddoublesize);
}

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

int initchar(void)
{
    int rv;
    rv = cppint( - 1);
    return rv;
}
int initbool(int imaginary)
{
    struct decldata *q =  *sptr = xalloc(sizeof(struct decldata));
	LLONG_TYPE ival;
    intconstinit(0, &ival);
    q->val.i = !!ival;
    sptr = &(*sptr)->link;
    q->mode = dd_bool;
    return (1);
}

int initshort(void)
{
    int rv;
    rv = cppint( - stdshortsize);
    return rv;
}

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

int inituchar(void)
{
    int rv;
    rv = cppint(1);
    return rv;
}

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

int initushort(void)
{
    int rv;
    rv = cppint(stdshortsize);
    return rv;
}

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

int initint(void)
{
    int rv;
    rv = cppint( - stdintsize);
    return rv;
}

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

int inituint(void)
{
    int rv;
    rv = cppint(stdintsize);
    return rv;
}
int initlong(void)
{
    int rv;
    rv = cppint( - stdlongsize);
    return rv;
}

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

int initulong(void)
{
    int rv;
    rv = cppint(stdlongsize);
    return rv;
}

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

int initlonglong(void)
{
    int rv;
    rv = cppint( - stdlonglongsize);
    return rv;
}

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

int initulonglong(void)
{
    int rv;
    rv = cppint(stdlonglongsize);
    return 

⌨️ 快捷键说明

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