summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2019-12-16 17:07:45 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2019-12-16 17:07:45 +0000
commita326a3dedbff2c190418a28466946cac82295147 (patch)
tree2f36b10327c96cfd7e0dc65d5a6764117fa2d90c
parentbb03700c9b89f42b9e6bccccef8a74ce9b4fb91b (diff)
downloadgcc-a326a3dedbff2c190418a28466946cac82295147.tar.gz
Add pp_write_text_as_html_like_dot_to_stream
gcc/ChangeLog: * pretty-print.c (pp_write_text_as_html_like_dot_to_stream): New function. * pretty-print.h (pp_write_text_as_html_like_dot_to_stream): New decl. From-SVN: r279444
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/pretty-print.c48
-rw-r--r--gcc/pretty-print.h3
3 files changed, 57 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8fa7cc49c30..d25666380cd 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-16 David Malcolm <dmalcolm@redhat.com>
+
+ * pretty-print.c (pp_write_text_as_html_like_dot_to_stream): New
+ function.
+ * pretty-print.h (pp_write_text_as_html_like_dot_to_stream): New decl.
+
2019-12-16 Segher Boessenkool <segher@kernel.crashing.org>
* config/rs6000/rs6000.md (movsi_to_cr_one): Use CR0_REGNO instead of
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 084e03c73c7..2ecb0343ba0 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -907,6 +907,54 @@ pp_write_text_as_dot_label_to_stream (pretty_printer *pp, bool for_record)
pp_clear_output_area (pp);
}
+/* As pp_write_text_to_stream, but for GraphViz HTML-like strings.
+
+ Flush the formatted text of pretty-printer PP onto the attached stream,
+ escaping these characters
+ " & < >
+ using XML escape sequences.
+
+ http://www.graphviz.org/doc/info/lang.html#html states:
+ special XML escape sequences for ", &, <, and > may be necessary in
+ order to embed these characters in attribute values or raw text
+ This doesn't list "'" (which would normally be escaped in XML
+ as "&apos;" or in HTML as "&#39;");.
+
+ Experiments show that escaping "'" doesn't seem to be necessary. */
+
+void
+pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp)
+{
+ const char *text = pp_formatted_text (pp);
+ const char *p = text;
+ FILE *fp = pp_buffer (pp)->stream;
+
+ for (;*p; p++)
+ {
+ switch (*p)
+ {
+ case '"':
+ fputs ("&quot;", fp);
+ break;
+ case '&':
+ fputs ("&amp;", fp);
+ break;
+ case '<':
+ fputs ("&lt;", fp);
+ break;
+ case '>':
+ fputs ("&gt;",fp);
+ break;
+
+ default:
+ fputc (*p, fp);
+ break;
+ }
+ }
+
+ 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)
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index 493507d4141..86b9e869eeb 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -393,8 +393,11 @@ extern void pp_indent (pretty_printer *);
extern void pp_newline (pretty_printer *);
extern void pp_character (pretty_printer *, int);
extern void pp_string (pretty_printer *, const char *);
+
extern void pp_write_text_to_stream (pretty_printer *);
extern void pp_write_text_as_dot_label_to_stream (pretty_printer *, bool);
+extern void pp_write_text_as_html_like_dot_to_stream (pretty_printer *pp);
+
extern void pp_maybe_space (pretty_printer *);
extern void pp_begin_quote (pretty_printer *, bool);