FAUST compiler  0.9.9.6b8
Public Member Functions | Private Member Functions | Private Attributes
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:
fnamethe name of the file to check
Returns:
true if the file is in the cache

Definition at line 222 of file sourcereader.cpp.

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

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

References nil.

Referenced by main(), and realeval().

{
    set<string> visited;
    return expandrec(ldef, visited, nil);   
}

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(), hd(), isImportFile(), isNil(), tl(), and tree2str().

{
    for (;!isNil(ldef); ldef = tl(ldef)) {
        Tree d = hd(ldef); 
        Tree fname;
        if (isNil(d)) {
            // skill null definitions produced by declarations
        } else if (isImportFile(d,fname)) {
            string f = tree2str(fname);
            //cerr << "import(" << f << ")" << endl;
            
            //string f = tree2str(fname);
            if (visited.find(f) == visited.end()) {
                visited.insert(f);
                //Tree l = getlist(f);
                lresult = expandrec(getlist(f), visited, lresult);
            }
            
        } else {
            lresult = cons(d, lresult);
        }
    }
    return lresult;
}

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

Referenced by realeval().

{
    if (!cached(fname)) {
        fFileCache[fname] = parse(fname);
    }
    if (fFileCache[fname] == 0) exit(1);
    return fFileCache[fname];
}

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.

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

{
//  vector<string>                      srcfiles;

//  for (map<string, Tree>::const_iterator p = fFileCache.begin(); p != fFileCache.end(); p++) {
//      srcfiles.push_back(p->first);
//  }

//  return srcfiles;    
    return fFilePathnames;
}

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

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

{
    string  fullpath;
    
    yyerr = 0;
    
    yyfilename = fname.c_str();
    yyin = fopensearch(yyfilename, fullpath);
    if (yyin == NULL) {
        fprintf(stderr, "ERROR : Unable to open file  %s \n", yyfilename); 
        exit(1);
    }
    
    yylineno = 1;
    int r = yyparse();
    if (r) { 
        fprintf(stderr, "Parse error : code = %d \n", r); 
    }
    if (yyerr > 0) {
        //fprintf(stderr, "Erreur de parsing 2, count = %d \n", yyerr); 
        exit(1);
    }

    // we have parsed a valid file
    fFilePathnames.push_back(fullpath);
    return gResult;
}

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: