|
||
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
tree_visitor.hGo to the documentation of this file.00001 // $Id: tree_visitor.h,v 1.6 2003/08/07 23:13:57 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_TREE_VISITOR_H 00039 #define CBZ_TREE_VISITOR_H 00040 00041 00042 00043 template< class T > 00044 void visit_list(list< T > & l, Visitor * the_visitor) 00045 { 00046 for (typename list< T >::iterator p = l.begin(); 00047 p != l.end(); 00048 ++p) 00049 (*p)->visit(the_visitor); 00050 } 00051 00052 00053 class tree_visitor : public Visitor 00054 { 00055 00056 public: 00057 00058 virtual void at_unit(unitNode * the_unit) 00059 { 00060 visit_list(the_unit->defs(), this); 00061 } 00062 00063 virtual void at_decl(declNode * the_decl) 00064 { 00065 if (the_decl->type()) 00066 the_decl->type()->visit(this); 00067 00068 if (the_decl->init()) 00069 the_decl->init()->visit(this); 00070 00071 if (the_decl->bitsize()) 00072 the_decl->bitsize()->visit(this); 00073 00074 visit_list(the_decl->attribs(), this); 00075 } 00076 00077 virtual void at_proc(procNode * the_proc) 00078 { 00079 if (the_proc->decl()) 00080 the_proc->decl()->visit(this); 00081 00082 if (the_proc->body()) 00083 the_proc->body()->visit(this); 00084 } 00085 00086 virtual void at_prim(primNode * the_prim) 00087 {} 00088 00089 virtual void at_tdef(tdefNode * the_tdef) 00090 {} 00091 00092 virtual void at_ptr(ptrNode * the_ptr) 00093 { 00094 the_ptr->type()->visit(this); 00095 } 00096 00097 virtual void at_array(arrayNode * the_array) 00098 { 00099 if (the_array->type()) 00100 the_array->type()->visit(this); 00101 00102 if (the_array->dim()) 00103 the_array->dim()->visit(this); 00104 } 00105 00106 virtual void at_func(funcNode * the_func) 00107 { 00108 visit_list(the_func->args(), this); 00109 00110 if (the_func->returns()) 00111 the_func->returns()->visit(this); 00112 } 00113 00114 virtual void at_struct(structNode * the_struct) 00115 { 00116 if (the_struct->elaborated() && the_struct->spec()) 00117 the_struct->spec()->visit(this); 00118 } 00119 00120 virtual void at_union(unionNode * the_union) 00121 { 00122 if (the_union->elaborated() && the_union->spec()) 00123 the_union->spec()->visit(this); 00124 } 00125 00126 virtual void at_enum(enumNode * the_enum) 00127 { 00128 if (the_enum->elaborated() && the_enum->spec()) 00129 the_enum->spec()->visit(this); 00130 } 00131 00132 virtual void at_suespec(suespecNode * the_suespec) 00133 { 00134 visit_list(the_suespec->fields(), this); 00135 } 00136 00137 virtual void at_const(constNode * the_const) 00138 { 00139 if (the_const->type()) 00140 the_const->type()->visit(this); 00141 } 00142 00143 virtual void at_id(idNode * the_id) 00144 { 00145 if (the_id->type()) 00146 the_id->type()->visit(this); 00147 } 00148 00149 virtual void at_binary(binaryNode * the_binary) 00150 { 00151 if (the_binary->right()) 00152 the_binary->right()->visit(this); 00153 00154 if (the_binary->left()) 00155 the_binary->left()->visit(this); 00156 00157 if (the_binary->type()) 00158 the_binary->type()->visit(this); 00159 } 00160 00161 virtual void at_unary(unaryNode * the_unary) 00162 { 00163 if (the_unary->expr()) 00164 the_unary->expr()->visit(this); 00165 00166 if (the_unary->type()) 00167 the_unary->type()->visit(this); 00168 00169 if (the_unary->sizeof_type()) 00170 the_unary->sizeof_type()->visit(this); 00171 } 00172 00173 virtual void at_cast(castNode * the_cast) 00174 { 00175 if (the_cast->type()) 00176 the_cast->type()->visit(this); 00177 00178 if (the_cast->expr()) 00179 the_cast->expr()->visit(this); 00180 } 00181 00182 virtual void at_comma(commaNode * the_comma) 00183 { 00184 visit_list(the_comma->exprs(), this); 00185 00186 if (the_comma->type()) 00187 the_comma->type()->visit(this); 00188 } 00189 00190 virtual void at_ternary(ternaryNode * the_ternary) 00191 { 00192 if (the_ternary->cond()) 00193 the_ternary->cond()->visit(this); 00194 00195 if (the_ternary->true_br()) 00196 the_ternary->true_br()->visit(this); 00197 00198 if (the_ternary->false_br()) 00199 the_ternary->false_br()->visit(this); 00200 00201 if (the_ternary->type()) 00202 the_ternary->type()->visit(this); 00203 } 00204 00205 virtual void at_call(callNode * the_call) 00206 { 00207 if (the_call->name()) 00208 the_call->name()->visit(this); 00209 00210 visit_list(the_call->args(), this); 00211 00212 if (the_call->type()) 00213 the_call->type()->visit(this); 00214 } 00215 00216 virtual void at_initializer(initializerNode * the_initializer) 00217 { 00218 visit_list(the_initializer->exprs(), this); 00219 00220 if (the_initializer->type()) 00221 the_initializer->type()->visit(this); 00222 } 00223 00224 virtual void at_block(blockNode * the_block) 00225 { 00226 visit_list(the_block->decls(), this); 00227 visit_list(the_block->stmts(), this); 00228 00229 if (the_block->type()) 00230 the_block->type()->visit(this); 00231 } 00232 00233 virtual void at_exprstmt(exprstmtNode * the_exprstmt) 00234 { 00235 if (the_exprstmt->expr()) 00236 the_exprstmt->expr()->visit(this); 00237 } 00238 00239 virtual void at_label(labelNode * the_label) 00240 { 00241 if (the_label->stmt()) 00242 the_label->stmt()->visit(this); 00243 } 00244 00245 virtual void at_case(caseNode * the_case) 00246 { 00247 if (the_case->expr()) 00248 the_case->expr()->visit(this); 00249 00250 if (the_case->stmt()) 00251 the_case->stmt()->visit(this); 00252 } 00253 00254 virtual void at_if(ifNode * the_if) 00255 { 00256 if (the_if->expr()) 00257 the_if->expr()->visit(this); 00258 00259 if (the_if->true_br()) 00260 the_if->true_br()->visit(this); 00261 00262 if (the_if->false_br()) 00263 the_if->false_br()->visit(this); 00264 } 00265 00266 virtual void at_switch(switchNode * the_switch) 00267 { 00268 if (the_switch->expr()) 00269 the_switch->expr()->visit(this); 00270 00271 if (the_switch->stmt()) 00272 the_switch->stmt()->visit(this); 00273 } 00274 00275 virtual void at_while(whileNode * the_while) 00276 { 00277 if (the_while->cond()) 00278 the_while->cond()->visit(this); 00279 00280 if (the_while->body()) 00281 the_while->body()->visit(this); 00282 } 00283 00284 virtual void at_do(doNode * the_do) 00285 { 00286 if (the_do->body()) 00287 the_do->body()->visit(this); 00288 00289 if (the_do->cond()) 00290 the_do->cond()->visit(this); 00291 } 00292 00293 virtual void at_for(forNode * the_for) 00294 { 00295 if (the_for->init()) 00296 the_for->init()->visit(this); 00297 00298 if (the_for->cond()) 00299 the_for->cond()->visit(this); 00300 00301 if (the_for->next()) 00302 the_for->next()->visit(this); 00303 00304 if (the_for->body()) 00305 the_for->body()->visit(this); 00306 } 00307 00308 virtual void at_goto(gotoNode * the_goto) 00309 {} 00310 00311 virtual void at_continue(continueNode * the_continue) 00312 {} 00313 00314 virtual void at_break(breakNode * the_break) 00315 {} 00316 00317 virtual void at_return(returnNode * the_return) 00318 { 00319 if (the_return->expr()) 00320 the_return->expr()->visit(this); 00321 } 00322 00323 virtual void at_attrib(attribNode * the_attrib) 00324 { 00325 if (the_attrib->arg()) 00326 the_attrib->arg()->visit(this); 00327 } 00328 00329 virtual void at_text(textNode * the_text) 00330 {} 00331 }; 00332 00333 00334 #endif // CBZ_TREE_VISITOR_H |
Generated on February 1, 2006
Back to the C-Breeze home page