//===-- ChangeNamespace.h -- Change namespace ------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CHANGE_NAMESPACE_CHANGENAMESPACE_H #define LLVM_CLANG_TOOLS_EXTRA_CHANGE_NAMESPACE_CHANGENAMESPACE_H #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Format/Format.h" #include "clang/Tooling/Core/Replacement.h" #include "llvm/Support/Regex.h" #include <string> namespace clang { namespace change_namespace { // This tool can be used to change the surrounding namespaces of class/function // definitions. Classes/functions in the moved namespace will have new // 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 // specified files will be moved: forward declarations will remain in the old // namespace. // For example, changing "a" to "x": // Old code: // namespace a { // class FWD; // class A { FWD *fwd; } // } // a // New code: // namespace a { // class FWD; // } // a // namespace x { // class A { ::a::FWD *fwd; } // } // x // FIXME: support moving typedef, enums across namespaces. class ChangeNamespaceTool : public ast_matchers::MatchFinder::MatchCallback { … }; } // namespace change_namespace } // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CHANGE_NAMESPACE_CHANGENAMESPACE_H