This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fdump-ast-original and strg:


On Fri, 30 Nov 2001, Zack Weinberg wrote:

> > Note that you cannot write "\122" as that would specify
> > only a single character.
> > You could call this a pathological example, but I think
> > you want to come up with an algorithm that can handle
> > the general case.
>
> "\0122" will work fine.  (Or, in this case, "\n2" assuming ASCII.)

Yes it will produce "\n2"

>
> We already have code to emit strings safely, into the assembly output;
> you could just use that.

I will look to your code tonight. I put what I've done at the end of the
mail and I will modify it if I can find code to emit strings safely.

The function dump_string_cst() produced the following output:

@51     string_cst       type: @58     strg: "Hello\nit's a \t\"test\"\n" lngt: 22


for the following input:

  fprintf (stderr, "Hello\nit's a \t\"test\"\n");

Thanks to all of you for your help
Guillaume

-----------
diff -urN gcc-3.0.2-20011014/gcc/c-dump.c
gcc-3.0.2-20011014-mod/gcc/c-dump.c
--- gcc-3.0.2-20011014/gcc/c-dump.c     Tue Jun  5 03:46:58 2001
+++ gcc-3.0.2-20011014-mod/gcc/c-dump.c Fri Nov 30 16:25:48 2001
@@ -214,6 +214,49 @@
     di->column += 14;
 }

+void
+dump_string_cst (di, string)
+     dump_info_p di;
+     const char *string;
+{
+  int index;
+
+  fprintf (di->stream, "strg: \"");
+  for (index = 0; string[index] != '\0' ; index++)
+    {
+    switch (string[index])
+      {
+      case '\a':
+        fprintf (di->stream, "%c%c", '\\', 'a');
+       break;
+      case '\b':
+        fprintf (di->stream, "%c%c", '\\', 'b');
+       break;
+      case '\t':
+        fprintf (di->stream, "%c%c", '\\', 't');
+       break;
+      case '\n':
+        fprintf (di->stream, "%c%c", '\\', 'n');
+       break;
+      case '\v':
+        fprintf (di->stream, "%c%c", '\\', 'v');
+       break;
+      case '\f':
+        fprintf (di->stream, "%c%c", '\\', 'f');
+       break;
+      case '\r':
+        fprintf (di->stream, "%c%c", '\\', 'r');
+       break;
+      case '\"':
+        fprintf (di->stream, "%c%c", '\\', '\"');
+       break;
+      default :
+        fprintf (di->stream, "%c", string[index]);
+      }
+    }
+  fprintf (di->stream, "\"");
+}
+
 /* Dump the string field S.  */

 static void
@@ -646,7 +689,7 @@
       break;

     case STRING_CST:
-      fprintf (di->stream, "strg: %-7s ", TREE_STRING_POINTER (t));
+      dump_string_cst (di, TREE_STRING_POINTER(t));
       dump_int (di, "lngt", TREE_STRING_LENGTH (t));
       break;

diff -urN gcc-3.0.2-20011014/gcc/c-dump.h
gcc-3.0.2-20011014-mod/gcc/c-dump.h
--- gcc-3.0.2-20011014/gcc/c-dump.h     Tue Jun  5 03:46:58 2001
+++ gcc-3.0.2-20011014-mod/gcc/c-dump.h Fri Nov 30 16:23:12 2001
@@ -80,6 +80,8 @@
   PARAMS ((dump_info_p, const char *, int));
 extern void dump_string
   PARAMS ((dump_info_p, const char *));
+extern void dump_string_cst
+  PARAMS ((dump_info_p, const char *));
 extern void dump_stmt
   PARAMS ((dump_info_p, tree));
 extern void dump_next_stmt

--------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]