FAUST compiler  0.9.9.6b8
occurrences.cpp
Go to the documentation of this file.
1 /************************************************************************
2  ************************************************************************
3  FAUST compiler
4  Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
5  ---------------------------------------------------------------------
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  ************************************************************************
20  ************************************************************************/
29 // construction des representations graphiques
30 
31 
32 #include "occurrences.hh"
33 #include "compatibility.hh"
34 
39 {
40  fKey = specificKey(root);
41  countOccurrences(root);
42  setCount(root,0); // root as no occurences in itself
43 }
44 
49 {
50  Tree c;
51  return (getProperty(t, fKey, c)) ? c->node().getInt() : 0;
52 }
53 
58 {
59  setProperty(t, fKey, tree(c));
60 }
61 
62 
63 
68 {
69  char keyname[256];
70  snprintf(keyname, 256, "OCCURRENCES COUNT IN %p : ", (CTree*)root);
71 
72  return tree(unique(keyname));
73 }
74 
79 {
80  setCount(t, getCount(t)+1); // increment t occurrences count
81  for (int i=0; i<t->arity(); i++) {
82  countOccurrences(t->branch(i));
83  }
84 }
85 
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
void countOccurrences(Tree t)
Increment the occurrences count of t and its subtrees.
Definition: occurrences.cpp:78
void setCount(Tree t, int c)
Set the number of occurrences of t.
Definition: occurrences.cpp:57
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
Tree specificKey(Tree root)
Creates a specific property key for occurrences count in root.
Definition: occurrences.cpp:67
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
Tree tree(const Node &n)
Definition: tree.hh:186
int getInt() const
Definition: node.hh:104
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
int getCount(Tree t)
Get the number of occurrences of t.
Definition: occurrences.cpp:48
Occurrences(Tree root)
Count the number of occurrences of each subtree of root.
Definition: occurrences.cpp:38
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423