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

changer.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_CHANGER_H
00038 #define CBZ_CHANGER_H
00039 
00142 class Changer {
00143 
00144 public:
00145 
00146   typedef enum { Preorder, Postorder, Both } Order;
00147   typedef enum { Subtree, NodeOnly } Depth;
00148 
00149 private:
00150 
00153   Order _order;
00154 
00157   Depth _depth;
00158 
00161   bool _delete_old;
00162 
00163 public:
00164 
00178   Changer(Order the_order, Depth depth, bool delete_old)
00179     : _order(the_order),
00180       _depth(depth),
00181       _delete_old(delete_old)
00182   {}
00187 
00188 
00195   inline Order order() const { return _order; }
00196 
00203   inline Depth depth() const { return _depth; }
00204 
00208   inline bool delete_old() const { return _delete_old; }
00209 
00211 
00219 
00220 
00221 
00222   virtual Node * at_node(Node * the_node, Order ord)
00223      { return the_node; }
00224 
00225   virtual Node * at_unit(unitNode * the_unit, Order ord)
00226      { return at_node(the_unit, ord); }
00227 
00228   virtual Node * at_def(defNode * the_def, Order ord)
00229      { return at_node(the_def, ord); }
00230 
00231   virtual Node * at_decl(declNode * the_decl, Order ord)
00232      { return at_def(the_decl, ord); }
00233 
00234   virtual Node * at_subdecl(subdeclNode * the_subdecl, Order ord)
00235      { return at_decl(the_subdecl, ord); }
00236 
00237   virtual Node * at_proc(procNode * the_proc, Order ord)
00238      { return at_def(the_proc, ord); }
00239 
00240   virtual Node * at_type(typeNode * the_type, Order ord)
00241      { return at_node(the_type, ord); }
00242 
00243   virtual Node * at_prim(primNode * the_prim, Order ord)
00244      { return at_type(the_prim, ord); }
00245 
00246   virtual Node * at_tdef(tdefNode * the_tdef, Order ord)
00247      { return at_type(the_tdef, ord); }
00248 
00249   virtual Node * at_ptr(ptrNode * the_ptr, Order ord)
00250      { return at_type(the_ptr, ord); }
00251 
00252   virtual Node * at_array(arrayNode * the_array, Order ord)
00253      { return at_type(the_array, ord); }
00254 
00255   virtual Node * at_func(funcNode * the_func, Order ord)
00256      { return at_type(the_func, ord); }
00257 
00258   virtual Node * at_sue(sueNode * the_sue, Order ord)
00259      { return at_type(the_sue, ord); }
00260 
00261   virtual Node * at_struct(structNode * the_struct, Order ord)
00262      { return at_sue(the_struct, ord); }
00263 
00264   virtual Node * at_union(unionNode * the_union, Order ord)
00265      { return at_sue(the_union, ord); }
00266 
00267   virtual Node * at_enum(enumNode * the_enum, Order ord)
00268      { return at_sue(the_enum, ord); }
00269 
00270   virtual Node * at_suespec(suespecNode * the_suespec, Order ord)
00271      { return at_type(the_suespec, ord); }
00272 
00273   virtual Node * at_expr(exprNode * the_expr, Order ord)
00274      { return at_node(the_expr, ord); }
00275 
00276   virtual Node * at_const(constNode * the_const, Order ord)
00277      { return at_expr(the_const, ord); }
00278 
00279   virtual Node * at_id(idNode * the_id, Order ord)
00280      { return at_expr(the_id, ord); }
00281 
00282   virtual Node * at_binary(binaryNode * the_binary, Order ord)
00283      { return at_expr(the_binary, ord); }
00284 
00285   virtual Node * at_unary(unaryNode * the_unary, Order ord)
00286      { return at_expr(the_unary, ord); }
00287 
00288   virtual Node * at_cast(castNode * the_cast, Order ord)
00289      { return at_expr(the_cast, ord); }
00290 
00291   virtual Node * at_comma(commaNode * the_comma, Order ord)
00292      { return at_expr(the_comma, ord); }
00293 
00294   virtual Node * at_ternary(ternaryNode * the_ternary, Order ord)
00295      { return at_expr(the_ternary, ord); }
00296 
00297   virtual Node * at_call(callNode * the_call, Order ord)
00298      { return at_expr(the_call, ord); }
00299 
00300   virtual Node * at_initializer(initializerNode * the_initializer, Order ord)
00301      { return at_expr(the_initializer, ord); }
00302 
00303   virtual Node * at_stmt(stmtNode * the_stmt, Order ord)
00304      { return at_node(the_stmt, ord); }
00305 
00306   virtual Node * at_block(blockNode * the_block, Order ord)
00307      { return at_stmt(the_block, ord); }
00308 
00309   virtual Node * at_basicblock(basicblockNode * the_basicblock, Order ord)
00310      { return at_block(the_basicblock, ord); }
00311 
00312   virtual Node * at_exprstmt(exprstmtNode * the_exprstmt, Order ord)
00313      { return at_stmt(the_exprstmt, ord); }
00314 
00315   virtual Node * at_target(targetNode * the_target, Order ord)
00316      { return at_stmt(the_target, ord); }
00317 
00318   virtual Node * at_label(labelNode * the_label, Order ord)
00319      { return at_target(the_label, ord); }
00320 
00321   virtual Node * at_case(caseNode * the_case, Order ord)
00322      { return at_target(the_case, ord); }
00323 
00324   virtual Node * at_selection(selectionNode * the_selection, Order ord)
00325      { return at_stmt(the_selection, ord); }
00326 
00327   virtual Node * at_if(ifNode * the_if, Order ord)
00328      { return at_selection(the_if, ord); }
00329 
00330   virtual Node * at_switch(switchNode * the_switch, Order ord)
00331      { return at_selection(the_switch, ord); }
00332 
00333   virtual Node * at_loop(loopNode * the_loop, Order ord)
00334      { return at_stmt(the_loop, ord); }
00335 
00336   virtual Node * at_while(whileNode * the_while, Order ord)
00337      { return at_loop(the_while, ord); }
00338 
00339   virtual Node * at_do(doNode * the_do, Order ord)
00340      { return at_loop(the_do, ord); }
00341 
00342   virtual Node * at_for(forNode * the_for, Order ord)
00343      { return at_loop(the_for, ord); }
00344 
00345   virtual Node * at_jump(jumpNode * the_jump, Order ord)
00346      { return at_stmt(the_jump, ord); }
00347 
00348   virtual Node * at_goto(gotoNode * the_goto, Order ord)
00349      { return at_jump(the_goto, ord); }
00350 
00351   virtual Node * at_continue(continueNode * the_continue, Order ord)
00352      { return at_jump(the_continue, ord); }
00353 
00354   virtual Node * at_break(breakNode * the_break, Order ord)
00355      { return at_jump(the_break, ord); }
00356 
00357   virtual Node * at_return(returnNode * the_return, Order ord)
00358      { return at_jump(the_return, ord); }
00359 
00360   virtual Node * at_attrib(attribNode * the_attrib, Order ord)
00361      { return at_stmt(the_attrib, ord); }
00362 
00363   virtual Node * at_text(textNode * the_text, Order ord)
00364      { return at_node(the_text, ord); }
00366 
00367 private:
00368 
00369   /* -- Deprecated...
00370 
00371   virtual Node * at_index(indexNode * the_index, Order ord)
00372      { return at_expr(the_index, ord); }
00373 
00374   virtual Node * at_implicitcast(implicitcastNode * the_implicitcast, Order ord)
00375      { return at_expr(the_implicitcast, ord); }
00376 
00377   virtual Node * at_default(defaultNode * the_default, Order ord)
00378      { return at_target(the_default, ord); }
00379 
00380   virtual Node * at_ifelse(ifelseNode * the_ifelse, Order ord)
00381      { return at_selection(the_ifelse, ord); }
00382 
00383   */
00384 
00385 };
00386 
00393 template< class T >
00394 void change_list(list< T > & l, Changer & the_changer)
00395 {
00396   for (list< T >::iterator p = l.begin();
00397        p != l.end(); ++p)
00398     {
00399       Node * n = (*p)->change(the_changer);
00400       if (n != (*p)) {
00401 
00402         if (the_changer.delete_old())
00403           delete (*p);
00404 
00405         if (n)
00406           (*p) = (T) n;
00407         else {
00408           list< T >::iterator q = p;
00409           l.erase(q);
00410         }
00411       }
00412     }
00413 }
00414 
00415 
00416 #endif // CBZ_CHANGER_H

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