]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Serialization/ASTCommon.h
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / lib / Serialization / ASTCommon.h
1 //===- ASTCommon.h - Common stuff for ASTReader/ASTWriter -*- C++ -*-=========//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file defines common functions that both ASTReader and ASTWriter use.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
15 #define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H
16
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclFriend.h"
19 #include "clang/Serialization/ASTBitCodes.h"
20
21 namespace clang {
22
23 namespace serialization {
24
25 enum DeclUpdateKind {
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_ADDED_VAR_DEFINITION,
31   UPD_CXX_POINT_OF_INSTANTIATION,
32   UPD_CXX_INSTANTIATED_CLASS_DEFINITION,
33   UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT,
34   UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER,
35   UPD_CXX_RESOLVED_DTOR_DELETE,
36   UPD_CXX_RESOLVED_EXCEPTION_SPEC,
37   UPD_CXX_DEDUCED_RETURN_TYPE,
38   UPD_DECL_MARKED_USED,
39   UPD_MANGLING_NUMBER,
40   UPD_STATIC_LOCAL_NUMBER,
41   UPD_DECL_MARKED_OPENMP_THREADPRIVATE,
42   UPD_DECL_MARKED_OPENMP_DECLARETARGET,
43   UPD_DECL_EXPORTED,
44   UPD_ADDED_ATTR_TO_RECORD
45 };
46
47 TypeIdx TypeIdxFromBuiltin(const BuiltinType *BT);
48
49 template <typename IdxForTypeTy>
50 TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) {
51   if (T.isNull())
52     return PREDEF_TYPE_NULL_ID;
53
54   unsigned FastQuals = T.getLocalFastQualifiers();
55   T.removeLocalFastQualifiers();
56
57   if (T.hasLocalNonFastQualifiers())
58     return IdxForType(T).asTypeID(FastQuals);
59
60   assert(!T.hasLocalQualifiers());
61
62   if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
63     return TypeIdxFromBuiltin(BT).asTypeID(FastQuals);
64
65   if (T == Context.AutoDeductTy)
66     return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals);
67   if (T == Context.AutoRRefDeductTy)
68     return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals);
69
70   return IdxForType(T).asTypeID(FastQuals);
71 }
72
73 unsigned ComputeHash(Selector Sel);
74
75 /// Retrieve the "definitive" declaration that provides all of the
76 /// visible entries for the given declaration context, if there is one.
77 ///
78 /// The "definitive" declaration is the only place where we need to look to
79 /// find information about the declarations within the given declaration
80 /// context. For example, C++ and Objective-C classes, C structs/unions, and
81 /// Objective-C protocols, categories, and extensions are all defined in a
82 /// single place in the source code, so they have definitive declarations
83 /// associated with them. C++ namespaces, on the other hand, can have
84 /// multiple definitions.
85 const DeclContext *getDefinitiveDeclContext(const DeclContext *DC);
86
87 /// Determine whether the given declaration kind is redeclarable.
88 bool isRedeclarableDeclKind(unsigned Kind);
89
90 /// Determine whether the given declaration needs an anonymous
91 /// declaration number.
92 bool needsAnonymousDeclarationNumber(const NamedDecl *D);
93
94 /// Visit each declaration within \c DC that needs an anonymous
95 /// declaration number and call \p Visit with the declaration and its number.
96 template<typename Fn> void numberAnonymousDeclsWithin(const DeclContext *DC,
97                                                       Fn Visit) {
98   unsigned Index = 0;
99   for (Decl *LexicalD : DC->decls()) {
100     // For a friend decl, we care about the declaration within it, if any.
101     if (auto *FD = dyn_cast<FriendDecl>(LexicalD))
102       LexicalD = FD->getFriendDecl();
103
104     auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD);
105     if (!ND || !needsAnonymousDeclarationNumber(ND))
106       continue;
107
108     Visit(ND, Index++);
109   }
110 }
111
112 } // namespace serialization
113
114 } // namespace clang
115
116 #endif