Compiler Class Reference

#include <compile.hh>

Inherited by ScalarCompiler.

Collaboration diagram for Compiler:
[legend]

List of all members.

Public Member Functions

 Compiler (const string &name, const string &super, int numInputs, int numOutputs, bool vec)
 Compiler (Klass *k)
virtual ~Compiler ()
virtual void compileMultiSignal (Tree lsig)=0
virtual void compileSingleSignal (Tree lsig)=0
KlassgetClass ()
void setDescription (Description *descr)
DescriptiongetDescription ()

Protected Member Functions

virtual Tree prepare (Tree L0)=0
virtual Tree prepare2 (Tree L0)=0
void addIncludeFile (const string &str)
void addLibrary (const string &str)
void addUIWidget (Tree path, Tree widget)
 Add a widget with a certain path to the user interface tree.
void generateWidgetCode (Tree fulllabel, Tree varname, Tree sig)
 Generate buildUserInterface C++ lines of code corresponding to user interface widget t.
void generateUserInterfaceTree (Tree t)
 Generate buildUserInterface C++ lines of code corresponding to user interface element t.
void generateUserInterfaceElements (Tree elements)
 Iterate generateUserInterfaceTree on a list of user interface elements.
Tree prepareUserInterfaceTree (Tree t)
 Remove fake root folder if not needed (that is if the UI is completely enclosed in one folder.
void generateMacroInterfaceTree (const string &pathname, Tree t)
 Generate user interface macros corresponding to user interface element t.
void generateMacroInterfaceElements (const string &pathname, Tree elements)
 Iterate generateMacroInterfaceTree on a list of user interface elements.
void generateWidgetMacro (const string &pathname, Tree fulllabel, Tree varname, Tree sig)
 Generate user interface macros corresponding to a user interface widget.

Protected Attributes

KlassfClass
bool fNeedToDeleteClass
Tree fUIRoot
DescriptionfDescription

Detailed Description

Definition at line 50 of file compile.hh.


Constructor & Destructor Documentation

Compiler::Compiler ( const string &  name,
const string &  super,
int  numInputs,
int  numOutputs,
bool  vec 
)

Definition at line 94 of file compile.cpp.

00095         : fClass(new Klass(name, super, numInputs, numOutputs, vec)),
00096           fNeedToDeleteClass(true), 
00097           fUIRoot(uiFolder(cons(tree(0), tree(subst("$0", gMasterName))))),
00098           fDescription(0)
00099 {}

Compiler::Compiler ( Klass k  ) 

Definition at line 101 of file compile.cpp.

00102         : fClass(k),
00103           fNeedToDeleteClass(false), 
00104           fUIRoot(uiFolder(cons(tree(0), tree(subst("$0", gMasterName))))),
00105           fDescription(0)
00106 {}

Compiler::~Compiler (  )  [virtual]

Definition at line 109 of file compile.cpp.

References fClass, and fNeedToDeleteClass.

00110 { 
00111     if (fNeedToDeleteClass) delete fClass;
00112 }


Member Function Documentation

void Compiler::addIncludeFile ( const string &  str  )  [inline, protected]

Definition at line 77 of file compile.hh.

References Klass::addIncludeFile(), and fClass.

Referenced by ScalarCompiler::generateFConst(), ScalarCompiler::generateFFun(), and ScalarCompiler::generateFVar().

00077 { fClass->addIncludeFile(str);  }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::addLibrary ( const string &  str  )  [inline, protected]

Definition at line 78 of file compile.hh.

References Klass::addLibrary(), and fClass.

Referenced by ScalarCompiler::generateFFun().

00078 { fClass->addLibrary(str);      }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::addUIWidget ( Tree  path,
Tree  widget 
) [protected]

Add a widget with a certain path to the user interface tree.

Definition at line 123 of file compile.cpp.

References fUIRoot, and putSubFolder().

Referenced by ScalarCompiler::generateButton(), ScalarCompiler::generateCheckbox(), ScalarCompiler::generateHBargraph(), ScalarCompiler::generateHSlider(), ScalarCompiler::generateNumEntry(), ScalarCompiler::generateVBargraph(), and ScalarCompiler::generateVSlider().

00124 {
00125     fUIRoot = putSubFolder(fUIRoot, path, widget);
00126 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void Compiler::compileMultiSignal ( Tree  lsig  )  [pure virtual]

Implemented in ScalarCompiler, and VectorCompiler.

Referenced by main().

Here is the caller graph for this function:

virtual void Compiler::compileSingleSignal ( Tree  lsig  )  [pure virtual]

Implemented in ScalarCompiler.

void Compiler::generateMacroInterfaceElements ( const string &  pathname,
Tree  elements 
) [protected]

Iterate generateMacroInterfaceTree on a list of user interface elements.

Definition at line 437 of file compile.cpp.

References generateMacroInterfaceTree(), hd(), isNil(), right(), and tl().

Referenced by generateMacroInterfaceTree().

00438 {
00439     while (!isNil(elements)) {
00440         generateMacroInterfaceTree(pathname, right(hd(elements)));
00441         elements = tl(elements);
00442     }
00443 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::generateMacroInterfaceTree ( const string &  pathname,
Tree  t 
) [protected]

Generate user interface macros corresponding to user interface element t.

Definition at line 410 of file compile.cpp.

References generateMacroInterfaceElements(), generateWidgetMacro(), isUiFolder(), isUiWidget(), right(), and tree2str().

Referenced by VectorCompiler::compileMultiSignal(), ScalarCompiler::compileMultiSignal(), ScalarCompiler::compileSingleSignal(), and generateMacroInterfaceElements().

00411 {
00412     Tree    label, elements, varname, sig;
00413 
00414     if (isUiFolder(t, label, elements)) {
00415         string pathname2 = pathname;
00416         //string str = unquote(tree2str(right(label)));
00417         string str = tree2str(right(label));
00418         if (str.length()>0) pathname2 += str + "/";
00419         generateMacroInterfaceElements(pathname2, elements);
00420 
00421     } else if (isUiWidget(t, label, varname, sig)) {
00422 
00423         generateWidgetMacro(pathname, label, varname, sig);
00424 
00425     } else {
00426 
00427         fprintf(stderr, "error in user interface macro generation 2\n");
00428         exit(1);
00429 
00430     }
00431 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::generateUserInterfaceElements ( Tree  elements  )  [protected]

Iterate generateUserInterfaceTree on a list of user interface elements.

Definition at line 315 of file compile.cpp.

References generateUserInterfaceTree(), hd(), isNil(), right(), and tl().

Referenced by generateUserInterfaceTree().

00316 {
00317     while (!isNil(elements)) {
00318         generateUserInterfaceTree(right(hd(elements)));
00319         elements = tl(elements);
00320     }
00321 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::generateUserInterfaceTree ( Tree  t  )  [protected]

Generate buildUserInterface C++ lines of code corresponding to user interface element t.

Definition at line 279 of file compile.cpp.

References Klass::addUICode(), fClass, generateUserInterfaceElements(), generateWidgetCode(), isUiFolder(), isUiWidget(), left(), right(), subst(), tree2int(), and tree2str().

Referenced by VectorCompiler::compileMultiSignal(), ScalarCompiler::compileMultiSignal(), ScalarCompiler::compileSingleSignal(), and generateUserInterfaceElements().

00280 {
00281     Tree    label, elements, varname, sig;
00282 
00283     if (isUiFolder(t, label, elements)) {
00284         const int       orient = tree2int(left(label));
00285         const char *    str = tree2str(right(label));
00286         const char *    model;
00287 
00288         switch (orient) {
00289             case 0 : model = "interface->openVerticalBox(\"$0\");"; break;
00290             case 1 : model = "interface->openHorizontalBox(\"$0\");"; break;
00291             case 2 : model = "interface->openTabBox(\"$0\");"; break;
00292             default :
00293                     fprintf(stderr, "error in user interface generation 1\n");
00294                 exit(1);
00295         }
00296         fClass->addUICode(subst(model, str));
00297         generateUserInterfaceElements(elements);
00298         fClass->addUICode("interface->closeBox();");
00299 
00300     } else if (isUiWidget(t, label, varname, sig)) {
00301 
00302         generateWidgetCode(label, varname, sig);
00303 
00304     } else {
00305 
00306         fprintf(stderr, "error in user interface generation 2\n");
00307         exit(1);
00308 
00309     }
00310 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::generateWidgetCode ( Tree  fulllabel,
Tree  varname,
Tree  sig 
) [protected]

Generate buildUserInterface C++ lines of code corresponding to user interface widget t.

Definition at line 327 of file compile.cpp.

References Klass::addUICode(), extractMetadata(), fClass, Klass::incUIActiveCount(), Klass::incUIPassiveCount(), isSigButton(), isSigCheckbox(), isSigHBargraph(), isSigHSlider(), isSigNumEntry(), isSigVBargraph(), isSigVSlider(), subst(), T(), tree2float(), tree2str(), and wdel().

Referenced by generateUserInterfaceTree().

00328 {
00329     Tree path, c, x, y, z;
00330     string label;
00331     map<string, set<string> >   metadata;
00332 
00333     extractMetadata(tree2str(fulllabel), label, metadata);
00334 
00335     // add metadata if any
00336     for (map<string, set<string> >::iterator i = metadata.begin(); i != metadata.end(); i++) {
00337         const string& key = i->first;
00338         const set<string>& values = i->second;
00339         for (set<string>::iterator j = values.begin(); j != values.end(); j++) {
00340             fClass->addUICode(subst("interface->declare(&$0, \"$1\", \"$2\");", tree2str(varname), wdel(key) ,wdel(*j)));
00341         }
00342     }
00343 
00344     if ( isSigButton(sig, path) )                   {
00345         fClass->incUIActiveCount();
00346         fClass->addUICode(subst("interface->addButton(\"$0\", &$1);", label, tree2str(varname)));
00347 
00348     } else if ( isSigCheckbox(sig, path) )          {
00349         fClass->incUIActiveCount();
00350         fClass->addUICode(subst("interface->addCheckButton(\"$0\", &$1);", label, tree2str(varname)));
00351 
00352     } else if ( isSigVSlider(sig, path,c,x,y,z) )   {
00353         fClass->incUIActiveCount();
00354         fClass->addUICode(subst("interface->addVerticalSlider(\"$0\", &$1, $2, $3, $4, $5);",
00355                 label,
00356                 tree2str(varname),
00357                 T(tree2float(c)),
00358                 T(tree2float(x)),
00359                 T(tree2float(y)),
00360                 T(tree2float(z))));
00361 
00362     } else if ( isSigHSlider(sig, path,c,x,y,z) )   {
00363         fClass->incUIActiveCount();
00364         fClass->addUICode(subst("interface->addHorizontalSlider(\"$0\", &$1, $2, $3, $4, $5);",
00365                 label,
00366                 tree2str(varname),
00367                 T(tree2float(c)),
00368                 T(tree2float(x)),
00369                 T(tree2float(y)),
00370                 T(tree2float(z))));
00371 
00372     } else if ( isSigNumEntry(sig, path,c,x,y,z) )  {
00373         fClass->incUIActiveCount();
00374         fClass->addUICode(subst("interface->addNumEntry(\"$0\", &$1, $2, $3, $4, $5);",
00375                 label,
00376                 tree2str(varname),
00377                 T(tree2float(c)),
00378                 T(tree2float(x)),
00379                 T(tree2float(y)),
00380                 T(tree2float(z))));
00381 
00382     } else if ( isSigVBargraph(sig, path,x,y,z) )   {
00383         fClass->incUIPassiveCount();
00384         fClass->addUICode(subst("interface->addVerticalBargraph(\"$0\", &$1, $2, $3);",
00385                 label,
00386                 tree2str(varname),
00387                 T(tree2float(x)),
00388                 T(tree2float(y))));
00389 
00390     } else if ( isSigHBargraph(sig, path,x,y,z) )   {
00391         fClass->incUIPassiveCount();
00392         fClass->addUICode(subst("interface->addHorizontalBargraph(\"$0\", &$1, $2, $3);",
00393                 label,
00394                 tree2str(varname),
00395                 T(tree2float(x)),
00396                 T(tree2float(y))));
00397 
00398     } else {
00399         fprintf(stderr, "Error in generating widget code\n");
00400         exit(1);
00401     }
00402 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::generateWidgetMacro ( const string &  pathname,
Tree  fulllabel,
Tree  varname,
Tree  sig 
) [protected]

Generate user interface macros corresponding to a user interface widget.

Definition at line 450 of file compile.cpp.

References Klass::addUIMacro(), extractMetadata(), fClass, isSigButton(), isSigCheckbox(), isSigHBargraph(), isSigHSlider(), isSigNumEntry(), isSigVBargraph(), isSigVSlider(), subst(), T(), tree2float(), and tree2str().

Referenced by generateMacroInterfaceTree().

00451 {
00452     Tree path, c, x, y, z;
00453     string label;
00454     map<string, set<string> >   metadata;
00455 
00456     extractMetadata(tree2str(fulllabel), label, metadata);
00457 
00458     //string pathlabel = pathname+unquote(label);
00459     string pathlabel = pathname+label;
00460 
00461 
00462     if ( isSigButton(sig, path) )                   {
00463         fClass->addUIMacro(subst("FAUST_ADDBUTTON(\"$0\", $1);", pathlabel, tree2str(varname)));
00464 
00465     } else if ( isSigCheckbox(sig, path) )          {
00466         fClass->addUIMacro(subst("FAUST_ADDCHECKBOX(\"$0\", $1);", pathlabel, tree2str(varname)));
00467 
00468     } else if ( isSigVSlider(sig, path,c,x,y,z) )   {
00469         fClass->addUIMacro(subst("FAUST_ADDVERTICALSLIDER(\"$0\", $1, $2, $3, $4, $5);",
00470                 pathlabel,
00471                 tree2str(varname),
00472                 T(tree2float(c)),
00473                 T(tree2float(x)),
00474                 T(tree2float(y)),
00475                 T(tree2float(z))));
00476 
00477     } else if ( isSigHSlider(sig, path,c,x,y,z) )   {
00478         fClass->addUIMacro(subst("FAUST_ADDHORIZONTALSLIDER(\"$0\", $1, $2, $3, $4, $5);",
00479                 pathlabel,
00480                 tree2str(varname),
00481                 T(tree2float(c)),
00482                 T(tree2float(x)),
00483                 T(tree2float(y)),
00484                 T(tree2float(z))));
00485 
00486     } else if ( isSigNumEntry(sig, path,c,x,y,z) )  {
00487         fClass->addUIMacro(subst("FAUST_ADDNUMENTRY(\"$0\", $1, $2, $3, $4, $5);",
00488                 pathlabel,
00489                 tree2str(varname),
00490                 T(tree2float(c)),
00491                 T(tree2float(x)),
00492                 T(tree2float(y)),
00493                 T(tree2float(z))));
00494 
00495     } else if ( isSigVBargraph(sig, path,x,y,z) )   {
00496         fClass->addUIMacro(subst("FAUST_ADDVERTICALBARGRAPH(\"$0\", $1, $2, $3);",
00497                 pathlabel,
00498                 tree2str(varname),
00499                 T(tree2float(x)),
00500                 T(tree2float(y))));
00501 
00502     } else if ( isSigHBargraph(sig, path,x,y,z) )   {
00503         fClass->addUIMacro(subst("FAUST_ADDHORIZONTALBARGRAPH(\"$0\", $1, $2, $3);",
00504                 pathlabel,
00505                 tree2str(varname),
00506                 T(tree2float(x)),
00507                 T(tree2float(y))));
00508 
00509     } else {
00510         fprintf(stderr, "Error in generating widget code\n");
00511         exit(1);
00512     }
00513 }

Here is the call graph for this function:

Here is the caller graph for this function:

Klass* Compiler::getClass (  )  [inline]

Definition at line 67 of file compile.hh.

References fClass.

Referenced by main(), and signal2klass().

00067 { return (Klass*)fClass; }

Here is the caller graph for this function:

Description* Compiler::getDescription (  )  [inline]

Definition at line 70 of file compile.hh.

References fDescription.

Referenced by main().

00070 { return fDescription; }

Here is the caller graph for this function:

virtual Tree Compiler::prepare ( Tree  L0  )  [protected, pure virtual]

Implemented in ScalarCompiler.

virtual Tree Compiler::prepare2 ( Tree  L0  )  [protected, pure virtual]

Implemented in ScalarCompiler.

Tree Compiler::prepareUserInterfaceTree ( Tree  t  )  [protected]

Remove fake root folder if not needed (that is if the UI is completely enclosed in one folder.

Definition at line 133 of file compile.cpp.

References hd(), isList(), isNil(), isUiFolder(), right(), and tl().

Referenced by VectorCompiler::compileMultiSignal(), ScalarCompiler::compileMultiSignal(), and ScalarCompiler::compileSingleSignal().

00134 {
00135     Tree root, elems;
00136     if (isUiFolder(t, root, elems) && isList(elems) && isNil(tl(elems)) ) {
00137         Tree folder = right(hd(elems));
00138         return (isUiFolder(folder)) ? folder : t;
00139     }
00140     return t;
00141 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Compiler::setDescription ( Description descr  )  [inline]

Definition at line 69 of file compile.hh.

References fDescription.

Referenced by main().

00069 { fDescription= descr; }

Here is the caller graph for this function:


Member Data Documentation

Klass* Compiler::fClass [protected]
bool Compiler::fNeedToDeleteClass [protected]

Definition at line 54 of file compile.hh.

Referenced by ~Compiler().

Tree Compiler::fUIRoot [protected]

The documentation for this class was generated from the following files:
Generated on Thu Apr 29 00:00:18 2010 for FAUST compiler by  doxygen 1.6.3