24 #include "llvm/Support/ErrorHandling.h" 28 using namespace clang;
38 static const unsigned int POOL_SIZE = 512;
43 struct IdDeclInfoPool {
45 IdDeclInfo Pool[POOL_SIZE];
47 IdDeclInfoPool(IdDeclInfoPool *Next) : Next(Next) {}
50 IdDeclInfoPool *CurPool =
nullptr;
51 unsigned int CurIndex = POOL_SIZE;
57 IdDeclInfoPool *Cur = CurPool;
58 while (IdDeclInfoPool *
P = Cur) {
75 void IdentifierResolver::IdDeclInfo::RemoveDecl(
NamedDecl *D) {
76 for (DeclsTy::iterator I = Decls.end(); I != Decls.begin(); --I) {
83 llvm_unreachable(
"Didn't find this decl on its identifier's chain!");
91 : LangOpt(PP.getLangOpts()), PP(PP), IdDeclInfos(new
IdDeclInfoMap) {}
101 bool AllowInlineNamespace)
const {
111 if (LangOpt.CPlusPlus) {
148 updatingIdentifier(*II);
159 if (isDeclPtr(Ptr)) {
161 IDI = &(*IdDeclInfos)[Name];
165 IDI = toIdDeclInfo(Ptr);
173 updatingIdentifier(*II);
182 if (isDeclPtr(Ptr)) {
201 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
205 IDI->InsertDecl(IDI->decls_begin(), D);
211 assert(D &&
"null param passed");
214 updatingIdentifier(*II);
218 assert(Ptr &&
"Didn't find this decl on its identifier's chain!");
220 if (isDeclPtr(Ptr)) {
221 assert(D == Ptr &&
"Didn't find this decl on its identifier's chain!");
226 return toIdDeclInfo(Ptr)->RemoveDecl(D);
233 readingIdentifier(*II);
236 if (!Ptr)
return end();
239 return iterator(static_cast<NamedDecl*>(Ptr));
241 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
243 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
244 if (I != IDI->decls_begin())
270 return DMK_Different;
277 return DMK_Different;
281 if (Existing == MostRecent)
284 if (New == MostRecent)
289 for (
auto RD : New->
redecls()) {
293 if (RD->isCanonicalDecl())
300 return DMK_Different;
305 readingIdentifier(*II);
316 if (isDeclPtr(Ptr)) {
332 IDI = &(*IdDeclInfos)[Name];
346 IDI = toIdDeclInfo(Ptr);
350 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
351 IEnd = IDI->decls_end();
366 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
369 IDI->InsertDecl(I, D);
398 IdentifierResolver::IdDeclInfo &
402 if (Ptr)
return *toIdDeclInfo(Ptr);
404 if (CurIndex == POOL_SIZE) {
405 CurPool =
new IdDeclInfoPool(CurPool);
408 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
410 reinterpret_cast<uintptr_t>(IDI) | 0x1)
419 assert(!isDeclPtr(InfoPtr) &&
"Decl with wrong id ?");
420 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
423 if (I != Info->decls_begin())
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...
BaseIter getIterator() const
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'...
Decl - This represents one declaration (or definition), e.g.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
iterator begin(DeclarationName Name)
begin - Returns an iterator for decls with the name 'Name'.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
One of these records is kept for each identifier that is lexed.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
iterator end()
end - Returns an iterator that has 'finished'.
The controlling scope in a if/switch/while/for statement.
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
void RemoveDecl(NamedDecl *D)
RemoveDecl - Unlink the decl from its shadowed decl chain.
Scope - A scope is a transient data structure that is used while parsing the program.
IdDeclInfoMap - Associates IdDeclInfos with declaration names.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
unsigned getFlags() const
getFlags - Return the flags for this scope.
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.
IdDeclInfo::DeclsTy::iterator BaseIter
bool isDeclScope(Decl *D)
isDeclScope - Return true if this is the scope that the specified decl is declared in...
DeclContext * getEntity() const
Defines the clang::Preprocessor interface.
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...
DeclContext * getDeclContext()
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isFunctionOrMethod() const
ExternalPreprocessorSource * getExternalSource() const
void setFETokenInfoChangedSinceDeserialization()
Note that the frontend token information for this identifier has changed since it was loaded from an ...
IdDeclInfo & operator[](DeclarationName Name)
Returns the IdDeclInfo associated to the DeclarationName.
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.
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
IdentifierResolver(Preprocessor &PP)
const Scope * getParent() const
getParent - Return the scope that this is nested in.
The name of a declaration.
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 * getFETokenInfo() const
Get and set FETokenInfo.
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 ...
void setFETokenInfo(void *T)
NamedDecl * getMostRecentDecl()
This represents a decl that may have a name.
bool isTranslationUnit() const
iterator - Iterate over the decls of a specified declaration name.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
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.