FAUST compiler  0.9.9.6b8
Macros | Enumerations | Functions | Variables
doc.cpp File Reference

Implementation of documentation trees support and printing. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <time.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <string>
#include <vector>
#include "ppbox.hh"
#include "prim2.hh"
#include "doc.hh"
#include "eval.hh"
#include "errormsg.hh"
#include "doc_Text.hh"
#include "sigprint.hh"
#include "propagate.hh"
#include "enrobage.hh"
#include "drawschema.hh"
#include "names.hh"
#include "simplify.hh"
#include "privatise.hh"
#include "recursivness.hh"
#include "sourcereader.hh"
#include "lateq.hh"
#include "doc_compile.hh"
#include "doc_lang.hh"
#include "doc_notice.hh"
#include "doc_autodoc.hh"
#include "compatibility.hh"
#include "files.hh"
Include dependency graph for doc.cpp:

Go to the source code of this file.

Macros

#define MAXIDCHARS   5
 max numbers (characters) to represent ids (e.g. for directories). More...
 

Enumerations

enum  { langEN, langFR, langIT }
 

Functions

static void printlatexheader (istream &latexheader, const string &faustversion, ostream &docout)
 Print a static LaTeX header. More...
 
static void printfaustlistings (ostream &docout)
 Print listings of each Faust code ".dsp" files, calling the 'printfaustlisting' function. More...
 
static void printfaustlisting (string &faustfile, ostream &docout)
 Print a listing of the Faust code, in a LaTeX "listing" environment. More...
 
static void printlatexfooter (ostream &docout)
 Print the static LaTeX footer. More...
 
static void printdoccontent (const char *svgTopDir, const vector< Tree > &docVector, const string &faustversion, ostream &docout)
 Main documentator loop. More...
 
static void printfaustdocstamp (const string &faustversion, ostream &docout)
 Print a "doc stamp" in the LaTeX document : More...
 
static void printDocEqn (Lateq *ltq, ostream &docout)
 Print doc equations, following the Lateq::println method. More...
 
static void printDocDgm (const Tree expr, const char *svgTopDir, ostream &docout, int i)
 Doc diagrams handling. More...
 
static void printDocMetadata (const Tree expr, ostream &docout)
 Print a metadata set. More...
 
static void prepareDocEqns (const vector< Tree > &docBoxes, vector< Lateq * > &docCompiledEqnsVector)
 Caller function. More...
 
static void collectDocEqns (const vector< Tree > &docBoxes, vector< Tree > &eqBoxes)
 step 0. Feed a vector. More...
 
static void mapEvalDocEqn (const vector< Tree > &eqBoxes, const Tree &env, vector< Tree > &evalEqBoxes)
 step 1. Evaluate boxes. More...
 
static void mapGetEqName (const vector< Tree > &evalEqBoxes, vector< string > &eqNames)
 step 2. Get boxes name. More...
 
static void calcEqnsNicknames (const vector< string > &eqNames, vector< string > &eqNicknames)
 step 3. Calculate nicknames. More...
 
static void mapPrepareEqSig (const vector< Tree > &evalEqBoxes, vector< int > &eqInputs, vector< int > &eqOutputs, vector< Tree > &eqSigs)
 step 4&5. Propagate and prepare signals. More...
 
static void mapSetSigNickname (const vector< string > &eqNicknames, const vector< int > &eqInputs, const vector< Tree > &eqSigs)
 step 6. Set signals nicknames. More...
 
static void collectEqSigs (const vector< Tree > &eqSigs, Tree &superEqList)
 step 7. Collect all signals in a superlist. More...
 
static void annotateSuperList (DocCompiler *DC, Tree superEqList)
 step 8. Annotate superlist. More...
 
static void mapCompileDocEqnSigs (const vector< Tree > &eqSigs, const vector< int > &eqInputs, const vector< int > &eqOutputs, DocCompiler *DC, vector< Lateq * > &docCompiledEqnsVector)
 step 10. Compile equations. More...
 
static string calcNumberedName (const char *base, int i)
 Simply concat a string with a number in a "%03d" format. More...
 
static void getBoxInputsAndOutputs (const Tree t, int &numInputs, int &numOutputs)
 Just get the number of inputs and the number of outputs of a box. More...
 
static string calcDocEqnInitial (const string s)
 Calculate an appropriate nickname for equations, from previous names. More...
 
static void initCompilationDate ()
 
static struct tm * getCompilationDate ()
 
static istream * openArchFile (const string &filename)
 Open architecture file. More...
 
static char * legalFileName (const Tree t, int n, char *dst)
 Transform the definition name property of tree <t> into a legal file name. More...
 
static string rmExternalDoubleQuotes (const string &s)
 Remove the leading and trailing double quotes of a string (but not those in the middle of the string) More...
 
static void copyFaustSources (const char *projname, const vector< string > &pathnames)
 Copy all Faust source files into an 'src' subdirectory. More...
 
vector< string > & docCodeSlicer (const string &faustfile, vector< string > &codeSlices)
 Slice faust code between "mdoc" sections. More...
 
static void printdocCodeSlices (const string &code, ostream &docout)
 Print faust code inside a listing environment. More...
 
static bool doesFileBeginWithCode (const string &faustfile)
 Test whether a file does begin with some faust code or not. More...
 
Tree docTxt (const char *name)
 
bool isDocTxt (Tree t)
 
bool isDocTxt (Tree t0, const char **str)
 
Tree docEqn (Tree x)
 
bool isDocEqn (Tree t, Tree &x)
 
Tree docDgm (Tree x)
 
bool isDocDgm (Tree t, Tree &x)
 
Tree docNtc ()
 
bool isDocNtc (Tree t)
 
Tree docLst ()
 
bool isDocLst (Tree t)
 
Tree docMtd (Tree x)
 
bool isDocMtd (Tree t, Tree &x)
 
void printDoc (const char *projname, const char *docdev, const char *faustversion)
 The entry point to generate faust doc files. More...
 

Variables

Tree gExpandedDefList
 
map< Tree, set< Tree > > gMetaDataSet
 
map< string, string > gDocMetadatasStringMap
 
map< string, string > gDocMathStringMap
 
bool gDetailsSwitch
 
bool gStripDocSwitch
 
string gFaustDirectory
 
string gFaustSuperDirectory
 
string gFaustSuperSuperDirectory
 
string gMasterDocument
 
string gMasterName
 
SourceReader gReader
 
string gDocName
 Contains the filename for out documentation. More...
 
static const char * gDocDevSuffix
 ".tex" (or .??? - used to choose output device). More...
 
static const string gLatexheaderfilename = "latexheader.tex"
 
vector< TreegDocVector
 Contains <mdoc> parsed trees: DOCTXT, DOCEQN, DOCDGM. More...
 
static struct tm gCompilationDate
 
bool gLstDependenciesSwitch = true
 mdoc listing management. More...
 
bool gLstMdocTagsSwitch = true
 mdoc listing management. More...
 
bool gLstDistributedSwitch = true
 mdoc listing management. More...
 
string gDocLang
 
Sym DOCTXT = symbol ("DocTxt")
 
Sym DOCEQN = symbol ("DocEqn")
 
Sym DOCDGM = symbol ("DocDgm")
 
Sym DOCNTC = symbol ("DocNtc")
 
Sym DOCLST = symbol ("DocLst")
 
Sym DOCMTD = symbol ("DocMtd")
 

Detailed Description

Implementation of documentation trees support and printing.

Author
Karim Barkati and Yann Orlarey
Version
1.0
Date
2009

Definition in file doc.cpp.

Macro Definition Documentation

#define MAXIDCHARS   5

max numbers (characters) to represent ids (e.g. for directories).

Definition at line 83 of file doc.cpp.

Referenced by calcNumberedName(), and printDocDgm().

Enumeration Type Documentation

anonymous enum
Enumerator
langEN 
langFR 
langIT 

Definition at line 117 of file doc.cpp.

117 { langEN, langFR, langIT };
Definition: doc.cpp:117
Definition: doc.cpp:117
Definition: doc.cpp:117

Function Documentation

static void annotateSuperList ( DocCompiler DC,
Tree  superEqList 
)
static

step 8. Annotate superlist.

#8.

Annotate superEqList (to find candidate signals to be named later).

Parameters
[in]DCThe signals compiler.
[out]superEqListThe super equations signal tree to annotate.

Definition at line 732 of file doc.cpp.

References DocCompiler::annotate().

Referenced by prepareDocEqns().

733 {
734  DC->annotate(superEqList);
735 }
Tree annotate(Tree L0)
Definition: doc_compile.cpp:88

Here is the call graph for this function:

Here is the caller graph for this function:

static string calcDocEqnInitial ( const string  s)
static

Calculate an appropriate nickname for equations, from previous names.

Parameters
Thestring to parse.
Returns
Essentially returns the initial character, except "Y" for "process", and "Z" for unnamed equations.

Definition at line 783 of file doc.cpp.

Referenced by calcEqnsNicknames().

784 {
785  string nn;
786  if(s == "process")
787  nn = "Y";
788  else if (s.substr(0,6) == "doceqn")
789  nn = "Z";
790  else
791  nn += toupper(s[0]);
792  return nn;
793 }

Here is the caller graph for this function:

static void calcEqnsNicknames ( const vector< string > &  eqNames,
vector< string > &  eqNicknames 
)
static

step 3. Calculate nicknames.

#3.

Calculate a nickname for each equation and store it.

Parameters
[in]eqNamesEquations names to parse.
[out]eqNicknamesThe place to store calculated nicknames.
Todo:
Should check unicity : check whether several names share the same initial, or else capture consonants for example.

Check duplicates

Definition at line 618 of file doc.cpp.

References calcDocEqnInitial().

Referenced by prepareDocEqns().

619 {
620  //cerr << "###\n# Documentator : calcEqnsNicknames" << endl;
621 
622  vector<string> v;
623 
624  for( vector<string>::const_iterator eq = eqNames.begin(); eq < eqNames.end(); eq++ ) {
625  string init = calcDocEqnInitial(*eq);
626  v.push_back(init);
628 // for( vector<string>::iterator it = v.begin(); it < v.end()-1; ++it ) {
629 // if (init == *it) {
630 // //cerr << "!! Warning Documentator : calcEqnsNicknames : duplicates \"" << init << "\"" << endl;
631 // }
632 // }
633  eqNicknames.push_back(init);
634  }
635 
636 // for( vector<string>::const_iterator eq = eqNames.begin(); eq < eqNames.end(); eq++ ) {
637 // int c = 0;
638 // c = count_if(eqNames.begin(), eqNames.end(), bind2nd(equal_to<string>(), *eq));
639 // if (c > 0) {
640 // cerr << "- Duplicate nickname !! " << *eq << endl;
641 // } else {
642 // cerr << "(no duplicate) " << *eq << endl;
643 // }
644 // }
645 
646  //cerr << "Documentator : end of calcEqnsNicknames\n---" << endl;
647 }
static string calcDocEqnInitial(const string s)
Calculate an appropriate nickname for equations, from previous names.
Definition: doc.cpp:783

Here is the call graph for this function:

Here is the caller graph for this function:

static string calcNumberedName ( const char *  base,
int  i 
)
static

Simply concat a string with a number in a "%03d" format.

The number has MAXIDCHARS characters.

Definition at line 1021 of file doc.cpp.

References MAXIDCHARS, and subst().

Referenced by mapGetEqName().

1022 {
1023  char nb[MAXIDCHARS+1];
1024  sprintf(nb, "%03d", i);
1025  return subst("$0$1", base, nb);
1026 }
#define MAXIDCHARS
max numbers (characters) to represent ids (e.g. for directories).
Definition: doc.cpp:83
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47

Here is the call graph for this function:

Here is the caller graph for this function:

static void collectDocEqns ( const vector< Tree > &  docBoxes,
vector< Tree > &  eqBoxes 
)
static

step 0. Feed a vector.

#0.

Collect every <equation> found in all <mdoc> faust comments.

Parameters
[in]docBoxesThe <mdoc> boxes to filter.
[out]eqBoxesThe place to store only <equation> boxes.

Definition at line 544 of file doc.cpp.

References doc, hd(), isDocEqn(), isList(), reverse(), and tl().

Referenced by prepareDocEqns().

545 {
546  int nbdoceqn = 0;
547 
548  for (vector<Tree>::const_iterator doc=docBoxes.begin(); doc<docBoxes.end(); doc++) {
549  Tree L = reverse(*doc);
550  Tree expr;
551  while (isList(L)) {
552  if ( isDocEqn(hd(L), expr) ) {
553  eqBoxes.push_back(expr);
554  nbdoceqn++;
555  }
556  L = tl(L);
557  }
558  }
559  //cerr << "Documentator : collectDocEqns : " << nbdoceqn << " <equation> tags found." << endl;
560 }
Tree reverse(Tree l)
Definition: list.cpp:240
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
#define doc
Definition: faustlexer.cpp:806
bool isDocEqn(Tree t, Tree &x)
Definition: doc.cpp:186
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

static void collectEqSigs ( const vector< Tree > &  eqSigs,
Tree superEqList 
)
static

step 7. Collect all signals in a superlist.

#7.

Collect each prepared list of signals to construct a super list.

Parameters
[in]eqSigsContains well-prepared and nicknamed signals.
[out]superEqListThe root where to 'cons' signals all together.

Definition at line 711 of file doc.cpp.

References cons(), and nil.

Referenced by prepareDocEqns().

712 {
713  //cerr << "###\n# Documentator : collectEqSigs" << endl;
714 
715  superEqList = nil;
716 
717  for( vector<Tree>::const_iterator it = eqSigs.begin(); it < eqSigs.end(); ++it ) {
718  superEqList = cons( *it, superEqList );
719  }
720  //printSignal(superEqList, stdout, 0);
721 
722  //cerr << endl << "Documentator : end of collectEqSigs\n---" << endl;
723 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static void copyFaustSources ( const char *  projname,
const vector< string > &  pathnames 
)
static

Copy all Faust source files into an 'src' subdirectory.

Parameters
[in]projnameBasename of the new doc directory ("*-math").
[in]pathnamesThe paths list of the source files to copy.

Definition at line 1051 of file doc.cpp.

References filebasename(), makedir(), and subst().

Referenced by printDoc().

1052 {
1053  string srcdir = subst("$0/src", projname);
1054  //cerr << "Documentator : copyFaustSources : Creating directory '" << srcdir << "'" << endl;
1055  makedir(srcdir.c_str()); // create a directory.
1056 
1057  for (unsigned int i=0; i< pathnames.size(); i++) {
1058  ifstream src;
1059  ofstream dst;
1060  string faustfile = pathnames[i];
1061  string copy = subst("$0/$1", srcdir, filebasename(faustfile.c_str()));
1062  //cerr << "Documentator : copyFaustSources : Opening input file '" << faustfile << "'" << endl;
1063  //cerr << "Documentator : copyFaustSources : Opening output file '" << copy << "'" << endl;
1064  src.open(faustfile.c_str(), ifstream::in);
1065  dst.open(copy.c_str(), ofstream::out);
1066  string s;
1067  while ( getline(src,s) ) dst << s << endl;
1068  }
1069 }
int makedir(string dirname)
Definition: files.cpp:72
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
const char * filebasename(const char *name)
returns a pointer on the basename part of name
Definition: enrobage.cpp:544

Here is the call graph for this function:

Here is the caller graph for this function:

vector< string > & docCodeSlicer ( const string &  faustfile,
vector< string > &  codeSlices 
)

Slice faust code between "mdoc" sections.

Parameters
[in]faustfileName of the input faust file to parse.
[in]codeSlicesThe place to store code "slices".

Caution: we suppose there's only one <mdoc> tag per line!

A change has come. ;)

Definition at line 891 of file doc.cpp.

Referenced by printdoccontent().

892 {
893  string s;
894  ifstream src;
895  src.open(faustfile.c_str(), ifstream::in);
896  string tmp = "";
897 
898  bool isInsideDoc = false;
899 
900  if (faustfile != "" && src.good()) {
901  while(getline(src, s)) {
902  size_t foundopendoc = s.find("<mdoc>");
903 
904  if (foundopendoc != string::npos) {
905  if (isInsideDoc == false) {
906  if (! tmp.empty() ) {
907  codeSlices.push_back(tmp); }
908  tmp = "";
909  }
910  isInsideDoc = true;
911  }
912 
913  if (isInsideDoc == false) {
914  tmp += s + '\n';
915  }
916 
917  size_t foundclosedoc = s.find("</mdoc>");
918  if (foundclosedoc != string::npos) isInsideDoc = false;
919  }
920  } else {
921  cerr << "ERROR : can't open faust source file " << faustfile << endl;
922  exit(1);
923  }
924  return codeSlices;
925 }

Here is the caller graph for this function:

Tree docDgm ( Tree  x)

Definition at line 189 of file doc.cpp.

References DOCDGM, and tree().

Referenced by declareAutoDoc(), and yyparse().

189 { return tree(DOCDGM, x); }
Tree tree(const Node &n)
Definition: tree.hh:186
Sym DOCDGM
Definition: doc.cpp:188

Here is the call graph for this function:

Here is the caller graph for this function:

Tree docEqn ( Tree  x)

Definition at line 185 of file doc.cpp.

References DOCEQN, and tree().

Referenced by declareAutoDoc(), and yyparse().

185 { return tree(DOCEQN, x); }
Sym DOCEQN
Definition: doc.cpp:184
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Tree docLst ( )

Definition at line 197 of file doc.cpp.

References DOCLST, and tree().

Referenced by declareAutoDoc(), and yyparse().

197 { return tree(DOCLST); }
Tree tree(const Node &n)
Definition: tree.hh:186
Sym DOCLST
Definition: doc.cpp:196

Here is the call graph for this function:

Here is the caller graph for this function:

Tree docMtd ( Tree  x)

Definition at line 201 of file doc.cpp.

References DOCMTD, and tree().

Referenced by declareAutoDoc(), and yyparse().

201 { return tree(DOCMTD, x); }
Tree tree(const Node &n)
Definition: tree.hh:186
Sym DOCMTD
Definition: doc.cpp:200

Here is the call graph for this function:

Here is the caller graph for this function:

Tree docNtc ( )

Definition at line 193 of file doc.cpp.

References DOCNTC, and tree().

Referenced by declareAutoDoc(), and yyparse().

193 { return tree(DOCNTC); }
Sym DOCNTC
Definition: doc.cpp:192
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Tree docTxt ( const char *  name)

Definition at line 171 of file doc.cpp.

References DOCTXT, symbol(), and tree().

Referenced by declareAutoDoc(), and yyparse().

171 { return tree( DOCTXT, tree(symbol(name)) ); }
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
Definition: symbol.hh:95
Sym DOCTXT
Definition: doc.cpp:170

Here is the call graph for this function:

Here is the caller graph for this function:

static bool doesFileBeginWithCode ( const string &  faustfile)
static

Test whether a file does begin with some faust code or not.

Parameters
[in]faustfileName of the input faust file to parse.

Definition at line 949 of file doc.cpp.

Referenced by printdoccontent().

950 {
951  string s;
952  ifstream src;
953  src.open(faustfile.c_str(), ifstream::in);
954 
955  if (faustfile != "" && src.good()) {
956  getline(src, s);
957  size_t foundopendoc = s.find("<mdoc>");
958  if(int(foundopendoc)==0) {
959  return false;
960  } else {
961  return true;
962  }
963  } else {
964  cerr << "ERROR : can't open faust source file " << faustfile << endl;
965  exit(1);
966  }
967 }

Here is the caller graph for this function:

static void getBoxInputsAndOutputs ( const Tree  t,
int &  numInputs,
int &  numOutputs 
)
static

Just get the number of inputs and the number of outputs of a box.

Parameters
[in]tThe box tree to get inputs and outputs from.
[out]numInputsThe place to store the number of inputs.
[out]numOutputsThe place to store the number of outputs.

Definition at line 803 of file doc.cpp.

References getBoxType().

Referenced by mapPrepareEqSig().

804 {
805  if (!getBoxType(t, &numInputs, &numOutputs)) {
806  cerr << "ERROR during the evaluation of t : " << boxpp(t) << endl;
807  exit(1);
808  }
809  //cerr << "Documentator : " << numInputs <<" inputs and " << numOutputs <<" outputs for box : " << boxpp(t) << endl;
810 }
Definition: ppbox.hh:58
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static struct tm * getCompilationDate ( )
static

Definition at line 1083 of file doc.cpp.

References gCompilationDate, and initCompilationDate().

Referenced by printfaustdocstamp(), and printlatexheader().

1084 {
1086  return &gCompilationDate;
1087 }
static void initCompilationDate()
Definition: doc.cpp:1075
static struct tm gCompilationDate
Definition: doc.cpp:111

Here is the call graph for this function:

Here is the caller graph for this function:

static void initCompilationDate ( )
static

Definition at line 1075 of file doc.cpp.

References gCompilationDate.

Referenced by getCompilationDate().

1076 {
1077  time_t now;
1078 
1079  time(&now);
1080  gCompilationDate = *localtime(&now);
1081 }
static struct tm gCompilationDate
Definition: doc.cpp:111

Here is the caller graph for this function:

bool isDocDgm ( Tree  t,
Tree x 
)

Definition at line 190 of file doc.cpp.

References DOCDGM, and isTree().

Referenced by printdoccontent().

190 { return isTree(t, DOCDGM, x); }
Sym DOCDGM
Definition: doc.cpp:188
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

Here is the call graph for this function:

Here is the caller graph for this function:

bool isDocEqn ( Tree  t,
Tree x 
)

Definition at line 186 of file doc.cpp.

References DOCEQN, and isTree().

Referenced by collectDocEqns(), and printdoccontent().

186 { return isTree(t, DOCEQN, x); }
Sym DOCEQN
Definition: doc.cpp:184
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

Here is the call graph for this function:

Here is the caller graph for this function:

bool isDocLst ( Tree  t)

Definition at line 198 of file doc.cpp.

References DOCLST, and isTree().

Referenced by printdoccontent().

198 { return isTree(t, DOCLST); }
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305
Sym DOCLST
Definition: doc.cpp:196

Here is the call graph for this function:

Here is the caller graph for this function:

bool isDocMtd ( Tree  t,
Tree x 
)

Definition at line 202 of file doc.cpp.

References DOCMTD, and isTree().

Referenced by printdoccontent().

202 { return isTree(t, DOCMTD, x); }
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305
Sym DOCMTD
Definition: doc.cpp:200

Here is the call graph for this function:

Here is the caller graph for this function:

bool isDocNtc ( Tree  t)

Definition at line 194 of file doc.cpp.

References DOCNTC, and isTree().

Referenced by printdoccontent().

194 { return isTree(t, DOCNTC); }
Sym DOCNTC
Definition: doc.cpp:192
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305

Here is the call graph for this function:

Here is the caller graph for this function:

bool isDocTxt ( Tree  t)

Definition at line 172 of file doc.cpp.

References DOCTXT, and CTree::node().

Referenced by printdoccontent().

172 { return t->node() == Node(DOCTXT); }
Class Node = (type x (int + double + Sym + void*))
Definition: node.hh:75
const Node & node() const
return the content of the tree
Definition: tree.hh:143
Sym DOCTXT
Definition: doc.cpp:170

Here is the call graph for this function:

Here is the caller graph for this function:

bool isDocTxt ( Tree  t0,
const char **  str 
)

Definition at line 173 of file doc.cpp.

References DOCTXT, isSym(), isTree(), name(), and CTree::node().

174 {
175  Tree t1; Sym s;
176  if ( isTree(t0, DOCTXT, t1) && isSym(t1->node(), &s) ) {
177  *str = name(s);
178  return true;
179  } else {
180  return false;
181  }
182 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isSym(const Node &n)
Definition: node.hh:199
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Symbols are unique objects with a name stored in a hash table.
Definition: symbol.hh:53
bool isTree(const Tree &t, const Node &n)
Definition: tree.cpp:305
Sym DOCTXT
Definition: doc.cpp:170

Here is the call graph for this function:

static char * legalFileName ( const Tree  t,
int  n,
char *  dst 
)
static

Transform the definition name property of tree <t> into a legal file name.

The resulting file name is stored in <dst> a table of at least <n> chars. Returns the <dst> pointer for convenience.

Definition at line 999 of file doc.cpp.

References getDefNameProperty(), and tree2str().

Referenced by printDocDgm().

1000 {
1001  Tree id;
1002  int i=0;
1003  if (getDefNameProperty(t, id)) {
1004  const char* src = tree2str(id);
1005  for (i=0; isalnum(src[i]) && i<16; i++) {
1006  dst[i] = src[i];
1007  }
1008  }
1009  dst[i] = 0;
1010  if (strcmp(dst, "process") != 0) {
1011  // if it is not process add the hex address to make the name unique
1012  snprintf(&dst[i], n-i, "-%p", t);
1013  }
1014  return dst;
1015 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278

Here is the call graph for this function:

Here is the caller graph for this function:

static void mapCompileDocEqnSigs ( const vector< Tree > &  eqSigs,
const vector< int > &  eqInputs,
const vector< int > &  eqOutputs,
DocCompiler DC,
vector< Lateq * > &  docCompiledEqnsVector 
)
static

step 10. Compile equations.

#9.

Calculated and set lateq (LaTeX equation) names. Note : Transfered into mapCompileDocEqnSigs (DocCompiler::compileMultiSignal). #10. Name and compile prepared doc <equation> signals.

Parameters
[in]eqSigsContains well-prepared and nicknamed signals.
[in]DCThe signals compiler.
[out]docCompiledEqnsVectorThe place to store each compiled Lateq* object.

Definition at line 755 of file doc.cpp.

References DocCompiler::compileLateq().

Referenced by prepareDocEqns().

756 {
757  //cerr << "###\n# Documentator : mapCompileDocEqnSigs" << endl;
758 
759  for( unsigned int i=0; i < eqSigs.size(); i++ ) {
760 
761  // docCompiledEqnsVector.push_back( DC->compileMultiSignal(*it, 0) );
762  docCompiledEqnsVector.push_back( DC->compileLateq(eqSigs[i], new Lateq(eqInputs[i], eqOutputs[i])) );
763  }
764 
765  //cerr << "Documentator : end of mapCompileDocEqnSigs\n---" << endl;
766 }
Definition: lateq.hh:56
Lateq * compileLateq(Tree L, Lateq *compiledEqn)

Here is the call graph for this function:

Here is the caller graph for this function:

static void mapEvalDocEqn ( const vector< Tree > &  eqBoxes,
const Tree env,
vector< Tree > &  evalEqBoxes 
)
static

step 1. Evaluate boxes.

#1.

Evaluate every doc <equation> (evaluation replaces abstractions by symbolic boxes).

Parameters
[in]eqBoxesThe boxes to evaluate.
[in]envThe environment for the evaluation.
[out]evalEqBoxesThe place to store evaluated equations boxes.

Definition at line 570 of file doc.cpp.

References evaldocexpr().

Referenced by prepareDocEqns().

571 {
572  //cerr << "###\n# Documentator : mapEvalDocEqn" << endl;
573 
574  for ( vector<Tree>::const_iterator eq=eqBoxes.begin(); eq < eqBoxes.end(); eq++)
575  {
576  evalEqBoxes.push_back(evaldocexpr( *eq, env ));
577  }
578  //cerr << "Documentator : end of mapEvalDocEqn\n---" << endl;
579 }
Tree evaldocexpr(Tree docexpr, Tree eqlist)
Definition: eval.cpp:114

Here is the call graph for this function:

Here is the caller graph for this function:

static void mapGetEqName ( const vector< Tree > &  evalEqBoxes,
vector< string > &  eqNames 
)
static

step 2. Get boxes name.

#2.

Get name if exists, else create one, and store it.

Parameters
[in]evalEqBoxesEvaluated box trees, eventually containing an equation name.
[out]eqNamesThe place to store equations names.

Definition at line 588 of file doc.cpp.

References calcNumberedName(), getBoxType(), getDefNameProperty(), and tree2str().

Referenced by prepareDocEqns().

589 {
590  //cerr << "###\n# Documentator : mapGetEqName" << endl;
591 
592  int i = 1;
593  for( vector<Tree>::const_iterator eq = evalEqBoxes.begin(); eq < evalEqBoxes.end(); eq++, i++ ) {
594  Tree id;
595  string s;
596  int n,m; getBoxType(*eq, &n, &m); // eq name only for bd without inputs
597  if ( n==0 && getDefNameProperty(*eq, id) ) {
598  s = tree2str(id);
599  }
600  else {
601  s = calcNumberedName("doceqn-", i);
602  }
603  eqNames.push_back( s ) ;
604  }
605  //cerr << "Documentator : end of mapGetEqName\n---" << endl;
606 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
static string calcNumberedName(const char *base, int i)
Simply concat a string with a number in a "%03d" format.
Definition: doc.cpp:1021
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static void mapPrepareEqSig ( const vector< Tree > &  evalEqBoxes,
vector< int > &  eqInputs,
vector< int > &  eqOutputs,
vector< Tree > &  eqSigs 
)
static

step 4&5. Propagate and prepare signals.

#4&5.

Propagate and prepare every doc <equation>.

Call boxPropagateSig, deBruijn2Sym, simplify, and privatise.

Parameters
[in]evalEqBoxesEquations boxes to propagate as signals.
[out]eqSigsThe place to store prepared signals.

< Convert debruijn recursion into symbolic recursion

< Simplify by executing every computable operation

< convert regular tables into special doctables (regular tables are difficult to translate to equations)

Definition at line 658 of file doc.cpp.

References boxPropagateSig(), deBruijn2Sym(), docTableConvertion(), getBoxInputsAndOutputs(), makeSigInputList(), nil, and simplify().

Referenced by prepareDocEqns().

659 {
660  //cerr << "###\n# Documentator : mapPrepareEqSig" << endl;
661 
662  for( vector<Tree>::const_iterator eq = evalEqBoxes.begin(); eq < evalEqBoxes.end(); eq++ ) {
663 
664  int numInputs, numOutputs;
665  getBoxInputsAndOutputs(*eq, numInputs, numOutputs);
666  //cerr << numInputs <<" ins and " << numOutputs <<" outs" << endl;
667  eqInputs.push_back(numInputs);
668  eqOutputs.push_back(numOutputs);
669 
670  Tree lsig1 = boxPropagateSig( nil, *eq , makeSigInputList(numInputs) );
671  //cerr << "output signals are : " << endl; printSignal(lsig1, stderr);
672 
673  Tree lsig2 = deBruijn2Sym(lsig1);
674  Tree lsig3 = simplify(lsig2);
675  //Tree lsig4 = privatise(lsig3); ///< Un-share tables with multiple writers
676  Tree lsig4 = docTableConvertion(lsig3);
677 
679  eqSigs.push_back(lsig4);
680  }
681  //cerr << "Documentator : end of mapPrepareEqSig\n---" << endl;
682 }
Tree deBruijn2Sym(Tree t)
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree simplify(Tree sig)
Definition: simplify.cpp:76
Tree docTableConvertion(Tree sig)
Definition: simplify.cpp:317
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
Definition: propagate.cpp:501
static void getBoxInputsAndOutputs(const Tree t, int &numInputs, int &numOutputs)
Just get the number of inputs and the number of outputs of a box.
Definition: doc.cpp:803
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
Definition: propagate.cpp:96
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static void mapSetSigNickname ( const vector< string > &  eqNicknames,
const vector< int > &  eqInputs,
const vector< Tree > &  eqSigs 
)
static

step 6. Set signals nicknames.

#6.

Set signals nicknames.

Do nothing for the moment !

Parameters
[in]eqNicknamesContains previously calculated nicknames.
[out]eqSigsThe signals to tag with a NICKNAMEPROPERTY.

Definition at line 692 of file doc.cpp.

Referenced by prepareDocEqns().

693 {
694  //cerr << "###\n# Documentator : mapSetSigNickname" << endl;
695 
696 // Do nothing for the moment...
697 // for( unsigned int i=0; i < eqSigs.size(); i++ ) {
698 // if (eqInputs[i] == 0) // Only "generators" should be finally named with user equation (nick)name.
699 // setSigListNickName(eqSigs[i], eqNicknames[i]);
700 // }
701  //cerr << "Documentator : end of mapSetSigNickname\n---" << endl;
702 }

Here is the caller graph for this function:

static istream * openArchFile ( const string &  filename)
static

Open architecture file.

Definition at line 977 of file doc.cpp.

References cholddir(), getCurrentDir(), and open_arch_stream().

Referenced by printDoc().

978 {
979  istream* file;
980  getCurrentDir(); // Save the current directory.
981  //cerr << "Documentator : openArchFile : Opening input file '" << filename << "'" << endl;
982  if ( (file = open_arch_stream(filename.c_str())) ) {
983  //cerr << "Documentator : openArchFile : Opening '" << filename << "'" << endl;
984  } else {
985  cerr << "ERROR : can't open architecture file " << filename << endl;
986  exit(1);
987  }
988  cholddir(); // Return to current directory.
989  return file;
990 }
static int cholddir()
Switch back to the previously stored current directory.
Definition: doc_lang.cpp:242
ifstream * open_arch_stream(const char *filename)
Try to open an architecture file searching in various directories.
Definition: enrobage.cpp:220
static void getCurrentDir()
Get current directory and store it in gCurrentDir.
Definition: doc_lang.cpp:256

Here is the call graph for this function:

Here is the caller graph for this function:

static void prepareDocEqns ( const vector< Tree > &  docBoxes,
vector< Lateq * > &  docCompiledEqnsVector 
)
static

Caller function.

Caller function for all steps of doc equations preparation.

Note : many of the functions called put their result into their last argument in a "source / destination" manner, the "destination" being declared before the function call.

Parameters
[in]docBoxesThe <mdoc> boxes to collect and prepare.
[out]docCompiledEqnsVectorThe place to store compiled equations.

< step 0. Feed a vector.

< step 1. Evaluate boxes.

< step 2. Get boxes name.

< step 3. Calculate nicknames.

< step 4&5. Propagate and prepare signals.

< step 6. Set signals nicknames.

< step 7. Collect all signals in a superlist.

< step 8. Annotate superEqList.

< step 10. Compile every signal.

Definition at line 515 of file doc.cpp.

References annotateSuperList(), calcEqnsNicknames(), collectDocEqns(), collectEqSigs(), gExpandedDefList, mapCompileDocEqnSigs(), mapEvalDocEqn(), mapGetEqName(), mapPrepareEqSig(), and mapSetSigNickname().

Referenced by printdoccontent().

516 {
517  vector<Tree> eqBoxes; collectDocEqns( docBoxes, eqBoxes );
518 
519  if(! eqBoxes.empty() ) {
520  vector<Tree> evalEqBoxes; mapEvalDocEqn( eqBoxes, gExpandedDefList, evalEqBoxes );
521  vector<string> eqNames; mapGetEqName( evalEqBoxes, eqNames );
522  vector<string> eqNicknames; calcEqnsNicknames( eqNames, eqNicknames );
523 
524  vector<int> eqInputs;
525  vector<int> eqOutputs;
526  vector<Tree> eqSigs; mapPrepareEqSig( evalEqBoxes, eqInputs, eqOutputs, eqSigs );
527  mapSetSigNickname( eqNicknames, eqInputs, eqSigs );
528  Tree superEqList; collectEqSigs( eqSigs, superEqList );
529 
530  DocCompiler* DC = new DocCompiler(0, 0);
531  annotateSuperList( DC, superEqList );
532  //calcAndSetLtqNames( superEqList ); ///< step 9. (directly in 10.)
533  mapCompileDocEqnSigs( eqSigs, eqInputs, eqOutputs, DC, docCompiledEqnsVector );
534  }
535 }
static void annotateSuperList(DocCompiler *DC, Tree superEqList)
step 8. Annotate superlist.
Definition: doc.cpp:732
static void mapCompileDocEqnSigs(const vector< Tree > &eqSigs, const vector< int > &eqInputs, const vector< int > &eqOutputs, DocCompiler *DC, vector< Lateq * > &docCompiledEqnsVector)
step 10. Compile equations.
Definition: doc.cpp:755
static void mapSetSigNickname(const vector< string > &eqNicknames, const vector< int > &eqInputs, const vector< Tree > &eqSigs)
step 6. Set signals nicknames.
Definition: doc.cpp:692
static void collectDocEqns(const vector< Tree > &docBoxes, vector< Tree > &eqBoxes)
step 0. Feed a vector.
Definition: doc.cpp:544
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree gExpandedDefList
Definition: main.cpp:108
static void mapPrepareEqSig(const vector< Tree > &evalEqBoxes, vector< int > &eqInputs, vector< int > &eqOutputs, vector< Tree > &eqSigs)
step 4&5. Propagate and prepare signals.
Definition: doc.cpp:658
static void collectEqSigs(const vector< Tree > &eqSigs, Tree &superEqList)
step 7. Collect all signals in a superlist.
Definition: doc.cpp:711
Compile a list of FAUST signals into a list of LaTeX formulas.
Definition: doc_compile.hh:48
static void calcEqnsNicknames(const vector< string > &eqNames, vector< string > &eqNicknames)
step 3. Calculate nicknames.
Definition: doc.cpp:618
static void mapGetEqName(const vector< Tree > &evalEqBoxes, vector< string > &eqNames)
step 2. Get boxes name.
Definition: doc.cpp:588
static void mapEvalDocEqn(const vector< Tree > &eqBoxes, const Tree &env, vector< Tree > &evalEqBoxes)
step 1. Evaluate boxes.
Definition: doc.cpp:570

Here is the call graph for this function:

Here is the caller graph for this function:

void printDoc ( const char *  projname,
const char *  docdev,
const char *  faustversion 
)

The entry point to generate faust doc files.

The entry point to generate the output LaTeX file, stored in the directory "<projname>-math/". This file eventually references images for diagrams, generated in SVG subdirectories. The device system was adapted from drawSchema's device system.

Parameters
[in]projnameBasename of the new doc directory ("*-math").
[in]docdevThe doc device; only ".tex" is supported for the moment.
[in]faustversionThe current version of this Faust compiler.

File stuff : create doc directories and a tex file.

Create THE mathdoc tex file.

Init and load translation file.

Simulate a default doc if no <mdoc> tag detected.

Printing stuff : in the '.tex' ouptut file, eventually including SVG files.

< Faust version and compilation date (comment).

< Static LaTeX header (packages and setup).

< Generate math contents (main stuff!).

< Static LaTeX footer.

Definition at line 224 of file doc.cpp.

References cholddir(), copyFaustSources(), declareAutoDoc(), gDocDevSuffix, gDocLang, gDocName, gDocVector, gLatexheaderfilename, gReader, SourceReader::listSrcFiles(), loadTranslationFile(), makedir(), mkchdir(), openArchFile(), printdoccontent(), printfaustdocstamp(), printlatexfooter(), printlatexheader(), and subst().

Referenced by main().

225 {
226  gDocDevSuffix = docdev;
227 
229  //cerr << "Documentator : printDoc : gFaustDirectory = '" << gFaustDirectory << "'" << endl;
230  //cerr << "Documentator : printDoc : gFaustSuperDirectory = '" << gFaustSuperDirectory << "'" << endl;
231  //cerr << "Documentator : printDoc : gFaustSuperSuperDirectory = '" << gFaustSuperSuperDirectory << "'" << endl;
232  //cerr << "Documentator : printDoc : gCurrentDir = '" << gCurrentDir << "'" << endl;
233 
234  makedir(projname); // create a top directory to store files
235 
236  string svgTopDir = subst("$0/svg", projname);
237  makedir(svgTopDir.c_str()); // create a directory to store svg-* subdirectories.
238 
239  string cppdir = subst("$0/cpp", projname);
240  makedir(cppdir.c_str()); // create a cpp directory.
241 
242  string pdfdir = subst("$0/pdf", projname);
243  makedir(pdfdir.c_str()); // create a pdf directory.
244 
245  /* Copy all Faust source files into an 'src' sub-directory. */
246  vector<string> pathnames = gReader.listSrcFiles();
247  copyFaustSources(projname, pathnames);
248 
249  string texdir = subst("$0/tex", projname);
250  mkchdir(texdir.c_str()); // create a directory and move into.
251 
253  ofstream docout(subst("$0.$1", gDocName, docdev).c_str());
254  cholddir(); // return to current directory
255 
258 
260  if (gDocVector.empty()) { declareAutoDoc(); }
261 
263  printfaustdocstamp(faustversion, docout);
264  istream* latexheader = openArchFile(gLatexheaderfilename);
265  printlatexheader(*latexheader, faustversion, docout);
266  printdoccontent(svgTopDir.c_str(), gDocVector, faustversion, docout);
267  printlatexfooter(docout);
268 }
static void printlatexheader(istream &latexheader, const string &faustversion, ostream &docout)
Print a static LaTeX header.
Definition: doc.cpp:283
static int cholddir()
Switch back to the previously stored current directory.
Definition: doc_lang.cpp:242
int mkchdir(string dirname)
Create a new directory in the current one to store the diagrams.
Definition: files.cpp:55
static void printdoccontent(const char *svgTopDir, const vector< Tree > &docVector, const string &faustversion, ostream &docout)
Main documentator loop.
Definition: doc.cpp:436
static void copyFaustSources(const char *projname, const vector< string > &pathnames)
Copy all Faust source files into an 'src' subdirectory.
Definition: doc.cpp:1051
static istream * openArchFile(const string &filename)
Open architecture file.
Definition: doc.cpp:977
int makedir(string dirname)
Definition: files.cpp:72
string gDocName
Contains the filename for out documentation.
Definition: main.cpp:107
string gDocLang
Definition: doc.cpp:118
vector< string > listSrcFiles()
Return a vector of pathnames representing the list of all the source files that have been required to...
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
vector< Tree > gDocVector
Contains parsed trees: DOCTXT, DOCEQN, DOCDGM.
Definition: doc.cpp:109
static void printlatexfooter(ostream &docout)
Print the static LaTeX footer.
Definition: doc.cpp:389
static const string gLatexheaderfilename
Definition: doc.cpp:107
void loadTranslationFile(const string &lang)
Definition: doc_lang.cpp:76
SourceReader gReader
Definition: main.cpp:89
static const char * gDocDevSuffix
".tex" (or .??? - used to choose output device).
Definition: doc.cpp:106
static void printfaustdocstamp(const string &faustversion, ostream &docout)
Print a "doc stamp" in the LaTeX document :
Definition: doc.cpp:404
void declareAutoDoc()
Declare an automatic documentation.
Definition: doc_autodoc.cpp:61

Here is the call graph for this function:

Here is the caller graph for this function:

static void printdocCodeSlices ( const string &  code,
ostream &  docout 
)
static

Print faust code inside a listing environment.

Parameters
[in]codeFaust code as a string (may contain '
' characters).
[out]docoutThe output file to print into.

Definition at line 934 of file doc.cpp.

Referenced by printdoccontent().

935 {
936  if ( ! code.empty() ) {
937  docout << endl << "\\begin{lstlisting}[numbers=none, frame=none, basicstyle=\\small\\ttfamily, backgroundcolor=\\color{yobg}]" << endl;
938  docout << code << endl;
939  docout << "\\end{lstlisting}" << endl << endl;
940  }
941 }

Here is the caller graph for this function:

static void printdoccontent ( const char *  svgTopDir,
const vector< Tree > &  docVector,
const string &  faustversion,
ostream &  docout 
)
static

Main documentator loop.

First loop on gDocVector, which contains the faust <mdoc> trees. Second loop for each of these <mdoc> trees, which contain parsed input expressions of 3 types : DOCEQN for <equation> tags, DOCDGM for <diagram> tags, and DOCTXT for direct LaTeX text (no tag).

  • DOCTXT expressions printing is trivial.
  • DOCDGM expressions printing calls 'printDocDgm' to generate SVG files and print LaTeX "figure" code.
  • DOCEQN expressions printing calls 'printDocEqn' after an important preparing work has been done by 'prepareDocEqns'.
Parameters
[in]projnameBasename of the new doc directory ("*-math").
[in]docVectorContains all <mdoc> parsed content (as boxes).
[in]faustversionThe current version of this Faust compiler.
[out]docoutThe output file to print into.

Equations need to be prepared (named and compiled) before printing.

< Quite a lot of stuff there.

< For diagram directories numbering.

First level printing loop, on docVector.

Second level printing loop, on each <mdoc>.

< After equations are well prepared and named.

Definition at line 436 of file doc.cpp.

References CTree::branch(), doc, docCodeSlicer(), doesFileBeginWithCode(), gLstDistributedSwitch, gMasterDocument, hd(), isDocDgm(), isDocEqn(), isDocLst(), isDocMtd(), isDocNtc(), isDocTxt(), isList(), prepareDocEqns(), printdocCodeSlices(), printDocDgm(), printDocEqn(), printDocMetadata(), printDocNotice(), printfaustlistings(), reverse(), and tl().

Referenced by printDoc().

437 {
438  //cerr << endl << "Documentator : printdoccontent : " << docVector.size() << " <mdoc> tags read." << endl;
439 
441  vector<Lateq*> docCompiledEqnsVector;
442  prepareDocEqns( docVector, docCompiledEqnsVector );
443  vector<Lateq*>::iterator eqn_it = docCompiledEqnsVector.begin();
444 
445  int dgmIndex = 1;
446 
447  vector<string> docMasterCodeMap;
448  docMasterCodeMap = docCodeSlicer(gMasterDocument, docMasterCodeMap);
449 
450  vector<Tree>::const_iterator doc;
451  vector<string>::const_iterator code;
452  code = docMasterCodeMap.begin();
453 
454  if(doesFileBeginWithCode(gMasterDocument) && (! docMasterCodeMap.empty()) && gLstDistributedSwitch ) {
455  printdocCodeSlices(*code, docout);
456  code++;
457  }
458 
460  for (doc=docVector.begin(); doc<docVector.end(); doc++, code++) {
461 
462  Tree L = reverse(*doc);
463  //cerr << "Entering into <mdoc> parsing..." << endl;
464 
466  while (isList(L)) {
467  Tree expr;
468  if ( isDocEqn(hd(L), expr) ) {
469  printDocEqn(*eqn_it++, docout);
470  }
471  else if ( isDocDgm(hd(L), expr) ) {
472  printDocDgm(expr, svgTopDir, docout, dgmIndex++);
473  }
474  else if ( isDocMtd(hd(L), expr) ) {
475  printDocMetadata(expr, docout);
476  }
477  else if ( isDocTxt(hd(L)) ) {
478  docout << *hd(L)->branch(0); // Directly print registered doc text.
479  }
480  else if ( isDocNtc(hd(L)) ) {
481  printDocNotice(faustversion, docout);
482  }
483  else if ( isDocLst(hd(L)) ) {
484  printfaustlistings(docout);
485  }
486  else {
487  cerr << "ERROR : " << *hd(L) << " is not a valid documentation type." << endl;
488  }
489  L = tl(L);
490  }
491  //cerr << " ...end of <mdoc> parsing." << endl;
492 
493  if ( code != docMasterCodeMap.end() && gLstDistributedSwitch ) {
494  printdocCodeSlices(*code, docout);
495  }
496  }
497 }
Tree reverse(Tree l)
Definition: list.cpp:240
static void prepareDocEqns(const vector< Tree > &docBoxes, vector< Lateq * > &docCompiledEqnsVector)
Caller function.
Definition: doc.cpp:515
bool gLstDistributedSwitch
mdoc listing management.
Definition: doc.cpp:115
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isDocDgm(Tree t, Tree &x)
Definition: doc.cpp:190
bool isDocNtc(Tree t)
Definition: doc.cpp:194
static void printDocEqn(Lateq *ltq, ostream &docout)
Print doc equations, following the Lateq::println method.
Definition: doc.cpp:819
bool isDocTxt(Tree t)
Definition: doc.cpp:172
bool isList(Tree l)
Definition: list.hh:138
#define doc
Definition: faustlexer.cpp:806
bool isDocMtd(Tree t, Tree &x)
Definition: doc.cpp:202
static void printfaustlistings(ostream &docout)
Print listings of each Faust code ".dsp" files, calling the 'printfaustlisting' function.
Definition: doc.cpp:331
vector< string > & docCodeSlicer(const string &faustfile, vector< string > &codeSlices)
Slice faust code between "mdoc" sections.
Definition: doc.cpp:891
bool isDocEqn(Tree t, Tree &x)
Definition: doc.cpp:186
static void printdocCodeSlices(const string &code, ostream &docout)
Print faust code inside a listing environment.
Definition: doc.cpp:934
string gMasterDocument
Definition: main.cpp:104
bool isDocLst(Tree t)
Definition: doc.cpp:198
static void printDocMetadata(const Tree expr, ostream &docout)
Print a metadata set.
Definition: doc.cpp:311
void printDocNotice(const string &faustversion, ostream &docout)
Print the content of the notice (a string map), as LaTeX items inside an itemize environment.
Definition: doc_notice.cpp:66
static void printDocDgm(const Tree expr, const char *svgTopDir, ostream &docout, int i)
Doc diagrams handling.
Definition: doc.cpp:842
static bool doesFileBeginWithCode(const string &faustfile)
Test whether a file does begin with some faust code or not.
Definition: doc.cpp:949
Tree tl(Tree l)
Definition: list.hh:134
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static void printDocDgm ( const Tree  expr,
const char *  svgTopDir,
ostream &  docout,
int  i 
)
static

Doc diagrams handling.

Three steps :

  1. evaluate expression
  2. call svg drawing in the appropriate directory
  3. print latex figure code with the appropriate directory reference
Parameters
[in]exprParsed input expression, as boxes tree.
[in]svgTopDirBasename of the new doc directory ("*-math/svg").
[out]docoutThe output file to print into.
  1. Evaluate expression.
  2. Draw the diagram after its evaluation, in SVG. Warning : pdflatex can't directly include SVG files !
  3. Print LaTeX figure code.
  4. Warn about naming interferences (in the notice).

Definition at line 842 of file doc.cpp.

References drawSchema(), evaldocexpr(), gDocMathStringMap, gDocNoticeFlagMap, gErrorCount, gExpandedDefList, legalFileName(), MAXIDCHARS, and subst().

Referenced by printdoccontent().

843 {
845  Tree docdgm = evaldocexpr(expr, gExpandedDefList);
846  if (gErrorCount > 0) {
847  cerr << "Total of " << gErrorCount << " errors during evaluation of : diagram docdgm = " << boxpp(docdgm) << ";\n";
848  exit(1);
849  }
850 
855  char dgmid[MAXIDCHARS+1];
856  sprintf(dgmid, "%02d", i);
857  string thisdgmdir = subst("$0/svg-$1", svgTopDir, dgmid);
858  //cerr << "Documentator : printDocDgm : drawSchema in '" << gCurrentDir << "/" << thisdgmdir << "'" << endl;
859 
860  drawSchema( docdgm, thisdgmdir.c_str(), "svg" );
861 
863  char temp[1024];
864  const string dgmfilename = legalFileName(docdgm, 1024, temp);
865  //docout << "figure \\ref{figure" << i << "}";
866  docout << "\\begin{figure}[ht!]" << endl;
867  docout << "\t\\centering" << endl;
868  docout << "\t\\includegraphics[width=\\textwidth]{" << subst("../svg/svg-$0/", dgmid) << dgmfilename << "}" << endl;
869  docout << "\t\\caption{" << gDocMathStringMap["dgmcaption"] << " \\texttt{" << dgmfilename << "}}" << endl;
870  docout << "\t\\label{figure" << i << "}" << endl;
871  docout << "\\end{figure}" << endl << endl;
872 
874  gDocNoticeFlagMap["nameconflicts"] = true;
875  gDocNoticeFlagMap["svgdir"] = true;
876 }
static char * legalFileName(const Tree t, int n, char *dst)
Transform the definition name property of tree into a legal file name.
Definition: doc.cpp:999
#define MAXIDCHARS
max numbers (characters) to represent ids (e.g. for directories).
Definition: doc.cpp:83
void drawSchema(Tree bd, const char *projname, const char *dev)
The entry point to generate from a block diagram as a set of svg files stored in the directory "
Definition: drawschema.cpp:161
Tree evaldocexpr(Tree docexpr, Tree eqlist)
Definition: eval.cpp:114
map< string, bool > gDocNoticeFlagMap
gDocNoticeFlagMap is public to let others turn to "true" flags that one want to print.
Definition: doc_notice.cpp:36
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree gExpandedDefList
Definition: main.cpp:108
map< string, string > gDocMathStringMap
Definition: lateq.cpp:51
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
int gErrorCount
Definition: errormsg.cpp:31
Definition: ppbox.hh:58

Here is the call graph for this function:

Here is the caller graph for this function:

static void printDocEqn ( Lateq ltq,
ostream &  docout 
)
static

Print doc equations, following the Lateq::println method.

Parameters
[in]ltqThe object containing compiled LaTeX code of equations.
[out]docoutThe output file to print into.

Definition at line 819 of file doc.cpp.

References Lateq::println().

Referenced by printdoccontent().

820 {
821  ltq->println(docout);
822  //cerr << "Documentator : printDocEqn : "; ltq->println(cerr); cerr << endl;
823 }
void println(ostream &docout)
Top-level method to print a whole set of compiled LaTeX formulas.
Definition: lateq.cpp:83

Here is the call graph for this function:

Here is the caller graph for this function:

static void printDocMetadata ( const Tree  expr,
ostream &  docout 
)
static

Print a metadata set.

Each metadata is a set, in order to handle multiple items, like multiple authors, even if most of metadatas have unique items.

Parameters
[in]exprParsed metadata keyname, as boxes tree.
[out]docoutThe output file to print into.

Definition at line 311 of file doc.cpp.

References gMetaDataSet, rmExternalDoubleQuotes(), and tree2str().

Referenced by printdoccontent().

312 {
313  if (gMetaDataSet.count(expr)) {
314  string sep = "";
315  set<Tree> mset = gMetaDataSet[expr];
316 
317  for (set<Tree>::iterator j = mset.begin(); j != mset.end(); j++) {
318  docout << sep << rmExternalDoubleQuotes(tree2str(*j));
319  sep = ", ";
320  }
321  }
322 }
map< Tree, set< Tree > > gMetaDataSet
Definition: main.cpp:91
static string rmExternalDoubleQuotes(const string &s)
Remove the leading and trailing double quotes of a string (but not those in the middle of the string)...
Definition: doc.cpp:1032
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278

Here is the call graph for this function:

Here is the caller graph for this function:

static void printfaustdocstamp ( const string &  faustversion,
ostream &  docout 
)
static

Print a "doc stamp" in the LaTeX document :

  • the Faust version,
  • the date of doc compilation,
  • faust's web site URL.
Parameters
[in]faustversionThe current version of this Faust compiler.
[out]docoutThe LaTeX output file to print into.

Definition at line 404 of file doc.cpp.

References getCompilationDate().

Referenced by printDoc().

405 {
406  char datebuf [150];
407  strftime (datebuf, 150, "%c", getCompilationDate());
408 
409  docout << "%% This documentation was generated with Faust version " << faustversion << endl;
410  docout << "%% " << datebuf << endl;
411  docout << "%% http://faust.grame.fr" << endl << endl;
412 }
static struct tm * getCompilationDate()
Definition: doc.cpp:1083

Here is the call graph for this function:

Here is the caller graph for this function:

static void printfaustlisting ( string &  faustfile,
ostream &  docout 
)
static

Print a listing of the Faust code, in a LaTeX "listing" environment.

Strip content of <mdoc> tags.

Parameters
[in]faustfileThe source file containing the Faust code.
[out]docoutThe LaTeX output file to print into.

We suppose there's only one <mdoc> tag per line.

Definition at line 351 of file doc.cpp.

References filebasename(), and gStripDocSwitch.

Referenced by printfaustlistings().

352 {
353  string s;
354  ifstream src;
355 
356  //cerr << "Documentator : printfaustlisting : Opening file '" << faustfile << "'" << endl;
357  src.open(faustfile.c_str(), ifstream::in);
358 
359  docout << endl << "\\bigskip\\bigskip" << endl;
360  docout << "\\begin{lstlisting}[caption=\\texttt{" << filebasename(faustfile.c_str()) << "}]" << endl;
361 
362  bool isInsideDoc = false;
363 
364  if (faustfile != "" && src.good()) {
365  while(getline(src, s)) {
366  size_t foundopendoc = s.find("<mdoc>");
367  if (foundopendoc != string::npos && gStripDocSwitch) isInsideDoc = true;
368 
369  if (isInsideDoc == false)
370  docout << s << endl;
371 
372  size_t foundclosedoc = s.find("</mdoc>");
373  if (foundclosedoc != string::npos && gStripDocSwitch) isInsideDoc = false;
374  }
375  } else {
376  cerr << "ERROR : can't open faust source file " << faustfile << endl;
377  exit(1);
378  }
379 
380  docout << "\\end{lstlisting}" << endl << endl;
381 }
bool gStripDocSwitch
Definition: main.cpp:124
const char * filebasename(const char *name)
returns a pointer on the basename part of name
Definition: enrobage.cpp:544

Here is the call graph for this function:

Here is the caller graph for this function:

static void printfaustlistings ( ostream &  docout)
static

Print listings of each Faust code ".dsp" files, calling the 'printfaustlisting' function.

Parameters
[out]docoutThe LaTeX output file to print into.

Definition at line 331 of file doc.cpp.

References gLstDependenciesSwitch, gMasterDocument, gReader, SourceReader::listSrcFiles(), and printfaustlisting().

Referenced by printdoccontent().

332 {
334  vector<string> pathnames = gReader.listSrcFiles();
335  for (unsigned int i=0; i< pathnames.size(); i++) {
336  printfaustlisting(pathnames[i], docout);
337  }
338  } else {
340  }
341 }
vector< string > listSrcFiles()
Return a vector of pathnames representing the list of all the source files that have been required to...
SourceReader gReader
Definition: main.cpp:89
string gMasterDocument
Definition: main.cpp:104
static void printfaustlisting(string &path, ostream &docout)
Print a listing of the Faust code, in a LaTeX "listing" environment.
Definition: doc.cpp:351
bool gLstDependenciesSwitch
mdoc listing management.
Definition: doc.cpp:113

Here is the call graph for this function:

Here is the caller graph for this function:

static void printlatexfooter ( ostream &  docout)
static

Print the static LaTeX footer.

Parameters
[out]docoutThe LaTeX output file to print into.

Definition at line 389 of file doc.cpp.

Referenced by printDoc().

390 {
391  docout << endl << "\\end{document}" << endl << endl;
392 }

Here is the caller graph for this function:

static void printlatexheader ( istream &  latexheader,
const string &  faustversion,
ostream &  docout 
)
static

Print a static LaTeX header.

Parameters
[in]latexheaderThe file containing the static part of the LaTeX header.
[in]faustversionThe current version of this Faust compiler.
[out]docoutThe LaTeX output file to print into.

Specific LaTeX macros for Faust

Definition at line 283 of file doc.cpp.

References getCompilationDate(), gMasterDocument, and gMasterName.

Referenced by printDoc().

284 {
285  string s;
286  while(getline(latexheader, s)) docout << s << endl;
287 
289  docout << "\\newcommand{\\faustfilename}{" << gMasterDocument << "}" << endl;
290  docout << "\\newcommand{\\faustdocdir}{" << gMasterName << "-mdoc}" << endl;
291  docout << "\\newcommand{\\faustprogname}{" << gMasterName << "}" << endl;
292  docout << "\\newcommand{\\faustversion}{" << faustversion << "}" << endl;
293  char datebuf [150];
294  strftime (datebuf, 150, "%B %d, %Y", getCompilationDate());
295  docout << "\\newcommand{\\faustdocdate}{" << datebuf << "}" << endl;
296 
297  docout << endl << "\\begin{document}" << endl;
298 }
static struct tm * getCompilationDate()
Definition: doc.cpp:1083
string gMasterName
Definition: main.cpp:106
string gMasterDocument
Definition: main.cpp:104

Here is the call graph for this function:

Here is the caller graph for this function:

static string rmExternalDoubleQuotes ( const string &  s)
static

Remove the leading and trailing double quotes of a string (but not those in the middle of the string)

Definition at line 1032 of file doc.cpp.

Referenced by printDocMetadata().

1033 {
1034  size_t i = s.find_first_not_of("\"");
1035  size_t j = s.find_last_not_of("\"");
1036 
1037  if ( (i != string::npos) & (j != string::npos) ) {
1038  return s.substr(i, 1+j-i);
1039  } else {
1040  return "";
1041  }
1042 }

Here is the caller graph for this function:

Variable Documentation

Sym DOCDGM = symbol ("DocDgm")

Definition at line 188 of file doc.cpp.

Referenced by docDgm(), and isDocDgm().

Sym DOCEQN = symbol ("DocEqn")

Definition at line 184 of file doc.cpp.

Referenced by docEqn(), and isDocEqn().

Sym DOCLST = symbol ("DocLst")

Definition at line 196 of file doc.cpp.

Referenced by docLst(), and isDocLst().

Sym DOCMTD = symbol ("DocMtd")

Definition at line 200 of file doc.cpp.

Referenced by docMtd(), and isDocMtd().

Sym DOCNTC = symbol ("DocNtc")

Definition at line 192 of file doc.cpp.

Referenced by docNtc(), and isDocNtc().

Sym DOCTXT = symbol ("DocTxt")

Definition at line 170 of file doc.cpp.

Referenced by docTxt(), and isDocTxt().

struct tm gCompilationDate
static

Definition at line 111 of file doc.cpp.

Referenced by getCompilationDate(), and initCompilationDate().

bool gDetailsSwitch

Definition at line 114 of file main.cpp.

const char* gDocDevSuffix
static

".tex" (or .??? - used to choose output device).

Definition at line 106 of file doc.cpp.

Referenced by printDoc().

string gDocLang

Definition at line 118 of file doc.cpp.

Referenced by printDoc(), and process_cmdline().

map<string, string> gDocMathStringMap

Definition at line 51 of file lateq.cpp.

Referenced by printDocDgm().

map<string, string> gDocMetadatasStringMap

Definition at line 35 of file doc_metadatas.cpp.

string gDocName

Contains the filename for out documentation.

Definition at line 107 of file main.cpp.

Referenced by printDoc().

vector<Tree> gDocVector

Contains <mdoc> parsed trees: DOCTXT, DOCEQN, DOCDGM.

Definition at line 109 of file doc.cpp.

Referenced by declareDoc(), and printDoc().

Tree gExpandedDefList

Definition at line 108 of file main.cpp.

Referenced by main(), prepareDocEqns(), and printDocDgm().

string gFaustDirectory

Definition at line 103 of file main.cpp.

string gFaustSuperDirectory

Definition at line 102 of file main.cpp.

string gFaustSuperSuperDirectory

Definition at line 101 of file main.cpp.

const string gLatexheaderfilename = "latexheader.tex"
static

Definition at line 107 of file doc.cpp.

Referenced by printDoc().

bool gLstDependenciesSwitch = true

mdoc listing management.

Definition at line 113 of file doc.cpp.

Referenced by printfaustlistings(), and yyparse().

bool gLstDistributedSwitch = true

mdoc listing management.

Definition at line 115 of file doc.cpp.

Referenced by printdoccontent(), and yyparse().

bool gLstMdocTagsSwitch = true

mdoc listing management.

Definition at line 114 of file doc.cpp.

string gMasterDocument

Definition at line 104 of file main.cpp.

Referenced by printdoccontent(), printfaustlistings(), and printlatexheader().

string gMasterName

Definition at line 106 of file main.cpp.

Referenced by printlatexheader().

map<Tree, set<Tree> > gMetaDataSet

Definition at line 91 of file main.cpp.

Referenced by printDocMetadata().

SourceReader gReader

Definition at line 89 of file main.cpp.

Referenced by printDoc(), and printfaustlistings().

bool gStripDocSwitch

Definition at line 124 of file main.cpp.

Referenced by printfaustlisting().