Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / pretty-print.c
index 8aa9978..4c45e51 100644 (file)
@@ -1,6 +1,5 @@
 /* Various declarations for language-independent pretty-print subroutines.
-   Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010
-   Free Software Foundation, Inc.
+   Copyright (C) 2003-2013 Free Software Foundation, Inc.
    Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net>
 
 This file is part of GCC.
@@ -99,6 +98,58 @@ pp_write_text_to_stream (pretty_printer *pp)
   pp_clear_output_area (pp);
 }
 
+/* As pp_write_text_to_stream, but for GraphViz label output.
+
+   Flush the formatted text of pretty-printer PP onto the attached stream.
+   Replace characters in PPF that have special meaning in a GraphViz .dot
+   file.
+   
+   This routine is not very fast, but it doesn't have to be as this is only
+   be used by routines dumping intermediate representations in graph form.  */
+
+void
+pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record)
+{
+  const char *text = pp_formatted_text (pp);
+  const char *p = text;
+  FILE *fp = pp->buffer->stream;
+
+  while (*p)
+    {
+      switch (*p)
+       {
+       /* Print newlines as a left-aligned newline.  */
+       case '\n':
+         fputs ("\\l\\\n", fp);
+         break;
+
+       /* A pipe is only special for record-shape nodes.  */
+       case '|':
+         if (for_record)
+           fputc ('\\', fp);
+         fputc (*p, fp);
+         break;
+
+       /* The following characters always have to be escaped
+          for use in labels.  */
+       case '{':
+       case '}':
+       case '<':
+       case '>':
+       case '"':
+       case ' ':
+         fputc ('\\', fp);
+         /* fall through */
+       default:
+         fputc (*p, fp);
+         break;
+       }
+      p++;
+    }
+
+  pp_clear_output_area (pp);
+}
+
 /* Wrap a text delimited by START and END into PRETTY-PRINTER.  */
 static void
 pp_wrap_text (pretty_printer *pp, const char *start, const char *end)
@@ -575,9 +626,7 @@ pp_base_flush (pretty_printer *pp)
 {
   pp_write_text_to_stream (pp);
   pp_clear_state (pp);
-  fputc ('\n', pp->buffer->stream);
   fflush (pp->buffer->stream);
-  pp_needs_newline (pp) = false;
 }
 
 /* Sets the number of maximum characters per line PRETTY-PRINTER can
@@ -759,6 +808,7 @@ void
 pp_base_newline (pretty_printer *pp)
 {
   obstack_1grow (pp->buffer->obstack, '\n');
+  pp_needs_newline (pp) = false;
   pp->buffer->line_length = 0;
 }