27#include "llvm/ADT/FoldingSet.h"
28#include "llvm/Support/Compiler.h"
29#include "llvm/Support/ErrorHandling.h"
30#include "llvm/Support/raw_ostream.h"
39NestedNameSpecifier::FindOrInsert(
const ASTContext &Context,
41 llvm::FoldingSetNodeID
ID;
44 void *InsertPos =
nullptr;
46 = Context.NestedNameSpecifiers.FindNodeOrInsertPos(ID, InsertPos);
50 Context.NestedNameSpecifiers.InsertNode(NNS, InsertPos);
59 assert(II &&
"Identifier cannot be NULL");
60 assert((!Prefix || Prefix->
isDependent()) &&
"Prefix must be dependent");
63 Mockup.Prefix.setPointer(Prefix);
64 Mockup.Prefix.setInt(StoredIdentifier);
66 return FindOrInsert(Context, Mockup);
73 assert(NS &&
"Namespace cannot be NULL");
77 "Broken nested name specifier");
79 Mockup.Prefix.setPointer(Prefix);
80 Mockup.Prefix.setInt(StoredDecl);
82 return FindOrInsert(Context, Mockup);
89 assert(Alias &&
"Namespace alias cannot be NULL");
93 "Broken nested name specifier");
95 Mockup.Prefix.setPointer(Prefix);
96 Mockup.Prefix.setInt(StoredDecl);
98 return FindOrInsert(Context, Mockup);
104 bool Template,
const Type *
T) {
105 assert(
T &&
"Type cannot be NULL");
107 Mockup.Prefix.setPointer(Prefix);
108 Mockup.Prefix.setInt(Template? StoredTypeSpecWithTemplate : StoredTypeSpec);
109 Mockup.Specifier =
const_cast<Type*
>(
T);
110 return FindOrInsert(Context, Mockup);
115 assert(II &&
"Identifier cannot be NULL");
117 Mockup.Prefix.setPointer(
nullptr);
118 Mockup.Prefix.setInt(StoredIdentifier);
120 return FindOrInsert(Context, Mockup);
125 if (!Context.GlobalNestedNameSpecifier)
126 Context.GlobalNestedNameSpecifier =
128 return Context.GlobalNestedNameSpecifier;
135 Mockup.Prefix.setPointer(
nullptr);
136 Mockup.Prefix.setInt(StoredDecl);
137 Mockup.Specifier = RD;
138 return FindOrInsert(Context, Mockup);
145 switch (Prefix.getInt()) {
146 case StoredIdentifier:
151 if (isa<CXXRecordDecl>(ND))
159 case StoredTypeSpecWithTemplate:
163 llvm_unreachable(
"Invalid NNS Kind!");
168 if (Prefix.getInt() == StoredDecl)
169 return dyn_cast<NamespaceDecl>(
static_cast<NamedDecl *
>(Specifier));
176 if (Prefix.getInt() == StoredDecl)
177 return dyn_cast<NamespaceAliasDecl>(
static_cast<NamedDecl *
>(Specifier));
184 switch (Prefix.getInt()) {
185 case StoredIdentifier:
189 return dyn_cast<CXXRecordDecl>(
static_cast<NamedDecl *
>(Specifier));
192 case StoredTypeSpecWithTemplate:
196 llvm_unreachable(
"Invalid NNS Kind!");
203 auto F = NestedNameSpecifierDependence::Dependent |
204 NestedNameSpecifierDependence::Instantiation;
214 return NestedNameSpecifierDependence::None;
219 if (
Base.getType()->isDependentType())
221 return NestedNameSpecifierDependence::Dependent;
222 return NestedNameSpecifierDependence::None;
229 llvm_unreachable(
"Invalid NNS Kind!");
233 return getDependence() & NestedNameSpecifierDependence::Dependent;
237 return getDependence() & NestedNameSpecifierDependence::Instantiation;
241 return getDependence() & NestedNameSpecifierDependence::UnexpandedPack;
245 return getDependence() & NestedNameSpecifierDependence::Error;
251 bool ResolveTemplateArguments)
const {
286 if (ResolveTemplateArguments &&
Record) {
288 Record->printName(OS, Policy);
290 OS,
Record->getTemplateArgs().asArray(), Policy,
291 Record->getSpecializedTemplate()->getTemplateParameters());
306 assert(!isa<ElaboratedType>(
T) &&
307 "Elaborated type in nested-name-specifier");
309 = dyn_cast<TemplateSpecializationType>(
T)) {
312 SpecType->getTemplateName().print(OS, InnerPolicy,
318 }
else if (
const auto *DepSpecType =
319 dyn_cast<DependentTemplateSpecializationType>(
T)) {
322 OS << DepSpecType->getIdentifier()->getName();
338 dump(llvm::errs(), LO);
355 assert(Qualifier &&
"Expected a non-NULL qualifier");
360 switch (Qualifier->getKind()) {
377 Length +=
sizeof(
void *);
388 Length += getLocalDataLength(Qualifier);
396 memcpy(&Raw,
static_cast<char *
>(
Data) + Offset,
sizeof(Raw));
425 switch (Qualifier->getKind()) {