FAUST compiler  0.9.9.6b8
Classes | Functions
sourcereader.hh File Reference
#include "boxes.hh"
#include <string>
#include <set>
#include <vector>
Include dependency graph for sourcereader.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SourceReader
 

Functions

Tree formatDefinitions (Tree rldef)
 Formats a list of raw definitions represented by triplets <name,arglist,body> into abstractions or pattern matching rules when appropriate. More...
 
Tree checkRulelist (Tree lrules)
 
void declareMetadata (Tree key, Tree value)
 
void declareDoc (Tree t)
 

Function Documentation

Tree checkRulelist ( Tree  lrules)

Definition at line 76 of file sourcereader.cpp.

References hd(), isNil(), len(), printPatternError(), and tl().

Referenced by yyparse().

77 {
78  Tree lrules = lr;
79  if (isNil(lrules)) { cerr << "ERROR : a case expression can't be empty" << endl; exit(1); }
80  // first pattern used as a reference
81  Tree lhs1 = hd(hd(lrules));
82  Tree rhs1 = tl(hd(lrules));
83  int npat = len(lhs1);
84  lrules = tl(lrules);
85  while (! isNil(lrules)) {
86  Tree lhs2 = hd(hd(lrules));
87  Tree rhs2 = tl(hd(lrules));
88  if (npat != len(lhs2)) {
89  printPatternError(lhs1,rhs1,lhs2,rhs2);
90  exit(1);
91  }
92 
93  lhs1 = lhs2;
94  rhs1 = rhs2;
95  lrules = tl(lrules);
96  }
97  return lr;
98 }
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
static void printPatternError(Tree lhs1, Tree rhs1, Tree lhs2, Tree rhs2)
int len(Tree l)
Definition: list.cpp:198
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

void declareDoc ( Tree  t)

Definition at line 353 of file sourcereader.cpp.

References gDocVector.

Referenced by declareAutoDoc(), and yyparse().

354 {
355  //gLatexDocSwitch = true;
356  gDocVector.push_back(t);
357 }
vector< Tree > gDocVector
Contains parsed trees: DOCTXT, DOCEQN, DOCDGM.
Definition: doc.cpp:109

Here is the caller graph for this function:

void declareMetadata ( Tree  key,
Tree  value 
)

Definition at line 338 of file sourcereader.cpp.

References gMasterDocument, gMetaDataSet, tree(), tree2str(), and yyfilename.

Referenced by yyparse().

339 {
340  if (gMasterDocument == yyfilename) {
341  // inside master document, no prefix needed to declare metadata
342  gMetaDataSet[key].insert(value);
343  } else {
344  string fkey(yyfilename);
345  fkey += "/";
346  fkey += tree2str(key);
347  gMetaDataSet[tree(fkey.c_str())].insert(value);
348  }
349  //cout << "Master " << gMasterDocument << ", file " << yyfilename << " : declare " << *key << "," << *value << endl;
350 }
const char * yyfilename
Definition: errormsg.cpp:30
string gMasterDocument
Definition: main.cpp:104
Tree tree(const Node &n)
Definition: tree.hh:186
map< Tree, set< Tree > > gMetaDataSet
Definition: main.cpp:91
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:

Tree formatDefinitions ( Tree  rldef)

Formats a list of raw definitions represented by triplets <name,arglist,body> into abstractions or pattern matching rules when appropriate.

Parameters
rldeflist of raw definitions in reverse order
Returns
the list of formatted definitions

Definition at line 149 of file sourcereader.cpp.

References cons(), hd(), isImportFile(), isNil(), makeDefinition(), nil, and tl().

Referenced by yyparse().

150 {
151  map<Tree,list<Tree> > dic;
152  map<Tree,list<Tree> >::iterator p;
153  Tree ldef2 = nil;
154  Tree file;
155 
156  //cout << "Format definitions " << *rldef << endl;
157  // collects the definitions in a dictionnary
158  while (!isNil(rldef)) {
159  Tree def = hd(rldef);
160  rldef = tl(rldef);
161  if (isImportFile(def, file)) {
162  ldef2 = cons(def,ldef2);
163  } else if (!isNil(def)) {
164  //cout << " def : " << *def << endl;
165  dic[hd(def)].push_front(tl(def));
166  }
167  }
168 
169  // produce the definitions
170 
171  for (p=dic.begin(); p!=dic.end(); p++) {
172  ldef2 = cons (cons(p->first, makeDefinition(p->second)), ldef2);
173  }
174 
175  //cout << "list of definitions : " << *ldef2 << endl;
176  return ldef2;
177 
178 }
bool isImportFile(Tree s, Tree &filename)
Definition: boxes.cpp:301
Tree cons(Tree a, Tree b)
Definition: list.hh:124
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
static Tree makeDefinition(list< Tree > &variants)
Transforms a list of variants (arglist.body) into an abstraction or a boxCase.
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function: