Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

walker.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 //  C-Breeze
00004 //  C Compiler Framework
00005 // 
00006 //  Copyright (c) 2000 University of Texas at Austin
00007 // 
00008 //  Samuel Z. Guyer
00009 //  Daniel A. Jimenez
00010 //  Calvin Lin
00011 // 
00012 //  Permission is hereby granted, free of charge, to any person
00013 //  obtaining a copy of this software and associated documentation
00014 //  files (the "Software"), to deal in the Software without
00015 //  restriction, including without limitation the rights to use, copy,
00016 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00017 //  of the Software, and to permit persons to whom the Software is
00018 //  furnished to do so, subject to the following conditions:
00019 //  
00020 //  The above copyright notice and this permission notice shall be
00021 //  included in all copies or substantial portions of the Software.
00022 //  
00023 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00026 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00027 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00028 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00029 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00030 //  THE SOFTWARE.
00031 //
00032 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00033 //  Computer Science for inspiring parts of the C-Breeze design.
00034 //
00035 // ----------------------------------------------------------------------
00036 
00037 #ifndef CBZ_WALKER_H
00038 #define CBZ_WALKER_H
00039 
00141 class Walker {
00142 
00143 public:
00144 
00146   typedef enum {
00147     Preorder,     
00148     Postorder,    
00149     Both          
00151   } Order;
00152 
00154   typedef enum {
00155     Subtree,     
00156     NodeOnly     
00157   } Depth;
00158 
00159 private:
00160 
00162   Order _order;
00163 
00165   Depth _depth;
00166 
00167 
00168 public:
00169 
00186   Walker(Order the_order, Depth depth)
00187     : _order(the_order),
00188       _depth(depth)
00189   {}
00190 
00195 
00202   inline Order order() const { return _order; }
00203 
00210   inline Depth depth() const { return _depth; }
00211 
00213 
00221 
00222   virtual void at_node(Node * the_node, Order ord)
00223      { // Default: do nothing
00224      }
00225 
00226   virtual void at_unit(unitNode * the_unit, Order ord)
00227      { at_node(the_unit, ord); }
00228 
00229   virtual void at_def(defNode * the_def, Order ord)
00230      { at_node(the_def, ord); }
00231 
00232   virtual void at_decl(declNode * the_decl, Order ord)
00233      { at_def(the_decl, ord); }
00234 
00235   virtual void at_subdecl(subdeclNode * the_subdecl, Order ord)
00236      { at_decl(the_subdecl, ord); }
00237 
00238   virtual void at_proc(procNode * the_proc, Order ord)
00239      { at_def(the_proc, ord); }
00240 
00241   virtual void at_type(typeNode * the_type, Order ord)
00242      { at_node(the_type, ord); }
00243 
00244   virtual void at_prim(primNode * the_prim, Order ord)
00245      { at_type(the_prim, ord); }
00246 
00247   virtual void at_tdef(tdefNode * the_tdef, Order ord)
00248      { at_type(the_tdef, ord); }
00249 
00250   virtual void at_ptr(ptrNode * the_ptr, Order ord)
00251      { at_type(the_ptr, ord); }
00252 
00253   virtual void at_array(arrayNode * the_array, Order ord)
00254      { at_type(the_array, ord); }
00255 
00256   virtual void at_func(funcNode * the_func, Order ord)
00257      { at_type(the_func, ord); }
00258 
00259   virtual void at_sue(sueNode * the_sue, Order ord)
00260      { at_type(the_sue, ord); }
00261 
00262   virtual void at_struct(structNode * the_struct, Order ord)
00263      { at_sue(the_struct, ord); }
00264 
00265   virtual void at_union(unionNode * the_union, Order ord)
00266      { at_sue(the_union, ord); }
00267 
00268   virtual void at_enum(enumNode * the_enum, Order ord)
00269      { at_sue(the_enum, ord); }
00270 
00271   virtual void at_suespec(suespecNode * the_suespec, Order ord)
00272      { at_type(the_suespec, ord); }
00273 
00274   virtual void at_expr(exprNode * the_expr, Order ord)
00275      { at_node(the_expr, ord); }
00276 
00277   virtual void at_const(constNode * the_const, Order ord)
00278      { at_expr(the_const, ord); }
00279 
00280   virtual void at_id(idNode * the_id, Order ord)
00281      { at_expr(the_id, ord); }
00282 
00283   virtual void at_binary(binaryNode * the_binary, Order ord)
00284      { at_expr(the_binary, ord); }
00285 
00286   virtual void at_unary(unaryNode * the_unary, Order ord)
00287      { at_expr(the_unary, ord); }
00288 
00289   virtual void at_cast(castNode * the_cast, Order ord)
00290      { at_expr(the_cast, ord); }
00291 
00292   virtual void at_comma(commaNode * the_comma, Order ord)
00293      { at_expr(the_comma, ord); }
00294 
00295   virtual void at_ternary(ternaryNode * the_ternary, Order ord)
00296      { at_expr(the_ternary, ord); }
00297 
00298   virtual void at_call(callNode * the_call, Order ord)
00299      { at_expr(the_call, ord); }
00300 
00301   virtual void at_initializer(initializerNode * the_initializer, Order ord)
00302      { at_expr(the_initializer, ord); }
00303 
00304   virtual void at_stmt(stmtNode * the_stmt, Order ord)
00305      { at_node(the_stmt, ord); }
00306 
00307   virtual void at_block(blockNode * the_block, Order ord)
00308      { at_stmt(the_block, ord); }
00309 
00310   virtual void at_basicblock(basicblockNode * the_basicblock, Order ord)
00311      { at_block(the_basicblock, ord); }
00312 
00313   virtual void at_exprstmt(exprstmtNode * the_exprstmt, Order ord)
00314      { at_stmt(the_exprstmt, ord); }
00315 
00316   virtual void at_target(targetNode * the_target, Order ord)
00317      { at_stmt(the_target, ord); }
00318 
00319   virtual void at_label(labelNode * the_label, Order ord)
00320      { at_target(the_label, ord); }
00321 
00322   virtual void at_case(caseNode * the_case, Order ord)
00323      { at_target(the_case, ord); }
00324 
00325   virtual void at_selection(selectionNode * the_selection, Order ord)
00326      { at_stmt(the_selection, ord); }
00327 
00328   virtual void at_if(ifNode * the_if, Order ord)
00329      { at_selection(the_if, ord); }
00330 
00331   virtual void at_switch(switchNode * the_switch, Order ord)
00332      { at_selection(the_switch, ord); }
00333 
00334   virtual void at_loop(loopNode * the_loop, Order ord)
00335      { at_stmt(the_loop, ord); }
00336 
00337   virtual void at_while(whileNode * the_while, Order ord)
00338      { at_loop(the_while, ord); }
00339 
00340   virtual void at_do(doNode * the_do, Order ord)
00341      { at_loop(the_do, ord); }
00342 
00343   virtual void at_for(forNode * the_for, Order ord)
00344      { at_loop(the_for, ord); }
00345 
00346   virtual void at_jump(jumpNode * the_jump, Order ord)
00347      { at_stmt(the_jump, ord); }
00348 
00349   virtual void at_goto(gotoNode * the_goto, Order ord)
00350      { at_jump(the_goto, ord); }
00351 
00352   virtual void at_continue(continueNode * the_continue, Order ord)
00353      { at_jump(the_continue, ord); }
00354 
00355   virtual void at_break(breakNode * the_break, Order ord)
00356      { at_jump(the_break, ord); }
00357 
00358   virtual void at_return(returnNode * the_return, Order ord)
00359      { at_jump(the_return, ord); }
00360 
00361   virtual void at_attrib(attribNode * the_attrib, Order ord)
00362      { at_stmt(the_attrib, ord); }
00363 
00364   virtual void at_text(textNode * the_text, Order ord)
00365      { at_node(the_text, ord); }
00366 
00368 
00369 private:
00370 
00371   /* -- Deprecated...
00372 
00373   virtual void at_index(indexNode * the_index, Order ord)
00374      { at_expr(the_index, ord); }
00375 
00376   virtual void at_implicitcast(implicitcastNode * the_implicitcast, Order ord)
00377      { at_expr(the_implicitcast, ord); }
00378 
00379   virtual void at_default(defaultNode * the_default, Order ord)
00380      { at_target(the_default, ord); }
00381 
00382   virtual void at_ifelse(ifelseNode * the_ifelse, Order ord)
00383      { at_selection(the_ifelse, ord); }
00384 
00385   */
00386 };
00387 
00388 // -- Invoke the walker on a list...
00389 
00398 template< class T >
00399 void list_walker(list< T > & l, Walker & the_walker)
00400 {
00401   for (list< T >::iterator p = l.begin();
00402        p != l.end();
00403        ++p)
00404     (*p)->walk(the_walker);
00405 }
00406 
00407 
00408 #endif // CBZ_WALKER_H

Generated on Thu Jan 10 12:06:20 2002 for C-Breeze by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001