This is the mail archive of the gcc-patches@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: [gccgo] Support //line comments


On Sat, 11 Sep 2010 23:32:58 -0700
Ian Lance Taylor <iant@google.com> wrote:

> By convention, a Go comment of the form //line FILE:LINENO is the
> equivalent of a C #line comment.  This patch implements that for gccgo.
> Committed to gccgo branch.

I don't use Go yet (even if I liked reading its specification &
documentation) but, as someone who did wrote significant source code
generators (notably the GCC MELT branch and plugin see
http://gcc.gnu.org/wiki/MELT for more) I would suggest an advice.  

There are lots of code generators which generate several lines of
generated code per line of their input code. So it would help these to
be able to say that a given chunk of lines of code is orginated from
the same position.

So an hypothetical code generator would not have to generate
  //line "ab.cd":3
  x23 = 2 + z;
  //line "ab.cd":3
  x34 = 3 * y;
  //line "ab.cd":3
  y = x23 + x34;
  //line "ab.cd":3
  if (y < 0) y=0;
  //line "ab.cd":3
  if (z > x34) z=x34;
I assume above is correct Go syntax. 

If it is generated C it would be
  #line "ab.cd" 3
  x23 = 2 + z;
  #line "ab.cd" 3
  x32 = 3 * y;
  #line "ab.cd" 3
  y = x23 + x34;
  #line "ab.cd" 3
  if (y < 0) y = 0;
  #line "ab.cd" 3
  if (z > x34) z=x34;

I am suggesting to accept in Go two new magical
comments //startsamelines & //endsamelines and generate  
   //startsamelines "ab.cd":3
   x23 = 2 + z;
   x34 = 3 * y;
   y = x23 + x33;
   if (y < 0) y = 0;
   if (z > x34) z=x34;
   //endsamelines
this in addition of your //line proposal.

Within GCC, the suggestions could be to have pragmas
   #pragma GCC startsamelines "ab.cd":3
   x23 = 2 + z;
   x34 = 3 * y;
   y = x23 + x33;
   if (y < 0) y = 0;
   if (z > x34) z=x34;
   #pragma GCC endsamelines
   
And these chunks of code will have the same effect as the previous with
only //line for Go & #line for C. The proposed trick avoid the
generator to have to emit the same //line comment in Go or #line
directive in C for every line generated for the same source position.

Regards.
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***


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