summaryrefslogtreecommitdiff
path: root/clang-tools-extra/change-namespace
diff options
context:
space:
mode:
authorEric Liu <ioeric@google.com>2016-12-07 20:08:02 +0000
committerEric Liu <ioeric@google.com>2016-12-07 20:08:02 +0000
commit5136ec081ff9861c4245cd081072b9c1625a52c6 (patch)
treef73ea5795c37e8bbb2ae46908db96cd22c22c5cb /clang-tools-extra/change-namespace
parent8df7913bb0054b4c8ea5ed82c035e3377cb1deab (diff)
[change-namespace] always add a '::' prefix when a symbol reference needs to be fully-qualified.
Diffstat (limited to 'clang-tools-extra/change-namespace')
-rw-r--r--clang-tools-extra/change-namespace/ChangeNamespace.cpp4
-rw-r--r--clang-tools-extra/change-namespace/ChangeNamespace.h5
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 {