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() && S->getEntity()->isTransparentContext())
115 if (S->isDeclScope(D))
117 if (LangOpt.CPlusPlus) {
130 assert(S->getParent() &&
"No TUScope?");
133 if (S->getParent()->isControlScope() && !S->isFunctionScope()) {
135 if (S->isDeclScope(D))
138 if (S->isFnTryCatchScope())
139 return S->getParent()->isDeclScope(D);
156 updatingIdentifier(*II);
158 void *Ptr = Name.getFETokenInfo();
161 Name.setFETokenInfo(D);
167 if (isDeclPtr(Ptr)) {
168 Name.setFETokenInfo(
nullptr);
169 IDI = &(*IdDeclInfos)[Name];
173 IDI = toIdDeclInfo(Ptr);
181 updatingIdentifier(*II);
183 void *Ptr = Name.getFETokenInfo();
190 if (isDeclPtr(Ptr)) {
209 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
213 IDI->InsertDecl(IDI->decls_begin(), D);
219 assert(D &&
"null param passed");
222 updatingIdentifier(*II);
224 void *Ptr = Name.getFETokenInfo();
226 assert(Ptr &&
"Didn't find this decl on its identifier's chain!");
228 if (isDeclPtr(Ptr)) {
229 assert(D == Ptr &&
"Didn't find this decl on its identifier's chain!");
230 Name.setFETokenInfo(
nullptr);
234 return toIdDeclInfo(Ptr)->RemoveDecl(D);
237llvm::iterator_range<IdentifierResolver::iterator>
244 readingIdentifier(*II);
246 void *Ptr = Name.getFETokenInfo();
247 if (!Ptr)
return end();
252 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
254 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
255 if (I != IDI->decls_begin())
281 return DMK_Different;
288 return DMK_Different;
292 if (Existing == MostRecent)
295 if (New == MostRecent)
300 for (
auto *RD : New->
redecls()) {
304 if (RD->isCanonicalDecl())
311 return DMK_Different;
316 readingIdentifier(*II);
318 void *Ptr = Name.getFETokenInfo();
321 Name.setFETokenInfo(D);
327 if (isDeclPtr(Ptr)) {
338 Name.setFETokenInfo(D);
342 Name.setFETokenInfo(
nullptr);
343 IDI = &(*IdDeclInfos)[Name];
357 IDI = toIdDeclInfo(Ptr);
361 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
362 IEnd = IDI->decls_end();
377 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
380 IDI->InsertDecl(I, D);
409IdentifierResolver::IdDeclInfo &
411 void *Ptr = Name.getFETokenInfo();
413 if (Ptr)
return *toIdDeclInfo(Ptr);
415 if (CurIndex == POOL_SIZE) {
416 CurPool =
new IdDeclInfoPool(CurPool);
419 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
420 Name.setFETokenInfo(
reinterpret_cast<void*
>(
430 assert(!isDeclPtr(InfoPtr) &&
"Decl with wrong id ?");
431 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
434 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.
void * getFETokenInfo() const
Get and set FETokenInfo.
virtual void updateOutOfDateIdentifier(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.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special 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.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...