FAUST compiler  0.9.9.6b8
Public Member Functions | Protected Member Functions | Protected Attributes
Compiler Class Reference

#include <compile.hh>

Inheritance diagram for Compiler:
Inheritance graph
[legend]
Collaboration diagram for Compiler:
Collaboration graph
[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.

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

Definition at line 101 of file compile.cpp.

Compiler::~Compiler ( ) [virtual]

Definition at line 109 of file compile.cpp.

References fClass, and fNeedToDeleteClass.

{ 
    if (fNeedToDeleteClass) delete fClass;
}

Member Function Documentation

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

Definition at line 77 of file compile.hh.

References Klass::addIncludeFile(), and fClass.

Here is the call 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.

{ fClass->addLibrary(str);      }

Here is the call 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().

{
    fUIRoot = putSubFolder(fUIRoot, path, widget);
}

Here is the call graph for this function:

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

Implemented in ScalarCompiler, VectorCompiler, and SchedulerCompiler.

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 339 of file compile.cpp.

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

Referenced by generateMacroInterfaceTree().

{
    while (!isNil(elements)) {
        generateMacroInterfaceTree(pathname, right(hd(elements)));
        elements = tl(elements);
    }
}

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 312 of file compile.cpp.

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

Referenced by SchedulerCompiler::compileMultiSignal(), VectorCompiler::compileMultiSignal(), and generateMacroInterfaceElements().

{
    Tree    label, elements, varname, sig;

    if (isUiFolder(t, label, elements)) {
        string pathname2 = pathname;
        //string str = unquote(tree2str(right(label)));
        string str = tree2str(right(label));
        if (str.length()>0) pathname2 += str + "/";
        generateMacroInterfaceElements(pathname2, elements);

    } else if (isUiWidget(t, label, varname, sig)) {

        generateWidgetMacro(pathname, label, varname, sig);

    } else {

        fprintf(stderr, "error in user interface macro generation 2\n");
        exit(1);

    }
}

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 217 of file compile.cpp.

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

Referenced by generateUserInterfaceTree().

{
    while (!isNil(elements)) {
        generateUserInterfaceTree(right(hd(elements)));
        elements = tl(elements);
    }
}

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 164 of file compile.cpp.

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

Referenced by SchedulerCompiler::compileMultiSignal(), VectorCompiler::compileMultiSignal(), and generateUserInterfaceElements().

{
    Tree    label, elements, varname, sig;

    if (isUiFolder(t, label, elements)) {
        const int       orient = tree2int(left(label));
        const char *    str = tree2str(right(label));
        const char *    model;

        // extract metadata from group label str resulting in a simplifiedLabel
        // and metadata declarations for fictive zone at address 0
        string  simplifiedLabel;
        map<string, set<string> >   metadata;
        extractMetadata(str, simplifiedLabel, metadata);

        // add metadata if any
        for (map<string, set<string> >::iterator i = metadata.begin(); i != metadata.end(); i++) {
            const string& key = i->first;
            const set<string>& values = i->second;
            for (set<string>::const_iterator j = values.begin(); j != values.end(); j++) {
                fClass->addUICode(subst("interface->declare($0, \"$1\", \"$2\");", "0", wdel(key) ,wdel(*j)));
            }
        }
        //-----------------


        switch (orient) {
            case 0 : model = "interface->openVerticalBox(\"$0\");"; break;
            case 1 : model = "interface->openHorizontalBox(\"$0\");"; break;
            case 2 : model = "interface->openTabBox(\"$0\");"; break;
            default :
                    fprintf(stderr, "error in user interface generation 1\n");
                exit(1);
        }
        fClass->addUICode(subst(model, simplifiedLabel));
        generateUserInterfaceElements(elements);
        fClass->addUICode("interface->closeBox();");

    } else if (isUiWidget(t, label, varname, sig)) {

        generateWidgetCode(label, varname, sig);

    } else {

        fprintf(stderr, "error in user interface generation 2\n");
        exit(1);

    }
}

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 229 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().

{
    Tree path, c, x, y, z;
    string label;
    map<string, set<string> >   metadata;

    extractMetadata(tree2str(fulllabel), label, metadata);

    // add metadata if any
    for (map<string, set<string> >::iterator i = metadata.begin(); i != metadata.end(); i++) {
        const string& key = i->first;
        const set<string>& values = i->second;
        for (set<string>::const_iterator j = values.begin(); j != values.end(); j++) {
            fClass->addUICode(subst("interface->declare(&$0, \"$1\", \"$2\");", tree2str(varname), wdel(key) ,wdel(*j)));
        }
    }

    if ( isSigButton(sig, path) )                   {
        fClass->incUIActiveCount();
        fClass->addUICode(subst("interface->addButton(\"$0\", &$1);", label, tree2str(varname)));

    } else if ( isSigCheckbox(sig, path) )          {
        fClass->incUIActiveCount();
        fClass->addUICode(subst("interface->addCheckButton(\"$0\", &$1);", label, tree2str(varname)));

    } else if ( isSigVSlider(sig, path,c,x,y,z) )   {
        fClass->incUIActiveCount();
        fClass->addUICode(subst("interface->addVerticalSlider(\"$0\", &$1, $2, $3, $4, $5);",
                label,
                tree2str(varname),
                T(tree2float(c)),
                T(tree2float(x)),
                T(tree2float(y)),
                T(tree2float(z))));

    } else if ( isSigHSlider(sig, path,c,x,y,z) )   {
        fClass->incUIActiveCount();
        fClass->addUICode(subst("interface->addHorizontalSlider(\"$0\", &$1, $2, $3, $4, $5);",
                label,
                tree2str(varname),
                T(tree2float(c)),
                T(tree2float(x)),
                T(tree2float(y)),
                T(tree2float(z))));

    } else if ( isSigNumEntry(sig, path,c,x,y,z) )  {
        fClass->incUIActiveCount();
        fClass->addUICode(subst("interface->addNumEntry(\"$0\", &$1, $2, $3, $4, $5);",
                label,
                tree2str(varname),
                T(tree2float(c)),
                T(tree2float(x)),
                T(tree2float(y)),
                T(tree2float(z))));

    } else if ( isSigVBargraph(sig, path,x,y,z) )   {
        fClass->incUIPassiveCount();
        fClass->addUICode(subst("interface->addVerticalBargraph(\"$0\", &$1, $2, $3);",
                label,
                tree2str(varname),
                T(tree2float(x)),
                T(tree2float(y))));

    } else if ( isSigHBargraph(sig, path,x,y,z) )   {
        fClass->incUIPassiveCount();
        fClass->addUICode(subst("interface->addHorizontalBargraph(\"$0\", &$1, $2, $3);",
                label,
                tree2str(varname),
                T(tree2float(x)),
                T(tree2float(y))));

    } else {
        fprintf(stderr, "Error in generating widget code\n");
        exit(1);
    }
}

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 352 of file compile.cpp.

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

Referenced by generateMacroInterfaceTree().

{
    Tree path, c, x, y, z;
    string label;
    map<string, set<string> >   metadata;

    extractMetadata(tree2str(fulllabel), label, metadata);

    //string pathlabel = pathname+unquote(label);
    string pathlabel = pathname+label;


    if ( isSigButton(sig, path) )                   {
        fClass->addUIMacro(subst("FAUST_ADDBUTTON(\"$0\", $1);", pathlabel, tree2str(varname)));

    } else if ( isSigCheckbox(sig, path) )          {
        fClass->addUIMacro(subst("FAUST_ADDCHECKBOX(\"$0\", $1);", pathlabel, tree2str(varname)));

    } else if ( isSigVSlider(sig, path,c,x,y,z) )   {
        fClass->addUIMacro(subst("FAUST_ADDVERTICALSLIDER(\"$0\", $1, $2, $3, $4, $5);",
                pathlabel,
                tree2str(varname),
                T(tree2float(c)),
                T(tree2float(x)),
                T(tree2float(y)),
                T(tree2float(z))));

    } else if ( isSigHSlider(sig, path,c,x,y,z) )   {
        fClass->addUIMacro(subst("FAUST_ADDHORIZONTALSLIDER(\"$0\", $1, $2, $3, $4, $5);",
                pathlabel,
                tree2str(varname),
                T(tree2float(c)),
                T(tree2float(x)),
                T(tree2float(y)),
                T(tree2float(z))));

    } else if ( isSigNumEntry(sig, path,c,x,y,z) )  {
        fClass->addUIMacro(subst("FAUST_ADDNUMENTRY(\"$0\", $1, $2, $3, $4, $5);",
                pathlabel,
                tree2str(varname),
                T(tree2float(c)),
                T(tree2float(x)),
                T(tree2float(y)),
                T(tree2float(z))));

    } else if ( isSigVBargraph(sig, path,x,y,z) )   {
        fClass->addUIMacro(subst("FAUST_ADDVERTICALBARGRAPH(\"$0\", $1, $2, $3);",
                pathlabel,
                tree2str(varname),
                T(tree2float(x)),
                T(tree2float(y))));

    } else if ( isSigHBargraph(sig, path,x,y,z) )   {
        fClass->addUIMacro(subst("FAUST_ADDHORIZONTALBARGRAPH(\"$0\", $1, $2, $3);",
                pathlabel,
                tree2str(varname),
                T(tree2float(x)),
                T(tree2float(y))));

    } else {
        fprintf(stderr, "Error in generating widget code\n");
        exit(1);
    }
}

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().

{ return (Klass*)fClass; }

Here is the caller graph for this function:

Definition at line 70 of file compile.hh.

References fDescription.

Referenced by main().

{ 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.

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 SchedulerCompiler::compileMultiSignal(), and VectorCompiler::compileMultiSignal().

{
    Tree root, elems;
    if (isUiFolder(t, root, elems) && isList(elems) && isNil(tl(elems)) ) {
        Tree folder = right(hd(elems));
        return (isUiFolder(folder)) ? folder : t;
    }
    return t;
}

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().

{ 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: