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

📄 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 页
字号:
    {
        allocated = TRUE;
        nbytes = 0;
        if ((tp->btp->type == bt_char || tp->btp->type == bt_unsignedchar) &&
            lastst == sconst)
        {
            canpad = TRUE;
            while (lastst == lsconst || lastst == sconst)
            {
                if (lastst == sconst) {
                    p = laststr;
                    while (laststrlen--)
                    {
                        nbytes++;
                        agflush(1,  *p++);
                    }
                } else {
                    p = laststr;
                    while (laststrlen--)
                    {
                        nbytes++;
                        agflush(1,  *((short *)p)++);
                    }
                }
                getsym();
            }
            if (has_begin)
                needpunc(end, skm_declend);
            agflush(1, 0);
            nbytes++;
        }
        else if ((tp->btp->type == bt_short || tp->btp->type ==
            bt_unsignedshort) && lastst == lsconst)
        {
            while (lastst == lsconst || lastst == sconst)
            {
                if (lastst == lsconst) {
                    short *p = laststr;
                    while (laststrlen--)
                    {
                        nbytes += 2;
                        agflush(2,  *p++);
                    }
                } else {
                    char *p = laststr;
                    while (laststrlen--)
                    {
                        nbytes += 2;
                        agflush(2, *p++);
                    }
                }
                getsym();
            }
            if (has_begin)
                needpunc(end, skm_declend);
            agflush(2, 0);
            nbytes += 2;
        }
        else
            generror(ERR_PUNCT, semicolon, 0);
    }
    else
    {
        if (begin_nesting == 1 && !has_begin)
            generror(ERR_PUNCT,(int)begin,0) ;
        size = tp->size/tp->btp->size ;
        if (size ==0)
            maxsize = 50;
        sizearray = xalloc(sizeof(struct decldata *) * (size == 0 ? maxsize : size));
        while (lastst != end && lastst != eof)
        {
            if (prm_cplusplus && isstructured(tp->btp) && search
                (cpp_funcname_tab[CI_CONSTRUCTOR], &tp->btp->lst))
            {
                if (!strcmp(lastid, tp->btp->sp->name))
                {
                    TYP *tp1;
                    ENODE *qn;
                    getsym();
                    if (lastst == openpa)
                    {
                        getsym();
                        tp1 = gatherparms(&qn, FALSE);
                        headptr = &head;
                        head = tp->btp;
                        conspair(locsp, sc_global,  - 1, tp1, qn, FALSE, nbytes,
                            FALSE);
                        parm_ns_level--;
                        nbytes += tp->btp->size;
                    }
                    else
                    {
                        backup(id);
                        goto join;
                    }
                }
                else
                {
                    ENODE *qn;
                    TYP *tp2;
                    join: tp2 = exprnc(&qn);
                    if (tp2)
                    {
                        SYM *sm;
                        TYP *tp1 = maketype(bt_func, 0);
                        qn = makenode(en_void, qn, 0);
                        sm = makesym(0);
                        tp1->lst.head = tp1->lst.tail = sm;
                        sm->tp = tp2;
                        headptr = &head;
                        head = tp->btp;
                        conspair(locsp, sc_global,  - 1, tp1, qn, FALSE, nbytes,
                            TRUE);
                        nbytes += tp->btp->size;
                    }
                    else
                        generror(ERR_ILLINIT, 0, 0);
                }
            }
            else {
                if (prm_c99 && lastst == openbr) 
                {
                    int l;
                    getsym() ;
                    l = intexpr(0);
                    index = l;
                    needpunc(closebr,0);
                    needpunc(assign,0);
                }
                    if (index >= size) 
                    {
                        if (maxsize == -1) 
                        {
                            index = 0;
                            generror(ERR_INITSIZE, 0, 0);
                        } 
                        else
                        {
                            size = index + 1 ;
                            if (size > maxsize)
                            {
                                struct decldata *newarray ;
                                int oldsize = maxsize;
                                maxsize = size + 50 ;
                                
                                newarray = xalloc(sizeof(struct decldata *) * maxsize);
                                memcpy(newarray,sizearray,sizeof(struct decldata *) * oldsize) ;
                                sizearray = newarray;
                            }  
                        }
                    }
                sptr = &sizearray[index];
                *sptr = 0;
                inittype(tp->btp);
                index++;
            }
            if (maxsize == -1 && !has_begin && index >= size)
                break;
            if (lastst == comma)
                getsym();
            else if (lastst != end)
            {
                expecttoken(end, 0);
                break;
            }
        }
        if (has_begin)
            needpunc(end,0);
      
        sptr = osptr;
        nbytes = 0 ;
        for (index=0;index < size;index++) 
        {
            *sptr = sizearray[index];
            while (*sptr) {
                switch((*sptr)->mode) 
                {
                    case dd_byte:
                        nbytes++;
                        ;
                        break;
                    case dd_word:
                        nbytes += stdshortsize;
                        break;
	                case dd_enum:
        	            nbytes += stdenumsize;
            	        break;
					case dd_int:
						nbytes += stdintsize ;
						break;
                    case dd_long:
                        nbytes += stdlongsize;
                        break;
                    case dd_longlong:
                        nbytes += stdlonglongsize;
                        break;
                    case dd_float:
                        nbytes += stdfloatsize;
                        break;
                    case dd_double:
                        nbytes += stddoublesize;
                        break;
                    case dd_ldouble:
                        nbytes += stdldoublesize;
                        break;
                    case dd_fcomplex:
                        nbytes += stdfloatsize * 2;
                        break;
                    case dd_rcomplex:
                        nbytes += stddoublesize * 2;
                        break;
                    case dd_lrcomplex:
                        nbytes += stdldoublesize * 2;
                        break;
                    case dd_pcname:
                        nbytes += stdaddrsize;
                        break;
                    case dd_dataname:
                        nbytes += stdaddrsize;
                        break;
                    case dd_storage:
                        nbytes += (*sptr)->val.i;
                        break;
                    case dd_label:
                        nbytes += stdaddrsize;
                        break;
                    case dd_farpointer:
                        nbytes += stdaddrsize + stdshortsize;
                        break;
                }
                sptr = &(*sptr)->link;
            }
            if (nbytes < tp->btp->size)
                makestorage(tp->btp->size-nbytes);
            nbytes = 0 ;            
        }
        nbytes = size * tp->btp->size;
    }
    if (nbytes < tp->size)
    {
        if (prm_cplusplus && isstructured(tp->btp) && search
            (cpp_funcname_tab[CI_CONSTRUCTOR], &tp->btp->lst))
        {
            int num = (tp->size - nbytes) / tp->btp->size;
            TYP *tp1 = maketype(bt_func, 0);
            ENODE *qn = makenode(en_void, 0, 0);
            tp1->lst.head = tp1->lst.tail =  - 1;
            conspair(locsp, sc_global,  - num, tp1, qn, FALSE, nbytes, TRUE);
        }
        else
        {
            nl();
            makestorage(tp->size - nbytes);
        }
        nbytes = tp->size;
    }
    else if (tp->size == 0)
        tp->size = nbytes;
    else if (nbytes > tp->size && (!canpad || nbytes > tp->size + 1) && !(tp->cflags & DF_FLEXARRAY))
        generror(ERR_INITSIZE, 0, 0);
     /* too many initializers */
    return nbytes;
}

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

int initunion(TYP *tp)
{
    int nbytes=0, has_begin = TRUE;
    struct decldata **osptr = sptr;
    SYM *sp = tp->lst.head;
    if (begin_nesting == 1)
    {
        if (!needpunc(begin,skm_declend))
            return tp->size;       
    }
    else
        if (lastst == begin)
            getsym() ;
        else
            has_begin = FALSE;
    if (prm_c99 && lastst == dot) 
    {
        getsym() ;
        if (lastst == id) 
        {
            SYM *sp1 = tp->lst.head ;
            while (sp1) {
                if (!strcmp(sp1->name,lastid)) 
                    break ;
                sp1 = sp1->next;
            }
            if (!sp1)
                gensymerror(ERR_UNDEFINED,lastid) ;
            else
                sp = sp1;
            getsym();
            needpunc(assign,0);
        }
        else
            gensymerror(ERR_UNDEFINED,lastid) ;
    } 
    sptr = &sp->init;
    sp->init = 0;
    inittype(sp->tp);

    sp = tp->lst.head; /* start at top of symbol table */
    sptr = osptr;
    while (sp) {
        *sptr = sp->init;
        while (*sptr) {
            switch((*sptr)->mode) 
            {
                case dd_byte:
                    nbytes++;
                    ;
                    break;
                case dd_word:
                    nbytes += stdshortsize;
                    break;
                case dd_enum:
       	            nbytes += stdenumsize;
           	        break;
				case dd_int:
					nbytes += stdintsize ;
					break;
                case dd_long:
                    nbytes += stdlongsize;
                    break;
                case dd_longlong:
                    nbytes += stdlonglongsize;
                    break;
                case dd_float:
                    nbytes += stdfloatsize;
                    break;
                case dd_double:
                    nbytes += stddoublesize;
                    break;
                case dd_ldouble:
                    nbytes += stdldoublesize;
                    break;
                case dd_fcomplex:
                    nbytes += stdfloatsize * 2;
                    break;
                case dd_rcomplex:
                    nbytes += stddoublesize * 2;
                    break;
                case dd_lrcomplex:
                    nbytes += stdldoublesize * 2;
                    break;
                case dd_pcname:
                    nbytes += stdaddrsize;
                    break;
                case dd_dataname:
                    nbytes += stdaddrsize;
                    break;
                case dd_storage:
                    nbytes += (*sptr)->val.i;
                    break;
                case dd_label:
                    nbytes += stdaddrsize;
                    break;
                case dd_farpointer:
                    nbytes += stdaddrsize + stdshortsize;
                    break;
            }
            sptr = &(*sptr)->link;
        }
        if (sp->init) 
        {
            sp->init = 0;
            break;
        }
        sp = sp->next;
    }
    if (has_begin)
        needpunc(end, 0);
    if (nbytes < tp->size)
        makestorage(tp->size - nbytes);
    return tp->size;
}

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

int initstruct(TYP *tp)
/*
 * Init for structures
 */
{
    SYM *sp;
    struct decldata *osptr = sptr;
    int nbytes;
    int has_begin = TRUE;
    if (prm_cplusplus && lastst == id)
    {
        if (lastst != id)
            generror(ERR_IDEXPECT, 0, skm_declend);
        else
        {
            ENODE *ep1,  *ep2;
            TYP *tp2;
            ep1 = makenode(en_nacon, (void*)locsp, 0);
            if (tp->val_flag == 0)
                tp = deref(&ep1, tp);
            tp2 = exprnc(&ep2);
            if (!exactype(tp, tp2, FALSE))
                cppcast(tp2, tp, &ep2, FALSE);
            if (ep2->nodetype == en_callblock)
            {
                ep2->v.p[0] = ep1;
                ep1 = ep2;
            }
            else
            {
                ep1 = makenode(en_moveblock, ep1, ep2);
                ep1->size = tp->size;
            }
            cppinitinsert(ep1);
        }
        return tp->size;
    }
    if (begin_nesting == 1)
    {
        if (!needpunc(begin,skm_declend))
            return tp->size;       
    }
    else
        if (lastst == begin)
            getsym() ;
        else
            has_begin = FALSE;
    nbytes = 0;
    sp = tp->lst.head; /* start at top of symbol table */
    if (lastst == end)
        generror(ERR_ILLINIT,0,0);
    while (lastst != end && lastst != eof)
    {
        if (prm_c99 && lastst == dot) 
        {
            getsym() ;
            if (lastst == id) 
            {
                SYM *sp1 = tp->lst.head ;
                while (sp1) {

⌨️ 快捷键说明

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