On 03/09/2019 22:17, Richard wrote:
> [Please do not mail me a copy of your followup]
>
> David Brown <
david...@hesbynett.no> spake the secret code
> <qk6nnl$nh0$
1...@dont-email.me> thusly:
>
>> On 28/08/2019 22:00, Richard wrote:
>>> I agree, but suggesting that one use lex/yacc for parsing C++ is an
>>> approach that many people have tried and failed. It's a really awful
>>> idea. That suggestion should not be left out in the open
>>> unchallenged.
>>>
>>> This is particularly true when you can just use the clang libraries to
>>> get a perfectly conforming C++20 parser that will just hand you an
>>> AST.
>>>
>
>> Another option that would be interesting for static analysis is a gcc
>> plugin, possibly written in a different language (Python is a reasonable
>> choice for such tasks).
>
> Bwuahahahahaha! That is hilarious. Seriously. I know they've
> improved gcc at this point, but Stallman et al. have literally said
> that they made the internal interface as painful as possible to put
> into a library on purpose because they didn't want anyone doing that.
>
That was certainly true. But it is a long time - a very long time -
since Stallman and others with that attitude have ruled gcc. There is
no doubt that Stallman specifically wanted strong ties between different
parts of the code in gcc, to make it as difficult as possible to split
it up and mix the gcc front ends with commercial or closed backends, or
vice versa. However, as the project grew, with many more people
involved, many front ends, and many back ends, it got steadily cleaner
separation and more modularisation. And with gcc 4.5, nearly 10 years
ago (IIRC), it got plugin support.
One of the big influences and motivations for gcc plugins is the
competitive / cooperative relationship with llvm/clang. The two
projects push each other forward, which is great for users of either
tool suite.
RMS may not like the fact that gcc has plugins, with the risk that has
of mixing closed source software with gcc, but there is no doubt that
gcc supports plugins and these are used, amongst other things, for
additional static analysis.
> Clang was designed from the ground up to be used as a library.
>
True.
>> I can't tell you whether clang or gcc would be the best starting point
>> for making your own static analysis tools, but I look at both of them
>> /long/ before looking at lex/yacc.
>
> Don't bother looking at lex/yacc because the context-sensitive nature
> of many C++ constructs makes it impossible to use lex/yacc.
>
True.
> Don't waste your time with GCC because it isn't designed to be used
> this way.
Unless you are stuck a decade behind the times, /do/ look at gcc, and
especially the existing plugin libraries, if you want to make your own
static analysis. And look at clang. Compare their approaches, compare
the documentation, websites, blogs, tutorials, third-party code,
examples and other information. Then figure out what is going to make
sense for the kind of tool you want to make and use.
My guess - and it is only a guess - is that clang is going to be the
best base if you want to write a large-scale checker and you want high
speed for analysing large code bases. And gcc with the Python or Melt
(Lisp) plugins are going to be good for small-scale checks written in
higher level languages.