brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · c9b9b1b Raw
109 lines · c
1//===- ASTCommon.h - Common stuff for ASTReader/ASTWriter -*- C++ -*-=========//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9//  This file defines common functions that both ASTReader and ASTWriter use.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H14#define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H15 16#include "clang/AST/ASTContext.h"17#include "clang/AST/DeclFriend.h"18#include "clang/Basic/LLVM.h"19#include "clang/Serialization/ASTBitCodes.h"20 21namespace clang {22 23namespace serialization {24 25enum class DeclUpdateKind {26  CXXAddedImplicitMember,27  CXXAddedAnonymousNamespace,28  CXXAddedFunctionDefinition,29  CXXAddedVarDefinition,30  CXXPointOfInstantiation,31  CXXInstantiatedClassDefinition,32  CXXInstantiatedDefaultArgument,33  CXXInstantiatedDefaultMemberInitializer,34  CXXResolvedDtorDelete,35  CXXResolvedExceptionSpec,36  CXXDeducedReturnType,37  DeclMarkedUsed,38  ManglingNumber,39  StaticLocalNumber,40  DeclMarkedOpenMPThreadPrivate,41  DeclMarkedOpenMPAllocate,42  DeclMarkedOpenMPDeclareTarget,43  DeclExported,44  AddedAttrToRecord,45  CXXResolvedDtorGlobDelete46};47 48TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);49 50unsigned ComputeHash(Selector Sel);51 52/// Retrieve the "definitive" declaration that provides all of the53/// visible entries for the given declaration context, if there is one.54///55/// The "definitive" declaration is the only place where we need to look to56/// find information about the declarations within the given declaration57/// context. For example, C++ and Objective-C classes, C structs/unions, and58/// Objective-C protocols, categories, and extensions are all defined in a59/// single place in the source code, so they have definitive declarations60/// associated with them. C++ namespaces, on the other hand, can have61/// multiple definitions.62const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);63 64/// Determine whether the given declaration kind is redeclarable.65bool isRedeclarableDeclKind(unsigned Kind);66 67/// Determine whether the given declaration needs an anonymous68/// declaration number.69bool needsAnonymousDeclarationNumber(const NamedDecl *D);70 71/// Visit each declaration within \c DC that needs an anonymous72/// declaration number and call \p Visit with the declaration and its number.73template<typename Fn> void numberAnonymousDeclsWithin(const DeclContext *DC,74                                                      Fn Visit) {75  unsigned Index = 0;76  for (Decl *LexicalD : DC->decls()) {77    // For a friend decl, we care about the declaration within it, if any.78    if (auto *FD = dyn_cast<FriendDecl>(LexicalD))79      LexicalD = FD->getFriendDecl();80 81    auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD);82    if (!ND || !needsAnonymousDeclarationNumber(ND))83      continue;84 85    Visit(ND, Index++);86  }87}88 89/// Determine whether the given declaration will be included in the per-module90/// initializer if it needs to be eagerly handed to the AST consumer. If so, we91/// should not hand it to the consumer when deserializing it, nor include it in92/// the list of eagerly deserialized declarations.93inline bool isPartOfPerModuleInitializer(const Decl *D) {94  if (isa<ImportDecl>(D))95    return true;96  // Template instantiations are notionally in an "instantiation unit" rather97  // than in any particular translation unit, so they need not be part of any98  // particular (sub)module's per-module initializer.99  if (auto *VD = dyn_cast<VarDecl>(D))100    return !isTemplateInstantiation(VD->getTemplateSpecializationKind());101  return false;102}103 104} // namespace serialization105 106} // namespace clang107 108#endif109