109 for (
int i = 0;
isList(L); L =
tl(L), i++) {
197 Tree c, sel, x, y, z, u, label, ff, largs, type,
name, file;
222 else if (
isSigSelect3(sig, sel, x, y, z) ) {
printGCCall(sig,
"generateSelect3");
return generateSelect3 (sig, sel, x, y, z, priority); }
231 else if (
isSigVSlider(sig, label,c,x,y,z) ) {
printGCCall(sig,
"generateVSlider");
return generateVSlider (sig, label, c,x,y,z); }
232 else if (
isSigHSlider(sig, label,c,x,y,z) ) {
printGCCall(sig,
"generateHSlider");
return generateHSlider (sig, label, c,x,y,z); }
233 else if (
isSigNumEntry(sig, label,c,x,y,z) ) {
printGCCall(sig,
"generateNumEntry");
return generateNumEntry (sig, label, c,x,y,z); }
240 cerr <<
"Error in d signal, unrecognized signal : " << *sig << endl;
244 return "error in generate code";
256 bool printCalls =
false;
257 bool maskSigs =
false;
260 cerr <<
" -> generateCode calls " << calledFunction;
264 cerr <<
" on " <<
ppsig(sig) << endl;
307 if (exp ==
"fSamplingFreq") {
312 return "\\mathrm{"+exp+
"}";
363 dst =
subst(
"y(t)", idx);
366 dst =
subst(
"y_{$0}(t)", idx);
402 return (opcode ==
kAdd) || (opcode ==
kMul) || (opcode ==
kAND) || (opcode ==
kOR) || (opcode ==
kXOR);
413 if ( (thisPriority < priority) || ((thisPriority == priority) && !
associative(opcode)) ) {
421 bool intOpDetected =
false;
422 if ( (t1->nature() ==
kInt) && (t2->nature() ==
kInt) ) {
423 intOpDetected =
true;
455 if ( (opcode ==
kDiv) && (!intOpDetected) ) {
456 s =
subst(
"$0\\frac{$1}{$2}$3", lpar,
CS(arg1, 0),
CS(arg2, 0), rpar);
458 s =
subst(
"$0$1 $2 $3$4", lpar,
CS(arg1, thisPriority), op,
CS(arg2, thisPriority), rpar);
478 for (
int i = 0; i<
ffarity(ff); i++) {
480 code +=
CS(
nth(largs, i), priority);
487 return "\\mathrm{ff"+code+
"}";
497 if (t->nature() ==
kInt) {
515 Tree type,
name, file, label, c, x, y, z;
534 string vname, ctype, code, vectorname;
565 else if (sharing > 1) {
570 cerr <<
"Error in sharing count (" << sharing <<
") for " << *sig << endl;
574 return "Error in generateCacheCode";
583 switch (t->variability()) {
596 return subst(
"$0(t)", vname);
600 return subst(
"$0(t)", vname);
607 return subst(
"$0(t)", vname);
650 string varname = vname +
"(t)";
659 string varname = vname +
"(t)";
695 switch (t->variability()) {
715 switch (t->variability()) {
736 exp =
CS(x, priority);
761 string init =
CS(isig,0);
765 cerr <<
"error in DocCompiler::generateDocConstantTbl() : "
767 <<
" is not an integer expression and can't be used as a table size' "
790 bool w = ( ((c >=
'a') && (c <=
'z'))
791 || ((c >=
'A') && (c <=
'Z'))
792 || ((c >=
'0') && (c <=
'9'))
806 for (
size_t i=0; i < src.size(); i++)
826 string init =
CS(isig,0);
829 cerr <<
"error in DocCompiler::generateDocWriteTbl() : "
831 <<
" is not an integer expression and can't be used as a table size' "
843 string ltqRWTableDef;
844 ltqRWTableDef +=
subst(
"$0(t)[i] = \n", vname);
845 ltqRWTableDef +=
"\\left\\{\\begin{array}{ll}\n";
846 ltqRWTableDef +=
subst(
"$0 & \\mbox{if \\,} t < 0 \\mbox{\\, and \\,} i \\in [0,$1] \\\\\n",
replaceTimeBy(init,
'i'),
T(n-1));
847 ltqRWTableDef +=
subst(
"$0 & \\mbox{if \\,} i = $1 \\\\\n",
CS(wsig,0),
CS(widx,0));
848 ltqRWTableDef +=
subst(
"$0(t\\!-\\!1)[i] & \\mbox{otherwise} \\\\\n", vname);
849 ltqRWTableDef +=
"\\end{array}\\right.";
866 string vname =
CS(tbl, 0);
867 string result =
subst(
"$0[$1]", vname,
CS(ridx,0) );
874 return (s.length() <=
max);
895 assert(
isRec(r, var, le));
904 return subst(
"$0(t)", vname);
915 vector<bool> used(N);
916 vector<int> delay(N);
917 vector<string> vname(N);
918 vector<string> ctype(N);
921 for (
int i=0; i<N; i++) {
941 for (
int i=0; i<N; i++) {
966 string exp0 =
CS(x, priority);
967 string exp1 =
CS(e, priority);
971 cerr <<
"No vector name for : " <<
ppsig(e) << endl;
976 ltqPrefixDef +=
subst(
"$0(t) = \n", var);
977 ltqPrefixDef +=
"\\left\\{\\begin{array}{ll}\n";
978 ltqPrefixDef +=
subst(
"$0 & \\mbox{, when \\,} t = 0\\\\\n", exp0);
979 ltqPrefixDef +=
subst(
"$0 & \\mbox{, when \\,} t > 0\n",
subst(
"$0(t\\!-\\!1)", vecname));
980 ltqPrefixDef +=
"\\end{array}\\right.";
999 if (!
isSigInt(n, &size)) { fprintf(stderr,
"error in generateIota\n"); exit(1); }
1001 return subst(
" t \\bmod{$0} ",
docT(size));
1015 string expsel =
CS(sel, 0);
1016 string exps1 =
CS(s1, 0);
1017 string exps2 =
CS(s2, 0);
1020 ltqSelDef +=
subst(
"$0(t) = \n", var);
1021 ltqSelDef +=
"\\left\\{\\begin{array}{ll}\n";
1022 ltqSelDef +=
subst(
"$0 & \\mbox{if \\,} $1 = 0\\\\\n", exps1, expsel);
1023 ltqSelDef +=
subst(
"$0 & \\mbox{if \\,} $1 = 1\n", exps2, expsel);
1024 ltqSelDef +=
"\\end{array}\\right.";
1031 return subst(
"$0(t)", var);
1041 string expsel =
CS(sel, 0);
1042 string exps1 =
CS(s1, 0);
1043 string exps2 =
CS(s2, 0);
1044 string exps3 =
CS(s3, 0);
1047 ltqSelDef +=
subst(
"$0(t) = \n", var);
1048 ltqSelDef +=
"\\left\\{\\begin{array}{ll}\n";
1052 ltqSelDef +=
"\\end{array}\\right.";
1059 return subst(
"$0(t)", var);
1070 vector<string> args;
1073 for (
int i=0; i<sig->
arity(); i++) {
1074 args.push_back(
CS(sig->
branch(i), 0));
1160 cerr <<
"No vector name for : " <<
ppsig(exp) << endl;
1164 if (
isSigInt(delay, &d) && (d == 0)) {
1166 return subst(
"$0(t)", vecname);
1169 return subst(
"$0(t\\!-\\!$1)", vecname,
CS(delay, 7));
1202 return subst(
"$0(t)", vectorname);
1206 return subst(
"$0(t)", vname);
1249 while (!
isNil(dir)) {
1251 if ( (tmp[0] !=
'[') && (!tmp.empty()) ) {
1277 label = (label.size()>0) ? (
"\\textsf{\""+label+
"\"} ") :
"";
1278 unit = (unit.size()>0) ? (
"\\ ("+unit+
")") :
"";
1280 s +=
" & $" + name +
"$";
1281 s +=
" $\\in$ $\\left\\{\\,0, 1\\,\\right\\}$";
1304 string label, unit, cur,
min,
max;
1311 label = (label.size()>0) ? (
"\\textsf{\""+label+
"\"} ") :
"";
1312 unit = (unit.size()>0) ? (
"\\ ("+unit+
")") :
"";
1314 s +=
" & $" + name +
"$";
1315 s +=
" $\\in$ $\\left[\\," + min +
", " + max +
"\\,\\right]$";
1316 s +=
" & $(\\mbox{" +
gDocMathStringMap[
"defaultvalue"] +
"} = " + cur +
")$\\\\";
1333 map<string, set<string> > metadata;
1336 set<string> myunits = metadata[
"unit"];
1340 for (map<
string, set<string> >::iterator i = metadata.begin(); i != metadata.end(); i++) {
1341 const string& key = i->first;
1342 const set<string>& values = i->second;
1343 for (set<string>::const_iterator j = values.begin(); j != values.end(); j++) {
1344 if(key ==
"unit") unit += *j;
static const unsigned int MAX_RIGHT_MEMBER
string generateAttach(Tree sig, Tree x, Tree y, int priority)
bool isSigHSlider(Tree s)
void sharingAnalysis(Tree t)
string prepareIntervallicUI(const string &name, Tree path, Tree tcur, Tree tmin, Tree tmax)
Prepare "intervallic" user interface elements (sliders, nentry).
static bool isSeparator(char c)
tests if a charactere is a word separator
string generateDelayVec(Tree sig, const string &exp, const string &ctype, const string &vname, int mxd)
Generate code for the delay mecchanism.
string CS(Tree sig, int priority)
Compile a signal.
string generateCacheCode(Tree sig, const string &exp)
string generateIntCast(Tree sig, Tree x, int priority)
string setCompiledExpression(Tree sig, const string &name)
Set the string of a compiled expression is already compiled.
string prepareBinaryUI(const string &name, Tree pathname)
Prepare binary user interface elements (button, checkbox).
void generateDelayLine(const string &ctype, const string &vname, int mxd, const string &exp)
Generate code for the delay mecchanism without using temporary variables.
bool isSigPrefix(Tree t, Tree &t0, Tree &t1)
bool isSigCheckbox(Tree s)
bool isSigFFun(Tree s, Tree &ff, Tree &largs)
string generateFVar(Tree sig, const string &file, const string &name)
bool isSigNumEntry(Tree s)
bool isSigSelect2(Tree t, Tree &selector, Tree &s1, Tree &s2)
void addPrefixSigFormula(const string &str)
string generateSelect2(Tree sig, Tree sel, Tree s1, Tree s2, int priority)
Generate a select2 code.
string generateButton(Tree sig, Tree label)
bool getSigListNickName(Tree t, Tree &id)
void addRWTblSigFormula(const string &str)
void mark(Tree root)
start markup of root tree with new unique key
void addUISigFormula(const string &path, const string &str)
map< string, bool > gDocNoticeFlagMap
gDocNoticeFlagMap is public to let others turn to "true" flags that one want to print.
bool isSigIota(Tree t, Tree &t0)
virtual string generateLateq(Lateq *lateq, const vector< string > &args, const vector< Type > &types)=0
void addConstSigFormula(const string &str)
string generateXtended(Tree sig, int priority)
retrieve the type annotation of sig
string generateDocConstantTbl(Tree sig, Tree size, Tree content)
Generate the equation of a constant table (its content is time constant).
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
const char * ffname(Tree t)
void typeAnnotation(Tree sig)
Fully annotate every subtree of term with type information.
bool isSigInput(Tree t, int *i)
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
void setVectorNameProperty(Tree sig, const string &vecname)
Set the vector name property of a signal, the name of the vector used to store the previous values of...
BinOp * gBinOpLateqTable[]
string generateRecProj(Tree sig, Tree exp, int i, int priority)
Generate code for a projection of a group of mutually recursive definitions.
virtual bool needCache()=0
Occurences * retrieve(Tree t)
occurences of subtree t within root tree
Lateq * compileLateq(Tree L, Lateq *compiledEqn)
bool isSigVBargraph(Tree s)
bool isSigSelect3(Tree t, Tree &selector, Tree &s1, Tree &s2, Tree &s3)
static bool isVerySimpleFormula(Tree sig)
Test if exp is very simple that is it can't be considered a real component.
bool isSigVSlider(Tree s)
string generateCode(Tree sig, int priority)
Main code generator dispatch.
double max(double x, double y)
string generateDocWriteTbl(Tree sig, Tree size, Tree content, Tree widx, Tree wsig)
Generate the equation of a write table, which content is time dependent.
void set(Tree t, const P &data)
bool isSigReal(Tree t, double *r)
static string replaceTimeBy(const string &src, char r)
Replaces the occurences of 't' in a formula with another character.
bool getSigNickname(Tree t, Tree &id)
Get the nickname property of a signal.
void addStoreSigFormula(const string &str)
property< string > fVectorProperty
string generateSelect3(Tree sig, Tree sel, Tree s1, Tree s2, Tree s3, int priority)
Generate a select3 code.
string generateDocAccessTbl(Tree sig, Tree tbl, Tree ridx)
Generate the equation of a write table, which content is time dependent.
static bool associative(int opcode)
Generate binary operations, managing priority parenthesis.
Tree sigProj(int i, Tree rgroup)
void addRecurSigFormula(const string &str)
string generateFConst(Tree sig, const string &file, const string &name)
string subst(const string &model, const vector< string > &args)
Text substitution.
bool isSigHBargraph(Tree s)
string generateCheckbox(Tree sig, Tree label)
bool isSigDocConstantTbl(Tree t, Tree &n, Tree &sig)
string generateVBargraph(Tree sig, Tree label, Tree min, Tree max, const string &exp)
string generateNumEntry(Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
string generateBinOp(Tree sig, int opcode, Tree arg1, Tree arg2, int priority)
string generateIota(Tree sig, Tree arg)
Generate a "iota" time function, n-cyclical.
void getUIDocInfos(Tree path, string &label, string &unit)
Get information on a user interface element for documentation.
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
void printGCCall(Tree sig, const string &calledFunction)
Print calling information of generateCode, for debug purposes.
bool isSigAttach(Tree t, Tree &t0, Tree &t1)
bool isShortEnough(string &s, unsigned int max)
string generateDelayVecNoTemp(Tree sig, const string &exp, const string &ctype, const string &vname, int mxd)
Generate code for the delay mecchanism without using temporary variables.
string generatePrefix(Tree sig, Tree x, Tree e, int priority)
Generate LaTeX code for "prefix", a 1sample-delay explicitely initialized.
string generateFFun(Tree sig, Tree ff, Tree largs, int priority)
string generateHBargraph(Tree sig, Tree label, Tree min, Tree max, const string &exp)
bool isSigDocAccessTbl(Tree t, Tree &tbl, Tree &ridx)
bool get(Tree t, P &data)
void extractMetadata(const string &fulllabel, string &label, map< string, set< string > > &metadata)
Extracts metdata from a label : 'vol [unit: dB]' -> 'vol' + metadata.
void addSelectSigFormula(const string &str)
Type getCertifiedSigType(Tree sig)
Retrieve the type of sig and check it exists.
static const unsigned int MAX_SUB_EXPR
void recursivnessAnnotation(Tree sig)
Annotate a signal with recursivness.
string getUIDir(Tree pathname)
Get the directory of a user interface element.
int arity() const
return the number of branches (subtrees) of a tree
string generateInput(Tree sig, const string &idx)
bool getVectorNameProperty(Tree sig, string &vecname)
Get the vector name property of a signal, the name of the vector used to store the previous values of...
void getTypedNames(Type t, const string &prefix, string &ctype, string &vname)
const char * name(Symbol *sym)
Returns the name of a symbol.
void generateRec(Tree sig, Tree var, Tree le, int priority)
Generate code for a group of mutually recursive definitions.
void addRDTblSigFormula(const string &str)
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
bool isSigInt(Tree t, int *i)
int getSharingCount(Tree t)
void addOutputSigFormula(const string &str)
string generateFloatCast(Tree sig, Tree x, int priority)
Don't generate float cast !
bool isSigDocWriteTbl(Tree t, Tree &n, Tree &sig, Tree &widx, Tree &wsig)
bool isSigFloatCast(Tree t)
static map< string, int > fIDCounters
int getMaxDelay() const
return the maximal delay collected
void * getUserData(Symbol *sym)
Returns user data.
bool isSigIntCast(Tree t)
string generateVSlider(Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
void addInputSigFormula(const string &str)
Add a line of a latex equation code corresponding to a signal.
string generateNumber(Tree sig, const string &exp)
string generateOutput(Tree sig, const string &idx, const string &arg1)
Unused for the moment !
bool isProj(Tree t, int *i, Tree &rgroup)
Interface for names management.
bool getCompiledExpression(Tree sig, string &name)
Test if a signal is already compiled.
string generateFixDelay(Tree sig, Tree arg, Tree size, int priority)
Generate code for accessing a delayed signal.
API to the typing system of signals.
string generateVariableStore(Tree sig, const string &exp)
double min(double x, double y)
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
string getFreshID(const string &prefix)
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
string generateHSlider(Tree sig, Tree label, Tree cur, Tree min, Tree max, Tree step)
Tree branch(int i) const
return the ith branch (subtree) of a tree
bool isSigOutput(Tree t, int *i, Tree &t0)
void addParamSigFormula(const string &str)
map< string, string > gDocMathStringMap
property< string > fCompileProperty