Sebastian Redl | 3b3c874 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 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 | // |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file implements the ASTReader::ReadDeclRecord method, which is the |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 11 | // entrypoint for loading a decl. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Benjamin Kramer | 89f0b2d | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 16 | #include "ASTReaderInternals.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
| 18 | #include "clang/AST/DeclCXX.h" |
| 19 | #include "clang/AST/DeclGroup.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
| 21 | #include "clang/AST/DeclVisitor.h" |
| 22 | #include "clang/AST/Expr.h" |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 23 | #include "clang/Sema/IdentifierResolver.h" |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 24 | #include "clang/Sema/SemaDiagnostic.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 25 | #include "clang/Serialization/ASTReader.h" |
Argyrios Kyrtzidis | 0f7d7ab | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 26 | #include "llvm/Support/SaveAndRestore.h" |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 27 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 28 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 29 | using namespace clang::serialization; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 30 | |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | // Declaration deserialization |
| 33 | //===----------------------------------------------------------------------===// |
| 34 | |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 35 | namespace clang { |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 36 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 37 | ASTReader &Reader; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 38 | ASTRecordReader &Record; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 39 | ASTReader::RecordLocation Loc; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 40 | const DeclID ThisDeclID; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 41 | const SourceLocation ThisDeclLoc; |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 42 | typedef ASTReader::RecordData RecordData; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 43 | TypeID TypeIDForTypeDecl; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 44 | unsigned AnonymousDeclNumber; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 45 | GlobalDeclID NamedDeclForTagDecl; |
| 46 | IdentifierInfo *TypedefNameForLinkage; |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 47 | |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 48 | bool HasPendingBody; |
| 49 | |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 50 | ///\brief A flag to carry the information for a decl from the entity is |
| 51 | /// used. We use it to delay the marking of the canonical decl as used until |
| 52 | /// the entire declaration is deserialized and merged. |
| 53 | bool IsDeclMarkedUsed; |
| 54 | |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 55 | uint64_t GetCurrentCursorOffset(); |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 56 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 57 | uint64_t ReadLocalOffset() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 58 | uint64_t LocalOffset = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 59 | assert(LocalOffset < Loc.Offset && "offset point after current record"); |
| 60 | return LocalOffset ? Loc.Offset - LocalOffset : 0; |
Richard Smith | e37e9f4 | 2016-03-25 01:17:43 +0000 | [diff] [blame] | 61 | } |
| 62 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 63 | uint64_t ReadGlobalOffset() { |
| 64 | uint64_t Local = ReadLocalOffset(); |
| 65 | return Local ? Record.getGlobalBitOffset(Local) : 0; |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 66 | } |
| 67 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 68 | SourceLocation ReadSourceLocation() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 69 | return Record.readSourceLocation(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 70 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 71 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 72 | SourceRange ReadSourceRange() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 73 | return Record.readSourceRange(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 74 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 75 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 76 | TypeSourceInfo *GetTypeSourceInfo() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 77 | return Record.getTypeSourceInfo(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 78 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 79 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 80 | serialization::DeclID ReadDeclID() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 81 | return Record.readDeclID(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 82 | } |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 83 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 84 | std::string ReadString() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 85 | return Record.readString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 88 | void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 89 | for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 90 | IDs.push_back(ReadDeclID()); |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 91 | } |
| 92 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 93 | Decl *ReadDecl() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 94 | return Record.readDecl(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | template<typename T> |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 98 | T *ReadDeclAs() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 99 | return Record.readDeclAs<T>(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 100 | } |
| 101 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 102 | void ReadQualifierInfo(QualifierInfo &Info) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 103 | Record.readQualifierInfo(Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 104 | } |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 105 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 106 | void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 107 | Record.readDeclarationNameLoc(DNLoc, Name); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | serialization::SubmoduleID readSubmoduleID() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 111 | if (Record.getIdx() == Record.size()) |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 112 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 113 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 114 | return Record.getGlobalSubmoduleID(Record.readInt()); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 115 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 116 | |
| 117 | Module *readModule() { |
| 118 | return Record.getSubmodule(readSubmoduleID()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 119 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 120 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 121 | void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update); |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 122 | void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, |
| 123 | const CXXRecordDecl *D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 124 | void MergeDefinitionData(CXXRecordDecl *D, |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 125 | struct CXXRecordDecl::DefinitionData &&NewDD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 126 | void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 127 | void MergeDefinitionData(ObjCInterfaceDecl *D, |
| 128 | struct ObjCInterfaceDecl::DefinitionData &&NewDD); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 129 | void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); |
| 130 | void MergeDefinitionData(ObjCProtocolDecl *D, |
| 131 | struct ObjCProtocolDecl::DefinitionData &&NewDD); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 132 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 133 | static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, |
| 134 | DeclContext *DC, |
| 135 | unsigned Index); |
| 136 | static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, |
| 137 | unsigned Index, NamedDecl *D); |
| 138 | |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 139 | /// Results from loading a RedeclarableDecl. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 140 | class RedeclarableResult { |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 141 | Decl *MergeWith; |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 142 | GlobalDeclID FirstID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 143 | bool IsKeyDecl; |
Richard Smith | c89bb9d | 2015-02-25 01:11:29 +0000 | [diff] [blame] | 144 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 145 | public: |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 146 | RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) |
| 147 | : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 148 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 149 | /// \brief Retrieve the first ID. |
| 150 | GlobalDeclID getFirstID() const { return FirstID; } |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 151 | |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 152 | /// \brief Is this declaration a key declaration? |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 153 | bool isKeyDecl() const { return IsKeyDecl; } |
| 154 | |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 155 | /// \brief Get a known declaration that this should be merged with, if |
| 156 | /// any. |
| 157 | Decl *getKnownMergeTarget() const { return MergeWith; } |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 158 | }; |
Douglas Gregor | fe732d5 | 2013-01-21 16:16:40 +0000 | [diff] [blame] | 159 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 160 | /// \brief Class used to capture the result of searching for an existing |
| 161 | /// declaration of a specific kind and name, along with the ability |
| 162 | /// to update the place where this result was found (the declaration |
| 163 | /// chain hanging off an identifier or the DeclContext we searched in) |
| 164 | /// if requested. |
| 165 | class FindExistingResult { |
| 166 | ASTReader &Reader; |
| 167 | NamedDecl *New; |
| 168 | NamedDecl *Existing; |
Benjamin Kramer | b6aadc1 | 2016-08-06 12:45:16 +0000 | [diff] [blame] | 169 | bool AddResult; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 170 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 171 | unsigned AnonymousDeclNumber; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 172 | IdentifierInfo *TypedefNameForLinkage; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 173 | |
Benjamin Kramer | b6aadc1 | 2016-08-06 12:45:16 +0000 | [diff] [blame] | 174 | void operator=(FindExistingResult &&) = delete; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 175 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 176 | public: |
| 177 | FindExistingResult(ASTReader &Reader) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 178 | : Reader(Reader), New(nullptr), Existing(nullptr), AddResult(false), |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 179 | AnonymousDeclNumber(0), TypedefNameForLinkage(nullptr) {} |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 180 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 181 | FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 182 | unsigned AnonymousDeclNumber, |
| 183 | IdentifierInfo *TypedefNameForLinkage) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 184 | : Reader(Reader), New(New), Existing(Existing), AddResult(true), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 185 | AnonymousDeclNumber(AnonymousDeclNumber), |
| 186 | TypedefNameForLinkage(TypedefNameForLinkage) {} |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 187 | |
Benjamin Kramer | b6aadc1 | 2016-08-06 12:45:16 +0000 | [diff] [blame] | 188 | FindExistingResult(FindExistingResult &&Other) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 189 | : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), |
| 190 | AddResult(Other.AddResult), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 191 | AnonymousDeclNumber(Other.AnonymousDeclNumber), |
| 192 | TypedefNameForLinkage(Other.TypedefNameForLinkage) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 193 | Other.AddResult = false; |
| 194 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 195 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 196 | ~FindExistingResult(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 197 | |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 198 | /// \brief Suppress the addition of this result into the known set of |
| 199 | /// names. |
| 200 | void suppress() { AddResult = false; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 201 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 202 | operator NamedDecl*() const { return Existing; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 203 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 204 | template<typename T> |
| 205 | operator T*() const { return dyn_cast_or_null<T>(Existing); } |
| 206 | }; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 207 | |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 208 | static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, |
| 209 | DeclContext *DC); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 210 | FindExistingResult findExisting(NamedDecl *D); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 211 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 212 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 213 | ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, |
| 214 | ASTReader::RecordLocation Loc, |
| 215 | DeclID thisDeclID, SourceLocation ThisDeclLoc) |
| 216 | : Reader(Reader), Record(Record), Loc(Loc), |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 217 | ThisDeclID(thisDeclID), ThisDeclLoc(ThisDeclLoc), |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 218 | TypeIDForTypeDecl(0), NamedDeclForTagDecl(0), |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 219 | TypedefNameForLinkage(nullptr), HasPendingBody(false), |
| 220 | IsDeclMarkedUsed(false) {} |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 221 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 222 | template <typename T> static |
| 223 | void AddLazySpecializations(T *D, |
| 224 | SmallVectorImpl<serialization::DeclID>& IDs) { |
| 225 | if (IDs.empty()) |
| 226 | return; |
| 227 | |
| 228 | // FIXME: We should avoid this pattern of getting the ASTContext. |
| 229 | ASTContext &C = D->getASTContext(); |
| 230 | |
| 231 | auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; |
| 232 | |
| 233 | if (auto &Old = LazySpecializations) { |
| 234 | IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); |
| 235 | std::sort(IDs.begin(), IDs.end()); |
| 236 | IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); |
| 237 | } |
| 238 | |
| 239 | auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; |
| 240 | *Result = IDs.size(); |
| 241 | std::copy(IDs.begin(), IDs.end(), Result + 1); |
| 242 | |
| 243 | LazySpecializations = Result; |
| 244 | } |
| 245 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 246 | template <typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 247 | static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); |
| 248 | static Decl *getMostRecentDeclImpl(...); |
| 249 | static Decl *getMostRecentDecl(Decl *D); |
| 250 | |
| 251 | template <typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 252 | static void attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 253 | Redeclarable<DeclT> *D, Decl *Previous, |
| 254 | Decl *Canon); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 255 | static void attachPreviousDeclImpl(ASTReader &Reader, ...); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 256 | static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, |
| 257 | Decl *Canon); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 258 | |
| 259 | template <typename DeclT> |
| 260 | static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); |
| 261 | static void attachLatestDeclImpl(...); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 262 | static void attachLatestDecl(Decl *D, Decl *latest); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 263 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 264 | template <typename DeclT> |
| 265 | static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); |
| 266 | static void markIncompleteDeclChainImpl(...); |
| 267 | |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 268 | /// \brief Determine whether this declaration has a pending body. |
| 269 | bool hasPendingBody() const { return HasPendingBody; } |
| 270 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 271 | void ReadFunctionDefinition(FunctionDecl *FD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 272 | void Visit(Decl *D); |
| 273 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 274 | void UpdateDecl(Decl *D, llvm::SmallVectorImpl<serialization::DeclID>&); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 275 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 276 | static void setNextObjCCategory(ObjCCategoryDecl *Cat, |
| 277 | ObjCCategoryDecl *Next) { |
| 278 | Cat->NextClassCategory = Next; |
| 279 | } |
| 280 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 281 | void VisitDecl(Decl *D); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 282 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 283 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 284 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 285 | void VisitNamedDecl(NamedDecl *ND); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 286 | void VisitLabelDecl(LabelDecl *LD); |
Douglas Gregor | e31bbd9 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 287 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 288 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 289 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 290 | void VisitTypeDecl(TypeDecl *TD); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 291 | RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 292 | void VisitTypedefDecl(TypedefDecl *TD); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 293 | void VisitTypeAliasDecl(TypeAliasDecl *TD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 294 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 295 | RedeclarableResult VisitTagDecl(TagDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 296 | void VisitEnumDecl(EnumDecl *ED); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 297 | RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); |
| 298 | void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); } |
| 299 | RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); |
| 300 | void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } |
| 301 | RedeclarableResult VisitClassTemplateSpecializationDeclImpl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 302 | ClassTemplateSpecializationDecl *D); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 303 | void VisitClassTemplateSpecializationDecl( |
| 304 | ClassTemplateSpecializationDecl *D) { |
| 305 | VisitClassTemplateSpecializationDeclImpl(D); |
| 306 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 307 | void VisitClassTemplatePartialSpecializationDecl( |
| 308 | ClassTemplatePartialSpecializationDecl *D); |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 309 | void VisitClassScopeFunctionSpecializationDecl( |
| 310 | ClassScopeFunctionSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 311 | RedeclarableResult |
| 312 | VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); |
| 313 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { |
| 314 | VisitVarTemplateSpecializationDeclImpl(D); |
| 315 | } |
| 316 | void VisitVarTemplatePartialSpecializationDecl( |
| 317 | VarTemplatePartialSpecializationDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 318 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 319 | void VisitValueDecl(ValueDecl *VD); |
| 320 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 321 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 322 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 323 | void VisitFunctionDecl(FunctionDecl *FD); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 324 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 325 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 326 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 327 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 328 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 329 | void VisitFieldDecl(FieldDecl *FD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 330 | void VisitMSPropertyDecl(MSPropertyDecl *FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 331 | void VisitIndirectFieldDecl(IndirectFieldDecl *FD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 332 | RedeclarableResult VisitVarDeclImpl(VarDecl *D); |
| 333 | void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 334 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 335 | void VisitParmVarDecl(ParmVarDecl *PD); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 336 | void VisitDecompositionDecl(DecompositionDecl *DD); |
| 337 | void VisitBindingDecl(BindingDecl *BD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 338 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 339 | DeclID VisitTemplateDecl(TemplateDecl *D); |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 340 | RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 341 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 342 | void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 343 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 344 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 345 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 346 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 347 | void VisitUsingDecl(UsingDecl *D); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 348 | void VisitUsingPackDecl(UsingPackDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 349 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 350 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 351 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 352 | void VisitExportDecl(ExportDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 353 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 354 | void VisitImportDecl(ImportDecl *D); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 355 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 356 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 357 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 358 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 359 | void VisitBlockDecl(BlockDecl *BD); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 360 | void VisitCapturedDecl(CapturedDecl *CD); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 361 | void VisitEmptyDecl(EmptyDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 362 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 363 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 364 | |
| 365 | template<typename T> |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 366 | RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 367 | |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 368 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 369 | void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl, |
| 370 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 371 | |
| 372 | template<typename T> |
| 373 | void mergeRedeclarable(Redeclarable<T> *D, T *Existing, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 374 | RedeclarableResult &Redecl, |
| 375 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 376 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 377 | template<typename T> |
| 378 | void mergeMergeable(Mergeable<T> *D); |
| 379 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 380 | void mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 381 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 382 | DeclID DsID, bool IsKeyDecl); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 383 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 384 | ObjCTypeParamList *ReadObjCTypeParamList(); |
| 385 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 386 | // FIXME: Reorder according to DeclNodes.td? |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 387 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 388 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 389 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 390 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 391 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 392 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 393 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 394 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 395 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 396 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 397 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 398 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 399 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 400 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 401 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 402 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 403 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 404 | }; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 405 | } // end namespace clang |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 406 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 407 | namespace { |
| 408 | /// Iterator over the redeclarations of a declaration that have already |
| 409 | /// been merged into the same redeclaration chain. |
| 410 | template<typename DeclT> |
| 411 | class MergedRedeclIterator { |
| 412 | DeclT *Start, *Canonical, *Current; |
| 413 | public: |
| 414 | MergedRedeclIterator() : Current(nullptr) {} |
| 415 | MergedRedeclIterator(DeclT *Start) |
| 416 | : Start(Start), Canonical(nullptr), Current(Start) {} |
| 417 | |
| 418 | DeclT *operator*() { return Current; } |
| 419 | |
| 420 | MergedRedeclIterator &operator++() { |
| 421 | if (Current->isFirstDecl()) { |
| 422 | Canonical = Current; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 423 | Current = Current->getMostRecentDecl(); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 424 | } else |
| 425 | Current = Current->getPreviousDecl(); |
| 426 | |
| 427 | // If we started in the merged portion, we'll reach our start position |
| 428 | // eventually. Otherwise, we'll never reach it, but the second declaration |
| 429 | // we reached was the canonical declaration, so stop when we see that one |
| 430 | // again. |
| 431 | if (Current == Start || Current == Canonical) |
| 432 | Current = nullptr; |
| 433 | return *this; |
| 434 | } |
| 435 | |
| 436 | friend bool operator!=(const MergedRedeclIterator &A, |
| 437 | const MergedRedeclIterator &B) { |
| 438 | return A.Current != B.Current; |
| 439 | } |
| 440 | }; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 441 | } // end anonymous namespace |
| 442 | |
Benjamin Kramer | a0a13c3 | 2016-08-06 11:21:04 +0000 | [diff] [blame] | 443 | template <typename DeclT> |
| 444 | static llvm::iterator_range<MergedRedeclIterator<DeclT>> |
| 445 | merged_redecls(DeclT *D) { |
Craig Topper | 59c2ada | 2015-12-06 05:07:12 +0000 | [diff] [blame] | 446 | return llvm::make_range(MergedRedeclIterator<DeclT>(D), |
| 447 | MergedRedeclIterator<DeclT>()); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 450 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 451 | return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 452 | } |
| 453 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 454 | void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 455 | if (Record.readInt()) |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 456 | Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 457 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { |
| 458 | CD->NumCtorInitializers = Record.readInt(); |
| 459 | if (CD->NumCtorInitializers) |
| 460 | CD->CtorInitializers = ReadGlobalOffset(); |
| 461 | } |
| 462 | // Store the offset of the body so we can lazily load it later. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 463 | Reader.PendingBodies[FD] = GetCurrentCursorOffset(); |
| 464 | HasPendingBody = true; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 467 | void ASTDeclReader::Visit(Decl *D) { |
| 468 | DeclVisitor<ASTDeclReader, void>::Visit(D); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 469 | |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 470 | // At this point we have deserialized and merged the decl and it is safe to |
| 471 | // update its canonical decl to signal that the entire entity is used. |
| 472 | D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; |
| 473 | IsDeclMarkedUsed = false; |
| 474 | |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 475 | if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { |
| 476 | if (DD->DeclInfo) { |
| 477 | DeclaratorDecl::ExtInfo *Info = |
| 478 | DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 479 | Info->TInfo = GetTypeSourceInfo(); |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 480 | } |
| 481 | else { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 482 | DD->DeclInfo = GetTypeSourceInfo(); |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 486 | if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 487 | // We have a fully initialized TypeDecl. Read its type now. |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 488 | TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull()); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 489 | |
| 490 | // If this is a tag declaration with a typedef name for linkage, it's safe |
| 491 | // to load that typedef now. |
| 492 | if (NamedDeclForTagDecl) |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 493 | cast<TagDecl>(D)->TypedefNameDeclOrQualifier = |
| 494 | cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 495 | } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 496 | // if we have a fully initialized TypeDecl, we can safely read its type now. |
| 497 | ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull(); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 498 | } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
| 499 | // FunctionDecl's body was written last after all other Stmts/Exprs. |
Douglas Gregor | 559458c | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 500 | // We only read it if FD doesn't already have a body (e.g., from another |
| 501 | // module). |
Douglas Gregor | e4a838a | 2012-10-03 18:36:10 +0000 | [diff] [blame] | 502 | // FIXME: Can we diagnose ODR violations somehow? |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 503 | if (Record.readInt()) |
| 504 | ReadFunctionDefinition(FD); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 505 | } |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 508 | void ASTDeclReader::VisitDecl(Decl *D) { |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 509 | if (D->isTemplateParameter() || D->isTemplateParameterPack() || |
| 510 | isa<ParmVarDecl>(D)) { |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 511 | // We don't want to deserialize the DeclContext of a template |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 512 | // parameter or of a parameter of a function template immediately. These |
| 513 | // entities might be used in the formulation of its DeclContext (for |
| 514 | // example, a function parameter can be used in decltype() in trailing |
| 515 | // return type of the function). Use the translation unit DeclContext as a |
| 516 | // placeholder. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 517 | GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID(); |
| 518 | GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 519 | if (!LexicalDCIDForTemplateParmDecl) |
| 520 | LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 521 | Reader.addPendingDeclContextInfo(D, |
| 522 | SemaDCIDForTemplateParmDecl, |
| 523 | LexicalDCIDForTemplateParmDecl); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 524 | D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 525 | } else { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 526 | DeclContext *SemaDC = ReadDeclAs<DeclContext>(); |
| 527 | DeclContext *LexicalDC = ReadDeclAs<DeclContext>(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 528 | if (!LexicalDC) |
| 529 | LexicalDC = SemaDC; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 530 | DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 531 | // Avoid calling setLexicalDeclContext() directly because it uses |
| 532 | // Decl::getASTContext() internally which is unsafe during derialization. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 533 | D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, |
| 534 | Reader.getContext()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 535 | } |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 536 | D->setLocation(ThisDeclLoc); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 537 | D->setInvalidDecl(Record.readInt()); |
| 538 | if (Record.readInt()) { // hasAttrs |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 539 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 540 | Record.readAttributes(Attrs); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 541 | // Avoid calling setAttrs() directly because it uses Decl::getASTContext() |
| 542 | // internally which is unsafe during derialization. |
Argyrios Kyrtzidis | 6f40eb7 | 2012-02-09 02:44:08 +0000 | [diff] [blame] | 543 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 544 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 545 | D->setImplicit(Record.readInt()); |
| 546 | D->Used = Record.readInt(); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 547 | IsDeclMarkedUsed |= D->Used; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 548 | D->setReferenced(Record.readInt()); |
| 549 | D->setTopLevelDeclInObjCContainer(Record.readInt()); |
| 550 | D->setAccess((AccessSpecifier)Record.readInt()); |
Douglas Gregor | 98c05b2 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 551 | D->FromASTFile = true; |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 552 | bool ModulePrivate = Record.readInt(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 553 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 554 | // Determine whether this declaration is part of a (sub)module. If so, it |
| 555 | // may not yet be visible. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 556 | if (unsigned SubmoduleID = readSubmoduleID()) { |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 557 | // Store the owning submodule ID in the declaration. |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 558 | D->setModuleOwnershipKind( |
| 559 | ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate |
| 560 | : Decl::ModuleOwnershipKind::VisibleWhenImported); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 561 | D->setOwningModuleID(SubmoduleID); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 562 | |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 563 | if (ModulePrivate) { |
| 564 | // Module-private declarations are never visible, so there is no work to |
| 565 | // do. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 566 | } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { |
| 567 | // If local visibility is being tracked, this declaration will become |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 568 | // hidden and visible as the owning module does. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 569 | } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 570 | // Mark the declaration as visible when its owning module becomes visible. |
| 571 | if (Owner->NameVisibility == Module::AllVisible) |
| 572 | D->setVisibleDespiteOwningModule(); |
| 573 | else |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 574 | Reader.HiddenNamesMap[Owner].push_back(D); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 575 | } |
Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 576 | } else if (ModulePrivate) { |
| 577 | D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 578 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 581 | void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { |
| 582 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 583 | D->setLocation(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 584 | D->CommentKind = (PragmaMSCommentKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 585 | std::string Arg = ReadString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 586 | memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); |
| 587 | D->getTrailingObjects<char>()[Arg.size()] = '\0'; |
| 588 | } |
| 589 | |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 590 | void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { |
| 591 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 592 | D->setLocation(ReadSourceLocation()); |
| 593 | std::string Name = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 594 | memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); |
| 595 | D->getTrailingObjects<char>()[Name.size()] = '\0'; |
| 596 | |
| 597 | D->ValueStart = Name.size() + 1; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 598 | std::string Value = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 599 | memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), |
| 600 | Value.size()); |
| 601 | D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; |
| 602 | } |
| 603 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 604 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 605 | llvm_unreachable("Translation units are not serialized"); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 608 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 609 | VisitDecl(ND); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 610 | ND->setDeclName(Record.readDeclarationName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 611 | AnonymousDeclNumber = Record.readInt(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 614 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 615 | VisitNamedDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 616 | TD->setLocStart(ReadSourceLocation()); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 617 | // Delay type reading until after we have fully initialized the decl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 618 | TypeIDForTypeDecl = Record.getGlobalTypeID(Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 621 | ASTDeclReader::RedeclarableResult |
| 622 | ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 623 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 624 | VisitTypeDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 625 | TypeSourceInfo *TInfo = GetTypeSourceInfo(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 626 | if (Record.readInt()) { // isModed |
| 627 | QualType modedT = Record.readType(); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 628 | TD->setModedTypeSourceInfo(TInfo, modedT); |
| 629 | } else |
| 630 | TD->setTypeSourceInfo(TInfo); |
Richard Smith | c0ca4c2 | 2017-01-26 22:39:55 +0000 | [diff] [blame] | 631 | // Read and discard the declaration for which this is a typedef name for |
| 632 | // linkage, if it exists. We cannot rely on our type to pull in this decl, |
| 633 | // because it might have been merged with a type from another module and |
| 634 | // thus might not refer to our version of the declaration. |
| 635 | ReadDecl(); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 636 | return Redecl; |
Douglas Gregor | 1f17906 | 2011-12-19 14:40:25 +0000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 640 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
| 641 | mergeRedeclarable(TD, Redecl); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 644 | void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 645 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 646 | if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>()) |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 647 | // Merged when we merge the template. |
| 648 | TD->setDescribedAliasTemplate(Template); |
| 649 | else |
| 650 | mergeRedeclarable(TD, Redecl); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 653 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 654 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 655 | VisitTypeDecl(TD); |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 656 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 657 | TD->IdentifierNamespace = Record.readInt(); |
| 658 | TD->setTagKind((TagDecl::TagKind)Record.readInt()); |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 659 | if (!isa<CXXRecordDecl>(TD)) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 660 | TD->setCompleteDefinition(Record.readInt()); |
| 661 | TD->setEmbeddedInDeclarator(Record.readInt()); |
| 662 | TD->setFreeStanding(Record.readInt()); |
| 663 | TD->setCompleteDefinitionRequired(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 664 | TD->setBraceRange(ReadSourceRange()); |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 665 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 666 | switch (Record.readInt()) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 667 | case 0: |
| 668 | break; |
| 669 | case 1: { // ExtInfo |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 670 | TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 671 | ReadQualifierInfo(*Info); |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 672 | TD->TypedefNameDeclOrQualifier = Info; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 673 | break; |
| 674 | } |
| 675 | case 2: // TypedefNameForAnonDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 676 | NamedDeclForTagDecl = ReadDeclID(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 677 | TypedefNameForLinkage = Record.getIdentifierInfo(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 678 | break; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 679 | default: |
| 680 | llvm_unreachable("unexpected tag info kind"); |
| 681 | } |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 682 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 683 | if (!isa<CXXRecordDecl>(TD)) |
| 684 | mergeRedeclarable(TD, Redecl); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 685 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 688 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 689 | VisitTagDecl(ED); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 690 | if (TypeSourceInfo *TI = GetTypeSourceInfo()) |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 691 | ED->setIntegerTypeSourceInfo(TI); |
| 692 | else |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 693 | ED->setIntegerType(Record.readType()); |
| 694 | ED->setPromotionType(Record.readType()); |
| 695 | ED->setNumPositiveBits(Record.readInt()); |
| 696 | ED->setNumNegativeBits(Record.readInt()); |
| 697 | ED->IsScoped = Record.readInt(); |
| 698 | ED->IsScopedUsingClassTag = Record.readInt(); |
| 699 | ED->IsFixed = Record.readInt(); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 700 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 701 | // If this is a definition subject to the ODR, and we already have a |
| 702 | // definition, merge this one into it. |
| 703 | if (ED->IsCompleteDefinition && |
| 704 | Reader.getContext().getLangOpts().Modules && |
| 705 | Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 706 | EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; |
| 707 | if (!OldDef) { |
| 708 | // This is the first time we've seen an imported definition. Look for a |
| 709 | // local definition before deciding that we are the first definition. |
| 710 | for (auto *D : merged_redecls(ED->getCanonicalDecl())) { |
| 711 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { |
| 712 | OldDef = D; |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | if (OldDef) { |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 718 | Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); |
| 719 | ED->IsCompleteDefinition = false; |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 720 | Reader.mergeDefinitionVisibility(OldDef, ED); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 721 | } else { |
| 722 | OldDef = ED; |
| 723 | } |
| 724 | } |
| 725 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 726 | if (EnumDecl *InstED = ReadDeclAs<EnumDecl>()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 727 | TemplateSpecializationKind TSK = |
| 728 | (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 729 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 730 | ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); |
| 731 | ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 732 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 735 | ASTDeclReader::RedeclarableResult |
| 736 | ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { |
| 737 | RedeclarableResult Redecl = VisitTagDecl(RD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 738 | RD->setHasFlexibleArrayMember(Record.readInt()); |
| 739 | RD->setAnonymousStructOrUnion(Record.readInt()); |
| 740 | RD->setHasObjectMember(Record.readInt()); |
| 741 | RD->setHasVolatileMember(Record.readInt()); |
Akira Hatanaka | 34fb264 | 2018-03-13 18:58:25 +0000 | [diff] [blame] | 742 | RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt()); |
| 743 | RD->setNonTrivialToPrimitiveCopy(Record.readInt()); |
| 744 | RD->setNonTrivialToPrimitiveDestroy(Record.readInt()); |
Akira Hatanaka | d791e92 | 2018-03-19 17:38:40 +0000 | [diff] [blame^] | 745 | RD->setCanPassInRegisters(Record.readInt()); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 746 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 749 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 750 | VisitNamedDecl(VD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 751 | VD->setType(Record.readType()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 754 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 755 | VisitValueDecl(ECD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 756 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 757 | ECD->setInitExpr(Record.readExpr()); |
| 758 | ECD->setInitVal(Record.readAPSInt()); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 759 | mergeMergeable(ECD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 762 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 763 | VisitValueDecl(DD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 764 | DD->setInnerLocStart(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 765 | if (Record.readInt()) { // hasExtInfo |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 766 | DeclaratorDecl::ExtInfo *Info |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 767 | = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 768 | ReadQualifierInfo(*Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 769 | DD->DeclInfo = Info; |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 770 | } |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 773 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 774 | RedeclarableResult Redecl = VisitRedeclarable(FD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 775 | VisitDeclaratorDecl(FD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 776 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 777 | ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 778 | FD->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 779 | |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 780 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, |
| 781 | // after everything else is read. |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 782 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 783 | FD->SClass = (StorageClass)Record.readInt(); |
| 784 | FD->IsInline = Record.readInt(); |
| 785 | FD->IsInlineSpecified = Record.readInt(); |
Richard Smith | 78e3d70 | 2017-02-10 01:32:04 +0000 | [diff] [blame] | 786 | FD->IsExplicitSpecified = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 787 | FD->IsVirtualAsWritten = Record.readInt(); |
| 788 | FD->IsPure = Record.readInt(); |
| 789 | FD->HasInheritedPrototype = Record.readInt(); |
| 790 | FD->HasWrittenPrototype = Record.readInt(); |
| 791 | FD->IsDeleted = Record.readInt(); |
| 792 | FD->IsTrivial = Record.readInt(); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 793 | FD->IsTrivialForCall = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 794 | FD->IsDefaulted = Record.readInt(); |
| 795 | FD->IsExplicitlyDefaulted = Record.readInt(); |
| 796 | FD->HasImplicitReturnZero = Record.readInt(); |
| 797 | FD->IsConstexpr = Record.readInt(); |
Reid Kleckner | 0d15738 | 2017-01-10 21:27:03 +0000 | [diff] [blame] | 798 | FD->UsesSEHTry = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 799 | FD->HasSkippedBody = Record.readInt(); |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 800 | FD->IsMultiVersion = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 801 | FD->IsLateTemplateParsed = Record.readInt(); |
| 802 | FD->setCachedLinkage(Linkage(Record.readInt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 803 | FD->EndRangeLoc = ReadSourceLocation(); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 804 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 805 | FD->ODRHash = Record.readInt(); |
| 806 | FD->HasODRHash = true; |
| 807 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 808 | switch ((FunctionDecl::TemplatedKind)Record.readInt()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 809 | case FunctionDecl::TK_NonTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 810 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 811 | break; |
| 812 | case FunctionDecl::TK_FunctionTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 813 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 814 | FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>()); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 815 | break; |
| 816 | case FunctionDecl::TK_MemberSpecialization: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 817 | FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 818 | TemplateSpecializationKind TSK = |
| 819 | (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 820 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 821 | FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 822 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 823 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 824 | break; |
| 825 | } |
| 826 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 827 | FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 828 | TemplateSpecializationKind TSK = |
| 829 | (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 830 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 831 | // Template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 832 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 833 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 834 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 835 | // Template args as written. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 836 | SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 837 | SourceLocation LAngleLoc, RAngleLoc; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 838 | bool HasTemplateArgumentsAsWritten = Record.readInt(); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 839 | if (HasTemplateArgumentsAsWritten) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 840 | unsigned NumTemplateArgLocs = Record.readInt(); |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 841 | TemplArgLocs.reserve(NumTemplateArgLocs); |
| 842 | for (unsigned i=0; i != NumTemplateArgLocs; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 843 | TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 844 | |
| 845 | LAngleLoc = ReadSourceLocation(); |
| 846 | RAngleLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 847 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 848 | |
| 849 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 850 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 851 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 852 | TemplateArgumentList *TemplArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 853 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 854 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 855 | for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i) |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 856 | TemplArgsInfo.addArgument(TemplArgLocs[i]); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 857 | FunctionTemplateSpecializationInfo *FTInfo |
| 858 | = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK, |
| 859 | TemplArgList, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 860 | HasTemplateArgumentsAsWritten ? &TemplArgsInfo |
| 861 | : nullptr, |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 862 | POI); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 863 | FD->TemplateOrSpecialization = FTInfo; |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 864 | |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 865 | if (FD->isCanonicalDecl()) { // if canonical add to template's set. |
Argyrios Kyrtzidis | f24d569 | 2010-09-13 11:45:48 +0000 | [diff] [blame] | 866 | // The template that contains the specializations set. It's not safe to |
| 867 | // use getCanonicalDecl on Template since it may still be initializing. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 868 | FunctionTemplateDecl *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 869 | // Get the InsertPos by FindNodeOrInsertPos() instead of calling |
| 870 | // InsertNode(FTInfo) directly to avoid the getASTContext() call in |
| 871 | // FunctionTemplateSpecializationInfo's Profile(). |
| 872 | // We avoid getASTContext because a decl in the parent hierarchy may |
| 873 | // be initializing. |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 874 | llvm::FoldingSetNodeID ID; |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 875 | FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 876 | void *InsertPos = nullptr; |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 877 | FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 878 | FunctionTemplateSpecializationInfo *ExistingInfo = |
| 879 | CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); |
Argyrios Kyrtzidis | e60e408 | 2012-09-10 23:28:22 +0000 | [diff] [blame] | 880 | if (InsertPos) |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 881 | CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); |
| 882 | else { |
| 883 | assert(Reader.getContext().getLangOpts().Modules && |
| 884 | "already deserialized this template specialization"); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 885 | mergeRedeclarable(FD, ExistingInfo->Function, Redecl); |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 886 | } |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 887 | } |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 888 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 889 | } |
| 890 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 891 | // Templates. |
| 892 | UnresolvedSet<8> TemplDecls; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 893 | unsigned NumTemplates = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 894 | while (NumTemplates--) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 895 | TemplDecls.addDecl(ReadDeclAs<NamedDecl>()); |
| 896 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 897 | // Templates args. |
| 898 | TemplateArgumentListInfo TemplArgs; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 899 | unsigned NumArgs = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 900 | while (NumArgs--) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 901 | TemplArgs.addArgument(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 902 | TemplArgs.setLAngleLoc(ReadSourceLocation()); |
| 903 | TemplArgs.setRAngleLoc(ReadSourceLocation()); |
| 904 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 905 | FD->setDependentTemplateSpecialization(Reader.getContext(), |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 906 | TemplDecls, TemplArgs); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 907 | // These are not merged; we don't need to merge redeclarations of dependent |
| 908 | // template friends. |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 909 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 910 | } |
| 911 | } |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 912 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 913 | // Read in the parameters. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 914 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 915 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 916 | Params.reserve(NumParams); |
| 917 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 918 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 919 | FD->setParams(Reader.getContext(), Params); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 922 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 923 | VisitNamedDecl(MD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 924 | if (Record.readInt()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 925 | // Load the body on-demand. Most clients won't care, because method |
| 926 | // definitions rarely show up in headers. |
| 927 | Reader.PendingBodies[MD] = GetCurrentCursorOffset(); |
| 928 | HasPendingBody = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 929 | MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>()); |
| 930 | MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 931 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 932 | MD->setInstanceMethod(Record.readInt()); |
| 933 | MD->setVariadic(Record.readInt()); |
| 934 | MD->setPropertyAccessor(Record.readInt()); |
| 935 | MD->setDefined(Record.readInt()); |
| 936 | MD->IsOverriding = Record.readInt(); |
| 937 | MD->HasSkippedBody = Record.readInt(); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 938 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 939 | MD->IsRedeclaration = Record.readInt(); |
| 940 | MD->HasRedeclaration = Record.readInt(); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 941 | if (MD->HasRedeclaration) |
| 942 | Reader.getContext().setObjCMethodRedeclaration(MD, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 943 | ReadDeclAs<ObjCMethodDecl>()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 944 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 945 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); |
| 946 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); |
| 947 | MD->SetRelatedResultType(Record.readInt()); |
| 948 | MD->setReturnType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 949 | MD->setReturnTypeSourceInfo(GetTypeSourceInfo()); |
| 950 | MD->DeclEndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 951 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 952 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 953 | Params.reserve(NumParams); |
| 954 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 955 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 956 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 957 | MD->SelLocsKind = Record.readInt(); |
| 958 | unsigned NumStoredSelLocs = Record.readInt(); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 959 | SmallVector<SourceLocation, 16> SelLocs; |
| 960 | SelLocs.reserve(NumStoredSelLocs); |
| 961 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 962 | SelLocs.push_back(ReadSourceLocation()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 963 | |
| 964 | MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 967 | void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
David Blaikie | 27a1bc0 | 2015-09-28 23:48:49 +0000 | [diff] [blame] | 968 | VisitTypedefNameDecl(D); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 969 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 970 | D->Variance = Record.readInt(); |
| 971 | D->Index = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 972 | D->VarianceLoc = ReadSourceLocation(); |
| 973 | D->ColonLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 976 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 977 | VisitNamedDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 978 | CD->setAtStartLoc(ReadSourceLocation()); |
| 979 | CD->setAtEndRange(ReadSourceRange()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 982 | ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 983 | unsigned numParams = Record.readInt(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 984 | if (numParams == 0) |
| 985 | return nullptr; |
| 986 | |
| 987 | SmallVector<ObjCTypeParamDecl *, 4> typeParams; |
| 988 | typeParams.reserve(numParams); |
| 989 | for (unsigned i = 0; i != numParams; ++i) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 990 | auto typeParam = ReadDeclAs<ObjCTypeParamDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 991 | if (!typeParam) |
| 992 | return nullptr; |
| 993 | |
| 994 | typeParams.push_back(typeParam); |
| 995 | } |
| 996 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 997 | SourceLocation lAngleLoc = ReadSourceLocation(); |
| 998 | SourceLocation rAngleLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 999 | |
| 1000 | return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, |
| 1001 | typeParams, rAngleLoc); |
| 1002 | } |
| 1003 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1004 | void ASTDeclReader::ReadObjCDefinitionData( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1005 | struct ObjCInterfaceDecl::DefinitionData &Data) { |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1006 | // Read the superclass. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1007 | Data.SuperClassTInfo = GetTypeSourceInfo(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1008 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1009 | Data.EndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1010 | Data.HasDesignatedInitializers = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1011 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1012 | // Read the directly referenced protocols and their SourceLocations. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1013 | unsigned NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1014 | SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 1015 | Protocols.reserve(NumProtocols); |
| 1016 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1017 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1018 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1019 | ProtoLocs.reserve(NumProtocols); |
| 1020 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1021 | ProtoLocs.push_back(ReadSourceLocation()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1022 | Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 1023 | Reader.getContext()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1024 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1025 | // Read the transitive closure of protocols referenced by this class. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1026 | NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1027 | Protocols.clear(); |
| 1028 | Protocols.reserve(NumProtocols); |
| 1029 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1030 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1031 | Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, |
| 1032 | Reader.getContext()); |
| 1033 | } |
| 1034 | |
| 1035 | void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D, |
| 1036 | struct ObjCInterfaceDecl::DefinitionData &&NewDD) { |
| 1037 | // FIXME: odr checking? |
| 1038 | } |
| 1039 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1040 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 1041 | RedeclarableResult Redecl = VisitRedeclarable(ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1042 | VisitObjCContainerDecl(ID); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1043 | TypeIDForTypeDecl = Record.getGlobalTypeID(Record.readInt()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 1044 | mergeRedeclarable(ID, Redecl); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1045 | |
| 1046 | ID->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1047 | if (Record.readInt()) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1048 | // Read the definition. |
| 1049 | ID->allocateDefinitionData(); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1050 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1051 | ReadObjCDefinitionData(ID->data()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1052 | ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); |
| 1053 | if (Canon->Data.getPointer()) { |
| 1054 | // If we already have a definition, keep the definition invariant and |
| 1055 | // merge the data. |
| 1056 | MergeDefinitionData(Canon, std::move(ID->data())); |
| 1057 | ID->Data = Canon->Data; |
| 1058 | } else { |
| 1059 | // Set the definition data of the canonical declaration, so other |
| 1060 | // redeclarations will see it. |
| 1061 | ID->getCanonicalDecl()->Data = ID->Data; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1062 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1063 | // We will rebuild this list lazily. |
| 1064 | ID->setIvarList(nullptr); |
| 1065 | } |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1066 | |
Douglas Gregor | c1a61fe | 2011-12-19 20:51:16 +0000 | [diff] [blame] | 1067 | // Note that we have deserialized a definition. |
| 1068 | Reader.PendingDefinitions.insert(ID); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1069 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1070 | // Note that we've loaded this Objective-C class. |
| 1071 | Reader.ObjCClassesLoaded.push_back(ID); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1072 | } else { |
| 1073 | ID->Data = ID->getCanonicalDecl()->Data; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1074 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1077 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1078 | VisitFieldDecl(IVD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1079 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1080 | // This field will be built lazily. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1081 | IVD->setNextIvar(nullptr); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1082 | bool synth = Record.readInt(); |
Fariborz Jahanian | aea8e1e | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 1083 | IVD->setSynthesize(synth); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1086 | void ASTDeclReader::ReadObjCDefinitionData( |
| 1087 | struct ObjCProtocolDecl::DefinitionData &Data) { |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1088 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1089 | unsigned NumProtoRefs = Record.readInt(); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1090 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 1091 | ProtoRefs.reserve(NumProtoRefs); |
| 1092 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1093 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1094 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1095 | ProtoLocs.reserve(NumProtoRefs); |
| 1096 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1097 | ProtoLocs.push_back(ReadSourceLocation()); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1098 | Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, |
| 1099 | ProtoLocs.data(), Reader.getContext()); |
| 1100 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1101 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1102 | void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D, |
| 1103 | struct ObjCProtocolDecl::DefinitionData &&NewDD) { |
| 1104 | // FIXME: odr checking? |
| 1105 | } |
| 1106 | |
| 1107 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 1108 | RedeclarableResult Redecl = VisitRedeclarable(PD); |
| 1109 | VisitObjCContainerDecl(PD); |
| 1110 | mergeRedeclarable(PD, Redecl); |
| 1111 | |
| 1112 | if (Record.readInt()) { |
| 1113 | // Read the definition. |
| 1114 | PD->allocateDefinitionData(); |
| 1115 | |
| 1116 | ReadObjCDefinitionData(PD->data()); |
| 1117 | |
| 1118 | ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); |
| 1119 | if (Canon->Data.getPointer()) { |
| 1120 | // If we already have a definition, keep the definition invariant and |
| 1121 | // merge the data. |
| 1122 | MergeDefinitionData(Canon, std::move(PD->data())); |
| 1123 | PD->Data = Canon->Data; |
| 1124 | } else { |
| 1125 | // Set the definition data of the canonical declaration, so other |
| 1126 | // redeclarations will see it. |
| 1127 | PD->getCanonicalDecl()->Data = PD->Data; |
| 1128 | } |
Douglas Gregor | a715bff | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1129 | // Note that we have deserialized a definition. |
| 1130 | Reader.PendingDefinitions.insert(PD); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1131 | } else { |
| 1132 | PD->Data = PD->getCanonicalDecl()->Data; |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1133 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1136 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1137 | VisitFieldDecl(FD); |
| 1138 | } |
| 1139 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1140 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1141 | VisitObjCContainerDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1142 | CD->setCategoryNameLoc(ReadSourceLocation()); |
| 1143 | CD->setIvarLBraceLoc(ReadSourceLocation()); |
| 1144 | CD->setIvarRBraceLoc(ReadSourceLocation()); |
| 1145 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1146 | // Note that this category has been deserialized. We do this before |
| 1147 | // deserializing the interface declaration, so that it will consider this |
| 1148 | /// category. |
| 1149 | Reader.CategoriesDeserialized.insert(CD); |
| 1150 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1151 | CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1152 | CD->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1153 | unsigned NumProtoRefs = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1154 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1155 | ProtoRefs.reserve(NumProtoRefs); |
| 1156 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1157 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1158 | SmallVector<SourceLocation, 16> ProtoLocs; |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1159 | ProtoLocs.reserve(NumProtoRefs); |
| 1160 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1161 | ProtoLocs.push_back(ReadSourceLocation()); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1162 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1163 | Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1166 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1167 | VisitNamedDecl(CAD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1168 | CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1171 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1172 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1173 | D->setAtLoc(ReadSourceLocation()); |
| 1174 | D->setLParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1175 | QualType T = Record.readType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1176 | TypeSourceInfo *TSI = GetTypeSourceInfo(); |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1177 | D->setType(T, TSI); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1178 | D->setPropertyAttributes( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1179 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 1180 | D->setPropertyAttributesAsWritten( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1181 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1182 | D->setPropertyImplementation( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1183 | (ObjCPropertyDecl::PropertyControl)Record.readInt()); |
Argyrios Kyrtzidis | c6c4ec8 | 2017-03-17 00:49:42 +0000 | [diff] [blame] | 1184 | DeclarationName GetterName = Record.readDeclarationName(); |
| 1185 | SourceLocation GetterLoc = ReadSourceLocation(); |
| 1186 | D->setGetterName(GetterName.getObjCSelector(), GetterLoc); |
| 1187 | DeclarationName SetterName = Record.readDeclarationName(); |
| 1188 | SourceLocation SetterLoc = ReadSourceLocation(); |
| 1189 | D->setSetterName(SetterName.getObjCSelector(), SetterLoc); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1190 | D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1191 | D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1192 | D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1195 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | 067c407 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 1196 | VisitObjCContainerDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1197 | D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1200 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1201 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1202 | D->CategoryNameLoc = ReadSourceLocation(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1205 | void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1206 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1207 | D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>()); |
| 1208 | D->SuperLoc = ReadSourceLocation(); |
| 1209 | D->setIvarLBraceLoc(ReadSourceLocation()); |
| 1210 | D->setIvarRBraceLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1211 | D->setHasNonZeroConstructors(Record.readInt()); |
| 1212 | D->setHasDestructors(Record.readInt()); |
| 1213 | D->NumIvarInitializers = Record.readInt(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 1214 | if (D->NumIvarInitializers) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1215 | D->IvarInitializers = ReadGlobalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1218 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1219 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1220 | D->setAtLoc(ReadSourceLocation()); |
| 1221 | D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>()); |
| 1222 | D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(); |
| 1223 | D->IvarLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1224 | D->setGetterCXXConstructor(Record.readExpr()); |
| 1225 | D->setSetterCXXAssignment(Record.readExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1228 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 1229 | VisitDeclaratorDecl(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1230 | FD->Mutable = Record.readInt(); |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1231 | |
| 1232 | if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) { |
| 1233 | FD->InitStorage.setInt(ISK); |
| 1234 | FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType |
| 1235 | ? Record.readType().getAsOpaquePtr() |
| 1236 | : Record.readExpr()); |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 1237 | } |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1238 | |
| 1239 | if (auto *BW = Record.readExpr()) |
| 1240 | FD->setBitWidth(BW); |
| 1241 | |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1242 | if (!FD->getDeclName()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1243 | if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1244 | Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1245 | } |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 1246 | mergeMergeable(FD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1249 | void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { |
| 1250 | VisitDeclaratorDecl(PD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1251 | PD->GetterId = Record.getIdentifierInfo(); |
| 1252 | PD->SetterId = Record.getIdentifierInfo(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1255 | void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { |
| 1256 | VisitValueDecl(FD); |
| 1257 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1258 | FD->ChainingSize = Record.readInt(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1259 | assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1260 | FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1261 | |
| 1262 | for (unsigned I = 0; I != FD->ChainingSize; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1263 | FD->Chaining[I] = ReadDeclAs<NamedDecl>(); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 1264 | |
| 1265 | mergeMergeable(FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1268 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 1269 | RedeclarableResult Redecl = VisitRedeclarable(VD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 1270 | VisitDeclaratorDecl(VD); |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1271 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1272 | VD->VarDeclBits.SClass = (StorageClass)Record.readInt(); |
| 1273 | VD->VarDeclBits.TSCSpec = Record.readInt(); |
| 1274 | VD->VarDeclBits.InitStyle = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1275 | if (!isa<ParmVarDecl>(VD)) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1276 | VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = |
| 1277 | Record.readInt(); |
| 1278 | VD->NonParmVarDeclBits.ExceptionVar = Record.readInt(); |
| 1279 | VD->NonParmVarDeclBits.NRVOVariable = Record.readInt(); |
| 1280 | VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt(); |
| 1281 | VD->NonParmVarDeclBits.ARCPseudoStrong = Record.readInt(); |
| 1282 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 1283 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
| 1284 | VD->NonParmVarDeclBits.IsConstexpr = Record.readInt(); |
| 1285 | VD->NonParmVarDeclBits.IsInitCapture = Record.readInt(); |
| 1286 | VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1287 | VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1288 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1289 | Linkage VarLinkage = Linkage(Record.readInt()); |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1290 | VD->setCachedLinkage(VarLinkage); |
| 1291 | |
| 1292 | // Reconstruct the one piece of the IdentifierNamespace that we need. |
Ted Kremenek | a683f63 | 2014-02-11 06:29:29 +0000 | [diff] [blame] | 1293 | if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1294 | VD->getLexicalDeclContext()->isFunctionOrMethod()) |
| 1295 | VD->setLocalExternDecl(); |
Rafael Espindola | 50df3a0 | 2013-05-25 17:16:20 +0000 | [diff] [blame] | 1296 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1297 | if (uint64_t Val = Record.readInt()) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1298 | VD->setInit(Record.readExpr()); |
Vassil Vassilev | d1a8813 | 2016-10-06 13:04:54 +0000 | [diff] [blame] | 1299 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1300 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 1301 | Eval->CheckedICE = true; |
| 1302 | Eval->IsICE = Val == 3; |
| 1303 | } |
| 1304 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1305 | |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 1306 | if (VD->getStorageDuration() == SD_Static && Record.readInt()) |
| 1307 | Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
| 1308 | |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1309 | enum VarKind { |
| 1310 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| 1311 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1312 | switch ((VarKind)Record.readInt()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1313 | case VarNotTemplate: |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1314 | // Only true variables (not parameters or implicit parameters) can be |
| 1315 | // merged; the other kinds are not really redeclarable at all. |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 1316 | if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && |
| 1317 | !isa<VarTemplateSpecializationDecl>(VD)) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1318 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1319 | break; |
| 1320 | case VarTemplate: |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1321 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1322 | VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>()); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1323 | break; |
| 1324 | case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1325 | VarDecl *Tmpl = ReadDeclAs<VarDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1326 | TemplateSpecializationKind TSK = |
| 1327 | (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1328 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1329 | Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1330 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1333 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1334 | |
| 1335 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1338 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1339 | VisitVarDecl(PD); |
| 1340 | } |
| 1341 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1342 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1343 | VisitVarDecl(PD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1344 | unsigned isObjCMethodParam = Record.readInt(); |
| 1345 | unsigned scopeDepth = Record.readInt(); |
| 1346 | unsigned scopeIndex = Record.readInt(); |
| 1347 | unsigned declQualifier = Record.readInt(); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1348 | if (isObjCMethodParam) { |
| 1349 | assert(scopeDepth == 0); |
| 1350 | PD->setObjCMethodScopeInfo(scopeIndex); |
| 1351 | PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; |
| 1352 | } else { |
| 1353 | PD->setScopeInfo(scopeDepth, scopeIndex); |
| 1354 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1355 | PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); |
| 1356 | PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); |
| 1357 | if (Record.readInt()) // hasUninstantiatedDefaultArg. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1358 | PD->setUninstantiatedDefaultArg(Record.readExpr()); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 1359 | |
| 1360 | // FIXME: If this is a redeclaration of a function from another module, handle |
| 1361 | // inheritance of default arguments. |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1364 | void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { |
| 1365 | VisitVarDecl(DD); |
| 1366 | BindingDecl **BDs = DD->getTrailingObjects<BindingDecl*>(); |
| 1367 | for (unsigned I = 0; I != DD->NumBindings; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1368 | BDs[I] = ReadDeclAs<BindingDecl>(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { |
| 1372 | VisitValueDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1373 | BD->Binding = Record.readExpr(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1376 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1377 | VisitDecl(AD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1378 | AD->setAsmString(cast<StringLiteral>(Record.readExpr())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1379 | AD->setRParenLoc(ReadSourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1382 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1383 | VisitDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1384 | BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1385 | BD->setSignatureAsWritten(GetTypeSourceInfo()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1386 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1387 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1388 | Params.reserve(NumParams); |
| 1389 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1390 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 1391 | BD->setParams(Params); |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 1392 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1393 | BD->setIsVariadic(Record.readInt()); |
| 1394 | BD->setBlockMissingReturnType(Record.readInt()); |
| 1395 | BD->setIsConversionFromLambda(Record.readInt()); |
John McCall | cf6ce28 | 2012-04-13 17:33:29 +0000 | [diff] [blame] | 1396 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1397 | bool capturesCXXThis = Record.readInt(); |
| 1398 | unsigned numCaptures = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1399 | SmallVector<BlockDecl::Capture, 16> captures; |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1400 | captures.reserve(numCaptures); |
| 1401 | for (unsigned i = 0; i != numCaptures; ++i) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1402 | VarDecl *decl = ReadDeclAs<VarDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1403 | unsigned flags = Record.readInt(); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1404 | bool byRef = (flags & 1); |
| 1405 | bool nested = (flags & 2); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1406 | Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1407 | |
| 1408 | captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); |
| 1409 | } |
Benjamin Kramer | b40e4af | 2015-08-05 09:40:35 +0000 | [diff] [blame] | 1410 | BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1413 | void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { |
| 1414 | VisitDecl(CD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1415 | unsigned ContextParamPos = Record.readInt(); |
| 1416 | CD->setNothrow(Record.readInt() != 0); |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1417 | // Body is set by VisitCapturedStmt. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1418 | for (unsigned I = 0; I < CD->NumParams; ++I) { |
| 1419 | if (I != ContextParamPos) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1420 | CD->setParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1421 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1422 | CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1423 | } |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1426 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1427 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1428 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1429 | D->setExternLoc(ReadSourceLocation()); |
| 1430 | D->setRBraceLoc(ReadSourceLocation()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1433 | void ASTDeclReader::VisitExportDecl(ExportDecl *D) { |
| 1434 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1435 | D->RBraceLoc = ReadSourceLocation(); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1438 | void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { |
| 1439 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1440 | D->setLocStart(ReadSourceLocation()); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1443 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1444 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1445 | VisitNamedDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1446 | D->setInline(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1447 | D->LocStart = ReadSourceLocation(); |
| 1448 | D->RBraceLoc = ReadSourceLocation(); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 1449 | |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1450 | // Defer loading the anonymous namespace until we've finished merging |
| 1451 | // this namespace; loading it might load a later declaration of the |
| 1452 | // same namespace, and we have an invariant that older declarations |
| 1453 | // get merged before newer ones try to merge. |
| 1454 | GlobalDeclID AnonNamespace = 0; |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1455 | if (Redecl.getFirstID() == ThisDeclID) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1456 | AnonNamespace = ReadDeclID(); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1457 | } else { |
| 1458 | // Link this namespace back to the first declaration, which has already |
| 1459 | // been deserialized. |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 1460 | D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl()); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1461 | } |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 1462 | |
| 1463 | mergeRedeclarable(D, Redecl); |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1464 | |
| 1465 | if (AnonNamespace) { |
| 1466 | // Each module has its own anonymous namespace, which is disjoint from |
| 1467 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 1468 | // namespace at all. |
| 1469 | NamespaceDecl *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1470 | if (!Record.isModule()) |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1471 | D->setAnonymousNamespace(Anon); |
| 1472 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1475 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1476 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1477 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1478 | D->NamespaceLoc = ReadSourceLocation(); |
| 1479 | D->IdentLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1480 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1481 | D->Namespace = ReadDeclAs<NamedDecl>(); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1482 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1485 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1486 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1487 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1488 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1489 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
| 1490 | D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1491 | D->setTypename(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1492 | if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1493 | Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1494 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1497 | void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { |
| 1498 | VisitNamedDecl(D); |
| 1499 | D->InstantiatedFrom = ReadDeclAs<NamedDecl>(); |
| 1500 | NamedDecl **Expansions = D->getTrailingObjects<NamedDecl*>(); |
| 1501 | for (unsigned I = 0; I != D->NumExpansions; ++I) |
| 1502 | Expansions[I] = ReadDeclAs<NamedDecl>(); |
| 1503 | mergeMergeable(D); |
| 1504 | } |
| 1505 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1506 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1507 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1508 | VisitNamedDecl(D); |
Richard Smith | a263c34 | 2018-01-06 01:07:05 +0000 | [diff] [blame] | 1509 | D->Underlying = ReadDeclAs<NamedDecl>(); |
| 1510 | D->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1511 | D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(); |
| 1512 | UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1513 | if (Pattern) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1514 | Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1515 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1518 | void ASTDeclReader::VisitConstructorUsingShadowDecl( |
| 1519 | ConstructorUsingShadowDecl *D) { |
| 1520 | VisitUsingShadowDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1521 | D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1522 | D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1523 | D->IsVirtual = Record.readInt(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1526 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1527 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1528 | D->UsingLoc = ReadSourceLocation(); |
| 1529 | D->NamespaceLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1530 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1531 | D->NominatedNamespace = ReadDeclAs<NamedDecl>(); |
| 1532 | D->CommonAncestor = ReadDeclAs<DeclContext>(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1535 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1536 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1537 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1538 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1539 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1540 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1541 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1544 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1545 | UnresolvedUsingTypenameDecl *D) { |
| 1546 | VisitTypeDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1547 | D->TypenameLocation = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1548 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1549 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1550 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1553 | void ASTDeclReader::ReadCXXDefinitionData( |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1554 | struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) { |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1555 | // Note: the caller has deserialized the IsLambda bit already. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1556 | Data.UserDeclaredConstructor = Record.readInt(); |
| 1557 | Data.UserDeclaredSpecialMembers = Record.readInt(); |
| 1558 | Data.Aggregate = Record.readInt(); |
| 1559 | Data.PlainOldData = Record.readInt(); |
| 1560 | Data.Empty = Record.readInt(); |
| 1561 | Data.Polymorphic = Record.readInt(); |
| 1562 | Data.Abstract = Record.readInt(); |
| 1563 | Data.IsStandardLayout = Record.readInt(); |
| 1564 | Data.HasNoNonEmptyBases = Record.readInt(); |
| 1565 | Data.HasPrivateFields = Record.readInt(); |
| 1566 | Data.HasProtectedFields = Record.readInt(); |
| 1567 | Data.HasPublicFields = Record.readInt(); |
| 1568 | Data.HasMutableFields = Record.readInt(); |
| 1569 | Data.HasVariantMembers = Record.readInt(); |
| 1570 | Data.HasOnlyCMembers = Record.readInt(); |
| 1571 | Data.HasInClassInitializer = Record.readInt(); |
| 1572 | Data.HasUninitializedReferenceMember = Record.readInt(); |
| 1573 | Data.HasUninitializedFields = Record.readInt(); |
| 1574 | Data.HasInheritedConstructor = Record.readInt(); |
| 1575 | Data.HasInheritedAssignment = Record.readInt(); |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1576 | Data.NeedOverloadResolutionForCopyConstructor = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1577 | Data.NeedOverloadResolutionForMoveConstructor = Record.readInt(); |
| 1578 | Data.NeedOverloadResolutionForMoveAssignment = Record.readInt(); |
| 1579 | Data.NeedOverloadResolutionForDestructor = Record.readInt(); |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1580 | Data.DefaultedCopyConstructorIsDeleted = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1581 | Data.DefaultedMoveConstructorIsDeleted = Record.readInt(); |
| 1582 | Data.DefaultedMoveAssignmentIsDeleted = Record.readInt(); |
| 1583 | Data.DefaultedDestructorIsDeleted = Record.readInt(); |
| 1584 | Data.HasTrivialSpecialMembers = Record.readInt(); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1585 | Data.HasTrivialSpecialMembersForCall = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1586 | Data.DeclaredNonTrivialSpecialMembers = Record.readInt(); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1587 | Data.DeclaredNonTrivialSpecialMembersForCall = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1588 | Data.HasIrrelevantDestructor = Record.readInt(); |
| 1589 | Data.HasConstexprNonCopyMoveConstructor = Record.readInt(); |
| 1590 | Data.HasDefaultedDefaultConstructor = Record.readInt(); |
| 1591 | Data.DefaultedDefaultConstructorIsConstexpr = Record.readInt(); |
| 1592 | Data.HasConstexprDefaultConstructor = Record.readInt(); |
| 1593 | Data.HasNonLiteralTypeFieldsOrBases = Record.readInt(); |
| 1594 | Data.ComputedVisibleConversions = Record.readInt(); |
| 1595 | Data.UserProvidedDefaultConstructor = Record.readInt(); |
| 1596 | Data.DeclaredSpecialMembers = Record.readInt(); |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1597 | Data.ImplicitCopyConstructorCanHaveConstParamForVBase = Record.readInt(); |
| 1598 | Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1599 | Data.ImplicitCopyAssignmentHasConstParam = Record.readInt(); |
| 1600 | Data.HasDeclaredCopyConstructorWithConstParam = Record.readInt(); |
| 1601 | Data.HasDeclaredCopyAssignmentWithConstParam = Record.readInt(); |
Richard Trieu | b6adf54 | 2017-02-18 02:09:28 +0000 | [diff] [blame] | 1602 | Data.ODRHash = Record.readInt(); |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1603 | Data.HasODRHash = true; |
Anders Carlsson | 703d6e6 | 2011-01-22 18:11:02 +0000 | [diff] [blame] | 1604 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 1605 | if (Record.readInt()) |
| 1606 | Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1607 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1608 | Data.NumBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1609 | if (Data.NumBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1610 | Data.Bases = ReadGlobalOffset(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1611 | Data.NumVBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1612 | if (Data.NumVBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1613 | Data.VBases = ReadGlobalOffset(); |
| 1614 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1615 | Record.readUnresolvedSet(Data.Conversions); |
| 1616 | Record.readUnresolvedSet(Data.VisibleConversions); |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1617 | assert(Data.Definition && "Data.Definition should be already set!"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1618 | Data.FirstFriend = ReadDeclID(); |
Richard Smith | 9dd9f03 | 2013-08-30 00:23:29 +0000 | [diff] [blame] | 1619 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1620 | if (Data.IsLambda) { |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 1621 | typedef LambdaCapture Capture; |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1622 | CXXRecordDecl::LambdaDefinitionData &Lambda |
| 1623 | = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1624 | Lambda.Dependent = Record.readInt(); |
| 1625 | Lambda.IsGenericLambda = Record.readInt(); |
| 1626 | Lambda.CaptureDefault = Record.readInt(); |
| 1627 | Lambda.NumCaptures = Record.readInt(); |
| 1628 | Lambda.NumExplicitCaptures = Record.readInt(); |
| 1629 | Lambda.ManglingNumber = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1630 | Lambda.ContextDecl = ReadDeclID(); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1631 | Lambda.Captures = (Capture *)Reader.getContext().Allocate( |
| 1632 | sizeof(Capture) * Lambda.NumCaptures); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1633 | Capture *ToCapture = Lambda.Captures; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1634 | Lambda.MethodTyInfo = GetTypeSourceInfo(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1635 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1636 | SourceLocation Loc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1637 | bool IsImplicit = Record.readInt(); |
| 1638 | LambdaCaptureKind Kind = static_cast<LambdaCaptureKind>(Record.readInt()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1639 | switch (Kind) { |
Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 1640 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1641 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 1642 | case LCK_VLAType: |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1643 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 1646 | case LCK_ByRef: |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1647 | VarDecl *Var = ReadDeclAs<VarDecl>(); |
| 1648 | SourceLocation EllipsisLoc = ReadSourceLocation(); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1649 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); |
| 1650 | break; |
| 1651 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1652 | } |
| 1653 | } |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1656 | void ASTDeclReader::MergeDefinitionData( |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1657 | CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1658 | assert(D->DefinitionData && |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1659 | "merging class definition into non-definition"); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1660 | auto &DD = *D->DefinitionData; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1661 | |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1662 | if (DD.Definition != MergeDD.Definition) { |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1663 | // Track that we merged the definitions. |
| 1664 | Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, |
| 1665 | DD.Definition)); |
| 1666 | Reader.PendingDefinitions.erase(MergeDD.Definition); |
| 1667 | MergeDD.Definition->IsCompleteDefinition = false; |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 1668 | Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1669 | assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() && |
| 1670 | "already loaded pending lookups for merged definition"); |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1671 | } |
| 1672 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1673 | auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); |
| 1674 | if (PFDI != Reader.PendingFakeDefinitionData.end() && |
| 1675 | PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1676 | // We faked up this definition data because we found a class for which we'd |
| 1677 | // not yet loaded the definition. Replace it with the real thing now. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1678 | assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1679 | PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1680 | |
| 1681 | // Don't change which declaration is the definition; that is required |
| 1682 | // to be invariant once we select it. |
| 1683 | auto *Def = DD.Definition; |
| 1684 | DD = std::move(MergeDD); |
| 1685 | DD.Definition = Def; |
| 1686 | return; |
| 1687 | } |
| 1688 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1689 | // FIXME: Move this out into a .def file? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1690 | bool DetectedOdrViolation = false; |
| 1691 | #define OR_FIELD(Field) DD.Field |= MergeDD.Field; |
| 1692 | #define MATCH_FIELD(Field) \ |
| 1693 | DetectedOdrViolation |= DD.Field != MergeDD.Field; \ |
| 1694 | OR_FIELD(Field) |
| 1695 | MATCH_FIELD(UserDeclaredConstructor) |
| 1696 | MATCH_FIELD(UserDeclaredSpecialMembers) |
| 1697 | MATCH_FIELD(Aggregate) |
| 1698 | MATCH_FIELD(PlainOldData) |
| 1699 | MATCH_FIELD(Empty) |
| 1700 | MATCH_FIELD(Polymorphic) |
| 1701 | MATCH_FIELD(Abstract) |
| 1702 | MATCH_FIELD(IsStandardLayout) |
| 1703 | MATCH_FIELD(HasNoNonEmptyBases) |
| 1704 | MATCH_FIELD(HasPrivateFields) |
| 1705 | MATCH_FIELD(HasProtectedFields) |
| 1706 | MATCH_FIELD(HasPublicFields) |
| 1707 | MATCH_FIELD(HasMutableFields) |
| 1708 | MATCH_FIELD(HasVariantMembers) |
| 1709 | MATCH_FIELD(HasOnlyCMembers) |
| 1710 | MATCH_FIELD(HasInClassInitializer) |
| 1711 | MATCH_FIELD(HasUninitializedReferenceMember) |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1712 | MATCH_FIELD(HasUninitializedFields) |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1713 | MATCH_FIELD(HasInheritedConstructor) |
| 1714 | MATCH_FIELD(HasInheritedAssignment) |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1715 | MATCH_FIELD(NeedOverloadResolutionForCopyConstructor) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1716 | MATCH_FIELD(NeedOverloadResolutionForMoveConstructor) |
| 1717 | MATCH_FIELD(NeedOverloadResolutionForMoveAssignment) |
| 1718 | MATCH_FIELD(NeedOverloadResolutionForDestructor) |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1719 | MATCH_FIELD(DefaultedCopyConstructorIsDeleted) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1720 | MATCH_FIELD(DefaultedMoveConstructorIsDeleted) |
| 1721 | MATCH_FIELD(DefaultedMoveAssignmentIsDeleted) |
| 1722 | MATCH_FIELD(DefaultedDestructorIsDeleted) |
| 1723 | OR_FIELD(HasTrivialSpecialMembers) |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1724 | OR_FIELD(HasTrivialSpecialMembersForCall) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1725 | OR_FIELD(DeclaredNonTrivialSpecialMembers) |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1726 | OR_FIELD(DeclaredNonTrivialSpecialMembersForCall) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1727 | MATCH_FIELD(HasIrrelevantDestructor) |
| 1728 | OR_FIELD(HasConstexprNonCopyMoveConstructor) |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1729 | OR_FIELD(HasDefaultedDefaultConstructor) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1730 | MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr) |
| 1731 | OR_FIELD(HasConstexprDefaultConstructor) |
| 1732 | MATCH_FIELD(HasNonLiteralTypeFieldsOrBases) |
| 1733 | // ComputedVisibleConversions is handled below. |
| 1734 | MATCH_FIELD(UserProvidedDefaultConstructor) |
| 1735 | OR_FIELD(DeclaredSpecialMembers) |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1736 | MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForVBase) |
| 1737 | MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForNonVBase) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1738 | MATCH_FIELD(ImplicitCopyAssignmentHasConstParam) |
| 1739 | OR_FIELD(HasDeclaredCopyConstructorWithConstParam) |
| 1740 | OR_FIELD(HasDeclaredCopyAssignmentWithConstParam) |
| 1741 | MATCH_FIELD(IsLambda) |
| 1742 | #undef OR_FIELD |
| 1743 | #undef MATCH_FIELD |
| 1744 | |
| 1745 | if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) |
| 1746 | DetectedOdrViolation = true; |
| 1747 | // FIXME: Issue a diagnostic if the base classes don't match when we come |
| 1748 | // to lazily load them. |
| 1749 | |
| 1750 | // FIXME: Issue a diagnostic if the list of conversion functions doesn't |
| 1751 | // match when we come to lazily load them. |
| 1752 | if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { |
| 1753 | DD.VisibleConversions = std::move(MergeDD.VisibleConversions); |
| 1754 | DD.ComputedVisibleConversions = true; |
| 1755 | } |
| 1756 | |
| 1757 | // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to |
| 1758 | // lazily load it. |
| 1759 | |
| 1760 | if (DD.IsLambda) { |
| 1761 | // FIXME: ODR-checking for merging lambdas (this happens, for instance, |
| 1762 | // when they occur within the body of a function template specialization). |
| 1763 | } |
| 1764 | |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1765 | if (D->getODRHash() != MergeDD.ODRHash) { |
| 1766 | DetectedOdrViolation = true; |
| 1767 | } |
| 1768 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1769 | if (DetectedOdrViolation) |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 1770 | Reader.PendingOdrMergeFailures[DD.Definition].push_back( |
| 1771 | {MergeDD.Definition, &MergeDD}); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1774 | void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1775 | struct CXXRecordDecl::DefinitionData *DD; |
| 1776 | ASTContext &C = Reader.getContext(); |
| 1777 | |
| 1778 | // Determine whether this is a lambda closure type, so that we can |
| 1779 | // allocate the appropriate DefinitionData structure. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1780 | bool IsLambda = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1781 | if (IsLambda) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1782 | DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1783 | LCD_None); |
| 1784 | else |
| 1785 | DD = new (C) struct CXXRecordDecl::DefinitionData(D); |
| 1786 | |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1787 | ReadCXXDefinitionData(*DD, D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1788 | |
Richard Smith | 5156c38 | 2015-01-22 01:41:56 +0000 | [diff] [blame] | 1789 | // We might already have a definition for this record. This can happen either |
| 1790 | // because we're reading an update record, or because we've already done some |
| 1791 | // merging. Either way, just merge into it. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1792 | CXXRecordDecl *Canon = D->getCanonicalDecl(); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1793 | if (Canon->DefinitionData) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1794 | MergeDefinitionData(Canon, std::move(*DD)); |
| 1795 | D->DefinitionData = Canon->DefinitionData; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1796 | return; |
| 1797 | } |
| 1798 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1799 | // Mark this declaration as being a definition. |
| 1800 | D->IsCompleteDefinition = true; |
| 1801 | D->DefinitionData = DD; |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1802 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1803 | // If this is not the first declaration or is an update record, we can have |
| 1804 | // other redeclarations already. Make a note that we need to propagate the |
| 1805 | // DefinitionData pointer onto them. |
| 1806 | if (Update || Canon != D) { |
| 1807 | Canon->DefinitionData = D->DefinitionData; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1808 | Reader.PendingDefinitions.insert(D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1812 | ASTDeclReader::RedeclarableResult |
| 1813 | ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { |
| 1814 | RedeclarableResult Redecl = VisitRecordDeclImpl(D); |
Argyrios Kyrtzidis | a41f660 | 2010-10-20 00:11:15 +0000 | [diff] [blame] | 1815 | |
Douglas Gregor | 3a5ae56 | 2012-01-15 18:17:48 +0000 | [diff] [blame] | 1816 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 1817 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1818 | enum CXXRecKind { |
| 1819 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 1820 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1821 | switch ((CXXRecKind)Record.readInt()) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1822 | case CXXRecNotTemplate: |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame] | 1823 | // Merged when we merge the folding set entry in the primary template. |
| 1824 | if (!isa<ClassTemplateSpecializationDecl>(D)) |
| 1825 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1826 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1827 | case CXXRecTemplate: { |
| 1828 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1829 | ClassTemplateDecl *Template = ReadDeclAs<ClassTemplateDecl>(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1830 | D->TemplateOrInstantiation = Template; |
| 1831 | if (!Template->getTemplatedDecl()) { |
| 1832 | // We've not actually loaded the ClassTemplateDecl yet, because we're |
| 1833 | // currently being loaded as its pattern. Rely on it to set up our |
| 1834 | // TypeForDecl (see VisitClassTemplateDecl). |
| 1835 | // |
| 1836 | // Beware: we do not yet know our canonical declaration, and may still |
| 1837 | // get merged once the surrounding class template has got off the ground. |
| 1838 | TypeIDForTypeDecl = 0; |
| 1839 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1840 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1841 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1842 | case CXXRecMemberSpecialization: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1843 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1844 | TemplateSpecializationKind TSK = |
| 1845 | (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1846 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | caf8248 | 2010-09-13 11:45:25 +0000 | [diff] [blame] | 1847 | MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); |
| 1848 | MSI->setPointOfInstantiation(POI); |
| 1849 | D->TemplateOrInstantiation = MSI; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1850 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1851 | break; |
| 1852 | } |
| 1853 | } |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1854 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1855 | bool WasDefinition = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1856 | if (WasDefinition) |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1857 | ReadCXXRecordDefinition(D, /*Update*/false); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1858 | else |
| 1859 | // Propagate DefinitionData pointer from the canonical declaration. |
| 1860 | D->DefinitionData = D->getCanonicalDecl()->DefinitionData; |
| 1861 | |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1862 | // Lazily load the key function to avoid deserializing every method so we can |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1863 | // compute it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 1864 | if (WasDefinition) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1865 | DeclID KeyFn = ReadDeclID(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 1866 | if (KeyFn && D->IsCompleteDefinition) |
Richard Smith | a9a1c68 | 2014-07-07 06:38:20 +0000 | [diff] [blame] | 1867 | // FIXME: This is wrong for the ARM ABI, where some other module may have |
| 1868 | // made this function no longer be a key function. We need an update |
| 1869 | // record or similar for that case. |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1870 | C.KeyFunctions[D] = KeyFn; |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1871 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1872 | |
| 1873 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1876 | void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
| 1877 | VisitFunctionDecl(D); |
Faisal Vali | 1f3a2af | 2017-11-11 18:02:29 +0000 | [diff] [blame] | 1878 | D->IsCopyDeductionCandidate = Record.readInt(); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1881 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1882 | VisitFunctionDecl(D); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1883 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1884 | unsigned NumOverridenMethods = Record.readInt(); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1885 | if (D->isCanonicalDecl()) { |
| 1886 | while (NumOverridenMethods--) { |
| 1887 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| 1888 | // MD may be initializing. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1889 | if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>()) |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1890 | Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); |
| 1891 | } |
| 1892 | } else { |
| 1893 | // We don't care about which declarations this used to override; we get |
| 1894 | // the relevant information from the canonical declaration. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1895 | Record.skipInts(NumOverridenMethods); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1896 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1899 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1900 | // We need the inherited constructor information to merge the declaration, |
| 1901 | // so we have to read it before we call VisitCXXMethodDecl. |
| 1902 | if (D->isInheritingConstructor()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1903 | auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1904 | auto *Ctor = ReadDeclAs<CXXConstructorDecl>(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1905 | *D->getTrailingObjects<InheritedConstructor>() = |
| 1906 | InheritedConstructor(Shadow, Ctor); |
| 1907 | } |
| 1908 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1909 | VisitCXXMethodDecl(D); |
| 1910 | } |
| 1911 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1912 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1913 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 1914 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1915 | if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) { |
George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 1916 | CXXDestructorDecl *Canon = D->getCanonicalDecl(); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1917 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1918 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1919 | if (!Canon->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1920 | Canon->OperatorDelete = OperatorDelete; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1921 | Canon->OperatorDeleteThisArg = ThisArg; |
| 1922 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1923 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1926 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1927 | VisitCXXMethodDecl(D); |
| 1928 | } |
| 1929 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1930 | void ASTDeclReader::VisitImportDecl(ImportDecl *D) { |
| 1931 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1932 | D->ImportedAndComplete.setPointer(readModule()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1933 | D->ImportedAndComplete.setInt(Record.readInt()); |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 1934 | SourceLocation *StoredLocs = D->getTrailingObjects<SourceLocation>(); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1935 | for (unsigned I = 0, N = Record.back(); I != N; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1936 | StoredLocs[I] = ReadSourceLocation(); |
David L. Jones | 267b884 | 2017-01-24 01:04:30 +0000 | [diff] [blame] | 1937 | Record.skipInts(1); // The number of stored source locations. |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1940 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1941 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1942 | D->setColonLoc(ReadSourceLocation()); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1945 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | a95d019 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 1946 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1947 | if (Record.readInt()) // hasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1948 | D->Friend = ReadDeclAs<NamedDecl>(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 1949 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1950 | D->Friend = GetTypeSourceInfo(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 1951 | for (unsigned i = 0; i != D->NumTPLists; ++i) |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 1952 | D->getTrailingObjects<TemplateParameterList *>()[i] = |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1953 | Record.readTemplateParameterList(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1954 | D->NextFriend = ReadDeclID(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1955 | D->UnsupportedFriend = (Record.readInt() != 0); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1956 | D->FriendLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1959 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1960 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1961 | unsigned NumParams = Record.readInt(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1962 | D->NumParams = NumParams; |
| 1963 | D->Params = new TemplateParameterList*[NumParams]; |
| 1964 | for (unsigned i = 0; i != NumParams; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1965 | D->Params[i] = Record.readTemplateParameterList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1966 | if (Record.readInt()) // HasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1967 | D->Friend = ReadDeclAs<NamedDecl>(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1968 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1969 | D->Friend = GetTypeSourceInfo(); |
| 1970 | D->FriendLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1973 | DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1974 | VisitNamedDecl(D); |
| 1975 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1976 | DeclID PatternID = ReadDeclID(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1977 | NamedDecl *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID)); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1978 | TemplateParameterList *TemplateParams = Record.readTemplateParameterList(); |
Hubert Tong | 5a8ec4e | 2017-02-10 02:46:19 +0000 | [diff] [blame] | 1979 | // FIXME handle associated constraints |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1980 | D->init(TemplatedDecl, TemplateParams); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 1981 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1982 | return PatternID; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1985 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 1986 | ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 1987 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1988 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 1989 | // Make sure we've allocated the Common pointer first. We do this before |
| 1990 | // VisitTemplateDecl so that getCommonPtr() can be used during initialization. |
| 1991 | RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); |
| 1992 | if (!CanonD->Common) { |
| 1993 | CanonD->Common = CanonD->newCommon(Reader.getContext()); |
| 1994 | Reader.PendingDefinitions.insert(CanonD); |
| 1995 | } |
| 1996 | D->Common = CanonD->Common; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 1997 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 1998 | // If this is the first declaration of the template, fill in the information |
| 1999 | // for the 'common' pointer. |
| 2000 | if (ThisDeclID == Redecl.getFirstID()) { |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2001 | if (RedeclarableTemplateDecl *RTD |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2002 | = ReadDeclAs<RedeclarableTemplateDecl>()) { |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2003 | assert(RTD->getKind() == D->getKind() && |
| 2004 | "InstantiatedFromMemberTemplate kind mismatch"); |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2005 | D->setInstantiatedFromMemberTemplate(RTD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2006 | if (Record.readInt()) |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2007 | D->setMemberSpecialization(); |
| 2008 | } |
| 2009 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2010 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2011 | DeclID PatternID = VisitTemplateDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2012 | D->IdentifierNamespace = Record.readInt(); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2013 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2014 | mergeRedeclarable(D, Redecl, PatternID); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2015 | |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 2016 | // If we merged the template with a prior declaration chain, merge the common |
| 2017 | // pointer. |
| 2018 | // FIXME: Actually merge here, don't just overwrite. |
| 2019 | D->Common = D->getCanonicalDecl()->Common; |
| 2020 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2021 | return Redecl; |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2024 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2025 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2027 | if (ThisDeclID == Redecl.getFirstID()) { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 2028 | // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of |
| 2029 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2030 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2031 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2032 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2033 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2034 | |
| 2035 | if (D->getTemplatedDecl()->TemplateOrInstantiation) { |
| 2036 | // We were loaded before our templated declaration was. We've not set up |
| 2037 | // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct |
| 2038 | // it now. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2039 | Reader.getContext().getInjectedClassNameType( |
Richard Smith | a1406fa | 2014-05-23 21:31:59 +0000 | [diff] [blame] | 2040 | D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2041 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 2044 | void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 2045 | llvm_unreachable("BuiltinTemplates are not serialized"); |
| 2046 | } |
| 2047 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2048 | /// TODO: Unify with ClassTemplateDecl version? |
| 2049 | /// May require unifying ClassTemplateDecl and |
| 2050 | /// VarTemplateDecl beyond TemplateDecl... |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2051 | void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 2052 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| 2053 | |
| 2054 | if (ThisDeclID == Redecl.getFirstID()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 2055 | // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2056 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2057 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2058 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2059 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2060 | } |
| 2061 | } |
| 2062 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2063 | ASTDeclReader::RedeclarableResult |
| 2064 | ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( |
| 2065 | ClassTemplateSpecializationDecl *D) { |
| 2066 | RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2067 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2068 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2069 | if (Decl *InstD = ReadDecl()) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2070 | if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2071 | D->SpecializedTemplate = CTD; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2072 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2073 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2074 | Record.readTemplateArgumentList(TemplArgs); |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2075 | TemplateArgumentList *ArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2076 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2077 | ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS |
| 2078 | = new (C) ClassTemplateSpecializationDecl:: |
| 2079 | SpecializedPartialSpecialization(); |
| 2080 | PS->PartialSpecialization |
| 2081 | = cast<ClassTemplatePartialSpecializationDecl>(InstD); |
| 2082 | PS->TemplateArgs = ArgList; |
| 2083 | D->SpecializedTemplate = PS; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2087 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2088 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2089 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2090 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2091 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2092 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2093 | bool writtenAsCanonicalDecl = Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2094 | if (writtenAsCanonicalDecl) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2095 | ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2096 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2097 | // Set this as, or find, the canonical declaration for this specialization |
| 2098 | ClassTemplateSpecializationDecl *CanonSpec; |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 2099 | if (ClassTemplatePartialSpecializationDecl *Partial = |
| 2100 | dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2101 | CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 2102 | .GetOrInsertNode(Partial); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2103 | } else { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2104 | CanonSpec = |
| 2105 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2106 | } |
| 2107 | // If there was already a canonical specialization, merge into it. |
| 2108 | if (CanonSpec != D) { |
| 2109 | mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); |
| 2110 | |
| 2111 | // This declaration might be a definition. Merge with any existing |
| 2112 | // definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2113 | if (auto *DDD = D->DefinitionData) { |
| 2114 | if (CanonSpec->DefinitionData) |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2115 | MergeDefinitionData(CanonSpec, std::move(*DDD)); |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2116 | else |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2117 | CanonSpec->DefinitionData = D->DefinitionData; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2118 | } |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2119 | D->DefinitionData = CanonSpec->DefinitionData; |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2120 | } |
Argyrios Kyrtzidis | 8704057 | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 2121 | } |
| 2122 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2123 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2124 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2125 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2126 | ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo |
| 2127 | = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; |
| 2128 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2129 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2130 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2131 | D->ExplicitInfo = ExplicitInfo; |
| 2132 | } |
| 2133 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2134 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2137 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2138 | ClassTemplatePartialSpecializationDecl *D) { |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2139 | RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2140 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2141 | D->TemplateParams = Record.readTemplateParameterList(); |
| 2142 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2143 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2144 | // These are read/set from/to the first declaration. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2145 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2146 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2147 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2148 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2149 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 2152 | void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( |
| 2153 | ClassScopeFunctionSpecializationDecl *D) { |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2154 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2155 | D->Specialization = ReadDeclAs<CXXMethodDecl>(); |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2158 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2159 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2160 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2161 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2162 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2163 | SmallVector<serialization::DeclID, 32> SpecIDs; |
| 2164 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2165 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2166 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2169 | /// TODO: Unify with ClassTemplateSpecializationDecl version? |
| 2170 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2171 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2172 | /// structure Template(Partial)SpecializationDecl, and |
| 2173 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2174 | ASTDeclReader::RedeclarableResult |
| 2175 | ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( |
| 2176 | VarTemplateSpecializationDecl *D) { |
| 2177 | RedeclarableResult Redecl = VisitVarDeclImpl(D); |
| 2178 | |
| 2179 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2180 | if (Decl *InstD = ReadDecl()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2181 | if (VarTemplateDecl *VTD = dyn_cast<VarTemplateDecl>(InstD)) { |
| 2182 | D->SpecializedTemplate = VTD; |
| 2183 | } else { |
| 2184 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2185 | Record.readTemplateArgumentList(TemplArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2186 | TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2187 | C, TemplArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2188 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization *PS = |
| 2189 | new (C) |
| 2190 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); |
| 2191 | PS->PartialSpecialization = |
| 2192 | cast<VarTemplatePartialSpecializationDecl>(InstD); |
| 2193 | PS->TemplateArgs = ArgList; |
| 2194 | D->SpecializedTemplate = PS; |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2199 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2200 | VarTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo = |
| 2201 | new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; |
| 2202 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2203 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2204 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2205 | D->ExplicitInfo = ExplicitInfo; |
| 2206 | } |
| 2207 | |
| 2208 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2209 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2210 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2211 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2212 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Richard Smith | 435e647 | 2017-12-02 02:48:42 +0000 | [diff] [blame] | 2213 | D->IsCompleteDefinition = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2214 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2215 | bool writtenAsCanonicalDecl = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2216 | if (writtenAsCanonicalDecl) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2217 | VarTemplateDecl *CanonPattern = ReadDeclAs<VarTemplateDecl>(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2218 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 2219 | // FIXME: If it's already present, merge it. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2220 | if (VarTemplatePartialSpecializationDecl *Partial = |
| 2221 | dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2222 | CanonPattern->getCommonPtr()->PartialSpecializations |
| 2223 | .GetOrInsertNode(Partial); |
| 2224 | } else { |
| 2225 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2226 | } |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | return Redecl; |
| 2231 | } |
| 2232 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2233 | /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? |
| 2234 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2235 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2236 | /// structure Template(Partial)SpecializationDecl, and |
| 2237 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2238 | void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( |
| 2239 | VarTemplatePartialSpecializationDecl *D) { |
| 2240 | RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); |
| 2241 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2242 | D->TemplateParams = Record.readTemplateParameterList(); |
| 2243 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2244 | |
| 2245 | // These are read/set from/to the first declaration. |
| 2246 | if (ThisDeclID == Redecl.getFirstID()) { |
| 2247 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2248 | ReadDeclAs<VarTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2249 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2253 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2254 | VisitTypeDecl(D); |
| 2255 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2256 | D->setDeclaredWithTypename(Record.readInt()); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2257 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2258 | if (Record.readInt()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2259 | D->setDefaultArgument(GetTypeSourceInfo()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2262 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 2263 | VisitDeclaratorDecl(D); |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 2264 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2265 | D->setDepth(Record.readInt()); |
| 2266 | D->setPosition(Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2267 | if (D->isExpandedParameterPack()) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 2268 | auto TypesAndInfos = |
| 2269 | D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2270 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2271 | new (&TypesAndInfos[I].first) QualType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2272 | TypesAndInfos[I].second = GetTypeSourceInfo(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2273 | } |
| 2274 | } else { |
| 2275 | // Rest of NonTypeTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2276 | D->ParameterPack = Record.readInt(); |
| 2277 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2278 | D->setDefaultArgument(Record.readExpr()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2279 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2280 | } |
| 2281 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2282 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | 9f2d24a | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 2283 | VisitTemplateDecl(D); |
| 2284 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2285 | D->setDepth(Record.readInt()); |
| 2286 | D->setPosition(Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2287 | if (D->isExpandedParameterPack()) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 2288 | TemplateParameterList **Data = |
| 2289 | D->getTrailingObjects<TemplateParameterList *>(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2290 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
| 2291 | I != N; ++I) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2292 | Data[I] = Record.readTemplateParameterList(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2293 | } else { |
| 2294 | // Rest of TemplateTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2295 | D->ParameterPack = Record.readInt(); |
| 2296 | if (Record.readInt()) |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 2297 | D->setDefaultArgument(Reader.getContext(), |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2298 | Record.readTemplateArgumentLoc()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2299 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 2302 | void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 2303 | VisitRedeclarableTemplateDecl(D); |
| 2304 | } |
| 2305 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2306 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 2d8891c | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 2307 | VisitDecl(D); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2308 | D->AssertExprAndFailed.setPointer(Record.readExpr()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2309 | D->AssertExprAndFailed.setInt(Record.readInt()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2310 | D->Message = cast_or_null<StringLiteral>(Record.readExpr()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2311 | D->RParenLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2312 | } |
| 2313 | |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 2314 | void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { |
| 2315 | VisitDecl(D); |
| 2316 | } |
| 2317 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2318 | std::pair<uint64_t, uint64_t> |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2319 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2320 | uint64_t LexicalOffset = ReadLocalOffset(); |
| 2321 | uint64_t VisibleOffset = ReadLocalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2322 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 2323 | } |
| 2324 | |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2325 | template <typename T> |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2326 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2327 | ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2328 | DeclID FirstDeclID = ReadDeclID(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2329 | Decl *MergeWith = nullptr; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2330 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2331 | bool IsKeyDecl = ThisDeclID == FirstDeclID; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2332 | bool IsFirstLocalDecl = false; |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2333 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2334 | uint64_t RedeclOffset = 0; |
| 2335 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2336 | // 0 indicates that this declaration was the only declaration of its entity, |
| 2337 | // and is used for space optimization. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2338 | if (FirstDeclID == 0) { |
Douglas Gregor | 074a409 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 2339 | FirstDeclID = ThisDeclID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2340 | IsKeyDecl = true; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2341 | IsFirstLocalDecl = true; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2342 | } else if (unsigned N = Record.readInt()) { |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2343 | // This declaration was the first local declaration, but may have imported |
| 2344 | // other declarations. |
| 2345 | IsKeyDecl = N == 1; |
| 2346 | IsFirstLocalDecl = true; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2347 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 2348 | // We have some declarations that must be before us in our redeclaration |
| 2349 | // chain. Read them now, and remember that we ought to merge with one of |
| 2350 | // them. |
| 2351 | // FIXME: Provide a known merge target to the second and subsequent such |
| 2352 | // declaration. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2353 | for (unsigned I = 0; I != N - 1; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2354 | MergeWith = ReadDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2355 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2356 | RedeclOffset = ReadLocalOffset(); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2357 | } else { |
| 2358 | // This declaration was not the first local declaration. Read the first |
| 2359 | // local declaration now, to trigger the import of other redeclarations. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2360 | (void)ReadDecl(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2363 | T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); |
| 2364 | if (FirstDecl != D) { |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 2365 | // We delay loading of the redeclaration chain to avoid deeply nested calls. |
| 2366 | // We temporarily set the first (canonical) declaration as the previous one |
| 2367 | // which is the one that matters and mark the real previous DeclID to be |
| 2368 | // loaded & attached later on. |
David Blaikie | 7e64fd9 | 2012-05-28 19:38:42 +0000 | [diff] [blame] | 2369 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2370 | D->First = FirstDecl->getCanonicalDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2371 | } |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2372 | |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2373 | T *DAsT = static_cast<T*>(D); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2374 | |
| 2375 | // Note that we need to load local redeclarations of this decl and build a |
| 2376 | // decl chain for them. This must happen *after* we perform the preloading |
| 2377 | // above; this ensures that the redeclaration chain is built in the correct |
| 2378 | // order. |
| 2379 | if (IsFirstLocalDecl) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2380 | Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset)); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2381 | |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2382 | return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2385 | /// \brief Attempts to merge the given declaration (D) with another declaration |
| 2386 | /// of the same entity. |
| 2387 | template<typename T> |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2388 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2389 | RedeclarableResult &Redecl, |
| 2390 | DeclID TemplatePatternID) { |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2391 | // If modules are not available, there is no reason to perform this merge. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2392 | if (!Reader.getContext().getLangOpts().Modules) |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2393 | return; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2394 | |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2395 | // If we're not the canonical declaration, we don't need to merge. |
| 2396 | if (!DBase->isFirstDecl()) |
| 2397 | return; |
| 2398 | |
Vassil Vassilev | 916d8be | 2016-10-06 13:18:06 +0000 | [diff] [blame] | 2399 | T *D = static_cast<T*>(DBase); |
| 2400 | |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2401 | if (auto *Existing = Redecl.getKnownMergeTarget()) |
| 2402 | // We already know of an existing declaration we should merge with. |
| 2403 | mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID); |
| 2404 | else if (FindExistingResult ExistingRes = findExisting(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2405 | if (T *Existing = ExistingRes) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2406 | mergeRedeclarable(D, Existing, Redecl, TemplatePatternID); |
| 2407 | } |
| 2408 | |
| 2409 | /// \brief "Cast" to type T, asserting if we don't have an implicit conversion. |
| 2410 | /// We use this to put code in a template that will only be valid for certain |
| 2411 | /// instantiations. |
| 2412 | template<typename T> static T assert_cast(T t) { return t; } |
| 2413 | template<typename T> static T assert_cast(...) { |
| 2414 | llvm_unreachable("bad assert_cast"); |
| 2415 | } |
| 2416 | |
| 2417 | /// \brief Merge together the pattern declarations from two template |
| 2418 | /// declarations. |
| 2419 | void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 2420 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2421 | DeclID DsID, bool IsKeyDecl) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2422 | auto *DPattern = D->getTemplatedDecl(); |
| 2423 | auto *ExistingPattern = Existing->getTemplatedDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2424 | RedeclarableResult Result(/*MergeWith*/ ExistingPattern, |
| 2425 | DPattern->getCanonicalDecl()->getGlobalID(), |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2426 | IsKeyDecl); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2427 | |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2428 | if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { |
| 2429 | // Merge with any existing definition. |
| 2430 | // FIXME: This is duplicated in several places. Refactor. |
| 2431 | auto *ExistingClass = |
| 2432 | cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl(); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2433 | if (auto *DDD = DClass->DefinitionData) { |
| 2434 | if (ExistingClass->DefinitionData) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2435 | MergeDefinitionData(ExistingClass, std::move(*DDD)); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2436 | } else { |
| 2437 | ExistingClass->DefinitionData = DClass->DefinitionData; |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2438 | // We may have skipped this before because we thought that DClass |
| 2439 | // was the canonical declaration. |
Richard Smith | 7474dd92 | 2015-03-11 18:21:02 +0000 | [diff] [blame] | 2440 | Reader.PendingDefinitions.insert(DClass); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2441 | } |
| 2442 | } |
| 2443 | DClass->DefinitionData = ExistingClass->DefinitionData; |
| 2444 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2445 | return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern), |
| 2446 | Result); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2447 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2448 | if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern)) |
| 2449 | return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern), |
| 2450 | Result); |
| 2451 | if (auto *DVar = dyn_cast<VarDecl>(DPattern)) |
| 2452 | return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result); |
Richard Smith | f59b735 | 2014-07-28 21:16:37 +0000 | [diff] [blame] | 2453 | if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern)) |
| 2454 | return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern), |
| 2455 | Result); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2456 | llvm_unreachable("merged an unknown kind of redeclarable template"); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | /// \brief Attempts to merge the given declaration (D) with another declaration |
| 2460 | /// of the same entity. |
| 2461 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2462 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing, |
| 2463 | RedeclarableResult &Redecl, |
| 2464 | DeclID TemplatePatternID) { |
| 2465 | T *D = static_cast<T*>(DBase); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2466 | T *ExistingCanon = Existing->getCanonicalDecl(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2467 | T *DCanon = D->getCanonicalDecl(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2468 | if (ExistingCanon != DCanon) { |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2469 | assert(DCanon->getGlobalID() == Redecl.getFirstID() && |
| 2470 | "already merged this declaration"); |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2471 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2472 | // Have our redeclaration link point back at the canonical declaration |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2473 | // of the existing declaration, so that this declaration has the |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2474 | // appropriate canonical declaration. |
| 2475 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2476 | D->First = ExistingCanon; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 2477 | ExistingCanon->Used |= D->Used; |
| 2478 | D->Used = false; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2479 | |
| 2480 | // When we merge a namespace, update its pointer to the first namespace. |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 2481 | // We cannot have loaded any redeclarations of this declaration yet, so |
| 2482 | // there's nothing else that needs to be updated. |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2483 | if (auto *Namespace = dyn_cast<NamespaceDecl>(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2484 | Namespace->AnonOrFirstNamespaceAndInline.setPointer( |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2485 | assert_cast<NamespaceDecl*>(ExistingCanon)); |
| 2486 | |
| 2487 | // When we merge a template, merge its pattern. |
| 2488 | if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D)) |
| 2489 | mergeTemplatePattern( |
| 2490 | DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon), |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2491 | TemplatePatternID, Redecl.isKeyDecl()); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2492 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2493 | // If this declaration is a key declaration, make a note of that. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2494 | if (Redecl.isKeyDecl()) |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2495 | Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2496 | } |
| 2497 | } |
| 2498 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2499 | /// \brief Attempts to merge the given declaration (D) with another declaration |
| 2500 | /// of the same entity, for the case where the entity is not actually |
| 2501 | /// redeclarable. This happens, for instance, when merging the fields of |
| 2502 | /// identical class definitions from two different modules. |
| 2503 | template<typename T> |
| 2504 | void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { |
| 2505 | // If modules are not available, there is no reason to perform this merge. |
| 2506 | if (!Reader.getContext().getLangOpts().Modules) |
| 2507 | return; |
| 2508 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2509 | // ODR-based merging is only performed in C++. In C, identically-named things |
| 2510 | // in different translation units are not redeclarations (but may still have |
| 2511 | // compatible types). |
| 2512 | if (!Reader.getContext().getLangOpts().CPlusPlus) |
| 2513 | return; |
| 2514 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2515 | if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) |
| 2516 | if (T *Existing = ExistingRes) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2517 | Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D), |
| 2518 | Existing->getCanonicalDecl()); |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2521 | void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 2522 | VisitDecl(D); |
| 2523 | unsigned NumVars = D->varlist_size(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2524 | SmallVector<Expr *, 16> Vars; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2525 | Vars.reserve(NumVars); |
| 2526 | for (unsigned i = 0; i != NumVars; ++i) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2527 | Vars.push_back(Record.readExpr()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2528 | } |
| 2529 | D->setVars(Vars); |
| 2530 | } |
| 2531 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2532 | void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2533 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2534 | D->setLocation(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2535 | D->setCombiner(Record.readExpr()); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 2536 | D->setInitializer( |
| 2537 | Record.readExpr(), |
| 2538 | static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2539 | D->PrevDeclInScope = ReadDeclID(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2542 | void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2543 | VisitVarDecl(D); |
| 2544 | } |
| 2545 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2546 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2547 | // Attribute Reading |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2548 | //===----------------------------------------------------------------------===// |
| 2549 | |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2550 | /// \brief Reads attributes from the current stream position. |
David L. Jones | 267b884 | 2017-01-24 01:04:30 +0000 | [diff] [blame] | 2551 | void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { |
| 2552 | for (unsigned i = 0, e = Record.readInt(); i != e; ++i) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2553 | Attr *New = nullptr; |
David L. Jones | 267b884 | 2017-01-24 01:04:30 +0000 | [diff] [blame] | 2554 | attr::Kind Kind = (attr::Kind)Record.readInt(); |
| 2555 | SourceRange Range = Record.readSourceRange(); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2556 | ASTContext &Context = getContext(); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2557 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2558 | #include "clang/Serialization/AttrPCHRead.inc" |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2559 | |
| 2560 | assert(New && "Unable to decode attribute?"); |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2561 | Attrs.push_back(New); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2562 | } |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2566 | // ASTReader Implementation |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2567 | //===----------------------------------------------------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2568 | |
| 2569 | /// \brief Note that we have loaded the declaration with the given |
| 2570 | /// Index. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2571 | /// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2572 | /// This routine notes that this declaration has already been loaded, |
| 2573 | /// so that future GetDecl calls will return this declaration rather |
| 2574 | /// than trying to load a new declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2575 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2576 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 2577 | DeclsLoaded[Index] = D; |
| 2578 | } |
| 2579 | |
| 2580 | |
| 2581 | /// \brief Determine whether the consumer will be interested in seeing |
| 2582 | /// this declaration (via HandleTopLevelDecl). |
| 2583 | /// |
| 2584 | /// This routine should return true for anything that might affect |
| 2585 | /// code generation, e.g., inline function definitions, Objective-C |
| 2586 | /// declarations with metadata, etc. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2587 | static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { |
Argyrios Kyrtzidis | a98e861 | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 2588 | // An ObjCMethodDecl is never considered as "interesting" because its |
| 2589 | // implementation container always is. |
| 2590 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 2591 | // An ImportDecl or VarDecl imported from a module map module will get |
| 2592 | // emitted when we import the relevant module. |
| 2593 | if (isa<ImportDecl>(D) || isa<VarDecl>(D)) { |
| 2594 | auto *M = D->getImportedOwningModule(); |
| 2595 | if (M && M->Kind == Module::ModuleMapModule && |
| 2596 | Ctx.DeclMustBeEmitted(D)) |
| 2597 | return false; |
| 2598 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2599 | |
Douglas Gregor | 87d8124 | 2011-09-10 00:22:34 +0000 | [diff] [blame] | 2600 | if (isa<FileScopeAsmDecl>(D) || |
| 2601 | isa<ObjCProtocolDecl>(D) || |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2602 | isa<ObjCImplDecl>(D) || |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2603 | isa<ImportDecl>(D) || |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 2604 | isa<PragmaCommentDecl>(D) || |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2605 | isa<PragmaDetectMismatchDecl>(D)) |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 2606 | return true; |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2607 | if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D)) |
| 2608 | return !D->getDeclContext()->isFunctionOrMethod(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2609 | if (VarDecl *Var = dyn_cast<VarDecl>(D)) |
Argyrios Kyrtzidis | 4ba81b2 | 2010-08-05 09:47:59 +0000 | [diff] [blame] | 2610 | return Var->isFileVarDecl() && |
| 2611 | Var->isThisDeclarationADefinition() == VarDecl::Definition; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2612 | if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2613 | return Func->doesThisDeclarationHaveABody() || HasBody; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 2614 | |
| 2615 | if (auto *ES = D->getASTContext().getExternalSource()) |
| 2616 | if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) |
| 2617 | return true; |
| 2618 | |
Douglas Gregor | 87d8124 | 2011-09-10 00:22:34 +0000 | [diff] [blame] | 2619 | return false; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2620 | } |
| 2621 | |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2622 | /// \brief Get the correct cursor and offset for loading a declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2623 | ASTReader::RecordLocation |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2624 | ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2625 | GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); |
| 2626 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2627 | ModuleFile *M = I->second; |
Richard Smith | 34da751 | 2016-03-27 05:52:25 +0000 | [diff] [blame] | 2628 | const DeclOffset &DOffs = |
| 2629 | M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2630 | Loc = TranslateSourceLocation(*M, DOffs.getLocation()); |
Argyrios Kyrtzidis | 81ddd18 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 2631 | return RecordLocation(M, DOffs.BitOffset); |
Sebastian Redl | 3462779 | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2634 | ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2635 | ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2636 | = GlobalBitOffsetsMap.find(GlobalOffset); |
| 2637 | |
| 2638 | assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); |
| 2639 | return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); |
| 2640 | } |
| 2641 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2642 | uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2643 | return LocalOffset + M.GlobalBitOffset; |
| 2644 | } |
| 2645 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2646 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2647 | const TemplateParameterList *Y); |
| 2648 | |
| 2649 | /// \brief Determine whether two template parameters are similar enough |
| 2650 | /// that they may be used in declarations of the same template. |
| 2651 | static bool isSameTemplateParameter(const NamedDecl *X, |
| 2652 | const NamedDecl *Y) { |
| 2653 | if (X->getKind() != Y->getKind()) |
| 2654 | return false; |
| 2655 | |
| 2656 | if (const TemplateTypeParmDecl *TX = dyn_cast<TemplateTypeParmDecl>(X)) { |
| 2657 | const TemplateTypeParmDecl *TY = cast<TemplateTypeParmDecl>(Y); |
| 2658 | return TX->isParameterPack() == TY->isParameterPack(); |
| 2659 | } |
| 2660 | |
| 2661 | if (const NonTypeTemplateParmDecl *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) { |
| 2662 | const NonTypeTemplateParmDecl *TY = cast<NonTypeTemplateParmDecl>(Y); |
| 2663 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2664 | TX->getASTContext().hasSameType(TX->getType(), TY->getType()); |
| 2665 | } |
| 2666 | |
| 2667 | const TemplateTemplateParmDecl *TX = cast<TemplateTemplateParmDecl>(X); |
| 2668 | const TemplateTemplateParmDecl *TY = cast<TemplateTemplateParmDecl>(Y); |
| 2669 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2670 | isSameTemplateParameterList(TX->getTemplateParameters(), |
| 2671 | TY->getTemplateParameters()); |
| 2672 | } |
| 2673 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 2674 | static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) { |
| 2675 | if (auto *NS = X->getAsNamespace()) |
| 2676 | return NS; |
| 2677 | if (auto *NAS = X->getAsNamespaceAlias()) |
| 2678 | return NAS->getNamespace(); |
| 2679 | return nullptr; |
| 2680 | } |
| 2681 | |
| 2682 | static bool isSameQualifier(const NestedNameSpecifier *X, |
| 2683 | const NestedNameSpecifier *Y) { |
| 2684 | if (auto *NSX = getNamespace(X)) { |
| 2685 | auto *NSY = getNamespace(Y); |
| 2686 | if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl()) |
| 2687 | return false; |
| 2688 | } else if (X->getKind() != Y->getKind()) |
| 2689 | return false; |
| 2690 | |
| 2691 | // FIXME: For namespaces and types, we're permitted to check that the entity |
| 2692 | // is named via the same tokens. We should probably do so. |
| 2693 | switch (X->getKind()) { |
| 2694 | case NestedNameSpecifier::Identifier: |
| 2695 | if (X->getAsIdentifier() != Y->getAsIdentifier()) |
| 2696 | return false; |
| 2697 | break; |
| 2698 | case NestedNameSpecifier::Namespace: |
| 2699 | case NestedNameSpecifier::NamespaceAlias: |
| 2700 | // We've already checked that we named the same namespace. |
| 2701 | break; |
| 2702 | case NestedNameSpecifier::TypeSpec: |
| 2703 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2704 | if (X->getAsType()->getCanonicalTypeInternal() != |
| 2705 | Y->getAsType()->getCanonicalTypeInternal()) |
| 2706 | return false; |
| 2707 | break; |
| 2708 | case NestedNameSpecifier::Global: |
| 2709 | case NestedNameSpecifier::Super: |
| 2710 | return true; |
| 2711 | } |
| 2712 | |
| 2713 | // Recurse into earlier portion of NNS, if any. |
| 2714 | auto *PX = X->getPrefix(); |
| 2715 | auto *PY = Y->getPrefix(); |
| 2716 | if (PX && PY) |
| 2717 | return isSameQualifier(PX, PY); |
| 2718 | return !PX && !PY; |
| 2719 | } |
| 2720 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2721 | /// \brief Determine whether two template parameter lists are similar enough |
| 2722 | /// that they may be used in declarations of the same template. |
| 2723 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2724 | const TemplateParameterList *Y) { |
| 2725 | if (X->size() != Y->size()) |
| 2726 | return false; |
| 2727 | |
| 2728 | for (unsigned I = 0, N = X->size(); I != N; ++I) |
| 2729 | if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I))) |
| 2730 | return false; |
| 2731 | |
| 2732 | return true; |
| 2733 | } |
| 2734 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2735 | /// Determine whether the attributes we can overload on are identical for A and |
George Burgess IV | b776021 | 2017-02-24 02:49:47 +0000 | [diff] [blame] | 2736 | /// B. Will ignore any overloadable attrs represented in the type of A and B. |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2737 | static bool hasSameOverloadableAttrs(const FunctionDecl *A, |
| 2738 | const FunctionDecl *B) { |
George Burgess IV | b776021 | 2017-02-24 02:49:47 +0000 | [diff] [blame] | 2739 | // Note that pass_object_size attributes are represented in the function's |
| 2740 | // ExtParameterInfo, so we don't need to check them here. |
| 2741 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2742 | SmallVector<const EnableIfAttr *, 4> AEnableIfs; |
| 2743 | // Since this is an equality check, we can ignore that enable_if attrs show up |
| 2744 | // in reverse order. |
| 2745 | for (const auto *EIA : A->specific_attrs<EnableIfAttr>()) |
| 2746 | AEnableIfs.push_back(EIA); |
| 2747 | |
| 2748 | SmallVector<const EnableIfAttr *, 4> BEnableIfs; |
| 2749 | for (const auto *EIA : B->specific_attrs<EnableIfAttr>()) |
| 2750 | BEnableIfs.push_back(EIA); |
| 2751 | |
| 2752 | // Two very common cases: either we have 0 enable_if attrs, or we have an |
| 2753 | // unequal number of enable_if attrs. |
| 2754 | if (AEnableIfs.empty() && BEnableIfs.empty()) |
| 2755 | return true; |
| 2756 | |
| 2757 | if (AEnableIfs.size() != BEnableIfs.size()) |
| 2758 | return false; |
| 2759 | |
| 2760 | llvm::FoldingSetNodeID Cand1ID, Cand2ID; |
| 2761 | for (unsigned I = 0, E = AEnableIfs.size(); I != E; ++I) { |
| 2762 | Cand1ID.clear(); |
| 2763 | Cand2ID.clear(); |
| 2764 | |
| 2765 | AEnableIfs[I]->getCond()->Profile(Cand1ID, A->getASTContext(), true); |
| 2766 | BEnableIfs[I]->getCond()->Profile(Cand2ID, B->getASTContext(), true); |
| 2767 | if (Cand1ID != Cand2ID) |
| 2768 | return false; |
| 2769 | } |
| 2770 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2771 | return true; |
| 2772 | } |
| 2773 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2774 | /// \brief Determine whether the two declarations refer to the same entity. |
| 2775 | static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { |
| 2776 | assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!"); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2777 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2778 | if (X == Y) |
| 2779 | return true; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2780 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2781 | // Must be in the same context. |
| 2782 | if (!X->getDeclContext()->getRedeclContext()->Equals( |
| 2783 | Y->getDeclContext()->getRedeclContext())) |
| 2784 | return false; |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2785 | |
| 2786 | // Two typedefs refer to the same entity if they have the same underlying |
| 2787 | // type. |
| 2788 | if (TypedefNameDecl *TypedefX = dyn_cast<TypedefNameDecl>(X)) |
| 2789 | if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y)) |
| 2790 | return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), |
| 2791 | TypedefY->getUnderlyingType()); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2792 | |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2793 | // Must have the same kind. |
| 2794 | if (X->getKind() != Y->getKind()) |
| 2795 | return false; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2796 | |
Douglas Gregor | da38930 | 2012-01-01 21:47:52 +0000 | [diff] [blame] | 2797 | // Objective-C classes and protocols with the same name always match. |
| 2798 | if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2799 | return true; |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2800 | |
| 2801 | if (isa<ClassTemplateSpecializationDecl>(X)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2802 | // No need to handle these here: we merge them when adding them to the |
| 2803 | // template. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2804 | return false; |
| 2805 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2806 | |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 2807 | // Compatible tags match. |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2808 | if (TagDecl *TagX = dyn_cast<TagDecl>(X)) { |
| 2809 | TagDecl *TagY = cast<TagDecl>(Y); |
| 2810 | return (TagX->getTagKind() == TagY->getTagKind()) || |
| 2811 | ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || |
| 2812 | TagX->getTagKind() == TTK_Interface) && |
| 2813 | (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class || |
| 2814 | TagY->getTagKind() == TTK_Interface)); |
| 2815 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2816 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2817 | // Functions with the same type and linkage match. |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2818 | // FIXME: This needs to cope with merging of prototyped/non-prototyped |
| 2819 | // functions, etc. |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 2820 | if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) { |
| 2821 | FunctionDecl *FuncY = cast<FunctionDecl>(Y); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2822 | if (CXXConstructorDecl *CtorX = dyn_cast<CXXConstructorDecl>(X)) { |
| 2823 | CXXConstructorDecl *CtorY = cast<CXXConstructorDecl>(Y); |
| 2824 | if (CtorX->getInheritedConstructor() && |
| 2825 | !isSameEntity(CtorX->getInheritedConstructor().getConstructor(), |
| 2826 | CtorY->getInheritedConstructor().getConstructor())) |
| 2827 | return false; |
| 2828 | } |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 2829 | |
| 2830 | if (FuncX->isMultiVersion() != FuncY->isMultiVersion()) |
| 2831 | return false; |
| 2832 | |
| 2833 | // Multiversioned functions with different feature strings are represented |
| 2834 | // as separate declarations. |
| 2835 | if (FuncX->isMultiVersion()) { |
| 2836 | const auto *TAX = FuncX->getAttr<TargetAttr>(); |
| 2837 | const auto *TAY = FuncY->getAttr<TargetAttr>(); |
| 2838 | assert(TAX && TAY && "Multiversion Function without target attribute"); |
| 2839 | |
| 2840 | if (TAX->getFeaturesStr() != TAY->getFeaturesStr()) |
| 2841 | return false; |
| 2842 | } |
| 2843 | |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 2844 | ASTContext &C = FuncX->getASTContext(); |
| 2845 | if (!C.hasSameType(FuncX->getType(), FuncY->getType())) { |
| 2846 | // We can get functions with different types on the redecl chain in C++17 |
| 2847 | // if they have differing exception specifications and at least one of |
| 2848 | // the excpetion specs is unresolved. |
| 2849 | // FIXME: Do we need to check for C++14 deduced return types here too? |
| 2850 | auto *XFPT = FuncX->getType()->getAs<FunctionProtoType>(); |
| 2851 | auto *YFPT = FuncY->getType()->getAs<FunctionProtoType>(); |
Aaron Ballman | c351fba | 2017-12-04 20:27:34 +0000 | [diff] [blame] | 2852 | if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT && |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 2853 | (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) || |
| 2854 | isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) && |
| 2855 | C.hasSameFunctionTypeIgnoringExceptionSpec(FuncX->getType(), |
| 2856 | FuncY->getType())) |
| 2857 | return true; |
| 2858 | return false; |
| 2859 | } |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2860 | return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() && |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2861 | hasSameOverloadableAttrs(FuncX, FuncY); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 2862 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2863 | |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 2864 | // Variables with the same type and linkage match. |
| 2865 | if (VarDecl *VarX = dyn_cast<VarDecl>(X)) { |
| 2866 | VarDecl *VarY = cast<VarDecl>(Y); |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 2867 | if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) { |
| 2868 | ASTContext &C = VarX->getASTContext(); |
| 2869 | if (C.hasSameType(VarX->getType(), VarY->getType())) |
| 2870 | return true; |
| 2871 | |
| 2872 | // We can get decls with different types on the redecl chain. Eg. |
| 2873 | // template <typename T> struct S { static T Var[]; }; // #1 |
| 2874 | // template <typename T> T S<T>::Var[sizeof(T)]; // #2 |
| 2875 | // Only? happens when completing an incomplete array type. In this case |
Vassil Vassilev | 4d75e8d | 2016-02-28 19:08:24 +0000 | [diff] [blame] | 2876 | // when comparing #1 and #2 we should go through their element type. |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 2877 | const ArrayType *VarXTy = C.getAsArrayType(VarX->getType()); |
| 2878 | const ArrayType *VarYTy = C.getAsArrayType(VarY->getType()); |
| 2879 | if (!VarXTy || !VarYTy) |
| 2880 | return false; |
| 2881 | if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType()) |
| 2882 | return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType()); |
| 2883 | } |
| 2884 | return false; |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 2885 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2886 | |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 2887 | // Namespaces with the same name and inlinedness match. |
| 2888 | if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) { |
| 2889 | NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y); |
| 2890 | return NamespaceX->isInline() == NamespaceY->isInline(); |
| 2891 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2892 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2893 | // Identical template names and kinds match if their template parameter lists |
| 2894 | // and patterns match. |
| 2895 | if (TemplateDecl *TemplateX = dyn_cast<TemplateDecl>(X)) { |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2896 | TemplateDecl *TemplateY = cast<TemplateDecl>(Y); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2897 | return isSameEntity(TemplateX->getTemplatedDecl(), |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2898 | TemplateY->getTemplatedDecl()) && |
| 2899 | isSameTemplateParameterList(TemplateX->getTemplateParameters(), |
| 2900 | TemplateY->getTemplateParameters()); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2901 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2902 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2903 | // Fields with the same name and the same type match. |
| 2904 | if (FieldDecl *FDX = dyn_cast<FieldDecl>(X)) { |
| 2905 | FieldDecl *FDY = cast<FieldDecl>(Y); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2906 | // FIXME: Also check the bitwidth is odr-equivalent, if any. |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2907 | return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); |
| 2908 | } |
| 2909 | |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 2910 | // Indirect fields with the same target field match. |
| 2911 | if (auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) { |
| 2912 | auto *IFDY = cast<IndirectFieldDecl>(Y); |
| 2913 | return IFDX->getAnonField()->getCanonicalDecl() == |
| 2914 | IFDY->getAnonField()->getCanonicalDecl(); |
| 2915 | } |
| 2916 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2917 | // Enumerators with the same name match. |
| 2918 | if (isa<EnumConstantDecl>(X)) |
| 2919 | // FIXME: Also check the value is odr-equivalent. |
| 2920 | return true; |
| 2921 | |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 2922 | // Using shadow declarations with the same target match. |
| 2923 | if (UsingShadowDecl *USX = dyn_cast<UsingShadowDecl>(X)) { |
| 2924 | UsingShadowDecl *USY = cast<UsingShadowDecl>(Y); |
| 2925 | return USX->getTargetDecl() == USY->getTargetDecl(); |
| 2926 | } |
| 2927 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 2928 | // Using declarations with the same qualifier match. (We already know that |
| 2929 | // the name matches.) |
| 2930 | if (auto *UX = dyn_cast<UsingDecl>(X)) { |
| 2931 | auto *UY = cast<UsingDecl>(Y); |
| 2932 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 2933 | UX->hasTypename() == UY->hasTypename() && |
| 2934 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 2935 | } |
| 2936 | if (auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) { |
| 2937 | auto *UY = cast<UnresolvedUsingValueDecl>(Y); |
| 2938 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 2939 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 2940 | } |
| 2941 | if (auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X)) |
| 2942 | return isSameQualifier( |
| 2943 | UX->getQualifier(), |
| 2944 | cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier()); |
| 2945 | |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2946 | // Namespace alias definitions with the same target match. |
| 2947 | if (auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) { |
| 2948 | auto *NAY = cast<NamespaceAliasDecl>(Y); |
| 2949 | return NAX->getNamespace()->Equals(NAY->getNamespace()); |
| 2950 | } |
| 2951 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2952 | return false; |
| 2953 | } |
| 2954 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2955 | /// Find the context in which we should search for previous declarations when |
| 2956 | /// looking for declarations to merge. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2957 | DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, |
| 2958 | DeclContext *DC) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2959 | if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC)) |
| 2960 | return ND->getOriginalNamespace(); |
| 2961 | |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2962 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) { |
| 2963 | // Try to dig out the definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2964 | auto *DD = RD->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2965 | if (!DD) |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2966 | DD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2967 | |
| 2968 | // If there's no definition yet, then DC's definition is added by an update |
| 2969 | // record, but we've not yet loaded that update record. In this case, we |
| 2970 | // commit to DC being the canonical definition now, and will fix this when |
| 2971 | // we load the update record. |
| 2972 | if (!DD) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2973 | DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2974 | RD->IsCompleteDefinition = true; |
| 2975 | RD->DefinitionData = DD; |
| 2976 | RD->getCanonicalDecl()->DefinitionData = DD; |
| 2977 | |
| 2978 | // Track that we did this horrible thing so that we can fix it later. |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 2979 | Reader.PendingFakeDefinitionData.insert( |
| 2980 | std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake)); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | return DD->Definition; |
| 2984 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2985 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2986 | if (EnumDecl *ED = dyn_cast<EnumDecl>(DC)) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2987 | return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() |
| 2988 | : nullptr; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2989 | |
Richard Smith | 4eca9b9 | 2015-02-04 23:37:59 +0000 | [diff] [blame] | 2990 | // We can see the TU here only if we have no Sema object. In that case, |
| 2991 | // there's no TU scope to look in, so using the DC alone is sufficient. |
| 2992 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 2993 | return TU; |
| 2994 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2995 | return nullptr; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2996 | } |
| 2997 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2998 | ASTDeclReader::FindExistingResult::~FindExistingResult() { |
Richard Smith | f1f4bc2 | 2015-01-22 02:21:23 +0000 | [diff] [blame] | 2999 | // Record that we had a typedef name for linkage whether or not we merge |
| 3000 | // with that declaration. |
| 3001 | if (TypedefNameForLinkage) { |
| 3002 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
| 3003 | Reader.ImportedTypedefNamesForLinkage.insert( |
| 3004 | std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New)); |
| 3005 | return; |
| 3006 | } |
| 3007 | |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3008 | if (!AddResult || Existing) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3009 | return; |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3010 | |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3011 | DeclarationName Name = New->getDeclName(); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3012 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3013 | if (needsAnonymousDeclarationNumber(New)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3014 | setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(), |
| 3015 | AnonymousDeclNumber, New); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3016 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3017 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3018 | if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name)) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3019 | Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()] |
| 3020 | .push_back(New); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3021 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3022 | // Add the declaration to its redeclaration context so later merging |
| 3023 | // lookups will find it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3024 | MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3025 | } |
| 3026 | } |
| 3027 | |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3028 | /// Find the declaration that should be merged into, given the declaration found |
| 3029 | /// by name lookup. If we're merging an anonymous declaration within a typedef, |
| 3030 | /// we need a matching typedef, and we merge with the type inside it. |
| 3031 | static NamedDecl *getDeclForMerging(NamedDecl *Found, |
| 3032 | bool IsTypedefNameForLinkage) { |
| 3033 | if (!IsTypedefNameForLinkage) |
| 3034 | return Found; |
| 3035 | |
| 3036 | // If we found a typedef declaration that gives a name to some other |
| 3037 | // declaration, then we want that inner declaration. Declarations from |
| 3038 | // AST files are handled via ImportedTypedefNamesForLinkage. |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3039 | if (Found->isFromASTFile()) |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3040 | return nullptr; |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3041 | |
| 3042 | if (auto *TND = dyn_cast<TypedefNameDecl>(Found)) |
Richard Smith | 3fb1a85 | 2016-08-30 19:13:18 +0000 | [diff] [blame] | 3043 | return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3044 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3045 | return nullptr; |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3048 | NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader, |
| 3049 | DeclContext *DC, |
| 3050 | unsigned Index) { |
| 3051 | // If the lexical context has been merged, look into the now-canonical |
| 3052 | // definition. |
| 3053 | if (auto *Merged = Reader.MergedDeclContexts.lookup(DC)) |
| 3054 | DC = Merged; |
| 3055 | |
| 3056 | // If we've seen this before, return the canonical declaration. |
| 3057 | auto &Previous = Reader.AnonymousDeclarationsForMerging[DC]; |
| 3058 | if (Index < Previous.size() && Previous[Index]) |
| 3059 | return Previous[Index]; |
| 3060 | |
| 3061 | // If this is the first time, but we have parsed a declaration of the context, |
| 3062 | // build the anonymous declaration list from the parsed declaration. |
| 3063 | if (!cast<Decl>(DC)->isFromASTFile()) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3064 | numberAnonymousDeclsWithin(DC, [&](NamedDecl *ND, unsigned Number) { |
| 3065 | if (Previous.size() == Number) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3066 | Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl())); |
| 3067 | else |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3068 | Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl()); |
| 3069 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | return Index < Previous.size() ? Previous[Index] : nullptr; |
| 3073 | } |
| 3074 | |
| 3075 | void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader, |
| 3076 | DeclContext *DC, unsigned Index, |
| 3077 | NamedDecl *D) { |
| 3078 | if (auto *Merged = Reader.MergedDeclContexts.lookup(DC)) |
| 3079 | DC = Merged; |
| 3080 | |
| 3081 | auto &Previous = Reader.AnonymousDeclarationsForMerging[DC]; |
| 3082 | if (Index >= Previous.size()) |
| 3083 | Previous.resize(Index + 1); |
| 3084 | if (!Previous[Index]) |
| 3085 | Previous[Index] = D; |
| 3086 | } |
| 3087 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3088 | ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3089 | DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage |
| 3090 | : D->getDeclName(); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3091 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3092 | if (!Name && !needsAnonymousDeclarationNumber(D)) { |
| 3093 | // Don't bother trying to find unnamed declarations that are in |
| 3094 | // unmergeable contexts. |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3095 | FindExistingResult Result(Reader, D, /*Existing=*/nullptr, |
| 3096 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 3097 | Result.suppress(); |
| 3098 | return Result; |
| 3099 | } |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3100 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3101 | DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3102 | if (TypedefNameForLinkage) { |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3103 | auto It = Reader.ImportedTypedefNamesForLinkage.find( |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3104 | std::make_pair(DC, TypedefNameForLinkage)); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3105 | if (It != Reader.ImportedTypedefNamesForLinkage.end()) |
| 3106 | if (isSameEntity(It->second, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3107 | return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber, |
| 3108 | TypedefNameForLinkage); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3109 | // Go on to check in other places in case an existing typedef name |
| 3110 | // was not imported. |
| 3111 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3112 | |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3113 | if (needsAnonymousDeclarationNumber(D)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3114 | // This is an anonymous declaration that we may need to merge. Look it up |
| 3115 | // in its context by number. |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3116 | if (auto *Existing = getAnonymousDeclForMerging( |
| 3117 | Reader, D->getLexicalDeclContext(), AnonymousDeclNumber)) |
| 3118 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3119 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3120 | TypedefNameForLinkage); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3121 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3122 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3123 | IdentifierResolver &IdResolver = Reader.getIdResolver(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3124 | |
| 3125 | // Temporarily consider the identifier to be up-to-date. We don't want to |
| 3126 | // cause additional lookups here. |
| 3127 | class UpToDateIdentifierRAII { |
| 3128 | IdentifierInfo *II; |
| 3129 | bool WasOutToDate; |
| 3130 | |
| 3131 | public: |
| 3132 | explicit UpToDateIdentifierRAII(IdentifierInfo *II) |
| 3133 | : II(II), WasOutToDate(false) |
| 3134 | { |
| 3135 | if (II) { |
| 3136 | WasOutToDate = II->isOutOfDate(); |
| 3137 | if (WasOutToDate) |
| 3138 | II->setOutOfDate(false); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | ~UpToDateIdentifierRAII() { |
| 3143 | if (WasOutToDate) |
| 3144 | II->setOutOfDate(true); |
| 3145 | } |
| 3146 | } UpToDate(Name.getAsIdentifierInfo()); |
| 3147 | |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 3148 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3149 | IEnd = IdResolver.end(); |
| 3150 | I != IEnd; ++I) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3151 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 87dacc7 | 2014-08-25 23:33:46 +0000 | [diff] [blame] | 3152 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3153 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3154 | TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3155 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3156 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3157 | DeclContext::lookup_result R = MergeDC->noload_lookup(Name); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3158 | for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3159 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3160 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3161 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3162 | TypedefNameForLinkage); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3163 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3164 | } else { |
| 3165 | // Not in a mergeable context. |
| 3166 | return FindExistingResult(Reader); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3167 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3168 | |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3169 | // If this declaration is from a merged context, make a note that we need to |
| 3170 | // check that the canonical definition of that context contains the decl. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3171 | // |
| 3172 | // FIXME: We should do something similar if we merge two definitions of the |
| 3173 | // same template specialization into the same CXXRecordDecl. |
Richard Smith | 88126a2 | 2014-08-25 02:10:01 +0000 | [diff] [blame] | 3174 | auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); |
| 3175 | if (MergedDCIt != Reader.MergedDeclContexts.end() && |
| 3176 | MergedDCIt->second == D->getDeclContext()) |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3177 | Reader.PendingOdrMergeChecks.push_back(D); |
| 3178 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3179 | return FindExistingResult(Reader, D, /*Existing=*/nullptr, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3180 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3183 | template<typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3184 | Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) { |
| 3185 | return D->RedeclLink.getLatestNotUpdated(); |
| 3186 | } |
| 3187 | Decl *ASTDeclReader::getMostRecentDeclImpl(...) { |
| 3188 | llvm_unreachable("getMostRecentDecl on non-redeclarable declaration"); |
| 3189 | } |
| 3190 | |
| 3191 | Decl *ASTDeclReader::getMostRecentDecl(Decl *D) { |
| 3192 | assert(D); |
| 3193 | |
| 3194 | switch (D->getKind()) { |
| 3195 | #define ABSTRACT_DECL(TYPE) |
| 3196 | #define DECL(TYPE, BASE) \ |
| 3197 | case Decl::TYPE: \ |
| 3198 | return getMostRecentDeclImpl(cast<TYPE##Decl>(D)); |
| 3199 | #include "clang/AST/DeclNodes.inc" |
| 3200 | } |
| 3201 | llvm_unreachable("unknown decl kind"); |
| 3202 | } |
| 3203 | |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 3204 | Decl *ASTReader::getMostRecentExistingDecl(Decl *D) { |
| 3205 | return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); |
| 3206 | } |
| 3207 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3208 | template<typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3209 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
| 3210 | Redeclarable<DeclT> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3211 | Decl *Previous, Decl *Canon) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3212 | D->RedeclLink.setPrevious(cast<DeclT>(Previous)); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3213 | D->First = cast<DeclT>(Previous)->First; |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3214 | } |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3215 | |
Richard Smith | 24d166c | 2014-07-31 23:52:38 +0000 | [diff] [blame] | 3216 | namespace clang { |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3217 | template<> |
| 3218 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3219 | Redeclarable<VarDecl> *D, |
| 3220 | Decl *Previous, Decl *Canon) { |
| 3221 | VarDecl *VD = static_cast<VarDecl*>(D); |
| 3222 | VarDecl *PrevVD = cast<VarDecl>(Previous); |
| 3223 | D->RedeclLink.setPrevious(PrevVD); |
| 3224 | D->First = PrevVD->First; |
| 3225 | |
| 3226 | // We should keep at most one definition on the chain. |
| 3227 | // FIXME: Cache the definition once we've found it. Building a chain with |
| 3228 | // N definitions currently takes O(N^2) time here. |
| 3229 | if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3230 | for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { |
| 3231 | if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3232 | Reader.mergeDefinitionVisibility(CurD, VD); |
| 3233 | VD->demoteThisDefinitionToDeclaration(); |
| 3234 | break; |
| 3235 | } |
| 3236 | } |
| 3237 | } |
| 3238 | } |
| 3239 | |
| 3240 | template<> |
| 3241 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3242 | Redeclarable<FunctionDecl> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3243 | Decl *Previous, Decl *Canon) { |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3244 | FunctionDecl *FD = static_cast<FunctionDecl*>(D); |
| 3245 | FunctionDecl *PrevFD = cast<FunctionDecl>(Previous); |
| 3246 | |
| 3247 | FD->RedeclLink.setPrevious(PrevFD); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3248 | FD->First = PrevFD->First; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3249 | |
| 3250 | // If the previous declaration is an inline function declaration, then this |
| 3251 | // declaration is too. |
| 3252 | if (PrevFD->IsInline != FD->IsInline) { |
| 3253 | // FIXME: [dcl.fct.spec]p4: |
| 3254 | // If a function with external linkage is declared inline in one |
| 3255 | // translation unit, it shall be declared inline in all translation |
| 3256 | // units in which it appears. |
| 3257 | // |
| 3258 | // Be careful of this case: |
| 3259 | // |
| 3260 | // module A: |
| 3261 | // template<typename T> struct X { void f(); }; |
| 3262 | // template<typename T> inline void X<T>::f() {} |
| 3263 | // |
| 3264 | // module B instantiates the declaration of X<int>::f |
| 3265 | // module C instantiates the definition of X<int>::f |
| 3266 | // |
| 3267 | // If module B and C are merged, we do not have a violation of this rule. |
| 3268 | FD->IsInline = true; |
| 3269 | } |
| 3270 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3271 | // If we need to propagate an exception specification along the redecl |
| 3272 | // chain, make a note of that so that we can do so later. |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3273 | auto *FPT = FD->getType()->getAs<FunctionProtoType>(); |
| 3274 | auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>(); |
Richard Smith | 8096975 | 2015-03-10 02:00:53 +0000 | [diff] [blame] | 3275 | if (FPT && PrevFPT) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3276 | bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType()); |
| 3277 | bool WasUnresolved = |
| 3278 | isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType()); |
| 3279 | if (IsUnresolved != WasUnresolved) |
| 3280 | Reader.PendingExceptionSpecUpdates.insert( |
| 3281 | std::make_pair(Canon, IsUnresolved ? PrevFD : FD)); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3282 | } |
| 3283 | } |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3284 | } // end namespace clang |
| 3285 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3286 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3287 | llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); |
| 3288 | } |
| 3289 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3290 | /// Inherit the default template argument from \p From to \p To. Returns |
| 3291 | /// \c false if there is no default template for \p From. |
| 3292 | template <typename ParmDecl> |
| 3293 | static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, |
| 3294 | Decl *ToD) { |
| 3295 | auto *To = cast<ParmDecl>(ToD); |
| 3296 | if (!From->hasDefaultArgument()) |
| 3297 | return false; |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 3298 | To->setInheritedDefaultArgument(Context, From); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3299 | return true; |
| 3300 | } |
| 3301 | |
| 3302 | static void inheritDefaultTemplateArguments(ASTContext &Context, |
| 3303 | TemplateDecl *From, |
| 3304 | TemplateDecl *To) { |
| 3305 | auto *FromTP = From->getTemplateParameters(); |
| 3306 | auto *ToTP = To->getTemplateParameters(); |
| 3307 | assert(FromTP->size() == ToTP->size() && "merged mismatched templates?"); |
| 3308 | |
| 3309 | for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { |
| 3310 | NamedDecl *FromParam = FromTP->getParam(N - I - 1); |
Richard Smith | 3d98703 | 2016-02-04 22:54:41 +0000 | [diff] [blame] | 3311 | if (FromParam->isParameterPack()) |
| 3312 | continue; |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3313 | NamedDecl *ToParam = ToTP->getParam(N - I - 1); |
| 3314 | |
| 3315 | if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) { |
Richard Smith | afe800c | 2015-06-17 22:13:23 +0000 | [diff] [blame] | 3316 | if (!inheritDefaultTemplateArgument(Context, FTTP, ToParam)) |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3317 | break; |
| 3318 | } else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) { |
Richard Smith | afe800c | 2015-06-17 22:13:23 +0000 | [diff] [blame] | 3319 | if (!inheritDefaultTemplateArgument(Context, FNTTP, ToParam)) |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3320 | break; |
| 3321 | } else { |
Richard Smith | afe800c | 2015-06-17 22:13:23 +0000 | [diff] [blame] | 3322 | if (!inheritDefaultTemplateArgument( |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3323 | Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam)) |
| 3324 | break; |
| 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3329 | void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3330 | Decl *Previous, Decl *Canon) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3331 | assert(D && Previous); |
| 3332 | |
| 3333 | switch (D->getKind()) { |
| 3334 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3335 | #define DECL(TYPE, BASE) \ |
| 3336 | case Decl::TYPE: \ |
| 3337 | attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3338 | break; |
| 3339 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3340 | } |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3341 | |
| 3342 | // If the declaration was visible in one module, a redeclaration of it in |
| 3343 | // another module remains visible even if it wouldn't be visible by itself. |
| 3344 | // |
| 3345 | // FIXME: In this case, the declaration should only be visible if a module |
| 3346 | // that makes it visible has been imported. |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3347 | D->IdentifierNamespace |= |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3348 | Previous->IdentifierNamespace & |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3349 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 3350 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3351 | // If the declaration declares a template, it may inherit default arguments |
| 3352 | // from the previous declaration. |
| 3353 | if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D)) |
| 3354 | inheritDefaultTemplateArguments(Reader.getContext(), |
| 3355 | cast<TemplateDecl>(Previous), TD); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3356 | } |
| 3357 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3358 | template<typename DeclT> |
| 3359 | void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3360 | D->RedeclLink.setLatest(cast<DeclT>(Latest)); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3361 | } |
| 3362 | void ASTDeclReader::attachLatestDeclImpl(...) { |
| 3363 | llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); |
| 3364 | } |
| 3365 | |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3366 | void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { |
| 3367 | assert(D && Latest); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3368 | |
| 3369 | switch (D->getKind()) { |
| 3370 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3371 | #define DECL(TYPE, BASE) \ |
| 3372 | case Decl::TYPE: \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3373 | attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ |
| 3374 | break; |
| 3375 | #include "clang/AST/DeclNodes.inc" |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3379 | template<typename DeclT> |
| 3380 | void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) { |
| 3381 | D->RedeclLink.markIncomplete(); |
| 3382 | } |
| 3383 | void ASTDeclReader::markIncompleteDeclChainImpl(...) { |
| 3384 | llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration"); |
| 3385 | } |
| 3386 | |
| 3387 | void ASTReader::markIncompleteDeclChain(Decl *D) { |
| 3388 | switch (D->getKind()) { |
| 3389 | #define ABSTRACT_DECL(TYPE) |
| 3390 | #define DECL(TYPE, BASE) \ |
| 3391 | case Decl::TYPE: \ |
| 3392 | ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \ |
| 3393 | break; |
| 3394 | #include "clang/AST/DeclNodes.inc" |
| 3395 | } |
| 3396 | } |
| 3397 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 3398 | /// \brief Read the declaration at the given offset from the AST file. |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3399 | Decl *ASTReader::ReadDeclRecord(DeclID ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3400 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 3401 | SourceLocation DeclLoc; |
| 3402 | RecordLocation Loc = DeclCursorForID(ID, DeclLoc); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3403 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3404 | // Keep track of where we are in the stream, then jump back there |
| 3405 | // after reading this declaration. |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 3406 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3407 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3408 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3409 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3410 | // Note that we are loading a declaration record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3411 | Deserializing ADecl(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3412 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3413 | DeclsCursor.JumpToBit(Loc.Offset); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3414 | ASTRecordReader Record(*this, *Loc.F); |
| 3415 | ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 3416 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3417 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3418 | ASTContext &Context = getContext(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3419 | Decl *D = nullptr; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3420 | switch ((DeclCode)Record.readRecord(DeclsCursor, Code)) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3421 | case DECL_CONTEXT_LEXICAL: |
| 3422 | case DECL_CONTEXT_VISIBLE: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3423 | llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3424 | case DECL_TYPEDEF: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3425 | D = TypedefDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3426 | break; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3427 | case DECL_TYPEALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3428 | D = TypeAliasDecl::CreateDeserialized(Context, ID); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3429 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3430 | case DECL_ENUM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3431 | D = EnumDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3432 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3433 | case DECL_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3434 | D = RecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3435 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3436 | case DECL_ENUM_CONSTANT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3437 | D = EnumConstantDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3438 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3439 | case DECL_FUNCTION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3440 | D = FunctionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3441 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3442 | case DECL_LINKAGE_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3443 | D = LinkageSpecDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3444 | break; |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 3445 | case DECL_EXPORT: |
| 3446 | D = ExportDecl::CreateDeserialized(Context, ID); |
| 3447 | break; |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3448 | case DECL_LABEL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3449 | D = LabelDecl::CreateDeserialized(Context, ID); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3450 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3451 | case DECL_NAMESPACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3452 | D = NamespaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3453 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3454 | case DECL_NAMESPACE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3455 | D = NamespaceAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3456 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3457 | case DECL_USING: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3458 | D = UsingDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3459 | break; |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3460 | case DECL_USING_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3461 | D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3462 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3463 | case DECL_USING_SHADOW: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3464 | D = UsingShadowDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3465 | break; |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 3466 | case DECL_CONSTRUCTOR_USING_SHADOW: |
| 3467 | D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID); |
| 3468 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3469 | case DECL_USING_DIRECTIVE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3470 | D = UsingDirectiveDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3471 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3472 | case DECL_UNRESOLVED_USING_VALUE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3473 | D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3474 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3475 | case DECL_UNRESOLVED_USING_TYPENAME: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3476 | D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3477 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3478 | case DECL_CXX_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3479 | D = CXXRecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3480 | break; |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 3481 | case DECL_CXX_DEDUCTION_GUIDE: |
| 3482 | D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID); |
| 3483 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3484 | case DECL_CXX_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3485 | D = CXXMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3486 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3487 | case DECL_CXX_CONSTRUCTOR: |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 3488 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, false); |
| 3489 | break; |
| 3490 | case DECL_CXX_INHERITED_CONSTRUCTOR: |
| 3491 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, true); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3492 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3493 | case DECL_CXX_DESTRUCTOR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3494 | D = CXXDestructorDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3495 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3496 | case DECL_CXX_CONVERSION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3497 | D = CXXConversionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3498 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3499 | case DECL_ACCESS_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3500 | D = AccessSpecDecl::CreateDeserialized(Context, ID); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 3501 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3502 | case DECL_FRIEND: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3503 | D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3504 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3505 | case DECL_FRIEND_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3506 | D = FriendTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3507 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3508 | case DECL_CLASS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3509 | D = ClassTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3510 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3511 | case DECL_CLASS_TEMPLATE_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3512 | D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3513 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3514 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3515 | D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3516 | break; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3517 | case DECL_VAR_TEMPLATE: |
| 3518 | D = VarTemplateDecl::CreateDeserialized(Context, ID); |
| 3519 | break; |
| 3520 | case DECL_VAR_TEMPLATE_SPECIALIZATION: |
| 3521 | D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
| 3522 | break; |
| 3523 | case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: |
| 3524 | D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
| 3525 | break; |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3526 | case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3527 | D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3528 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3529 | case DECL_FUNCTION_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3530 | D = FunctionTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3531 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3532 | case DECL_TEMPLATE_TYPE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3533 | D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3534 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3535 | case DECL_NON_TYPE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3536 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3537 | break; |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3538 | case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3539 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, |
| 3540 | Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3541 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3542 | case DECL_TEMPLATE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3543 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3544 | break; |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3545 | case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: |
| 3546 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3547 | Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3548 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3549 | case DECL_TYPE_ALIAS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3550 | D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3551 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3552 | case DECL_STATIC_ASSERT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3553 | D = StaticAssertDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3554 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3555 | case DECL_OBJC_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3556 | D = ObjCMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3557 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3558 | case DECL_OBJC_INTERFACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3559 | D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3560 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3561 | case DECL_OBJC_IVAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3562 | D = ObjCIvarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3563 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3564 | case DECL_OBJC_PROTOCOL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3565 | D = ObjCProtocolDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3566 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3567 | case DECL_OBJC_AT_DEFS_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3568 | D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3569 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3570 | case DECL_OBJC_CATEGORY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3571 | D = ObjCCategoryDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3572 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3573 | case DECL_OBJC_CATEGORY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3574 | D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3575 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3576 | case DECL_OBJC_IMPLEMENTATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3577 | D = ObjCImplementationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3578 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3579 | case DECL_OBJC_COMPATIBLE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3580 | D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3581 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3582 | case DECL_OBJC_PROPERTY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3583 | D = ObjCPropertyDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3584 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3585 | case DECL_OBJC_PROPERTY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3586 | D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3587 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3588 | case DECL_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3589 | D = FieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3590 | break; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3591 | case DECL_INDIRECTFIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3592 | D = IndirectFieldDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3593 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3594 | case DECL_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3595 | D = VarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3596 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3597 | case DECL_IMPLICIT_PARAM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3598 | D = ImplicitParamDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3599 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3600 | case DECL_PARM_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3601 | D = ParmVarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3602 | break; |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3603 | case DECL_DECOMPOSITION: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3604 | D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3605 | break; |
| 3606 | case DECL_BINDING: |
| 3607 | D = BindingDecl::CreateDeserialized(Context, ID); |
| 3608 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3609 | case DECL_FILE_SCOPE_ASM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3610 | D = FileScopeAsmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3611 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3612 | case DECL_BLOCK: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3613 | D = BlockDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3614 | break; |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 3615 | case DECL_MS_PROPERTY: |
| 3616 | D = MSPropertyDecl::CreateDeserialized(Context, ID); |
| 3617 | break; |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3618 | case DECL_CAPTURED: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3619 | D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3620 | break; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3621 | case DECL_CXX_BASE_SPECIFIERS: |
| 3622 | Error("attempt to read a C++ base-specifier record as a declaration"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3623 | return nullptr; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3624 | case DECL_CXX_CTOR_INITIALIZERS: |
| 3625 | Error("attempt to read a C++ ctor initializer record as a declaration"); |
| 3626 | return nullptr; |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3627 | case DECL_IMPORT: |
| 3628 | // Note: last entry of the ImportDecl record is the number of stored source |
| 3629 | // locations. |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3630 | D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3631 | break; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3632 | case DECL_OMP_THREADPRIVATE: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3633 | D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3634 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3635 | case DECL_OMP_DECLARE_REDUCTION: |
| 3636 | D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID); |
| 3637 | break; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3638 | case DECL_OMP_CAPTUREDEXPR: |
| 3639 | D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 3640 | break; |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3641 | case DECL_PRAGMA_COMMENT: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3642 | D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3643 | break; |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3644 | case DECL_PRAGMA_DETECT_MISMATCH: |
| 3645 | D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3646 | Record.readInt()); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3647 | break; |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 3648 | case DECL_EMPTY: |
| 3649 | D = EmptyDecl::CreateDeserialized(Context, ID); |
| 3650 | break; |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3651 | case DECL_OBJC_TYPE_PARAM: |
| 3652 | D = ObjCTypeParamDecl::CreateDeserialized(Context, ID); |
| 3653 | break; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3654 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3655 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 3656 | assert(D && "Unknown declaration reading AST file"); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3657 | LoadedDecl(Index, D); |
Argyrios Kyrtzidis | 6c07547 | 2012-02-09 06:02:44 +0000 | [diff] [blame] | 3658 | // Set the DeclContext before doing any deserialization, to make sure internal |
| 3659 | // calls to Decl::getASTContext() by Decl's methods will find the |
| 3660 | // TranslationUnitDecl without crashing. |
| 3661 | D->setDeclContext(Context.getTranslationUnitDecl()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3662 | Reader.Visit(D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3663 | |
| 3664 | // If this declaration is also a declaration context, get the |
| 3665 | // offsets for its tables of lexical and visible declarations. |
| 3666 | if (DeclContext *DC = dyn_cast<DeclContext>(D)) { |
| 3667 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3668 | if (Offsets.first && |
| 3669 | ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) |
| 3670 | return nullptr; |
| 3671 | if (Offsets.second && |
| 3672 | ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID)) |
| 3673 | return nullptr; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3674 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3675 | assert(Record.getIdx() == Record.size()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3676 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3677 | // Load any relevant update records. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3678 | PendingUpdateRecords.push_back( |
| 3679 | PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); |
Argyrios Kyrtzidis | 7d268c3 | 2011-11-14 07:07:59 +0000 | [diff] [blame] | 3680 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3681 | // Load the categories after recursive loading is finished. |
| 3682 | if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D)) |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 3683 | // If we already have a definition when deserializing the ObjCInterfaceDecl, |
| 3684 | // we put the Decl in PendingDefinitions so we can pull the categories here. |
| 3685 | if (Class->isThisDeclarationADefinition() || |
| 3686 | PendingDefinitions.count(Class)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3687 | loadObjCCategories(ID, Class); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3688 | |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3689 | // If we have deserialized a declaration that has a definition the |
| 3690 | // AST consumer might need to know about, queue it. |
| 3691 | // We don't pass it to the consumer immediately because we may be in recursive |
| 3692 | // loading, and some declarations may still be initializing. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3693 | PotentiallyInterestingDecls.push_back( |
| 3694 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3695 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3696 | return D; |
| 3697 | } |
| 3698 | |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3699 | void ASTReader::PassInterestingDeclsToConsumer() { |
| 3700 | assert(Consumer); |
| 3701 | |
| 3702 | if (PassingDeclsToConsumer) |
| 3703 | return; |
| 3704 | |
| 3705 | // Guard variable to avoid recursively redoing the process of passing |
| 3706 | // decls to consumer. |
| 3707 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 3708 | true); |
| 3709 | |
| 3710 | // Ensure that we've loaded all potentially-interesting declarations |
| 3711 | // that need to be eagerly loaded. |
| 3712 | for (auto ID : EagerlyDeserializedDecls) |
| 3713 | GetDecl(ID); |
| 3714 | EagerlyDeserializedDecls.clear(); |
| 3715 | |
| 3716 | while (!PotentiallyInterestingDecls.empty()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3717 | InterestingDecl D = PotentiallyInterestingDecls.front(); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3718 | PotentiallyInterestingDecls.pop_front(); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3719 | if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) |
| 3720 | PassInterestingDeclToConsumer(D.getDecl()); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3721 | } |
| 3722 | } |
| 3723 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3724 | void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3725 | // The declaration may have been modified by files later in the chain. |
| 3726 | // If this is the case, read the record containing the updates from each file |
| 3727 | // and pass it to ASTDeclReader to make the modifications. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3728 | serialization::GlobalDeclID ID = Record.ID; |
| 3729 | Decl *D = Record.D; |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 3730 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3731 | DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3732 | |
| 3733 | llvm::SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs; |
| 3734 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3735 | if (UpdI != DeclUpdateOffsets.end()) { |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3736 | auto UpdateOffsets = std::move(UpdI->second); |
| 3737 | DeclUpdateOffsets.erase(UpdI); |
| 3738 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3739 | // Check if this decl was interesting to the consumer. If we just loaded |
| 3740 | // the declaration, then we know it was interesting and we skip the call |
| 3741 | // to isConsumerInterestedIn because it is unsafe to call in the |
| 3742 | // current ASTReader state. |
| 3743 | bool WasInteresting = |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3744 | Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3745 | for (auto &FileAndOffset : UpdateOffsets) { |
| 3746 | ModuleFile *F = FileAndOffset.first; |
| 3747 | uint64_t Offset = FileAndOffset.second; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3748 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3749 | SavedStreamPosition SavedPosition(Cursor); |
| 3750 | Cursor.JumpToBit(Offset); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3751 | unsigned Code = Cursor.ReadCode(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3752 | ASTRecordReader Record(*this, *F); |
| 3753 | unsigned RecCode = Record.readRecord(Cursor, Code); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3754 | (void)RecCode; |
| 3755 | assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!"); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 3756 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3757 | ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, |
| 3758 | SourceLocation()); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3759 | Reader.UpdateDecl(D, PendingLazySpecializationIDs); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 3760 | |
| 3761 | // We might have made this declaration interesting. If so, remember that |
| 3762 | // we need to hand it off to the consumer. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3763 | if (!WasInteresting && |
| 3764 | isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { |
| 3765 | PotentiallyInterestingDecls.push_back( |
| 3766 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 3767 | WasInteresting = true; |
| 3768 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3769 | } |
| 3770 | } |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3771 | // Add the lazy specializations to the template. |
| 3772 | assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || |
| 3773 | isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && |
| 3774 | "Must not have pending specializations"); |
| 3775 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) |
| 3776 | ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); |
| 3777 | else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 3778 | ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); |
| 3779 | else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) |
| 3780 | ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); |
| 3781 | PendingLazySpecializationIDs.clear(); |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 3782 | |
| 3783 | // Load the pending visible updates for this decl context, if it has any. |
| 3784 | auto I = PendingVisibleUpdates.find(ID); |
| 3785 | if (I != PendingVisibleUpdates.end()) { |
| 3786 | auto VisibleUpdates = std::move(I->second); |
| 3787 | PendingVisibleUpdates.erase(I); |
| 3788 | |
| 3789 | auto *DC = cast<DeclContext>(D)->getPrimaryContext(); |
| 3790 | for (const PendingVisibleUpdate &Update : VisibleUpdates) |
| 3791 | Lookups[DC].Table.add( |
| 3792 | Update.Mod, Update.Data, |
| 3793 | reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); |
| 3794 | DC->setHasExternalVisibleStorage(true); |
| 3795 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3796 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3797 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 3798 | void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { |
| 3799 | // Attach FirstLocal to the end of the decl chain. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 3800 | Decl *CanonDecl = FirstLocal->getCanonicalDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 3801 | if (FirstLocal != CanonDecl) { |
| 3802 | Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl); |
| 3803 | ASTDeclReader::attachPreviousDecl( |
| 3804 | *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl, |
| 3805 | CanonDecl); |
| 3806 | } |
| 3807 | |
| 3808 | if (!LocalOffset) { |
| 3809 | ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal); |
| 3810 | return; |
| 3811 | } |
| 3812 | |
| 3813 | // Load the list of other redeclarations from this module file. |
| 3814 | ModuleFile *M = getOwningModuleFile(FirstLocal); |
| 3815 | assert(M && "imported decl from no module file"); |
| 3816 | |
| 3817 | llvm::BitstreamCursor &Cursor = M->DeclsCursor; |
| 3818 | SavedStreamPosition SavedPosition(Cursor); |
| 3819 | Cursor.JumpToBit(LocalOffset); |
| 3820 | |
| 3821 | RecordData Record; |
| 3822 | unsigned Code = Cursor.ReadCode(); |
| 3823 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 3824 | (void)RecCode; |
| 3825 | assert(RecCode == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!"); |
| 3826 | |
| 3827 | // FIXME: We have several different dispatches on decl kind here; maybe |
| 3828 | // we should instead generate one loop per kind and dispatch up-front? |
| 3829 | Decl *MostRecent = FirstLocal; |
| 3830 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 3831 | auto *D = GetLocalDecl(*M, Record[N - I - 1]); |
Richard Smith | e2f8ce9 | 2015-07-15 00:02:40 +0000 | [diff] [blame] | 3832 | ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); |
| 3833 | MostRecent = D; |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3834 | } |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3835 | ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | namespace { |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3839 | /// \brief Given an ObjC interface, goes through the modules and links to the |
| 3840 | /// interface all the categories for it. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3841 | class ObjCCategoriesVisitor { |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3842 | ASTReader &Reader; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3843 | ObjCInterfaceDecl *Interface; |
Craig Topper | 4dd9b43 | 2014-08-17 23:49:53 +0000 | [diff] [blame] | 3844 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3845 | ObjCCategoryDecl *Tail; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3846 | llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 3847 | serialization::GlobalDeclID InterfaceID; |
| 3848 | unsigned PreviousGeneration; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3849 | |
| 3850 | void add(ObjCCategoryDecl *Cat) { |
| 3851 | // Only process each category once. |
Benjamin Kramer | fc6eb7d | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 3852 | if (!Deserialized.erase(Cat)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3853 | return; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3854 | |
| 3855 | // Check for duplicate categories. |
| 3856 | if (Cat->getDeclName()) { |
| 3857 | ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; |
| 3858 | if (Existing && |
| 3859 | Reader.getOwningModuleFile(Existing) |
| 3860 | != Reader.getOwningModuleFile(Cat)) { |
| 3861 | // FIXME: We should not warn for duplicates in diamond: |
| 3862 | // |
| 3863 | // MT // |
| 3864 | // / \ // |
| 3865 | // ML MR // |
| 3866 | // \ / // |
| 3867 | // MB // |
| 3868 | // |
| 3869 | // If there are duplicates in ML/MR, there will be warning when |
| 3870 | // creating MB *and* when importing MB. We should not warn when |
| 3871 | // importing. |
| 3872 | Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) |
| 3873 | << Interface->getDeclName() << Cat->getDeclName(); |
| 3874 | Reader.Diag(Existing->getLocation(), diag::note_previous_definition); |
| 3875 | } else if (!Existing) { |
| 3876 | // Record this category. |
| 3877 | Existing = Cat; |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | // Add this category to the end of the chain. |
| 3882 | if (Tail) |
| 3883 | ASTDeclReader::setNextObjCCategory(Tail, Cat); |
| 3884 | else |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 3885 | Interface->setCategoryListRaw(Cat); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3886 | Tail = Cat; |
| 3887 | } |
| 3888 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3889 | public: |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3890 | ObjCCategoriesVisitor(ASTReader &Reader, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3891 | ObjCInterfaceDecl *Interface, |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 3892 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized, |
| 3893 | serialization::GlobalDeclID InterfaceID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3894 | unsigned PreviousGeneration) |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 3895 | : Reader(Reader), Interface(Interface), Deserialized(Deserialized), |
| 3896 | Tail(nullptr), InterfaceID(InterfaceID), |
| 3897 | PreviousGeneration(PreviousGeneration) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3898 | { |
| 3899 | // Populate the name -> category map with the set of known categories. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3900 | for (auto *Cat : Interface->known_categories()) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3901 | if (Cat->getDeclName()) |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3902 | NameCategoryMap[Cat->getDeclName()] = Cat; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3903 | |
| 3904 | // Keep track of the tail of the category list. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 3905 | Tail = Cat; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3906 | } |
| 3907 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3908 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 3909 | bool operator()(ModuleFile &M) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3910 | // If we've loaded all of the category information we care about from |
| 3911 | // this module file, we're done. |
| 3912 | if (M.Generation <= PreviousGeneration) |
| 3913 | return true; |
| 3914 | |
| 3915 | // Map global ID of the definition down to the local ID used in this |
| 3916 | // module file. If there is no such mapping, we'll find nothing here |
| 3917 | // (or in any module it imports). |
| 3918 | DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); |
| 3919 | if (!LocalID) |
| 3920 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3921 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3922 | // Perform a binary search to find the local redeclarations for this |
| 3923 | // declaration (if any). |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 3924 | const ObjCCategoriesInfo Compare = { LocalID, 0 }; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3925 | const ObjCCategoriesInfo *Result |
| 3926 | = std::lower_bound(M.ObjCCategoriesMap, |
| 3927 | M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 3928 | Compare); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3929 | if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || |
| 3930 | Result->DefinitionID != LocalID) { |
| 3931 | // We didn't find anything. If the class definition is in this module |
| 3932 | // file, then the module files it depends on cannot have any categories, |
| 3933 | // so suppress further lookup. |
| 3934 | return Reader.isDeclIDFromModule(InterfaceID, M); |
| 3935 | } |
| 3936 | |
| 3937 | // We found something. Dig out all of the categories. |
| 3938 | unsigned Offset = Result->Offset; |
| 3939 | unsigned N = M.ObjCCategories[Offset]; |
| 3940 | M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again |
| 3941 | for (unsigned I = 0; I != N; ++I) |
| 3942 | add(cast_or_null<ObjCCategoryDecl>( |
| 3943 | Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); |
| 3944 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3945 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3946 | }; |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3947 | } // end anonymous namespace |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3948 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3949 | void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, |
| 3950 | ObjCInterfaceDecl *D, |
| 3951 | unsigned PreviousGeneration) { |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 3952 | ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3953 | PreviousGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 3954 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3955 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3956 | |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 3957 | template<typename DeclT, typename Fn> |
| 3958 | static void forAllLaterRedecls(DeclT *D, Fn F) { |
| 3959 | F(D); |
| 3960 | |
| 3961 | // Check whether we've already merged D into its redeclaration chain. |
| 3962 | // MostRecent may or may not be nullptr if D has not been merged. If |
| 3963 | // not, walk the merged redecl chain and see if it's there. |
| 3964 | auto *MostRecent = D->getMostRecentDecl(); |
| 3965 | bool Found = false; |
| 3966 | for (auto *Redecl = MostRecent; Redecl && !Found; |
| 3967 | Redecl = Redecl->getPreviousDecl()) |
| 3968 | Found = (Redecl == D); |
| 3969 | |
| 3970 | // If this declaration is merged, apply the functor to all later decls. |
| 3971 | if (Found) { |
| 3972 | for (auto *Redecl = MostRecent; Redecl != D; |
| 3973 | Redecl = Redecl->getPreviousDecl()) |
| 3974 | F(Redecl); |
| 3975 | } |
| 3976 | } |
| 3977 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3978 | void ASTDeclReader::UpdateDecl(Decl *D, |
| 3979 | llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3980 | while (Record.getIdx() < Record.size()) { |
| 3981 | switch ((DeclUpdateKind)Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3982 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: { |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 3983 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 3984 | // FIXME: If we also have an update record for instantiating the |
| 3985 | // definition of D, we need that to happen before we get here. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 3986 | Decl *MD = Record.readDecl(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3987 | assert(MD && "couldn't read decl from update record"); |
Richard Smith | 46bb581 | 2014-08-01 01:56:39 +0000 | [diff] [blame] | 3988 | // FIXME: We should call addHiddenDecl instead, to add the member |
| 3989 | // to its DeclContext. |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 3990 | RD->addedMember(MD); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 3991 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3992 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 3993 | |
| 3994 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3995 | // It will be added to the template's lazy specialization set. |
| 3996 | PendingLazySpecializationIDs.push_back(ReadDeclID()); |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 3997 | break; |
| 3998 | |
| 3999 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4000 | NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>(); |
| 4001 | |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4002 | // Each module has its own anonymous namespace, which is disjoint from |
| 4003 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 4004 | // namespace at all. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4005 | if (!Record.isModule()) { |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4006 | if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D)) |
| 4007 | TU->setAnonymousNamespace(Anon); |
| 4008 | else |
| 4009 | cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); |
| 4010 | } |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4011 | break; |
| 4012 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4013 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4014 | case UPD_CXX_ADDED_VAR_DEFINITION: { |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4015 | VarDecl *VD = cast<VarDecl>(D); |
Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 4016 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 4017 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4018 | uint64_t Val = Record.readInt(); |
| 4019 | if (Val && !VD->getInit()) { |
| 4020 | VD->setInit(Record.readExpr()); |
| 4021 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 |
| 4022 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 4023 | Eval->CheckedICE = true; |
| 4024 | Eval->IsICE = Val == 3; |
| 4025 | } |
| 4026 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4027 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4028 | } |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4029 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4030 | case UPD_CXX_POINT_OF_INSTANTIATION: { |
| 4031 | SourceLocation POI = Record.readSourceLocation(); |
| 4032 | if (VarTemplateSpecializationDecl *VTSD = |
| 4033 | dyn_cast<VarTemplateSpecializationDecl>(D)) { |
| 4034 | VTSD->setPointOfInstantiation(POI); |
| 4035 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| 4036 | VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 4037 | } else { |
| 4038 | auto *FD = cast<FunctionDecl>(D); |
| 4039 | if (auto *FTSInfo = FD->TemplateOrSpecialization |
| 4040 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) |
| 4041 | FTSInfo->setPointOfInstantiation(POI); |
| 4042 | else |
| 4043 | FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>() |
| 4044 | ->setPointOfInstantiation(POI); |
| 4045 | } |
| 4046 | break; |
| 4047 | } |
| 4048 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4049 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { |
| 4050 | auto Param = cast<ParmVarDecl>(D); |
| 4051 | |
| 4052 | // We have to read the default argument regardless of whether we use it |
| 4053 | // so that hypothetical further update records aren't messed up. |
| 4054 | // TODO: Add a function to skip over the next expr record. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4055 | auto DefaultArg = Record.readExpr(); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4056 | |
| 4057 | // Only apply the update if the parameter still has an uninstantiated |
| 4058 | // default argument. |
| 4059 | if (Param->hasUninstantiatedDefaultArg()) |
| 4060 | Param->setDefaultArg(DefaultArg); |
| 4061 | break; |
| 4062 | } |
| 4063 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4064 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { |
| 4065 | auto FD = cast<FieldDecl>(D); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4066 | auto DefaultInit = Record.readExpr(); |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4067 | |
| 4068 | // Only apply the update if the field still has an uninstantiated |
| 4069 | // default member initializer. |
| 4070 | if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) { |
| 4071 | if (DefaultInit) |
| 4072 | FD->setInClassInitializer(DefaultInit); |
| 4073 | else |
| 4074 | // Instantiation failed. We can get here if we serialized an AST for |
| 4075 | // an invalid program. |
| 4076 | FD->removeInClassInitializer(); |
| 4077 | } |
| 4078 | break; |
| 4079 | } |
| 4080 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4081 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: { |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4082 | FunctionDecl *FD = cast<FunctionDecl>(D); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 4083 | if (Reader.PendingBodies[FD]) { |
| 4084 | // FIXME: Maybe check for ODR violations. |
| 4085 | // It's safe to stop now because this update record is always last. |
| 4086 | return; |
| 4087 | } |
| 4088 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4089 | if (Record.readInt()) { |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4090 | // Maintain AST consistency: any later redeclarations of this function |
| 4091 | // are inline if this one is. (We might have merged another declaration |
| 4092 | // into this one.) |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4093 | forAllLaterRedecls(FD, [](FunctionDecl *FD) { |
| 4094 | FD->setImplicitlyInline(); |
| 4095 | }); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4096 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4097 | FD->setInnerLocStart(ReadSourceLocation()); |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 4098 | ReadFunctionDefinition(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4099 | assert(Record.getIdx() == Record.size() && "lazy body must be last"); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4100 | break; |
| 4101 | } |
| 4102 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4103 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4104 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 4105 | auto *OldDD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4106 | bool HadRealDefinition = |
Richard Smith | 7483d20 | 2015-02-04 01:23:46 +0000 | [diff] [blame] | 4107 | OldDD && (OldDD->Definition != RD || |
| 4108 | !Reader.PendingFakeDefinitionData.count(OldDD)); |
Akira Hatanaka | d791e92 | 2018-03-19 17:38:40 +0000 | [diff] [blame^] | 4109 | RD->setCanPassInRegisters(Record.readInt()); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4110 | ReadCXXRecordDefinition(RD, /*Update*/true); |
| 4111 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4112 | // Visible update is handled separately. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4113 | uint64_t LexicalOffset = ReadLocalOffset(); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 4114 | if (!HadRealDefinition && LexicalOffset) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4115 | Record.readLexicalDeclContextStorage(LexicalOffset, RD); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4116 | Reader.PendingFakeDefinitionData.erase(OldDD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4119 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4120 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4121 | if (MemberSpecializationInfo *MSInfo = |
| 4122 | RD->getMemberSpecializationInfo()) { |
| 4123 | MSInfo->setTemplateSpecializationKind(TSK); |
| 4124 | MSInfo->setPointOfInstantiation(POI); |
| 4125 | } else { |
| 4126 | ClassTemplateSpecializationDecl *Spec = |
| 4127 | cast<ClassTemplateSpecializationDecl>(RD); |
| 4128 | Spec->setTemplateSpecializationKind(TSK); |
| 4129 | Spec->setPointOfInstantiation(POI); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4130 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4131 | if (Record.readInt()) { |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4132 | auto PartialSpec = |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4133 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>(); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4134 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4135 | Record.readTemplateArgumentList(TemplArgs); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4136 | auto *TemplArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 4137 | Reader.getContext(), TemplArgs); |
Richard Smith | 72544f8 | 2014-08-14 03:30:27 +0000 | [diff] [blame] | 4138 | |
| 4139 | // FIXME: If we already have a partial specialization set, |
| 4140 | // check that it matches. |
| 4141 | if (!Spec->getSpecializedTemplateOrPartial() |
| 4142 | .is<ClassTemplatePartialSpecializationDecl *>()) |
| 4143 | Spec->setInstantiationOf(PartialSpec, TemplArgList); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4144 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4147 | RD->setTagKind((TagTypeKind)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4148 | RD->setLocation(ReadSourceLocation()); |
| 4149 | RD->setLocStart(ReadSourceLocation()); |
| 4150 | RD->setBraceRange(ReadSourceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4151 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4152 | if (Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4153 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4154 | Record.readAttributes(Attrs); |
Richard Smith | 842e46e | 2016-10-26 02:31:56 +0000 | [diff] [blame] | 4155 | // If the declaration already has attributes, we assume that some other |
| 4156 | // AST file already loaded them. |
| 4157 | if (!D->hasAttrs()) |
| 4158 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4159 | } |
| 4160 | break; |
| 4161 | } |
| 4162 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4163 | case UPD_CXX_RESOLVED_DTOR_DELETE: { |
| 4164 | // Set the 'operator delete' directly to avoid emitting another update |
| 4165 | // record. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4166 | auto *Del = ReadDeclAs<FunctionDecl>(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4167 | auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl()); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4168 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4169 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4170 | if (!First->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4171 | First->OperatorDelete = Del; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4172 | First->OperatorDeleteThisArg = ThisArg; |
| 4173 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4174 | break; |
| 4175 | } |
| 4176 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4177 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 4178 | FunctionProtoType::ExceptionSpecInfo ESI; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4179 | SmallVector<QualType, 8> ExceptionStorage; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4180 | Record.readExceptionSpec(ExceptionStorage, ESI); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4181 | |
| 4182 | // Update this declaration's exception specification, if needed. |
| 4183 | auto *FD = cast<FunctionDecl>(D); |
| 4184 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); |
| 4185 | // FIXME: If the exception specification is already present, check that it |
| 4186 | // matches. |
| 4187 | if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4188 | FD->setType(Reader.getContext().getFunctionType( |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4189 | FPT->getReturnType(), FPT->getParamTypes(), |
| 4190 | FPT->getExtProtoInfo().withExceptionSpec(ESI))); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4191 | |
| 4192 | // When we get to the end of deserializing, see if there are other decls |
| 4193 | // that we need to propagate this exception specification onto. |
| 4194 | Reader.PendingExceptionSpecUpdates.insert( |
| 4195 | std::make_pair(FD->getCanonicalDecl(), FD)); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4196 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4197 | break; |
| 4198 | } |
| 4199 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4200 | case UPD_CXX_DEDUCED_RETURN_TYPE: { |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4201 | // FIXME: Also do this when merging redecls. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4202 | QualType DeducedResultType = Record.readType(); |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4203 | for (auto *Redecl : merged_redecls(D)) { |
| 4204 | // FIXME: If the return type is already deduced, check that it matches. |
| 4205 | FunctionDecl *FD = cast<FunctionDecl>(Redecl); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4206 | Reader.getContext().adjustDeducedFunctionResultType(FD, |
| 4207 | DeducedResultType); |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4208 | } |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4209 | break; |
| 4210 | } |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4211 | |
| 4212 | case UPD_DECL_MARKED_USED: { |
Richard Smith | 675d279 | 2014-06-16 20:26:19 +0000 | [diff] [blame] | 4213 | // Maintain AST consistency: any later redeclarations are used too. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4214 | D->markUsed(Reader.getContext()); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4215 | break; |
| 4216 | } |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4217 | |
| 4218 | case UPD_MANGLING_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4219 | Reader.getContext().setManglingNumber(cast<NamedDecl>(D), |
| 4220 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4221 | break; |
| 4222 | |
| 4223 | case UPD_STATIC_LOCAL_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4224 | Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D), |
| 4225 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4226 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4227 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4228 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4229 | D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(), |
| 4230 | ReadSourceRange())); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4231 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4232 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4233 | case UPD_DECL_EXPORTED: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4234 | unsigned SubmoduleID = readSubmoduleID(); |
Richard Smith | beb4478 | 2015-06-20 01:05:19 +0000 | [diff] [blame] | 4235 | auto *Exported = cast<NamedDecl>(D); |
| 4236 | if (auto *TD = dyn_cast<TagDecl>(Exported)) |
| 4237 | Exported = TD->getDefinition(); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4238 | Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 4239 | if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 4240 | Reader.getContext().mergeDefinitionIntoModule(cast<NamedDecl>(Exported), |
| 4241 | Owner); |
Richard Smith | 1e02a5a | 2015-06-25 21:42:33 +0000 | [diff] [blame] | 4242 | Reader.PendingMergedDefinitionsToDeduplicate.insert( |
| 4243 | cast<NamedDecl>(Exported)); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 4244 | } else if (Owner && Owner->NameVisibility != Module::AllVisible) { |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4245 | // If Owner is made visible at some later point, make this declaration |
| 4246 | // visible too. |
Richard Smith | 1e02a5a | 2015-06-25 21:42:33 +0000 | [diff] [blame] | 4247 | Reader.HiddenNamesMap[Owner].push_back(Exported); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4248 | } else { |
| 4249 | // The declaration is now visible. |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 4250 | Exported->setVisibleDespiteOwningModule(); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4251 | } |
| 4252 | break; |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4253 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4254 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 4255 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4256 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4257 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4258 | Record.readAttributes(Attrs); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4259 | assert(Attrs.size() == 1); |
| 4260 | D->addAttr(Attrs[0]); |
| 4261 | break; |
| 4262 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4263 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4264 | } |