[BACK]Return to struct.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/struct.c, Revision 1.3

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3     ! noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.3     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/struct.c,v 1.2 2000/08/21 08:31:47 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "comp.h"
                     53:
                     54: struct oSS oLSS;
                     55: SS LSS = &oLSS;
                     56:
                     57: void structdef(name,member)
                     58: char *name;
                     59: NODE member;
                     60: {
                     61:        int i,j,k,type;
                     62:        SDEF sdef,s;
                     63:        NODE n,ms;
                     64:        char *mname,*sname;
                     65:
                     66:        for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                     67:                if ( !strcmp(s[i].name,name) ) {
                     68:                        fprintf(stderr,"redeclaration of %s\n",name); break;
                     69:                }
                     70:        if ( !LSS->sa || ((i == LSS->n)&&(LSS->n==LSS->asize)) )
                     71:                reallocarray((char **)&LSS->sa,(int *)&LSS->asize,(int *)&LSS->n,(int)sizeof(struct oSDEF));
                     72:        sdef = &LSS->sa[i];
                     73:        if ( i == LSS->n )
                     74:                LSS->n++;
                     75:        for ( i = 0, n = member; n; n = NEXT(n), i++ );
                     76:        sdef->name = (char *)MALLOC(strlen(name)+1);
                     77:        bcopy(name,sdef->name,strlen(name)+1);
                     78:        for ( j = 0, n = member; n; n = NEXT(n) )
                     79:                for ( ms = NEXT((NODE)BDY(n)); ms; ms = NEXT(ms), j++ );
                     80:        sdef->n = j;
                     81:        sdef->f = (struct oFIELD *)MALLOC(sdef->n*sizeof(struct oFIELD));
                     82:        for ( j = 0, n = member; n; n = NEXT(n) ) {
                     83:                ms = (NODE)BDY(n);
                     84:                if ( sname = (char *)BDY(ms) ) {
                     85:                        for ( s = LSS->sa, k = 0; k < LSS->n; k++ )
                     86:                                if ( !strcmp(s[k].name,sname) )
                     87:                                        break;
                     88:                        if ( k == LSS->n ) {
                     89:                                fprintf(stderr,"%s: undefined structure\n",sname); return;
                     90:                        } else
                     91:                                type = k;
                     92:                } else
                     93:                        type = -1;
                     94:                for ( ms = NEXT(ms); ms; ms = NEXT(ms), j++ ) {
                     95:                        mname = (char *)MALLOC(strlen(BDY(ms))+1);
                     96:                        bcopy(BDY(ms),mname,strlen(BDY(ms))+1);
                     97:                        sdef->f[j].name = mname; sdef->f[j].type = type;
                     98:                }
                     99:        }
                    100: }
                    101:
                    102: void setstruct(name,vars)
                    103: char *name;
                    104: NODE vars;
                    105: {
                    106:        SDEF s;
                    107:        int i;
                    108:        NODE n;
                    109:
                    110:        for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                    111:                if ( !strcmp(s[i].name,name) )
                    112:                        break;
                    113:        if ( i == LSS->n ) {
                    114:                fprintf(stderr,"%s: undefined structure\n",name); return;
                    115:        }
                    116:        s = &LSS->sa[i];
                    117:        for ( n = vars; n; n = NEXT(n) )
                    118:                CPVS->va[(int)BDY(n)].type = i;
                    119: }
                    120:
                    121: void newstruct(type,rp)
                    122: int type;
                    123: COMP *rp;
                    124: {
                    125:        NEWCOMP(*rp,LSS->sa[type].n); (*rp)->type = type;
                    126: }
                    127:
                    128: int structtoindex(name)
                    129: char *name;
                    130: {
                    131:        SDEF s;
                    132:        int i;
                    133:
                    134:        for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                    135:                if ( !strcmp(s[i].name,name) )
                    136:                        break;
                    137:        if ( i == LSS->n ) {
                    138:                fprintf(stderr,"%s: undefined structure\n",name); return -1; /* XXX */
                    139:        } else
                    140:                return i;
                    141: }
                    142:
                    143: int membertoindex(type,name)
                    144: int type;
                    145: char *name;
                    146: {
                    147:        SDEF s;
                    148:        FIELD f;
                    149:        int i;
                    150:
                    151:        s = &LSS->sa[type];
                    152:        for ( f = s->f, i = 0; i < s->n; i++ )
                    153:                if ( !strcmp(f[i].name,name) )
                    154:                        break;
                    155:        if ( i == s->n ) {
                    156:                fprintf(stderr,"structure has no member named `%s'\n",name);
                    157:                return -1;
                    158:        } else
                    159:                return i;
                    160: }
                    161:
                    162: int indextotype(type,index)
                    163: int type,index;
                    164: {
                    165:        return LSS->sa[type].f[index].type;
                    166: }
                    167:
                    168: int gettype(index)
                    169: unsigned int index;
                    170: {
                    171:        if ( MSB & index )
                    172:                return (int)GPVS->va[index&~MSB].type;
                    173:        else
                    174:                return (int)CPVS->va[index].type;
                    175: }
                    176:
                    177: int getcompsize(type)
                    178: int type;
                    179: {
                    180:        return LSS->sa[type].n;
                    181: }
                    182:
                    183: void getmember(expr,memp)
                    184: FNODE expr;
                    185: Obj *memp;
                    186: {
                    187:        int i;
                    188:        FNODE root;
                    189:        COMP t;
                    190:        PV v0;
                    191:        NODE2 mchain;
                    192:
                    193:        root = (FNODE)FA1(expr); mchain = (NODE2)FA2(expr);
                    194:        if ( ID(root) == I_PVAR ) {
                    195:                i = (int)FA0(root);
                    196:                v0 = i>=0?&CPVS->va[(unsigned int)i]:&GPVS->va[((unsigned int)i)&~MSB];
                    197:                t = (COMP)v0->priv;
                    198:        } else
                    199:                t = (COMP)eval(root);
                    200:        for ( ; mchain; mchain = NEXT(mchain) )
                    201:                t = (COMP)(t->member[(int)BDY1(mchain)]);
                    202:        *memp = (Obj)t;
                    203: }
                    204:
                    205: void getmemberp(expr,addrp)
                    206: FNODE expr;
                    207: Obj **addrp;
                    208: {
                    209:        int i;
                    210:        FNODE root;
                    211:        COMP t;
                    212:        PV v0;
                    213:        COMP *addr;
                    214:        NODE2 mchain;
                    215:
                    216:        root = (FNODE)FA1(expr); mchain = (NODE2)FA2(expr);
                    217:        if ( ID(root) == I_PVAR ) {
                    218:                i = (int)FA0(root);
                    219:                v0 = i>=0?&CPVS->va[(unsigned int)i]:&GPVS->va[((unsigned int)i)&~MSB];
                    220:                addr = (COMP *)&v0->priv;
                    221:        } else {
                    222:                t = (COMP)eval(root);
                    223:                addr = (COMP *)&t;
                    224:        }
                    225:        for ( ; mchain; mchain = NEXT(mchain) )
                    226:                addr = (COMP *)&((*addr)->member[(int)BDY1(mchain)]);
                    227:        *addrp = (Obj *)addr;
                    228: }
                    229:
                    230: void getarrayp(a,ind,addrp)
                    231: Obj a;
                    232: NODE ind;
                    233: Obj **addrp;
                    234: {
                    235:        Obj len,row,col;
                    236:        Obj *addr;
                    237:
                    238:        switch ( OID(a) ) {
                    239:                case O_VECT:
                    240:                        len = (Obj)BDY(ind);
                    241:                        if ( !rangecheck(len,((VECT)a)->len) )
                    242:                                error("getarrayp : Out of range");
                    243:                        else
                    244:                                addr = (Obj *)&(BDY((VECT)a)[QTOS((Q)len)]);
                    245:                        break;
                    246:                case O_MAT:
                    247:                        row = (Obj)BDY(ind); col = (Obj)BDY(NEXT(ind));
                    248:                        if ( !rangecheck(row,((MAT)a)->row)
                    249:                                || !rangecheck(col,((MAT)a)->col) )
                    250:                                error("getarrayp : Out of range");
                    251:                        else
                    252:                                addr = (Obj *)&(BDY((MAT)a)[QTOS((Q)row)][QTOS((Q)col)]);
                    253:                        break;
                    254:                default:
                    255:                                addr = 0;
                    256:                        break;
                    257:        }
                    258:        *addrp = addr;
                    259: }
                    260:
                    261: void memberofstruct(pexpr,name,exprp)
                    262: FNODE pexpr;
                    263: char *name;
                    264: FNODE *exprp;
                    265: {
                    266:        NODE2 n,*np;
                    267:        int type,ind;
                    268:
                    269:        if ( pexpr->id != I_CAST ) {
                    270:                if ( pexpr->id == I_PVAR )
                    271:                        pexpr = (FNODE)mkfnode(3,I_CAST,gettype((unsigned int)pexpr->arg[0]),pexpr,0);
                    272:                else
                    273:                        error("memberofstruct : ???");
                    274:        }
                    275:        if ( !pexpr->arg[2] ) {
                    276:                np = (NODE2 *)&(pexpr->arg[2]); type = (int)pexpr->arg[0];
                    277:        } else {
                    278:                for ( n = (NODE2)pexpr->arg[2]; NEXT(n); n = NEXT(n) );
                    279:                np = &NEXT(n); type = (int)BDY2(n);
                    280:        }
                    281:        ind = membertoindex(type,name);
                    282:        MKNODE2(*np,ind,indextotype(type,ind),0);
                    283:        *exprp = pexpr;
                    284: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>