This is an archive of the discontinued LLVM Phabricator instance.

[clang-rename] Support renaming qualified symbol
ClosedPublic

Authored by hokein on Mar 21 2017, 2:42 AM.

Details

Summary

The patch adds a new feature for renaming qualified symbol references.
Unlike orginal clang-rename behavior, when renaming a qualified symbol to a new
qualified symbol (e.g "A::Foo" => "B::Bar"), this new rename behavior will
consider the prefix qualifiers of the symbol, and calculate the new prefix
qualifiers. It aims to add as few additional qualifiers as possible.

As this is an early version (only supports renaming classes), I don't change
current clang-rename interfaces at the moment, and would like to keep its
(command-line tool) behavior. So I added new interfaces for the prototype.
In the long run, these interfaces should be unified.

No functionality changes in original clang-rename command-line tool.

This patch also contains a few bug fixes of clang-rename which are discovered by
the new unittest:

  • fix a potential nullptr accessment when class declaration doesn't have definition.
  • add USRs of nested declartaions in "getNamedDeclFor".

Event Timeline

hokein created this revision.Mar 21 2017, 2:42 AM
hokein updated this revision to Diff 92444.Mar 21 2017, 2:50 AM

A few updates.

hokein added subscribers: cfe-commits, alexfh.
ioeric edited edge metadata.Mar 21 2017, 4:10 AM

I think this is a great start!

First round with some nits.

clang-rename/RenamingAction.cpp
87

Comments.

clang-rename/RenamingAction.h
45

Comments. Same for other classes.

60

What is USRList?

clang-rename/USRFinder.cpp
139

nit: No braces for one-liners.

199

It is unclear to me what nested declarations are.

clang-rename/USRLocFinder.cpp
152

You don't need "clang::" here and elsewhere.

156

Variable names should be LLVM style.

157

Is this cast always safe?

169

nit: No braces around one-liners. Same below.

196

Comments.

196

I think this visitor deserves a file of its own.

368

Note this is not expected behavior for alias types which would always be skipped in this check.

462

Loc seems to be a bad name here. It is usually used for TypeLoc.

clang-rename/USRLocFinder.h
35

Comments.

hokein updated this revision to Diff 92636.Mar 22 2017, 7:34 AM
hokein marked 14 inline comments as done.

Address review comments.

hokein added inline comments.Mar 22 2017, 7:35 AM
clang-rename/USRLocFinder.cpp
157

Yes, because we have checked the type of the TL is an elaborated type. I have changed to getAs which makes the indication more explicitly.

196

I'm not sure it is the right time to do it at the moment since it is in early stage. I'd keep it here. We can do it when needed.

368

Acked. Add a FIXME.

ioeric added inline comments.Mar 23 2017, 8:13 AM
clang-rename/USRFinder.cpp
199

But what is the nested name? Is it the nested name specifier? Of what?

clang-rename/USRLocFinder.cpp
195

I think this also does some renaming?

217

Could you be more specific in this FIXME? I don't quite get it. Maybe an example?

359

I think these are using shadows only?

clang-rename/USRLocFinder.h
36

Why use std::vector instead of tooling::Replacements?

hokein updated this revision to Diff 92954.Mar 24 2017, 8:58 AM
hokein marked 3 inline comments as done.

Add comments and polish tests.

hokein added inline comments.Mar 24 2017, 8:58 AM
clang-rename/USRLocFinder.cpp
195

No, this class is only responsible for finding rename locations and other information which are used for renaming. The renaming stuff is done by USRSymbolRenamer.

217

You can also see the FIXME in the test.

359

These are interested UsingDecls which contain UsingShadowDecl of the symbol declarations being renamed.

clang-rename/USRLocFinder.h
36

Seems that we don't get many benefits from using tooling::Replacements here. This function could be called multiple times (for renaming multiple symbols), we need to merge/add all replacements in caller side. if using tooling::Replacements, we will merge twice (one is in the API implementation).

ioeric added inline comments.Mar 24 2017, 9:03 AM
clang-rename/USRLocFinder.cpp
195

Sure. I meant you should also document it.

359

Sure. But maybe also document it?

clang-rename/USRLocFinder.h
36

I think what we really want is AtomicChange. We shouldn't be using std::vector or std::set replacements anymore.

hokein updated this revision to Diff 93468.Mar 30 2017, 5:06 AM
hokein marked 2 inline comments as done.

Use AtomicChange.

hokein updated this revision to Diff 93469.Mar 30 2017, 5:08 AM
hokein marked an inline comment as done.

update comments.

clang-rename/USRLocFinder.cpp
359

I have documented it at the "UsingDecls" member definition.

clang-rename/USRLocFinder.h
36

Good idea. Done. I think we might still need to refine the interface in the future.

ioeric accepted this revision.Mar 30 2017, 5:14 AM

Lg with a few nits.

clang-rename/RenamingAction.cpp
104

Maybe add a FIXME to fully replace this with AtomicChanges in the future?

clang-rename/USRLocFinder.h
37

I'd name this createRenameAtomicChanges for clarity.

This revision is now accepted and ready to land.Mar 30 2017, 5:14 AM
hokein updated this revision to Diff 93474.Mar 30 2017, 6:22 AM
hokein marked 2 inline comments as done.

Fix a few nits.

This revision was automatically updated to reflect the committed changes.