|
||
name_mangle_walker.ccGo to the documentation of this file.00001 // $Id: name_mangle_walker.cc,v 1.6 2003/08/07 23:13:49 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 /*Adapted from C-breeze version*/ 00039 00040 #include "name_mangle_walker.h" 00041 00042 00043 // ------------------------------------------------------------ 00044 // Entry point 00045 // ------------------------------------------------------------ 00046 00047 void name_mangle_walker::mangle() 00048 { 00049 00050 for(unit_list_p n= CBZ::Program.begin(); n!= CBZ::Program.end(); n++) 00051 name_mangle_walker::mangle(*n); 00052 00053 } 00054 00055 // ------------------------------------------------------------ 00056 // Entry point 00057 // ------------------------------------------------------------ 00058 00059 void name_mangle_walker::mangle(unitNode * u) 00060 { 00061 00062 name_mangle_walker nmw(u); 00063 fix_goto_walker fgw; 00064 00065 u->walk(nmw); 00066 00067 u->walk(fgw); 00068 00069 } 00070 00071 00072 00073 // ------------------------------------------------------------ 00074 // Handle entries into the symbol table 00075 // ------------------------------------------------------------ 00076 00077 void name_mangle_walker::at_proc(procNode * the_proc, Order ord) 00078 { 00079 if (ord == Preorder) { 00080 00081 // -- Put the formal parameters into the symbol table 00082 00083 enter_scope(); 00084 00085 funcNode * f = (funcNode *) the_proc->decl()->type(); 00086 decl_list & as = f->args(); 00087 00088 for (decl_list_p p = as.begin(); p != as.end(); ++p) { 00089 00090 if ((*p)->datatype()->is_ellipsis() || 00091 (*p)->datatype()->is_void()) 00092 ; 00093 else 00094 if (! (*p)->name().empty()) { 00095 00096 // -- Normal declaration... 00097 00098 declNode * a_decl = (declNode *) (*p); 00099 string newname = ids()->insert_unique(a_decl->name(), a_decl); 00100 if (newname != a_decl->name()) 00101 a_decl->name(newname); 00102 } 00103 } 00104 } 00105 00106 if (ord == Postorder) { 00107 00108 // -- Exit the scope 00109 00110 exit_scope(); 00111 00112 } 00113 00114 } 00115 00116 void name_mangle_walker::at_decl(declNode * the_decl, Order ord) 00117 { 00118 if (ord == Preorder) { 00119 00120 // -- Skip abstract declarators... 00121 00122 if (the_decl->name().empty()) 00123 return; 00124 00125 // -- Skip function declarations... 00126 00127 if ((the_decl->type()->typ() == Func) && 00128 ! in_formals()) 00129 return; 00130 00131 // -- Skip external declarations... 00132 00133 if ((the_decl->storage_class() == declNode::EXTERN) || 00134 (symbol_level() == 0)) 00135 return; 00136 00137 // -- Set decl_location and insert into the symbol table... 00138 00139 if (in_su()) 00140 return; 00141 else 00142 if (in_formals()) 00143 return; 00144 else { 00145 00146 // -- add to current scope 00147 string newname = ids()->insert_unique(the_decl->name(), the_decl); 00148 if (newname != the_decl->name()) 00149 the_decl->name(newname); 00150 } 00151 } 00152 } 00153 00154 void name_mangle_walker::at_label(labelNode * the_label, Order ord) 00155 { 00156 if (ord == Preorder) 00157 { 00158 // -- add to current scope 00159 string newname = labels()->insert_unique(the_label->name(), the_label); 00160 if (newname != the_label->name()) 00161 the_label->name(newname); 00162 } 00163 00164 } 00165 00166 00167 // ------------------------------------------------------------ 00168 // Fix identifier names 00169 // ------------------------------------------------------------ 00170 00171 void name_mangle_walker::at_id(idNode * the_id, Order ord) 00172 { 00173 declNode * d = the_id->decl(); 00174 if ((ord == Preorder) && 00175 d && 00176 (d->name() != the_id->name())) 00177 the_id->name(d->name()); 00178 } 00179 00180 // ------------------------------------------------------------ 00181 // Fix goto names 00182 // ------------------------------------------------------------ 00183 00184 void fix_goto_walker::at_goto(gotoNode * g, Order ord) 00185 { 00186 labelNode * lbl = g->label(); 00187 if ((ord == Preorder) && lbl && (lbl->name() != g->name())) 00188 g->name(lbl->name()); 00189 } 00190 00191 |
Generated on August 27, 2003
Back to the C-Breeze home page