23#include "llvm/Support/ErrorHandling.h"
37 static const unsigned int POOL_SIZE = 512;
42 struct IdDeclInfoPool {
44 IdDeclInfo Pool[POOL_SIZE];
46 IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {}
49 IdDeclInfoPool *CurPool =
nullptr;
50 unsigned int CurIndex = POOL_SIZE;
56 IdDeclInfoPool *Cur = CurPool;
57 while (IdDeclInfoPool *
P = Cur) {
77void IdentifierResolver::IdDeclInfo::RemoveDecl(
NamedDecl *
D) {
78 for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) {
85 llvm_unreachable(
"Didn't find this decl on its identifier's chain!");
93 : LangOpt(PP.getLangOpts()), PP(PP), IdDeclInfos(new
IdDeclInfoMap) {}
103 bool AllowInlineNamespace)
const {
108 if (LangOpt.HLSL && isa<HLSLBufferDecl>(
D))
112 while (S->getEntity() &&
113 (S->getEntity()->isTransparentContext() ||
114 (!LangOpt.CPlusPlus && isa<RecordDecl>(S->getEntity()))))
117 if (S->isDeclScope(
D))
119 if (LangOpt.CPlusPlus) {
132 assert(S->getParent() &&
"No TUScope?");
135 if (S->getParent()->isControlScope() && !S->isFunctionScope()) {
137 if (S->isDeclScope(
D))
140 if (S->isFnTryCatchScope())
141 return S->getParent()->isDeclScope(
D);
158 updatingIdentifier(*II);
160 void *Ptr = Name.getFETokenInfo();
163 Name.setFETokenInfo(
D);
169 if (isDeclPtr(Ptr)) {
170 Name.setFETokenInfo(
nullptr);
171 IDI = &(*IdDeclInfos)[Name];
175 IDI = toIdDeclInfo(Ptr);
183 updatingIdentifier(*II);
185 void *Ptr = Name.getFETokenInfo();
192 if (isDeclPtr(Ptr)) {
211 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
215 IDI->InsertDecl(IDI->decls_begin(),
D);
221 assert(
D &&
"null param passed");
224 updatingIdentifier(*II);
226 void *Ptr = Name.getFETokenInfo();
228 assert(Ptr &&
"Didn't find this decl on its identifier's chain!");
230 if (isDeclPtr(Ptr)) {
231 assert(
D == Ptr &&
"Didn't find this decl on its identifier's chain!");
232 Name.setFETokenInfo(
nullptr);
236 return toIdDeclInfo(Ptr)->RemoveDecl(
D);
239llvm::iterator_range<IdentifierResolver::iterator>
246 readingIdentifier(*II);
248 void *Ptr = Name.getFETokenInfo();
249 if (!Ptr)
return end();
254 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
256 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
257 if (I != IDI->decls_begin())
283 return DMK_Different;
290 return DMK_Different;
294 if (Existing == MostRecent)
297 if (New == MostRecent)
302 for (
auto *RD : New->
redecls()) {
306 if (RD->isCanonicalDecl())
313 return DMK_Different;
318 readingIdentifier(*II);
320 void *Ptr = Name.getFETokenInfo();
323 Name.setFETokenInfo(
D);
329 if (isDeclPtr(Ptr)) {
340 Name.setFETokenInfo(
D);
344 Name.setFETokenInfo(
nullptr);
345 IDI = &(*IdDeclInfos)[Name];
359 IDI = toIdDeclInfo(Ptr);
363 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
364 IEnd = IDI->decls_end();
379 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
382 IDI->InsertDecl(I,
D);
411IdentifierResolver::IdDeclInfo &
413 void *Ptr = Name.getFETokenInfo();
415 if (Ptr)
return *toIdDeclInfo(Ptr);
417 if (CurIndex == POOL_SIZE) {
418 CurPool =
new IdDeclInfoPool(CurPool);
421 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
422 Name.setFETokenInfo(
reinterpret_cast<void*
>(
431 void *InfoPtr =
D->getDeclName().getFETokenInfo();
432 assert(!isDeclPtr(InfoPtr) &&
"Decl with wrong id ?");
433 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
436 if (I != Info->decls_begin())
static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New)
Compare two declarations to see whether they are different or, if they are the same,...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines the clang::LangOptions interface.
Defines the clang::Preprocessor interface.
IdDeclInfoMap - Associates IdDeclInfos with declaration names.
IdDeclInfoMap(const IdDeclInfoMap &)=delete
IdDeclInfoMap & operator=(const IdDeclInfoMap &)=delete
IdDeclInfo & operator[](DeclarationName Name)
Returns the IdDeclInfo associated to the DeclarationName.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool InEnclosingNamespaceSetOf(const DeclContext *NS) const
Test if this context is part of the enclosing namespace set of the context NS, as defined in C++0x [n...
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool isFunctionOrMethod() const
Decl - This represents one declaration (or definition), e.g.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
DeclContext * getDeclContext()
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
virtual void updateOutOfDateIdentifier(const IdentifierInfo &II)=0
Update an out-of-date identifier.
One of these records is kept for each identifier that is lexed.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
iterator - Iterate over the decls of a specified declaration name.
IdDeclInfo::DeclsTy::iterator BaseIter
BaseIter getIterator() const
iterator begin(DeclarationName Name)
Returns an iterator over decls with the name 'Name'.
void RemoveDecl(NamedDecl *D)
RemoveDecl - Unlink the decl from its shadowed decl chain.
IdentifierResolver(Preprocessor &PP)
void InsertDeclAfter(iterator Pos, NamedDecl *D)
Insert the given declaration after the given iterator position.
bool tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name)
Try to add the given declaration to the top level scope, if it (or a redeclaration of it) hasn't alre...
iterator end()
Returns the end iterator.
void AddDecl(NamedDecl *D)
AddDecl - Link the decl to its shadowed decl chain.
llvm::iterator_range< iterator > decls(DeclarationName Name)
Returns a range of decls with the name 'Name'.
bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S=nullptr, bool AllowInlineNamespace=false) const
isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true if 'D' is in Scope 'S',...
This represents a decl that may have a name.
NamedDecl * getMostRecentDecl()
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
ExternalPreprocessorSource * getExternalSource() const
Scope - A scope is a transient data structure that is used while parsing the program.
The JSON file list parser is used to communicate input to InstallAPI.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...