23 #include "llvm/Support/ErrorHandling.h" 27 using namespace clang;
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) {
74 void 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 {
110 if (LangOpt.CPlusPlus) {
147 updatingIdentifier(*II);
158 if (isDeclPtr(Ptr)) {
160 IDI = &(*IdDeclInfos)[Name];
164 IDI = toIdDeclInfo(Ptr);
172 updatingIdentifier(*II);
181 if (isDeclPtr(Ptr)) {
200 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
204 IDI->InsertDecl(IDI->decls_begin(), D);
210 assert(D &&
"null param passed");
213 updatingIdentifier(*II);
217 assert(Ptr &&
"Didn't find this decl on its identifier's chain!");
219 if (isDeclPtr(Ptr)) {
220 assert(D == Ptr &&
"Didn't find this decl on its identifier's chain!");
225 return toIdDeclInfo(Ptr)->RemoveDecl(D);
232 readingIdentifier(*II);
235 if (!Ptr)
return end();
238 return iterator(static_cast<NamedDecl*>(Ptr));
240 IdDeclInfo *IDI = toIdDeclInfo(Ptr);
242 IdDeclInfo::DeclsTy::iterator I = IDI->decls_end();
243 if (I != IDI->decls_begin())
269 return DMK_Different;
276 return DMK_Different;
280 if (Existing == MostRecent)
283 if (New == MostRecent)
288 for (
auto RD : New->
redecls()) {
292 if (RD->isCanonicalDecl())
299 return DMK_Different;
304 readingIdentifier(*II);
315 if (isDeclPtr(Ptr)) {
331 IDI = &(*IdDeclInfos)[Name];
345 IDI = toIdDeclInfo(Ptr);
349 for (IdDeclInfo::DeclsTy::iterator I = IDI->decls_begin(),
350 IEnd = IDI->decls_end();
365 if (!(*I)->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
368 IDI->InsertDecl(I, D);
397 IdentifierResolver::IdDeclInfo &
401 if (Ptr)
return *toIdDeclInfo(Ptr);
403 if (CurIndex == POOL_SIZE) {
404 CurPool =
new IdDeclInfoPool(CurPool);
407 IdDeclInfo *IDI = &CurPool->Pool[CurIndex];
409 reinterpret_cast<uintptr_t>(IDI) | 0x1)
418 assert(!isDeclPtr(InfoPtr) &&
"Decl with wrong id ?");
419 IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
422 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.