Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > ffa1e6f5ad04360808fe8840fe3ba036 > files > 269

vrq-devel-1.0.88-1.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>vrq: /net/fileserver/nas/home/mdh/vrq/src/csymtab.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
  <table border="0" cellspacing="0" cellpadding="0" width="100%">
   <tr>
    <td width="180"><a href="index.html"><img src="vrq.png" width="150" height="100" border="0" alt="vrq"></a></td>
    <td background="top_bg.png" align="right" width="100%">
      <img src="glyth.png" width="500" height="100" border="0" alt="">
    </td>
   </tr>
   <tr>
    <td background="#FFFFFF" align="right" width="50" height="4"></td>
   </tr>
  </table>
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<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="modules.html"><span>Modules</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>
<h1>/net/fileserver/nas/home/mdh/vrq/src/csymtab.h</h1><a href="csymtab_8h.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"> * Copyright (C) 1997-2007, Mark Hummel</span>
<a name="l00003"></a>00003 <span class="comment"> * This file is part of Vrq.</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Vrq is free software; you can redistribute it and/or</span>
<a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the GNU General Public</span>
<a name="l00007"></a>00007 <span class="comment"> * License as published by the Free Software Foundation; either</span>
<a name="l00008"></a>00008 <span class="comment"> * version 2 of the License, or (at your option) any later version.</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * Vrq is distributed in the hope that it will be useful,</span>
<a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<a name="l00013"></a>00013 <span class="comment"> * General Public License for more details.</span>
<a name="l00014"></a>00014 <span class="comment"> *</span>
<a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU General Public</span>
<a name="l00016"></a>00016 <span class="comment"> * License along with this library; if not, write to the Free Software</span>
<a name="l00017"></a>00017 <span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, </span>
<a name="l00018"></a>00018 <span class="comment"> * Boston, MA  02110-1301  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="comment">/******************************************************************************</span>
<a name="l00022"></a>00022 <span class="comment"> *</span>
<a name="l00023"></a>00023 <span class="comment"> *</span>
<a name="l00024"></a>00024 <span class="comment"> *         csymtab.hpp</span>
<a name="l00025"></a>00025 <span class="comment"> *              - class definition for symbol tables </span>
<a name="l00026"></a>00026 <span class="comment"> *</span>
<a name="l00027"></a>00027 <span class="comment"> *</span>
<a name="l00028"></a>00028 <span class="comment"> ******************************************************************************</span>
<a name="l00029"></a>00029 <span class="comment"> */</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#ifndef CSYMTAB_HPP</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define CSYMTAB_HPP</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="glue_8h.html">glue.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="cdecl_8h.html">cdecl.h</a>"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;map&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <span class="keyword">class </span><a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>;
<a name="l00042"></a>00042                         
<a name="l00048"></a>00048 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T1&gt;
<a name="l00049"></a>00049 <span class="keyword">class </span>CSymtabEntry : <span class="keyword">public</span> map&lt;CSymbol*,T1*&gt;
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051 <span class="keyword">private</span>:
<a name="l00052"></a>00052         <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a>           depth;
<a name="l00053"></a>00053         CSymtabEntry*   previous;
<a name="l00054"></a>00054 <span class="keyword">public</span>:
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="comment">/*********************************************************</span>
<a name="l00057"></a>00057 <span class="comment">        Constructor</span>
<a name="l00058"></a>00058 <span class="comment">**********************************************************/</span>
<a name="l00059"></a>00059 CSymtabEntry( <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a> aDepth, CSymtabEntry* parent ) 
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061         depth        = aDepth;
<a name="l00062"></a>00062         previous     = parent;
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064 <span class="comment">/*********************************************************</span>
<a name="l00065"></a>00065 <span class="comment">        GetDepth</span>
<a name="l00066"></a>00066 <span class="comment">        - return current symbol table depth </span>
<a name="l00067"></a>00067 <span class="comment">**********************************************************/</span>
<a name="l00068"></a>00068 <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a>   GetDepth() {
<a name="l00069"></a>00069         <span class="keywordflow">return</span> depth;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 <span class="comment">/*********************************************************</span>
<a name="l00072"></a>00072 <span class="comment">        GetPrevious</span>
<a name="l00073"></a>00073 <span class="comment">        - return previous level </span>
<a name="l00074"></a>00074 <span class="comment">**********************************************************/</span>
<a name="l00075"></a>00075 CSymtabEntry*   GetPrevious() {
<a name="l00076"></a>00076         <span class="keywordflow">return</span> previous;
<a name="l00077"></a>00077 }
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 <span class="comment">/*********************************************************</span>
<a name="l00080"></a>00080 <span class="comment">        Lookup</span>
<a name="l00081"></a>00081 <span class="comment">        - find symbol by recursively searching table </span>
<a name="l00082"></a>00082 <span class="comment">**********************************************************/</span>
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 T1* Lookup( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* key )
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086         T1*                         result;
<a name="l00087"></a>00087         <span class="keyword">typename</span> map&lt;CSymbol*,T1*&gt;::iterator ptr;
<a name="l00088"></a>00088 
<a name="l00089"></a>00089         result = NULL;
<a name="l00090"></a>00090         ptr = this-&gt;find( key );
<a name="l00091"></a>00091         <span class="keywordflow">if</span>( ptr != this-&gt;end() ) {
<a name="l00092"></a>00092                 <span class="keywordflow">return</span> ptr-&gt;second;
<a name="l00093"></a>00093         }
<a name="l00094"></a>00094         <span class="keywordflow">if</span>( previous ) {
<a name="l00095"></a>00095                 result = previous-&gt;Lookup( key );
<a name="l00096"></a>00096         }
<a name="l00097"></a>00097         <span class="keywordflow">return</span> result;
<a name="l00098"></a>00098 }       
<a name="l00099"></a>00099 
<a name="l00100"></a>00100 <span class="comment">/*********************************************************</span>
<a name="l00101"></a>00101 <span class="comment">        LookupTop</span>
<a name="l00102"></a>00102 <span class="comment">        - find symbol at top level only </span>
<a name="l00103"></a>00103 <span class="comment">**********************************************************/</span>
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 T1* LookupTop( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* key )
<a name="l00106"></a>00106 {
<a name="l00107"></a>00107         T1*                         result;
<a name="l00108"></a>00108         <span class="keyword">typename</span> map&lt;CSymbol*,T1*&gt;::iterator ptr;
<a name="l00109"></a>00109 
<a name="l00110"></a>00110         result = NULL;
<a name="l00111"></a>00111         ptr = this-&gt;find( key );
<a name="l00112"></a>00112         <span class="keywordflow">if</span>( ptr != this-&gt;end() ) {
<a name="l00113"></a>00113                 result = ptr-&gt;second;
<a name="l00114"></a>00114         } 
<a name="l00115"></a>00115         <span class="keywordflow">return</span> result;
<a name="l00116"></a>00116 }       
<a name="l00117"></a>00117 
<a name="l00118"></a>00118 <span class="keywordtype">void</span>    Dump( FILE *f, <span class="keywordtype">int</span> recurse ) 
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120         <span class="keyword">typename</span> map&lt;CSymbol*,T1*&gt;::iterator ptr;
<a name="l00121"></a>00121 
<a name="l00122"></a>00122         <span class="keywordflow">for</span>( ptr = this-&gt;begin(); ptr != this-&gt;end(); ++ptr) {
<a name="l00123"></a>00123                 printf( <span class="stringliteral">"\t%s =&gt; "</span>, ptr-&gt;first-&gt;GetName() );
<a name="l00124"></a>00124                 ptr-&gt;second-&gt;DumpDeclInfo( f );
<a name="l00125"></a>00125         }
<a name="l00126"></a>00126         <span class="keywordflow">if</span>( recurse &amp;&amp; previous != NULL ) {
<a name="l00127"></a>00127                 previous-&gt;Dump( f, recurse );
<a name="l00128"></a>00128         }
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130                 
<a name="l00131"></a>00131 };
<a name="l00142"></a><a class="code" href="classCSymtab.html">00142</a> <span class="keyword">template</span>&lt;<span class="keyword">class</span> T1&gt;
<a name="l00143"></a>00143 <span class="keyword">class </span><a class="code" href="classCSymtab.html" title="Aux class used to create symbol table scoping.">CSymtab</a>
<a name="l00144"></a>00144 {
<a name="l00145"></a>00145 <span class="keyword">private</span>:
<a name="l00146"></a>00146         <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a>                   currentDepth;   
<a name="l00147"></a>00147         CSymtabEntry&lt;T1&gt;*       table;          
<a name="l00148"></a>00148 <span class="keyword">public</span>:
<a name="l00149"></a>00149 
<a name="l00153"></a>00153 <a class="code" href="classCSymtab.html#fdb92980563b3571f3497cc0f9d97f40" title="Create a symbol table.">CSymtab</a>() 
<a name="l00154"></a>00154 {
<a name="l00155"></a>00155         currentDepth = 0;
<a name="l00156"></a>00156         table        = <span class="keyword">new</span> CSymtabEntry&lt;T1&gt;( 0, NULL );
<a name="l00157"></a>00157 }
<a name="l00161"></a>00161 <span class="keywordtype">void</span> <a class="code" href="classCSymtab.html#356d0c0f64fc4fa474728edee01afb48" title="Jump back to parent scope.">PopScope</a>()
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163         <a class="code" href="group__utilities.html#g6dbd4cb0f492800d40e2cad42a0ea250" title="Add invariant checks to code.">MASSERT</a>( currentDepth &gt; 0 );
<a name="l00164"></a>00164         <a class="code" href="group__utilities.html#g6dbd4cb0f492800d40e2cad42a0ea250" title="Add invariant checks to code.">MASSERT</a>( table != NULL );
<a name="l00165"></a>00165 
<a name="l00166"></a>00166         currentDepth--;
<a name="l00167"></a>00167         <span class="keywordflow">if</span>( table-&gt;GetDepth() &lt;= currentDepth ) {
<a name="l00168"></a>00168                 <span class="keywordflow">return</span>;
<a name="l00169"></a>00169         }
<a name="l00170"></a>00170         
<a name="l00171"></a>00171         table = table-&gt;GetPrevious();
<a name="l00172"></a>00172 }       
<a name="l00178"></a>00178 <span class="keywordtype">void</span> <a class="code" href="classCSymtab.html#f674e884f18df32512aa951b633c2414" title="Create a new scope for table.">PushScope</a>( <span class="keywordtype">int</span> lazy )
<a name="l00179"></a>00179 {
<a name="l00180"></a>00180         currentDepth++;
<a name="l00181"></a>00181         <span class="keywordflow">if</span>( !lazy ) {
<a name="l00182"></a>00182                 table = <span class="keyword">new</span> CSymtabEntry&lt;T1&gt;( currentDepth, table );
<a name="l00183"></a>00183         }
<a name="l00184"></a>00184 }
<a name="l00189"></a>00189 <a class="code" href="glue_8h.html#0cb58e7e6f0bad369840a52e54a56ae0" title="Short cut for signed 32 bit integer.">INT32</a>   <a class="code" href="classCSymtab.html#5255cc93f48dc29985e69425db24c798" title="Get current symbol table nesting depth.">GetDepth</a>() { <span class="keywordflow">return</span> currentDepth; }
<a name="l00190"></a>00190 
<a name="l00197"></a>00197 <span class="keywordtype">void</span>    <a class="code" href="classCSymtab.html#dc05d90930af6c7576fc00193a90a313" title="Add a symbol and it&amp;#39;s assocated object at the current level.">Add</a>( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* sym, T1* obj )
<a name="l00198"></a>00198 {
<a name="l00199"></a>00199         <span class="keywordflow">if</span>( table-&gt;GetDepth() &lt; currentDepth ) {
<a name="l00200"></a>00200                 table = <span class="keyword">new</span> CSymtabEntry&lt;T1&gt;( currentDepth, table );
<a name="l00201"></a>00201         }
<a name="l00202"></a>00202 
<a name="l00203"></a>00203         (*table)[sym] = obj;
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205                 
<a name="l00212"></a>00212 T1*     <a class="code" href="classCSymtab.html#a01df1c918f304f970ea4f79415d072a" title="Lookup symbol only in current scope.">LookupTop</a>( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* sym )
<a name="l00213"></a>00213 {
<a name="l00214"></a>00214         <span class="keywordflow">if</span>( currentDepth != table-&gt;GetDepth() ) {
<a name="l00215"></a>00215                 <span class="keywordflow">return</span> NULL;
<a name="l00216"></a>00216         }
<a name="l00217"></a>00217         <span class="keywordflow">return</span> table-&gt;LookupTop( sym );
<a name="l00218"></a>00218 }
<a name="l00219"></a>00219                 
<a name="l00226"></a>00226 T1*     <a class="code" href="classCSymtab.html#bd368272c0a967bde6840a8c1fe693cf" title="Lookup symbol in all scopes starting at the current scope.">Lookup</a>( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* sym )
<a name="l00227"></a>00227 {
<a name="l00228"></a>00228         <span class="keywordflow">return</span> table-&gt;Lookup( sym );
<a name="l00229"></a>00229 }
<a name="l00230"></a>00230                 
<a name="l00236"></a>00236 <span class="keywordtype">void</span>    <a class="code" href="classCSymtab.html#c3db6c89c96d9e5e9dec4200fa942892" title="Dump all symbols in table to file descriptor.">Dump</a>( FILE *f, <span class="keywordtype">int</span> recurse ) 
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238         table-&gt;Dump( f, recurse );
<a name="l00239"></a>00239 }
<a name="l00240"></a>00240 
<a name="l00241"></a>00241 };
<a name="l00242"></a>00242 
<a name="l00243"></a>00243 <span class="preprocessor">#endif // CSYMTAB_HPP</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Wed Oct 21 18:05:36 2009 for vrq by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.5 </small></address>
</body>
</html>