<!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.7.1 --> <div class="navigation" id="top"> <div class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related 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> <div class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <h1>/net/fileserver/nas/home/mdh/vrq/src/csymtab.h</h1> </div> </div> <div class="contents"> <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 <map></span> <a name="l00037"></a>00037 <span class="preprocessor">#include <algorithm></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><<span class="keyword">class</span> T1> <a name="l00049"></a>00049 <span class="keyword">class </span>CSymtabEntry : <span class="keyword">public</span> map<CSymbol*,T1*> <a name="l00050"></a>00050 { <a name="l00051"></a>00051 <span class="keyword">private</span>: <a name="l00052"></a>00052 CSymtabEntry* previous; <a name="l00053"></a>00053 <span class="keyword">public</span>: <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="comment">/*********************************************************</span> <a name="l00056"></a>00056 <span class="comment"> Constructor</span> <a name="l00057"></a>00057 <span class="comment">**********************************************************/</span> <a name="l00058"></a>00058 CSymtabEntry( CSymtabEntry* parent ) <a name="l00059"></a>00059 { <a name="l00060"></a>00060 previous = parent; <a name="l00061"></a>00061 } <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="comment">/*********************************************************</span> <a name="l00064"></a>00064 <span class="comment"> GetPrevious</span> <a name="l00065"></a>00065 <span class="comment"> - return previous level </span> <a name="l00066"></a>00066 <span class="comment">**********************************************************/</span> <a name="l00067"></a>00067 CSymtabEntry* GetPrevious() { <a name="l00068"></a>00068 <span class="keywordflow">return</span> previous; <a name="l00069"></a>00069 } <a name="l00070"></a>00070 <a name="l00071"></a>00071 <span class="comment">/*********************************************************</span> <a name="l00072"></a>00072 <span class="comment"> Lookup</span> <a name="l00073"></a>00073 <span class="comment"> - find symbol by recursively searching table </span> <a name="l00074"></a>00074 <span class="comment">**********************************************************/</span> <a name="l00075"></a>00075 <a name="l00076"></a>00076 T1* Lookup( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* key ) <a name="l00077"></a>00077 { <a name="l00078"></a>00078 T1* result; <a name="l00079"></a>00079 <span class="keyword">typename</span> map<CSymbol*,T1*>::iterator ptr; <a name="l00080"></a>00080 <a name="l00081"></a>00081 result = NULL; <a name="l00082"></a>00082 ptr = this->find( key ); <a name="l00083"></a>00083 <span class="keywordflow">if</span>( ptr != this->end() ) { <a name="l00084"></a>00084 <span class="keywordflow">return</span> ptr->second; <a name="l00085"></a>00085 } <a name="l00086"></a>00086 <span class="keywordflow">if</span>( previous ) { <a name="l00087"></a>00087 result = previous->Lookup( key ); <a name="l00088"></a>00088 } <a name="l00089"></a>00089 <span class="keywordflow">return</span> result; <a name="l00090"></a>00090 } <a name="l00091"></a>00091 <a name="l00092"></a>00092 <span class="comment">/*********************************************************</span> <a name="l00093"></a>00093 <span class="comment"> LookupTop</span> <a name="l00094"></a>00094 <span class="comment"> - find symbol at top level only </span> <a name="l00095"></a>00095 <span class="comment">**********************************************************/</span> <a name="l00096"></a>00096 <a name="l00097"></a>00097 T1* LookupTop( <a class="code" href="classCSymbol.html" title="Holder for character strings.">CSymbol</a>* key ) <a name="l00098"></a>00098 { <a name="l00099"></a>00099 T1* result; <a name="l00100"></a>00100 <span class="keyword">typename</span> map<CSymbol*,T1*>::iterator ptr; <a name="l00101"></a>00101 <a name="l00102"></a>00102 result = NULL; <a name="l00103"></a>00103 ptr = this->find( key ); <a name="l00104"></a>00104 <span class="keywordflow">if</span>( ptr != this->end() ) { <a name="l00105"></a>00105 result = ptr->second; <a name="l00106"></a>00106 } <a name="l00107"></a>00107 <span class="keywordflow">return</span> result; <a name="l00108"></a>00108 } <a name="l00109"></a>00109 <a name="l00110"></a>00110 <span class="keywordtype">void</span> Dump( FILE *f, <span class="keywordtype">int</span> recurse ) <a name="l00111"></a>00111 { <a name="l00112"></a>00112 <span class="keyword">typename</span> map<CSymbol*,T1*>::iterator ptr; <a name="l00113"></a>00113 <a name="l00114"></a>00114 <span class="keywordflow">for</span>( ptr = this->begin(); ptr != this->end(); ++ptr) { <a name="l00115"></a>00115 printf( <span class="stringliteral">"\t%s => "</span>, ptr->first->GetName() ); <a name="l00116"></a>00116 ptr->second->DumpDeclInfo( f ); <a name="l00117"></a>00117 } <a name="l00118"></a>00118 <span class="keywordflow">if</span>( recurse && previous != NULL ) { <a name="l00119"></a>00119 previous->Dump( f, recurse ); <a name="l00120"></a>00120 } <a name="l00121"></a>00121 } <a name="l00122"></a>00122 <a name="l00123"></a>00123 }; <a name="l00134"></a>00134 <span class="keyword">template</span><<span class="keyword">class</span> T1> <a name="l00135"></a><a class="code" href="classCSymtab.html">00135</a> <span class="keyword">class </span><a class="code" href="classCSymtab.html" title="Aux class used to create symbol table scoping.">CSymtab</a> <a name="l00136"></a>00136 { <a name="l00137"></a>00137 <span class="keyword">private</span>: <a name="l00138"></a>00138 CSymtabEntry<T1>* table; <a name="l00139"></a>00139 <span class="keyword">public</span>: <a name="l00140"></a>00140 <a name="l00144"></a><a class="code" href="classCSymtab.html#afdb92980563b3571f3497cc0f9d97f40">00144</a> <a class="code" href="classCSymtab.html#afdb92980563b3571f3497cc0f9d97f40" title="Create a symbol table.">CSymtab</a>() <a name="l00145"></a>00145 { <a name="l00146"></a>00146 table = <span class="keyword">new</span> CSymtabEntry<T1>( NULL ); <a name="l00147"></a>00147 } <a name="l00151"></a><a class="code" href="classCSymtab.html#a356d0c0f64fc4fa474728edee01afb48">00151</a> <span class="keywordtype">void</span> <a class="code" href="classCSymtab.html#a356d0c0f64fc4fa474728edee01afb48" title="Jump back to parent scope.">PopScope</a>() <a name="l00152"></a>00152 { <a name="l00153"></a>00153 MASSERT( table != NULL ); <a name="l00154"></a>00154 <a name="l00155"></a>00155 table = table->GetPrevious(); <a name="l00156"></a>00156 } <a name="l00160"></a><a class="code" href="classCSymtab.html#a11270ecff582507a26ddde378bf63de4">00160</a> <span class="keywordtype">void</span> <a class="code" href="classCSymtab.html#a11270ecff582507a26ddde378bf63de4" title="Create a new scope for table.">PushScope</a>() <a name="l00161"></a>00161 { <a name="l00162"></a>00162 table = <span class="keyword">new</span> CSymtabEntry<T1>( table ); <a name="l00163"></a>00163 } <a name="l00164"></a>00164 <a name="l00171"></a><a class="code" href="classCSymtab.html#adc05d90930af6c7576fc00193a90a313">00171</a> <span class="keywordtype">void</span> <a class="code" href="classCSymtab.html#adc05d90930af6c7576fc00193a90a313" title="Add a symbol and it&#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="l00172"></a>00172 { <a name="l00173"></a>00173 (*table)[sym] = obj; <a name="l00174"></a>00174 } <a name="l00175"></a>00175 <a name="l00182"></a><a class="code" href="classCSymtab.html#aa01df1c918f304f970ea4f79415d072a">00182</a> T1* <a class="code" href="classCSymtab.html#aa01df1c918f304f970ea4f79415d072a" 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="l00183"></a>00183 { <a name="l00184"></a>00184 <a name="l00185"></a>00185 <span class="keywordflow">return</span> table->LookupTop( sym ); <a name="l00186"></a>00186 } <a name="l00187"></a>00187 <a name="l00194"></a><a class="code" href="classCSymtab.html#abd368272c0a967bde6840a8c1fe693cf">00194</a> T1* <a class="code" href="classCSymtab.html#abd368272c0a967bde6840a8c1fe693cf" 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="l00195"></a>00195 { <a name="l00196"></a>00196 <span class="keywordflow">return</span> table->Lookup( sym ); <a name="l00197"></a>00197 } <a name="l00198"></a>00198 <a name="l00204"></a><a class="code" href="classCSymtab.html#ac3db6c89c96d9e5e9dec4200fa942892">00204</a> <span class="keywordtype">void</span> <a class="code" href="classCSymtab.html#ac3db6c89c96d9e5e9dec4200fa942892" title="Dump all symbols in table to file descriptor.">Dump</a>( FILE *f, <span class="keywordtype">int</span> recurse ) <a name="l00205"></a>00205 { <a name="l00206"></a>00206 table->Dump( f, recurse ); <a name="l00207"></a>00207 } <a name="l00208"></a>00208 <a name="l00209"></a>00209 }; <a name="l00210"></a>00210 <a name="l00211"></a>00211 <span class="preprocessor">#endif // CSYMTAB_HPP</span> </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.1 </small></address> </body> </html>