Annotation of OpenXM_contrib2/asir2018/builtin/var.c, Revision 1.1
1.1 ! 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
! 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
! 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: *
! 48: * $OpenXM$
! 49: */
! 50: #include "ca.h"
! 51: #include "parse.h"
! 52:
! 53: void Pvar(), Pvars(), Puc(), Pvars_recursive(),Psimple_is_eq();
! 54: void Pdelete_uc();
! 55:
! 56: struct ftab var_tab[] = {
! 57: {"var",Pvar,1},
! 58: {"vars",Pvars,1},
! 59: {"vars_recursive",Pvars_recursive,1},
! 60: {"uc",Puc,0},
! 61: {"delete_uc",Pdelete_uc,-1},
! 62: {"simple_is_eq",Psimple_is_eq,2},
! 63: {0,0,0},
! 64: };
! 65:
! 66: void Psimple_is_eq(NODE arg,Z *rp)
! 67: {
! 68: int ret;
! 69:
! 70: ret = is_eq(ARG0(arg),ARG1(arg));
! 71: STOQ(ret,*rp);
! 72: }
! 73:
! 74: int is_eq(Obj a0,Obj a1)
! 75: {
! 76: P p0,p1;
! 77: DCP dc0,dc1;
! 78:
! 79: if ( !a0 ) return a1?0:1;
! 80: else if ( !a1 ) return 0;
! 81: else if ( OID(a0) != OID(a1) ) return 0;
! 82: else {
! 83: switch ( OID(a0) ) {
! 84: case O_P:
! 85: p0 = (P)a0; p1 = (P)a1;
! 86: if ( VR(p0) == VR(p1) ) {
! 87: for ( dc0 = DC(p0), dc1 = DC(p1); dc0 && dc1; dc0 = NEXT(dc0), dc1 = NEXT(dc1) ) {
! 88: if ( cmpz(DEG(dc0),DEG(dc1)) ) return 0;
! 89: if ( !is_eq((Obj)COEF(dc0),(Obj)COEF(dc1)) ) return 0;
! 90: }
! 91: return (dc0||dc1)?0:1;
! 92: } else return 0;
! 93: break;
! 94: default:
! 95: return !arf_comp(CO,a0,a1);
! 96: break;
! 97: }
! 98: }
! 99: }
! 100:
! 101: void Pvar(NODE arg,Obj *rp)
! 102: {
! 103: Obj t;
! 104: P p;
! 105: V vn,vd,v;
! 106: VL vl;
! 107:
! 108: if ( !(t = (Obj)ARG0(arg)) )
! 109: v = 0;
! 110: else
! 111: switch ( OID(t) ) {
! 112: case O_P:
! 113: v = VR((P)t); break;
! 114: case O_R:
! 115: vn = VR(NM((R)t)); vd = VR(DN((R)t));
! 116: for ( vl = CO; (vl->v != vn) && (vl->v != vd); vl = NEXT(vl) );
! 117: v = vl->v; break;
! 118: default:
! 119: v = 0; break;
! 120: }
! 121: if ( v ) {
! 122: MKV(v,p); *rp = (Obj)p;
! 123: } else
! 124: *rp = 0;
! 125: }
! 126:
! 127: void Pvars(NODE arg,LIST *rp)
! 128: {
! 129: VL vl;
! 130: NODE n,n0;
! 131: P p;
! 132:
! 133: get_vars((Obj)ARG0(arg),&vl);
! 134: for ( n0 = 0; vl; vl = NEXT(vl) ) {
! 135: NEXTNODE(n0,n); MKV(vl->v,p); BDY(n) = (pointer)p;
! 136: }
! 137: if ( n0 )
! 138: NEXT(n) = 0;
! 139: MKLIST(*rp,n0);
! 140: }
! 141:
! 142: void Pvars_recursive(NODE arg,LIST *rp)
! 143: {
! 144: VL vl;
! 145: NODE n,n0;
! 146: P p;
! 147:
! 148: get_vars_recursive((Obj)ARG0(arg),&vl);
! 149: for ( n0 = 0; vl; vl = NEXT(vl) ) {
! 150: NEXTNODE(n0,n); MKV(vl->v,p); BDY(n) = (pointer)p;
! 151: }
! 152: if ( n0 )
! 153: NEXT(n) = 0;
! 154: MKLIST(*rp,n0);
! 155: }
! 156:
! 157: void get_vars_recursive(Obj obj,VL *vlp)
! 158: {
! 159: VL vl,vl0,vl1,vl2,t;
! 160: PFINS ins;
! 161: int argc,i;
! 162: PFAD ad;
! 163:
! 164: get_vars(obj,&vl);
! 165: vl0 = 0;
! 166: for ( t = vl; t; t = NEXT(t) )
! 167: if ( t->v->attr == (pointer)V_PF ) {
! 168: ins = (PFINS)t->v->priv;
! 169: argc = ins->pf->argc;
! 170: ad = ins->ad;
! 171: for ( i = 0; i < argc; i++ ) {
! 172: get_vars_recursive(ad[i].arg,&vl1);
! 173: mergev(CO,vl0,vl1,&vl2); vl0 = vl2;
! 174: }
! 175: }
! 176: mergev(CO,vl,vl0,vlp);
! 177: }
! 178:
! 179: void get_vars(Obj t,VL *vlp)
! 180: {
! 181: pointer *vb;
! 182: pointer **mb;
! 183: VL vl,vl1,vl2;
! 184: NODE n;
! 185: MP mp;
! 186: int i,j,row,col,len;
! 187:
! 188: if ( !t )
! 189: vl = 0;
! 190: else
! 191: switch ( OID(t) ) {
! 192: case O_P: case O_R:
! 193: clctvr(CO,t,&vl); break;
! 194: case O_VECT:
! 195: len = ((VECT)t)->len; vb = BDY((VECT)t);
! 196: for ( i = 0, vl = 0; i < len; i++ ) {
! 197: get_vars((Obj)vb[i],&vl1); mergev(CO,vl,vl1,&vl2);
! 198: vl = vl2;
! 199: }
! 200: break;
! 201: case O_MAT:
! 202: row = ((MAT)t)->row; col = ((MAT)t)->col; mb = BDY((MAT)t);
! 203: for ( i = 0, vl = 0; i < row; i++ )
! 204: for ( j = 0; j < col; j++ ) {
! 205: get_vars((Obj)mb[i][j],&vl1); mergev(CO,vl,vl1,&vl2);
! 206: vl = vl2;
! 207: }
! 208: break;
! 209: case O_LIST:
! 210: n = BDY((LIST)t);
! 211: for ( vl = 0; n; n = NEXT(n) ) {
! 212: get_vars((Obj)BDY(n),&vl1); mergev(CO,vl,vl1,&vl2);
! 213: vl = vl2;
! 214: }
! 215: break;
! 216: case O_DP:
! 217: mp = ((DP)t)->body;
! 218: for ( vl = 0; mp; mp = NEXT(mp) ) {
! 219: get_vars((Obj)mp->c,&vl1); mergev(CO,vl,vl1,&vl2);
! 220: vl = vl2;
! 221: }
! 222: break;
! 223: case O_NBP:
! 224: n = BDY((NBP)t);
! 225: for ( vl = 0; n; n = NEXT(n) ) {
! 226: get_vars((Obj)(((NBM)BDY(n))->c),&vl1);
! 227: mergev(CO,vl,vl1,&vl2);
! 228: vl = vl2;
! 229: }
! 230: break;
! 231: default:
! 232: vl = 0; break;
! 233: }
! 234: *vlp = vl;
! 235: }
! 236:
! 237: void Puc(Obj *p)
! 238: {
! 239: VL vl;
! 240: V v;
! 241: P t;
! 242: char buf[BUFSIZ];
! 243: char *n,*nv;
! 244: static int UCN;
! 245:
! 246: NEWV(v); v->attr = (pointer)V_UC;
! 247: sprintf(buf,"_%d",UCN++);
! 248: nv = NAME(v) = (char *)CALLOC(strlen(buf)+1,sizeof(char));
! 249: strcpy(NAME(v),buf);
! 250: for ( vl = CO; vl; vl = NEXT(vl) )
! 251: if ( (n=NAME(VR(vl))) && !strcmp(n,nv) ) break;
! 252: else if ( !NEXT(vl) ) {
! 253: NEWVL(NEXT(vl)); VR(NEXT(vl)) = v; NEXT(NEXT(vl)) = 0;
! 254: LASTCO = NEXT(vl);
! 255: break;
! 256: }
! 257: MKV(v,t); *p = (Obj)t;
! 258: }
! 259:
! 260: void Pdelete_uc(NODE arg,Obj *p)
! 261: {
! 262: VL vl,prev;
! 263: V v;
! 264:
! 265: if ( argc(arg) == 1 ) {
! 266: asir_assert(ARG0(arg),O_P,"delete_uc");
! 267: v = VR((P)ARG0(arg));
! 268: } else
! 269: v = 0;
! 270:
! 271: for ( prev = 0, vl = CO; vl; vl = NEXT(vl) ) {
! 272: if ( (!v || v == vl->v) && vl->v->attr == (pointer)V_UC ) {
! 273: if ( prev == 0 )
! 274: CO = NEXT(vl);
! 275: else
! 276: NEXT(prev) = NEXT(vl);
! 277: } else
! 278: prev = vl;
! 279: }
! 280: update_LASTCO();
! 281: *p = 0;
! 282: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>