SourceReader Class Reference

#include <sourcereader.hh>

List of all members.

Public Member Functions

bool cached (string fname)
 Check if a file as been read and is in the "cache".
Tree getlist (string fname)
 Return the list of definitions file contains.
Tree expandlist (Tree ldef)
 Return the list of definitions where all imports have been expanded.
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).

Private Member Functions

Tree parse (string fname)
 Parse a single faust source file.
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:
fname the name of the file to check
Returns:
true if the file is in the cache

Definition at line 222 of file sourcereader.cpp.

References fFileCache.

Referenced by getlist().

00223 {
00224     return fFileCache.find(fname) != fFileCache.end();
00225 }

Here is the caller graph for this function:

Tree SourceReader::expandlist ( Tree  ldef  ) 

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

Parameters:
ldef the list of definitions to expand
Returns:
the expanded list of definitions

Definition at line 271 of file sourcereader.cpp.

References expandrec(), and nil.

Referenced by main(), and realeval().

00272 {
00273     set<string> visited;
00274     return expandrec(ldef, visited, nil);   
00275 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 277 of file sourcereader.cpp.

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

Referenced by expandlist().

00278 {
00279     for (;!isNil(ldef); ldef = tl(ldef)) {
00280         Tree d = hd(ldef); 
00281         Tree fname;
00282         if (isNil(d)) {
00283             // skill null definitions produced by declarations
00284         } else if (isImportFile(d,fname)) {
00285             string f = tree2str(fname);
00286             //cerr << "import(" << f << ")" << endl;
00287             
00288             //string f = tree2str(fname);
00289             if (visited.find(f) == visited.end()) {
00290                 visited.insert(f);
00291                 //Tree l = getlist(f);
00292                 lresult = expandrec(getlist(f), visited, lresult);
00293             }
00294             
00295         } else {
00296             lresult = cons(d, lresult);
00297         }
00298     }
00299     return lresult;
00300 }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree SourceReader::getlist ( string  fname  ) 

Return the list of definitions file contains.

Cache the result.

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

Definition at line 235 of file sourcereader.cpp.

References cached(), fFileCache, and parse().

Referenced by expandrec(), and realeval().

00236 {
00237     if (!cached(fname)) {
00238         fFileCache[fname] = parse(fname);
00239     }
00240     if (fFileCache[fname] == 0) exit(1);
00241     return fFileCache[fname];
00242 }

Here is the call graph for this function:

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 251 of file sourcereader.cpp.

References fFilePathnames.

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

00252 {
00253 //  vector<string>                      srcfiles;
00254 
00255 //  for (map<string, Tree>::const_iterator p = fFileCache.begin(); p != fFileCache.end(); p++) {
00256 //      srcfiles.push_back(p->first);
00257 //  }
00258 
00259 //  return srcfiles;    
00260     return fFilePathnames;
00261 }

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:
fname the name of the file to parse
Returns:
the list of definitions it contains

Definition at line 186 of file sourcereader.cpp.

References fFilePathnames, fopensearch(), yyerr, yyfilename, yyin, yylineno, and yyparse().

Referenced by getlist().

00187 {
00188     string  fullpath;
00189     
00190     yyerr = 0;
00191     
00192     yyfilename = fname.c_str();
00193     yyin = fopensearch(yyfilename, fullpath);
00194     if (yyin == NULL) {
00195         fprintf(stderr, "ERROR : Unable to open file  %s \n", yyfilename); 
00196         exit(1);
00197     }
00198     
00199     yylineno = 1;
00200     int r = yyparse();
00201     if (r) { 
00202         fprintf(stderr, "Parse error : code = %d \n", r); 
00203     }
00204     if (yyerr > 0) {
00205         //fprintf(stderr, "Erreur de parsing 2, count = %d \n", yyerr); 
00206         exit(1);
00207     }
00208 
00209     // we have parsed a valid file
00210     fFilePathnames.push_back(fullpath);
00211     return gResult;
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

map<string, Tree> SourceReader::fFileCache [private]

Definition at line 18 of file sourcereader.hh.

Referenced by cached(), and getlist().

vector<string> SourceReader::fFilePathnames [private]

Definition at line 19 of file sourcereader.hh.

Referenced by listSrcFiles(), and parse().


The documentation for this class was generated from the following files:
Generated on Thu Jul 15 16:16:02 2010 for FAUST compiler by  doxygen 1.6.3