/[ascend]/trunk/base/generic/compiler/relation_io.c
ViewVC logotype

Diff of /trunk/base/generic/compiler/relation_io.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 668 by johnpye, Fri Mar 31 08:52:57 2006 UTC revision 669 by johnpye, Wed Jun 21 07:00:45 2006 UTC
# Line 42  Line 42 
42  #include "dimen.h"  #include "dimen.h"
43  #include "functype.h"  #include "functype.h"
44  #include "func.h"  #include "func.h"
45  #include "types.h"  #include "expr_types.h"
46  #include "extcall.h"  #include "extcall.h"
47  #include "instance_enum.h"  #include "instance_enum.h"
48  #include "extfunc.h"  #include "extfunc.h"
# Line 758  void WriteSide(FILE *f, Line 758  void WriteSide(FILE *f,
758    }    }
759  }  }
760    
761  /* write a side in infix */  /**
762        write a side in infix notation
763    */
764  static  static
765  void WriteSideDS(Asc_DString *dsPtr, CONST struct relation *r, int side,  void WriteSideDS(Asc_DString *dsPtr, CONST struct relation *r, int side,
766                   CONST struct Instance *ref, WRSNameFunc func, void *userdata,                   CONST struct Instance *ref, WRSNameFunc func, void *userdata,
# Line 781  void WriteSideDS(Asc_DString *dsPtr, CON Line 783  void WriteSideDS(Asc_DString *dsPtr, CON
783      pos = PopRelation();    /* check the top */      pos = PopRelation();    /* check the top */
784      term = RelationTerm(r,pos,side);      term = RelationTerm(r,pos,side);
785      t = RelationTermType(term);      t = RelationTermType(term);
786      switch (t) {      switch (t) {
787        case e_diff:
788          /*cur_var = RelationVariable(r,TermVarNumber(term));
789          Asc_DStringAppend(dsPtr,"DIFF(",-1);
790          WriteInstanceNameDS(dsPtr,cur_var,ref);
791          Asc_DStringAppend(dsPtr,")",-1);*/
792          Asc_DStringAppend(dsPtr,"DIFF(__something__)",-1);
793          ERROR_REPORTER_HERE(ASC_PROG_WARNING,"e_diff relation term not implemented");
794          break;
795      case e_var:      case e_var:
796        if (func == NULL) {        if (func == NULL) {
797          cur_var = RelationVariable(r,TermVarNumber(term));          cur_var = RelationVariable(r,TermVarNumber(term));
# Line 827  void WriteSideDS(Asc_DString *dsPtr, CON Line 837  void WriteSideDS(Asc_DString *dsPtr, CON
837      case e_func:      case e_func:
838        if(first) {        if(first) {
839          if (lang == relio_C) {          if (lang == relio_C) {
840        sprintf(SB255,"%s(",FuncCName(TermFunc(term)));            sprintf(SB255,"%s(",FuncCName(TermFunc(term)));
841          } else {          } else {
842        sprintf(SB255,"%s(",FuncName(TermFunc(term)));            sprintf(SB255,"%s(",FuncName(TermFunc(term)));
843          }          }
844          Asc_DStringAppend(dsPtr,SB255,-1);          Asc_DStringAppend(dsPtr,SB255,-1);
845      PushRelation(pos,0,NOLHS);          PushRelation(pos,0,NOLHS);
846      PushRelation(pos-1,1,NOLHS);          PushRelation(pos-1,1,NOLHS);
847        }        }
848        else{        else{
849          Asc_DStringAppend(dsPtr,")",1);          Asc_DStringAppend(dsPtr,")",1);
# Line 853  void WriteSideDS(Asc_DString *dsPtr, CON Line 863  void WriteSideDS(Asc_DString *dsPtr, CON
863            } else {            } else {
864              Asc_DStringAppend(dsPtr,"asc_ipow((",10);              Asc_DStringAppend(dsPtr,"asc_ipow((",10);
865            }            }
866        PushRelation(pos,2,NOLHS);            PushRelation(pos,2,NOLHS);
867        lhs = LeftHandSide(r,pos,side);            lhs = LeftHandSide(r,pos,side);
868        PushRelation(lhs,1,NOLHS);            PushRelation(lhs,1,NOLHS);
869        break;        break;
870          case 2:          case 2:
871            /* seeing this binary token the second time */            /* seeing this binary token the second time */
# Line 864  void WriteSideDS(Asc_DString *dsPtr, CON Line 874  void WriteSideDS(Asc_DString *dsPtr, CON
874            } else {            } else {
875              Asc_DStringAppend(dsPtr,") , ",4);              Asc_DStringAppend(dsPtr,") , ",4);
876            }            }
877        PushRelation(pos,0,NOLHS);            PushRelation(pos,0,NOLHS);
878        PushRelation(pos-1,1,NOLHS);            PushRelation(pos-1,1,NOLHS);
879        break;            break;
880          case 0:          case 0:
881            /* seeing binary token the third (last) time */            /* seeing binary token the third (last) time */
882            if (t==e_power) {            if (t==e_power) {
# Line 874  void WriteSideDS(Asc_DString *dsPtr, CON Line 884  void WriteSideDS(Asc_DString *dsPtr, CON
884            } else {            } else {
885              Asc_DStringAppend(dsPtr,")",1);              Asc_DStringAppend(dsPtr,")",1);
886            }            }
887        break;            break;
888          default: /* first */          default: /* first */
889            Asc_Panic(2, "WriteSideDS", "Don't know this type of stack first");            Asc_Panic(2, "WriteSideDS", "Don't know this type of stack first");
890            break;            break;
# Line 889  void WriteSideDS(Asc_DString *dsPtr, CON Line 899  void WriteSideDS(Asc_DString *dsPtr, CON
899        switch(first){        switch(first){
900        case 1:        case 1:
901          /* seeing this binary token the first time */          /* seeing this binary token the first time */
902      lhs = LeftHandSide(r,pos,side);          lhs = LeftHandSide(r,pos,side);
903      term = RelationTerm(r,lhs,side);          term = RelationTerm(r,lhs,side);
904      if (NeedParen(t,RelationTermType(term),0)) {          if (NeedParen(t,RelationTermType(term),0)) {
905            Asc_DStringAppend(dsPtr,"(",1);            Asc_DStringAppend(dsPtr,"(",1);
906          }          }
907      PushRelation(pos,2,lhs);          PushRelation(pos,2,lhs);
908      PushRelation(lhs,1,NOLHS);          PushRelation(lhs,1,NOLHS);
909      break;          break;
910        case 2:        case 2:
911          /* seeing this binary token the second time */          /* seeing this binary token the second time */
912      term = RelationTerm(r,oldlhs,side);          term = RelationTerm(r,oldlhs,side);
913      if (NeedParen(t,RelationTermType(term),0)) {          if (NeedParen(t,RelationTermType(term),0)) {
914            Asc_DStringAppend(dsPtr,")",1);            Asc_DStringAppend(dsPtr,")",1);
915          }          }
916          Asc_DStringAppend(dsPtr," ",1);          Asc_DStringAppend(dsPtr," ",1);
917      WriteOpDS(dsPtr,t,lang);          WriteOpDS(dsPtr,t,lang);
918          Asc_DStringAppend(dsPtr," ",1);          Asc_DStringAppend(dsPtr," ",1);
919      PushRelation(pos,0,NOLHS);          PushRelation(pos,0,NOLHS);
920      term = RelationTerm(r,pos-1,side);          term = RelationTerm(r,pos-1,side);
921      if (NeedParen(t,RelationTermType(term),1)) {          if (NeedParen(t,RelationTermType(term),1)) {
922            Asc_DStringAppend(dsPtr,"(",1);            Asc_DStringAppend(dsPtr,"(",1);
923          }          }
924      PushRelation(pos-1,1,NOLHS);          PushRelation(pos-1,1,NOLHS);
925      break;          break;
926        case 0:        case 0:
927          /* seeing binary token the third (last) time */          /* seeing binary token the third (last) time */
928      term = RelationTerm(r,pos-1,side);          term = RelationTerm(r,pos-1,side);
929      if (NeedParen(t,RelationTermType(term),1))          if (NeedParen(t,RelationTermType(term),1))
930            Asc_DStringAppend(dsPtr,")",1);            Asc_DStringAppend(dsPtr,")",1);
931      break;          break;
932        }        }
933        break;        break;
934      case e_uminus:      case e_uminus:
935        term = RelationTerm(r,pos-1,side);        term = RelationTerm(r,pos-1,side);
936        if (first){        if (first){
937          Asc_DStringAppend(dsPtr,"-",1);          Asc_DStringAppend(dsPtr,"-",1);
938      PushRelation(pos,0,NOLHS);          PushRelation(pos,0,NOLHS);
939      switch(RelationTermType(term)){          switch(RelationTermType(term)){
940      case e_power:          case e_power:
941      case e_ipower:          case e_ipower:
942      case e_zero:          case e_zero:
943      case e_int:          case e_int:
944      case e_real:          case e_real:
945      case e_var:          case e_var:
946      case e_func:          case e_func:
947      case e_uminus:          case e_uminus:
948        break;            break;
949      default:          default:
950            Asc_DStringAppend(dsPtr,"(",1);            Asc_DStringAppend(dsPtr,"(",1);
951        break;            break;
952      }          }
953      PushRelation(pos-1,1,NOLHS);          PushRelation(pos-1,1,NOLHS);
954        }        }
955        else{        else{
956      switch(RelationTermType(term)){          switch(RelationTermType(term)){
957      case e_power:          case e_power:
958      case e_ipower:          case e_ipower:
959      case e_int:          case e_int:
960      case e_zero:          case e_zero:
961      case e_real:          case e_real:
962      case e_var:          case e_var:
963      case e_func:          case e_func:
964      case e_uminus:          case e_uminus:
965        break;            break;
966      default:          default:
967            Asc_DStringAppend(dsPtr,")",1);            Asc_DStringAppend(dsPtr,")",1);
968        break;            break;
969      }          }
970        }        }
971        break;        break;
972      default:      default:

Legend:
Removed from v.668  
changed lines
  Added in v.669

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22