[cfe-dev] RFC: Adding a rename refactoring tool to clang

James Dennett james.dennett at gmail.com
Fri Aug 1 14:09:38 PDT 2014

On Fri, Aug 1, 2014 at 1:22 PM, Gabriel Dos Reis
<gdr at integrable-solutions.net> wrote:
> On Wed, Jul 30, 2014 at 9:42 AM, Richard <legalize at xmission.com> wrote:
>> In article
>> <CAMfx8+eLTwdAbHw64L-O71hChrsKJKBOsgB-cuYaXN4xU7Qp5Q at mail.gmail.com>,
>>     Matthew Plant <mplant at google.com> writes:
>> > The code does not need to be compile-able, but it does need to be at
>> > least
>> > some-what parseable.
>> In this regard, clang's rename won't be any worse than any other
>> language's rename.
>> For instance, refactoring tools are pretty mature in .NET/Java, but
>> none of them successfully rename an identifier whose type can't be parsed.
>> You're fundamentally missing the semantic information needed to decide
>> where else this identifier needs to be changed.
>> As far as C++ refactoring tools goes, *anything* based on clang's
>> parser is going to be light years ahead of other tools that are based
>> on ad-hoc homegrown parsers.
> not to be argumentative, but in what ways is Clang's parser not ad-hoc and
> homegrown?

The distinction is primarily between tools that can actually parse C++
properly (such as Clang's parser, and a small number of others -- I'd
prefer not to argue about exactly which qualify as doing the job
"properly", given that none is bug-free) and the many, many homegrown,
ad-hoc tools that (by design) fall far short of that.  As I'm sure
you're aware, parsing C++ robustly means handling overload resolution,
template instantiation, constexpr evaluation, and a pile of other
things that are too much work for most tool creators to do from
scratch.  Typically they do something "good enough" for their
purposes, and where necessary sometimes even re-write their C++ source
code to avoid needing a more fully-featured parser.

To give an example: Doxygen has what might be termed an "ad-hoc,
homegrown parser" for C++, which for the most part worked well enough
to extract documentation and associated structure, but had
limitations.  clang-format uses an ad-hoc parser (sometimes called a
"recognizer" to distinguish it from a tool that aims for formally
correct parsing).  I've a feeling SWIG tries to parse C++ (not always

-- James

More information about the cfe-dev mailing list