1 /*************************************************************************** 2 print_tree.hpp 3 Print an ANTLR abstract syntax tree in operator prefix form. 4 Used for debugging only. 5 ------------------- 6 begin : ? 7 copyright : ? (modified from ANTLR package) 8 email : ? 9 ***************************************************************************/ 10 11 12 #ifndef _PRINT_TREE_HPP_ 13 #define _PRINT_TREE_HPP_ 14 15 #include "typedefs.hpp" 16 #include "prognode.hpp" 17 18 #include <antlr/ASTRefCount.hpp> 19 #include <antlr/AST.hpp> 20 21 namespace antlr { 22 23 24 25 class print_tree { 26 private: 27 typedef enum { INDENT = 2 } bogus; 28 unsigned long indent_level; 29 30 private: 31 void pr_name( RefAST node ); 32 void pr_name( ProgNodeP node ); 33 void pr_indent(); 34 void pr_top( RefAST top ); 35 void pr_top( ProgNodeP top ); 36 void pr_open_angle(); 37 void pr_close_angle(bool first); 38 void pr_leaves( RefAST top ); 39 void pr_leaves( ProgNodeP top ); 40 is_nonleaf(RefAST node)41 bool is_nonleaf( RefAST node ) 42 { 43 bool rslt = (node->getFirstChild() != NULL); 44 return rslt; 45 } is_nonleaf(ProgNodeP node)46 bool is_nonleaf( ProgNodeP node ) 47 { 48 bool rslt = (node->getFirstChild() != NULL); 49 return rslt; 50 } 51 public: 52 void pr_tree( const RefAST top ); 53 void pr_tree( const ProgNodeP top ); 54 }; // print_tree 55 56 } // namespace 57 #endif 58