Debugging helper class: print value of tokens in debugging output.
authorMario de Sousa <msousa@fe.up.pt>
Mon, 03 Jul 2017 20:27:15 +0100
changeset 1052 f91488700835
parent 1051 e483512edbeb
child 1053 e94368340160
Debugging helper class: print value of tokens in debugging output.
absyntax_utils/debug_ast.cc
--- a/absyntax_utils/debug_ast.cc	Tue May 09 21:46:44 2017 +0100
+++ b/absyntax_utils/debug_ast.cc	Mon Jul 03 20:27:15 2017 +0100
@@ -120,13 +120,16 @@
 
 
 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());
-
-  fprintf(stderr, "  datatype=");
+  fprintf(stderr, "(%s->%03d:%03d..%03d:%03d) \t%s", symbol->first_file, symbol->first_line, symbol->first_column, symbol->last_line, symbol->last_column, symbol->absyntax_cname());
+
+  if ((NULL != symbol->token) && (NULL != symbol->token->value))
+    fprintf(stderr, "(%s)", symbol->token->value);
+
+  fprintf(stderr, "\t  datatype=");
   if (NULL == symbol->datatype)
     fprintf(stderr, "NULL\t\t");
   else {
-	  fprintf(stderr, "%s", symbol->datatype->absyntax_cname());
+    fprintf(stderr, "%s", symbol->datatype->absyntax_cname());
   }
   fprintf(stderr, "\t<-{");
   if (symbol->candidate_datatypes.size() == 0) {
@@ -153,26 +156,25 @@
    dump_symbol(symbol);
 
    /* NOTE: std::map.size() returns a size_type, whose type is dependent on compiler/platform. To be portable, we need to do an explicit type cast. */
+  fprintf(stderr, "  prev_il_=%lu ", (unsigned long int)symbol->prev_il_instruction.size());
+  if (symbol->prev_il_instruction.size() == 0)
+    fprintf(stderr, "(----)");
+  else if (symbol->prev_il_instruction[0]->datatype == NULL)
+    fprintf(stderr, "(NULL)");
+  else if (!get_datatype_info_c::is_type_valid(symbol->prev_il_instruction[0]->datatype))
+    fprintf(stderr, "(****)");
+  else
+    fprintf(stderr, "(    )");
+
   fprintf(stderr, "  next_il_=%lu ", (unsigned long int)symbol->next_il_instruction.size());
-  fprintf(stderr, "  prev_il_=%lu ", (unsigned long int)symbol->prev_il_instruction.size());
-  
-  if (symbol->prev_il_instruction.size() == 0)
-    fprintf(stderr, "(----,");
-  else if (symbol->prev_il_instruction[0]->datatype == NULL)
-    fprintf(stderr, "(NULL,");
-  else if (!get_datatype_info_c::is_type_valid(symbol->prev_il_instruction[0]->datatype))
-    fprintf(stderr, "(****,");
-  else
-    fprintf(stderr, "(    ,");
-  
   if (symbol->next_il_instruction.size() == 0)
-    fprintf(stderr, "----)");
+    fprintf(stderr, "(----)");
   else if (symbol->next_il_instruction[0]->datatype == NULL)
-    fprintf(stderr, "NULL)");
+    fprintf(stderr, "(NULL)");
   else if (!get_datatype_info_c::is_type_valid(symbol->next_il_instruction[0]->datatype))
-    fprintf(stderr, "****)");
+    fprintf(stderr, "(****)");
   else 
-    fprintf(stderr, "    )");
+    fprintf(stderr, "(    )");
   
   fprintf(stderr, "\n");