Path: blob/main/contrib/llvm-project/clang/lib/Serialization/ASTCommon.h
35233 views
//===- ASTCommon.h - Common stuff for ASTReader/ASTWriter -*- C++ -*-=========//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines common functions that both ASTReader and ASTWriter use.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H13#define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H1415#include "clang/AST/ASTContext.h"16#include "clang/AST/DeclFriend.h"17#include "clang/Serialization/ASTBitCodes.h"1819namespace clang {2021namespace serialization {2223enum DeclUpdateKind {24UPD_CXX_ADDED_IMPLICIT_MEMBER,25UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,26UPD_CXX_ADDED_ANONYMOUS_NAMESPACE,27UPD_CXX_ADDED_FUNCTION_DEFINITION,28UPD_CXX_ADDED_VAR_DEFINITION,29UPD_CXX_POINT_OF_INSTANTIATION,30UPD_CXX_INSTANTIATED_CLASS_DEFINITION,31UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT,32UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER,33UPD_CXX_RESOLVED_DTOR_DELETE,34UPD_CXX_RESOLVED_EXCEPTION_SPEC,35UPD_CXX_DEDUCED_RETURN_TYPE,36UPD_DECL_MARKED_USED,37UPD_MANGLING_NUMBER,38UPD_STATIC_LOCAL_NUMBER,39UPD_DECL_MARKED_OPENMP_THREADPRIVATE,40UPD_DECL_MARKED_OPENMP_ALLOCATE,41UPD_DECL_MARKED_OPENMP_DECLARETARGET,42UPD_DECL_EXPORTED,43UPD_ADDED_ATTR_TO_RECORD44};4546TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);4748unsigned ComputeHash(Selector Sel);4950/// Retrieve the "definitive" declaration that provides all of the51/// visible entries for the given declaration context, if there is one.52///53/// The "definitive" declaration is the only place where we need to look to54/// find information about the declarations within the given declaration55/// context. For example, C++ and Objective-C classes, C structs/unions, and56/// Objective-C protocols, categories, and extensions are all defined in a57/// single place in the source code, so they have definitive declarations58/// associated with them. C++ namespaces, on the other hand, can have59/// multiple definitions.60const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);6162/// Determine whether the given declaration kind is redeclarable.63bool isRedeclarableDeclKind(unsigned Kind);6465/// Determine whether the given declaration needs an anonymous66/// declaration number.67bool needsAnonymousDeclarationNumber(const NamedDecl *D);6869/// Visit each declaration within \c DC that needs an anonymous70/// declaration number and call \p Visit with the declaration and its number.71template<typename Fn> void numberAnonymousDeclsWithin(const DeclContext *DC,72Fn Visit) {73unsigned Index = 0;74for (Decl *LexicalD : DC->decls()) {75// For a friend decl, we care about the declaration within it, if any.76if (auto *FD = dyn_cast<FriendDecl>(LexicalD))77LexicalD = FD->getFriendDecl();7879auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD);80if (!ND || !needsAnonymousDeclarationNumber(ND))81continue;8283Visit(ND, Index++);84}85}8687/// Determine whether the given declaration will be included in the per-module88/// initializer if it needs to be eagerly handed to the AST consumer. If so, we89/// should not hand it to the consumer when deserializing it, nor include it in90/// the list of eagerly deserialized declarations.91inline bool isPartOfPerModuleInitializer(const Decl *D) {92if (isa<ImportDecl>(D))93return true;94// Template instantiations are notionally in an "instantiation unit" rather95// than in any particular translation unit, so they need not be part of any96// particular (sub)module's per-module initializer.97if (auto *VD = dyn_cast<VarDecl>(D))98return !isTemplateInstantiation(VD->getTemplateSpecializationKind());99return false;100}101102} // namespace serialization103104} // namespace clang105106#endif107108109