//===- IdentifierResolver.cpp - Lexical Scope Name lookup -----------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the IdentifierResolver class, which is used for lexical // scoped lookup, based on declaration names. // //===----------------------------------------------------------------------===// #include "clang/Sema/IdentifierResolver.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/DeclarationName.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" #include "clang/Lex/ExternalPreprocessorSource.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/Scope.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> #include <cstdint> usingnamespaceclang; //===----------------------------------------------------------------------===// // IdDeclInfoMap class //===----------------------------------------------------------------------===// /// IdDeclInfoMap - Associates IdDeclInfos with declaration names. /// Allocates 'pools' (vectors of IdDeclInfos) to avoid allocating each /// individual IdDeclInfo to heap. class IdentifierResolver::IdDeclInfoMap { … }; //===----------------------------------------------------------------------===// // IdDeclInfo Implementation //===----------------------------------------------------------------------===// /// RemoveDecl - Remove the decl from the scope chain. /// The decl must already be part of the decl chain. void IdentifierResolver::IdDeclInfo::RemoveDecl(NamedDecl *D) { … } //===----------------------------------------------------------------------===// // IdentifierResolver Implementation //===----------------------------------------------------------------------===// IdentifierResolver::IdentifierResolver(Preprocessor &PP) : … { … } IdentifierResolver::~IdentifierResolver() { … } /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns /// true if 'D' belongs to the given declaration context. bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S, bool AllowInlineNamespace) const { … } /// AddDecl - Link the decl to its shadowed decl chain. void IdentifierResolver::AddDecl(NamedDecl *D) { … } void IdentifierResolver::InsertDeclAfter(iterator Pos, NamedDecl *D) { … } /// RemoveDecl - Unlink the decl from its shadowed decl chain. /// The decl must already be part of the decl chain. void IdentifierResolver::RemoveDecl(NamedDecl *D) { … } llvm::iterator_range<IdentifierResolver::iterator> IdentifierResolver::decls(DeclarationName Name) { … } IdentifierResolver::iterator IdentifierResolver::begin(DeclarationName Name) { … } namespace { enum DeclMatchKind { … }; } // namespace /// Compare two declarations to see whether they are different or, /// if they are the same, whether the new declaration should replace the /// existing declaration. static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) { … } bool IdentifierResolver::tryAddTopLevelDecl(NamedDecl *D, DeclarationName Name){ … } void IdentifierResolver::readingIdentifier(IdentifierInfo &II) { … } void IdentifierResolver::updatingIdentifier(IdentifierInfo &II) { … } //===----------------------------------------------------------------------===// // IdDeclInfoMap Implementation //===----------------------------------------------------------------------===// /// Returns the IdDeclInfo associated to the DeclarationName. /// It creates a new IdDeclInfo if one was not created before for this id. IdentifierResolver::IdDeclInfo & IdentifierResolver::IdDeclInfoMap::operator[](DeclarationName Name) { … } void IdentifierResolver::iterator::incrementSlowCase() { … }