14#ifndef LLVM_CLANG_AST_NESTEDNAMESPECIFIERBASE_H
15#define LLVM_CLANG_AST_NESTEDNAMESPECIFIERBASE_H
20#include "llvm/ADT/FoldingSet.h"
21#include "llvm/Support/Compiler.h"
22#include "llvm/Support/PointerLikeTypeTraits.h"
34class NamespaceBaseDecl;
39struct NamespaceAndPrefix;
40struct alignas(8) NamespaceAndPrefixStorage;
52 enum class FlagKind { Null,
Global, Invalid };
53 enum class StoredKind {
57 NamespaceWithNamespace
59 static constexpr uintptr_t FlagBits = 2, FlagMask = (1u << FlagBits) - 1u,
60 FlagOffset = 1, PtrOffset = FlagBits + FlagOffset,
61 PtrMask = (1u << PtrOffset) - 1u;
66 : StoredOrFlag(StoredOrFlag) {}
73 assert(PK.Ptr !=
nullptr);
74 assert((
uintptr_t(PK.Ptr) & ((1u << PtrOffset) - 1u)) == 0);
75 assert((
uintptr_t(PK.Ptr) >> PtrOffset) != 0);
79 : StoredOrFlag(
uintptr_t(K) << FlagOffset) {}
81 bool isStoredKind()
const {
return (StoredOrFlag >> PtrOffset) != 0; }
83 std::pair<StoredKind, const void *> getStored()
const {
84 assert(isStoredKind());
85 return {StoredKind(StoredOrFlag >> FlagOffset & FlagMask),
86 reinterpret_cast<const void *
>(StoredOrFlag & ~PtrMask)};
89 FlagKind getFlagKind()
const {
90 assert(!isStoredKind());
91 return FlagKind(StoredOrFlag >> FlagOffset);
95 MakeNamespaceAndPrefixStorage(
const ASTContext &Ctx,
98 static inline PtrKind MakeNamespacePtrKind(
const ASTContext &Ctx,
148 explicit operator bool()
const {
return StoredOrFlag != 0; }
151 return reinterpret_cast<void *
>(StoredOrFlag);
158 auto [
Kind, Ptr] = getStored();
159 assert(
Kind == StoredKind::Type);
160 assert(Ptr !=
nullptr);
161 return static_cast<const Type *
>(Ptr);
167 auto [
Kind, Ptr] = getStored();
168 assert(
Kind == StoredKind::NamespaceOrSuper);
169 assert(Ptr !=
nullptr);
170 return static_cast<CXXRecordDecl *
>(
const_cast<void *
>(Ptr));
178 return LHS.StoredOrFlag == RHS.StoredOrFlag;
181 return LHS.StoredOrFlag != RHS.StoredOrFlag;
220 return getDependence() & NestedNameSpecifierDependence::Dependent;
226 return getDependence() & NestedNameSpecifierDependence::Instantiation;
232 return getDependence() & NestedNameSpecifierDependence::UnexpandedPack;
237 return getDependence() & NestedNameSpecifierDependence::Error;
245 bool ResolveTemplateArguments =
false,
246 bool PrintFinalScopeResOp =
true)
const;
249 ID.AddInteger(StoredOrFlag);
253 void dump(llvm::raw_ostream *OS =
nullptr,
256 void dump(llvm::raw_ostream &OS)
const;
268 llvm::FoldingSetNode {
282 auto [
Kind, Ptr] = getStored();
284 case StoredKind::NamespaceOrSuper:
285 case StoredKind::NamespaceWithGlobal:
287 Kind == StoredKind::NamespaceWithGlobal
290 case StoredKind::NamespaceWithNamespace:
292 case StoredKind::Type:;
294 llvm_unreachable(
"unexpected stored kind");
303 void *Data =
nullptr;
309 memcpy(&Raw,
static_cast<char *
>(
Data) + Offset,
sizeof(Raw));
315 void *LoadPointer(
unsigned Offset)
const {
336 : Qualifier(Qualifier),
Data(
Data) {}
340 explicit operator bool()
const {
return bool(Qualifier); }
405 return X.Qualifier == Y.Qualifier &&
X.Data == Y.Data;
434 char *Buffer =
nullptr;
438 unsigned BufferSize = 0;
442 unsigned BufferCapacity = 0;
515 Representation = Qualifier;
517 PushTrivial(Context, Qualifier, R);
546 Representation = std::nullopt;
556 return std::make_pair(Buffer, BufferSize);
575 return P.getAsVoidPointer();
580 static constexpr int NumLowBitsAvailable =
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 *.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents C++ namespaces and their aliases.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
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.
NestedNameSpecifierLocBuilder()=default
void Clear()
Clear out this builder, and prepare it to build another nested-name-specifier with source-location in...
NestedNameSpecifierLoc getTemporary() const
Retrieve a nested-name-specifier with location information based on the information in this builder.
std::pair< char *, unsigned > getBuffer() const
Retrieve the underlying buffer.
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.
~NestedNameSpecifierLocBuilder()
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.
NamespaceAndPrefixLoc getAsNamespaceAndPrefix() const
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.
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.
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)
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.
bool hasQualifier() const
Evaluates true when this nested-name-specifier location is non-empty.
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<int>::".
static constexpr NestedNameSpecifier getGlobal()
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
bool isInstantiationDependent() const
Whether this nested name specifier involves a template parameter.
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
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...
void Profile(llvm::FoldingSetNodeID &ID) const
NestedNameSpecifier(std::nullopt_t)
static constexpr auto NumLowBitsAvailable
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)
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.
friend bool operator==(NestedNameSpecifier LHS, NestedNameSpecifier RHS)
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
static constexpr NestedNameSpecifier getInvalid()
friend bool operator!=(NestedNameSpecifier LHS, NestedNameSpecifier RHS)
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.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
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.
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
@ Result
The result type of a method or function.
const FunctionProtoType * T
@ 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
NestedNameSpecifierLoc Prefix
static void Profile(llvm::FoldingSetNodeID &ID, const NamespaceBaseDecl *Namespace, NestedNameSpecifier Prefix)
NamespaceAndPrefixStorage(const NamespaceBaseDecl *Namespace, NestedNameSpecifier Prefix)
void Profile(llvm::FoldingSetNodeID &ID)
const NamespaceBaseDecl * Namespace
NestedNameSpecifier Prefix
Describes how types, statements, expressions, and declarations should be printed.
static void * getAsVoidPointer(clang::NestedNameSpecifier P)
static clang::NestedNameSpecifier getFromVoidPointer(const void *P)