Annotation of OpenXM_contrib2/asir2000/io/cpexpr.c, Revision 1.29
1.3 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.4 noro 26: * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3 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.
1.29 ! noro 47: * $OpenXM: OpenXM_contrib2/asir2000/io/cpexpr.c,v 1.28 2017/08/31 02:36:21 noro Exp $
1.3 noro 48: */
1.1 noro 49: #include "ca.h"
50: #include "parse.h"
1.2 noro 51: #include "al.h"
1.1 noro 52: #include "base.h"
53:
1.21 noro 54: #ifndef CPRINT
55: #define CPRINT
56: #endif
57:
1.8 noro 58: extern int hex_output,fortran_output,double_output,real_digit;
1.21 noro 59: extern int hideargs,outputstyle;
60: static int total_length;
1.2 noro 61:
1.1 noro 62: #define TAIL
63: #define PUTS(s) (total_length+=strlen(s))
64: #define PRINTN length_n
1.2 noro 65: #define PRINTBF length_bf
1.1 noro 66: #define PRINTCPLX length_cplx
1.2 noro 67: #define PRINTLM length_lm
68: #define PRINTUP2 length_up2
1.1 noro 69: #define PRINTV length_v
70: #define PRINTEXPR length_expr
71: #define PRINTNUM length_num
72: #define PRINTP length_p
73: #define PRINTR length_r
74: #define PRINTLIST length_list
75: #define PRINTVECT length_vect
76: #define PRINTMAT length_mat
77: #define PRINTSTR length_str
78: #define PRINTCOMP length_comp
79: #define PRINTDP length_dp
1.28 noro 80: #define PRINTDPM length_dpm
1.2 noro 81: #define PRINTUI length_ui
82: #define PRINTGF2MAT length_gf2mat
83: #define PRINTGFMMAT length_gfmmat
1.5 noro 84: #define PRINTBYTEARRAY length_bytearray
1.11 noro 85: #define PRINTQUOTE length_QUOTE
1.23 noro 86: #define PRINTQUOTEARG length_QUOTEARG
1.17 noro 87: #define PRINTSYMBOL length_SYMBOL
88: #define PRINTRANGE length_RANGE
1.18 noro 89: #define PRINTTB length_TB
1.22 noro 90: #define PRINTDPV length_DPV
1.25 noro 91: #define PRINTNBP length_nbp
1.2 noro 92: #define PRINTERR length_err
93: #define PRINTLF length_lf
94: #define PRINTLOP length_lop
95: #define PRINTFOP length_fop
96: #define PRINTEOP length_eop
97: #define PRINTQOP length_qop
98: #define PRINTUP length_up
1.12 noro 99: #define PRINTUM length_um
100: #define PRINTSF length_sf
1.19 noro 101: #define PRINTFARGS length_fargs
102: #define PRINTFNODENODE length_fnodenode
103: #define PRINTFNODE length_fnode
1.1 noro 104:
1.21 noro 105: #include "pexpr_body.c"
106:
107: /* special functions for estimating length */
1.1 noro 108:
109: static int total_length;
110:
1.13 noro 111: int estimate_length(VL vl,pointer p)
1.1 noro 112: {
1.29 ! noro 113: total_length = 0;
! 114: PRINTEXPR(vl,p);
! 115: return total_length;
1.1 noro 116: }
117:
1.13 noro 118: void PRINTBF(BF a)
1.2 noro 119: {
1.29 ! noro 120: char *str;
! 121: int dprec;
! 122: char fbuf[BUFSIZ];
! 123:
! 124: dprec = a->body->_mpfr_prec*0.30103;
! 125: sprintf(fbuf,"%%.%dR%c",dprec,double_output?'f':'g');
! 126: mpfr_asprintf(&str,fbuf,a->body);
! 127: total_length += strlen(str);
! 128: mpfr_free_str(str);
1.2 noro 129: }
130:
1.13 noro 131: void PRINTNUM(Num q)
1.1 noro 132: {
1.29 ! noro 133: DAlg d;
! 134: DP nm;
! 135: Q dn;
! 136:
! 137: if ( !q ) {
! 138: PUTS("0");
! 139: return;
! 140: }
! 141: switch ( NID(q) ) {
! 142: case N_Q:
! 143: if ( SGN((Q)q) == -1 )
! 144: PUTS("-");
! 145: PRINTN(NM((Q)q));
! 146: if ( !INT((Q)q) ) {
! 147: PUTS("/"); PRINTN(DN((Q)q));
! 148: }
! 149: break;
! 150: case N_R:
! 151: if ( double_output )
! 152: total_length += 400+real_digit; /* XXX */
! 153: else
! 154: total_length += 20+real_digit; /* XXX */
! 155: break;
! 156: case N_A:
! 157: PUTS("("); PRINTR(ALG,(R)BDY((Alg)q)); PUTS(")");
! 158: break;
! 159: case N_B:
! 160: PRINTBF((BF)q); break;
! 161: case N_C:
! 162: PRINTCPLX((C)q); break;
! 163: case N_M:
! 164: total_length += 11; /* XXX */
! 165: break;
! 166: case N_LM:
! 167: PRINTN(((LM)q)->body); break;
! 168: case N_GF2N:
! 169: if ( hex_output )
! 170: PRINTN((N)(((GF2N)q)->body));
! 171: else
! 172: PRINTUP2(((GF2N)q)->body);
! 173: break;
! 174: case N_GFPN:
! 175: PRINTUP((UP)(((GFPN)q)->body));
! 176: break;
! 177: case N_GFS:
! 178: total_length += 13; /* XXX */
! 179: break;
! 180: case N_GFSN:
! 181: PRINTUM(BDY((GFSN)q));
! 182: break;
! 183: case N_DA:
! 184: d = (DAlg)q;
! 185: nm = d->nm;
! 186: dn = d->dn;
! 187: if ( SGN((Q)dn) == -1 ) PUTS("-");
! 188: PUTS("(");
! 189: PRINTDP(CO,((DAlg)q)->nm);
! 190: PUTS(")");
! 191: if ( !UNIN(NM(dn)) ) {
! 192: PUTS("/");
! 193: PRINTN(NM(dn));
! 194: }
! 195: break;
! 196: default:
! 197: break;
! 198: }
1.1 noro 199: }
200:
1.13 noro 201: void PRINTV(VL vl,V v)
1.1 noro 202: {
1.29 ! noro 203: PF pf;
! 204: PFAD ad;
! 205: int i;
! 206:
! 207: if ( NAME(v) )
! 208: PUTS(NAME(v));
! 209: else if ( (vid)v->attr == V_PF ) {
! 210: pf = ((PFINS)v->priv)->pf; ad = ((PFINS)v->priv)->ad;
! 211: if ( !strcmp(NAME(pf),"pow") ) {
! 212: PUTS("(("); PRINTR(vl,(R)ad[0].arg); PUTS(")"); PRINTHAT; PUTS("(");
! 213: PRINTR(vl,(R)ad[1].arg); PUTS("))");
! 214: } else if ( !pf->argc )
! 215: PUTS(NAME(pf));
! 216: else {
! 217: if ( hideargs ) {
! 218: for ( i = 0; i < pf->argc; i++ )
! 219: if ( ad[i].d )
! 220: break;
! 221: if ( i < pf->argc ) {
! 222: PUTS(NAME(pf));
! 223: total_length += 11; /* XXX */
! 224: for ( i = 1; i < pf->argc; i++ ) {
! 225: total_length += 11; /* XXX */
! 226: }
! 227: PUTS("}");
! 228: } else {
! 229: PUTS(NAME(pf));
! 230: total_length += 1; /* XXX */
! 231: }
! 232: } else {
! 233: for ( i = 0; i < pf->argc; i++ )
! 234: if ( ad[i].d )
! 235: break;
! 236: if ( i < pf->argc ) {
! 237: PUTS(NAME(pf));
! 238: total_length += 11; /* XXX */
! 239: for ( i = 1; i < pf->argc; i++ ) {
! 240: total_length += 11; /* XXX */
! 241: }
! 242: PUTS(")(");
! 243: } else {
! 244: PUTS(NAME(pf));
! 245: total_length += 1; /* XXX */
! 246: }
! 247: PRINTR(vl,(R)ad[0].arg);
! 248: for ( i = 1; i < pf->argc; i++ ) {
! 249: PUTS(","); PRINTR(vl,(R)ad[i].arg);
! 250: }
! 251: PUTS(")");
! 252: }
! 253: }
! 254: }
1.1 noro 255: }
256:
1.21 noro 257: void PRINTN(N n)
1.1 noro 258: {
1.29 ! noro 259: double ceil();
1.21 noro 260:
1.29 ! noro 261: if ( !n )
! 262: PUTS("0");
! 263: else if ( hex_output )
! 264: total_length += 2+(int)(PL(n)*8);
! 265: else
! 266: total_length += (int)(ceil(0.31*((double)(BSH*PL(n))))+1);
1.1 noro 267: }
268:
1.13 noro 269: void PRINTSTR(STRING str)
1.1 noro 270: {
1.29 ! noro 271: char *p;
1.1 noro 272:
1.29 ! noro 273: for ( p = BDY(str); *p; p++ )
! 274: if ( *p == '"' )
! 275: PUTS("\"");
! 276: else {
! 277: total_length += 1;
! 278: }
1.1 noro 279: }
280:
1.13 noro 281: void PRINTDP(VL vl,DP d)
1.1 noro 282: {
1.29 ! noro 283: int n,i;
! 284: MP m;
! 285: DL dl;
! 286:
! 287: for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
! 288: PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
! 289: for ( i = 0, dl = m->dl; i < n-1; i++ ) {
! 290: total_length += 11;
! 291: }
! 292: total_length += 10;
! 293: PUTS(">>");
! 294: if ( NEXT(m) )
! 295: PUTS("+");
! 296: }
1.2 noro 297: }
298:
1.28 noro 299: void PRINTDPM(VL vl,DPM d)
300: {
1.29 ! noro 301: int n,i;
! 302: DMM m;
! 303: DL dl;
! 304:
! 305: for ( n = d->nv, m = BDY(d); m; m = NEXT(m) ) {
! 306: PUTS("("); PRINTEXPR(vl,(pointer)m->c); PUTS(")*<<");
! 307: for ( i = 0, dl = m->dl; i < n-1; i++ ) {
! 308: total_length += 11;
! 309: }
! 310: total_length += 10;
! 311: total_length += 11; /* for ':pos' */
! 312: PUTS(">>");
! 313: if ( NEXT(m) )
! 314: PUTS("+");
! 315: }
1.28 noro 316: }
317:
318:
1.13 noro 319: void PRINTUI(VL vl,USINT u)
1.2 noro 320: {
1.29 ! noro 321: total_length += 10;
1.2 noro 322: }
323:
1.13 noro 324: void PRINTGFMMAT(VL vl,GFMMAT mat)
1.2 noro 325: {
1.29 ! noro 326: int row,col,i,j;
! 327: unsigned int **b;
1.2 noro 328:
1.29 ! noro 329: row = mat->row;
! 330: col = mat->col;
! 331: b = mat->body;
! 332: for ( i = 0; i < row; i++ ) {
! 333: PUTS("[");
! 334: for ( j = 0; j < col; j++ ) {
! 335: total_length += 10; /* XXX */
! 336: }
! 337: PUTS("]\n");
! 338: }
1.5 noro 339: }
340:
1.13 noro 341: void PRINTBYTEARRAY(VL vl,BYTEARRAY array)
1.5 noro 342: {
1.29 ! noro 343: /* |xx xx ... xx| */
! 344: total_length += 1+3*array->len;
1.11 noro 345: }
346:
1.19 noro 347: extern int print_quote;
348:
1.13 noro 349: void PRINTQUOTE(VL vl,QUOTE quote)
1.11 noro 350: {
1.29 ! noro 351: LIST list;
1.19 noro 352:
1.29 ! noro 353: if ( print_quote == 2 ) {
! 354: PRINTFNODE(BDY(quote),0);
! 355: } else if ( print_quote == 1 ) {
! 356: /* XXX */
! 357: fnodetotree(BDY(quote),&list);
! 358: PRINTEXPR(vl,(Obj)list);
! 359: } else {
! 360: /* <...quoted...> */
! 361: total_length += 20;
! 362: }
1.23 noro 363: }
364:
365: void PRINTQUOTEARG(VL vl,QUOTEARG quote)
366: {
1.29 ! noro 367: /* XXX */
! 368: /* <...quoted...> */
! 369: total_length += 20;
1.17 noro 370: }
371:
372: void PRINTSYMBOL(SYMBOL sym)
373: {
1.29 ! noro 374: total_length += strlen(sym->name);
1.17 noro 375: }
376:
1.18 noro 377: void PRINTTB(VL vl,TB p)
378: {
1.29 ! noro 379: int i;
1.18 noro 380:
1.29 ! noro 381: for ( i = 0; i < p->next; i++ ) {
! 382: total_length += strlen(p->body[i]);
! 383: }
1.2 noro 384: }
385:
1.13 noro 386: void PRINTUP2(UP2 p)
1.2 noro 387: {
1.29 ! noro 388: int d,i;
1.2 noro 389:
1.29 ! noro 390: if ( !p ) {
! 391: PUTS("0");
! 392: } else {
! 393: d = degup2(p);
! 394: PUTS("(");
! 395: if ( !d ) {
! 396: PUTS("1");
! 397: } else if ( d == 1 ) {
! 398: PUTS("@");
! 399: } else {
! 400: PRINTHAT;
! 401: total_length += 11;
! 402: }
! 403: for ( i = d-1; i >= 0; i-- ) {
! 404: if ( p->b[i/BSH] & (1<<(i%BSH)) )
! 405: if ( !i ) {
! 406: PUTS("+1");
! 407: } else if ( i == 1 ) {
! 408: PUTS("+@");
! 409: } else {
! 410: PRINTHAT;
! 411: total_length += 12;
! 412: }
! 413: }
! 414: PUTS(")");
! 415: }
1.2 noro 416: }
417:
1.13 noro 418: void PRINTQOP(VL vl,F f)
1.2 noro 419: {
1.29 ! noro 420: char *op;
1.2 noro 421:
1.29 ! noro 422: op = FOP(f)==AL_EX?"ex":"all";
! 423: PUTS(op); PUTS(NAME(FQVR(f)));
! 424: total_length += 2;
! 425: PRINTEXPR(vl,(Obj)FQMAT(f)); PUTS(")");
1.2 noro 426: }
427:
1.13 noro 428: void PRINTUP(UP n)
1.2 noro 429: {
1.29 ! noro 430: int i,d;
1.2 noro 431:
1.29 ! noro 432: if ( !n )
! 433: PUTS("0");
! 434: else if ( !n->d )
! 435: PRINTNUM(n->c[0]);
! 436: else {
! 437: d = n->d;
! 438: PUTS("(");
! 439: if ( !d ) {
! 440: PRINTNUM(n->c[d]);
! 441: } else if ( d == 1 ) {
! 442: PRINTNUM(n->c[d]);
! 443: PUTS("*@p");
! 444: } else {
! 445: PRINTNUM(n->c[d]);
! 446: PRINTHAT;
! 447: total_length += 13;
! 448: }
! 449: for ( i = d-1; i >= 0; i-- ) {
! 450: if ( n->c[i] ) {
! 451: PUTS("+("); PRINTNUM(n->c[i]); PUTS(")");
! 452: if ( i >= 2 ) {
! 453: PRINTHAT;
! 454: total_length += 13;
! 455: } else if ( i == 1 )
! 456: PUTS("*@p");
! 457: }
! 458: }
! 459: PUTS(")");
! 460: }
1.12 noro 461: }
462:
1.13 noro 463: void PRINTUM(UM n)
1.12 noro 464: {
1.29 ! noro 465: int i,d;
1.12 noro 466:
1.29 ! noro 467: if ( !n )
! 468: PUTS("0");
! 469: else if ( !n->d )
! 470: PRINTSF(n->c[0]);
! 471: else {
! 472: d = n->d;
! 473: PUTS("(");
! 474: if ( !d ) {
! 475: PRINTSF(n->c[d]);
! 476: } else if ( d == 1 ) {
! 477: PRINTSF(n->c[d]);
! 478: PUTS("*@s");
! 479: } else {
! 480: PRINTSF(n->c[d]);
! 481: PUTS("*@s"); PRINTHAT; total_length += 13;
! 482: }
! 483: for ( i = d-1; i >= 0; i-- ) {
! 484: if ( n->c[i] ) {
! 485: PUTS("+("); PRINTSF(n->c[i]); PUTS(")");
! 486: if ( i >= 2 ) {
! 487: PUTS("*@s"); PRINTHAT; total_length += 13;
! 488: } else if ( i == 1 )
! 489: PUTS("*@s");
! 490: }
! 491: }
! 492: PUTS(")");
! 493: }
1.25 noro 494: }
495:
496: void PRINTNBP(VL vl,NBP p)
497: {
1.29 ! noro 498: NODE t;
! 499: NBM m;
! 500: int d,i;
! 501: unsigned int *b;
! 502: if ( !p ) PUTS("0");
! 503: else {
! 504: for ( t = BDY(p); t; t = NEXT(t) ) {
! 505: m = (NBM)BDY(t);
! 506: PRINTEXPR(vl,(Obj)m->c);
! 507: d = m->d;
! 508: b = m->b;
! 509: if ( d )
! 510: for ( i = 0; i < d; i++ ) {
! 511: if ( NBM_GET(b,i) ) PUTS("x");
! 512: else PUTS("y");
! 513: }
! 514: else PUTS("1");
! 515: if ( NEXT(t) ) PUTS("+");
! 516: }
! 517: }
1.12 noro 518: }
519:
1.13 noro 520: void PRINTSF(unsigned int i)
1.12 noro 521: {
1.29 ! noro 522: if ( !i ) {
! 523: PUTS("0");
! 524: } else
! 525: total_length += 15;
1.19 noro 526:
1.21 noro 527: #ifndef CPRINT
528: #define CPRINT
529: #endif
1.1 noro 530: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>