C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ref_clone_changer.cc

Go to the documentation of this file.
00001 // $Id: ref_clone_changer.cc,v 1.9 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 #include "c_breeze.h"
00039 #include "ref_clone_changer.h"
00040 
00041 Node * ref_clone_changer::clone(Node * n, bool nil_bad_links)
00042 {
00043   if (!n)
00044     return n;
00045 
00046   ref_clone_changer rcc;
00047   Node * cl = n->change(rcc);
00048 
00049   ref_fix_walker rfw(rcc.map(), nil_bad_links);
00050   cl->walk(rfw);
00051 
00052   delete rcc.map();
00053 
00054   return cl;
00055 }
00056 
00057 Node * ref_fix_walker::lookup(Node * old)
00058 {
00059   if (! old)
00060     return 0;
00061 
00062   node_map_p p = _map->find(old);
00063   if (p == _map->end()) {
00064     if (_nil_bad_links)
00065       return 0;
00066     else
00067       return old;
00068   }
00069   else
00070     return (*p).second;
00071 }
00072 
00073 void ref_fix_walker::at_tdef(tdefNode * the_tdef, Order ord)
00074 {
00075   typeNode * t = (typeNode *) lookup(the_tdef->def());
00076   the_tdef->def(t); 
00077 }
00078 
00079 void ref_fix_walker::at_id(idNode * the_id, Order ord)
00080 {
00081   declNode * d = (declNode *) lookup(the_id->decl());
00082   the_id->decl(d);
00083 }
00084 
00085 void ref_fix_walker::at_call(callNode * the_call, Order ord)
00086 {
00087   procNode * p = (procNode *) lookup(the_call->proc());
00088   the_call->proc(p);
00089 }
00090 
00091 void ref_fix_walker::at_case(caseNode * the_case, Order ord)
00092 {
00093   switchNode * s = (switchNode *) lookup(the_case->container());
00094   the_case->container(s);
00095 }
00096 
00097 void ref_fix_walker::at_goto(gotoNode * the_goto, Order ord)
00098 {
00099   labelNode * target = (labelNode *) lookup(the_goto->label());
00100   the_goto->label(target);
00101 }
00102 
00103 void ref_fix_walker::at_continue(continueNode * the_continue, Order ord)
00104 {
00105   loopNode * l = (loopNode *) lookup(the_continue->container());
00106   the_continue->container(l);
00107 }
00108 
00109 void ref_fix_walker::at_break(breakNode * the_break, Order ord)
00110 {
00111   stmtNode * s = (stmtNode *) lookup(the_break->container());
00112   the_break->container(s);
00113 }
00114 
00115 void ref_fix_walker::at_return(returnNode * the_return, Order ord)
00116 {
00117   procNode * p = (procNode *) lookup(the_return->proc());
00118   the_return->proc(p);
00119 }
00120 
00121 void ref_fix_walker::at_proc(procNode * the_proc, Order ord)
00122 {
00123   labelNode * l = (labelNode *) lookup(the_proc->return_label());
00124   the_proc->return_label(l);
00125   declNode * d = (declNode *) lookup(the_proc->return_decl());
00126   the_proc->return_decl(d);
00127 }

Generated on August 27, 2003
Back to the C-Breeze home page