[GCC-XML]Endline of a method

Iwan Birrer ibirrer at control.ee.ethz.ch
Thu Aug 7 10:19:18 EDT 2003


I looked at the .tu dump of gcc with the option '-fdump-translation-unit'
and there is a ending line given for a function. That known I looked at the
xml.c source and tried to print the endline as well to the xml file. After a
couple of hours ( ... ) I finally got the solution. I added this to the
'xml_output_function_decl' function:

tree body;
...
body = DECL_SAVED_TREE(fd);
if( body ) {
    xml_print_endline_attribute (xdi, body);
}

the 'xml_print_endline_attribute' function looks like this:

/* Print the XML attribute endline="line" for the given COMPOUND_STMT */
static void
xml_print_endline_attribute (xml_dump_info_p xdi, tree d)
{
    unsigned int source_endline = STMT_LINENO( d );
    fprintf (xdi->file, " endline=\"%d\"", source_endline);
}

I tested it only with a very small cpp file. But for that it worked.

You are right that I can't blindly add code after/before lines. But if I say
the ending brace has to be on a new line it works.. :-)


-Iwan



> Iwan,
>
> > I want to use GCC_XML for code transformation (Adding code at the
> > beginning and at the end of a method plus adding attributes a class). To
> > do that I need the line of the beginning of a method
> > declaration/definition and the end of the method declaration/definition.
> > The generated XML from GCC_XML only privides the beginning line of the
> > method declaration/definition. Is it somehow possible to have the end
> > line as well? Or somebody even know a better way to for transforming
> > methods in c++ source code.
>
> GCC does not internally store the ending line, so GCC-XML cannot dump it.
> You can't just blindly add code after/before lines, though, because of
> code like this:
>
> void foo() {}
> int bar() {int x=0;
> return x;}
>
> You'll have to write a curly-matching parser that starts with the line
> given by GCC-XML's dump.
>
> -Brad
>
> _______________________________________________
> gccxml mailing list
> gccxml at gccxml.org
> http://www.gccxml.org/mailman/listinfo/gccxml
>




More information about the gccxml mailing list