clang: include/clang/AST/DeclContextInternals.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_AST_DECLCONTEXTINTERNALS_H

15#define LLVM_CLANG_AST_DECLCONTEXTINTERNALS_H

16

22#include "llvm/ADT/DenseMap.h"

23#include "llvm/ADT/PointerIntPair.h"

24#include "llvm/ADT/PointerUnion.h"

25#include

26

28

29class DependentDiagnostic;

30

31

32

35

36

37

38 using DeclsAndHasExternalTy = llvm::PointerIntPair<Decls, 1, bool>;

39

40

41

42

43 DeclsAndHasExternalTy Data;

44

46 Decls List = Data.getPointer();

47

48 if (!List)

49 return nullptr;

50

55 while (true) {

57 NewLast = NewTail;

58 *NewTail = List;

60 NewTail = &Node->Rest;

61 List = Node->Rest;

62 } else {

63 break;

64 }

66 List = N->Rest;

67 C.DeallocateDeclListNode(N);

68 } else {

69

70

71

72 if (NewLast) {

74 *NewLast = Node->D;

75 C.DeallocateDeclListNode(Node);

76 }

77 break;

78 }

79 }

80 Data.setPointer(NewHead);

81

82 assert(llvm::none_of(getLookupResult(), ShouldErase) && "Still exists!");

83

84 if (Data.getPointer())

85

86 return nullptr;

87 else if (isa<NamedDecl *>(NewHead))

88

90 else {

91 assert(NewLast && isa<NamedDecl *>(*NewLast) && "Not the tail?");

92 return NewLast;

93 }

94 }

95

97 erase_if([ND](NamedDecl *D) { return D == ND; });

98 }

99

100public:

102

104 RHS.Data.setPointer(nullptr);

105 RHS.Data.setInt(false);

106 }

107

110 return;

111

113 Decls List = Data.getPointer();

115 List = ToDealloc->Rest;

116 C.DeallocateDeclListNode(ToDealloc);

117 }

118 }

119

122 }

123

126

127 Data = RHS.Data;

128 RHS.Data.setPointer(nullptr);

129 RHS.Data.setInt(false);

130 return *this;

131 }

132

133 bool isNull() const { return Data.getPointer().isNull(); }

134

136 assert(isNull() && "No ASTContext.");

140 }

141

143

146 }

147

150 }

151

154 }

155

157 Data.setInt(true);

158 }

159

161 assert(isNull() && "removing from empty list");

162 erase(D);

163 }

164

165

168

169

170 Data.setInt(false);

171 }

172

174

175

178 return true;

179

181

182

184 D->declarationReplaces(ND, false))

185 return true;

186 return false;

187 });

188

189

190 Data.setInt(false);

191

192 if (Decls.empty())

193 return;

194

195

196 ASTContext &C = Decls.front()->getASTContext();

198 for (size_t I = Decls.size() - 1; I != 0; --I) {

200 Node->Rest = DeclsAsList;

201 DeclsAsList = Node;

202 }

203

204 if (Data.getPointer()) {

205 Data.setPointer(DeclsAsList);

206 return;

207 }

208

209

210 DeclListNode *Node = C.AllocateDeclListNode(cast<NamedDecl *>(*Tail));

211 Node->Rest = DeclsAsList;

212 *Tail = Node;

213 }

214

215

218 }

219

220

221

223 const bool IsKnownNewer = true;

224

226 Data.setPointer(D);

227 return;

228 }

229

230

232 if (D->declarationReplaces(OldD, IsKnownNewer)) {

233 Data.setPointer(D);

234 return;

235 }

236

237

242 return;

243 }

244

245

246

247 assert(!llvm::is_contained(getLookupResult(), D) && "Already exists!");

248

251 if (D->declarationReplaces(N->D, IsKnownNewer)) {

252 N->D = D;

253 return;

254 }

255 if (auto *ND = N->Rest.dyn_cast<NamedDecl *>()) {

256 if (D->declarationReplaces(ND, IsKnownNewer)) {

257 N->Rest = D;

258 return;

259 }

260

261

264 N->Rest = Node;

266 return;

267 }

268 }

269 }

270

271

274 Data.setPointer(D);

275 return;

276 }

277

280 Node->Rest = Data.getPointer();

282 }

283

284 LLVM_DUMP_METHOD void dump() const {

285 Decls D = Data.getPointer();

286 if (D) {

287 llvm::errs() << "\n";

288 return;

289 }

290

291 while (true) {

293 llvm::errs() << '[' << Node->D << "] -> ";

295 } else {

296 llvm::errs() << '[' << cast<NamedDecl *>(D) << "]\n";

297 return;

298 }

299 }

300 }

301};

302

304 : public llvm::SmallDenseMap<DeclarationName, StoredDeclsList, 4> {

305 friend class ASTContext;

307

308 llvm::PointerIntPair<StoredDeclsMap*, 1> Previous;

309public:

311};

312

314 friend class DeclContext;

316

318public:

320};

321

322}

323

324#endif

Defines the clang::ASTContext interface.

Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

The results of name lookup within a DeclContext.

DeclContext - This is used only as base class of specific decl types that can act as declaration cont...

DeclContextLookupResult lookup_result

A list storing NamedDecls in the lookup tables.

llvm::PointerUnion< NamedDecl *, DeclListNode * > Decls

ASTContext & getASTContext() const LLVM_READONLY

ModuleOwnershipKind getModuleOwnershipKind() const

Get the kind of module ownership for this declaration.

bool isFromASTFile() const

Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...

A dependently-generated diagnostic.

DependentStoredDeclsMap()=default

This represents a decl that may have a name.

An array of decls optimized for the common case of only containing one entry.

void setHasExternalDecls()

DeclsAndHasExternalTy getAsListAndHasExternal() const

DeclListNode * getAsList() const

StoredDeclsList(StoredDeclsList &&RHS)

void addOrReplaceDecl(NamedDecl *D)

If this is a redeclaration of an existing decl, replace the old one with D.

bool hasExternalDecls() const

NamedDecl * getAsDecl() const

void prependDeclNoReplace(NamedDecl *D)

Add a declaration to the list without checking if it replaces anything.

void replaceExternalDecls(ArrayRef< NamedDecl * > Decls)

void remove(NamedDecl *D)

ASTContext & getASTContext()

StoredDeclsList()=default

void removeExternalDecls()

Remove any declarations which were imported from an external AST source.

DeclContext::lookup_result getLookupResult() const

Return the list of all the decls.

LLVM_DUMP_METHOD void dump() const

StoredDeclsList & operator=(StoredDeclsList &&RHS)

static void DestroyAll(StoredDeclsMap *Map, bool Dependent)

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

for(const auto &A :T->param_types())