Expr const* Substitution::subst(Abs const* e) const { Var const* v = cast<Var>(subst(e->var())); Expr const* d = subst(e->expr()); return new Abs(e->type(), v, d); }
expr_ref sym_expr::accept(expr* e) { ast_manager& m = m_t.get_manager(); expr_ref result(m); switch (m_ty) { case t_pred: { var_subst subst(m); subst(m_t, 1, &e, result); break; } case t_char: SASSERT(m.get_sort(e) == m.get_sort(m_t)); result = m.mk_eq(e, m_t); break; case t_range: { bv_util bv(m); rational r1, r2, r3; unsigned sz; if (bv.is_numeral(m_t, r1, sz) && bv.is_numeral(e, r2, sz) && bv.is_numeral(m_s, r3, sz)) { result = m.mk_bool_val((r1 <= r2) && (r2 <= r3)); } else { result = m.mk_and(bv.mk_ule(m_t, e), bv.mk_ule(e, m_s)); } break; } } return result; }
Lateq* DocCompiler::compileLateq(Tree L, Lateq* compiledEqn) { // cerr << "Documentator : compileLateq : L = "; printSignal(L, stdout, 0); cerr << endl; fLateq = compiledEqn; ///< Dynamic field ! int priority = 0; for(int i = 0; isList(L); L = tl(L), i++) { Tree sig = hd(L); Tree id; if(getSigNickname(sig, id)) { // cerr << "Documentator : compileLateq : NICKNAMEPROPERTY = " << tree2str(id) << endl; fLateq->addOutputSigFormula(subst("$0(t) = $1", tree2str(id), CS(sig, priority), docT(i))); } else { // cerr << "Documentator : compileLateq : NO NICKNAMEPROPERTY" << endl; if(fLateq->outputs() == 1) { fLateq->addOutputSigFormula(subst("y(t) = $0", CS(sig, priority))); gDocNoticeFlagMap["outputsig"] = true; } else { fLateq->addOutputSigFormula(subst("$0(t) = $1", getFreshID("y"), CS(sig, priority))); gDocNoticeFlagMap["outputsigs"] = true; } } } return fLateq; }
/** * Generate the equation of a write table, which content is time dependent. * It is basically a signal of vectors. */ string DocCompiler::generateDocWriteTbl(Tree /*tbl*/, Tree size, Tree isig, Tree widx, Tree wsig) { string vname, ctype; string init = CS(isig, 0); int n; if(!isSigInt(size, &n)) { cerr << "error in DocCompiler::generateDocWriteTbl() : " << *size << " is not an integer expression and can't be used as a table size' " << endl; } // allocate a name w_i for the table getTypedNames(getCertifiedSigType(isig), "w", ctype, vname); // add a comment on tables in the notice gDocNoticeFlagMap["tablesigs"] = true; // describe the table equation string ltqRWTableDef; ltqRWTableDef += subst("$0(t)[i] = \n", vname); ltqRWTableDef += "\\left\\{\\begin{array}{ll}\n"; ltqRWTableDef += subst("$0 & \\mbox{if \\,} t < 0 \\mbox{\\, and \\,} i \\in [0,$1] \\\\\n", replaceTimeBy(init, 'i'), T(n - 1)); ltqRWTableDef += subst("$0 & \\mbox{if \\,} i = $1 \\\\\n", CS(wsig, 0), CS(widx, 0)); ltqRWTableDef += subst("$0(t\\!-\\!1)[i] & \\mbox{otherwise} \\\\\n", vname); ltqRWTableDef += "\\end{array}\\right."; // add the table equation fLateq->addRWTblSigFormula(ltqRWTableDef); // w(t) = initsig(t) // note that the name of the table can never be used outside an sigDocTableAccess return vname; }
/* Parse a cursor-full of data */ static int /* ret 0 or +ve if ok, else -ve error code */ pxl_impl_process( pl_interp_instance_t *instance, /* interp instance to process data job in */ stream_cursor_read *cursor /* data to process */ ) { pxl_interp_instance_t *pxli = (pxl_interp_instance_t *)instance; int code; /* Process some input */ switch (pxli->processState) { case PSDone: return e_ExitLanguage; case PSHeader: /* Input stream header */ code = px_stream_header_process(&pxli->headerState, cursor); if (code == 0) break; /* need more input later */ else /* stream header termination */ if (code < 0) { pxli->processState = PSDone; return code; /* return error */ } else { code = 0; pxli->processState = PSXL; } /* fall thru to PSXL */ case PSXL: /* PCL XL */ code = px_process(pxli->st, pxli->pxs, cursor); if ( code == e_ExitLanguage ) { pxli->processState = PSDone; code = 0; } else if ( code == errorWarningsReported ) { /* The parser doesn't skip over the EndSession */ /* operator, because an "error" occurred. */ cursor->ptr++; } else if (code < 0) /* Map library error codes to PCL XL codes when possible. */ switch ( code ) { #define subst(gs_error, px_error)\ case gs_error: code = px_error; break subst(gs_error_invalidfont, errorIllegalFontData); subst(gs_error_limitcheck, errorInternalOverflow); subst(gs_error_nocurrentpoint, errorCurrentCursorUndefined); subst(gs_error_rangecheck, errorIllegalAttributeValue); subst(gs_error_VMerror, errorInsufficientMemory); #undef subst } break; /* may need more input later */ } return code; }
void VectorCompiler::compileMultiSignal (Tree L) { //contextor recursivness(0); L = prepare(L); // optimize, share and annotate expression for (int i = 0; i < fClass->inputs(); i++) { fClass->addZone3(subst("$1* input$0 = &input[$0][index];", T(i), xfloat())); } for (int i = 0; i < fClass->outputs(); i++) { fClass->addZone3(subst("$1* output$0 = &output[$0][index];", T(i), xfloat())); } fClass->addSharedDecl("fullcount"); fClass->addSharedDecl("input"); fClass->addSharedDecl("output"); for (int i = 0; isList(L); L = tl(L), i++) { Tree sig = hd(L); fClass->openLoop("count"); fClass->addExecCode(subst("output$0[i] = $2$1;", T(i), CS(sig), xcast())); fClass->closeLoop(sig); } generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot)); generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot)); if (fDescription) { fDescription->ui(prepareUserInterfaceTree(fUIRoot)); } }
void Description::addGroup(int level, Tree t) { Tree label, elements, varname, sig; const char* groupnames[] = { "vgroup", "hgroup", "tgroup" }; if(isUiFolder(t, label, elements)) { const int orient = tree2int(left(label)); addLayoutLine(level, subst("<group type=\"$0\">", groupnames[orient])); addLayoutLine(level + 1, subst("<label>$0</label>", checkNullLabel(t, xmlize(tree2str(right(label))), false))); while(!isNil(elements)) { addGroup(level + 1, right(hd(elements))); elements = tl(elements); } addLayoutLine(level, "</group>"); } else if(isUiWidget(t, label, varname, sig)) { int w = addWidget(label, varname, sig); addLayoutLine(level, subst("<widgetref id=\"$0\" />", T(w))); } else { fprintf(stderr, "error in user interface generation 2\n"); exit(1); } }
/* * Reads a token from a given preprocessing context, expands it if macro, and * returns it. */ static Token *expand_one(CppContext *ctx) { Token *tok = read_cpp_token(ctx); if (!tok) return NULL; if (tok->toktype != TOKTYPE_IDENT) return tok; String *name = tok->val.str; Macro *macro = dict_get(ctx->defs, name); if (!macro) return tok; if (list_in(tok->hideset, name)) return tok; switch (macro->type) { case MACRO_OBJ: { List *ts = subst(ctx, macro, make_list(), list_union1(tok->hideset, name)); pushback(ctx, ts); return expand_one(ctx); } case MACRO_FUNC: { List *args = read_args(ctx, macro); Token *rparen = read_cpp_token(ctx); List *hideset = list_union1(list_intersect(tok->hideset, rparen->hideset), name); List *ts = subst(ctx, macro, args, hideset); pushback(ctx, ts); return expand_one(ctx); } case MACRO_SPECIAL: macro->fn(ctx, tok); return expand_one(ctx); } panic("should not reach here"); }
/** * Generate LaTeX code for "prefix", a 1sample-delay explicitely initialized. * * @param sig The signal expression to treat. * @param x The initial value for the delay line. * @param e The value for the delay line, after initialization. * @param priority The priority of the environment of the expression. * * @return <string> The LaTeX code translation of the signal, cached. */ string DocCompiler::generatePrefix(Tree sig, Tree x, Tree e, int priority) { string var = getFreshID("m"); string exp0 = CS(x, priority); string exp1 = CS(e, priority); // ensure exp1 is compiled to have a vector name string vecname; if(!getVectorNameProperty(e, vecname)) { cerr << "No vector name for : " << ppsig(e) << endl; assert(0); } string ltqPrefixDef; ltqPrefixDef += subst("$0(t) = \n", var); ltqPrefixDef += "\\left\\{\\begin{array}{ll}\n"; ltqPrefixDef += subst("$0 & \\mbox{, when \\,} t = 0\\\\\n", exp0); ltqPrefixDef += subst("$0 & \\mbox{, when \\,} t > 0\n", subst("$0(t\\!-\\!1)", vecname)); ltqPrefixDef += "\\end{array}\\right."; fLateq->addPrefixSigFormula(ltqPrefixDef); gDocNoticeFlagMap["prefixsigs"] = true; return generateCacheCode(sig, subst("$0(t)", var)); }
void filter_passwd(struct passwd *pwd, char *buffer, size_t buflen) { /* Ideally we want to add some means of configuring the * filters that we apply here. For now we'll simply * hard-code a couple of examples. */ /* N.B. there's no means of returning to your caller how much * of buffer you have used up. Thus when stacking NSS modules, * you can't rely on buffer's being available for storing your * updated data -- you don't know whether anyone has had at it * already. * * It is /not/ safe to free members that you are replacing, unless * you are certain that they lie outside of buffer[0:buflen]. * Is it safe simply to malloc more memory? We'll try it. */ printd("pwd = %p, pwd->pw_gecos = %p, buffer = %p[%d]\n", pwd, pwd->pw_gecos, buffer, buflen); #define CANFREE(p) (((p) < buffer) || ((p) > (buffer + buflen))) if (pwd->pw_gecos && strchr(pwd->pw_gecos, '&')) subst(&pwd->pw_gecos, "&", pwd->pw_name, CANFREE(pwd->pw_gecos), pass_capitalize); if (pwd->pw_dir && strchr(pwd->pw_dir, '&')) subst(&pwd->pw_dir, "&", pwd->pw_name, CANFREE(pwd->pw_dir), pass_lowercase); if (pwd->pw_shell && strchr(pwd->pw_shell, '&')) subst(&pwd->pw_shell, "&", pwd->pw_name, CANFREE(pwd->pw_shell), pass_lowercase); return; }
Expr const* Substitution::subst(Seq const* e) const { Expr const* e1 = subst(e->left()); Expr const* e2 = subst(e->right()); return new App(e->type(), e1, e2); }
Expr const* Substitution::subst(App const* e) const { Expr const* e1 = subst(e->fn()); Expr const* e2 = subst(e->arg()); return new App(e->type(), e1, e2); }
void DocCompiler::getTypedNames(Type t, const string& prefix, string& ctype, string& vname) { if (t->nature() == kInt) { ctype = "int"; vname = subst("$0", getFreshID(prefix)); } else { ctype = ifloat(); vname = subst("$0", getFreshID(prefix)); } }
/** * Generate code for the delay mecchanism without using temporary variables */ void DocCompiler::generateDelayLine(const string& ctype, const string& vname, int mxd, const string& exp) { //faustassert(mxd > 0); if (mxd == 0) { fLateq->addRecurSigFormula(subst("$0(t) = $1", vname, exp)); } else { fLateq->addRecurSigFormula(subst("$0(t) = $1", vname, exp)); } }
static void r_mult(int arg1,int arg2,set index1) { char name0[8],name1[8],name2[8]; set mind; unsigned m,mm,maxmm; int pstn[15]; int n,l; set index; index=index1; sprintf(name1,"Vrt_%d",arg1); sprintf(name2,"Vrt_%d",arg2); if(arg1 < arg2) strcpy(name0,name1); else strcpy(name0,name2); mind=set_and(index,setmassindex); if(set_eq0(mind)) reducemult(name0,name1,name2,index); else { reducemult("Vrt_0",name1,name2,index); l = 1; n = 0; while (!set_eq0(mind)) { if (set_in(l,mind)) pstn[n++] = l; set_del1(&mind,l++); } maxmm = (1 << n) - 1 ; for (mm = 1;mm <= maxmm ; mm++) { writeF(" Vrt_L:=%s$ Vrt_R:=%s$\n",name1,name2); mind=set_constr(_E); m = mm; n = 1; while (m != 0) { if ((m & 1) != 0 && (l = pstn[n-1]) != 0) { writeF(" Vrt_L:=(Vrt_L where %s)$\n",subst(l,arg1)); writeF(" Vrt_R:=(Vrt_R where %s)$\n",subst(l,arg2)); set_add1(&mind,l); } ++(n); m >>= 1; } reducemult("Vrt_0","Vrt_0 + Vrt_L","Vrt_R",set_aun(index,mind)); writeF(" Clear Vrt_L $ Clear Vrt_R $\n"); } writeF(" %s:=Vrt_0 $ Clear Vrt_0 $\n",name0); } if (arg1 < arg2) { writeF(" Clear %s$\n",name2); for (n = 1; n <= vcs.sizet; n++) if (vertmap[n-1] == arg2) vertmap[n-1] = arg1; } if (arg2 < arg1) { writeF(" Clear %s$\n",name1); for (n = 1; n <= vcs.sizet; n++) if (vertmap[n-1] == arg1) vertmap[n-1] = arg2; } } /* R_mult */
string VectorCompiler::generateWaveform(Tree sig) { string vname; int size; declareWaveform(sig, vname, size); fClass->addPostCode(subst("idx$0 = (idx$0 + count) % $1;", vname, T(size)) ); return generateCacheCode(sig, subst("$0[(idx$0+i)%$1]", vname, T(size))); }
Ident Code_Project::findEquality(Ident x, VarCode vc) { Ident y = -1; if (!vc.vars->exists(x)) return -1; x = subst(x, vc.vars, &vc.code->vars); if (vc.code->eqlist && vc.code->eqlist->exists(x)) return -1; switch (vc.code->kind) { case cAnd: { Code_And *c = (Code_And *) vc.code; y = findEquality(x, c->vc1); if (y == -1) y = findEquality(x, c->vc2); break; } case cProject: case cRestrict: case cPredCall: { Code_c *c = (Code_c *) vc.code; y = findEquality(x, c->vc); break; } case cEq1: case cEq2: { Code_nn *c = (Code_nn *) vc.code; if (c->id1 == x && c->id2 != x && sameUnivs(c->id1, c->id2)) y = c->id2; else if (c->id2 == x && c->id1 != x && sameUnivs(c->id1, c->id2)) y = c->id1; break; } case cBiimpl: { Code_Biimpl *c = (Code_Biimpl *) vc.code; if (c->vc1.code->kind == cBoolVar && c->vc2.code->kind == cBoolVar) { Code_BoolVar *c1 = (Code_BoolVar *) c->vc1.code; Code_BoolVar *c2 = (Code_BoolVar *) c->vc2.code; if (c1->id == x && c2->id != x) y = c2->id; else if (c2->id == x && c1->id != x) y = c1->id; } break; } default: ; // no equality found } if (y != -1) y = subst(y, &vc.code->vars, vc.vars); if (!vc.code->eqlist) vc.code->eqlist = new IdentList; vc.code->eqlist->insert(x); return y; }
bool Code_cc::checkExport(Ident x) { if (eqlist && eqlist->exists(x)) return true; if (!eqlist) eqlist = new IdentList; eqlist->insert(x); return vc1.code->checkExport(subst(x, vc1.vars, &vc1.code->vars)) && vc2.code->checkExport(subst(x, vc2.vars, &vc2.code->vars)); }
/** * Generate the code for a (short) delay line * @param k the c++ class where the delay line will be placed. * @param l the loop where the code will be placed. * @param tname the name of the C++ type (float or int) * @param dlname the name of the delay line (vector) to be used. * @param delay the maximum delay * @param cexp the content of the signal as a C++ expression */ void VectorCompiler::vectorLoop (const string& tname, const string& vecname, const string& cexp) { // -- declare the vector fClass->addSharedDecl(vecname); // -- variables moved as class fields... fClass->addZone1(subst("$0 \t$1[$2];", tname, vecname, T(gVecSize))); // -- compute the new samples fClass->addExecCode(subst("$0[i] = $1;", vecname, cexp)); }
virtual string generateCode (Klass* klass, const vector<string>& args, const vector<Type>& types) { assert (args.size() == arity()); assert (types.size() == arity()); if (types[1]->nature() == kInt) { klass->rememberNeedPowerDef(); return subst("faustpower<$1>($0)", args[0], args[1]); } else { return subst("pow$2($0,$1)", args[0], args[1], isuffix()); } }
QString const externalLineEnding(docstring const & str) { #ifdef Q_WS_MACX // The MAC clipboard uses \r for lineendings, and we use \n return toqstr(subst(str, '\n', '\r')); #elif defined(Q_WS_WIN) // Windows clipboard uses \r\n for lineendings, and we use \n return toqstr(subst(str, from_ascii("\n"), from_ascii("\r\n"))); #else return toqstr(str); #endif }
/** * Generate buildUserInterface C++ lines of code corresponding * to user interface element t */ void Compiler::generateUserInterfaceTree(Tree t) { Tree label, elements, varname, sig; if (isUiFolder(t, label, elements)) { const int orient = tree2int(left(label)); // Empty labels will be renamed with a 0xABCD (address) kind of name that is ignored and not displayed by UI architectures const char* str = tree2str(right(label)); const char* model; // extract metadata from group label str resulting in a simplifiedLabel // and metadata declarations for fictive zone at address 0 string simplifiedLabel; map<string, set<string> > metadata; extractMetadata(str, simplifiedLabel, metadata); // add metadata if any for (map<string, set<string> >::iterator i = metadata.begin(); i != metadata.end(); i++) { const string& key = i->first; const set<string>& values = i->second; for (set<string>::const_iterator j = values.begin(); j != values.end(); j++) { fClass->addUICode(subst("interface->declare($0, \"$1\", \"$2\");", "0", wdel(key) ,wdel(*j))); fJSON.declare(NULL, wdel(key).c_str(), wdel(*j).c_str()); } } //----------------- switch (orient) { case 0 : model = "interface->openVerticalBox(\"$0\");"; fJSON.openVerticalBox(checkNullLabel(t, simplifiedLabel).c_str()); break; case 1 : model = "interface->openHorizontalBox(\"$0\");"; fJSON.openHorizontalBox(checkNullLabel(t, simplifiedLabel).c_str()); break; case 2 : model = "interface->openTabBox(\"$0\");"; fJSON.openTabBox(checkNullLabel(t, simplifiedLabel).c_str()); break; default : fprintf(stderr, "error in user interface generation 1\n"); exit(1); } fClass->addUICode(subst(model, checkNullLabel(t, simplifiedLabel))); generateUserInterfaceElements(elements); fClass->addUICode("interface->closeBox();"); fJSON.closeBox(); } else if (isUiWidget(t, label, varname, sig)) { generateWidgetCode(label, varname, sig); } else { fprintf(stderr, "error in user interface generation 2\n"); exit(1); } }
static Tree subst (Tree t, Tree propkey, Tree id, Tree val) { Tree p; if (t==id) { return val; } else if (t->arity() == 0) { return t; } else if (getProperty(t, propkey, p)) { return (isNil(p)) ? t : p; } else { Tree r=nil; switch (t->arity()) { case 1 : r = tree(t->node(), subst(t->branch(0), propkey, id, val)); break; case 2 : r = tree(t->node(), subst(t->branch(0), propkey, id, val), subst(t->branch(1), propkey, id, val)); break; case 3 : r = tree(t->node(), subst(t->branch(0), propkey, id, val), subst(t->branch(1), propkey, id, val), subst(t->branch(2), propkey, id, val)); break; case 4 : r = tree(t->node(), subst(t->branch(0), propkey, id, val), subst(t->branch(1), propkey, id, val), subst(t->branch(2), propkey, id, val), subst(t->branch(3), propkey, id, val)); break; } if (r == t) { setProperty(t, propkey, nil); } else { setProperty(t, propkey, r); } return r; } }
bool SpecialisedMover::do_copy(FileName const & from, FileName const & to, string const & latex) const { if (command_.empty()) return Mover::do_copy(from, to, latex); string command = command_; command = subst(command, "$$i", quoteName(from.toFilesystemEncoding())); command = subst(command, "$$o", quoteName(to.toFilesystemEncoding())); command = subst(command, "$$l", quoteName(latex)); Systemcall one; return one.startscript(Systemcall::Wait, command) == 0; }
void Code_Restrict::reduce2() { vc.reduce(); VarCodeList::iterator i; restrconj = new VarCodeList; if (vc.code->conj) for (i = vc.code->conj->begin(); i != vc.code->conj->end(); i++) restrconj->insert(subst((*i).vars, &vc.code->vars, vc.vars), (*i).code); if (vc.code->restrconj) for (i = vc.code->restrconj->begin(); i != vc.code->restrconj->end(); i++) restrconj->insert(subst((*i).vars, &vc.code->vars, vc.vars), (*i).code); }
string DocCompiler::generateInput (Tree sig, const string& idx) { if (fLateq->inputs() == 1) { setVectorNameProperty(sig, "x"); fLateq->addInputSigFormula("x(t)"); gGlobal->gDocNoticeFlagMap["inputsig"] = true; return generateCacheCode(sig, "x(t)"); } else { setVectorNameProperty(sig, subst("x_{$0}", idx)); fLateq->addInputSigFormula(subst("x_{$0}(t)", idx)); gGlobal->gDocNoticeFlagMap["inputsigs"] = true; return generateCacheCode(sig, subst("x_{$0}(t)", idx)); } }
/** Unused for the moment ! */ string DocCompiler::generateOutput (Tree sig, const string& idx, const string& arg) { string dst; if (fLateq->outputs() == 1) { dst = subst("y(t)", idx); gGlobal->gDocNoticeFlagMap["outputsig"] = true; } else { dst = subst("y_{$0}(t)", idx); gGlobal->gDocNoticeFlagMap["outputsigs"] = true; } fLateq->addOutputSigFormula(subst("$0 = $1", dst, arg)); return dst; }
void Code_Project::reduce2() { Code_c::reduce2(); // for obscure reasons it is safe to add sublists VarCodeList::iterator i; restrconj = new VarCodeList; if (vc.code->conj) for (i = vc.code->conj->begin(); i != vc.code->conj->end(); i++) conj->insert(subst((*i).vars, &vc.code->vars, vc.vars), (*i).code); if (vc.code->restrconj) for (i = vc.code->restrconj->begin(); i != vc.code->restrconj->end(); i++) restrconj->insert(subst((*i).vars, &vc.code->vars, vc.vars), (*i).code); }
/** * Generate code for the delay mecchanism without using temporary variables */ string DocCompiler::generateDelayVecNoTemp(Tree sig, const string& exp, const string& ctype, const string& vname, int mxd) { faustassert(mxd > 0); //cerr << " entering generateDelayVecNoTemp" << endl; string vectorname; // if generateVariableStore has already tagged sig, no definition is needed. if(getVectorNameProperty(sig, vectorname)) { return subst("$0(t)", vectorname); } else { fLateq->addRecurSigFormula(subst("$0(t) = $1", vname, exp)); setVectorNameProperty(sig, vname); return subst("$0(t)", vname); } }
virtual string generateLateq (Lateq* lateq, const vector<string>& args, const vector<Type>& types) { assert (args.size() == arity()); assert (types.size() == arity()); return subst("{$0}^{$1}", args[0], args[1]); }