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) {
74void IdentifierResolver::IdDeclInfo::RemoveDecl(
NamedDecl *D) {
75 for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) {
82 llvm_unreachable(
"Didn't find this decl on its identifier's chain!");
90 : LangOpt(PP.getLangOpts()), PP(PP), IdDeclInfos(new
IdDeclInfoMap) {}
100 bool AllowInlineNamespace)
const {
105 if (LangOpt.HLSL && isa<HLSLBufferDecl>(D))
109 while (S->getEntity() && S->getEntity()->isTransparentContext())
112 if (S->isDeclScope(D))
114 if (LangOpt.CPlusPlus) {
127 assert(S->getParent() &&
"No TUScope?");
130 if (S->getParent()->isControlScope() && !S->isFunctionScope()) {
132 if (S->isDeclScope(D))
135 if (S->isFnTryCatchScope())
136 return S->getParent()->isDeclScope(D);
153 updatingIdentifier(*II);
155 void *Ptr = Name.getFETokenInfo();
158 Name.setFETokenInfo(D);
164 if (isDeclPtr(Ptr)) {
165 Name.setFETokenInfo(
nullptr);
166 IDI = &(*IdDeclInfos)[Name];
170 IDI = toIdDeclInfo(Ptr);
178 updatingIdentifier(*II);
180 void *Ptr = Name.getFETokenInfo();
187 if (isDeclPtr(Ptr)) {
206 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
210 IDI->InsertDecl(IDI->decls_begin(), D);
216 assert(D &&
"null param passed");
219 updatingIdentifier(*II);
221 void *Ptr = Name.getFETokenInfo();
223 assert(Ptr &&
"Didn't find this decl on its identifier's chain!");
225 if (isDeclPtr(Ptr)) {
226 assert(D == Ptr &&
"Didn't find this decl on its identifier's chain!");
227 Name.setFETokenInfo(
nullptr);
231 return toIdDeclInfo(Ptr)->RemoveDecl(D);
238 readingIdentifier(*II);
240 void *Ptr = Name.getFETokenInfo();
241 if (!Ptr)
return end();
246 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
248 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
249 if (I != IDI->decls_begin())
275 return DMK_Different;
282 return DMK_Different;
286 if (Existing == MostRecent)
289 if (New == MostRecent)
294 for (
auto *RD : New->
redecls()) {
298 if (RD->isCanonicalDecl())
305 return DMK_Different;
310 readingIdentifier(*II);
312 void *Ptr = Name.getFETokenInfo();
315 Name.setFETokenInfo(D);
321 if (isDeclPtr(Ptr)) {
332 Name.setFETokenInfo(D);
336 Name.setFETokenInfo(
nullptr);
337 IDI = &(*IdDeclInfos)[Name];
351 IDI = toIdDeclInfo(Ptr);
355 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
356 IEnd = IDI->decls_end();
371 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
374 IDI->InsertDecl(I, D);
403IdentifierResolver::IdDeclInfo &
405 void *Ptr = Name.getFETokenInfo();
407 if (Ptr)
return *toIdDeclInfo(Ptr);
409 if (CurIndex == POOL_SIZE) {
410 CurPool =
new IdDeclInfoPool(CurPool);
413 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
414 Name.setFETokenInfo(
reinterpret_cast<void*
>(
424 assert(!isDeclPtr(InfoPtr) &&
"Decl with wrong id ?");
425 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
428 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.
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)
begin - Returns an iterator for 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()
end - Returns an iterator that has 'finished'.
void AddDecl(NamedDecl *D)
AddDecl - Link the decl to its shadowed decl chain.
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...