FAUST compiler  0.9.9.6b8
Functions | Variables
list.cpp File Reference
#include <stdlib.h>
#include "list.hh"
#include "compatibility.hh"
#include <map>
#include <cstdlib>
Include dependency graph for list.cpp:

Go to the source code of this file.

Functions

static bool printlist (Tree l, FILE *out)
void print (Tree t, FILE *out)
Tree nth (Tree l, int i)
Tree replace (Tree l, int i, Tree e)
int len (Tree l)
Tree rconcat (Tree l, Tree q)
Tree concat (Tree l, Tree q)
Tree lrange (Tree l, int i, int j)
static Tree rmap (tfun f, Tree l)
Tree reverse (Tree l)
Tree lmap (tfun f, Tree l)
Tree reverseall (Tree l)
bool isElement (Tree e, Tree l)
Tree addElement (Tree e, Tree l)
Tree remElement (Tree e, Tree l)
Tree singleton (Tree e)
Tree list2set (Tree l)
Tree setUnion (Tree A, Tree B)
Tree setIntersection (Tree A, Tree B)
Tree setDifference (Tree A, Tree B)
Tree pushEnv (Tree key, Tree val, Tree env)
bool searchEnv (Tree key, Tree &v, Tree env)
static bool findKey (Tree pl, Tree key, Tree &val)
static Tree updateKey (Tree pl, Tree key, Tree val)
static Tree removeKey (Tree pl, Tree key)
void setProperty (Tree t, Tree key, Tree val)
bool getProperty (Tree t, Tree key, Tree &val)
void remProperty (Tree t, Tree key)
Tree tmap (Tree key, tfun f, Tree t)
static Tree substkey (Tree t, Tree id, Tree val)
static Tree subst (Tree t, Tree propkey, Tree id, Tree val)
Tree substitute (Tree t, Tree id, Tree val)

Variables

Sym CONS = symbol("cons")
Sym NIL = symbol("nil")
Tree nil = tree(NIL)

Function Documentation

Tree addElement ( Tree  e,
Tree  l 
)

Definition at line 272 of file list.cpp.

References addElement(), cons(), hd(), isList(), and tl().

Referenced by addElement(), evalIdDef(), list2set(), and ppsig::printrec().

{
    if (isList(l)) {
        if (e < hd(l)) {
            return cons(e,l);
        } else if (e == hd(l)) {
            return l;
        } else {
            return cons(hd(l), addElement(e,tl(l)));
        }
    } else {
        return cons(e,nil);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree concat ( Tree  l,
Tree  q 
)

Definition at line 216 of file list.cpp.

References rconcat(), and reverse().

Referenced by applyList(), and sigCartesianProd().

{
    return rconcat(reverse(l), q);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool findKey ( Tree  pl,
Tree  key,
Tree val 
) [static]

Definition at line 373 of file list.cpp.

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

{
    if (isNil(pl))              return false;
    if (left(hd(pl)) == key)    { val= right(hd(pl)); return true; }
    /*  left(hd(pl)) != key */  return findKey (tl(pl), key, val); 
}

Here is the call graph for this function:

bool getProperty ( Tree  t,
Tree  key,
Tree val 
)
bool isElement ( Tree  e,
Tree  l 
)

Definition at line 262 of file list.cpp.

References hd(), isList(), and tl().

{
    while (isList(l)) {
        if (hd(l) == e) return true;
        if (hd(l) > e) return false;
        l = tl(l);
    }
    return false;
}

Here is the call graph for this function:

int len ( Tree  l)

Definition at line 198 of file list.cpp.

References isList(), and tl().

Referenced by checkRulelist(), evalCase(), ffarity(), ScalarCompiler::generateRec(), DocCompiler::generateRec(), make_pattern_matcher(), makeDefinition(), Symbol::Symbol(), symlistVisit(), and typeAnnotation().

{
    int     n = 0;
    while (isList(l)) { l = tl(l); n++; }
    return n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree list2set ( Tree  l)

Definition at line 307 of file list.cpp.

References addElement(), hd(), isList(), nil, and tl().

{
    Tree s = nil;
    while (isList(l)) {
        s = addElement(hd(l),s);
        l = tl(l);
    }
    return s;
}

Here is the call graph for this function:

Tree lmap ( tfun  f,
Tree  l 
)

Definition at line 247 of file list.cpp.

References reverse(), and rmap().

Referenced by preparePattern(), prepareRule(), and prepareRules().

{
    return reverse(rmap(f,l));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree lrange ( Tree  l,
int  i,
int  j 
)

Definition at line 221 of file list.cpp.

References cons(), nil, and nth().

{
    Tree    r = nil;
    int     c = j;
    while (c>i) r = cons( nth(l,--c), r);
    return r;
}

Here is the call graph for this function:

Tree nth ( Tree  l,
int  i 
)

Definition at line 182 of file list.cpp.

References hd(), isList(), nil, and tl().

Referenced by ffargtype(), ffname(), ScalarCompiler::generateFFun(), DocCompiler::generateFFun(), ScalarCompiler::generateRec(), DocCompiler::generateRec(), isBoxHSlider(), isBoxNumEntry(), isBoxVSlider(), isSigHSlider(), isSigNumEntry(), isSigVSlider(), lrange(), and symlistVisit().

{
    while (isList(l)) {
        if (i == 0)  return hd(l);
        l = tl(l);
        i--;
    }
    return nil;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void print ( Tree  t,
FILE *  out 
)

Definition at line 154 of file list.cpp.

References CTree::arity(), CTree::branch(), isDouble(), isInt(), isPointer(), isSym(), name(), CTree::node(), print(), and printlist().

Referenced by addLayerDef(), evalerror(), evalremark(), evalwarning(), ScalarCompiler::generateCode(), generateInsideSchema(), infereSigOrder(), infereSigType(), print(), printlist(), and printSignal().

{
    int i; double f; Sym s; void* p;
    
    if (printlist(t, out))      return;
    
    Node n = t->node();
         if (isInt(n, &i))      fprintf (out, "%d", i);
    else if (isDouble(n, &f))   fprintf (out, "%f", f);
    else if (isSym(n, &s))      fprintf (out, "%s", name(s));
    else if (isPointer(n, &p))  fprintf (out, "#%p", p);
    
    int k = t->arity();
    if (k > 0) {
        char sep = '[';
        for (int i=0; i<k; i++) {
            fputc(sep, out); sep = ',';
            print(t->branch(i), out);
        }
        fputc(']', out);
    } 
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool printlist ( Tree  l,
FILE *  out 
) [static]

Definition at line 123 of file list.cpp.

References hd(), isList(), isNil(), print(), and tl().

Referenced by print().

{
    if (isList(l)) {
        
        char sep = '(';
        
        do {
            fputc(sep, out); sep = ',';
            print(hd(l));
            l = tl(l);
        } while (isList(l));
        
        if (! isNil(l)) {
            fprintf(out, " . ");
            print(l, out);
        }
        
        fputc(')', out);
        return true;
        
    } else if (isNil(l)) {
        
        fprintf(out, "nil");
        return true;
        
    } else {
        
        return false;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree pushEnv ( Tree  key,
Tree  val,
Tree  env 
)

Definition at line 351 of file list.cpp.

References cons().

Referenced by propagate(), and sigMapRename().

{
    return cons (cons(key,val), env);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree rconcat ( Tree  l,
Tree  q 
)

Definition at line 210 of file list.cpp.

References cons(), hd(), isList(), and tl().

Referenced by concat().

{
    while (isList(l)) { q = cons(hd(l),q); l = tl(l); }
    return q;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree remElement ( Tree  e,
Tree  l 
)

Definition at line 287 of file list.cpp.

References cons(), hd(), isList(), nil, remElement(), and tl().

Referenced by remElement().

{
    if (isList(l)) {
        if (e < hd(l)) {
            return l;
        } else if (e == hd(l)) {
            return tl(l);
        } else {
            return cons(hd(l), remElement(e,tl(l)));
        }
    } else {
        return nil;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree removeKey ( Tree  pl,
Tree  key 
) [static]

Definition at line 387 of file list.cpp.

References cons(), hd(), isNil(), left(), nil, and tl().

{
    if (isNil(pl))              return nil;
    if (left(hd(pl)) == key)    return tl(pl);
    /*  left(hd(pl)) != key */  return cons (hd(pl), removeKey(tl(pl), key));
}

Here is the call graph for this function:

void remProperty ( Tree  t,
Tree  key 
)

Definition at line 434 of file list.cpp.

{
    exit(1); // fonction not implemented
}
Tree replace ( Tree  l,
int  i,
Tree  e 
)

Definition at line 192 of file list.cpp.

References cons(), hd(), replace(), and tl().

Referenced by replace().

{
    return (i==0) ? cons(e,tl(l)) : cons( hd(l), replace(tl(l),i-1,e) );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree reverse ( Tree  l)

Definition at line 252 of file list.cpp.

References isList(), reverseall(), and rmap().

Referenced by reverseall().

{
    return isList(l) ? rmap(reverseall, l) : l;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree rmap ( tfun  f,
Tree  l 
) [static]

Definition at line 233 of file list.cpp.

References cons(), hd(), isList(), nil, and tl().

Referenced by lmap(), and reverseall().

{
    Tree r = nil;
    while (isList(l)) { r = cons(f(hd(l)),r); l = tl(l); }
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool searchEnv ( Tree  key,
Tree v,
Tree  env 
)

Definition at line 356 of file list.cpp.

References hd(), isList(), and tl().

Referenced by propagate(), and sigMapRename().

{
    while (isList(env)) {
        if (hd(hd(env)) == key) {
            v = tl(hd(env));
            return true;
        }
        env = tl(env);
    }
    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree setDifference ( Tree  A,
Tree  B 
)

Definition at line 336 of file list.cpp.

References cons(), hd(), isNil(), setDifference(), and tl().

Referenced by setDifference().

{
    if (isNil(A))       return A;
    if (isNil(B))       return A;
    if (hd(A) == hd(B)) return setDifference(tl(A),tl(B));
    if (hd(A) < hd(B))  return cons(hd(A), setDifference(tl(A),B));
    /* (hd(A) > hd(B)*/ return setDifference(A,tl(B));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree setIntersection ( Tree  A,
Tree  B 
)

Definition at line 327 of file list.cpp.

References cons(), hd(), isNil(), setIntersection(), and tl().

Referenced by Loop::hasRecDependencyIn(), and setIntersection().

{
    if (isNil(A))       return A;
    if (isNil(B))       return B;
    if (hd(A) == hd(B)) return cons(hd(A), setIntersection(tl(A),tl(B)));
    if (hd(A) < hd(B))  return setIntersection(tl(A),B);
    /* (hd(A) > hd(B)*/ return setIntersection(A,tl(B));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void setProperty ( Tree  t,
Tree  key,
Tree  val 
)
Tree setUnion ( Tree  A,
Tree  B 
)

Definition at line 317 of file list.cpp.

References cons(), hd(), isNil(), setUnion(), and tl().

Referenced by Loop::absorb(), realeval(), setUnion(), and symlistVisit().

{
    if (isNil(A))       return B;
    if (isNil(B))       return A;
    
    if (hd(A) == hd(B)) return cons(hd(A), setUnion(tl(A),tl(B)));
    if (hd(A) < hd(B))  return cons(hd(A), setUnion(tl(A),B));
    /* hd(A) > hd(B) */ return cons(hd(B), setUnion(A,tl(B)));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 302 of file list.cpp.

References list1().

Referenced by VectorCompiler::generateLoopCode(), and symlistVisit().

{
    return list1(e);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree subst ( Tree  t,
Tree  propkey,
Tree  id,
Tree  val 
) [static]

Definition at line 506 of file list.cpp.

References CTree::arity(), CTree::branch(), getProperty(), isNil(), nil, CTree::node(), setProperty(), subst(), and tree().

{
    Tree p;
    
    if (t==id) {
        return val;
        
    } else if (t->arity() == 0) {
        return t;
    } else if (getProperty(t, propkey, p)) {
        return (isNil(p)) ?  t : p;
    } else {
        Tree r=nil;
        switch (t->arity()) {
            
            case 1 : 
                r = tree(t->node(), 
                            subst(t->branch(0), propkey, id, val)); 
                break;
                
            case 2 : 
                r = tree(t->node(), 
                            subst(t->branch(0), propkey, id, val), 
                            subst(t->branch(1), propkey, id, val)); 
                break;
                
            case 3 : 
                r = tree(t->node(), 
                            subst(t->branch(0), propkey, id, val), 
                            subst(t->branch(1), propkey, id, val), 
                            subst(t->branch(2), propkey, id, val)); 
                break;
                
            case 4 : 
                r = tree(t->node(), 
                            subst(t->branch(0), propkey, id, val), 
                            subst(t->branch(1), propkey, id, val), 
                            subst(t->branch(2), propkey, id, val), 
                            subst(t->branch(3), propkey, id, val)); 
                break;
            
        }
        if (r == t) {
            setProperty(t, propkey, nil);
        } else {
            setProperty(t, propkey, r);
        }
        return r;
    }
        
}

Here is the call graph for this function:

Tree substitute ( Tree  t,
Tree  id,
Tree  val 
)

Definition at line 559 of file list.cpp.

References subst(), and substkey().

Referenced by calcDeBruijn2Sym(), and calcsubstitute().

{
    return subst (t, substkey(t,id,val), id, val);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree substkey ( Tree  t,
Tree  id,
Tree  val 
) [static]

Definition at line 496 of file list.cpp.

References name(), tree(), and unique().

Referenced by substitute().

{
    char    name[256];
    snprintf(name, 255, "SUBST<%p,%p,%p> : ", (CTree*)t, (CTree*)id, (CTree*)val);
    return tree(unique(name));
}   

Here is the call graph for this function:

Here is the caller graph for this function:

Tree tmap ( Tree  key,
tfun  f,
Tree  t 
)

Definition at line 445 of file list.cpp.

References CTree::arity(), CTree::branch(), getProperty(), isNil(), nil, CTree::node(), setProperty(), tmap(), and tree().

Referenced by tmap().

{   
    //printf("start tmap\n");
    Tree p; 
    
    if (getProperty(t, key, p)) {
        
        return (isNil(p)) ? t : p;  // truc pour eviter les boucles
        
    } else {
        
        Tree r1=nil;
        switch (t->arity()) {
            
            case 0 : 
                r1 = t; 
                break;
            case 1 : 
                r1 = tree(t->node(), tmap(key,f,t->branch(0))); 
                break;
            case 2 : 
                r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1))); 
                break;
            case 3 : 
                r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1)),
                                           tmap(key,f,t->branch(2))); 
                break;
            case 4 : 
                r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1)),
                                           tmap(key,f,t->branch(2)), tmap(key,f,t->branch(3))); 
                break;
        }
        Tree r2 = f(r1);
        if (r2 == t) {
            setProperty(t, key, nil);
        } else {
            setProperty(t, key, r2);
        }
        return r2;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree updateKey ( Tree  pl,
Tree  key,
Tree  val 
) [static]

Definition at line 380 of file list.cpp.

References cons(), hd(), isNil(), left(), and tl().

{
    if (isNil(pl))              return cons ( cons(key,val), nil );
    if (left(hd(pl)) == key)    return cons ( cons(key,val), tl(pl) );
    /*  left(hd(pl)) != key */  return cons ( hd(pl), updateKey( tl(pl), key, val ));
}

Here is the call graph for this function:


Variable Documentation

Sym CONS = symbol("cons")

Definition at line 112 of file list.cpp.

Sym NIL = symbol("nil")

Definition at line 113 of file list.cpp.