clang: lib/AST/NestedNameSpecifier.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

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"

30#include

31#include

32#include

33#include

34

35using namespace clang;

36

38NestedNameSpecifier::MakeNamespaceAndPrefixStorage(

41 llvm::FoldingSetNodeID ID;

43

44 void *InsertPos = nullptr;

45 NamespaceAndPrefixStorage *S =

46 Ctx.NamespaceAndPrefixStorages.FindNodeOrInsertPos(ID, InsertPos);

47 if (!S) {

48 S = new (Ctx, alignof(NamespaceAndPrefixStorage))

49 NamespaceAndPrefixStorage(Namespace, Prefix);

50 Ctx.NamespaceAndPrefixStorages.InsertNode(S, InsertPos);

51 }

52 return S;

53}

54

58 return true;

61 return false;

66 }

67 llvm_unreachable("Invalid NNS Kind!");

68}

69

75 return NestedNameSpecifierDependence::None;

79 ? NestedNameSpecifierDependence::DependentInstantiation |

80 NestedNameSpecifierDependence::Dependent

81 : NestedNameSpecifierDependence::None;

82 }

85 }

86 llvm_unreachable("Invalid NNS Kind!");

87}

88

89

90

92 bool ResolveTemplateArguments,

93 bool PrintFinalScopeResOp) const {

97 Prefix.print(OS, Policy);

98 if (const auto *NS = dyn_cast(Namespace)) {

99 assert(!NS->isAnonymousNamespace());

100 OS << NS->getName();

101 } else {

102 OS << cast(Namespace)->getName();

103 }

104 break;

105 }

107 OS << "::";

108 return;

110 OS << "__super";

111 break;

116 break;

117 }

119 return;

120 }

121 if (PrintFinalScopeResOp)

122 OS << "::";

123}

124

129

131 dump(nullptr, &LO);

132}

140

142 if (!Qualifier)

144

148 return First.getLocalSourceRange().getBegin();

149}

150

151static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize,

152 unsigned &BufferCapacity) {

153 if (Start == End)

154 return;

155

156 if (BufferSize + (End - Start) > BufferCapacity) {

157

158 unsigned NewCapacity = std::max(

159 (unsigned)(BufferCapacity ? BufferCapacity * 2 : sizeof(void *) * 2),

160 (unsigned)(BufferSize + (End - Start)));

161 if (!BufferCapacity) {

162 char *NewBuffer = static_cast<char *>(llvm::safe_malloc(NewCapacity));

163 if (Buffer)

164 memcpy(NewBuffer, Buffer, BufferSize);

165 Buffer = NewBuffer;

166 } else {

167 Buffer = static_cast<char *>(llvm::safe_realloc(Buffer, NewCapacity));

168 }

169 BufferCapacity = NewCapacity;

170 }

171 assert(Buffer && Start && End && End > Start && "Illegal memory buffer copy");

172 memcpy(Buffer + BufferSize, Start, End - Start);

173 BufferSize += End - Start;

174}

175

176

178 unsigned &BufferSize, unsigned &BufferCapacity) {

180 Append(reinterpret_cast<char *>(&Raw),

181 reinterpret_cast<char *>(&Raw) + sizeof(Raw), Buffer, BufferSize,

182 BufferCapacity);

183}

184

185

186static void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize,

187 unsigned &BufferCapacity) {

188 Append(reinterpret_cast<char *>(&Ptr),

189 reinterpret_cast<char *>(&Ptr) + sizeof(void *),

190 Buffer, BufferSize, BufferCapacity);

191}

192

195 : Representation(Other.Representation) {

196 if (Other.Buffer)

197 return;

198

199 if (Other.BufferCapacity == 0) {

200

201 Buffer = Other.Buffer;

202 BufferSize = Other.BufferSize;

203 return;

204 }

205

206

208 BufferCapacity);

209}

210

214 Representation = Other.Representation;

215

216 if (Buffer && Other.Buffer && BufferCapacity >= Other.BufferSize) {

217

218 BufferSize = Other.BufferSize;

219 memcpy(Buffer, Other.Buffer, BufferSize);

220 return *this;

221 }

222

223

224 if (BufferCapacity) {

225 free(Buffer);

226 BufferCapacity = 0;

227 }

228

229 if (Other.Buffer) {

230

231 Buffer = nullptr;

232 BufferSize = 0;

233 return *this;

234 }

235

236 if (Other.BufferCapacity == 0) {

237

238 Buffer = Other.Buffer;

239 BufferSize = Other.BufferSize;

240 return *this;

241 }

242

243

244 BufferSize = 0;

246 BufferCapacity);

247 return *this;

248}

249

252 assert(!Representation);

254

255

257 SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);

258}

259

270

273 assert(!Representation && "Already have a nested-name-specifier!?");

275

276

277 SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity);

278}

279

289

290void NestedNameSpecifierLocBuilder::PushTrivial(ASTContext &Context,

293

294

295 switch (Qualifier.getKind()) {

297 return;

299 auto [_1, Prefix] = Qualifier.getAsNamespaceAndPrefix();

300 PushTrivial(Context, Prefix, R.getBegin());

302 break;

303 }

305 TypeSourceInfo *TSInfo = Context.getTrivialTypeSourceInfo(

308 BufferCapacity);

309 break;

310 }

313 break;

314 }

316}

317

319 if (BufferCapacity)

320 free(Buffer);

321

323 Representation = std::nullopt;

324 BufferSize = 0;

325 return;

326 }

327

328

329

330

331 Representation = Other.getNestedNameSpecifier();

332 Buffer = static_cast<char *>(Other.getOpaqueData());

333 BufferSize = Other.getDataLength();

334 BufferCapacity = 0;

335}

336

339 if (!Representation)

341

342

343

344 if (BufferCapacity == 0)

346

347

348

349

350 void *Mem = Context.Allocate(BufferSize, alignof(void *));

351 memcpy(Mem, Buffer, BufferSize);

353}

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)

Definition NestedNameSpecifier.cpp:151

static void SaveSourceLocation(SourceLocation Loc, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)

Save a source location to the given buffer.

Definition NestedNameSpecifier.cpp:177

static void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize, unsigned &BufferCapacity)

Save a pointer to the given buffer.

Definition NestedNameSpecifier.cpp:186

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).

Definition NestedNameSpecifier.cpp:318

NestedNameSpecifierLocBuilder & operator=(const NestedNameSpecifierLocBuilder &Other)

Definition NestedNameSpecifier.cpp:213

void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)

Make a nested-name-specifier of the form 'type::'.

Definition NestedNameSpecifier.cpp:250

void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)

Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.

Definition NestedNameSpecifier.cpp:280

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...

Definition NestedNameSpecifier.cpp:260

void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)

Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.

Definition NestedNameSpecifier.cpp:271

NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const

Retrieve a nested-name-specifier with location information, copied into the given AST context.

Definition NestedNameSpecifier.cpp:338

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.

Definition NestedNameSpecifier.cpp:141

Represents a C++ nested name specifier, such as "\::std::vector::".

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.

Definition NestedNameSpecifier.cpp:125

CXXRecordDecl * getAsMicrosoftSuper() const

NamespaceAndPrefix getAsNamespaceAndPrefix() const

bool isFullyQualified() const

Whether this nested name specifier starts with a '::'.

Definition NestedNameSpecifier.cpp:55

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.

Definition NestedNameSpecifier.cpp:91

NestedNameSpecifierDependence getDependence() const

Definition NestedNameSpecifier.cpp:70

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.

SourceLocation getEnd() const

SourceLocation getBegin() const

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.

The JSON file list parser is used to communicate input to InstallAPI.

if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))

NestedNameSpecifierDependence toNestedNameSpecifierDependence(TypeDependence D)

@ Other

Other implicit parameter.

void Profile(llvm::FoldingSetNodeID &ID)

NestedNameSpecifier Prefix

Describes how types, statements, expressions, and declarations should be printed.

unsigned SuppressTagKeyword

Whether type printing should skip printing the tag keyword.