00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef CBZ_WALKER_H
00038 #define CBZ_WALKER_H
00039
00141 class Walker {
00142
00143 public:
00144
00146 typedef enum {
00147 Preorder,
00148 Postorder,
00149 Both
00151 } Order;
00152
00154 typedef enum {
00155 Subtree,
00156 NodeOnly
00157 } Depth;
00158
00159 private:
00160
00162 Order _order;
00163
00165 Depth _depth;
00166
00167
00168 public:
00169
00186 Walker(Order the_order, Depth depth)
00187 : _order(the_order),
00188 _depth(depth)
00189 {}
00190
00195
00202 inline Order order() const { return _order; }
00203
00210 inline Depth depth() const { return _depth; }
00211
00213
00221
00222 virtual void at_node(Node * the_node, Order ord)
00223 {
00224 }
00225
00226 virtual void at_unit(unitNode * the_unit, Order ord)
00227 { at_node(the_unit, ord); }
00228
00229 virtual void at_def(defNode * the_def, Order ord)
00230 { at_node(the_def, ord); }
00231
00232 virtual void at_decl(declNode * the_decl, Order ord)
00233 { at_def(the_decl, ord); }
00234
00235 virtual void at_subdecl(subdeclNode * the_subdecl, Order ord)
00236 { at_decl(the_subdecl, ord); }
00237
00238 virtual void at_proc(procNode * the_proc, Order ord)
00239 { at_def(the_proc, ord); }
00240
00241 virtual void at_type(typeNode * the_type, Order ord)
00242 { at_node(the_type, ord); }
00243
00244 virtual void at_prim(primNode * the_prim, Order ord)
00245 { at_type(the_prim, ord); }
00246
00247 virtual void at_tdef(tdefNode * the_tdef, Order ord)
00248 { at_type(the_tdef, ord); }
00249
00250 virtual void at_ptr(ptrNode * the_ptr, Order ord)
00251 { at_type(the_ptr, ord); }
00252
00253 virtual void at_array(arrayNode * the_array, Order ord)
00254 { at_type(the_array, ord); }
00255
00256 virtual void at_func(funcNode * the_func, Order ord)
00257 { at_type(the_func, ord); }
00258
00259 virtual void at_sue(sueNode * the_sue, Order ord)
00260 { at_type(the_sue, ord); }
00261
00262 virtual void at_struct(structNode * the_struct, Order ord)
00263 { at_sue(the_struct, ord); }
00264
00265 virtual void at_union(unionNode * the_union, Order ord)
00266 { at_sue(the_union, ord); }
00267
00268 virtual void at_enum(enumNode * the_enum, Order ord)
00269 { at_sue(the_enum, ord); }
00270
00271 virtual void at_suespec(suespecNode * the_suespec, Order ord)
00272 { at_type(the_suespec, ord); }
00273
00274 virtual void at_expr(exprNode * the_expr, Order ord)
00275 { at_node(the_expr, ord); }
00276
00277 virtual void at_const(constNode * the_const, Order ord)
00278 { at_expr(the_const, ord); }
00279
00280 virtual void at_id(idNode * the_id, Order ord)
00281 { at_expr(the_id, ord); }
00282
00283 virtual void at_binary(binaryNode * the_binary, Order ord)
00284 { at_expr(the_binary, ord); }
00285
00286 virtual void at_unary(unaryNode * the_unary, Order ord)
00287 { at_expr(the_unary, ord); }
00288
00289 virtual void at_cast(castNode * the_cast, Order ord)
00290 { at_expr(the_cast, ord); }
00291
00292 virtual void at_comma(commaNode * the_comma, Order ord)
00293 { at_expr(the_comma, ord); }
00294
00295 virtual void at_ternary(ternaryNode * the_ternary, Order ord)
00296 { at_expr(the_ternary, ord); }
00297
00298 virtual void at_call(callNode * the_call, Order ord)
00299 { at_expr(the_call, ord); }
00300
00301 virtual void at_initializer(initializerNode * the_initializer, Order ord)
00302 { at_expr(the_initializer, ord); }
00303
00304 virtual void at_stmt(stmtNode * the_stmt, Order ord)
00305 { at_node(the_stmt, ord); }
00306
00307 virtual void at_block(blockNode * the_block, Order ord)
00308 { at_stmt(the_block, ord); }
00309
00310 virtual void at_basicblock(basicblockNode * the_basicblock, Order ord)
00311 { at_block(the_basicblock, ord); }
00312
00313 virtual void at_exprstmt(exprstmtNode * the_exprstmt, Order ord)
00314 { at_stmt(the_exprstmt, ord); }
00315
00316 virtual void at_target(targetNode * the_target, Order ord)
00317 { at_stmt(the_target, ord); }
00318
00319 virtual void at_label(labelNode * the_label, Order ord)
00320 { at_target(the_label, ord); }
00321
00322 virtual void at_case(caseNode * the_case, Order ord)
00323 { at_target(the_case, ord); }
00324
00325 virtual void at_selection(selectionNode * the_selection, Order ord)
00326 { at_stmt(the_selection, ord); }
00327
00328 virtual void at_if(ifNode * the_if, Order ord)
00329 { at_selection(the_if, ord); }
00330
00331 virtual void at_switch(switchNode * the_switch, Order ord)
00332 { at_selection(the_switch, ord); }
00333
00334 virtual void at_loop(loopNode * the_loop, Order ord)
00335 { at_stmt(the_loop, ord); }
00336
00337 virtual void at_while(whileNode * the_while, Order ord)
00338 { at_loop(the_while, ord); }
00339
00340 virtual void at_do(doNode * the_do, Order ord)
00341 { at_loop(the_do, ord); }
00342
00343 virtual void at_for(forNode * the_for, Order ord)
00344 { at_loop(the_for, ord); }
00345
00346 virtual void at_jump(jumpNode * the_jump, Order ord)
00347 { at_stmt(the_jump, ord); }
00348
00349 virtual void at_goto(gotoNode * the_goto, Order ord)
00350 { at_jump(the_goto, ord); }
00351
00352 virtual void at_continue(continueNode * the_continue, Order ord)
00353 { at_jump(the_continue, ord); }
00354
00355 virtual void at_break(breakNode * the_break, Order ord)
00356 { at_jump(the_break, ord); }
00357
00358 virtual void at_return(returnNode * the_return, Order ord)
00359 { at_jump(the_return, ord); }
00360
00361 virtual void at_attrib(attribNode * the_attrib, Order ord)
00362 { at_stmt(the_attrib, ord); }
00363
00364 virtual void at_text(textNode * the_text, Order ord)
00365 { at_node(the_text, ord); }
00366
00368
00369 private:
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 };
00387
00388
00389
00398 template< class T >
00399 void list_walker(list< T > & l, Walker & the_walker)
00400 {
00401 for (list< T >::iterator p = l.begin();
00402 p != l.end();
00403 ++p)
00404 (*p)->walk(the_walker);
00405 }
00406
00407
00408 #endif // CBZ_WALKER_H