Commit Graph

49 Commits

Author SHA1 Message Date
Eric Liu 5a6d57c75f [change-namespace] Fix crash when injected base-class name is used in friend declarations.
Reviewers: hokein

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D41001

llvm-svn: 320139
2017-12-08 10:06:16 +00:00
Shoaib Meenai d806af3499 [CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.
Dependencies added in this way apply to both the target and its
dependencies, i.e. they become part of the executable's link interface
and are transitive.

Transitive dependencies generally don't make sense for executables,
since you wouldn't normally be linking against an executable. This also
causes issues for generating install export files when using
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM
library dependencies, which are currently added as interface
dependencies. If clang is in the distribution components but the LLVM
libraries it depends on aren't (which is a perfectly legitimate use case
if the LLVM libraries are being built static and there are therefore no
run-time dependencies on them), CMake will complain about the LLVM
libraries not being in export set when attempting to generate the
install export file for clang. This is reasonable behavior on CMake's
part, and the right thing is for LLVM's build system to explicitly use
PRIVATE dependencies for executables.

Unfortunately, CMake doesn't allow you to mix and match the keyword and
non-keyword target_link_libraries signatures for a single target; i.e.,
if a single call to target_link_libraries for a particular target uses
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must
also be updated to use those keywords. This means we must do this change
in a single shot. I also fully expect to have missed some instances; I
tested by enabling all the projects in the monorepo (except dragonegg),
and configuring both with and without shared libraries, on both Darwin
and Linux, but I'm planning to rely on the buildbots for other
configurations (since it should be pretty easy to fix those).

Even after this change, we still have a lot of target_link_libraries
calls that don't specify a scope keyword, mostly for shared libraries.
I'm thinking about addressing those in a follow-up, but that's a
separate change IMO.

Differential Revision: https://reviews.llvm.org/D40823

llvm-svn: 319840
2017-12-05 21:49:56 +00:00
Eric Liu b583a7ead4 [change-namespace] do not change type locs in defaulted functions.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D38893

llvm-svn: 315892
2017-10-16 08:20:10 +00:00
Eric Liu 8bc2416414 [change-namespace] avoid adding leading '::' when possible.
Summary:
When changing namespaces, the tool adds leading "::" to references that need to
be fully-qualified, which would affect readability.

We avoid adding "::" when the symbol name does not conflict with the new
namespace name. For example, a symbol name "na::nb::X" conflicts with "ns::na"
since it would be resolved to "ns::na::nb::X" in the new namespace.

Reviewers: hokein

Reviewed By: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D30493

llvm-svn: 298363
2017-03-21 12:41:59 +00:00
Eric Liu 284b97c6bc [change-namespace] do not rename specialized template parameters.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D31076

llvm-svn: 298090
2017-03-17 14:05:39 +00:00
Eric Liu 413671507f [change-namespace] get insertion points of forward declarations correct.
Summary:
Previously, the insertion points would conflict with the old namespace
deletion.

Reviewers: hokein

Reviewed By: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D30490

llvm-svn: 296604
2017-03-01 10:29:39 +00:00
Eric Liu 3a7e13140a [change-namespace] trying to fix windows buildbot failure.
llvm-svn: 296458
2017-02-28 10:00:15 +00:00
Eric Liu 4c8767fa55 [change-namespace] fix asan failure in r296110.
llvm-svn: 296113
2017-02-24 12:56:51 +00:00
Eric Liu 7fccc9995a [change-namepsace] make it possible to whitelist symbols so they don't get updated.
Reviewers: hokein

Reviewed By: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D30328

llvm-svn: 296110
2017-02-24 11:54:45 +00:00
Eric Liu a13c419a29 [change-namespace] add an option to dump changed files in YAML.
Reviewers: hokein

Reviewed By: hokein

Subscribers: fhahn, cfe-commits

Differential Revision: https://reviews.llvm.org/D29893

llvm-svn: 294969
2017-02-13 17:24:14 +00:00
Eric Liu 28c30ce250 [change-namespace] trying to fix build bot failure caused by r293909.
llvm-svn: 293927
2017-02-02 19:46:12 +00:00
Eric Liu 0325a77c5b [change-namespace] fix unscoped enum constant references.
Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D29460

llvm-svn: 293909
2017-02-02 17:40:38 +00:00
Eric Liu ae7de7117a [change-namespace] check using shadow decl correctly when shortening namespace specifiers.
Summary:
This fixes mismatch between template decls and template specialization decls.

Also added a few more test cases.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D29447

llvm-svn: 293897
2017-02-02 15:29:54 +00:00
Eric Liu 9122916ee5 [change-namespace] correctly shorten namespace when references have leading '::'
Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D29182

llvm-svn: 293187
2017-01-26 16:31:32 +00:00
Eric Liu bc715504da [change-namespace] add leading '::' to references in new namespace when name conflict is possible.
Summary:
For example, when we change 'na' to "nb::nc", we need to add leading '::' to
references "::nc::X" in the changed namespace.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D29176

llvm-svn: 293182
2017-01-26 15:08:44 +00:00
Antonio Maiorano 0d7d9c20a5 Update tools to use new getStyle API
Depends on https://reviews.llvm.org/D28081

Differential Revision: https://reviews.llvm.org/D28315

llvm-svn: 292175
2017-01-17 00:13:32 +00:00
Eric Liu ee5104bbab [change-namespace] get newlines around moved namespace right.
Summary: Previously, a `\n` might be left in the old namespace and thus not copied to the new namespace, which is bad.

Reviewers: hokein

Subscribers: alexshap, cfe-commits

Differential Revision: https://reviews.llvm.org/D28282

llvm-svn: 290966
2017-01-04 14:49:08 +00:00
Eric Liu 180dac6396 [change-namespace] consider namespace aliases to shorten qualified names.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D28052

llvm-svn: 290421
2016-12-23 10:47:09 +00:00
Eric Liu e3f35e4db6 [change-namespace] do not fix calls to overloaded operator functions.
Summary: Also make sure one function reference is only processed once.

Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27982

llvm-svn: 290176
2016-12-20 14:39:04 +00:00
Eric Liu 0c0aea0c0a [change-namespace] fix a case references to templated using alias are qualified types.
llvm-svn: 289816
2016-12-15 13:02:41 +00:00
Eric Liu 26cf68af3a [change-namespace] handling templated type aliases correctly.
Summary: This fixes templated type aliases and templated type aliases in classes.

Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27801

llvm-svn: 289799
2016-12-15 10:42:35 +00:00
Eric Liu 4fe99e1431 [change-namespace] don't crash when type reference is in function type parameter list.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27758

llvm-svn: 289672
2016-12-14 17:01:52 +00:00
Piotr Padlewski 08124b110a modernize-use-auto NFC fixes
llvm-svn: 289656
2016-12-14 15:29:23 +00:00
Eric Liu 97f87add50 [change-namespace] always add a '::' prefix when a symbol reference needs to be fully-qualified.
llvm-svn: 288969
2016-12-07 20:08:02 +00:00
Eric Liu 8685c76472 [change-namespace] don't fix using shadow decls in classes.
Summary:
Using shadow declarations in classes always refers to base class, which does not
need to be fixed/qualified since it can be inferred from inheritance.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27523

llvm-svn: 288919
2016-12-07 17:04:07 +00:00
Eric Liu 41552d6a37 [change-namespace] move template class forward-declarations and don't move fwd-decls in classes.
Summary:
Forward declarations in moved namespaces should be moved back to the old
namespaces. We should also move template class forward declarations.

Also fix a bug that moves forward declarations of nested classes.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27515

llvm-svn: 288908
2016-12-07 14:20:52 +00:00
Eric Liu 2dd0e1bca3 [change-namespace] get changing namespace to global correct.
llvm-svn: 288662
2016-12-05 11:17:04 +00:00
Eric Liu c265b02bec [change-namespace] don't generate replacements for files that don't match file pattern.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27302

llvm-svn: 288376
2016-12-01 17:25:55 +00:00
Eric Liu da22b3cb8a [change-namespace] fix non-calling function references.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D27208

llvm-svn: 288139
2016-11-29 14:15:14 +00:00
Eric Liu ff51f011d1 [change-namespace] handle constructor initializer: Derived : Base::Base() {} and added conflict detections
Summary:
namespace nx { namespace ny { class Base { public: Base(i) {}} } }
namespace na {
namespace nb {
class X : public nx::ny {
public:
  X() : Base::Base(1) {}
};
}
}

When changing from na::nb to x::y, "Base::Base" will be changed to "nx::ny::Base" and
 "Base::" in "Base::Base" will be replaced with "nx::ny::Base" too, which causes
conflict. This conflict should've been detected when adding replacements but was hidden by `addOrMergeReplacement`. We now also detect conflict when adding replacements where conflict must not happen.

The namespace lookup is tricky here, we simply replace "Base::Base()" with "nx::ny::Base()" as a workaround, which compiles but not perfect.

Reviewers: hokein

Subscribers: bkramer, cfe-commits

Differential Revision: https://reviews.llvm.org/D26637

llvm-svn: 287118
2016-11-16 16:54:53 +00:00
Eric Liu 3215886b7a [change-namespace] consider typedef/using alias decls in the moved namespace.
Summary: If a TypeLoc refers to a type alias defined in the moved namespace, we do not need to update its specifier since the type alias decl will be moved along with the type reference.

Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26592

llvm-svn: 286873
2016-11-14 19:37:55 +00:00
Eric Liu 6aa9416d06 Handle adding new nested namespace in old namespace.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D26456

llvm-svn: 286486
2016-11-10 18:29:01 +00:00
Eric Liu 231c655851 [change-namespace] dyn_cast -> cast.
llvm-svn: 286485
2016-11-10 18:15:34 +00:00
Eric Liu b9bf1b5b85 [change-namespace] shorten namespace qualifier based on UsingDecl and UsingDirectiveDecl.
Summary:
when replacing symbol references in moved namespaces, trying to make the replace
name as short as possible by considering UsingDecl (i.e. UsingShadow) and
UsingDirectiveDecl (i.e. using namespace decl).

Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25771

llvm-svn: 286307
2016-11-08 22:44:17 +00:00
Mandeep Singh Grang 7c7ea7d0ae [clang-tools-extra] Format sources with clang-format. NFC.
Summary:
Ran clang-format on all .c/.cpp/.h files in clang-tools-extra.
Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories.

Reviewers: klimek, alexfh

Subscribers: nemanjai

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D26329

llvm-svn: 286221
2016-11-08 07:50:19 +00:00
Eric Liu 8393cb0191 [change-namespace] fix namespace specifiers of template arguments.
llvm-svn: 285549
2016-10-31 08:28:29 +00:00
Eric Liu 3db05219f7 Print stack trace for clang-change-namespace tool.
llvm-svn: 284147
2016-10-13 18:56:14 +00:00
Eric Liu 73f49fd3f9 [change-namespace] don't miss comments in the beginning of a namespace block.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25397

llvm-svn: 284011
2016-10-12 12:34:18 +00:00
Haojian Wu b530f1649e [change-namespace] Pass Style to ChangeNamespaceTool.
llvm-svn: 283338
2016-10-05 17:00:40 +00:00
Eric Liu 447164dea2 [change-namespace] Fixed a bug in getShortestQualifiedNameInNamespace.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25065

llvm-svn: 283333
2016-10-05 15:52:39 +00:00
Haojian Wu ef8a6dcd09 [change-namespace] Fix a misplaced case when there is no trailing newline character at the end of the file.
Reviewers: ioeric

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D25226

llvm-svn: 283210
2016-10-04 10:35:53 +00:00
Eric Liu 159f0135b1 [change-namespace] fix namespace specifier of global variables.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24963

llvm-svn: 282837
2016-09-30 04:32:39 +00:00
Eric Liu 912d039462 Workaround ASTMatcher crashes. Added some more test cases.
Summary:
- UsingDecl matcher crashed when `UsingShadowDecl` has no parent map. Workaround by moving parent check into `UsingDecl`.
- FunctionDecl matcher crashed when there is a lambda defined in parameter list (also due to no parent map).
  Workaround by putting `unless(cxxMethodDecl())` before parent check.

Reviewers: klimek, sbenza, aaron.ballman, hokein

Subscribers: aaron.ballman, cfe-commits

Differential Revision: https://reviews.llvm.org/D24862

llvm-svn: 282486
2016-09-27 12:54:48 +00:00
Eric Liu 12068d86c3 [change-namespace] fix qualifier of function references.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24803

llvm-svn: 282146
2016-09-22 11:54:00 +00:00
Eric Liu 68765a848b [change-namespace] fix name qualifiers in UsingShadowDecl and NestedNameSpecifier.
Reviewers: hokein

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24784

llvm-svn: 282073
2016-09-21 15:06:12 +00:00
NAKAMURA Takumi e9a6f09dda clang-change-namespace: Update libdeps.
FIXME: It seems clangFormat is not referred.
llvm-svn: 281954
2016-09-20 00:44:45 +00:00
Eric Liu 77b0c1adee Add missing dependency to change-namespace.
llvm-svn: 281935
2016-09-19 20:41:39 +00:00
Eric Liu cc83c66ee9 Trying to fix name conflict in change-namespace tool.
llvm-svn: 281920
2016-09-19 17:58:59 +00:00
Eric Liu 495b211a6c A clang tool for changing surrouding namespaces of class/function definitions.
Summary:
A tool for changing surrouding namespaces of class/function definitions while keeping
references to types in the changed namespace correctly qualified by prepending
namespace specifiers before them.

Example: test.cc
   namespace na {
   class X {};
   namespace nb {
   class Y { X x; };
   } // namespace nb
   } // namespace na

To move the definition of class Y from namespace "na::nb" to "x::y", run:
   clang-change-namespace --old_namespace "na::nb" \
     --new_namespace "x::y" --file_pattern "test.cc" test.cc --

Output:
   namespace na {
   class X {};
   } // namespace na
   namespace x {
   namespace y {
   class Y { na::X x; };
   } // namespace y
   } // namespace x

Reviewers: alexfh, omtcyfz, hokein

Subscribers: mgorny, klimek, djasper, beanz, alexshap, Eugene.Zelenko, cfe-commits

Differential Revision: https://reviews.llvm.org/D24183

llvm-svn: 281918
2016-09-19 17:40:32 +00:00