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

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

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