22 using namespace clang;
32 static const unsigned int POOL_SIZE = 512;
37 struct IdDeclInfoPool {
38 IdDeclInfoPool(IdDeclInfoPool *
Next) :
Next(Next) {}
41 IdDeclInfo Pool[POOL_SIZE];
44 IdDeclInfoPool *CurPool;
45 unsigned int CurIndex;
51 IdDeclInfoPool *Cur = CurPool;
52 while (IdDeclInfoPool *
P = Cur) {
70 void IdentifierResolver::IdDeclInfo::RemoveDecl(
NamedDecl *D) {
78 llvm_unreachable(
"Didn't find this decl on its identifier's chain!");
86 : LangOpt(PP.getLangOpts()), PP(PP),
98 bool AllowInlineNamespace)
const {
108 if (LangOpt.CPlusPlus) {
136 DeclContext *DCtx = D->getDeclContext()->getRedeclContext();
145 updatingIdentifier(*II);
156 if (isDeclPtr(Ptr)) {
158 IDI = &(*IdDeclInfos)[
Name];
162 IDI = toIdDeclInfo(Ptr);
170 updatingIdentifier(*II);
179 if (isDeclPtr(Ptr)) {
198 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
202 IDI->InsertDecl(IDI->decls_begin(), D);
208 assert(D &&
"null param passed");
211 updatingIdentifier(*II);
215 assert(Ptr &&
"Didn't find this decl on its identifier's chain!");
217 if (isDeclPtr(Ptr)) {
218 assert(D == Ptr &&
"Didn't find this decl on its identifier's chain!");
223 return toIdDeclInfo(Ptr)->RemoveDecl(D);
230 readingIdentifier(*II);
233 if (!Ptr)
return end();
236 return iterator(static_cast<NamedDecl*>(Ptr));
238 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
241 if (I != IDI->decls_begin())
264 if (Existing->getKind() != New->getKind())
265 return DMK_Different;
268 if (Existing->getCanonicalDecl() == New->getCanonicalDecl()) {
271 if (Existing->isFromASTFile() && New->isFromASTFile())
272 return DMK_Different;
276 if (Existing == MostRecent)
279 if (New == MostRecent)
284 for (
auto RD : New->redecls()) {
288 if (RD->isCanonicalDecl())
295 return DMK_Different;
300 readingIdentifier(*II);
311 if (isDeclPtr(Ptr)) {
327 IDI = &(*IdDeclInfos)[
Name];
331 if (!PrevD->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
341 IDI = toIdDeclInfo(Ptr);
346 IEnd = IDI->decls_end();
361 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
364 IDI->InsertDecl(
I, D);
393 IdentifierResolver::IdDeclInfo &
397 if (Ptr)
return *toIdDeclInfo(Ptr);
399 if (CurIndex == POOL_SIZE) {
400 CurPool =
new IdDeclInfoPool(CurPool);
403 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
405 reinterpret_cast<uintptr_t>(IDI) | 0x1)
411 void IdentifierResolver::iterator::incrementSlowCase() {
414 assert(!isDeclPtr(InfoPtr) &&
"Decl with wrong id ?");
415 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
418 if (I != Info->decls_begin())
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context, meaning that the members declared in this context are semantically declared in the nearest enclosing non-transparent (opaque) context but are lexically declared in this context.
ExternalPreprocessorSource * getExternalSource() const
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...
const Scope * getParent() const
getParent - Return the scope that this is nested in.
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn't a simple identifier.
iterator begin(DeclarationName Name)
begin - Returns an iterator for decls with the name 'Name'.
One of these records is kept for each identifier that is lexed.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
iterator end()
end - Returns an iterator that has 'finished'.
The controlling scope in a if/switch/while/for statement.
void RemoveDecl(NamedDecl *D)
RemoveDecl - Unlink the decl from its shadowed decl chain.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
Scope - A scope is a transient data structure that is used while parsing the program.
detail::InMemoryDirectory::const_iterator I
IdDeclInfoMap - Associates IdDeclInfos with declaration names.
static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New)
Compare two declarations to see whether they are different or, if they are the same, whether the new declaration should replace the existing declaration.
Defines the clang::LangOptions interface.
bool isDeclScope(Decl *D)
isDeclScope - Return true if this is the scope that the specified decl is declared in...
Defines the clang::Preprocessor interface.
bool isFunctionOrMethod() const
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
DeclContext * getEntity() const
const TemplateArgument * iterator
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
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...
IdDeclInfo & operator[](DeclarationName Name)
Returns the IdDeclInfo associated to the DeclarationName.
BaseIter getIterator() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
IdentifierResolver(Preprocessor &PP)
DeclarationName - The name of a declaration.
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'...
void InsertDeclAfter(iterator Pos, NamedDecl *D)
Insert the given declaration after the given iterator position.
This is the scope for a function-level C++ try or catch scope.
void AddDecl(NamedDecl *D)
AddDecl - Link the decl to its shadowed decl chain.
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)=0
Update an out-of-date identifier.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
IdDeclInfo::DeclsTy::iterator BaseIter
void setFETokenInfo(void *T)
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
NamedDecl * getMostRecentDecl()
NamedDecl - This represents a decl with a name.
T * getFETokenInfo() const
getFETokenInfo/setFETokenInfo - The language front-end is allowed to associate arbitrary metadata wit...
iterator - Iterate over the decls of a specified declaration name.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.