2
sourcereader : Faust source file reader
4
This component is in charge of mapping filenames to
5
the list of faust definitions they contain.
10
#include "sourcereader.hh"
11
#include "enrobage.hh"
14
/****************************************************************
16
*****************************************************************/
25
extern const char * yyfilename;
32
* Parse a single faust source file. returns the list of
33
* definitions it contains.
35
* @param fname the name of the file to parse
36
* @return the list of definitions it contains
39
Tree SourceReader::parse(string fname)
43
yyfilename = fname.c_str();
44
yyin = fopensearch(yyfilename);
46
fprintf(stderr, "ERROR : Unable to open file %s \n", yyfilename);
53
fprintf(stderr, "Parse error : code = %d \n", r);
56
//fprintf(stderr, "Erreur de parsing 2, count = %d \n", yyerr);
65
* Check if a file as been read and is in the "cache"
67
* @param fname the name of the file to check
68
* @return true if the file is in the cache
71
bool SourceReader::cached(string fname)
73
return fFileCache.find(fname) != fFileCache.end();
78
* Return the list of definitions file contains. Cache the result.
80
* @param fname the name of the file to check
81
* @return the list of definitions it contains
84
Tree SourceReader::getlist(string fname)
87
fFileCache[fname] = parse(fname);
89
return fFileCache[fname];
94
* Return the list of definitions where all imports have been expanded.
96
* @param ldef the list of definitions to expand
97
* @return the expanded list of definitions
100
Tree SourceReader::expandlist(Tree ldef)
103
return expandrec(ldef, visited, nil);
106
Tree SourceReader::expandrec(Tree ldef, set<string>& visited, Tree lresult)
108
for (;!isNil(ldef); ldef = tl(ldef)) {
112
// skill null definitions produced by declarations
113
} else if (isImportFile(d,fname)) {
114
string f = tree2str(fname);
115
//cerr << "import(" << f << ")" << endl;
117
//string f = tree2str(fname);
118
if (visited.find(f) == visited.end()) {
120
//Tree l = getlist(f);
121
lresult = expandrec(getlist(f), visited, lresult);
125
lresult = cons(d, lresult);