Change the public interface to debug functions.
authorMario de Sousa <msousa@fe.up.pt>
Tue, 13 Nov 2012 18:02:15 +0000
changeset 725 bfbe4aca6b77
parent 724 d19877568878
child 726 9b61eb4f00dc
Change the public interface to debug functions.
absyntax_utils/debug_ast.cc
absyntax_utils/debug_ast.hh
--- a/absyntax_utils/debug_ast.cc	Fri Nov 09 14:34:36 2012 +0000
+++ b/absyntax_utils/debug_ast.cc	Tue Nov 13 18:02:15 2012 +0000
@@ -44,14 +44,32 @@
 #include <unistd.h>
 #include <stdio.h>  /* required for NULL */
 #include "absyntax_utils.hh"
-
-
-
-
-
-
-
-
+#include "../absyntax/visitor.hh"
+
+
+
+
+
+
+/*********************************/
+/* Class to print a symbol       */
+/*********************************/
+
+
+class print_symbol_c: public fcall_visitor_c { 
+  public:
+    static void print(symbol_c *symbol);
+    
+  protected:
+    void fcall(symbol_c *symbol);  
+    /* AST symbols with extra data have their own specialised methods for printing that data */
+    void *visit(il_instruction_c *symbol);
+
+  private:
+    static print_symbol_c *singleton;
+    
+    void dump_symbol(symbol_c* symbol);
+};
 
 
 
@@ -70,9 +88,6 @@
 
 
 
-
-
-
 void print_symbol_c::fcall(symbol_c* symbol) {
   dump_symbol(symbol);
   fprintf(stderr, "\n");
@@ -137,10 +152,22 @@
 
 
 
-
-
-
-
+/*********************************/
+/* Class to print an AST         */
+/*********************************/
+
+class print_ast_c: public fcall_iterator_visitor_c { 
+  public:
+    static void print(symbol_c *symbol);
+    static void print(const char *str);
+    
+  protected:
+    void prefix_fcall(symbol_c *symbol);
+    void suffix_fcall(symbol_c *symbol);  
+  
+  private:
+    static print_ast_c *singleton;    
+};
 
 
 
@@ -155,6 +182,11 @@
   symbol->accept(*singleton);
 }
 
+
+void print_ast_c::print(const char *str) {
+  fprintf(stderr, str);
+}
+
   
 void print_ast_c::prefix_fcall(symbol_c* symbol) {print_symbol_c::print(symbol);}
 void print_ast_c::suffix_fcall(symbol_c* symbol) {}
@@ -163,14 +195,26 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
+/*********************************/
+/* The DEBUG class               */
+/*********************************/
+
+
+
+
+void debug_c::print(const char *str) {
+  fprintf(stderr, str);
+}
+
+void debug_c::print(symbol_c *symbol) {
+  print_symbol_c::print(symbol);
+}
+
+void debug_c::print_ast(symbol_c *symbol) {
+  print_ast_c::print(symbol);
+}
+
+
+
+
+
--- a/absyntax_utils/debug_ast.hh	Fri Nov 09 14:34:36 2012 +0000
+++ b/absyntax_utils/debug_ast.hh	Tue Nov 13 18:02:15 2012 +0000
@@ -41,40 +41,16 @@
 
 
 
-#include "../absyntax/visitor.hh"
+#include "../absyntax/absyntax.hh"
 
 
-
-class print_symbol_c: public fcall_visitor_c { 
+class debug_c { 
   public:
     static void print(symbol_c *symbol);
-    
-  protected:
-    void fcall(symbol_c *symbol);  
-    /* AST symbols with extra data have their own specialised methods for printing that data */
-    void *visit(il_instruction_c *symbol);
+    static void print(const char *str);
 
-  private:
-    static print_symbol_c *singleton;
-    
-    void dump_symbol(symbol_c* symbol);
-};
-
-
-
-
-
-
-class print_ast_c: public fcall_iterator_visitor_c { 
-  public:
-    static void print(symbol_c *symbol);
-    
-  protected:
-  void prefix_fcall(symbol_c *symbol);
-  void suffix_fcall(symbol_c *symbol);  
-  
-  private:
-    static print_ast_c *singleton;    
+    /* print the AST from this point downwards */
+    static void print_ast(symbol_c *root_symbol);
 };
 
 
@@ -92,3 +68,5 @@
 
 
 
+
+