26#include "llvm/ADT/FoldingSet.h"
27#include "llvm/Support/Compiler.h"
28#include "llvm/Support/ErrorHandling.h"
29#include "llvm/Support/raw_ostream.h"
38NestedNameSpecifier::MakeNamespaceAndPrefixStorage(
41 llvm::FoldingSetInsertToken Token;
42 NamespaceAndPrefixStorage *S =
43 Ctx.NamespaceAndPrefixStorages.lookup({
Namespace, Prefix}, Token);
45 S =
new (Ctx,
alignof(NamespaceAndPrefixStorage))
46 NamespaceAndPrefixStorage(
Namespace, Prefix);
47 Ctx.NamespaceAndPrefixStorages.insert(S, Token);
64 llvm_unreachable(
"Invalid NNS Kind!");
72 return NestedNameSpecifierDependence::None;
76 ? NestedNameSpecifierDependence::DependentInstantiation |
77 NestedNameSpecifierDependence::Dependent
78 : NestedNameSpecifierDependence::None;
83 llvm_unreachable(
"Invalid NNS Kind!");
89 bool ResolveTemplateArguments,
90 bool PrintFinalScopeResOp)
const {
94 Prefix.
print(OS, Policy);
95 if (
const auto *NS = dyn_cast<NamespaceDecl>(
Namespace)) {
96 assert(!NS->isAnonymousNamespace());
99 OS << cast<NamespaceAliasDecl>(
Namespace)->getName();
118 if (PrintFinalScopeResOp)
145 return First.getLocalSourceRange().getBegin();
148static void Append(
char *Start,
char *End,
char *&Buffer,
unsigned &BufferSize,
149 unsigned &BufferCapacity) {
153 if (BufferSize + (End - Start) > BufferCapacity) {
155 unsigned NewCapacity = std::max(
156 (
unsigned)(BufferCapacity ? BufferCapacity * 2 :
sizeof(
void *) * 2),
157 (
unsigned)(BufferSize + (End - Start)));
158 if (!BufferCapacity) {
159 char *NewBuffer =
static_cast<char *
>(llvm::safe_malloc(NewCapacity));
161 memcpy(NewBuffer, Buffer, BufferSize);
164 Buffer =
static_cast<char *
>(llvm::safe_realloc(Buffer, NewCapacity));
166 BufferCapacity = NewCapacity;
168 assert(Buffer && Start && End && End > Start &&
"Illegal memory buffer copy");
169 memcpy(Buffer + BufferSize, Start, End - Start);
170 BufferSize += End - Start;
175 unsigned &BufferSize,
unsigned &BufferCapacity) {
177 Append(
reinterpret_cast<char *
>(&Raw),
178 reinterpret_cast<char *
>(&Raw) +
sizeof(Raw), Buffer, BufferSize,
183static void SavePointer(
void *Ptr,
char *&Buffer,
unsigned &BufferSize,
184 unsigned &BufferCapacity) {
185 Append(
reinterpret_cast<char *
>(&Ptr),
186 reinterpret_cast<char *
>(&Ptr) +
sizeof(
void *),
187 Buffer, BufferSize, BufferCapacity);
192 : Representation(
Other.Representation) {
196 if (
Other.BufferCapacity == 0) {
198 Buffer = Other.Buffer;
199 BufferSize = Other.BufferSize;
210 : Representation(
std::move(
Other.Representation)),
212 BufferSize(
std::exchange(
Other.BufferSize, 0)),
213 BufferCapacity(
std::exchange(
Other.BufferCapacity, 0)) {}
218 Representation =
Other.Representation;
220 if (Buffer &&
Other.Buffer && BufferCapacity >=
Other.BufferSize) {
222 BufferSize =
Other.BufferSize;
228 if (BufferCapacity) {
240 if (
Other.BufferCapacity == 0) {
242 Buffer =
Other.Buffer;
243 BufferSize =
Other.BufferSize;
256 Representation = std::move(
Other.Representation);
259 if (BufferCapacity) {
262 Buffer = std::exchange(
Other.Buffer,
nullptr);
263 BufferSize = std::exchange(
Other.BufferSize, 0);
264 BufferCapacity = std::exchange(
Other.BufferCapacity, 0);
271 assert(!Representation);
292 assert(!Representation &&
"Already have a nested-name-specifier!?");
309void NestedNameSpecifierLocBuilder::PushTrivial(
ASTContext &Context,
314 switch (Qualifier.getKind()) {
318 auto [_1, Prefix] = Qualifier.getAsNamespaceAndPrefix();
319 PushTrivial(Context, Prefix, R.getBegin());
325 QualType(Qualifier.getAsType(), 0), R.getBegin());
342 Representation = std::nullopt;
350 Representation =
Other.getNestedNameSpecifier();
351 Buffer =
static_cast<char *
>(
Other.getOpaqueData());
352 BufferSize =
Other.getDataLength();
363 if (BufferCapacity == 0)
369 void *Mem = Context.Allocate(BufferSize,
alignof(
void *));
370 memcpy(Mem, Buffer, BufferSize);
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
static void SaveSourceLocation(SourceLocation Loc, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
Save a source location to the given buffer.
static void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)
Save a pointer to the given buffer.
Defines the clang::SourceLocation class and associated facilities.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
__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.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
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 Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
NestedNameSpecifierLocBuilder()=default
void Extend(ASTContext &Context, const NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
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.
NestedNameSpecifierLoc()=default
Construct an empty nested-name-specifier.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this 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.
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
bool isFullyQualified() const
Whether this nested name specifier starts with a '::'.
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.
NestedNameSpecifierDependence getDependence() const
const Type * getAsType() const
@ 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*.
A (possibly-)qualified type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Encodes a location in the source.
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
A trivial tuple used to represent a source range.
Base wrapper for a particular "section" of type source info.
void * getOpaqueData() const
Get the pointer where source information is stored.
const Type * getTypePtr() const
A container of type source information.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
NestedNameSpecifier getPrefix() const
If this type represents a qualified-id, this returns its nested name specifier.
Top level wrappers for InstallAPI frontend operations.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
NestedNameSpecifierDependence toNestedNameSpecifierDependence(TypeDependence D)
@ Other
Other implicit parameter.
NestedNameSpecifier Prefix
Describes how types, statements, expressions, and declarations should be printed.
unsigned SuppressTagKeyword
Whether type printing should skip printing the tag keyword.