xref: /minix3/external/bsd/llvm/dist/clang/lib/Serialization/ASTCommon.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===- ASTCommon.h - Common stuff for ASTReader/ASTWriter -*- C++ -*-=========//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc //  This file defines common functions that both ASTReader and ASTWriter use.
11f4a2713aSLionel Sambuc //
12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13f4a2713aSLionel Sambuc 
14*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
15*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h"
18f4a2713aSLionel Sambuc #include "clang/Serialization/ASTBitCodes.h"
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc namespace clang {
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc namespace serialization {
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc enum DeclUpdateKind {
25f4a2713aSLionel Sambuc   UPD_CXX_ADDED_IMPLICIT_MEMBER,
26f4a2713aSLionel Sambuc   UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION,
27f4a2713aSLionel Sambuc   UPD_CXX_ADDED_ANONYMOUS_NAMESPACE,
28*0a6a1f1dSLionel Sambuc   UPD_CXX_ADDED_FUNCTION_DEFINITION,
29f4a2713aSLionel Sambuc   UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER,
30*0a6a1f1dSLionel Sambuc   UPD_CXX_INSTANTIATED_CLASS_DEFINITION,
31*0a6a1f1dSLionel Sambuc   UPD_CXX_RESOLVED_EXCEPTION_SPEC,
32f4a2713aSLionel Sambuc   UPD_CXX_DEDUCED_RETURN_TYPE,
33*0a6a1f1dSLionel Sambuc   UPD_DECL_MARKED_USED,
34*0a6a1f1dSLionel Sambuc   UPD_MANGLING_NUMBER,
35*0a6a1f1dSLionel Sambuc   UPD_STATIC_LOCAL_NUMBER,
36*0a6a1f1dSLionel Sambuc   UPD_DECL_MARKED_OPENMP_THREADPRIVATE
37f4a2713aSLionel Sambuc };
38f4a2713aSLionel Sambuc 
39f4a2713aSLionel Sambuc TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc template <typename IdxForTypeTy>
MakeTypeID(ASTContext & Context,QualType T,IdxForTypeTy IdxForType)42f4a2713aSLionel Sambuc TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) {
43f4a2713aSLionel Sambuc   if (T.isNull())
44f4a2713aSLionel Sambuc     return PREDEF_TYPE_NULL_ID;
45f4a2713aSLionel Sambuc 
46f4a2713aSLionel Sambuc   unsigned FastQuals = T.getLocalFastQualifiers();
47f4a2713aSLionel Sambuc   T.removeLocalFastQualifiers();
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc   if (T.hasLocalNonFastQualifiers())
50f4a2713aSLionel Sambuc     return IdxForType(T).asTypeID(FastQuals);
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc   assert(!T.hasLocalQualifiers());
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
55f4a2713aSLionel Sambuc     return TypeIdxFromBuiltin(BT).asTypeID(FastQuals);
56f4a2713aSLionel Sambuc 
57f4a2713aSLionel Sambuc   if (T == Context.AutoDeductTy)
58f4a2713aSLionel Sambuc     return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
59f4a2713aSLionel Sambuc   if (T == Context.AutoRRefDeductTy)
60f4a2713aSLionel Sambuc     return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals);
61f4a2713aSLionel Sambuc   if (T == Context.VaListTagTy)
62f4a2713aSLionel Sambuc     return TypeIdx(PREDEF_TYPE_VA_LIST_TAG).asTypeID(FastQuals);
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc   return IdxForType(T).asTypeID(FastQuals);
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc unsigned ComputeHash(Selector Sel);
68f4a2713aSLionel Sambuc 
69f4a2713aSLionel Sambuc /// \brief Retrieve the "definitive" declaration that provides all of the
70f4a2713aSLionel Sambuc /// visible entries for the given declaration context, if there is one.
71f4a2713aSLionel Sambuc ///
72f4a2713aSLionel Sambuc /// The "definitive" declaration is the only place where we need to look to
73f4a2713aSLionel Sambuc /// find information about the declarations within the given declaration
74f4a2713aSLionel Sambuc /// context. For example, C++ and Objective-C classes, C structs/unions, and
75f4a2713aSLionel Sambuc /// Objective-C protocols, categories, and extensions are all defined in a
76f4a2713aSLionel Sambuc /// single place in the source code, so they have definitive declarations
77f4a2713aSLionel Sambuc /// associated with them. C++ namespaces, on the other hand, can have
78f4a2713aSLionel Sambuc /// multiple definitions.
79f4a2713aSLionel Sambuc const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc /// \brief Determine whether the given declaration kind is redeclarable.
82f4a2713aSLionel Sambuc bool isRedeclarableDeclKind(unsigned Kind);
83f4a2713aSLionel Sambuc 
84*0a6a1f1dSLionel Sambuc /// \brief Determine whether the given declaration needs an anonymous
85*0a6a1f1dSLionel Sambuc /// declaration number.
86*0a6a1f1dSLionel Sambuc bool needsAnonymousDeclarationNumber(const NamedDecl *D);
87*0a6a1f1dSLionel Sambuc 
88f4a2713aSLionel Sambuc } // namespace serialization
89f4a2713aSLionel Sambuc 
90f4a2713aSLionel Sambuc } // namespace clang
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc #endif
93