FAUST compiler  0.9.9.6b8
doc_sharing.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  ************************************************************************/
21 
22 
23 
24 /*****************************************************************************
25 ******************************************************************************
26  FAUST SIGNAL COMPILER
27  Y. Orlarey, (c) Grame 2002
28 ------------------------------------------------------------------------------
29 Compile a list of FAUST signals into a LaTeX equation.
30 
31  History :
32  ---------
33  2002-02-08 : First version (of sharing.cpp)
34  2009-08-18 : Doc version (Karim Barkati)
35 
36 ******************************************************************************
37 *****************************************************************************/
38 
39 
40 
41 #include <stdio.h>
42 
43 //#include "compile_vect.hh"
44 //#include "compile_scal.hh"
45 //#include "doc_compile_vect.hh"
46 #include "doc_compile.hh"
47 #include "sigtype.hh"
48 #include "sigtyperules.hh"
49 #include "sigprint.hh"
50 
51 //#include "doc_sharing.hh"
52 
53 
54 /*****************************************************************************
55 ******************************************************************************
56 
57  SHARING ANALYSIS
58 
59 ******************************************************************************
60 *****************************************************************************/
61 
62 //------------------------------------------------------------------------------
63 // Create a specific property key for the sharing count of subtrees of t
64 //------------------------------------------------------------------------------
65 
67 //int getSharingCount(Tree sig, int count)
68 {
69  //cerr << "getSharingCount of : " << *sig << " = ";
70  Tree c;
71  if (getProperty(sig, fSharingKey, c)) {
72  //cerr << c->node().getInt() << endl;
73  return c->node().getInt();
74  } else {
75  //cerr << 0 << endl;
76  return 0;
77  }
78 }
79 
80 
81 void DocCompiler::setSharingCount(Tree sig, int count)
82 //void setSharingCount(Tree sig, int count)
83 {
84  //cerr << "setSharingCount of : " << *sig << " <- " << count << endl;
85  setProperty(sig, fSharingKey, tree(count));
86 }
87 
88 
89 
90 //------------------------------------------------------------------------------
91 // Create a specific property key for the sharing count of subtrees of t
92 //------------------------------------------------------------------------------
93 
94 
95 
97 //void sharingAnalysis(Tree t)
98 {
99  fSharingKey = shprkey(t);
100  if (isList(t)) {
101  while (isList(t)) {
103  t = tl(t);
104  }
105  } else {
107  }
108 }
109 
110 
111 
112 //------------------------------------------------------------------------------
113 // Create a specific property key for the sharing count of subtrees of t
114 //------------------------------------------------------------------------------
115 
116 
118 //void sharingAnnotation(int vctxt, Tree sig)
119 {
120  //cerr << "START sharing annotation of " << *sig << endl;
121  int count = getSharingCount(sig);
122 
123  if (count > 0) {
124  // it is not our first visit
125  setSharingCount(sig, count+1);
126 
127  } else {
128  // it is our first visit,
129  int v = getCertifiedSigType(sig)->variability();
130 
131  // check "time sharing" cases
132  if (v < vctxt) {
133  setSharingCount(sig, 2); // time sharing occurence : slower expression in faster context
134  } else {
135  setSharingCount(sig, 1); // regular occurence
136  }
137 
138  // Annotate the sub signals
139  vector<Tree> subsig;
140  int n = getSubSignals(sig, subsig);
141  if (n>0 && ! isSigGen(sig)) {
142  for (int i=0; i<n; i++) sharingAnnotation(v, subsig[i]);
143  }
144  }
145  //cerr << "END sharing annotation of " << *sig << endl;
146 }
147 
148 
void sharingAnalysis(Tree t)
Definition: doc_sharing.cpp:96
Tree shprkey(Tree t)
Create a specific property key for the sharing count of subtrees of t.
Definition: shlysis.cpp:69
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
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
void sharingAnnotation(int vctxt, Tree t)
bool isList(Tree l)
Definition: list.hh:138
Tree fSharingKey
Definition: doc_compile.hh:59
void setSharingCount(Tree t, int count)
Definition: doc_sharing.cpp:81
Definition: sigtype.hh:56
Type getCertifiedSigType(Tree sig)
Retrieve the type of sig and check it exists.
int getSharingCount(Tree t)
Definition: doc_sharing.cpp:66
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
API to the typing system of signals.
Tree tl(Tree l)
Definition: list.hh:134
int getSubSignals(Tree sig, vector< Tree > &vsigs, bool visitgen=true)
Extract the sub signals of a signal expression, that is not necesseraly all the subtrees.
Definition: subsignals.cpp:12
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423