diff options
| author | Eric Liu <ioeric@google.com> | 2016-12-07 20:08:02 +0000 |
|---|---|---|
| committer | Eric Liu <ioeric@google.com> | 2016-12-07 20:08:02 +0000 |
| commit | 97f87add50e9b435a104449372fdd08a8f8723b7 (patch) | |
| tree | 981d35dc732c1f3c6e29d038e5feac252eefec1b /clang-tools-extra/change-namespace | |
| parent | c6885fc369945a8fe196301b7c2357e11a4c5f20 (diff) | |
| download | bcm5719-llvm-97f87add50e9b435a104449372fdd08a8f8723b7.tar.gz bcm5719-llvm-97f87add50e9b435a104449372fdd08a8f8723b7.zip | |
[change-namespace] always add a '::' prefix when a symbol reference needs to be fully-qualified.
llvm-svn: 288969
Diffstat (limited to 'clang-tools-extra/change-namespace')
| -rw-r--r-- | clang-tools-extra/change-namespace/ChangeNamespace.cpp | 4 | ||||
| -rw-r--r-- | clang-tools-extra/change-namespace/ChangeNamespace.h | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.cpp b/clang-tools-extra/change-namespace/ChangeNamespace.cpp index 45064ebeeb7..2dca1a98893 100644 --- a/clang-tools-extra/change-namespace/ChangeNamespace.cpp +++ b/clang-tools-extra/change-namespace/ChangeNamespace.cpp @@ -663,6 +663,10 @@ void ChangeNamespaceTool::replaceQualifiedSymbolInDeclContext( // old namespace, we don't create replacement. if (NestedName == ReplaceName) return; + // If the reference need to be fully-qualified, add a leading "::" unless + // NewNamespace is the global namespace. + if (ReplaceName == FromDeclName && !NewNamespace.empty()) + ReplaceName = "::" + ReplaceName; auto R = createReplacement(Start, End, ReplaceName, *Result.SourceManager); auto Err = FileToReplacements[R.getFilePath()].add(R); if (Err) diff --git a/clang-tools-extra/change-namespace/ChangeNamespace.h b/clang-tools-extra/change-namespace/ChangeNamespace.h index 048c32fd2d3..342457adf4c 100644 --- a/clang-tools-extra/change-namespace/ChangeNamespace.h +++ b/clang-tools-extra/change-namespace/ChangeNamespace.h @@ -24,6 +24,9 @@ namespace change_namespace { // namespaces while references to symbols (e.g. types, functions) which are not // defined in the changed namespace will be correctly qualified by prepending // namespace specifiers before them. +// This will try to add shortest namespace specifiers possible. When a symbol +// reference needs to be fully-qualified, this adds a "::" prefix to the +// namespace specifiers unless the new namespace is the global namespace. // For classes, only classes that are declared/defined in the given namespace in // speficifed files will be moved: forward declarations will remain in the old // namespace. @@ -38,7 +41,7 @@ namespace change_namespace { // class FWD; // } // a // namespace x { -// class A { a::FWD *fwd; } +// class A { ::a::FWD *fwd; } // } // x // FIXME: support moving typedef, enums across namespaces. class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback { |

