clang: include/clang/AST/NestedNameSpecifierBase.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_AST_NESTEDNAMESPECIFIERBASE_H
15#define LLVM_CLANG_AST_NESTEDNAMESPECIFIERBASE_H
16
20#include "llvm/ADT/FoldingSet.h"
21#include "llvm/Support/Compiler.h"
22#include "llvm/Support/PointerLikeTypeTraits.h"
23#include
24#include
25#include
26
28
38
41
42
43
44
45
46
47
48
49
50
51class NestedNameSpecifier {
52 enum class FlagKind { Null, Global, Invalid };
53 enum class StoredKind {
54 Type,
55 NamespaceOrSuper,
56 NamespaceWithGlobal,
57 NamespaceWithNamespace
58 };
59 static constexpr uintptr_t FlagBits = 2, FlagMask = (1u << FlagBits) - 1u,
60 FlagOffset = 1, PtrOffset = FlagBits + FlagOffset,
61 PtrMask = (1u << PtrOffset) - 1u;
62
64
66 : StoredOrFlag(StoredOrFlag) {}
67 struct PtrKind {
68 StoredKind SK;
69 const void *Ptr;
70 };
72 : StoredOrFlag(uintptr_t(PK.Ptr) | (uintptr_t(PK.SK) << FlagOffset)) {
73 assert(PK.Ptr != nullptr);
74 assert((uintptr_t(PK.Ptr) & ((1u << PtrOffset) - 1u)) == 0);
75 assert((uintptr_t(PK.Ptr) >> PtrOffset) != 0);
76 }
77
79 : StoredOrFlag(uintptr_t(K) << FlagOffset) {}
80
81 bool isStoredKind() const { return (StoredOrFlag >> PtrOffset) != 0; }
82
83 std::pair<StoredKind, const void *> getStored() const {
84 assert(isStoredKind());
85 return {StoredKind(StoredOrFlag >> FlagOffset & FlagMask),
86 reinterpret_cast<const void *>(StoredOrFlag & ~PtrMask)};
87 }
88
89 FlagKind getFlagKind() const {
90 assert(!isStoredKind());
91 return FlagKind(StoredOrFlag >> FlagOffset);
92 }
93
95 MakeNamespaceAndPrefixStorage(const ASTContext &Ctx,
97 NestedNameSpecifier Prefix);
98 static inline PtrKind MakeNamespacePtrKind(const ASTContext &Ctx,
100 NestedNameSpecifier Prefix);
101
102public:
106
107 static constexpr NestedNameSpecifier getGlobal() {
109 }
110
112
113
114
116
118
119
121
122
124
125
127
128
129
131 };
132
133 inline Kind getKind() const;
134
136
138
139
143
144
145
147
148 explicit operator bool() const { return StoredOrFlag != 0; }
149
151 return reinterpret_cast<void *>(StoredOrFlag);
152 }
156
158 auto [Kind, Ptr] = getStored();
159 assert(Kind == StoredKind::Type);
160 assert(Ptr != nullptr);
161 return static_cast<const Type *>(Ptr);
162 }
163
165
167 auto [Kind, Ptr] = getStored();
168 assert(Kind == StoredKind::NamespaceOrSuper);
169 assert(Ptr != nullptr);
170 return static_cast<CXXRecordDecl *>(const_cast<void *>(Ptr));
171 }
172
173
174
176
177 friend bool operator==(NestedNameSpecifier LHS, NestedNameSpecifier RHS) {
178 return LHS.StoredOrFlag == RHS.StoredOrFlag;
179 }
180 friend bool operator!=(NestedNameSpecifier LHS, NestedNameSpecifier RHS) {
181 return LHS.StoredOrFlag != RHS.StoredOrFlag;
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
208
209
211
212
214
215 NestedNameSpecifierDependence getDependence() const;
216
217
218
220 return getDependence() & NestedNameSpecifierDependence::Dependent;
221 }
222
223
224
226 return getDependence() & NestedNameSpecifierDependence::Instantiation;
227 }
228
229
230
232 return getDependence() & NestedNameSpecifierDependence::UnexpandedPack;
233 }
234
235
237 return getDependence() & NestedNameSpecifierDependence::Error;
238 }
239
240
241
242
243
245 bool ResolveTemplateArguments = false,
246 bool PrintFinalScopeResOp = true) const;
247
248 void Profile(llvm::FoldingSetNodeID &ID) const {
249 ID.AddInteger(StoredOrFlag);
250 }
251
252
253 void dump(llvm::raw_ostream *OS = nullptr,
256 void dump(llvm::raw_ostream &OS) const;
257 void dump(llvm::raw_ostream &OS, const LangOptions &LO) const;
258
260};
261
266
268 llvm::FoldingSetNode {
273 static void Profile(llvm::FoldingSetNodeID &ID,
278 }
279};
280
282 auto [Kind, Ptr] = getStored();
283 switch (Kind) {
284 case StoredKind::NamespaceOrSuper:
285 case StoredKind::NamespaceWithGlobal:
287 Kind == StoredKind::NamespaceWithGlobal
289 : std::nullopt};
290 case StoredKind::NamespaceWithNamespace:
292 case StoredKind::Type:;
293 }
294 llvm_unreachable("unexpected stored kind");
295}
296
298
299
300
303 void *Data = nullptr;
304
305
306
307 SourceLocation LoadSourceLocation(unsigned Offset) const {
309 memcpy(&Raw, static_cast<char *>(Data) + Offset, sizeof(Raw));
311 }
312
313
314
315 void *LoadPointer(unsigned Offset) const {
317 memcpy(&Result, static_cast<char *>(Data) + Offset, sizeof(void *));
319 }
320
321
322
323 static inline unsigned getLocalDataLength(NestedNameSpecifier Qualifier);
324
325
326
328
329public:
330
332
333
334
336 : Qualifier(Qualifier), Data(Data) {}
337
338
339
340 explicit operator bool() const { return bool(Qualifier); }
341
342
343
345
346
347
349
350
352
353
354
355
356
357
358
360
361
362
363
364
365
366
367
368
369
371
372
373
375
376
377
379
380
381
383
384
385
387
388
389
390
391
392
393
394
397
398
399
402
403
404
406
408 return X.Qualifier == Y.Qualifier && X.Data == Y.Data;
409 }
410
412 return !(X == Y);
413 }
414};
415
422
423
424
425
427
428
430
431
432
433
434
435
436
437 char *Buffer = nullptr;
438
439
440
441 unsigned BufferSize = 0;
442
443
444
445 unsigned BufferCapacity = 0;
446
449
450public:
453
456
458 if (BufferCapacity)
459 free(Buffer);
460 }
461
462
464
465
466
467
468
469
470
471
472
474
475
476
477
478
479
480
481
482
483
484
485
488
489
490
492
493
494
495
496
497
498
499
500
501
502
503
504
505
509
510
511
512
513
514
515
518 Representation = Qualifier;
519 BufferSize = 0;
520 PushTrivial(Context, Qualifier, R);
521 }
522
523
524
526
527
529
530
531
532
533
534
536
537
538
539
540
541
545
546
547
549 Representation = std::nullopt;
550 BufferSize = 0;
551 }
552
553
554
555
556
557
558 std::pair<char *, unsigned> getBuffer() const {
559 return std::make_pair(Buffer, BufferSize);
560 }
561};
562
563
564
571
572}
573
574namespace llvm {
575
586
587}
588
589#endif
Defines the Diagnostic-related interfaces.
Defines the clang::SourceLocation class and associated facilities.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Represents a C++ struct/union/class.
@ ak_nestednamespec
NestedNameSpecifier *.
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
This represents a decl that may have a name.
Represents C++ namespaces and their aliases.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
NestedNameSpecifierLocBuilder & operator=(const NestedNameSpecifierLocBuilder &Other)
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition NestedNameSpecifierBase.h:516
NestedNameSpecifierLocBuilder()=default
void Clear()
Clear out this builder, and prepare it to build another nested-name-specifier with source-location in...
Definition NestedNameSpecifierBase.h:548
NestedNameSpecifierLoc getTemporary() const
Retrieve a nested-name-specifier with location information based on the information in this builder.
Definition NestedNameSpecifierBase.h:542
std::pair< char *, unsigned > getBuffer() const
Retrieve the underlying buffer.
Definition NestedNameSpecifierBase.h:558
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covered by this nested-name-specifier.
NestedNameSpecifier getRepresentation() const
Retrieve the representation of the nested-name-specifier.
Definition NestedNameSpecifierBase.h:463
~NestedNameSpecifierLocBuilder()
Definition NestedNameSpecifierBase.h:457
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
Definition NestedNameSpecifierBase.h:301
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
Definition NestedNameSpecifierBase.h:348
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
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.
NestedNameSpecifierLoc(NestedNameSpecifier Qualifier, void *Data)
Construct a nested-name-specifier with source location information from.
Definition NestedNameSpecifierBase.h:335
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
TypeLoc getAsTypeLoc() const
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
friend bool operator!=(NestedNameSpecifierLoc X, NestedNameSpecifierLoc Y)
Definition NestedNameSpecifierBase.h:411
TypeLoc castAsTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
Definition NestedNameSpecifierBase.h:351
bool hasQualifier() const
Evaluates true when this nested-name-specifier location is non-empty.
Definition NestedNameSpecifierBase.h:344
SourceRange getLocalSourceRange() const
Retrieve the source range covering just the last part of this nested-name-specifier,...
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
unsigned getDataLength() const
Determines the data length for the entire nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector::".
Definition NestedNameSpecifierBase.h:51
static constexpr NestedNameSpecifier getGlobal()
Definition NestedNameSpecifierBase.h:107
void dump(llvm::raw_ostream *OS=nullptr, const LangOptions *LO=nullptr) const
Dump the nested name specifier to aid in debugging.
NestedNameSpecifier getCanonical() const
Retrieves the "canonical" nested name specifier for a given nested name specifier.
void * getAsVoidPointer() const
Definition NestedNameSpecifierBase.h:150
NestedNameSpecifier()
Definition NestedNameSpecifierBase.h:111
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
Definition NestedNameSpecifierBase.h:225
CXXRecordDecl * getAsMicrosoftSuper() const
Definition NestedNameSpecifierBase.h:166
NamespaceAndPrefix getAsNamespaceAndPrefix() const
Definition NestedNameSpecifierBase.h:281
bool isFullyQualified() const
Whether this nested name specifier starts with a '::'.
bool containsUnexpandedParameterPack() const
Whether this nested-name-specifier contains an unexpanded parameter pack (for C++11 variadic template...
Definition NestedNameSpecifierBase.h:231
void Profile(llvm::FoldingSetNodeID &ID) const
Definition NestedNameSpecifierBase.h:248
NestedNameSpecifier(std::nullopt_t)
Definition NestedNameSpecifierBase.h:135
static constexpr auto NumLowBitsAvailable
Definition NestedNameSpecifierBase.h:259
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false, bool PrintFinalScopeResOp=true) const
Print this nested name specifier to the given output stream.
static NestedNameSpecifier getFromVoidPointer(const void *Ptr)
Definition NestedNameSpecifierBase.h:153
NestedNameSpecifierDependence getDependence() const
bool isCanonical() const
Whether this nested name specifier is canonical.
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
bool containsErrors() const
Whether this nested name specifier contains an error.
Definition NestedNameSpecifierBase.h:236
friend bool operator==(NestedNameSpecifier LHS, NestedNameSpecifier RHS)
Definition NestedNameSpecifierBase.h:177
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
Definition NestedNameSpecifierBase.h:219
static constexpr NestedNameSpecifier getInvalid()
Definition NestedNameSpecifierBase.h:103
friend bool operator!=(NestedNameSpecifier LHS, NestedNameSpecifier RHS)
Definition NestedNameSpecifierBase.h:180
const Type * getAsType() const
Definition NestedNameSpecifierBase.h:157
Kind
The kind of specifier that completes this nested name specifier.
Definition NestedNameSpecifierBase.h:115
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
Definition NestedNameSpecifierBase.h:130
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Definition NestedNameSpecifierBase.h:126
Encodes a location in the source.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
A trivial tuple used to represent a source range.
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Base wrapper for a particular "section" of type source info.
The base class of the type hierarchy.
@ Extend
Lifetime-extend along this path.
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ConceptReference *C)
Insertion operator for diagnostics.
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
const NamespaceBaseDecl * Namespace
Definition NestedNameSpecifierBase.h:417
NestedNameSpecifierLoc Prefix
Definition NestedNameSpecifierBase.h:418
static void Profile(llvm::FoldingSetNodeID &ID, const NamespaceBaseDecl *Namespace, NestedNameSpecifier Prefix)
Definition NestedNameSpecifierBase.h:273
NamespaceAndPrefixStorage(const NamespaceBaseDecl *Namespace, NestedNameSpecifier Prefix)
Definition NestedNameSpecifierBase.h:269
void Profile(llvm::FoldingSetNodeID &ID)
Definition NestedNameSpecifierBase.h:272
const NamespaceBaseDecl * Namespace
Definition NestedNameSpecifierBase.h:263
NestedNameSpecifier Prefix
Definition NestedNameSpecifierBase.h:264
Describes how types, statements, expressions, and declarations should be printed.
static void * getAsVoidPointer(clang::NestedNameSpecifier P)
Definition NestedNameSpecifierBase.h:577
static clang::NestedNameSpecifier getFromVoidPointer(const void *P)
Definition NestedNameSpecifierBase.h:580
static constexpr int NumLowBitsAvailable
Definition NestedNameSpecifierBase.h:583