1 //===- ASTCommon.h - Common stuff for ASTReader/ASTWriter -*- C++ -*-=========//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines common functions that both ASTReader and ASTWriter use.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
15 #define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclFriend.h"
19 #include "clang/Serialization/ASTBitCodes.h"
23 namespace serialization {
26 UPD_CXX_ADDED_IMPLICIT_MEMBER,
27 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,
28 UPD_CXX_ADDED_ANONYMOUS_NAMESPACE,
29 UPD_CXX_ADDED_FUNCTION_DEFINITION,
30 UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER,
31 UPD_CXX_INSTANTIATED_CLASS_DEFINITION,
32 UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT,
33 UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER,
34 UPD_CXX_RESOLVED_DTOR_DELETE,
35 UPD_CXX_RESOLVED_EXCEPTION_SPEC,
36 UPD_CXX_DEDUCED_RETURN_TYPE,
39 UPD_STATIC_LOCAL_NUMBER,
40 UPD_DECL_MARKED_OPENMP_THREADPRIVATE,
41 UPD_DECL_MARKED_OPENMP_DECLARETARGET,
43 UPD_ADDED_ATTR_TO_RECORD
46 TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
48 template <typename IdxForTypeTy>
49 TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) {
51 return PREDEF_TYPE_NULL_ID;
53 unsigned FastQuals = T.getLocalFastQualifiers();
54 T.removeLocalFastQualifiers();
56 if (T.hasLocalNonFastQualifiers())
57 return IdxForType(T).asTypeID(FastQuals);
59 assert(!T.hasLocalQualifiers());
61 if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
62 return TypeIdxFromBuiltin(BT).asTypeID(FastQuals);
64 if (T == Context.AutoDeductTy)
65 return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
66 if (T == Context.AutoRRefDeductTy)
67 return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals);
69 return IdxForType(T).asTypeID(FastQuals);
72 unsigned ComputeHash(Selector Sel);
74 /// \brief Retrieve the "definitive" declaration that provides all of the
75 /// visible entries for the given declaration context, if there is one.
77 /// The "definitive" declaration is the only place where we need to look to
78 /// find information about the declarations within the given declaration
79 /// context. For example, C++ and Objective-C classes, C structs/unions, and
80 /// Objective-C protocols, categories, and extensions are all defined in a
81 /// single place in the source code, so they have definitive declarations
82 /// associated with them. C++ namespaces, on the other hand, can have
83 /// multiple definitions.
84 const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);
86 /// \brief Determine whether the given declaration kind is redeclarable.
87 bool isRedeclarableDeclKind(unsigned Kind);
89 /// \brief Determine whether the given declaration needs an anonymous
90 /// declaration number.
91 bool needsAnonymousDeclarationNumber(const NamedDecl *D);
93 /// \brief Visit each declaration within \c DC that needs an anonymous
94 /// declaration number and call \p Visit with the declaration and its number.
95 template<typename Fn> void numberAnonymousDeclsWithin(const DeclContext *DC,
98 for (Decl *LexicalD : DC->decls()) {
99 // For a friend decl, we care about the declaration within it, if any.
100 if (auto *FD = dyn_cast<FriendDecl>(LexicalD))
101 LexicalD = FD->getFriendDecl();
103 auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD);
104 if (!ND || !needsAnonymousDeclarationNumber(ND))
111 } // namespace serialization