C-Breeze
C Compiler Infrastructure

[ Project home page]

ref_clone_changer.h

Go to the documentation of this file.
00001 // $Id: ref_clone_changer.h,v 1.10 2003/08/07 23:13:50 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_REF_CLONE_CHANGER_H
00039 #define CBZ_REF_CLONE_CHANGER_H
00040 
00041 
00042 typedef map< Node *,
00043              Node *,
00044              less< Node * > > node_map;
00045 
00046 typedef node_map::iterator node_map_p;
00047 
00060 class ref_clone_changer : public Changer
00061 {
00062  public:
00063 
00081   static Node * clone(Node * n, bool nil_bad_links);
00082 
00083  private:
00084 
00085   node_map * map() const { return _map; }
00086 
00087   node_map * _map;
00088 
00089   ref_clone_changer()
00090     : Changer(Preorder, Subtree, false),
00091       _map(new node_map())
00092   {}
00093 
00094   virtual Node * at_node(Node * the_node, Order ord)
00095   {
00096     Node * newnode =  the_node->clone();
00097     (*_map)[the_node] = newnode;
00098     return newnode;
00099   }
00100 
00101   virtual Node * at_decl(declNode * the_decl, Order ord) {
00102     declNode * newnode = (declNode *) this->at_node(the_decl, ord);
00103     newnode->ref_list().clear();
00104     return newnode;
00105   }
00106 
00107   virtual Node * at_label(labelNode * the_label, Order ord) {
00108     labelNode * newnode = (labelNode *) this->at_node(the_label, ord);
00109     newnode->references().clear();
00110     return newnode;
00111   }
00112 
00113   virtual Node * at_switch(switchNode * the_switch, Order ord) {
00114     switchNode * newnode = (switchNode *) this->at_node(the_switch, ord);
00115     newnode->cases().clear();
00116     return newnode;
00117   }
00118 };
00119 
00120 class ref_fix_walker : public Walker
00121 {
00122 private:
00123 
00124   node_map * _map;
00125   bool _nil_bad_links;
00126 
00127   Node * lookup(Node * old);
00128 
00129 public:
00130 
00131   ref_fix_walker(node_map * m, bool nil_bad_links)
00132     : Walker(Preorder, Subtree),
00133       _map(m),
00134       _nil_bad_links(nil_bad_links)
00135   {}
00136 
00137   virtual void at_tdef(tdefNode * the_tdef, Order ord);
00138   virtual void at_id(idNode * the_id, Order ord);
00139   virtual void at_call(callNode * the_call, Order ord);
00140   virtual void at_case(caseNode * the_case, Order ord);
00141   virtual void at_goto(gotoNode * the_goto, Order ord);
00142   virtual void at_continue(continueNode * the_continue, Order ord);
00143   virtual void at_break(breakNode * the_break, Order ord);
00144   virtual void at_return(returnNode * the_return, Order ord);
00145   virtual void at_proc(procNode * the_proc, Order ord);
00146 };
00147 
00148 
00149 #endif // CBZ_REF_CLONE_CHANGER_H

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