clang: include/clang/AST/NestedNameSpecifier.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LLVM_CLANG_AST_NESTEDNAMESPECIFIER_H
14#define LLVM_CLANG_AST_NESTEDNAMESPECIFIER_H
15
20#include "llvm/ADT/DenseMapInfo.h"
21
23
25 if (!isStoredKind()) {
26 switch (getFlagKind()) {
27 case FlagKind::Null:
29 case FlagKind::Global:
31 case FlagKind::Invalid:
32 llvm_unreachable("use of invalid NestedNameSpecifier");
33 }
34 llvm_unreachable("unhandled FlagKind");
35 }
36 switch (auto [K, Ptr] = getStored(); K) {
37 case StoredKind::Type:
39 case StoredKind::NamespaceWithGlobal:
40 case StoredKind::NamespaceWithNamespace:
42 case StoredKind::NamespaceOrSuper:
43 switch (static_cast<const Decl *>(Ptr)->getKind()) {
44 case Decl::Namespace:
45 case Decl::NamespaceAlias:
47 case Decl::CXXRecord:
48 case Decl::ClassTemplateSpecialization:
49 case Decl::ClassTemplatePartialSpecialization:
51 default:
52 llvm_unreachable("unexpected decl kind");
53 }
54 }
55 llvm_unreachable("unknown StoredKind");
56}
57
59 : NestedNameSpecifier({StoredKind::Type, T}) {
60 assert(getKind() == Kind::Type);
61}
62
63auto NestedNameSpecifier::MakeNamespacePtrKind(
64 const ASTContext &Ctx, const NamespaceBaseDecl *Namespace,
65 NestedNameSpecifier Prefix) -> PtrKind {
66 switch (Prefix.getKind()) {
67 case Kind::Null:
68 return {StoredKind::NamespaceOrSuper, Namespace};
69 case Kind::Global:
70 return {StoredKind::NamespaceWithGlobal, Namespace};
71 case Kind::Namespace:
72 return {StoredKind::NamespaceWithNamespace,
73 MakeNamespaceAndPrefixStorage(Ctx, Namespace, Prefix)};
74 case Kind::MicrosoftSuper:
75 case Kind::Type:
76 llvm_unreachable("invalid prefix for namespace");
77 }
78 llvm_unreachable("unhandled kind");
79}
80
81
84 NestedNameSpecifier Prefix)
85 : NestedNameSpecifier(MakeNamespacePtrKind(Ctx, Namespace, Prefix)) {
87}
88
89
90
92 : NestedNameSpecifier({StoredKind::NamespaceOrSuper, RD}) {
93 assert(getKind() == Kind::MicrosoftSuper);
94}
95
105 return nullptr;
106 }
107 llvm_unreachable("Invalid NNS Kind!");
108}
109
115
116 return *this;
118
119
123 }
126 getAsType()->getCanonicalTypeInternal().getTypePtr());
127 }
128 llvm_unreachable("unhandled kind");
129}
130
134
136 return TypeLoc(Qualifier.getAsType(), LoadPointer(0));
137}
138
144
145unsigned
146NestedNameSpecifierLoc::getLocalDataLength(NestedNameSpecifier Qualifier) {
147
149
150 switch (Qualifier.getKind()) {
152
153 break;
154
157
159 break;
160
162
163
164 Length += sizeof(void *);
165 break;
166
168 llvm_unreachable("Expected a non-NULL qualifier");
169 }
170
171 return Length;
172}
173
175 auto [Namespace, Prefix] = Qualifier.getAsNamespaceAndPrefix();
177}
178
184
186 unsigned Length = 0;
187 for (; Qualifier; Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix) {
188 Length += getLocalDataLength(Qualifier);
190 break;
191 }
192 return Length;
193}
194
198
200 switch (auto Kind = Qualifier.getKind()) {
204 return LoadSourceLocation(0);
207 unsigned Offset =
209 ? getDataLength(Qualifier.getAsNamespaceAndPrefix().Prefix)
210 : 0;
212 LoadSourceLocation(Offset),
214 }
216
217
218 void *TypeData = LoadPointer(0);
219 TypeLoc TL(Qualifier.getAsType(), TypeData);
221 }
222 }
223
224 llvm_unreachable("Invalid NNS Kind!");
225}
226
230
234
235
236
240
241
242
246
250
251}
252
253namespace llvm {
254
255template <> struct DenseMapInfo<clang::NestedNameSpecifier> {
257
261
263 return hash_combine(V.getAsVoidPointer());
264 }
265};
266
267template <> struct DenseMapInfo<clang::NestedNameSpecifierLoc> {
268 using FirstInfo = DenseMapInfoclang::NestedNameSpecifier;
270
273 SecondInfo::getEmptyKey());
274 }
275
278 SecondInfo::getTombstoneKey());
279 }
280
282 return hash_combine(
284 SecondInfo::getHashValue(PairVal.getOpaqueData()));
285 }
286
289 return LHS == RHS;
290 }
291};
292}
293
294#endif
static Decl::Kind getKind(const Decl *D)
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ struct/union/class.
Decl - This represents one declaration (or definition), e.g.
Represents C++ namespaces and their aliases.
NamespaceDecl * getNamespace()
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covered by this nested-name-specifier.
Definition NestedNameSpecifier.h:247
A C++ nested-name-specifier augmented with source location information.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
Definition NestedNameSpecifier.h:179
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
Definition NestedNameSpecifier.h:243
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Definition NestedNameSpecifier.h:227
NestedNameSpecifierLoc()=default
Construct an empty nested-name-specifier.
NamespaceAndPrefixLoc castAsNamespaceAndPrefix() const
For a nested-name-specifier that refers to a namespace, retrieve the namespace and its prefix.
Definition NestedNameSpecifier.h:174
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
Definition NestedNameSpecifier.h:231
TypeLoc getAsTypeLoc() const
Definition NestedNameSpecifier.h:139
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
Definition NestedNameSpecifier.h:135
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier,...
Definition NestedNameSpecifier.h:199
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Definition NestedNameSpecifier.h:237
unsigned getDataLength() const
Determines the data length for the entire nested-name-specifier.
Definition NestedNameSpecifier.h:195
Represents a C++ nested name specifier, such as "\::std::vector::".
NestedNameSpecifier getCanonical() const
Retrieves the "canonical" nested name specifier for a given nested name specifier.
Definition NestedNameSpecifier.h:110
CXXRecordDecl * getAsMicrosoftSuper() const
Kind getKind() const
Definition NestedNameSpecifier.h:24
NamespaceAndPrefix getAsNamespaceAndPrefix() const
bool isCanonical() const
Whether this nested name specifier is canonical.
Definition NestedNameSpecifier.h:131
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
Definition NestedNameSpecifier.h:96
static constexpr NestedNameSpecifier getInvalid()
const Type * getAsType() const
Kind
The kind of specifier that completes this nested name specifier.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Base wrapper for a particular "section" of type source info.
SourceLocation getBeginLoc() const
Get the begin source location.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
const NamespaceBaseDecl * Namespace
static bool isEqual(const clang::NestedNameSpecifierLoc &LHS, const clang::NestedNameSpecifierLoc &RHS)
Definition NestedNameSpecifier.h:287
DenseMapInfo< void * > SecondInfo
Definition NestedNameSpecifier.h:269
static unsigned getHashValue(const clang::NestedNameSpecifierLoc &PairVal)
Definition NestedNameSpecifier.h:281
static clang::NestedNameSpecifierLoc getEmptyKey()
Definition NestedNameSpecifier.h:271
static clang::NestedNameSpecifierLoc getTombstoneKey()
Definition NestedNameSpecifier.h:276
DenseMapInfo< clang::NestedNameSpecifier > FirstInfo
Definition NestedNameSpecifier.h:268
static clang::NestedNameSpecifier getEmptyKey()
Definition NestedNameSpecifier.h:256
static unsigned getHashValue(const clang::NestedNameSpecifier &V)
Definition NestedNameSpecifier.h:262
static clang::NestedNameSpecifier getTombstoneKey()
Definition NestedNameSpecifier.h:258