This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: fdump-ast-original and strg:
- From: Florian Krohm <florian at edamail dot fishkill dot ibm dot com>
- To: Guillaume <guillaume dot thouvenin at polymtl dot ca>, Joe Buck <jbuck at synopsys dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Fri, 30 Nov 2001 13:12:07 -0500
- Subject: Re: fdump-ast-original and strg:
- References: <Pine.LNX.4.33L2.0111301216140.1619-100000@leffetriple.localdomain>
I'm afraid, things are even a bit more complex.
Consider a string containing two characters, the first
of which contains the bit pattern 00001010. The second
character is '2'. If you want to recover the original
representation for that string you will have to use a
string concatenation e.g. "\12" "2" or "\x6" "2".
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.
Florian
On Friday 30 November 2001 12:54, Guillaume wrote:
> On Thu, 29 Nov 2001, Joe Buck wrote:
> > Guillaume Thouvenin writes:
> > ...
> >
> > > The problem is the following. If you have something like:
> > >
> > > -- part of a C code --
> > >
> > > fprintf(stderr, "error strg: toto");
> > >
> > > --
> > >
> > > The asg given by gcc gives the following line:
> > >
> > > @247 string_cst type: @268 strg: error strg: toto lngt: 5
> > >
> > > So, I add a very basic modification inside GCC (in c-dump.c) and now,
> > > it produces this line:
> > >
> > > @247 string_cst type: @268 strg: "error strg: toto" lngt:
> > > 5
> >
> > This seems reasonable, but does your patch do the whole job? What
> > happens if the string contains newlines, control characters, or '"'? It
> > would seem reasonable to make the output match the input (that is, output
> > \", \n, etc).
>
> No it doesn't do the whole job. If you have something like :
>
> fprintf (stderr, "Hello\nit's a \"test\"\n");
>
> It will produce :
>
> @54 string_cst type: @67 strg: "Hello
> it's a "test"
> " lngt: 21
>
> So, the good output should be
>
> @54 string_cst type: @67 strg: "Hello\nit's a \"test\"\n"
> lngt: 21
>
>
> Actually, strings with newlines, control characters and '"' are treated by
> my parser. The only modification that I done in GCC is in file c-dump.c:
>
> line 649:
> ---
> 648: case STRING_CST:
> 649: fprintf (di->stream, "strg: \"%-7s\" ", TREE_STRING_POINTER (t));
> ^^ ^^
> 650: dump_int (di, "lngt", TREE_STRING_LENGTH (t));
> 651: break;
>
> So, I can try to path GCC to make output match the input?
>
> Guillaume