Sophie

Sophie

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

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: colorize.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>colorize.cpp</h1><a href="colorize_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00007"></a>00007 <span class="preprocessor">#include &quot;<a class="code" href="colorize_8h.html">colorize.h</a>&quot;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;<a class="code" href="signals_8hh.html">signals.hh</a>&quot;</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="keyword">using namespace </span>std; 
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment">// static funvtions needed to implement splitDependance</span>
<a name="l00013"></a>00013 
<a name="l00014"></a>00014 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="colorize_8cpp.html#a4bd3d0035fd38bae8aa83898889bb22f" title="allocate a new unique color for exp">allocateColor</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> exp);                         
<a name="l00015"></a>00015 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a8fceb2afc402ca2359e5de3d056de73d" title="add color information to exp and all its subtrees">colorize</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> exp, <span class="keywordtype">int</span> color);                  
<a name="l00016"></a>00016 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a8d5048eda3154390aea0838aec62dc89" title="remove color information">uncolorize</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> exp);                           
<a name="l00017"></a>00017 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a30dd1b2444e94cd3d6231eb8f7f112b5" title="list multicolored subexpressions of exp">listMultiColoredExp</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> exp, set&lt;Tree&gt;&amp; lst);  
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 
<a name="l00028"></a><a class="code" href="colorize_8h.html#a0f8ff1d12378dd049340876374a0356f">00028</a> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a0f8ff1d12378dd049340876374a0356f" title="Analyze a set of expressions to discover its dependencies that is subexpressions...">splitDependance</a>(<span class="keyword">const</span> set&lt;Tree&gt;&amp; exps, set&lt;Tree&gt;&amp; post, set&lt;Tree&gt;&amp; pre)
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030     set&lt;Tree&gt;::const_iterator e;
<a name="l00031"></a>00031     <span class="keywordflow">for</span> (e= exps.begin(); e != exps.end(); e++) {
<a name="l00032"></a>00032         <a class="code" href="colorize_8cpp.html#a8fceb2afc402ca2359e5de3d056de73d" title="add color information to exp and all its subtrees">colorize</a>(*e, <a class="code" href="colorize_8cpp.html#a4bd3d0035fd38bae8aa83898889bb22f" title="allocate a new unique color for exp">allocateColor</a>(*e));
<a name="l00033"></a>00033     }
<a name="l00034"></a>00034     
<a name="l00035"></a>00035     pre.clear();
<a name="l00036"></a>00036     <span class="keywordflow">for</span> (e = exps.begin(); e != exps.end(); e++) {
<a name="l00037"></a>00037         <a class="code" href="colorize_8cpp.html#a30dd1b2444e94cd3d6231eb8f7f112b5" title="list multicolored subexpressions of exp">listMultiColoredExp</a>(*e, pre);
<a name="l00038"></a>00038     }
<a name="l00039"></a>00039     
<a name="l00040"></a>00040     post.clear();
<a name="l00041"></a>00041     set_difference(exps.begin(), exps.end(), pre.begin(), pre.end(), inserter(post, post.begin()));
<a name="l00042"></a>00042     
<a name="l00043"></a>00043     <span class="keywordflow">for</span> (e = exps.begin(); e != exps.end(); e++) {
<a name="l00044"></a>00044         <a class="code" href="colorize_8cpp.html#a8d5048eda3154390aea0838aec62dc89" title="remove color information">uncolorize</a>(*e);
<a name="l00045"></a>00045     }
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 <span class="comment">//------------------------------------------- IMPLEMENTATION  (level 1)-----------------------------------------------------</span>
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a8cd7e641a8f14e8195a61f82096fd610" title="a color to the colors of exp">addColor</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> exp, <span class="keywordtype">int</span> color);                  
<a name="l00051"></a>00051 <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="colorize_8cpp.html#ae5b5116d7c057d1abfaeed6b7f186c03" title="true if exp is already colored with color">hasColor</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> exp, <span class="keywordtype">int</span> color);                  
<a name="l00052"></a>00052 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="colorize_8cpp.html#ab54ffb1c6ba10aa111050d08e9bc2cd4" title="returns the number of colors of exp">colorsCount</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> exp);                           
<a name="l00053"></a>00053 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a5aea1efcff76eacf3c026e3adb7331ae" title="remove the color property of exp">clearColors</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> exp);                          
<a name="l00054"></a>00054 
<a name="l00059"></a><a class="code" href="colorize_8cpp.html#a4bd3d0035fd38bae8aa83898889bb22f">00059</a> <span class="keywordtype">int</span> <a class="code" href="colorize_8cpp.html#a4bd3d0035fd38bae8aa83898889bb22f" title="allocate a new unique color for exp">allocateColor</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> exp)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061 <span class="comment">//  return int(exp); </span>
<a name="l00062"></a>00062     <span class="keyword">static</span> map&lt;Tree,int&gt; colorMap;
<a name="l00063"></a>00063     <span class="keyword">static</span> <span class="keywordtype">int</span> nextFreeColor = 1;
<a name="l00064"></a>00064     <span class="keywordtype">int</span>&amp; color = colorMap[exp];
<a name="l00065"></a>00065     <span class="keywordflow">if</span> (!color)
<a name="l00066"></a>00066         color = nextFreeColor++;
<a name="l00067"></a>00067     <span class="keywordflow">return</span> color;
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 
<a name="l00073"></a><a class="code" href="colorize_8cpp.html#a8fceb2afc402ca2359e5de3d056de73d">00073</a> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a8fceb2afc402ca2359e5de3d056de73d" title="add color information to exp and all its subtrees">colorize</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> exp, <span class="keywordtype">int</span> color)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075     <span class="keywordflow">if</span> (! <a class="code" href="colorize_8cpp.html#ae5b5116d7c057d1abfaeed6b7f186c03" title="true if exp is already colored with color">hasColor</a>(exp, color)) {
<a name="l00076"></a>00076         <a class="code" href="colorize_8cpp.html#a8cd7e641a8f14e8195a61f82096fd610" title="a color to the colors of exp">addColor</a>(exp, color);
<a name="l00077"></a>00077         vector&lt;Tree&gt; v;
<a name="l00078"></a>00078         <span class="keywordtype">int</span> n = <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>(exp, v, <span class="keyword">false</span>);
<a name="l00079"></a>00079         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n; i++) <a class="code" href="colorize_8cpp.html#a8fceb2afc402ca2359e5de3d056de73d" title="add color information to exp and all its subtrees">colorize</a>(v[i], color);
<a name="l00080"></a>00080     }   
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082 
<a name="l00086"></a><a class="code" href="colorize_8cpp.html#a8d5048eda3154390aea0838aec62dc89">00086</a> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a8d5048eda3154390aea0838aec62dc89" title="remove color information">uncolorize</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> exp)
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088     <span class="keywordflow">if</span> (<a class="code" href="colorize_8cpp.html#ab54ffb1c6ba10aa111050d08e9bc2cd4" title="returns the number of colors of exp">colorsCount</a>(exp) &gt; 0) {
<a name="l00089"></a>00089         <a class="code" href="colorize_8cpp.html#a5aea1efcff76eacf3c026e3adb7331ae" title="remove the color property of exp">clearColors</a>(exp);
<a name="l00090"></a>00090         vector&lt;Tree&gt; v;
<a name="l00091"></a>00091         <span class="keywordtype">int</span> n = <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>(exp, v, <span class="keyword">false</span>);
<a name="l00092"></a>00092         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n; i++) <a class="code" href="colorize_8cpp.html#a8d5048eda3154390aea0838aec62dc89" title="remove color information">uncolorize</a>(v[i]);
<a name="l00093"></a>00093     }   
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095 
<a name="l00099"></a><a class="code" href="colorize_8cpp.html#a30dd1b2444e94cd3d6231eb8f7f112b5">00099</a> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a30dd1b2444e94cd3d6231eb8f7f112b5" title="list multicolored subexpressions of exp">listMultiColoredExp</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> exp, set&lt;Tree&gt;&amp; lst)
<a name="l00100"></a>00100 {
<a name="l00101"></a>00101     assert(<a class="code" href="colorize_8cpp.html#ab54ffb1c6ba10aa111050d08e9bc2cd4" title="returns the number of colors of exp">colorsCount</a>(exp) &gt; 0);
<a name="l00102"></a>00102     <span class="keywordflow">if</span> (<a class="code" href="colorize_8cpp.html#ab54ffb1c6ba10aa111050d08e9bc2cd4" title="returns the number of colors of exp">colorsCount</a>(exp) &gt; 1) {
<a name="l00103"></a>00103         <span class="comment">// we have found a multicolored expression</span>
<a name="l00104"></a>00104         lst.insert(exp);
<a name="l00105"></a>00105     } <span class="keywordflow">else</span> {
<a name="l00106"></a>00106         <span class="comment">// it is a monocolored expression</span>
<a name="l00107"></a>00107         <span class="comment">// we search its subexpressions</span>
<a name="l00108"></a>00108         vector&lt;Tree&gt; v;
<a name="l00109"></a>00109         <span class="keywordtype">int</span> n = <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>(exp, v, <span class="keyword">false</span>);
<a name="l00110"></a>00110         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;n; i++) {
<a name="l00111"></a>00111             <a class="code" href="colorize_8cpp.html#a30dd1b2444e94cd3d6231eb8f7f112b5" title="list multicolored subexpressions of exp">listMultiColoredExp</a>(v[i], lst);
<a name="l00112"></a>00112         }
<a name="l00113"></a>00113     }   
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="comment">//------------------------------------------- IMPLEMENTATION  (level 2)-----------------------------------------------------</span>
<a name="l00117"></a>00117 
<a name="l00118"></a><a class="code" href="colorize_8cpp.html#a0bf6d3ed426f7267aaa1f0b93f4bfc09">00118</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="colorize_8cpp.html#a0bf6d3ed426f7267aaa1f0b93f4bfc09">COLORPROPERTY</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;ColorProperty&quot;</span>));
<a name="l00119"></a>00119 
<a name="l00125"></a><a class="code" href="colorize_8cpp.html#aade532065d8d5a93ff9f3b19d0008f2d">00125</a> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#aade532065d8d5a93ff9f3b19d0008f2d" title="set the color-set property of sig">setColorProperty</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, set&lt;int&gt;* colorset)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127     <a class="code" href="list_8cpp.html#a5ead5a3e91af18d8f94e0974990a3c5a">setProperty</a>(sig, COLORPROPERTY, <a class="code" href="tree_8hh.html#a61c13e9361cfa80bbb3cd6ce60a8f595">tree</a>((<span class="keywordtype">void</span>*)colorset));
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130 
<a name="l00135"></a><a class="code" href="colorize_8cpp.html#a08f52f77166b2ebccb74fce43908ba45">00135</a> set&lt;int&gt;* <a class="code" href="colorize_8cpp.html#a08f52f77166b2ebccb74fce43908ba45" title="retrieve the color-set property of sig">getColorProperty</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="l00136"></a>00136 {
<a name="l00137"></a>00137     <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> tt;
<a name="l00138"></a>00138     <span class="keywordflow">if</span> (!<a class="code" href="list_8cpp.html#a665745948013d012bb123e9577c094bd">getProperty</a>(sig, COLORPROPERTY, tt)) {
<a name="l00139"></a>00139         <span class="keywordflow">return</span> 0;
<a name="l00140"></a>00140     } <span class="keywordflow">else</span> {
<a name="l00141"></a>00141         <span class="keywordflow">return</span> (set&lt;int&gt;*)<a class="code" href="tree_8cpp.html#ad1d692b2c0a86d485a3d096af07632e6" title="if t has a node of type ptr, return it otherwise error">tree2ptr</a>(tt);
<a name="l00142"></a>00142     }
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144 
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 
<a name="l00147"></a>00147 
<a name="l00154"></a><a class="code" href="colorize_8cpp.html#a8cd7e641a8f14e8195a61f82096fd610">00154</a> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a8cd7e641a8f14e8195a61f82096fd610" title="a color to the colors of exp">addColor</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> exp, <span class="keywordtype">int</span> color)
<a name="l00155"></a>00155 {
<a name="l00156"></a>00156     set&lt;int&gt;* cset = <a class="code" href="colorize_8cpp.html#a08f52f77166b2ebccb74fce43908ba45" title="retrieve the color-set property of sig">getColorProperty</a>(exp);
<a name="l00157"></a>00157     <span class="keywordflow">if</span> (cset == 0) {
<a name="l00158"></a>00158         cset = <span class="keyword">new</span> set&lt;int&gt;();
<a name="l00159"></a>00159         <a class="code" href="colorize_8cpp.html#aade532065d8d5a93ff9f3b19d0008f2d" title="set the color-set property of sig">setColorProperty</a>(exp, cset);
<a name="l00160"></a>00160     }
<a name="l00161"></a>00161     cset-&gt;insert(color);
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 
<a name="l00171"></a><a class="code" href="colorize_8cpp.html#ae5b5116d7c057d1abfaeed6b7f186c03">00171</a> <span class="keywordtype">bool</span> <a class="code" href="colorize_8cpp.html#ae5b5116d7c057d1abfaeed6b7f186c03" title="true if exp is already colored with color">hasColor</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> exp, <span class="keywordtype">int</span> color)
<a name="l00172"></a>00172 {
<a name="l00173"></a>00173     set&lt;int&gt;* cset = <a class="code" href="colorize_8cpp.html#a08f52f77166b2ebccb74fce43908ba45" title="retrieve the color-set property of sig">getColorProperty</a>(exp);
<a name="l00174"></a>00174     <span class="keywordflow">if</span> (cset==0) {
<a name="l00175"></a>00175         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00176"></a>00176     } <span class="keywordflow">else</span> {
<a name="l00177"></a>00177         <span class="keywordflow">return</span> cset-&gt;find(color) != cset-&gt;end();
<a name="l00178"></a>00178     }
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 
<a name="l00187"></a><a class="code" href="colorize_8cpp.html#ab54ffb1c6ba10aa111050d08e9bc2cd4">00187</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="colorize_8cpp.html#ab54ffb1c6ba10aa111050d08e9bc2cd4" title="returns the number of colors of exp">colorsCount</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> exp)
<a name="l00188"></a>00188 {
<a name="l00189"></a>00189     set&lt;int&gt;* cset = <a class="code" href="colorize_8cpp.html#a08f52f77166b2ebccb74fce43908ba45" title="retrieve the color-set property of sig">getColorProperty</a>(exp);
<a name="l00190"></a>00190     <span class="keywordflow">if</span> (cset==0) {
<a name="l00191"></a>00191         <span class="keywordflow">return</span> 0;
<a name="l00192"></a>00192     } <span class="keywordflow">else</span> {
<a name="l00193"></a>00193         <span class="keywordflow">return</span> cset-&gt;size();
<a name="l00194"></a>00194     }
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196 
<a name="l00197"></a>00197 
<a name="l00203"></a><a class="code" href="colorize_8cpp.html#a5aea1efcff76eacf3c026e3adb7331ae">00203</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="colorize_8cpp.html#a5aea1efcff76eacf3c026e3adb7331ae" title="remove the color property of exp">clearColors</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> exp)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205     set&lt;int&gt;* cset = <a class="code" href="colorize_8cpp.html#a08f52f77166b2ebccb74fce43908ba45" title="retrieve the color-set property of sig">getColorProperty</a>(exp);
<a name="l00206"></a>00206     <span class="keywordflow">if</span> (cset != 0) {
<a name="l00207"></a>00207         cset-&gt;clear();
<a name="l00208"></a>00208     }
<a name="l00209"></a>00209 }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Apr 28 23:59:58 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>