Add debug_c::print(const_value_c) for printing of const values.
authormjsousa
Sun, 28 Dec 2014 12:05:39 +0000
changeset 979 f8f1d89ff7d5
parent 978 efab3a94d3c0
child 980 9ed5aff159db
Add debug_c::print(const_value_c) for printing of const values.
absyntax_utils/debug_ast.cc
absyntax_utils/debug_ast.hh
--- a/absyntax_utils/debug_ast.cc	Sun Dec 28 12:04:07 2014 +0000
+++ b/absyntax_utils/debug_ast.cc	Sun Dec 28 12:05:39 2014 +0000
@@ -49,6 +49,30 @@
 
 
 
+static void dump_cvalue(const_value_c const_value) {
+  fprintf(stderr, "constv{");
+  if      (const_value._real64.is_valid   ()) fprintf(stderr, "%f",        const_value._real64.get());
+  else if (const_value._real64.is_overflow()) fprintf(stderr, "ov");
+  else if (const_value._real64.is_nonconst()) fprintf(stderr, "nc");
+  else                                        fprintf(stderr, "?");
+  fprintf(stderr, ", i=");
+  if      (const_value. _int64.is_valid   ()) fprintf(stderr, "%"PRId64"", const_value. _int64.get());
+  else if (const_value. _int64.is_overflow()) fprintf(stderr, "ov");
+  else if (const_value. _int64.is_nonconst()) fprintf(stderr, "nc");
+  else                                        fprintf(stderr, "?");
+  fprintf(stderr, ", u=");
+  if      (const_value._uint64.is_valid   ()) fprintf(stderr, "%"PRIu64"", const_value._uint64.get());
+  else if (const_value._uint64.is_overflow()) fprintf(stderr, "ov");
+  else if (const_value._uint64.is_nonconst()) fprintf(stderr, "nc");
+  else                                        fprintf(stderr, "?");
+  fprintf(stderr, ", b=");
+  if      (const_value.  _bool.is_valid   ()) fprintf(stderr, "%d",        const_value.  _bool.get()?1:0);
+  else if (const_value.  _bool.is_overflow()) fprintf(stderr, "ov");
+  else if (const_value.  _bool.is_nonconst()) fprintf(stderr, "nc");
+  else                                        fprintf(stderr, "?");
+  fprintf(stderr, "}");
+}
+
 
 
 /*********************************/
@@ -94,6 +118,7 @@
 }
 
 
+
 void print_symbol_c::dump_symbol(symbol_c* symbol) {
   fprintf(stderr, "(%s->%03d:%03d..%03d:%03d) \t%s\t", symbol->first_file, symbol->first_line, symbol->first_column, symbol->last_line, symbol->last_column, symbol->absyntax_cname());
 
@@ -115,11 +140,11 @@
   } else {
     fprintf(stderr, "(%lu)\t\t\t\t\t", (unsigned long int)symbol->candidate_datatypes.size());
   }
-  fprintf(stderr, "}\t");         
+  fprintf(stderr, "}\t ");         
   
   /* print the const values... */
-  fprintf(stderr, " constv{f=%f, i=%"PRId64", u=%"PRIu64", b=%d}\t", symbol->const_value._real64.get(), symbol->const_value._int64.get(), symbol->const_value._uint64.get(), symbol->const_value._bool.get()?1:0);
-  
+  dump_cvalue(symbol->const_value);
+  fprintf(stderr, "\t");
 }
 
 
@@ -212,6 +237,10 @@
   fprintf(stderr, "%s", str);
 }
 
+void debug_c::print(const_value_c cvalue) {
+  dump_cvalue(cvalue);
+}
+
 void debug_c::print(symbol_c *symbol) {
   print_symbol_c::print(symbol);
 }
--- a/absyntax_utils/debug_ast.hh	Sun Dec 28 12:04:07 2014 +0000
+++ b/absyntax_utils/debug_ast.hh	Sun Dec 28 12:05:39 2014 +0000
@@ -46,8 +46,9 @@
 
 class debug_c { 
   public:
-    static void print(symbol_c *symbol);
-    static void print(const char *str);
+    static void print(const_value_c  cvalue);
+    static void print(symbol_c      *symbol);
+    static void print(const char    *str);
 
     /* print the AST from this point downwards */
     static void print_ast(symbol_c *root_symbol);