Sophie

Sophie

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

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: recursive-tree.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>recursive-tree.cpp</h1><a href="recursive-tree_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 
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;limits.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="tlib_8hh.html">tlib.hh</a>&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="comment">// Declaration of implementation</span>
<a name="l00031"></a>00031 <span class="keyword">static</span> <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="recursive-tree_8cpp.html#ab814aecf89e4591fd9a23f4ab145f8f0">calcDeBruijn2Sym</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> t);
<a name="l00032"></a>00032 <span class="keyword">static</span> <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="list_8cpp.html#a40185c4c5a347dcef0ae115ebf3443d6">substitute</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> t, <span class="keywordtype">int</span> n, <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> <span class="keywordtype">id</span>);
<a name="l00033"></a>00033 <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a5eff39d6a3254cfe871c9efdf4426b97">calcsubstitute</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> t, <span class="keywordtype">int</span> level, <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> <span class="keywordtype">id</span>);
<a name="l00034"></a>00034 <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">liftn</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> t, <span class="keywordtype">int</span> threshold);
<a name="l00035"></a>00035 <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a50c168abcbcc4183f530f5e0c49f91dd">calcliftn</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> t, <span class="keywordtype">int</span> threshold);
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="comment">// recursive trees</span>
<a name="l00038"></a>00038 
<a name="l00039"></a><a class="code" href="recursive-tree_8cpp.html#a079e594f132e158b05af96450deaeeb5">00039</a> <a class="code" href="classSymbol.html" title="Symbols are unique objects with a name stored in a hash table.">Sym</a>     <a class="code" href="recursive-tree_8cpp.html#a079e594f132e158b05af96450deaeeb5">DEBRUIJN</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;DEBRUIJN&quot;</span>);
<a name="l00040"></a><a class="code" href="recursive-tree_8cpp.html#a0a0bb7149e09722eb48442f920afa94a">00040</a> <a class="code" href="classSymbol.html" title="Symbols are unique objects with a name stored in a hash table.">Sym</a>     <a class="code" href="recursive-tree_8cpp.html#a0a0bb7149e09722eb48442f920afa94a">DEBRUIJNREF</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;DEBRUIJNREF&quot;</span>);
<a name="l00041"></a><a class="code" href="recursive-tree_8cpp.html#a66a0ec08beb7a4574d1e7abe55c24c49">00041</a> <a class="code" href="classSymbol.html" title="Symbols are unique objects with a name stored in a hash table.">Sym</a>     <a class="code" href="recursive-tree_8cpp.html#a66a0ec08beb7a4574d1e7abe55c24c49">SUBSTITUTE</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;SUBSTITUTE&quot;</span>);
<a name="l00042"></a>00042 
<a name="l00043"></a><a class="code" href="recursive-tree_8cpp.html#a472adc9dd3732243140a081d93b744db">00043</a> <a class="code" href="classSymbol.html" title="Symbols are unique objects with a name stored in a hash table.">Sym</a>     <a class="code" href="recursive-tree_8cpp.html#a472adc9dd3732243140a081d93b744db">SYMREC</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;SYMREC&quot;</span>);
<a name="l00044"></a><a class="code" href="recursive-tree_8cpp.html#a81aac32780f7a9114bc0d071e66e3b25">00044</a> <a class="code" href="classSymbol.html" title="Symbols are unique objects with a name stored in a hash table.">Sym</a>     <a class="code" href="recursive-tree_8cpp.html#a81aac32780f7a9114bc0d071e66e3b25">SYMRECREF</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;SYMRECREF&quot;</span>);
<a name="l00045"></a><a class="code" href="recursive-tree_8cpp.html#ae07d18a347a7116066f3b79da384c34c">00045</a> <a class="code" href="classSymbol.html" title="Symbols are unique objects with a name stored in a hash table.">Sym</a>     <a class="code" href="recursive-tree_8cpp.html#ae07d18a347a7116066f3b79da384c34c">SYMLIFTN</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;LIFTN&quot;</span>);
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="comment">//Tree  NOVAR       = tree(&quot;NOVAR&quot;);</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="comment">//-----------------------------------------------------------------------------------------</span>
<a name="l00050"></a>00050 <span class="comment">// rec, isRec : declare recursive trees</span>
<a name="l00051"></a>00051 <span class="comment">//-----------------------------------------------------------------------------------------</span>
<a name="l00052"></a>00052 
<a name="l00053"></a>00053 <span class="comment">// de Bruijn declaration of a recursive tree</span>
<a name="l00054"></a><a class="code" href="tree_8hh.html#aa598f21268aa7198407d2eb6929d09ab">00054</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="recursive-tree_8cpp.html#aa598f21268aa7198407d2eb6929d09ab" title="create a de Bruijn recursive tree">rec</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> body)
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056     <span class="keywordflow">return</span> <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(DEBRUIJN, body);
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 
<a name="l00059"></a><a class="code" href="tree_8hh.html#a4cb44c6e41e21da830e748dc35f16ba5">00059</a> <span class="keywordtype">bool</span> <a class="code" href="recursive-tree_8cpp.html#a4cb44c6e41e21da830e748dc35f16ba5" title="is t a de Bruijn recursive tree">isRec</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> t, <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>&amp; body)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061     <span class="keywordflow">return</span> <a class="code" href="tree_8cpp.html#a06be972e0437c7c09e8a1274586fe176">isTree</a>(t, DEBRUIJN, body);
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="tree_8hh.html#ab93ecee07e77e314fe39e3199d06437a">00064</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="recursive-tree_8cpp.html#ab93ecee07e77e314fe39e3199d06437a" title="create a de Bruijn recursive reference">ref</a>(<span class="keywordtype">int</span> level)
<a name="l00065"></a>00065 {
<a name="l00066"></a>00066     assert(level &gt; 0);
<a name="l00067"></a>00067     <span class="keywordflow">return</span> <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(DEBRUIJNREF, <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(level));  <span class="comment">// reference to enclosing recursive tree starting from 1</span>
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 
<a name="l00070"></a><a class="code" href="tree_8hh.html#a3a07093d0e487cc733adab39f6a18e78">00070</a> <span class="keywordtype">bool</span> <a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</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> t, <span class="keywordtype">int</span>&amp; level)
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072     <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>    u;
<a name="l00073"></a>00073 
<a name="l00074"></a>00074     <span class="keywordflow">if</span> (<a class="code" href="tree_8cpp.html#a06be972e0437c7c09e8a1274586fe176">isTree</a>(t, DEBRUIJNREF, u)) {
<a name="l00075"></a>00075         <span class="keywordflow">return</span> <a class="code" href="node_8hh.html#a8c9b968ac68f6cac1c361002da8afe99">isInt</a>(u-&gt;<a class="code" href="classCTree.html#a8de786fec095c8304b9ffa7c1c316237" title="return the content of the tree">node</a>(), &amp;level);
<a name="l00076"></a>00076     } <span class="keywordflow">else</span> {
<a name="l00077"></a>00077         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00078"></a>00078     }
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 
<a name="l00081"></a>00081 
<a name="l00082"></a>00082 <span class="comment">//-----------------------------------------------------------------------------------------</span>
<a name="l00083"></a>00083 <span class="comment">// Recursive tree in symbolic notation (using a recursive definition property)</span>
<a name="l00084"></a>00084 <span class="comment">//-----------------------------------------------------------------------------------------</span>
<a name="l00085"></a><a class="code" href="recursive-tree_8cpp.html#aa589b365baa26873e9e1f76f7482c3fc">00085</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="recursive-tree_8cpp.html#aa589b365baa26873e9e1f76f7482c3fc">RECDEF</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;RECDEF&quot;</span>));
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="comment">// declaration of a recursive tree using a symbolic variable</span>
<a name="l00088"></a><a class="code" href="tree_8hh.html#a23ecac1d7caf88fcb57c4d47da0d8e51">00088</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="recursive-tree_8cpp.html#aa598f21268aa7198407d2eb6929d09ab" title="create a de Bruijn recursive tree">rec</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> var, <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> body)
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090     <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 = <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(SYMREC, var);
<a name="l00091"></a>00091     t-&gt;<a class="code" href="classCTree.html#ac628a2ad0d2a21de584e3bca291bd38c">setProperty</a>(RECDEF, body);
<a name="l00092"></a>00092     <span class="keywordflow">return</span> t;
<a name="l00093"></a>00093 }
<a name="l00094"></a>00094 
<a name="l00095"></a><a class="code" href="tree_8hh.html#a6eaedeabb2e6f66b31e21c12adb96e54">00095</a> <span class="keywordtype">bool</span> <a class="code" href="recursive-tree_8cpp.html#a4cb44c6e41e21da830e748dc35f16ba5" title="is t a de Bruijn recursive tree">isRec</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> t, <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>&amp; var, <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>&amp; body)
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097     <span class="keywordflow">if</span> (<a class="code" href="tree_8cpp.html#a06be972e0437c7c09e8a1274586fe176">isTree</a>(t, SYMREC, var)) {
<a name="l00098"></a>00098         body = t-&gt;<a class="code" href="classCTree.html#a902b48b83db587f14dbd31999c0f715f">getProperty</a>(RECDEF);
<a name="l00099"></a>00099         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00100"></a>00100     } <span class="keywordflow">else</span> {
<a name="l00101"></a>00101         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00102"></a>00102     }
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a><a class="code" href="tree_8hh.html#a125af067c9ecda063a2eace315f5ae12">00106</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="recursive-tree_8cpp.html#ab93ecee07e77e314fe39e3199d06437a" title="create a de Bruijn recursive reference">ref</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> <span class="keywordtype">id</span>)
<a name="l00107"></a>00107 {
<a name="l00108"></a>00108     <span class="keywordflow">return</span> <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(SYMREC, <span class="keywordtype">id</span>);            <span class="comment">// reference to a symbolic id</span>
<a name="l00109"></a>00109 }
<a name="l00110"></a>00110 
<a name="l00111"></a><a class="code" href="tree_8hh.html#adb8fa0e2bea8270b17354331c1e344b5">00111</a> <span class="keywordtype">bool</span> <a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</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> t, <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>&amp; v)
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113     <span class="keywordflow">return</span> <a class="code" href="tree_8cpp.html#a06be972e0437c7c09e8a1274586fe176">isTree</a>(t, SYMREC, v);
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="comment">//-----------------------------------------------------------------------------------------</span>
<a name="l00117"></a>00117 <span class="comment">// L&#39;aperture d&#39;un arbre est la plus profonde reference de Bruijn qu&#39;il contienne.</span>
<a name="l00118"></a>00118 <span class="comment">// Les references symboliques compte pour zero ce qui veut dire qu&#39;un arbre d&#39;aperture</span>
<a name="l00119"></a>00119 <span class="comment">// 0 ne compte aucun reference de bruijn libres.</span>
<a name="l00120"></a>00120 
<a name="l00121"></a><a class="code" href="classCTree.html#ab6f456ea4f5400fb5b93807b281e6eb3">00121</a> <span class="keywordtype">int</span> <a class="code" href="classCTree.html#ab6f456ea4f5400fb5b93807b281e6eb3" title="compute how open is a tree">CTree::calcTreeAperture</a>( <span class="keyword">const</span> <a class="code" href="classNode.html" title="Class Node = (type x (int + double + Sym + void*)).">Node</a>&amp; n, <span class="keyword">const</span> <a class="code" href="tree_8hh.html#ad425127c677ce9f82f03e6dc57a87937">tvec</a>&amp; br  )
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123     <span class="keywordtype">int</span> x;
<a name="l00124"></a>00124     <span class="keywordflow">if</span> (n == DEBRUIJNREF) {
<a name="l00125"></a>00125 
<a name="l00126"></a>00126         <span class="keywordflow">if</span> (<a class="code" href="node_8hh.html#a8c9b968ac68f6cac1c361002da8afe99">isInt</a>(br[0]-&gt;<a class="code" href="classCTree.html#a8de786fec095c8304b9ffa7c1c316237" title="return the content of the tree">node</a>(), &amp;x)) {
<a name="l00127"></a>00127             <span class="keywordflow">return</span> x;
<a name="l00128"></a>00128         } <span class="keywordflow">else</span> {
<a name="l00129"></a>00129             <span class="keywordflow">return</span> 0;
<a name="l00130"></a>00130         }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n == DEBRUIJN) {
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         <span class="keywordflow">return</span> br[0]-&gt;fAperture - 1;
<a name="l00135"></a>00135 
<a name="l00136"></a>00136     } <span class="keywordflow">else</span> {
<a name="l00137"></a>00137         <span class="comment">// return max aperture of branches</span>
<a name="l00138"></a>00138         <span class="keywordtype">int</span> rc = 0;
<a name="l00139"></a>00139         tvec::const_iterator    b = br.begin();
<a name="l00140"></a>00140         tvec::const_iterator    z = br.end();
<a name="l00141"></a>00141         <span class="keywordflow">while</span> (b != z) {
<a name="l00142"></a>00142             <span class="keywordflow">if</span> ((*b)-&gt;aperture() &gt; rc) rc = (*b)-&gt;aperture();
<a name="l00143"></a>00143             ++b;
<a name="l00144"></a>00144         }
<a name="l00145"></a>00145         <span class="keywordflow">return</span> rc;
<a name="l00146"></a>00146     }
<a name="l00147"></a>00147 }
<a name="l00148"></a>00148 
<a name="l00149"></a><a class="code" href="tree_8hh.html#abf6659f19a0e48b81af0b0fb39ede302">00149</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="recursive-tree_8cpp.html#abf6659f19a0e48b81af0b0fb39ede302">lift</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> t) { <span class="keywordflow">return</span> <a class="code" href="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">liftn</a>(t, 1); }
<a name="l00150"></a>00150 
<a name="l00151"></a>00151 <span class="keywordtype">void</span> <a class="code" href="sigprint_8cpp.html#ac996689aaeee388feb18661ff38abe01">printSignal</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, FILE* out, <span class="keywordtype">int</span> prec=0);
<a name="l00152"></a>00152 
<a name="l00153"></a>00153 <span class="comment">// lift (t) : increase free references by 1</span>
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="preprocessor">#if 0</span>
<a name="l00156"></a>00156 <span class="preprocessor"></span><span class="keyword">static</span> <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> _liftn(<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> threshold);
<a name="l00157"></a>00157 
<a name="l00158"></a>00158 <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">liftn</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> t, <span class="keywordtype">int</span> threshold)
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160     fprintf(stderr, <span class="stringliteral">&quot;call of liftn(&quot;</span>); <a class="code" href="sigprint_8cpp.html#ac996689aaeee388feb18661ff38abe01">printSignal</a>(t, stderr); fprintf(stderr, <span class="stringliteral">&quot;, %d)\n&quot;</span>, threshold);
<a name="l00161"></a>00161     <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> r = _liftn(t, threshold);
<a name="l00162"></a>00162     fprintf(stderr, <span class="stringliteral">&quot;return of liftn(&quot;</span>); <a class="code" href="sigprint_8cpp.html#ac996689aaeee388feb18661ff38abe01">printSignal</a>(t, stderr); fprintf(stderr, <span class="stringliteral">&quot;, %d) -&gt; &quot;</span>, threshold);
<a name="l00163"></a>00163     <a class="code" href="sigprint_8cpp.html#ac996689aaeee388feb18661ff38abe01">printSignal</a>(r, stderr); fprintf(stderr, <span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00164"></a>00164     <span class="keywordflow">return</span> r;
<a name="l00165"></a>00165 }
<a name="l00166"></a>00166 <span class="preprocessor">#endif</span>
<a name="l00167"></a>00167 <span class="preprocessor"></span>
<a name="l00168"></a>00168 
<a name="l00169"></a><a class="code" href="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">00169</a> <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">liftn</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> t, <span class="keywordtype">int</span> threshold)
<a name="l00170"></a>00170 {
<a name="l00171"></a>00171     <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> L  = <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>( <a class="code" href="classNode.html" title="Class Node = (type x (int + double + Sym + void*)).">Node</a>(SYMLIFTN), <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(<a class="code" href="classNode.html" title="Class Node = (type x (int + double + Sym + void*)).">Node</a>(threshold)) );
<a name="l00172"></a>00172     <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> t2 = t-&gt;<a class="code" href="classCTree.html#a902b48b83db587f14dbd31999c0f715f">getProperty</a>(L);
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     <span class="keywordflow">if</span> (!t2) {
<a name="l00175"></a>00175         t2 = <a class="code" href="recursive-tree_8cpp.html#a50c168abcbcc4183f530f5e0c49f91dd">calcliftn</a>(t, threshold);
<a name="l00176"></a>00176         t-&gt;<a class="code" href="classCTree.html#ac628a2ad0d2a21de584e3bca291bd38c">setProperty</a>(L, t2);
<a name="l00177"></a>00177     }
<a name="l00178"></a>00178     <span class="keywordflow">return</span> t2;
<a name="l00179"></a>00179     
<a name="l00180"></a>00180 }
<a name="l00181"></a>00181 
<a name="l00182"></a><a class="code" href="recursive-tree_8cpp.html#a50c168abcbcc4183f530f5e0c49f91dd">00182</a> <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a50c168abcbcc4183f530f5e0c49f91dd">calcliftn</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> t, <span class="keywordtype">int</span> threshold)
<a name="l00183"></a>00183 {
<a name="l00184"></a>00184     <span class="keywordtype">int</span>     n;
<a name="l00185"></a>00185     <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>    u;
<a name="l00186"></a>00186 
<a name="l00187"></a>00187     <span class="keywordflow">if</span> (<a class="code" href="tree_8hh.html#a447a569f359244de90fa72c2efdb8be5" title="t dont contain free de Bruijn ref">isClosed</a>(t)) {
<a name="l00188"></a>00188 
<a name="l00189"></a>00189         <span class="keywordflow">return</span> t;
<a name="l00190"></a>00190 
<a name="l00191"></a>00191     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</a>(t,n)) {
<a name="l00192"></a>00192 
<a name="l00193"></a>00193         <span class="keywordflow">if</span> (n &lt; threshold) {
<a name="l00194"></a>00194             <span class="comment">// it is a bounded reference</span>
<a name="l00195"></a>00195             <span class="keywordflow">return</span> t;
<a name="l00196"></a>00196         } <span class="keywordflow">else</span> {
<a name="l00197"></a>00197             <span class="comment">// it is a free reference</span>
<a name="l00198"></a>00198             <span class="keywordflow">return</span> <a class="code" href="recursive-tree_8cpp.html#ab93ecee07e77e314fe39e3199d06437a" title="create a de Bruijn recursive reference">ref</a>(n+1);
<a name="l00199"></a>00199         }
<a name="l00200"></a>00200 
<a name="l00201"></a>00201     } <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>(t,u)) {
<a name="l00202"></a>00202 
<a name="l00203"></a>00203         <span class="keywordflow">return</span> <a class="code" href="recursive-tree_8cpp.html#aa598f21268aa7198407d2eb6929d09ab" title="create a de Bruijn recursive tree">rec</a>(<a class="code" href="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">liftn</a>(u, threshold+1));
<a name="l00204"></a>00204 
<a name="l00205"></a>00205     } <span class="keywordflow">else</span> {
<a name="l00206"></a>00206         <span class="keywordtype">int</span> n = t-&gt;<a class="code" href="classCTree.html#a68f2be5e845407bc956a2893fe6f0d03" title="return the number of branches (subtrees) of a tree">arity</a>();
<a name="l00207"></a>00207         <span class="comment">//Tree  br[4];</span>
<a name="l00208"></a>00208         <a class="code" href="tree_8hh.html#ad425127c677ce9f82f03e6dc57a87937">tvec</a>    br(n);
<a name="l00209"></a>00209         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; n; i++) {
<a name="l00210"></a>00210             br[i] = <a class="code" href="recursive-tree_8cpp.html#a170b606017c8f6e443ad39f1dbb9ca8d">liftn</a>(t-&gt;<a class="code" href="classCTree.html#a06c1513b23dc7b0d9da9c930c6dc43c5" title="return the ith branch (subtree) of a tree">branch</a>(i), threshold);
<a name="l00211"></a>00211         }
<a name="l00212"></a>00212         <span class="comment">//return CTree::make(t-&gt;node(), n, br);</span>
<a name="l00213"></a>00213         <span class="keywordflow">return</span> <a class="code" href="classCTree.html#a3184c572cef05308f59e36ea2bdf537e" title="return a new tree or an existing equivalent one">CTree::make</a>(t-&gt;<a class="code" href="classCTree.html#a8de786fec095c8304b9ffa7c1c316237" title="return the content of the tree">node</a>(), br);
<a name="l00214"></a>00214     }
<a name="l00215"></a>00215 
<a name="l00216"></a>00216 }
<a name="l00217"></a>00217 
<a name="l00218"></a>00218 <span class="comment">//-----------------------------------------------------------</span>
<a name="l00219"></a>00219 <span class="comment">// Transform a tree from deBruijn to symbolic representation</span>
<a name="l00220"></a>00220 <span class="comment">//-----------------------------------------------------------</span>
<a name="l00221"></a><a class="code" href="recursive-tree_8cpp.html#ade56faf8037fbd6fa55fe1ccc21c74f0">00221</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="recursive-tree_8cpp.html#ade56faf8037fbd6fa55fe1ccc21c74f0">DEBRUIJN2SYM</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;deBruijn2Sym&quot;</span>));
<a name="l00222"></a>00222 
<a name="l00223"></a><a class="code" href="tree_8hh.html#ab896f65486e6d80d4440721f2f89ff96">00223</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="recursive-tree_8cpp.html#ab896f65486e6d80d4440721f2f89ff96">deBruijn2Sym</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> t)
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225     assert(<a class="code" href="tree_8hh.html#a447a569f359244de90fa72c2efdb8be5" title="t dont contain free de Bruijn ref">isClosed</a>(t));
<a name="l00226"></a>00226     <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> t2 = t-&gt;<a class="code" href="classCTree.html#a902b48b83db587f14dbd31999c0f715f">getProperty</a>(DEBRUIJN2SYM);
<a name="l00227"></a>00227 
<a name="l00228"></a>00228     <span class="keywordflow">if</span> (!t2) {
<a name="l00229"></a>00229         t2 = <a class="code" href="recursive-tree_8cpp.html#ab814aecf89e4591fd9a23f4ab145f8f0">calcDeBruijn2Sym</a>(t);
<a name="l00230"></a>00230         t-&gt;<a class="code" href="classCTree.html#ac628a2ad0d2a21de584e3bca291bd38c">setProperty</a>(DEBRUIJN2SYM, t2);
<a name="l00231"></a>00231     }
<a name="l00232"></a>00232     <span class="keywordflow">return</span> t2;
<a name="l00233"></a>00233 }
<a name="l00234"></a>00234 
<a name="l00235"></a><a class="code" href="recursive-tree_8cpp.html#ab814aecf89e4591fd9a23f4ab145f8f0">00235</a> <span class="keyword">static</span> <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="recursive-tree_8cpp.html#ab814aecf89e4591fd9a23f4ab145f8f0">calcDeBruijn2Sym</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> t)
<a name="l00236"></a>00236 {
<a name="l00237"></a>00237     <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>    body, var;
<a name="l00238"></a>00238     <span class="keywordtype">int</span>     i;
<a name="l00239"></a>00239 
<a name="l00240"></a>00240     <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a4cb44c6e41e21da830e748dc35f16ba5" title="is t a de Bruijn recursive tree">isRec</a>(t,body)) {
<a name="l00241"></a>00241 
<a name="l00242"></a>00242         var = <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(<a class="code" href="symbol_8hh.html#a377309446e0e86ae663cd6709e02889d" title="Returns a new unique symbol of name strxxx.">unique</a>(<span class="stringliteral">&quot;W&quot;</span>));
<a name="l00243"></a>00243         <span class="keywordflow">return</span> <a class="code" href="recursive-tree_8cpp.html#aa598f21268aa7198407d2eb6929d09ab" title="create a de Bruijn recursive tree">rec</a>(var, <a class="code" href="recursive-tree_8cpp.html#ab896f65486e6d80d4440721f2f89ff96">deBruijn2Sym</a>(<a class="code" href="list_8cpp.html#a40185c4c5a347dcef0ae115ebf3443d6">substitute</a>(body,1,<a class="code" href="recursive-tree_8cpp.html#ab93ecee07e77e314fe39e3199d06437a" title="create a de Bruijn recursive reference">ref</a>(var))));
<a name="l00244"></a>00244 
<a name="l00245"></a>00245     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</a>(t,var)) {
<a name="l00246"></a>00246 
<a name="l00247"></a>00247         <span class="keywordflow">return</span> t;
<a name="l00248"></a>00248 
<a name="l00249"></a>00249     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</a>(t,i)) {
<a name="l00250"></a>00250 
<a name="l00251"></a>00251         fprintf(stderr, <span class="stringliteral">&quot;ERREUR, une reference de Bruijn touvee ! : &quot;</span>);
<a name="l00252"></a>00252         <a class="code" href="sigprint_8cpp.html#ac996689aaeee388feb18661ff38abe01">printSignal</a>(t, stderr);
<a name="l00253"></a>00253         fprintf(stderr, <span class="stringliteral">&quot;)\n&quot;</span>);
<a name="l00254"></a>00254         exit(1);
<a name="l00255"></a>00255         <span class="keywordflow">return</span> t;
<a name="l00256"></a>00256 
<a name="l00257"></a>00257     } <span class="keywordflow">else</span> {
<a name="l00258"></a>00258 
<a name="l00259"></a>00259         <span class="comment">//Tree  br[4];</span>
<a name="l00260"></a>00260         <span class="keywordtype">int</span>     a = t-&gt;<a class="code" href="classCTree.html#a68f2be5e845407bc956a2893fe6f0d03" title="return the number of branches (subtrees) of a tree">arity</a>();
<a name="l00261"></a>00261         <a class="code" href="tree_8hh.html#ad425127c677ce9f82f03e6dc57a87937">tvec</a>    br(a);
<a name="l00262"></a>00262 
<a name="l00263"></a>00263         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; a; i++) {
<a name="l00264"></a>00264             br[i] = <a class="code" href="recursive-tree_8cpp.html#ab896f65486e6d80d4440721f2f89ff96">deBruijn2Sym</a>(t-&gt;<a class="code" href="classCTree.html#a06c1513b23dc7b0d9da9c930c6dc43c5" title="return the ith branch (subtree) of a tree">branch</a>(i));
<a name="l00265"></a>00265         }
<a name="l00266"></a>00266         <span class="comment">//return CTree::make(t-&gt;node(), a, br);</span>
<a name="l00267"></a>00267         <span class="keywordflow">return</span> <a class="code" href="classCTree.html#a3184c572cef05308f59e36ea2bdf537e" title="return a new tree or an existing equivalent one">CTree::make</a>(t-&gt;<a class="code" href="classCTree.html#a8de786fec095c8304b9ffa7c1c316237" title="return the content of the tree">node</a>(), br);
<a name="l00268"></a>00268     }
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 
<a name="l00271"></a><a class="code" href="recursive-tree_8cpp.html#a77cfc706306e29611ef1fd28c731ab47">00271</a> <span class="keyword">static</span> <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="list_8cpp.html#a40185c4c5a347dcef0ae115ebf3443d6">substitute</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> t, <span class="keywordtype">int</span> level, <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> <span class="keywordtype">id</span>)
<a name="l00272"></a>00272 {
<a name="l00273"></a>00273     <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> S  = <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>( <a class="code" href="classNode.html" title="Class Node = (type x (int + double + Sym + void*)).">Node</a>(SUBSTITUTE), <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>(<a class="code" href="classNode.html" title="Class Node = (type x (int + double + Sym + void*)).">Node</a>(level)), <span class="keywordtype">id</span> );
<a name="l00274"></a>00274     <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> t2 = t-&gt;<a class="code" href="classCTree.html#a902b48b83db587f14dbd31999c0f715f">getProperty</a>(S);
<a name="l00275"></a>00275 
<a name="l00276"></a>00276     <span class="keywordflow">if</span> (!t2) {
<a name="l00277"></a>00277         t2 = <a class="code" href="recursive-tree_8cpp.html#a5eff39d6a3254cfe871c9efdf4426b97">calcsubstitute</a>(t, level, <span class="keywordtype">id</span>);
<a name="l00278"></a>00278         t-&gt;<a class="code" href="classCTree.html#ac628a2ad0d2a21de584e3bca291bd38c">setProperty</a>(S, t2);
<a name="l00279"></a>00279     }
<a name="l00280"></a>00280     <span class="keywordflow">return</span> t2;
<a name="l00281"></a>00281     
<a name="l00282"></a>00282 }
<a name="l00283"></a>00283 
<a name="l00284"></a><a class="code" href="recursive-tree_8cpp.html#a5eff39d6a3254cfe871c9efdf4426b97">00284</a> <span class="keyword">static</span> <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="recursive-tree_8cpp.html#a5eff39d6a3254cfe871c9efdf4426b97">calcsubstitute</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> t, <span class="keywordtype">int</span> level, <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> <span class="keywordtype">id</span>)
<a name="l00285"></a>00285 {
<a name="l00286"></a>00286     <span class="keywordtype">int</span>     l;
<a name="l00287"></a>00287     <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>    body;
<a name="l00288"></a>00288 
<a name="l00289"></a>00289     <span class="keywordflow">if</span> (t-&gt;<a class="code" href="classCTree.html#a3ce05a5474896a873ddbccd7caea2680" title="return how &amp;quot;open&amp;quot; is a tree in terms of free variables">aperture</a>()&lt;level) {
<a name="l00290"></a>00290 <span class="comment">//      fprintf(stderr, &quot;aperture %d &lt; level %d !!\n&quot;, t-&gt;aperture(), level);</span>
<a name="l00291"></a>00291         <span class="keywordflow">return</span> t;
<a name="l00292"></a>00292     }
<a name="l00293"></a>00293     <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</a>(t,l))          <span class="keywordflow">return</span> (l == level) ? <span class="keywordtype">id</span> : t;
<a name="l00294"></a>00294     <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a4cb44c6e41e21da830e748dc35f16ba5" title="is t a de Bruijn recursive tree">isRec</a>(t,body))       <span class="keywordflow">return</span> <a class="code" href="recursive-tree_8cpp.html#aa598f21268aa7198407d2eb6929d09ab" title="create a de Bruijn recursive tree">rec</a>(<a class="code" href="list_8cpp.html#a40185c4c5a347dcef0ae115ebf3443d6">substitute</a>(body, level+1, <span class="keywordtype">id</span>));
<a name="l00295"></a>00295 
<a name="l00296"></a>00296     <span class="keywordtype">int</span>     ar = t-&gt;<a class="code" href="classCTree.html#a68f2be5e845407bc956a2893fe6f0d03" title="return the number of branches (subtrees) of a tree">arity</a>();
<a name="l00297"></a>00297     <span class="comment">//Tree  br[4];</span>
<a name="l00298"></a>00298     <a class="code" href="tree_8hh.html#ad425127c677ce9f82f03e6dc57a87937">tvec</a>    br(ar);
<a name="l00299"></a>00299     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; ar; i++) {
<a name="l00300"></a>00300         br[i] = <a class="code" href="list_8cpp.html#a40185c4c5a347dcef0ae115ebf3443d6">substitute</a>(t-&gt;<a class="code" href="classCTree.html#a06c1513b23dc7b0d9da9c930c6dc43c5" title="return the ith branch (subtree) of a tree">branch</a>(i), level, id);
<a name="l00301"></a>00301     }
<a name="l00302"></a>00302     <span class="comment">//return CTree::make(t-&gt;node(), ar, br);</span>
<a name="l00303"></a>00303     <span class="keywordflow">return</span> <a class="code" href="classCTree.html#a3184c572cef05308f59e36ea2bdf537e" title="return a new tree or an existing equivalent one">CTree::make</a>(t-&gt;<a class="code" href="classCTree.html#a8de786fec095c8304b9ffa7c1c316237" title="return the content of the tree">node</a>(), br);
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 
<a name="l00306"></a>00306 
<a name="l00307"></a>00307 <span class="comment">//--------------------------------------------------------------------------</span>
<a name="l00308"></a>00308 <span class="comment">// UpdateAperture (t) : recursively mark open and closed terms.</span>
<a name="l00309"></a>00309 <span class="comment">// closed term : fAperture == 0,  open term fAperture == -1</span>
<a name="l00310"></a>00310 
<a name="l00311"></a><a class="code" href="structEnv.html">00311</a> <span class="keyword">struct </span><a class="code" href="structEnv.html">Env</a> {
<a name="l00312"></a><a class="code" href="structEnv.html#a5c54d61f82dc5d0e9f8fd642ba7446ff">00312</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="structEnv.html#a5c54d61f82dc5d0e9f8fd642ba7446ff">fTree</a>; <a class="code" href="structEnv.html">Env</a>* <a class="code" href="structEnv.html#a454d9ddd80ca67afeebeff609f79701b">fNext</a>;
<a name="l00313"></a><a class="code" href="structEnv.html#ac2fadbba968346b38b7f77e4b86b3747">00313</a>     <a class="code" href="structEnv.html#ac2fadbba968346b38b7f77e4b86b3747">Env</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> t, <a class="code" href="structEnv.html">Env</a>* nxt) : <a class="code" href="structEnv.html#a5c54d61f82dc5d0e9f8fd642ba7446ff">fTree</a>(t), <a class="code" href="structEnv.html#a454d9ddd80ca67afeebeff609f79701b">fNext</a>(nxt) {}
<a name="l00314"></a>00314 };
<a name="l00315"></a>00315 
<a name="l00316"></a>00316 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="recursive-tree_8cpp.html#a3ab4f44f961339b489f4a6289e8c6150">markOpen</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> t);
<a name="l00317"></a>00317 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursive-tree_8cpp.html#a9f4f307fe5880833a420d751e62779f0">recomputeAperture</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> t, <a class="code" href="structEnv.html">Env</a>* p);
<a name="l00318"></a>00318 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursive-tree_8cpp.html#a75385568fda3ed8a657985c612f2b2f7">orderof</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> t, <a class="code" href="structEnv.html">Env</a>* p);
<a name="l00319"></a>00319 
<a name="l00320"></a><a class="code" href="tree_8hh.html#ae6da444b930bc1b8eed51bd15108e5e2">00320</a> <span class="keywordtype">void</span> <a class="code" href="recursive-tree_8cpp.html#ae6da444b930bc1b8eed51bd15108e5e2">updateAperture</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> t)
<a name="l00321"></a>00321 {
<a name="l00322"></a>00322     <a class="code" href="recursive-tree_8cpp.html#a3ab4f44f961339b489f4a6289e8c6150">markOpen</a>(t);
<a name="l00323"></a>00323     <a class="code" href="recursive-tree_8cpp.html#a9f4f307fe5880833a420d751e62779f0">recomputeAperture</a>(t, NULL);
<a name="l00324"></a>00324 }
<a name="l00325"></a>00325 
<a name="l00326"></a>00326 <span class="comment">//----------------------implementation--------------------------------</span>
<a name="l00327"></a>00327 
<a name="l00328"></a><a class="code" href="recursive-tree_8cpp.html#a3ab4f44f961339b489f4a6289e8c6150">00328</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="recursive-tree_8cpp.html#a3ab4f44f961339b489f4a6289e8c6150">markOpen</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> t)
<a name="l00329"></a>00329 {
<a name="l00330"></a>00330     <span class="keywordflow">if</span> (t-&gt;<a class="code" href="classCTree.html#a3ce05a5474896a873ddbccd7caea2680" title="return how &amp;quot;open&amp;quot; is a tree in terms of free variables">aperture</a>() == INT_MAX) <span class="keywordflow">return</span>;
<a name="l00331"></a>00331     t-&gt;<a class="code" href="classCTree.html#a43dfbeab91c992660762d3d6783baff7" title="modify the aperture of a tree">setAperture</a>(INT_MAX);
<a name="l00332"></a>00332     <span class="keywordtype">int</span> ar = t-&gt;<a class="code" href="classCTree.html#a68f2be5e845407bc956a2893fe6f0d03" title="return the number of branches (subtrees) of a tree">arity</a>();
<a name="l00333"></a>00333     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; ar; i++) {
<a name="l00334"></a>00334         <a class="code" href="recursive-tree_8cpp.html#a3ab4f44f961339b489f4a6289e8c6150">markOpen</a>(t-&gt;<a class="code" href="classCTree.html#a06c1513b23dc7b0d9da9c930c6dc43c5" title="return the ith branch (subtree) of a tree">branch</a>(i));
<a name="l00335"></a>00335     }
<a name="l00336"></a>00336 }
<a name="l00337"></a>00337 
<a name="l00338"></a><a class="code" href="recursive-tree_8cpp.html#a9f4f307fe5880833a420d751e62779f0">00338</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursive-tree_8cpp.html#a9f4f307fe5880833a420d751e62779f0">recomputeAperture</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> t, <a class="code" href="structEnv.html">Env</a>* env)
<a name="l00339"></a>00339 {
<a name="l00340"></a>00340     <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>    var, body;
<a name="l00341"></a>00341 
<a name="l00342"></a>00342     <span class="keywordflow">if</span> (t-&gt;<a class="code" href="classCTree.html#a3ce05a5474896a873ddbccd7caea2680" title="return how &amp;quot;open&amp;quot; is a tree in terms of free variables">aperture</a>() == 0) <span class="keywordflow">return</span> 0;
<a name="l00343"></a>00343 
<a name="l00344"></a>00344     <span class="keywordflow">if</span> (<a class="code" href="recursive-tree_8cpp.html#a3a07093d0e487cc733adab39f6a18e78" title="is t a de Bruijn recursive reference">isRef</a>(t, var)) {
<a name="l00345"></a>00345 
<a name="l00346"></a>00346         <span class="keywordflow">return</span> <a class="code" href="recursive-tree_8cpp.html#a75385568fda3ed8a657985c612f2b2f7">orderof</a>(var, env);
<a name="l00347"></a>00347 
<a name="l00348"></a>00348     } <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>(t, var, body)) {
<a name="l00349"></a>00349 
<a name="l00350"></a>00350         <a class="code" href="structEnv.html">Env</a> e(var,env);
<a name="l00351"></a>00351         <span class="keywordtype">int</span> a = <a class="code" href="recursive-tree_8cpp.html#a9f4f307fe5880833a420d751e62779f0">recomputeAperture</a>(body, &amp;e) - 1;
<a name="l00352"></a>00352         <span class="keywordflow">if</span> (a&lt;=0) { <span class="comment">/*print(t, stderr);*/</span> t-&gt;<a class="code" href="classCTree.html#a43dfbeab91c992660762d3d6783baff7" title="modify the aperture of a tree">setAperture</a>(0); }
<a name="l00353"></a>00353         <span class="keywordflow">return</span> a;
<a name="l00354"></a>00354 
<a name="l00355"></a>00355     } <span class="keywordflow">else</span> {
<a name="l00356"></a>00356         <span class="comment">// return max aperture of branches</span>
<a name="l00357"></a>00357         <span class="keywordtype">int</span> ma = 0;
<a name="l00358"></a>00358         <span class="keywordtype">int</span> ar = t-&gt;<a class="code" href="classCTree.html#a68f2be5e845407bc956a2893fe6f0d03" title="return the number of branches (subtrees) of a tree">arity</a>();
<a name="l00359"></a>00359         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i&lt;ar; i++) {
<a name="l00360"></a>00360             <span class="keywordtype">int</span> a = <a class="code" href="recursive-tree_8cpp.html#a9f4f307fe5880833a420d751e62779f0">recomputeAperture</a>(t-&gt;<a class="code" href="classCTree.html#a06c1513b23dc7b0d9da9c930c6dc43c5" title="return the ith branch (subtree) of a tree">branch</a>(i), env);
<a name="l00361"></a>00361             <span class="keywordflow">if</span> (ma &lt; a) ma = a;
<a name="l00362"></a>00362         }
<a name="l00363"></a>00363         <span class="keywordflow">if</span> (ma &lt;= 0)  { <span class="comment">/*print(t, stderr);*/</span> t-&gt;<a class="code" href="classCTree.html#a43dfbeab91c992660762d3d6783baff7" title="modify the aperture of a tree">setAperture</a>(0); }
<a name="l00364"></a>00364         <span class="keywordflow">return</span> ma;
<a name="l00365"></a>00365     }
<a name="l00366"></a>00366 }
<a name="l00367"></a>00367 
<a name="l00368"></a>00368 
<a name="l00369"></a><a class="code" href="recursive-tree_8cpp.html#a75385568fda3ed8a657985c612f2b2f7">00369</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="recursive-tree_8cpp.html#a75385568fda3ed8a657985c612f2b2f7">orderof</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> t, <a class="code" href="structEnv.html">Env</a>* p)
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371     <span class="keywordflow">if</span> (p == NULL) <span class="keywordflow">return</span> 0;
<a name="l00372"></a>00372     <span class="keywordflow">if</span> (t == p-&gt;<a class="code" href="structEnv.html#a5c54d61f82dc5d0e9f8fd642ba7446ff">fTree</a>) <span class="keywordflow">return</span> 1;
<a name="l00373"></a>00373 
<a name="l00374"></a>00374     <span class="keywordtype">int</span> pos = 1;
<a name="l00375"></a>00375     <span class="keywordflow">while</span> (p != NULL) {
<a name="l00376"></a>00376         <span class="keywordflow">if</span> (t == p-&gt;<a class="code" href="structEnv.html#a5c54d61f82dc5d0e9f8fd642ba7446ff">fTree</a>) <span class="keywordflow">return</span> pos;
<a name="l00377"></a>00377         p = p-&gt;<a class="code" href="structEnv.html#a454d9ddd80ca67afeebeff609f79701b">fNext</a>;
<a name="l00378"></a>00378         pos++;
<a name="l00379"></a>00379     }
<a name="l00380"></a>00380     <span class="keywordflow">return</span> 0;
<a name="l00381"></a>00381 }
</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>