Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > by-pkgid > aaf33964de706a538481c929c1da6a44 > files > 5383

faust-doc-0.9.10-5mdv2010.1.x86_64.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>FAUST compiler: recursivness.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>recursivness.cpp</h1><a href="recursivness_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/************************************************************************</span>
<a name="l00002"></a>00002 <span class="comment"> ************************************************************************</span>
<a name="l00003"></a>00003 <span class="comment">    FAUST compiler</span>
<a name="l00004"></a>00004 <span class="comment">    Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale</span>
<a name="l00005"></a>00005 <span class="comment">    ---------------------------------------------------------------------</span>
<a name="l00006"></a>00006 <span class="comment">    This program is free software; you can redistribute it and/or modify</span>
<a name="l00007"></a>00007 <span class="comment">    it under the terms of the GNU General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment">    the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00009"></a>00009 <span class="comment">    (at your option) any later version.</span>
<a name="l00010"></a>00010 <span class="comment"></span>
<a name="l00011"></a>00011 <span class="comment">    This program is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00014"></a>00014 <span class="comment">    GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">    You should have received a copy of the GNU General Public License</span>
<a name="l00017"></a>00017 <span class="comment">    along with this program; if not, write to the Free Software</span>
<a name="l00018"></a>00018 <span class="comment">    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span>
<a name="l00019"></a>00019 <span class="comment"> ************************************************************************</span>
<a name="l00020"></a>00020 <span class="comment"> ************************************************************************/</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;limits.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;<a class="code" href="recursivness_8hh.html">recursivness.hh</a>&quot;</span>
<a name="l00026"></a>00026 
<a name="l00038"></a>00038 <span class="comment">//--------------------------------------------------------------------------</span>
<a name="l00039"></a>00039 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursivness_8cpp.html#ae84af43472c202883669180ea5452a2e" title="Annotate a signal with recursivness.">annotate</a>(<a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> env, <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> sig);
<a name="l00040"></a>00040 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursivness_8cpp.html#aa9065b39904397aad91ca561ca539b79" title="return the position of a signal in the current recursive environment">position</a> (<a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> env, <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> t, <span class="keywordtype">int</span> p=1);
<a name="l00041"></a>00041 
<a name="l00042"></a><a class="code" href="recursivness_8cpp.html#af2160822a1b0646b573fd5672fdd287a">00042</a> <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> <a class="code" href="recursivness_8cpp.html#af2160822a1b0646b573fd5672fdd287a">RECURSIVNESS</a> = <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(<a class="code" href="symbol_8hh.html#aaa87083235b70d1042e59ae25e0800d8" title="Returns (and creates if new) the symbol of name str.">symbol</a>(<span class="stringliteral">&quot;RecursivnessProp&quot;</span>));
<a name="l00043"></a>00043 <span class="comment">//--------------------------------------------------------------------------</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 
<a name="l00051"></a><a class="code" href="recursivness_8hh.html#ad6d53633cf1982b7d7b094188c7bfe17">00051</a> <span class="keywordtype">void</span> <a class="code" href="recursivness_8cpp.html#ad6d53633cf1982b7d7b094188c7bfe17" title="Annotate a signal with recursivness.">recursivnessAnnotation</a>(<a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> sig)
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053     <a class="code" href="recursivness_8cpp.html#ae84af43472c202883669180ea5452a2e" title="Annotate a signal with recursivness.">annotate</a>(<a class="code" href="list_8cpp.html#a538b704dd07794b7237108f1917c471e">nil</a>, sig);
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 
<a name="l00064"></a><a class="code" href="recursivness_8hh.html#a790b66847f9e2962b7af4cc4e422baf3">00064</a> <span class="keywordtype">int</span> <a class="code" href="recursivness_8cpp.html#a5e771832d204d89a67f42e4a0b9b15a5" title="Return the recursivness of a previously annotated signal.">getRecursivness</a>(<a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> sig)
<a name="l00065"></a>00065 {
<a name="l00066"></a>00066     <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> tr;
<a name="l00067"></a>00067     <span class="keywordflow">if</span> ( ! <a class="code" href="list_8cpp.html#a665745948013d012bb123e9577c094bd">getProperty</a>(sig, RECURSIVNESS, tr)) {
<a name="l00068"></a>00068         cerr &lt;&lt; <span class="stringliteral">&quot;Error in getRecursivness of &quot;</span> &lt;&lt; *sig &lt;&lt; endl;
<a name="l00069"></a>00069         exit(1);
<a name="l00070"></a>00070     }
<a name="l00071"></a>00071     <span class="keywordflow">return</span> <a class="code" href="tree_8cpp.html#a523bce65e2a281fe678f2362496061cf" title="if t has a node of type int, return it otherwise error">tree2int</a>(tr);
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 
<a name="l00074"></a>00074 <span class="comment">//-------------------------------------- IMPLEMENTATION ------------------------------------</span>
<a name="l00081"></a><a class="code" href="recursivness_8cpp.html#ae84af43472c202883669180ea5452a2e">00081</a> <span class="comment"></span><span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursivness_8cpp.html#ae84af43472c202883669180ea5452a2e" title="Annotate a signal with recursivness.">annotate</a>(<a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> env, <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> sig)
<a name="l00082"></a>00082 {
<a name="l00083"></a>00083     <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> tr, var, body;
<a name="l00084"></a>00084 
<a name="l00085"></a>00085     <span class="keywordflow">if</span> (<a class="code" href="list_8cpp.html#a665745948013d012bb123e9577c094bd">getProperty</a>(sig, RECURSIVNESS, tr)) {
<a name="l00086"></a>00086         <span class="keywordflow">return</span> <a class="code" href="tree_8cpp.html#a523bce65e2a281fe678f2362496061cf" title="if t has a node of type int, return it otherwise error">tree2int</a>(tr);    <span class="comment">// already annotated</span>
<a name="l00087"></a>00087     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a4cb44c6e41e21da830e748dc35f16ba5" title="is t a de Bruijn recursive tree">isRec</a>(sig, var, body)) {
<a name="l00088"></a>00088         <span class="keywordtype">int</span> p = <a class="code" href="recursivness_8cpp.html#aa9065b39904397aad91ca561ca539b79" title="return the position of a signal in the current recursive environment">position</a>(env, sig);
<a name="l00089"></a>00089         <span class="keywordflow">if</span> (p &gt; 0) {
<a name="l00090"></a>00090             <span class="keywordflow">return</span> p;   <span class="comment">// we are inside \x.(...)</span>
<a name="l00091"></a>00091         } <span class="keywordflow">else</span> {
<a name="l00092"></a>00092             <span class="keywordtype">int</span> r = <a class="code" href="recursivness_8cpp.html#ae84af43472c202883669180ea5452a2e" title="Annotate a signal with recursivness.">annotate</a>(<a class="code" href="list_8hh.html#ae1ed153946fcfc025009c6d9c9c40bee">cons</a>(sig, env), body) - 1;
<a name="l00093"></a>00093             <span class="keywordflow">if</span> (r&lt;0) r=0;
<a name="l00094"></a>00094             <a class="code" href="list_8cpp.html#a5ead5a3e91af18d8f94e0974990a3c5a">setProperty</a>(sig, RECURSIVNESS, <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(r));
<a name="l00095"></a>00095             <span class="keywordflow">return</span> r;
<a name="l00096"></a>00096         }
<a name="l00097"></a>00097     } <span class="keywordflow">else</span> {
<a name="l00098"></a>00098         <span class="keywordtype">int</span> rmax = 0;
<a name="l00099"></a>00099         vector&lt;Tree&gt; v; <a class="code" href="signals_8hh.html#ae5dd2bb17d8df90f5561bb8084b3f10f" title="Extract the sub signals of a signal expression, that is not necesseraly all the subtrees...">getSubSignals</a>(sig, v);
<a name="l00100"></a>00100         <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;v.size(); i++) {
<a name="l00101"></a>00101             <span class="keywordtype">int</span> r = <a class="code" href="recursivness_8cpp.html#ae84af43472c202883669180ea5452a2e" title="Annotate a signal with recursivness.">annotate</a>(env, v[i]);
<a name="l00102"></a>00102             <span class="keywordflow">if</span> (r&gt;rmax) rmax=r;
<a name="l00103"></a>00103         }
<a name="l00104"></a>00104         <a class="code" href="list_8cpp.html#a5ead5a3e91af18d8f94e0974990a3c5a">setProperty</a>(sig, RECURSIVNESS, <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(rmax));
<a name="l00105"></a>00105         <span class="keywordflow">return</span> rmax;
<a name="l00106"></a>00106     }
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 
<a name="l00110"></a>00110 
<a name="l00117"></a><a class="code" href="recursivness_8cpp.html#aa9065b39904397aad91ca561ca539b79">00117</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursivness_8cpp.html#aa9065b39904397aad91ca561ca539b79" title="return the position of a signal in the current recursive environment">position</a> (<a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> env, <a class="code" href="classCTree.html" title="A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches...">Tree</a> t, <span class="keywordtype">int</span> p)
<a name="l00118"></a>00118 {
<a name="l00119"></a>00119     <span class="keywordflow">if</span> (<a class="code" href="list_8hh.html#a2569c3a07bbbfa55e0afde62de62aeec">isNil</a>(env)) <span class="keywordflow">return</span> 0;   <span class="comment">// was not in the environment</span>
<a name="l00120"></a>00120     <span class="keywordflow">if</span> (<a class="code" href="list_8hh.html#a067ad6f83087b420a1c44e48e56be389">hd</a>(env) == t) <span class="keywordflow">return</span> p;
<a name="l00121"></a>00121     <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="recursivness_8cpp.html#aa9065b39904397aad91ca561ca539b79" title="return the position of a signal in the current recursive environment">position</a> (<a class="code" href="list_8hh.html#a4075748f5c7156306ec898795313a2e0">tl</a>(env), t, p+1);
<a name="l00122"></a>00122 }
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Apr 28 23:59:59 2010 for FAUST compiler by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>