FAUST compiler  0.9.9.6b8
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SourceReader Class Reference

#include <sourcereader.hh>

Public Member Functions

bool cached (string fname)
 Check if a file as been read and is in the "cache". More...
 
Tree getlist (string fname)
 Return the list of definitions file contains. More...
 
Tree expandlist (Tree ldef)
 Return the list of definitions where all imports have been expanded. More...
 
vector< string > listSrcFiles ()
 Return a vector of pathnames representing the list of all the source files that have been required to evaluate process (those in fFileCache) More...
 

Private Member Functions

Tree parse (string fname)
 Parse a single faust source file. More...
 
Tree expandrec (Tree ldef, set< string > &visited, Tree lresult)
 

Private Attributes

map< string, TreefFileCache
 
vector< string > fFilePathnames
 

Detailed Description

Definition at line 16 of file sourcereader.hh.

Member Function Documentation

bool SourceReader::cached ( string  fname)

Check if a file as been read and is in the "cache".

Parameters
fnamethe name of the file to check
Returns
true if the file is in the cache

Definition at line 257 of file sourcereader.cpp.

258 {
259  return fFileCache.find(fname) != fFileCache.end();
260 }
map< string, Tree > fFileCache
Definition: sourcereader.hh:18
Tree SourceReader::expandlist ( Tree  ldef)

Return the list of definitions where all imports have been expanded.

Parameters
ldefthe list of definitions to expand
Returns
the expanded list of definitions

Definition at line 306 of file sourcereader.cpp.

References nil.

Referenced by main(), and realeval().

307 {
308  set<string> visited;
309  return expandrec(ldef, visited, nil);
310 }
Tree expandrec(Tree ldef, set< string > &visited, Tree lresult)
Tree nil
Definition: list.cpp:116

Here is the caller graph for this function:

Tree SourceReader::expandrec ( Tree  ldef,
set< string > &  visited,
Tree  lresult 
)
private

Definition at line 312 of file sourcereader.cpp.

References cons(), hd(), isImportFile(), isNil(), tl(), and tree2str().

313 {
314  for (;!isNil(ldef); ldef = tl(ldef)) {
315  Tree d = hd(ldef);
316  Tree fname;
317  if (isNil(d)) {
318  // skill null definitions produced by declarations
319  } else if (isImportFile(d,fname)) {
320  string f = tree2str(fname);
321  //cerr << "import(" << f << ")" << endl;
322 
323  //string f = tree2str(fname);
324  if (visited.find(f) == visited.end()) {
325  visited.insert(f);
326  //Tree l = getlist(f);
327  lresult = expandrec(getlist(f), visited, lresult);
328  }
329 
330  } else {
331  lresult = cons(d, lresult);
332  }
333  }
334  return lresult;
335 }
bool isImportFile(Tree s, Tree &filename)
Definition: boxes.cpp:301
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree expandrec(Tree ldef, set< string > &visited, Tree lresult)
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 isNil(Tree l)
Definition: list.hh:137
Tree getlist(string fname)
Return the list of definitions file contains.
Tree tl(Tree l)
Definition: list.hh:134
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:

Tree SourceReader::getlist ( string  fname)

Return the list of definitions file contains.

Cache the result.

Parameters
fnamethe name of the file to check
Returns
the list of definitions it contains

Definition at line 270 of file sourcereader.cpp.

Referenced by realeval().

271 {
272  if (!cached(fname)) {
273  fFileCache[fname] = parse(fname);
274  }
275  if (fFileCache[fname] == 0) exit(1);
276  return fFileCache[fname];
277 }
bool cached(string fname)
Check if a file as been read and is in the "cache".
Tree parse(string fname)
Parse a single faust source file.
map< string, Tree > fFileCache
Definition: sourcereader.hh:18

Here is the caller graph for this function:

vector< string > SourceReader::listSrcFiles ( )

Return a vector of pathnames representing the list of all the source files that have been required to evaluate process (those in fFileCache)

Definition at line 286 of file sourcereader.cpp.

Referenced by declareAutoDoc(), main(), printDoc(), and printfaustlistings().

287 {
288 // vector<string> srcfiles;
289 
290 // for (map<string, Tree>::const_iterator p = fFileCache.begin(); p != fFileCache.end(); p++) {
291 // srcfiles.push_back(p->first);
292 // }
293 
294 // return srcfiles;
295  return fFilePathnames;
296 }
vector< string > fFilePathnames
Definition: sourcereader.hh:19

Here is the caller graph for this function:

Tree SourceReader::parse ( string  fname)
private

Parse a single faust source file.

returns the list of definitions it contains.

Parameters
fnamethe name of the file to parse
Returns
the list of definitions it contains

Definition at line 189 of file sourcereader.cpp.

References fopensearch(), gResult, http_fetch(), http_perror(), yy_scan_string(), yyerr, yyfilename, yyin, yylineno, yyparse(), and yyrestart().

190 {
191  string fullpath;
192  char* fileBuf = 0;
193 
194  yyerr = 0;
195 
196  yyfilename = fname.c_str();
197  if (strstr(yyfilename,"http://") != 0) {
198  // We are requested to parse an URL file
199  int ret = http_fetch(yyfilename, &fileBuf);
200  if (ret == -1) {
201  http_perror("http fetch");
202  exit(1);
203  }
204  yy_scan_string(fileBuf);
205  yylineno = 1;
206  int r = yyparse();
207  if (r) {
208  fprintf(stderr, "Parse error : code = %d \n", r);
209  }
210  if (yyerr > 0) {
211  //fprintf(stderr, "Erreur de parsing 2, count = %d \n", yyerr);
212  exit(1);
213  }
214 
215  // we have parsed a valid file
216  fFilePathnames.push_back(fullpath);
217  free(fileBuf);
218  return gResult;
219 
220  } else {
221  // test for local url
222  if (strstr(yyfilename,"file://") != 0) {
223  yyfilename = &yyfilename[7]; // skip 'file://'
224  }
225 
226  // We are requested to parse a regular file
227  yyin = fopensearch(yyfilename, fullpath);
228  if (yyin == NULL) {
229  fprintf(stderr, "ERROR : Unable to open file %s \n", yyfilename);
230  exit(1);
231  }
232  yyrestart(yyin); // make sure we scan from file again (in case we scanned a string just before)
233  yylineno = 1;
234  int r = yyparse();
235  if (r) {
236  fprintf(stderr, "Parse error : code = %d \n", r);
237  }
238  if (yyerr > 0) {
239  //fprintf(stderr, "Erreur de parsing 2, count = %d \n", yyerr);
240  exit(1);
241  }
242 
243  // we have parsed a valid file
244  fFilePathnames.push_back(fullpath);
245  return gResult;
246  }
247 }
const char * yyfilename
Definition: errormsg.cpp:30
void yyrestart(FILE *new_file)
Immediately switch to a different input stream.
void http_perror(const char *string)
Tree gResult
Definition: main.cpp:86
vector< string > fFilePathnames
Definition: sourcereader.hh:19
int yyparse()
FILE * fopensearch(const char *filename, string &fullpath)
Try to open the file searching in various directories.
Definition: enrobage.cpp:458
int http_fetch(const char *url_tmp, char **fileBuf)
FILE * yyin
int yyerr
Definition: main.cpp:83
int yylineno
struct yy_buffer_state * yy_scan_string(const char *yy_str)

Here is the call graph for this function:

Member Data Documentation

map<string, Tree> SourceReader::fFileCache
private

Definition at line 18 of file sourcereader.hh.

vector<string> SourceReader::fFilePathnames
private

Definition at line 19 of file sourcereader.hh.


The documentation for this class was generated from the following files: