comparison mc-tree.c @ 711:35e6841ba01a

pointer fixes (partial)
author kono
date Sat, 27 Oct 2007 13:30:38 +0900 (2007-10-27)
parents e16b34f2b386
children bf94c295d763
comparison
equal deleted inserted replaced
710:4348f61a5e54 711:35e6841ba01a
306 return; 306 return;
307 } 307 }
308 if((tags=caddr(type))) { 308 if((tags=caddr(type))) {
309 fprintf(out,"{"); 309 fprintf(out,"{");
310 while(tags) { 310 while(tags) {
311 n=(NMTBL*)caddr(tags); 311 n=ncaddr(tags);
312 type_print(car(tags),n,out); 312 type_print(car(tags),n,out);
313 fprintf(out,";"); 313 fprintf(out,";");
314 tags = cadr(tags); 314 tags = cadr(tags);
315 } 315 }
316 fprintf(out,"}"); 316 fprintf(out,"}");
492 } 492 }
493 switch (car(e)%SOP) { 493 switch (car(e)%SOP) {
494 case LVAR: 494 case LVAR:
495 case RLVAR: 495 case RLVAR:
496 case URLVAR: 496 case URLVAR:
497 if ((nptr = (NMTBL*)caddr(e))) { 497 if ((nptr = ncaddr(e))) {
498 fprintf(vout,"%s",nptr->nm); 498 fprintf(vout,"%s",nptr->nm);
499 } else { 499 } else {
500 // anonymous variable 500 // anonymous variable
501 fprintf(vout,"_%d",caddr(e)); 501 fprintf(vout,"_%d",caddr(e));
502 } 502 }
503 break; 503 break;
504 case GVAR: 504 case GVAR:
505 case RGVAR: 505 case RGVAR:
506 case URGVAR: 506 case URGVAR:
507 if ((nptr = (NMTBL*)caddr(e))) { 507 if ((nptr = ncaddr(e))) {
508 fprintf(vout,"%s",nptr->nm); 508 fprintf(vout,"%s",nptr->nm);
509 } else { 509 } else {
510 // anonymous variable 510 // anonymous variable
511 fprintf(vout,"_%d",caddr(e)); 511 fprintf(vout,"_%d",caddr(e));
512 } 512 }
515 // certainly this is wrong 515 // certainly this is wrong
516 fprintf(vout,"+%d",caddr(e)); 516 fprintf(vout,"+%d",caddr(e));
517 } 517 }
518 break; 518 break;
519 case REGISTER: 519 case REGISTER:
520 if ((nptr = (NMTBL*)caddr(e))) { 520 if ((nptr = ncaddr(e))) {
521 fprintf(vout,"%s",nptr->nm); 521 fprintf(vout,"%s",nptr->nm);
522 } else { 522 } else {
523 // anonymous register variable 523 // anonymous register variable
524 fprintf(vout,"_%d",caddr(e)); 524 fprintf(vout,"_%d",caddr(e));
525 } 525 }
550 break; 550 break;
551 } 551 }
552 case STRING: 552 case STRING:
553 { 553 {
554 int c; char *s; int i; 554 int c; char *s; int i;
555 nptr = (NMTBL*)cadr(e); s = nptr->nm;i=nptr->dsp; 555 nptr = ncaddr(e); s = nptr->nm;i=nptr->dsp;
556 fprintf(vout,"\""); 556 fprintf(vout,"\"");
557 while(--i>0) { 557 while(--i>0) {
558 c=*s++; 558 c=*s++;
559 if(c=='\n') fprintf(vout,"\\n"); 559 if(c=='\n') fprintf(vout,"\\n");
560 else if(c=='\r') fprintf(vout,"\\r"); 560 else if(c=='\r') fprintf(vout,"\\r");
574 print_expr(caddr(e),vout); 574 print_expr(caddr(e),vout);
575 fprintf(vout,"]"); 575 fprintf(vout,"]");
576 break; 576 break;
577 case PERIOD: 577 case PERIOD:
578 print_expr(cadr(e),vout); 578 print_expr(cadr(e),vout);
579 n = (NMTBL*)caddr(e); 579 n = ncaddr(e);
580 fprintf(vout,".%s",n->nm); 580 fprintf(vout,".%s",n->nm);
581 break; 581 break;
582 case ARROW: 582 case ARROW:
583 print_expr(cadr(e),vout); 583 print_expr(cadr(e),vout);
584 n = (NMTBL*)caddr(e); 584 n = ncaddr(e);
585 fprintf(vout,"->%s",n->nm); 585 fprintf(vout,"->%s",n->nm);
586 break; 586 break;
587 case INDIRECT: 587 case INDIRECT:
588 case RINDIRECT: 588 case RINDIRECT:
589 case URINDIRECT: 589 case URINDIRECT:
590 fprintf(vout,"*"); 590 fprintf(vout,"*");
591 print_expr(cadr(e),vout); 591 print_expr(cadr(e),vout);
592 break; 592 break;
593 case FNAME: 593 case FNAME:
594 n = (NMTBL*)cadr(e); 594 n = ncaddr(e);
595 fprintf(vout,"%s",n->nm); 595 fprintf(vout,"%s",n->nm);
596 break; 596 break;
597 case FUNCTION: 597 case FUNCTION:
598 print_function_call(e,vout); 598 print_function_call(e,vout);
599 break; 599 break;
636 } 636 }
637 637
638 static void 638 static void
639 print_decl(int e, FILE *vout) 639 print_decl(int e, FILE *vout)
640 { 640 {
641 NMTBL *n = (NMTBL*)caddr(e); 641 NMTBL *n = ncaddr(e);
642 int e1 = cadddr(e); 642 int e1 = cadddr(e);
643 // int mode = car(e1); 643 // int mode = car(e1);
644 int stmode = cadr(e1); 644 int stmode = cadr(e1);
645 int ctmode = caddr(e1); 645 int ctmode = caddr(e1);
646 646
711 case ST_GOTO: 711 case ST_GOTO:
712 fprintf(vout,"goto "); break; 712 fprintf(vout,"goto "); break;
713 case ST_ASM: 713 case ST_ASM:
714 fprintf(vout,"__asm__ "); break; 714 fprintf(vout,"__asm__ "); break;
715 case ST_LABEL: 715 case ST_LABEL:
716 n = (NMTBL*)(caddr(caddr(e))); 716 n = ncaddr(caddr(e));
717 fprintf(vout,"%s:", n->nm); break; 717 fprintf(vout,"%s:", n->nm); break;
718 case ST_OP: 718 case ST_OP:
719 e1 = caddr(e); 719 e1 = caddr(e);
720 print_expr(list3(cadr(e),car(e1),cadr(e1)),vout); 720 print_expr(list3(cadr(e),car(e1),cadr(e1)),vout);
721 break; 721 break;
722 case ST_COMMENT: 722 case ST_COMMENT:
723 fprintf(vout,"\n# %s\n",(char*)caddr(e)); 723 fprintf(vout,"\n# %s\n",vcaddr(e));
724 break; 724 break;
725 default: 725 default:
726 fprintf(stderr,"Unknown Statement ID %d\n",car(e)); 726 fprintf(stderr,"Unknown Statement ID %d\n",car(e));
727 } 727 }
728 } 728 }
734 int e2,e3; 734 int e2,e3;
735 NMTBL *fn = 0; 735 NMTBL *fn = 0;
736 736
737 e2 = cadr(e1); 737 e2 = cadr(e1);
738 if (car(e2) == FNAME) { 738 if (car(e2) == FNAME) {
739 fn=(NMTBL *)cadr(e2); 739 fn=ncaddr(e2);
740 fprintf(vout,"%s",fn->nm); 740 fprintf(vout,"%s",fn->nm);
741 } else { 741 } else {
742 if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case 742 if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case
743 fprintf(vout,"("); 743 fprintf(vout,"(");
744 print_expr(e2,vout); 744 print_expr(e2,vout);