New directory tree, with preprocessor/ inside interpretor/.
[Faustine.git] / interpretor / preprocessor / faust-0.9.47mr3 / compiler / documentator / doc_sharing.cpp
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
66 int DocCompiler::getSharingCount(Tree sig)
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
96 void DocCompiler::sharingAnalysis(Tree t)
97 //void sharingAnalysis(Tree t)
98 {
99 fSharingKey = shprkey(t);
100 if (isList(t)) {
101 while (isList(t)) {
102 sharingAnnotation(kSamp, hd(t));
103 t = tl(t);
104 }
105 } else {
106 sharingAnnotation(kSamp, t);
107 }
108 }
109
110
111
112 //------------------------------------------------------------------------------
113 // Create a specific property key for the sharing count of subtrees of t
114 //------------------------------------------------------------------------------
115
116
117 void DocCompiler::sharingAnnotation(int vctxt, Tree sig)
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