/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Serialization/ASTCommon.h
Line | Count | Source |
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-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file defines common functions that both ASTReader and ASTWriter use. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H |
14 | | #define LLVM_CLANG_LIB_SERIALIZATION_ASTCOMMON_H |
15 | | |
16 | | #include "clang/AST/ASTContext.h" |
17 | | #include "clang/AST/DeclFriend.h" |
18 | | #include "clang/Serialization/ASTBitCodes.h" |
19 | | |
20 | | namespace clang { |
21 | | |
22 | | namespace serialization { |
23 | | |
24 | | enum DeclUpdateKind { |
25 | | UPD_CXX_ADDED_IMPLICIT_MEMBER, |
26 | | UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, |
27 | | UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, |
28 | | UPD_CXX_ADDED_FUNCTION_DEFINITION, |
29 | | UPD_CXX_ADDED_VAR_DEFINITION, |
30 | | UPD_CXX_POINT_OF_INSTANTIATION, |
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, |
37 | | UPD_DECL_MARKED_USED, |
38 | | UPD_MANGLING_NUMBER, |
39 | | UPD_STATIC_LOCAL_NUMBER, |
40 | | UPD_DECL_MARKED_OPENMP_THREADPRIVATE, |
41 | | UPD_DECL_MARKED_OPENMP_ALLOCATE, |
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 | 7.43M | TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) { |
51 | 7.43M | if (T.isNull()) |
52 | 467k | return PREDEF_TYPE_NULL_ID; |
53 | | |
54 | 6.96M | unsigned FastQuals = T.getLocalFastQualifiers(); |
55 | 6.96M | T.removeLocalFastQualifiers(); |
56 | | |
57 | 6.96M | if (T.hasLocalNonFastQualifiers()) |
58 | 154k | return IdxForType(T).asTypeID(FastQuals); |
59 | | |
60 | 6.80M | assert(!T.hasLocalQualifiers()); |
61 | | |
62 | 6.80M | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) |
63 | 2.17M | return TypeIdxFromBuiltin(BT).asTypeID(FastQuals); |
64 | | |
65 | 4.63M | if (T == Context.AutoDeductTy) |
66 | 737 | return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals); |
67 | 4.62M | if (T == Context.AutoRRefDeductTy) |
68 | 55 | return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals); |
69 | | |
70 | 4.62M | return IdxForType(T).asTypeID(FastQuals); |
71 | 4.62M | } ASTWriter.cpp:unsigned int clang::serialization::MakeTypeID<clang::ASTWriter::GetOrCreateTypeID(clang::QualType)::$_0>(clang::ASTContext&, clang::QualType, clang::ASTWriter::GetOrCreateTypeID(clang::QualType)::$_0) Line | Count | Source | 50 | 7.43M | TypeID MakeTypeID(ASTContext &Context, QualType T, IdxForTypeTy IdxForType) { | 51 | 7.43M | if (T.isNull()) | 52 | 467k | return PREDEF_TYPE_NULL_ID; | 53 | | | 54 | 6.96M | unsigned FastQuals = T.getLocalFastQualifiers(); | 55 | 6.96M | T.removeLocalFastQualifiers(); | 56 | | | 57 | 6.96M | if (T.hasLocalNonFastQualifiers()) | 58 | 154k | return IdxForType(T).asTypeID(FastQuals); | 59 | | | 60 | 6.80M | assert(!T.hasLocalQualifiers()); | 61 | | | 62 | 6.80M | if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr())) | 63 | 2.17M | return TypeIdxFromBuiltin(BT).asTypeID(FastQuals); | 64 | | | 65 | 4.63M | if (T == Context.AutoDeductTy) | 66 | 737 | return TypeIdx(PREDEF_TYPE_AUTO_DEDUCT).asTypeID(FastQuals); | 67 | 4.62M | if (T == Context.AutoRRefDeductTy) | 68 | 55 | return TypeIdx(PREDEF_TYPE_AUTO_RREF_DEDUCT).asTypeID(FastQuals); | 69 | | | 70 | 4.62M | return IdxForType(T).asTypeID(FastQuals); | 71 | 4.62M | } |
Unexecuted instantiation: ASTWriter.cpp:unsigned int clang::serialization::MakeTypeID<clang::ASTWriter::getTypeID(clang::QualType) const::$_0>(clang::ASTContext&, clang::QualType, clang::ASTWriter::getTypeID(clang::QualType) const::$_0) |
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 | 53.7k | Fn Visit) { |
98 | 53.7k | unsigned Index = 0; |
99 | 268k | for (Decl *LexicalD : DC->decls()) { |
100 | | // For a friend decl, we care about the declaration within it, if any. |
101 | 268k | if (auto *FD = dyn_cast<FriendDecl>(LexicalD)) |
102 | 1.35k | LexicalD = FD->getFriendDecl(); |
103 | | |
104 | 268k | auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD); |
105 | 268k | if (!ND || !needsAnonymousDeclarationNumber(ND)230k ) |
106 | 180k | continue; |
107 | | |
108 | 88.9k | Visit(ND, Index++); |
109 | 88.9k | } |
110 | 53.7k | } ASTReaderDecl.cpp:void clang::serialization::numberAnonymousDeclsWithin<clang::ASTDeclReader::getAnonymousDeclForMerging(clang::ASTReader&, clang::DeclContext*, unsigned int)::$_0>(clang::DeclContext const*, clang::ASTDeclReader::getAnonymousDeclForMerging(clang::ASTReader&, clang::DeclContext*, unsigned int)::$_0) Line | Count | Source | 97 | 11 | Fn Visit) { | 98 | 11 | unsigned Index = 0; | 99 | 68 | for (Decl *LexicalD : DC->decls()) { | 100 | | // For a friend decl, we care about the declaration within it, if any. | 101 | 68 | if (auto *FD = dyn_cast<FriendDecl>(LexicalD)) | 102 | 1 | LexicalD = FD->getFriendDecl(); | 103 | | | 104 | 68 | auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD); | 105 | 68 | if (!ND || !needsAnonymousDeclarationNumber(ND)) | 106 | 38 | continue; | 107 | | | 108 | 30 | Visit(ND, Index++); | 109 | 30 | } | 110 | 11 | } |
ASTWriter.cpp:void clang::serialization::numberAnonymousDeclsWithin<clang::ASTWriter::getAnonymousDeclarationNumber(clang::NamedDecl const*)::$_0>(clang::DeclContext const*, clang::ASTWriter::getAnonymousDeclarationNumber(clang::NamedDecl const*)::$_0) Line | Count | Source | 97 | 53.7k | Fn Visit) { | 98 | 53.7k | unsigned Index = 0; | 99 | 268k | for (Decl *LexicalD : DC->decls()) { | 100 | | // For a friend decl, we care about the declaration within it, if any. | 101 | 268k | if (auto *FD = dyn_cast<FriendDecl>(LexicalD)) | 102 | 1.34k | LexicalD = FD->getFriendDecl(); | 103 | | | 104 | 268k | auto *ND = dyn_cast_or_null<NamedDecl>(LexicalD); | 105 | 268k | if (!ND || !needsAnonymousDeclarationNumber(ND)229k ) | 106 | 179k | continue; | 107 | | | 108 | 88.8k | Visit(ND, Index++); | 109 | 88.8k | } | 110 | 53.7k | } |
|
111 | | |
112 | | /// Determine whether the given declaration will be included in the per-module |
113 | | /// initializer if it needs to be eagerly handed to the AST consumer. If so, we |
114 | | /// should not hand it to the consumer when deserializing it, nor include it in |
115 | | /// the list of eagerly deserialized declarations. |
116 | 4.66M | inline bool isPartOfPerModuleInitializer(const Decl *D) { |
117 | 4.66M | if (isa<ImportDecl>(D)) |
118 | 42.7k | return true; |
119 | | // Template instantiations are notionally in an "instantiation unit" rather |
120 | | // than in any particular translation unit, so they need not be part of any |
121 | | // particular (sub)module's per-module initializer. |
122 | 4.62M | if (auto *VD = dyn_cast<VarDecl>(D)) |
123 | 1.24M | return !isTemplateInstantiation(VD->getTemplateSpecializationKind()); |
124 | 3.37M | return false; |
125 | 4.62M | } |
126 | | |
127 | | } // namespace serialization |
128 | | |
129 | | } // namespace clang |
130 | | |
131 | | #endif |