17 using namespace clang;
28 auto GetNextNamedNamespace = [](
const DeclContext *Context) {
30 while (Context && (!isa<NamespaceDecl>(Context) ||
31 cast<NamespaceDecl>(Context)->isAnonymousNamespace()))
35 for (Context = GetNextNamedNamespace(Context); Context !=
nullptr;
36 Context = GetNextNamedNamespace(Context->
getParent()))
37 Namespaces.push_back(cast<NamespaceDecl>(Context));
58 if (UseNamespaces.size() < FromNamespaces.size())
60 unsigned Diff = UseNamespaces.size() - FromNamespaces.size();
61 auto FromIter = FromNamespaces.begin();
65 auto UseIter = UseNamespaces.begin() + Diff;
66 for (; FromIter != FromNamespaces.end() && UseIter != UseNamespaces.end();
67 ++FromIter, ++UseIter) {
69 if (*FromIter == *UseIter)
73 if (cast<NamespaceDecl>(*FromIter)->getDeclName() ==
74 cast<NamespaceDecl>(*UseIter)->getDeclName())
77 assert(FromIter == FromNamespaces.end() && UseIter == UseNamespaces.end());
83 bool HadLeadingColonColon) {
85 while (DeclA && !isa<NamespaceDecl>(DeclA))
90 return HadLeadingColonColon ? NewName : NewName.substr(2);
96 "::" + cast<NamespaceDecl>(DeclA)->getQualifiedNameAsString() +
"::";
97 if (NewName.startswith(NS))
98 return NewName.substr(NS.size());
120 StringRef ReplacementString) {
121 assert(ReplacementString.startswith(
"::") &&
122 "Expected fully-qualified name!");
132 const bool class_name_only = !Use;
133 const bool in_global_namespace =
135 const bool is_class_forward_decl =
137 !cast<CXXRecordDecl>(FromDecl)->isCompleteDefinition();
138 if (class_name_only && !in_global_namespace && !is_class_forward_decl &&
141 auto Pos = ReplacementString.rfind(
"::");
142 return Pos != StringRef::npos ? ReplacementString.substr(Pos + 2)
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
static bool isFullyQualified(const NestedNameSpecifier *NNS)
Check if the name specifier begins with a written "::".
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static StringRef getBestNamespaceSubstr(const DeclContext *DeclA, StringRef NewName, bool HadLeadingColonColon)
DeclContext * getDeclContext()
static llvm::SmallVector< const NamespaceDecl *, 4 > getAllNamedNamespaces(const DeclContext *Context)
DeclContext * getParent()
getParent - Returns the containing DeclContext.
const NamedDecl * FromDecl
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
static bool usingFromDifferentCanonicalNamespace(const DeclContext *FromContext, const DeclContext *UseContext)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
This represents a decl that may have a name.
The global specifier '::'. There is no stored value.