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

Annotation of OpenXM_contrib2/asir2000/io/cpexpr.c, Revision 1.27

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

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