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