From 4c48e462417e473a162e9c47e683303989938fd0 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 7 Jul 2016 10:44:35 -0400
Subject: [PATCH 20/25] FIXME: WIP on unification part 2

---
 libcpp/charset.c | 162 +++----------------------------------------------------
 1 file changed, 7 insertions(+), 155 deletions(-)

diff --git a/libcpp/charset.c b/libcpp/charset.c
index 205025f..ad40860 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1545,6 +1545,7 @@ convert_escape_unified (cpp_reader *pfile, const uchar *from,
    the target, and to the execution character set.  Do not scan past
    LIMIT.  Write the converted value into TBUF.  Returns an advanced
    pointer.  Handles all relevant diagnostics.  */
+#if 0
 static const uchar *
 convert_escape (cpp_reader *pfile, const uchar *from, const uchar *limit,
 		struct _cpp_strbuf *tbuf, struct cset_converter cvt)
@@ -1561,6 +1562,7 @@ convert_escape_ranges (cpp_reader *pfile, const uchar *from, const uchar *limit,
   return convert_escape_unified (pfile, from, limit, NULL, dummy,
 				 loc_reader, &ranges);
 }
+#endif
 
 
 /* TYPE is a token type.  The return value is the conversion needed to
@@ -1722,91 +1724,8 @@ bool
 cpp_interpret_string (cpp_reader *pfile, const cpp_string *from, size_t count,
 		      cpp_string *to,  enum cpp_ttype type)
 {
-  struct _cpp_strbuf tbuf;
-  const uchar *p, *base, *limit;
-  size_t i;
-  struct cset_converter cvt = converter_for_type (pfile, type);
-
-  tbuf.asize = MAX (OUTBUF_BLOCK_SIZE, from->len);
-  tbuf.text = XNEWVEC (uchar, tbuf.asize);
-  tbuf.len = 0;
-  //tbuf.loc.init ();
-
-  for (i = 0; i < count; i++)
-    {
-      //cpp_string_location_reader loc_reader (&from[i].loc, pfile->line_table);
-      p = from[i].text;
-      if (*p == 'u')
-	{
-	  p++;
-	  //loc_reader.get_next ();
-	  if (*p == '8')
-	    {
-	      p++;
-	      //loc_reader.get_next ();
-	    }
-	}
-      else if (*p == 'L' || *p == 'U') p++;
-      if (*p == 'R')
-	{
-	  const uchar *prefix;
-
-	  /* Skip over 'R"'.  */
-	  p += 2;
-	  prefix = p;
-	  while (*p != '(')
-	    p++;
-	  p++;
-	  limit = from[i].text + from[i].len;
-	  if (limit >= p + (p - prefix) + 1)
-	    limit -= (p - prefix) + 1;
-
-	  /* Raw strings are all normal characters; these can be fed
-	     directly to convert_cset.  */
-	  if (!APPLY_CONVERSION (cvt, p, limit - p, &tbuf))//, &loc_reader, true))
-	    goto fail;
-
-	  continue;
-	}
-
-      /* Skip leading quote.  */
-      p++;
-      //loc_reader.get_next ();
-
-      limit = from[i].text + from[i].len - 1; /* Skip trailing quote.  */
-
-      for (;;)
-	{
-	  base = p;
-	  while (p < limit && *p != '\\')
-	    p++;
-	  if (p > base)
-	    {
-	      /* We have a run of normal characters; these can be fed
-		 directly to convert_cset.  */
-	      if (!APPLY_CONVERSION (cvt, base, p - base, &tbuf))//, &loc_reader,
-		//false))
-		goto fail;
-	    }
-	  if (p == limit)
-	    break;
-
-	  p = convert_escape (pfile, p + 1, limit, &tbuf, cvt);//, &loc_reader);
-	}
-    }
-  /* NUL-terminate the 'to' buffer and translate it to a cpp_string
-     structure.  */
-  emit_numeric_escape (pfile, 0, &tbuf, cvt);
-  tbuf.text = XRESIZEVEC (uchar, tbuf.text, tbuf.len);
-  to->text = tbuf.text;
-  to->len = tbuf.len;
-  //to->loc = tbuf.loc;
-  return true;
-
- fail:
-  cpp_errno (pfile, CPP_DL_ERROR, "converting to execution character set");
-  free (tbuf.text);
-  return false;
+  return cpp_interpret_string_unified (pfile, from, count, to, type,
+				       NULL, NULL);
 }
 
 /* FIXME.  */
@@ -1819,77 +1738,10 @@ cpp_interpret_string_ranges (cpp_reader *pfile, const cpp_string *from,
 {
   /* SOURCE_CHARSET "UTF-8" */
 #if HOST_CHARSET == HOST_CHARSET_ASCII
-  /* We assume UTF-8 to UTF-8 conversion.  */
-
-  const uchar *p, *base, *limit;
-  size_t i;
-
-  for (i = 0; i < count; i++)
-    {
-      cpp_string_location_reader *loc_reader = &loc_readers[i];
-      p = from[i].text;
-      if (*p == 'u')
-	{
-	  p++;
-	  if (loc_reader)
-	    loc_reader->get_next ();
-	  if (*p == '8')
-	    {
-	      p++;
-	      if (loc_reader)
-		loc_reader->get_next ();
-	    }
-	}
-      else if (*p == 'L' || *p == 'U') p++;
-      if (*p == 'R')
-	{
-	  const uchar *prefix;
-
-	  /* Skip over 'R"'.  */
-	  p += 2;
-	  prefix = p;
-	  while (*p != '(')
-	    p++;
-	  p++;
-	  limit = from[i].text + from[i].len;
-	  if (limit >= p + (p - prefix) + 1)
-	    limit -= (p - prefix) + 1;
 
-	  /* Raw strings are all normal characters; assume UTF-8 to UTF-8
-	     conversion, hence these can be all treated as one byte in the result
-	     per column.  */
-	  if (loc_reader)
-	    out->add_n_ranges (limit - p, *loc_reader);
-
-	  continue;
-	}
-
-      /* Skip leading quote.  */
-      p++;
-      if (loc_reader)
-	loc_reader->get_next ();
-
-      limit = from[i].text + from[i].len - 1; /* Skip trailing quote.  */
-
-      for (;;)
-	{
-	  base = p;
-	  while (p < limit && *p != '\\')
-	    p++;
-	  if (p > base)
-	    {
-	      /* We have a run of normal characters; these can be fed
-		 directly to convert_cset.  */
-	      if (loc_reader)
-		out->add_n_ranges (p - base, *loc_reader);
-	    }
-	  if (p == limit)
-	    break;
-
-	  p = convert_escape_ranges (pfile, p + 1, limit, loc_reader, *out);
-	}
-    }
-  return true;
+  /* We assume UTF-8 to UTF-8 conversion.  */
+  return cpp_interpret_string_unified (pfile, from, count, NULL, CPP_STRING,
+				       loc_readers, out);
 #else
   return false;
 #endif
-- 
1.8.5.3

