This is the mail archive of the 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: Access to source code from an analyser

> On Thu, 2012-01-19 at 14:06 +0100, Alberto Lozano Alelu wrote:
>> Hello.
>> Thanks for your fast response.
>> With expand_location I get struct expanded_location which has these fields:
>> type = struct {
>>     const char *file;
>>     int line;
>>     int column;
>>     unsigned char sysp;
>> }
>> But it hasn't source line text.
>> I know how I have to use expand_location function but I would like to
>> get source text from a source location. I would like a funcion such
>> as:
>> char *v_line_text = <a_gcc_function>(file,line);
>> or
>> expanded_location v_location=expand_location(SOURCE_LOCATION(my_element));
>> char * v_line_text = a_function(v_location);
>> v_line_text is a source code line.
>> I need to have source text
> I'm interested in hearing if there's a more "official" way of doing this
> from the GCC experts, but can't you just read the file from disk and
> split it on newline characters? (probably with some caching)

Since nobody can be bothered to answer you: No, there is not.

It would be nice if there were, because it could have many
applications, but as far as I know, no one is working on it. See: A.3

However, to be honest, even if you implement your own source-location
manager in your own plugin code, I don't think it will be very precise
because the internal representation of GCC C/C++ FE is not very close
to the actual code, and the locations are sometimes quite imprecise.
Nonetheless, I think having a source-location manager could help to
point out these issues.

If you wished to contribute a source-location manager to GCC, I think
it would be accepted, eventually. In fact, it should be possible to
reuse code from CPP. However, having precise locations is a much
harder problem to fix. As an alternative, you may wish to take a look
at Clang, which is more focused on supporting diverse clients and IDEs
and provides both a source-location manager module and very precise
location info. It also tracks the location of many more things than
GCC, which is another problem that is quite likely very hard to fix.



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