00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "ppsig.hh"
00025 #include "binop.hh"
00026 #include "prim2.hh"
00027 #include "xtended.hh"
00028 #include "recursivness.hh"
00029
00030 ostream& ppsig::printinfix (ostream& fout, const string& opname, int priority, Tree x, Tree y) const
00031 {
00032 if (fPriority > priority) fout << "(";
00033 fout << ppsig(x,fEnv,priority) << opname << ppsig(y,fEnv,priority);
00034 if (fPriority > priority) fout << ")";
00035 return fout;
00036 }
00037
00038 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x) const
00039 {
00040 return fout << funame << '(' << ppsig(x,fEnv) << ')';
00041 }
00042
00043 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y) const
00044 {
00045 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ')';
00046 }
00047
00048 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z) const
00049 {
00050 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ')';
00051 }
00052
00053 ostream& ppsig::printfun (ostream& fout, const string& funame, Tree x, Tree y, Tree z, Tree zz) const
00054 {
00055 return fout << funame << '(' << ppsig(x,fEnv) << ',' << ppsig(y,fEnv) << ',' << ppsig(z,fEnv) << ',' << ppsig(zz,fEnv) << ')';
00056 }
00057
00058 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label) const
00059 {
00060 fout << funame << '(';
00061 printlabel(fout, label);
00062 return fout << ')';
00063 }
00064
00065 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree lo, Tree hi, Tree step) const
00066 {
00067 fout << funame << '(';
00068 printlabel(fout, label);
00069 return fout
00070 << ',' << ppsig(lo,fEnv)
00071 << ',' << ppsig(hi,fEnv)
00072 << ',' << ppsig(step,fEnv)
00073 << ')';
00074 }
00075
00076 ostream& ppsig::printui (ostream& fout, const string& funame, Tree label, Tree cur, Tree lo, Tree hi, Tree step) const
00077 {
00078 fout << funame << '(';
00079 printlabel(fout, label);
00080 return fout
00081 << ',' << ppsig(cur,fEnv)
00082 << ',' << ppsig(lo,fEnv)
00083 << ',' << ppsig(hi,fEnv)
00084 << ',' << ppsig(step,fEnv)
00085 << ')';
00086 }
00087
00088 ostream& ppsig::printout (ostream& fout, int i, Tree x) const
00089 {
00090 if (fPriority > 0) fout << "(";
00091 fout << "OUT" << i << " = " << ppsig(x, fEnv, 0);
00092 if (fPriority > 0) fout << ")";
00093 return fout;
00094 }
00095
00096 ostream& ppsig::printlabel (ostream& fout, Tree pathname) const
00097 {
00098 fout << *hd(pathname);
00099 pathname = tl(pathname);
00100 while (!isNil(pathname)) {
00101 fout << '/' << *tl(hd(pathname));
00102 pathname = tl(pathname);
00103 }
00104 return fout;
00105 }
00106
00107 ostream& ppsig::printlist (ostream& fout, Tree largs) const
00108 {
00109 string sep = "";
00110 fout << '(';
00111 while (!isNil(largs)) {
00112 fout << sep << ppsig(hd(largs), fEnv);
00113 sep = ", ";
00114 largs = tl(largs);
00115 }
00116 fout << ')';
00117 return fout;
00118 }
00119
00120 ostream& ppsig::printff (ostream& fout, Tree ff, Tree largs) const
00121 {
00122 fout << ffname(ff); printlist(fout, largs);
00123 return fout;
00124 }
00125
00126 ostream& ppsig::printFixDelay (ostream& fout, Tree exp, Tree delay) const
00127 {
00128 int d;
00129
00130 if (isSigInt(delay, &d) && (d==1)) {
00131 fout << ppsig(exp,fEnv,8) << "'";
00132 } else {
00133 printinfix(fout, "@", 8, exp, delay);
00134 }
00135 return fout;
00136 }
00137
00138
00139
00140 ostream& ppsig::printrec (ostream& fout, Tree var, Tree lexp, bool hide) const
00141 {
00142 if (isElement(var, fEnv) ) {
00143 fout << *var;
00144 } else if (hide) {
00145 fout << *var;
00146 } else {
00147 fout << "letrec(" << *var << " = " << ppsig(lexp, addElement(var, fEnv)) << ")";
00148 }
00149 return fout;
00150 }
00151
00152 ostream& ppsig::printextended (ostream& fout, Tree sig) const
00153 {
00154 string sep = "";
00155 xtended* p = (xtended*) getUserData(sig);
00156
00157 fout << p->name() << '(';
00158 for (int i = 0; i < sig->arity(); i++) {
00159 fout << sep << ppsig(sig->branch(i), fEnv);
00160 sep = ", ";
00161 }
00162 fout << ')';
00163 return fout;
00164 }
00165
00166
00167 ostream& ppsig::print (ostream& fout) const
00168 {
00169 #if 0
00170 int i;
00171 float r;
00172 Tree c, sel, x, y, z, var, le, label, id, ff, largs, type, name, file;
00173
00174 if ( isSigBinOp(sig, &i, x, y) ) { printinfix(fout, gBinOpTable[i]->fName, gBinOpTable[i]->fPriority, x, y); }
00175 else { cerr << "ppsig::print of " << *sig <<endl; }
00176 #endif
00177
00178
00179
00180 #if 1
00181 int i;
00182 float r;
00183 Tree c, sel, x, y, z, var, le, label, id, ff, largs, type, name, file;
00184
00185 if ( isList(sig) ) { printlist(fout, sig); }
00186 else if ( isProj(sig, &i, x) ) { fout << "proj" << i << '(' << ppsig(x, fEnv) << ')'; }
00187 else if ( isRec(sig, var, le) ) { printrec(fout, var, le, fHideRecursion && (getRecursivness(sig)==0) ); }
00188
00189 else if ( getUserData(sig) ) { printextended(fout, sig); }
00190 else if ( isSigInt(sig, &i) ) { fout << i; }
00191 else if ( isSigReal(sig, &r) ) { fout << r; }
00192 else if ( isSigInput(sig, &i) ) { fout << "IN" << i; }
00193 else if ( isSigOutput(sig, &i, x) ) { printout(fout, i, x) ; }
00194
00195 else if ( isSigDelay1(sig, x) ) { fout << ppsig(x, fEnv, 9) << "'"; }
00196
00197 else if ( isSigFixDelay(sig, x, y) ) { printFixDelay(fout, x, y); }
00198 else if ( isSigPrefix(sig, x, y) ) { printfun(fout, "prefix", x, y); }
00199 else if ( isSigIota(sig, x) ) { printfun(fout, "iota", x); }
00200 else if ( isSigBinOp(sig, &i, x, y) ) { printinfix(fout, gBinOpTable[i]->fName, gBinOpTable[i]->fPriority, x, y); }
00201 else if ( isSigFFun(sig, ff, largs) ) { printff(fout, ff, largs); }
00202 else if ( isSigFConst(sig, type, name, file) ) { fout << tree2str(name); }
00203 else if ( isSigFVar(sig, type, name, file) ) { fout << tree2str(name); }
00204
00205 else if ( isSigTable(sig, id, x, y) ) { printfun(fout, "TABLE", x, y); }
00206 else if ( isSigWRTbl(sig, id, x, y, z) ) { printfun(fout, "write", x, y, z); }
00207 else if ( isSigRDTbl(sig, x, y) ) { printfun(fout, "read", x, y); }
00208 else if ( isSigGen(sig, x) ) { fout << ppsig(x, fEnv, fPriority); }
00209
00210 else if ( isSigSelect2(sig, sel, x, y) ) { printfun(fout, "select2", sel, x, y); }
00211 else if ( isSigSelect3(sig, sel, x, y, z) ) { printfun(fout, "select3", sel, x, y, z); }
00212
00213 else if ( isSigIntCast(sig, x) ) { printfun(fout, "int", x); }
00214 else if ( isSigFloatCast(sig, x) ) { printfun(fout, "float", x); }
00215
00216 else if ( isSigButton(sig, label) ) { printui(fout, "button", label); }
00217 else if ( isSigCheckbox(sig, label) ) { printui(fout, "checkbox", label); }
00218 else if ( isSigVSlider(sig, label,c,x,y,z) ) { printui(fout, "vslider", label, c, x, y, z); }
00219 else if ( isSigHSlider(sig, label,c,x,y,z) ) { printui(fout, "hslider", label, c, x, y, z); }
00220 else if ( isSigNumEntry(sig, label,c,x,y,z) ) { printui(fout, "nentry", label, c, x, y, z); }
00221 else if ( isSigVBargraph(sig, label,x,y,z) ) { printui(fout, "vbargraph", label, x, y, z); }
00222 else if ( isSigHBargraph(sig, label,x,y,z) ) { printui(fout, "hbargraph", label, x, y, z); }
00223 else if ( isSigAttach(sig, x, y) ) { printfun(fout, "attach", x, y); }
00224
00225 else {
00226 cerr << "ERROR, ppsig doesn't recognize signal : " << *sig << endl;
00227 exit(1);
00228 }
00229 #endif
00230 return fout;
00231 }
00232