C-Breeze
C Compiler Infrastructure

[ Project home page]

visitor.h

Go to the documentation of this file.
00001 // $Id: visitor.h,v 1.9 2003/08/07 23:13:57 pnav Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 // 
00013 //  Permission is hereby granted, free of charge, to any person
00014 //  obtaining a copy of this software and associated documentation
00015 //  files (the "Software"), to deal in the Software without
00016 //  restriction, including without limitation the rights to use, copy,
00017 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00018 //  of the Software, and to permit persons to whom the Software is
00019 //  furnished to do so, subject to the following conditions:
00020 //  
00021 //  The above copyright notice and this permission notice shall be
00022 //  included in all copies or substantial portions of the Software.
00023 //  
00024 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00028 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00029 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00030 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 //  THE SOFTWARE.
00032 //
00033 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00034 //  Computer Science for inspiring parts of the C-Breeze design.
00035 //
00036 // ----------------------------------------------------------------------
00037 
00038 #ifndef CBZ_VISITOR_H
00039 #define CBZ_VISITOR_H
00040 
00041 
00093 class Visitor {
00094 
00095 private:
00096 
00097 public:
00098 
00101   Visitor()
00102   {}
00103 
00110 
00111   virtual void at_node(Node * the_node)
00112      { // Default: do nothing
00113      }
00114 
00115   virtual void at_unit(unitNode * the_unit)
00116      { at_node(the_unit); }
00117 
00118   virtual void at_def(defNode * the_def)
00119      { at_node(the_def); }
00120 
00121   virtual void at_decl(declNode * the_decl)
00122      { at_def(the_decl); }
00123 
00124   virtual void at_subdecl(subdeclNode * the_subdecl)
00125      { at_decl(the_subdecl); }
00126 
00127   virtual void at_proc(procNode * the_proc)
00128      { at_def(the_proc); }
00129 
00130   virtual void at_type(typeNode * the_type)
00131      { at_node(the_type); }
00132 
00133   virtual void at_prim(primNode * the_prim)
00134      { at_type(the_prim); }
00135 
00136   virtual void at_tdef(tdefNode * the_tdef)
00137      { at_type(the_tdef); }
00138 
00139   virtual void at_ptr(ptrNode * the_ptr)
00140      { at_type(the_ptr); }
00141 
00142   virtual void at_array(arrayNode * the_array)
00143      { at_type(the_array); }
00144 
00145   virtual void at_func(funcNode * the_func)
00146      { at_type(the_func); }
00147 
00148   virtual void at_sue(sueNode * the_sue)
00149      { at_type(the_sue); }
00150 
00151   virtual void at_struct(structNode * the_struct)
00152      { at_sue(the_struct); }
00153 
00154   virtual void at_union(unionNode * the_union)
00155      { at_sue(the_union); }
00156 
00157   virtual void at_enum(enumNode * the_enum)
00158      { at_sue(the_enum); }
00159 
00160   virtual void at_suespec(suespecNode * the_suespec)
00161      { at_type(the_suespec); }
00162 
00163   virtual void at_expr(exprNode * the_expr)
00164      { at_node(the_expr); }
00165 
00166   virtual void at_index(indexNode * the_index)
00167     { at_expr(the_index); }
00168 
00169   virtual void at_const(constNode * the_const)
00170      { at_index(the_const); }
00171 
00172   virtual void at_id(idNode * the_id)
00173      { at_index(the_id); }
00174 
00175   virtual void at_binary(binaryNode * the_binary)
00176      { at_expr(the_binary); }
00177 
00178   virtual void at_unary(unaryNode * the_unary)
00179      { at_expr(the_unary); }
00180 
00181   virtual void at_cast(castNode * the_cast)
00182      { at_expr(the_cast); }
00183 
00184   virtual void at_comma(commaNode * the_comma)
00185      { at_expr(the_comma); }
00186 
00187   virtual void at_ternary(ternaryNode * the_ternary)
00188      { at_expr(the_ternary); }
00189 
00190   virtual void at_call(callNode * the_call)
00191      { at_expr(the_call); }
00192 
00193   virtual void at_initializer(initializerNode * the_initializer)
00194      { at_expr(the_initializer); }
00195 
00196   virtual void at_stmt(stmtNode * the_stmt)
00197      { at_node(the_stmt); }
00198 
00199   virtual void at_block(blockNode * the_block)
00200      { at_stmt(the_block); }
00201 
00202   virtual void at_basicblock(basicblockNode * the_basicblock)
00203      { at_block(the_basicblock); }
00204 
00205   virtual void at_exprstmt(exprstmtNode * the_exprstmt)
00206      { at_stmt(the_exprstmt); }
00207 
00208   virtual void at_target(targetNode * the_target)
00209      { at_stmt(the_target); }
00210 
00211   virtual void at_label(labelNode * the_label)
00212      { at_target(the_label); }
00213 
00214   virtual void at_case(caseNode * the_case)
00215      { at_target(the_case); }
00216 
00217   virtual void at_selection(selectionNode * the_selection)
00218      { at_stmt(the_selection); }
00219 
00220   virtual void at_if(ifNode * the_if)
00221      { at_selection(the_if); }
00222 
00223   virtual void at_switch(switchNode * the_switch)
00224      { at_selection(the_switch); }
00225 
00226   virtual void at_loop(loopNode * the_loop)
00227      { at_stmt(the_loop); }
00228 
00229   virtual void at_while(whileNode * the_while)
00230      { at_loop(the_while); }
00231 
00232   virtual void at_do(doNode * the_do)
00233      { at_loop(the_do); }
00234 
00235   virtual void at_for(forNode * the_for)
00236      { at_loop(the_for); }
00237 
00238   virtual void at_jump(jumpNode * the_jump)
00239      { at_stmt(the_jump); }
00240 
00241   virtual void at_goto(gotoNode * the_goto)
00242      { at_jump(the_goto); }
00243 
00244   virtual void at_continue(continueNode * the_continue)
00245      { at_jump(the_continue); }
00246 
00247   virtual void at_break(breakNode * the_break)
00248      { at_jump(the_break); }
00249 
00250   virtual void at_return(returnNode * the_return)
00251      { at_jump(the_return); }
00252 
00253   virtual void at_attrib(attribNode * the_attrib)
00254      { at_stmt(the_attrib); }
00255 
00256   virtual void at_operand(operandNode * the_oper)
00257     { at_expr(the_oper); }
00258 
00259   virtual void at_conditiongoto(conditiongotoNode * the_condgoto)
00260     { at_goto(the_condgoto); }
00261 
00262   virtual void at_threeAddr(threeAddrNode * the_3addr)
00263     { at_stmt(the_3addr); }
00264 
00265   virtual void at_text(textNode * the_text)
00266      { at_node(the_text); }
00268 
00269 private:
00270 
00271   /* -- Deprecated...
00272 
00273   virtual void at_implicitcast(implicitcastNode * the_implicitcast)
00274      { at_expr(the_implicitcast); }
00275 
00276   virtual void at_default(defaultNode * the_default)
00277      { at_target(the_default); }
00278 
00279   virtual void at_ifelse(ifelseNode * the_ifelse)
00280      { at_selection(the_ifelse); }
00281   */
00282 
00283 };
00284 
00285 // -- Invoke the visitor on a list...
00286 
00295 template< class T >
00296 void list_visitor(list< T > & l, Visitor * the_visitor)
00297 {
00298   for (typename list< T >::iterator p = l.begin();
00299        p != l.end();
00300        ++p)
00301     (*p)->visit(the_visitor);
00302 }
00303 
00304 
00305 #endif // CBZ_VISITOR_H

Generated on February 1, 2006
Back to the C-Breeze home page