Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +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 | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 16 | #include "clang/Serialization/ModuleManager.h" |
Chandler Carruth | a2398d7 | 2011-12-09 00:02:23 +0000 | [diff] [blame] | 17 | #include "clang/Serialization/SerializationDiagnostic.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 18 | #include "ASTCommon.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 19 | #include "ASTReaderInternals.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 27 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 28 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 29 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 31 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 33 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 39 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 40 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 41 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 45 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 46 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 47 | #include "llvm/Support/Path.h" |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 48 | #include "llvm/Support/SaveAndRestore.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 49 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 51 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 53 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 54 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 56 | using namespace clang::serialization; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 57 | using namespace clang::serialization::reader; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 58 | |
| 59 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 60 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | //===----------------------------------------------------------------------===// |
| 62 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 63 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 64 | |
| 65 | bool |
| 66 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 67 | const LangOptions &PPLangOpts = PP.getLangOpts(); |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 68 | |
| 69 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 70 | if (PPLangOpts.Name != LangOpts.Name) { \ |
| 71 | Reader.Diag(diag::err_pch_langopt_mismatch) \ |
| 72 | << Description << LangOpts.Name << PPLangOpts.Name; \ |
| 73 | return true; \ |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 76 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 77 | if (PPLangOpts.Name != LangOpts.Name) { \ |
| 78 | Reader.Diag(diag::err_pch_langopt_value_mismatch) \ |
| 79 | << Description; \ |
| 80 | return true; \ |
| 81 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 82 | |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 83 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 84 | if (PPLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 85 | Reader.Diag(diag::err_pch_langopt_value_mismatch) \ |
| 86 | << Description; \ |
| 87 | return true; \ |
| 88 | } |
| 89 | |
| 90 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 91 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 92 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 93 | |
| 94 | if (PPLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 95 | Reader.Diag(diag::err_pch_langopt_value_mismatch) |
| 96 | << "target Objective-C runtime"; |
| 97 | return true; |
| 98 | } |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 99 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 103 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 104 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 105 | return false; |
| 106 | |
| 107 | Reader.Diag(diag::warn_pch_target_triple) |
| 108 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 109 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 112 | namespace { |
| 113 | struct EmptyStringRef { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 114 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 115 | }; |
| 116 | struct EmptyBlock { |
| 117 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 118 | }; |
| 119 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 120 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 121 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 122 | PCHPredefinesBlocks R) { |
| 123 | // First, sum up the lengths. |
| 124 | unsigned LL = 0, RL = 0; |
| 125 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 126 | LL += L[I].size(); |
| 127 | } |
| 128 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 129 | RL += R[I].Data.size(); |
| 130 | } |
| 131 | if (LL != RL) |
| 132 | return false; |
| 133 | if (LL == 0 && RL == 0) |
| 134 | return true; |
| 135 | |
| 136 | // Kick out empty parts, they confuse the algorithm below. |
| 137 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 138 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 139 | |
| 140 | // Do it the hard way. At this point, both vectors must be non-empty. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 141 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 142 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 143 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 144 | for (;;) { |
| 145 | // Compare the current pieces. |
| 146 | if (LR.size() == RR.size()) { |
| 147 | // If they're the same length, it's pretty easy. |
| 148 | if (LR != RR) |
| 149 | return false; |
| 150 | // Both pieces are done, advance. |
| 151 | ++LI; |
| 152 | ++RI; |
| 153 | // If either string is done, they're both done, since they're the same |
| 154 | // length. |
| 155 | if (LI == LN) { |
| 156 | assert(RI == RN && "Strings not the same length after all?"); |
| 157 | return true; |
| 158 | } |
| 159 | LR = L[LI]; |
| 160 | RR = R[RI].Data; |
| 161 | } else if (LR.size() < RR.size()) { |
| 162 | // Right piece is longer. |
| 163 | if (!RR.startswith(LR)) |
| 164 | return false; |
| 165 | ++LI; |
| 166 | assert(LI != LN && "Strings not the same length after all?"); |
| 167 | RR = RR.substr(LR.size()); |
| 168 | LR = L[LI]; |
| 169 | } else { |
| 170 | // Left piece is longer. |
| 171 | if (!LR.startswith(RR)) |
| 172 | return false; |
| 173 | ++RI; |
| 174 | assert(RI != RN && "Strings not the same length after all?"); |
| 175 | LR = LR.substr(RR.size()); |
| 176 | RR = R[RI].Data; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 181 | static std::pair<FileID, StringRef::size_type> |
| 182 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 183 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 184 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 185 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 186 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 187 | Res.first = Buffers[I].BufferID; |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | return Res; |
| 192 | } |
| 193 | |
| 194 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 195 | StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 196 | std::string &SuggestedPredefines, |
| 197 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 198 | // We are in the context of an implicit include, so the predefines buffer will |
| 199 | // have a #include entry for the PCH file itself (as normalized by the |
| 200 | // preprocessor initialization). Find it and skip over it in the checking |
| 201 | // below. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 202 | SmallString<256> PCHInclude; |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 203 | PCHInclude += "#include \""; |
Chandler Carruth | cb381ea | 2011-12-09 01:33:57 +0000 | [diff] [blame] | 204 | PCHInclude += HeaderSearch::NormalizeDashIncludePath(OriginalFileName, |
| 205 | FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 206 | PCHInclude += "\"\n"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 207 | std::pair<StringRef,StringRef> Split = |
| 208 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 209 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 210 | if (Left == PP.getPredefines()) { |
| 211 | Error("Missing PCH include entry!"); |
| 212 | return true; |
| 213 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 214 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 215 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 216 | // command line, we're done. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 217 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 218 | CommandLine.push_back(Left); |
| 219 | CommandLine.push_back(Right); |
| 220 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 221 | return false; |
| 222 | |
| 223 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 225 | // The predefines buffers are different. Determine what the differences are, |
| 226 | // and whether they require us to reject the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 227 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 228 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 229 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 230 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 231 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 232 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 233 | |
| 234 | // Pick out implicit #includes after the PCH and don't consider them for |
| 235 | // validation; we will insert them into SuggestedPredefines so that the |
| 236 | // preprocessor includes them. |
| 237 | std::string IncludesAfterPCH; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 238 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 239 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 240 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 241 | if (AfterPCHLines[i].startswith("#include ")) { |
| 242 | IncludesAfterPCH += AfterPCHLines[i]; |
| 243 | IncludesAfterPCH += '\n'; |
| 244 | } else { |
| 245 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // Make sure we add the includes last into SuggestedPredefines before we |
| 250 | // exit this function. |
| 251 | struct AddIncludesRAII { |
| 252 | std::string &SuggestedPredefines; |
| 253 | std::string &IncludesAfterPCH; |
| 254 | |
| 255 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 256 | std::string &IncludesAfterPCH) |
| 257 | : SuggestedPredefines(SuggestedPredefines), |
| 258 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 259 | ~AddIncludesRAII() { |
| 260 | SuggestedPredefines += IncludesAfterPCH; |
| 261 | } |
| 262 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 263 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 264 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 265 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 266 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 267 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 268 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 269 | // Determine which predefines that were used to build the PCH file are missing |
| 270 | // from the command line. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 271 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 272 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 273 | CmdLineLines.begin(), CmdLineLines.end(), |
| 274 | std::back_inserter(MissingPredefines)); |
| 275 | |
| 276 | bool MissingDefines = false; |
| 277 | bool ConflictingDefines = false; |
| 278 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 279 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 280 | if (Missing.startswith("#include ")) { |
| 281 | // An -include was specified when generating the PCH; it is included in |
| 282 | // the PCH, just ignore it. |
| 283 | continue; |
| 284 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 285 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 286 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 287 | return true; |
| 288 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 290 | // This is a macro definition. Determine the name of the macro we're |
| 291 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 292 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 294 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 295 | assert(EndOfMacroName != std::string::npos && |
| 296 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 297 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 298 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 299 | // Determine whether this macro was given a different definition on the |
| 300 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 301 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 302 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 303 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 304 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 305 | MacroDefStart); |
| 306 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 307 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 308 | // Different macro; we're done. |
| 309 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 311 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
| 313 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 314 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 316 | (*ConflictPos)[MacroDefLen] != '(') |
| 317 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 318 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 319 | // We found a conflicting macro definition. |
| 320 | break; |
| 321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | if (ConflictPos != CmdLineLines.end()) { |
| 324 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 325 | << MacroName; |
| 326 | |
| 327 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 328 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 329 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 330 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 331 | SourceLocation PCHMissingLoc = |
| 332 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 333 | .getLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 334 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 335 | |
| 336 | ConflictingDefines = true; |
| 337 | continue; |
| 338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 340 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 341 | // definition from the PCH file. Warn the user that they made a mistake. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | if (ConflictingDefines) |
| 343 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | if (!MissingDefines) { |
| 346 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 347 | MissingDefines = true; |
| 348 | } |
| 349 | |
| 350 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 351 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 352 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 353 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 354 | SourceLocation PCHMissingLoc = |
| 355 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 356 | .getLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 360 | if (ConflictingDefines) |
| 361 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | // Determine what predefines were introduced based on command-line |
| 364 | // parameters that were not present when building the PCH |
| 365 | // file. Extra #defines are okay, so long as the identifiers being |
| 366 | // defined were not used within the precompiled header. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 367 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 369 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 372 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 373 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 374 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | // This is an extra macro definition. Determine the name of the |
| 379 | // macro we're defining. |
| 380 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 382 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 383 | assert(EndOfMacroName != std::string::npos && |
| 384 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 385 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 386 | |
| 387 | // Check whether this name was used somewhere in the PCH file. If |
| 388 | // so, defining it as a macro could change behavior, so we reject |
| 389 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 390 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 391 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | |
| 395 | // Add this definition to the suggested predefines buffer. |
| 396 | SuggestedPredefines += Extra; |
| 397 | SuggestedPredefines += '\n'; |
| 398 | } |
| 399 | |
| 400 | // If we get here, it's because the predefines buffer had compatible |
| 401 | // contents. Accept the PCH file. |
| 402 | return false; |
| 403 | } |
| 404 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 405 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 406 | unsigned ID) { |
| 407 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 408 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void PCHValidator::ReadCounter(unsigned Value) { |
| 412 | PP.setCounterValue(Value); |
| 413 | } |
| 414 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 415 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 416 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 417 | //===----------------------------------------------------------------------===// |
| 418 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 419 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 420 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 421 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 424 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 425 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 426 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 427 | return serialization::ComputeHash(Sel); |
| 428 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 429 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 431 | std::pair<unsigned, unsigned> |
| 432 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 433 | using namespace clang::io; |
| 434 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 435 | unsigned DataLen = ReadUnalignedLE16(d); |
| 436 | return std::make_pair(KeyLen, DataLen); |
| 437 | } |
| 438 | |
| 439 | ASTSelectorLookupTrait::internal_key_type |
| 440 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 441 | using namespace clang::io; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 442 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 443 | unsigned N = ReadUnalignedLE16(d); |
| 444 | IdentifierInfo *FirstII |
| 445 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 446 | if (N == 0) |
| 447 | return SelTable.getNullarySelector(FirstII); |
| 448 | else if (N == 1) |
| 449 | return SelTable.getUnarySelector(FirstII); |
| 450 | |
| 451 | SmallVector<IdentifierInfo *, 16> Args; |
| 452 | Args.push_back(FirstII); |
| 453 | for (unsigned I = 1; I != N; ++I) |
| 454 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 455 | |
| 456 | return SelTable.getSelector(N, Args.data()); |
| 457 | } |
| 458 | |
| 459 | ASTSelectorLookupTrait::data_type |
| 460 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 461 | unsigned DataLen) { |
| 462 | using namespace clang::io; |
| 463 | |
| 464 | data_type Result; |
| 465 | |
| 466 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 467 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 468 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 469 | |
| 470 | // Load instance methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 471 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 472 | if (ObjCMethodDecl *Method |
| 473 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 474 | Result.Instance.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 475 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 476 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 477 | // Load factory methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 478 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 479 | if (ObjCMethodDecl *Method |
| 480 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 481 | Result.Factory.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 483 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 484 | return Result; |
| 485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 487 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 488 | return llvm::HashString(StringRef(a.first, a.second)); |
| 489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 491 | std::pair<unsigned, unsigned> |
| 492 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 493 | using namespace clang::io; |
| 494 | unsigned DataLen = ReadUnalignedLE16(d); |
| 495 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 496 | return std::make_pair(KeyLen, DataLen); |
| 497 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 499 | std::pair<const char*, unsigned> |
| 500 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 501 | assert(n >= 2 && d[n-1] == '\0'); |
| 502 | return std::make_pair((const char*) d, n-1); |
| 503 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 505 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 506 | const unsigned char* d, |
| 507 | unsigned DataLen) { |
| 508 | using namespace clang::io; |
| 509 | unsigned RawID = ReadUnalignedLE32(d); |
| 510 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 512 | // Wipe out the "is interesting" bit. |
| 513 | RawID = RawID >> 1; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 514 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 515 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 516 | if (!IsInteresting) { |
| 517 | // For uninteresting identifiers, just build the IdentifierInfo |
| 518 | // and associate it with the persistent ID. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 519 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 520 | if (!II) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 521 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 522 | KnownII = II; |
| 523 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 524 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 525 | II->setIsFromAST(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 526 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 527 | return II; |
| 528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 530 | unsigned Bits = ReadUnalignedLE16(d); |
| 531 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 532 | Bits >>= 1; |
| 533 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 534 | Bits >>= 1; |
| 535 | bool Poisoned = Bits & 0x01; |
| 536 | Bits >>= 1; |
| 537 | bool ExtensionToken = Bits & 0x01; |
| 538 | Bits >>= 1; |
| 539 | bool hasMacroDefinition = Bits & 0x01; |
| 540 | Bits >>= 1; |
Craig Topper | 925be54 | 2011-12-19 05:04:33 +0000 | [diff] [blame] | 541 | unsigned ObjCOrBuiltinID = Bits & 0x7FF; |
| 542 | Bits >>= 11; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 543 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 544 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 545 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 546 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 547 | // Build the IdentifierInfo itself and link the identifier ID with |
| 548 | // the new IdentifierInfo. |
| 549 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 550 | if (!II) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 551 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 552 | KnownII = II; |
| 553 | } |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 554 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 555 | II->setIsFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 556 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 557 | // Set or check the various bits in the IdentifierInfo structure. |
| 558 | // Token IDs are read-only. |
| 559 | if (HasRevertedTokenIDToIdentifier) |
| 560 | II->RevertTokenIDToIdentifier(); |
| 561 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 562 | assert(II->isExtensionToken() == ExtensionToken && |
| 563 | "Incorrect extension token flag"); |
| 564 | (void)ExtensionToken; |
| 565 | if (Poisoned) |
| 566 | II->setIsPoisoned(true); |
| 567 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 568 | "Incorrect C++ operator keyword flag"); |
| 569 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 570 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 571 | // If this identifier is a macro, deserialize the macro |
| 572 | // definition. |
| 573 | if (hasMacroDefinition) { |
| 574 | // FIXME: Check for conflicts? |
| 575 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 576 | unsigned LocalSubmoduleID = ReadUnalignedLE32(d); |
| 577 | |
| 578 | // Determine whether this macro definition should be visible now, or |
| 579 | // whether it is in a hidden submodule. |
| 580 | bool Visible = true; |
| 581 | if (SubmoduleID GlobalSubmoduleID |
| 582 | = Reader.getGlobalSubmoduleID(F, LocalSubmoduleID)) { |
| 583 | if (Module *Owner = Reader.getSubmodule(GlobalSubmoduleID)) { |
| 584 | if (Owner->NameVisibility == Module::Hidden) { |
| 585 | // The owning module is not visible, and this macro definition should |
| 586 | // not be, either. |
| 587 | Visible = false; |
| 588 | |
| 589 | // Note that this macro definition was hidden because its owning |
| 590 | // module is not yet visible. |
| 591 | Reader.HiddenNamesMap[Owner].push_back(II); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | Reader.setIdentifierIsMacro(II, F, Offset, Visible); |
| 597 | DataLen -= 8; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 600 | Reader.SetIdentifierInfo(ID, II); |
| 601 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 602 | // Read all of the declarations visible at global scope with this |
| 603 | // name. |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 604 | if (DataLen > 0) { |
| 605 | SmallVector<uint32_t, 4> DeclIDs; |
| 606 | for (; DataLen > 0; DataLen -= 4) |
| 607 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 608 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 611 | return II; |
| 612 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 613 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 614 | unsigned |
| 615 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 616 | llvm::FoldingSetNodeID ID; |
| 617 | ID.AddInteger(Key.Kind); |
| 618 | |
| 619 | switch (Key.Kind) { |
| 620 | case DeclarationName::Identifier: |
| 621 | case DeclarationName::CXXLiteralOperatorName: |
| 622 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 623 | break; |
| 624 | case DeclarationName::ObjCZeroArgSelector: |
| 625 | case DeclarationName::ObjCOneArgSelector: |
| 626 | case DeclarationName::ObjCMultiArgSelector: |
| 627 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 628 | break; |
| 629 | case DeclarationName::CXXOperatorName: |
| 630 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 631 | break; |
| 632 | case DeclarationName::CXXConstructorName: |
| 633 | case DeclarationName::CXXDestructorName: |
| 634 | case DeclarationName::CXXConversionFunctionName: |
| 635 | case DeclarationName::CXXUsingDirective: |
| 636 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 639 | return ID.ComputeHash(); |
| 640 | } |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 641 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 642 | ASTDeclContextNameLookupTrait::internal_key_type |
| 643 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 644 | const external_key_type& Name) const { |
| 645 | DeclNameKey Key; |
| 646 | Key.Kind = Name.getNameKind(); |
| 647 | switch (Name.getNameKind()) { |
| 648 | case DeclarationName::Identifier: |
| 649 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 650 | break; |
| 651 | case DeclarationName::ObjCZeroArgSelector: |
| 652 | case DeclarationName::ObjCOneArgSelector: |
| 653 | case DeclarationName::ObjCMultiArgSelector: |
| 654 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 655 | break; |
| 656 | case DeclarationName::CXXOperatorName: |
| 657 | Key.Data = Name.getCXXOverloadedOperator(); |
| 658 | break; |
| 659 | case DeclarationName::CXXLiteralOperatorName: |
| 660 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 661 | break; |
| 662 | case DeclarationName::CXXConstructorName: |
| 663 | case DeclarationName::CXXDestructorName: |
| 664 | case DeclarationName::CXXConversionFunctionName: |
| 665 | case DeclarationName::CXXUsingDirective: |
| 666 | Key.Data = 0; |
| 667 | break; |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 670 | return Key; |
| 671 | } |
| 672 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 673 | std::pair<unsigned, unsigned> |
| 674 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 675 | using namespace clang::io; |
| 676 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 677 | unsigned DataLen = ReadUnalignedLE16(d); |
| 678 | return std::make_pair(KeyLen, DataLen); |
| 679 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 680 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 681 | ASTDeclContextNameLookupTrait::internal_key_type |
| 682 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 683 | using namespace clang::io; |
| 684 | |
| 685 | DeclNameKey Key; |
| 686 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 687 | switch (Key.Kind) { |
| 688 | case DeclarationName::Identifier: |
| 689 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 690 | break; |
| 691 | case DeclarationName::ObjCZeroArgSelector: |
| 692 | case DeclarationName::ObjCOneArgSelector: |
| 693 | case DeclarationName::ObjCMultiArgSelector: |
| 694 | Key.Data = |
| 695 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 696 | .getAsOpaquePtr(); |
| 697 | break; |
| 698 | case DeclarationName::CXXOperatorName: |
| 699 | Key.Data = *d++; // OverloadedOperatorKind |
| 700 | break; |
| 701 | case DeclarationName::CXXLiteralOperatorName: |
| 702 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 703 | break; |
| 704 | case DeclarationName::CXXConstructorName: |
| 705 | case DeclarationName::CXXDestructorName: |
| 706 | case DeclarationName::CXXConversionFunctionName: |
| 707 | case DeclarationName::CXXUsingDirective: |
| 708 | Key.Data = 0; |
| 709 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 712 | return Key; |
| 713 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 714 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 715 | ASTDeclContextNameLookupTrait::data_type |
| 716 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 717 | const unsigned char* d, |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 718 | unsigned DataLen) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 719 | using namespace clang::io; |
| 720 | unsigned NumDecls = ReadUnalignedLE16(d); |
Douglas Gregor | 9b8b20f | 2012-01-06 16:09:53 +0000 | [diff] [blame] | 721 | LE32DeclID *Start = (LE32DeclID *)d; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 722 | return std::make_pair(Start, Start + NumDecls); |
| 723 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 724 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 725 | bool ASTReader::ReadDeclContextStorage(ModuleFile &M, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 726 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 727 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 728 | DeclContextInfo &Info) { |
| 729 | SavedStreamPosition SavedPosition(Cursor); |
| 730 | // First the lexical decls. |
| 731 | if (Offsets.first != 0) { |
| 732 | Cursor.JumpToBit(Offsets.first); |
| 733 | |
| 734 | RecordData Record; |
| 735 | const char *Blob; |
| 736 | unsigned BlobLen; |
| 737 | unsigned Code = Cursor.ReadCode(); |
| 738 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 739 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 740 | Error("Expected lexical block"); |
| 741 | return true; |
| 742 | } |
| 743 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 744 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 745 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | // Now the lookup table. |
| 749 | if (Offsets.second != 0) { |
| 750 | Cursor.JumpToBit(Offsets.second); |
| 751 | |
| 752 | RecordData Record; |
| 753 | const char *Blob; |
| 754 | unsigned BlobLen; |
| 755 | unsigned Code = Cursor.ReadCode(); |
| 756 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 757 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 758 | Error("Expected visible lookup table block"); |
| 759 | return true; |
| 760 | } |
| 761 | Info.NameLookupTableData |
| 762 | = ASTDeclContextNameLookupTable::Create( |
| 763 | (const unsigned char *)Blob + Record[0], |
| 764 | (const unsigned char *)Blob, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 765 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | return false; |
| 769 | } |
| 770 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 771 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 772 | Error(diag::err_fe_pch_malformed, Msg); |
| 773 | } |
| 774 | |
| 775 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 776 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 777 | if (Diags.isDiagnosticInFlight()) |
| 778 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 779 | else |
| 780 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 783 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 784 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 785 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 786 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 787 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 788 | SuggestedPredefines, |
| 789 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 790 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 793 | //===----------------------------------------------------------------------===// |
| 794 | // Source Manager Deserialization |
| 795 | //===----------------------------------------------------------------------===// |
| 796 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 797 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 798 | /// \returns true if there was an error. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 799 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 800 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 801 | unsigned Idx = 0; |
| 802 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 803 | |
| 804 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 805 | std::map<int, int> FileIDs; |
| 806 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 807 | // Extract the file name |
| 808 | unsigned FilenameLen = Record[Idx++]; |
| 809 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 810 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 811 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 812 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Parse the line entries |
| 816 | std::vector<LineEntry> Entries; |
| 817 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 818 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 819 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 820 | // Remap FileID from 1-based old view. |
| 821 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 822 | |
| 823 | // Extract the line entries |
| 824 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 825 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 826 | Entries.clear(); |
| 827 | Entries.reserve(NumEntries); |
| 828 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 829 | unsigned FileOffset = Record[Idx++]; |
| 830 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 831 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 833 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 834 | unsigned IncludeOffset = Record[Idx++]; |
| 835 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 836 | FileKind, IncludeOffset)); |
| 837 | } |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 838 | LineTable.AddEntry(FileID::get(FID), Entries); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return false; |
| 842 | } |
| 843 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 844 | namespace { |
| 845 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 846 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 847 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 848 | const ino_t ino; |
| 849 | const dev_t dev; |
| 850 | const mode_t mode; |
| 851 | const time_t mtime; |
| 852 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 854 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 855 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 856 | }; |
| 857 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 858 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 859 | public: |
| 860 | typedef const char *external_key_type; |
| 861 | typedef const char *internal_key_type; |
| 862 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 863 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 864 | |
| 865 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 866 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 870 | |
| 871 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 872 | return strcmp(a, b) == 0; |
| 873 | } |
| 874 | |
| 875 | static std::pair<unsigned, unsigned> |
| 876 | ReadKeyDataLength(const unsigned char*& d) { |
| 877 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 878 | unsigned DataLen = (unsigned) *d++; |
| 879 | return std::make_pair(KeyLen + 1, DataLen); |
| 880 | } |
| 881 | |
| 882 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 883 | return (const char *)d; |
| 884 | } |
| 885 | |
| 886 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 887 | unsigned /*DataLen*/) { |
| 888 | using namespace clang::io; |
| 889 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 890 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 891 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 892 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 894 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 895 | return data_type(ino, dev, mode, mtime, size); |
| 896 | } |
| 897 | }; |
| 898 | |
| 899 | /// \brief stat() cache for precompiled headers. |
| 900 | /// |
| 901 | /// This cache is very similar to the stat cache used by pretokenized |
| 902 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 903 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 904 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 905 | CacheTy *Cache; |
| 906 | |
| 907 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 909 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 910 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 911 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 912 | Cache = CacheTy::Create(Buckets, Base); |
| 913 | } |
| 914 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 915 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 916 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 917 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 918 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 919 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 920 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 921 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 922 | // If we don't get a hit in the AST file just forward to 'stat'. |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 923 | if (I == Cache->end()) { |
| 924 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 925 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 926 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 928 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 929 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 931 | StatBuf.st_ino = Data.ino; |
| 932 | StatBuf.st_dev = Data.dev; |
| 933 | StatBuf.st_mtime = Data.mtime; |
| 934 | StatBuf.st_mode = Data.mode; |
| 935 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 936 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 937 | } |
| 938 | }; |
| 939 | } // end anonymous namespace |
| 940 | |
| 941 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 942 | /// \brief Read a source manager block |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 943 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 944 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 945 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 946 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 947 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 948 | // Set the source-location entry cursor to the current position in |
| 949 | // the stream. This cursor will be used to read the contents of the |
| 950 | // source manager block initially, and then lazily read |
| 951 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 952 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 953 | |
| 954 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 955 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 956 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 957 | return Failure; |
| 958 | } |
| 959 | |
| 960 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 961 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 962 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 963 | return Failure; |
| 964 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 965 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 966 | RecordData Record; |
| 967 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 968 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 969 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 970 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 971 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 972 | return Failure; |
| 973 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 974 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 975 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 976 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 977 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 978 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 979 | SLocEntryCursor.ReadSubBlockID(); |
| 980 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 981 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 982 | return Failure; |
| 983 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 984 | continue; |
| 985 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 987 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 988 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 989 | continue; |
| 990 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 992 | // Read a record. |
| 993 | const char *BlobStart; |
| 994 | unsigned BlobLen; |
| 995 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 996 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 997 | default: // Default behavior: ignore. |
| 998 | break; |
| 999 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1000 | case SM_SLOC_FILE_ENTRY: |
| 1001 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1002 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1003 | // Once we hit one of the source location entries, we're done. |
| 1004 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1009 | /// \brief If a header file is not found at the path that we expect it to be |
| 1010 | /// and the PCH file was moved from its original location, try to resolve the |
| 1011 | /// file by assuming that header+PCH were moved together and the header is in |
| 1012 | /// the same place relative to the PCH. |
| 1013 | static std::string |
| 1014 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1015 | const std::string &OriginalDir, |
| 1016 | const std::string &CurrDir) { |
| 1017 | assert(OriginalDir != CurrDir && |
| 1018 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1019 | using namespace llvm::sys; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1020 | SmallString<128> filePath(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1021 | fs::make_absolute(filePath); |
| 1022 | assert(path::is_absolute(OriginalDir)); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1023 | SmallString<128> currPCHPath(CurrDir); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1024 | |
| 1025 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1026 | fileDirE = path::end(path::parent_path(filePath)); |
| 1027 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1028 | origDirE = path::end(OriginalDir); |
| 1029 | // Skip the common path components from filePath and OriginalDir. |
| 1030 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1031 | *fileDirI == *origDirI) { |
| 1032 | ++fileDirI; |
| 1033 | ++origDirI; |
| 1034 | } |
| 1035 | for (; origDirI != origDirE; ++origDirI) |
| 1036 | path::append(currPCHPath, ".."); |
| 1037 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1038 | path::append(currPCHPath, path::filename(Filename)); |
| 1039 | return currPCHPath.str(); |
| 1040 | } |
| 1041 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1042 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1043 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1044 | if (ID == 0) |
| 1045 | return Success; |
| 1046 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1047 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1048 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1049 | return Failure; |
| 1050 | } |
| 1051 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1052 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1053 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1054 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1055 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1056 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1057 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1058 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1059 | if (Code == llvm::bitc::END_BLOCK || |
| 1060 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1061 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1062 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1063 | return Failure; |
| 1064 | } |
| 1065 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1066 | RecordData Record; |
| 1067 | const char *BlobStart; |
| 1068 | unsigned BlobLen; |
| 1069 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1070 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1071 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1072 | return Failure; |
| 1073 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1074 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1075 | if (Record.size() < 7) { |
| 1076 | Error("source location entry is incorrect"); |
| 1077 | return Failure; |
| 1078 | } |
| 1079 | |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1080 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1081 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1082 | ASTReader::ASTReadResult Result = Success; |
| 1083 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1084 | bool OverriddenBuffer = Record[6]; |
| 1085 | |
| 1086 | std::string OrigFilename(BlobStart, BlobStart + BlobLen); |
| 1087 | std::string Filename = OrigFilename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1088 | MaybeAddSystemRootToFilename(Filename); |
Douglas Gregor | a4581a1 | 2011-11-17 19:08:51 +0000 | [diff] [blame] | 1089 | const FileEntry *File = |
| 1090 | OverriddenBuffer? FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1091 | (time_t)Record[5]) |
| 1092 | : FileMgr.getFile(Filename, /*OpenFile=*/false); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1093 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1094 | OriginalDir != CurrentDir) { |
| 1095 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1096 | OriginalDir, |
| 1097 | CurrentDir); |
| 1098 | if (!resolved.empty()) |
| 1099 | File = FileMgr.getFile(resolved); |
| 1100 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1101 | if (File == 0) |
| 1102 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1103 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1104 | if (File == 0) { |
| 1105 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1106 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1107 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1108 | Error(ErrorStr.c_str()); |
| 1109 | return Failure; |
| 1110 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1111 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1112 | if (!DisableValidation && |
| 1113 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1114 | #if !defined(LLVM_ON_WIN32) |
| 1115 | // In our regression testing, the Windows file system seems to |
| 1116 | // have inconsistent modification times that sometimes |
| 1117 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1118 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1119 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1120 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1121 | Error(diag::err_fe_pch_file_modified, Filename); |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1122 | Result = Failure; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1125 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1126 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1127 | // This is the module's main file. |
| 1128 | IncludeLoc = getImportLocation(F); |
| 1129 | } |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1130 | SrcMgr::CharacteristicKind |
| 1131 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1132 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1133 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1134 | SrcMgr::FileInfo &FileInfo = |
| 1135 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1136 | FileInfo.NumCreatedFIDs = Record[7]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1137 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1138 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1139 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1140 | const DeclID *FirstDecl = F->FileSortedDecls + Record[8]; |
| 1141 | unsigned NumFileDecls = Record[9]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1142 | if (NumFileDecls) { |
| 1143 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 1144 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1145 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1146 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1148 | const SrcMgr::ContentCache *ContentCache |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1149 | = SourceMgr.getOrCreateContentCache(File, |
| 1150 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1151 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1152 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1153 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1154 | Record.clear(); |
| 1155 | unsigned RecCode |
| 1156 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1157 | |
| 1158 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1159 | Error("AST record has invalid code"); |
| 1160 | return Failure; |
| 1161 | } |
| 1162 | |
| 1163 | llvm::MemoryBuffer *Buffer |
| 1164 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1165 | Filename); |
| 1166 | SourceMgr.overrideFileContents(File, Buffer); |
| 1167 | } |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1168 | |
| 1169 | if (Result == Failure) |
| 1170 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1171 | break; |
| 1172 | } |
| 1173 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1174 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1175 | const char *Name = BlobStart; |
| 1176 | unsigned Offset = Record[0]; |
| 1177 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1178 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1180 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1181 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1182 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1183 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1184 | return Failure; |
| 1185 | } |
| 1186 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1187 | llvm::MemoryBuffer *Buffer |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1188 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1189 | Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1190 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1191 | BaseOffset + Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 1193 | if (strcmp(Name, "<built-in>") == 0 && F->Kind == MK_PCH) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1194 | PCHPredefinesBlock Block = { |
| 1195 | BufferID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1196 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1197 | }; |
| 1198 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1199 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1200 | |
| 1201 | break; |
| 1202 | } |
| 1203 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1204 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1205 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1206 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1207 | ReadSourceLocation(*F, Record[2]), |
| 1208 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1209 | Record[4], |
| 1210 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1211 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1212 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | return Success; |
| 1217 | } |
| 1218 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1219 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1220 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1221 | if (F->ImportLoc.isValid()) |
| 1222 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1224 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1225 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1226 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1227 | // Main file is the importer. We assume that it is the first entry in the |
| 1228 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1229 | // the main file entry doesn't exist yet. |
| 1230 | // The very first entry is the invalid instantiation loc, which takes up |
| 1231 | // offsets 0 and 1. |
| 1232 | return SourceLocation::getFromRawEncoding(2U); |
| 1233 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1234 | //return F->Loaders[0]->FirstLoc; |
| 1235 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1238 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1239 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1240 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1241 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1242 | unsigned BlockID) { |
| 1243 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1244 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1245 | return Failure; |
| 1246 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1248 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1249 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1250 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1251 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1252 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1253 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1254 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1255 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1256 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1257 | Cursor.ReadAbbrevRecord(); |
| 1258 | } |
| 1259 | } |
| 1260 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1261 | void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1262 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1263 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1264 | // Keep track of where we are in the stream, then jump back there |
| 1265 | // after reading this macro. |
| 1266 | SavedStreamPosition SavedPosition(Stream); |
| 1267 | |
| 1268 | Stream.JumpToBit(Offset); |
| 1269 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1270 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1271 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1272 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1273 | while (true) { |
| 1274 | unsigned Code = Stream.ReadCode(); |
| 1275 | switch (Code) { |
| 1276 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1277 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1278 | |
| 1279 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1280 | // No known subblocks, always skip them. |
| 1281 | Stream.ReadSubBlockID(); |
| 1282 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1283 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1284 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1285 | } |
| 1286 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1288 | case llvm::bitc::DEFINE_ABBREV: |
| 1289 | Stream.ReadAbbrevRecord(); |
| 1290 | continue; |
| 1291 | default: break; |
| 1292 | } |
| 1293 | |
| 1294 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1295 | const char *BlobStart = 0; |
| 1296 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1297 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1298 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1299 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1300 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1301 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1302 | case PP_MACRO_OBJECT_LIKE: |
| 1303 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1304 | // If we already have a macro, that means that we've hit the end |
| 1305 | // of the definition of the macro we were looking for. We're |
| 1306 | // done. |
| 1307 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1308 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1309 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1310 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1311 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1312 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1313 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1314 | } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1315 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1316 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1317 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1319 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1320 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1321 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1323 | bool IsPublic = Record[3]; |
| 1324 | unsigned NextIndex = 4; |
| 1325 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1326 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1327 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1328 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1329 | bool isC99VarArgs = Record[NextIndex++]; |
| 1330 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1331 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1332 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1333 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1334 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1335 | |
| 1336 | // Install function-like macro info. |
| 1337 | MI->setIsFunctionLike(); |
| 1338 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1339 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1340 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1341 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | // Finally, install the macro. |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1345 | PP.setMacroInfo(II, MI, /*LoadedFromAST=*/true); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | |
| 1347 | // Remember that we saw this macro last so that we add the tokens that |
| 1348 | // form its body to it. |
| 1349 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1350 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1351 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1352 | Record[NextIndex]) { |
| 1353 | // We have a macro definition. Register the association |
| 1354 | PreprocessedEntityID |
| 1355 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1356 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1357 | PPRec.RegisterMacroDefinition(Macro, |
| 1358 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1359 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1360 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1361 | ++NumMacrosRead; |
| 1362 | break; |
| 1363 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1365 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1366 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1367 | // erroneous, just pretend we didn't see this. |
| 1368 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1369 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1370 | Token Tok; |
| 1371 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1372 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1373 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1374 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1375 | Tok.setIdentifierInfo(II); |
| 1376 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1377 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1378 | Macro->AddTokenToBody(Tok); |
| 1379 | break; |
| 1380 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 1381 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1382 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1385 | PreprocessedEntityID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1386 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1387 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1388 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1389 | assert(I != M.PreprocessedEntityRemap.end() |
| 1390 | && "Invalid index into preprocessed entity index remap"); |
| 1391 | |
| 1392 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1395 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1396 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1397 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1398 | |
| 1399 | HeaderFileInfoTrait::internal_key_type |
| 1400 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1401 | |
| 1402 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1403 | if (strcmp(a, b) == 0) |
| 1404 | return true; |
| 1405 | |
| 1406 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1407 | return false; |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1408 | |
| 1409 | // Determine whether the actual files are equivalent. |
| 1410 | bool Result = false; |
| 1411 | if (llvm::sys::fs::equivalent(a, b, Result)) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1412 | return false; |
| 1413 | |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1414 | return Result; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | std::pair<unsigned, unsigned> |
| 1418 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1419 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1420 | unsigned DataLen = (unsigned) *d++; |
| 1421 | return std::make_pair(KeyLen + 1, DataLen); |
| 1422 | } |
| 1423 | |
| 1424 | HeaderFileInfoTrait::data_type |
| 1425 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1426 | unsigned DataLen) { |
| 1427 | const unsigned char *End = d + DataLen; |
| 1428 | using namespace clang::io; |
| 1429 | HeaderFileInfo HFI; |
| 1430 | unsigned Flags = *d++; |
| 1431 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1432 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1433 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1434 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1435 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1436 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1437 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1438 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1439 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1440 | // The framework offset is 1 greater than the actual offset, |
| 1441 | // since 0 is used as an indicator for "no framework name". |
| 1442 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1443 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1444 | } |
| 1445 | |
| 1446 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1447 | (void)End; |
| 1448 | |
| 1449 | // This HeaderFileInfo was externally loaded. |
| 1450 | HFI.External = true; |
| 1451 | return HFI; |
| 1452 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1453 | |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 1454 | void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F, |
| 1455 | uint64_t LocalOffset, bool Visible) { |
| 1456 | if (Visible) { |
| 1457 | // Note that this identifier has a macro definition. |
| 1458 | II->setHasMacroDefinition(true); |
| 1459 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1460 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1461 | // Adjust the offset to a global offset. |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1462 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1465 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1466 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1467 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1468 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1469 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1470 | // If there was no preprocessor block, skip this file. |
| 1471 | if (!MacroCursor.getBitStreamReader()) |
| 1472 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1473 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1474 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1475 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1476 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1477 | RecordData Record; |
| 1478 | while (true) { |
| 1479 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1480 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1481 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1482 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1483 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1484 | // No known subblocks, always skip them. |
| 1485 | Cursor.ReadSubBlockID(); |
| 1486 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1487 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1488 | return; |
| 1489 | } |
| 1490 | continue; |
| 1491 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1492 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1493 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1494 | Cursor.ReadAbbrevRecord(); |
| 1495 | continue; |
| 1496 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1497 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1498 | // Read a record. |
| 1499 | const char *BlobStart; |
| 1500 | unsigned BlobLen; |
| 1501 | Record.clear(); |
| 1502 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1503 | default: // Default behavior: ignore. |
| 1504 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1505 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1506 | case PP_MACRO_OBJECT_LIKE: |
| 1507 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1508 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1509 | break; |
| 1510 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1511 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1512 | // Ignore tokens. |
| 1513 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1514 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1515 | } |
| 1516 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1517 | |
| 1518 | // Drain the unread macro-record offsets map. |
| 1519 | while (!UnreadMacroRecordOffsets.empty()) |
| 1520 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1521 | } |
| 1522 | |
| 1523 | void ASTReader::LoadMacroDefinition( |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1524 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1525 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1526 | uint64_t Offset = Pos->second; |
| 1527 | UnreadMacroRecordOffsets.erase(Pos); |
| 1528 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1529 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1530 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1534 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1535 | = UnreadMacroRecordOffsets.find(II); |
| 1536 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1539 | namespace { |
| 1540 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1541 | class IdentifierLookupVisitor { |
| 1542 | StringRef Name; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1543 | unsigned PriorGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1544 | IdentifierInfo *Found; |
| 1545 | public: |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1546 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration) |
| 1547 | : Name(Name), PriorGeneration(PriorGeneration), Found() { } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1548 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1549 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1550 | IdentifierLookupVisitor *This |
| 1551 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1552 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1553 | // If we've already searched this module file, skip it now. |
| 1554 | if (M.Generation <= This->PriorGeneration) |
| 1555 | return true; |
| 1556 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1557 | ASTIdentifierLookupTable *IdTable |
| 1558 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1559 | if (!IdTable) |
| 1560 | return false; |
| 1561 | |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1562 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1563 | M, This->Found); |
| 1564 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1565 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1566 | This->Name.size()); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1567 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1568 | if (Pos == IdTable->end()) |
| 1569 | return false; |
| 1570 | |
| 1571 | // Dereferencing the iterator has the effect of building the |
| 1572 | // IdentifierInfo node and populating it with the various |
| 1573 | // declarations it needs. |
| 1574 | This->Found = *Pos; |
| 1575 | return true; |
| 1576 | } |
| 1577 | |
| 1578 | // \brief Retrieve the identifier info found within the module |
| 1579 | // files. |
| 1580 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1581 | }; |
| 1582 | } |
| 1583 | |
| 1584 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1585 | unsigned PriorGeneration = 0; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1586 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1587 | PriorGeneration = IdentifierGeneration[&II]; |
| 1588 | |
| 1589 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration); |
| 1590 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 1591 | markIdentifierUpToDate(&II); |
| 1592 | } |
| 1593 | |
| 1594 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1595 | if (!II) |
| 1596 | return; |
| 1597 | |
| 1598 | II->setOutOfDate(false); |
| 1599 | |
| 1600 | // Update the generation for this identifier. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1601 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1602 | IdentifierGeneration[II] = CurrentGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1605 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1606 | std::string Filename = filenameStrRef; |
| 1607 | MaybeAddSystemRootToFilename(Filename); |
| 1608 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1609 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1610 | OriginalDir != CurrentDir) { |
| 1611 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1612 | OriginalDir, |
| 1613 | CurrentDir); |
| 1614 | if (!resolved.empty()) |
| 1615 | File = FileMgr.getFile(resolved); |
| 1616 | } |
| 1617 | |
| 1618 | return File; |
| 1619 | } |
| 1620 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1621 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1622 | /// not an absolute path, add the system root to the beginning of the file |
| 1623 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1624 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1625 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1626 | if (!RelocatablePCH) |
| 1627 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1628 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1629 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1630 | return; |
| 1631 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1632 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1633 | // If no system root was given, default to '/' |
| 1634 | Filename.insert(Filename.begin(), '/'); |
| 1635 | return; |
| 1636 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1637 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1638 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1639 | if (isysroot[Length - 1] != '/') |
| 1640 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1641 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1642 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1645 | ASTReader::ASTReadResult |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1646 | ASTReader::ReadASTBlock(ModuleFile &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1647 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1648 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1649 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1650 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1651 | return Failure; |
| 1652 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1653 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1654 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1655 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1656 | while (!Stream.AtEndOfStream()) { |
| 1657 | unsigned Code = Stream.ReadCode(); |
| 1658 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1659 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1660 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1661 | return Failure; |
| 1662 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1663 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1664 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1668 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1669 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1670 | // We lazily load the decls block, but we want to set up the |
| 1671 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1672 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1673 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1674 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1675 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1676 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1677 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1678 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1679 | return Failure; |
| 1680 | } |
| 1681 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1683 | case DECL_UPDATES_BLOCK_ID: |
| 1684 | if (Stream.SkipBlock()) { |
| 1685 | Error("malformed block record in AST file"); |
| 1686 | return Failure; |
| 1687 | } |
| 1688 | break; |
| 1689 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1690 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1691 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1692 | if (!PP.getExternalSource()) |
| 1693 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1694 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1695 | if (Stream.SkipBlock() || |
| 1696 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1697 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1698 | return Failure; |
| 1699 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1700 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1701 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1702 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1703 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1704 | F.PreprocessorDetailCursor = Stream; |
| 1705 | if (Stream.SkipBlock() || |
| 1706 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1707 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1708 | Error("malformed preprocessor detail record in AST file"); |
| 1709 | return Failure; |
| 1710 | } |
| 1711 | F.PreprocessorDetailStartOffset |
| 1712 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1713 | |
| 1714 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 1715 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1716 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1717 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1718 | break; |
| 1719 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1720 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1721 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1722 | case Success: |
| 1723 | break; |
| 1724 | |
| 1725 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1726 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1727 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1728 | |
| 1729 | case IgnorePCH: |
| 1730 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1731 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1732 | break; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1733 | |
| 1734 | case SUBMODULE_BLOCK_ID: |
| 1735 | switch (ReadSubmoduleBlock(F)) { |
| 1736 | case Success: |
| 1737 | break; |
| 1738 | |
| 1739 | case Failure: |
| 1740 | Error("malformed submodule block in AST file"); |
| 1741 | return Failure; |
| 1742 | |
| 1743 | case IgnorePCH: |
| 1744 | return IgnorePCH; |
| 1745 | } |
| 1746 | break; |
| 1747 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1748 | case COMMENTS_BLOCK_ID: { |
| 1749 | llvm::BitstreamCursor C = Stream; |
| 1750 | if (Stream.SkipBlock() || |
| 1751 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 1752 | Error("malformed comments block in AST file"); |
| 1753 | return Failure; |
| 1754 | } |
| 1755 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 1756 | break; |
| 1757 | } |
| 1758 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1759 | default: |
| 1760 | if (!Stream.SkipBlock()) |
| 1761 | break; |
| 1762 | Error("malformed block record in AST file"); |
| 1763 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1764 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1765 | continue; |
| 1766 | } |
| 1767 | |
| 1768 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1769 | Stream.ReadAbbrevRecord(); |
| 1770 | continue; |
| 1771 | } |
| 1772 | |
| 1773 | // Read and process a record. |
| 1774 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1775 | const char *BlobStart = 0; |
| 1776 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1777 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1778 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1779 | default: // Default behavior: ignore. |
| 1780 | break; |
| 1781 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1782 | case METADATA: { |
| 1783 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1784 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1785 | : diag::warn_pch_version_too_new); |
| 1786 | return IgnorePCH; |
| 1787 | } |
| 1788 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1789 | bool hasErrors = Record[5]; |
| 1790 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 1791 | Diag(diag::err_pch_with_compiler_errors); |
| 1792 | return IgnorePCH; |
| 1793 | } |
| 1794 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1795 | RelocatablePCH = Record[4]; |
| 1796 | if (Listener) { |
| 1797 | std::string TargetTriple(BlobStart, BlobLen); |
| 1798 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1799 | return IgnorePCH; |
| 1800 | } |
| 1801 | break; |
| 1802 | } |
| 1803 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1804 | case IMPORTS: { |
| 1805 | // Load each of the imported PCH files. |
| 1806 | unsigned Idx = 0, N = Record.size(); |
| 1807 | while (Idx < N) { |
| 1808 | // Read information about the AST file. |
| 1809 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1810 | unsigned Length = Record[Idx++]; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1811 | SmallString<128> ImportedFile(Record.begin() + Idx, |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1812 | Record.begin() + Idx + Length); |
| 1813 | Idx += Length; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1814 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1815 | // Load the AST file. |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1816 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1817 | case Failure: return Failure; |
| 1818 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1819 | case IgnorePCH: return IgnorePCH; |
| 1820 | case Success: break; |
| 1821 | } |
| 1822 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1823 | break; |
| 1824 | } |
| 1825 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1826 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1827 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1828 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1829 | return Failure; |
| 1830 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1831 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1832 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1833 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1834 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1835 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1836 | if (F.LocalNumTypes > 0) { |
| 1837 | // Introduce the global -> local mapping for types within this module. |
| 1838 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1839 | |
| 1840 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1841 | F.TypeRemap.insertOrReplace( |
| 1842 | std::make_pair(LocalBaseTypeIndex, |
| 1843 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1844 | |
| 1845 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1846 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1847 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1850 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1851 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1852 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1853 | return Failure; |
| 1854 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 1855 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1856 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1857 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1858 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1859 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1860 | if (F.LocalNumDecls > 0) { |
| 1861 | // Introduce the global -> local mapping for declarations within this |
| 1862 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1863 | GlobalDeclMap.insert( |
| 1864 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1865 | |
| 1866 | // Introduce the local -> global mapping for declarations within this |
| 1867 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1868 | F.DeclRemap.insertOrReplace( |
| 1869 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1870 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 1871 | // Introduce the global -> local mapping for declarations within this |
| 1872 | // module. |
| 1873 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 1874 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1875 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1876 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1877 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1880 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1881 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1882 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1883 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1884 | Info.NumLexicalDecls |
| 1885 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1886 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1887 | break; |
| 1888 | } |
| 1889 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1890 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1891 | unsigned Idx = 0; |
| 1892 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 1893 | ASTDeclContextNameLookupTable *Table = |
| 1894 | ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1895 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1896 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1897 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1898 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1899 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1900 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1901 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1902 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1903 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1904 | break; |
| 1905 | } |
| 1906 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1907 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1908 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1909 | return IgnorePCH; |
| 1910 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1911 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1912 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1913 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1914 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1915 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1916 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1917 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1918 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1919 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1920 | |
| 1921 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1922 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1925 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1926 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1927 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1928 | return Failure; |
| 1929 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1930 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1931 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1932 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1933 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 1934 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1935 | if (F.LocalNumIdentifiers > 0) { |
| 1936 | // Introduce the global -> local mapping for identifiers within this |
| 1937 | // module. |
| 1938 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 1939 | &F)); |
| 1940 | |
| 1941 | // Introduce the local -> global mapping for identifiers within this |
| 1942 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1943 | F.IdentifierRemap.insertOrReplace( |
| 1944 | std::make_pair(LocalBaseIdentifierID, |
| 1945 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1946 | |
| 1947 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 1948 | + F.LocalNumIdentifiers); |
| 1949 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1950 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1953 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1954 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1955 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1956 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1957 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1958 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1959 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1960 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1963 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1964 | TotalNumStatements += Record[0]; |
| 1965 | TotalNumMacros += Record[1]; |
| 1966 | TotalLexicalDeclContexts += Record[2]; |
| 1967 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1968 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1969 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1970 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1971 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1972 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1973 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1974 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1975 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1976 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1977 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1978 | break; |
| 1979 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1980 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 1981 | if (Record.size() % 4 != 0) { |
| 1982 | Error("invalid weak identifiers record"); |
| 1983 | return Failure; |
| 1984 | } |
| 1985 | |
| 1986 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 1987 | // files. This isn't the way to do it :) |
| 1988 | WeakUndeclaredIdentifiers.clear(); |
| 1989 | |
| 1990 | // Translate the weak, undeclared identifiers into global IDs. |
| 1991 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 1992 | WeakUndeclaredIdentifiers.push_back( |
| 1993 | getGlobalIdentifierID(F, Record[I++])); |
| 1994 | WeakUndeclaredIdentifiers.push_back( |
| 1995 | getGlobalIdentifierID(F, Record[I++])); |
| 1996 | WeakUndeclaredIdentifiers.push_back( |
| 1997 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 1998 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 1999 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2000 | break; |
| 2001 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2002 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2003 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2004 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2005 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2006 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2007 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2008 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2009 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2010 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2011 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2012 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2013 | if (F.LocalNumSelectors > 0) { |
| 2014 | // Introduce the global -> local mapping for selectors within this |
| 2015 | // module. |
| 2016 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2017 | |
| 2018 | // Introduce the local -> global mapping for selectors within this |
| 2019 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2020 | F.SelectorRemap.insertOrReplace( |
| 2021 | std::make_pair(LocalBaseSelectorID, |
| 2022 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2023 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2024 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2029 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2030 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2031 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2032 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2033 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2034 | F.SelectorLookupTableData + Record[0], |
| 2035 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2036 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2037 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2038 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2039 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2040 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2041 | if (!Record.empty()) { |
| 2042 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2043 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2044 | Record[Idx++])); |
| 2045 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2046 | getRawEncoding()); |
| 2047 | } |
| 2048 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2051 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2052 | if (!Record.empty() && Listener) |
| 2053 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2054 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2055 | |
| 2056 | case FILE_SORTED_DECLS: |
| 2057 | F.FileSortedDecls = (const DeclID *)BlobStart; |
| 2058 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2059 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2060 | case SOURCE_LOCATION_OFFSETS: { |
| 2061 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2062 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2063 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2064 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2065 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2066 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2067 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2068 | // we invert it. Because we invert it, though, we need the other end of |
| 2069 | // the range. |
| 2070 | unsigned RangeStart = |
| 2071 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2072 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2073 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2074 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2075 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2076 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2077 | GlobalSLocOffsetMap.insert( |
| 2078 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2079 | - SLocSpaceSize,&F)); |
| 2080 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2081 | // Initialize the remapping table. |
| 2082 | // Invalid stays invalid. |
| 2083 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2084 | // This module. Base was 2 when being compiled. |
| 2085 | F.SLocRemap.insert(std::make_pair(2U, |
| 2086 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2087 | |
| 2088 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | } |
| 2091 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2092 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2093 | // Additional remapping information. |
| 2094 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2095 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2096 | |
| 2097 | // Continuous range maps we may be updating in our module. |
| 2098 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2099 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2100 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2101 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2102 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2103 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2104 | SubmoduleRemap(F.SubmoduleRemap); |
| 2105 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2106 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2107 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2108 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2109 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2110 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2111 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2112 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2113 | Data += Len; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2114 | ModuleFile *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2115 | if (!OM) { |
| 2116 | Error("SourceLocation remap refers to unknown module"); |
| 2117 | return Failure; |
| 2118 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2119 | |
| 2120 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2121 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2122 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2123 | uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2124 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2125 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2126 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2127 | |
| 2128 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2129 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2130 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2131 | IdentifierRemap.insert( |
| 2132 | std::make_pair(IdentifierIDOffset, |
| 2133 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2134 | PreprocessedEntityRemap.insert( |
| 2135 | std::make_pair(PreprocessedEntityIDOffset, |
| 2136 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2137 | SubmoduleRemap.insert(std::make_pair(SubmoduleIDOffset, |
| 2138 | OM->BaseSubmoduleID - SubmoduleIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2139 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2140 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2141 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2142 | OM->BaseDeclID - DeclIDOffset)); |
| 2143 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2144 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2145 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2146 | |
| 2147 | // Global -> local mappings. |
| 2148 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2149 | } |
| 2150 | break; |
| 2151 | } |
| 2152 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2153 | case SOURCE_MANAGER_LINE_TABLE: |
| 2154 | if (ParseLineTable(F, Record)) |
| 2155 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2158 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2159 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2160 | F.LocalNumSLocFileEntries = Record[0]; |
| 2161 | break; |
| 2162 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2163 | case SOURCE_LOCATION_PRELOADS: { |
| 2164 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2165 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2166 | if (!F.PreloadSLocEntries.empty()) { |
| 2167 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2168 | return Failure; |
| 2169 | } |
| 2170 | |
| 2171 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2172 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2173 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2174 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2175 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2176 | if (!DisableStatCache) { |
| 2177 | ASTStatCache *MyStatCache = |
| 2178 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2179 | (const unsigned char *)BlobStart, |
| 2180 | NumStatHits, NumStatMisses); |
| 2181 | FileMgr.addStatCache(MyStatCache); |
| 2182 | F.StatCache = MyStatCache; |
| 2183 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2184 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2185 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2186 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2187 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2188 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2189 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2190 | break; |
| 2191 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2192 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2193 | if (Record.size() % 3 != 0) { |
| 2194 | Error("Invalid VTABLE_USES record"); |
| 2195 | return Failure; |
| 2196 | } |
| 2197 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2198 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2199 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2200 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2201 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2202 | |
| 2203 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2204 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2205 | VTableUses.push_back( |
| 2206 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2207 | VTableUses.push_back(Record[Idx++]); |
| 2208 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2209 | break; |
| 2210 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2211 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2212 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2213 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2214 | break; |
| 2215 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2216 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2217 | if (PendingInstantiations.size() % 2 != 0) { |
| 2218 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2219 | return Failure; |
| 2220 | } |
| 2221 | |
| 2222 | // Later lists of pending instantiations overwrite earlier ones. |
| 2223 | // FIXME: This is most certainly wrong for modules. |
| 2224 | PendingInstantiations.clear(); |
| 2225 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2226 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2227 | PendingInstantiations.push_back( |
| 2228 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2229 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2230 | break; |
| 2231 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2232 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2233 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2234 | // FIXME: Modules will have some trouble with this. |
| 2235 | SemaDeclRefs.clear(); |
| 2236 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2237 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2238 | break; |
| 2239 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2240 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2241 | // The primary AST will be the last to get here, so it will be the one |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2242 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2243 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2244 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2245 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2246 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2247 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2248 | case ORIGINAL_FILE_ID: |
| 2249 | OriginalFileID = FileID::get(Record[0]); |
| 2250 | break; |
| 2251 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2252 | case ORIGINAL_PCH_DIR: |
| 2253 | // The primary AST will be the last to get here, so it will be the one |
| 2254 | // that's used. |
| 2255 | OriginalDir.assign(BlobStart, BlobLen); |
| 2256 | break; |
| 2257 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2258 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2259 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2260 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2261 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2262 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2263 | return IgnorePCH; |
| 2264 | } |
| 2265 | break; |
| 2266 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2267 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2268 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2269 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2270 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2271 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2272 | |
| 2273 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2275 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2276 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2277 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2278 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2279 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2280 | StartingID |
| 2281 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2282 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2283 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2284 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2285 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2286 | // Introduce the global -> local mapping for preprocessed entities in |
| 2287 | // this module. |
| 2288 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2289 | |
| 2290 | // Introduce the local -> global mapping for preprocessed entities in |
| 2291 | // this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2292 | F.PreprocessedEntityRemap.insertOrReplace( |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2293 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2294 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2295 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2296 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2297 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2300 | case DECL_UPDATE_OFFSETS: { |
| 2301 | if (Record.size() % 2 != 0) { |
| 2302 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2303 | return Failure; |
| 2304 | } |
| 2305 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2306 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2307 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2308 | break; |
| 2309 | } |
| 2310 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2311 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2312 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2313 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2314 | return Failure; |
| 2315 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2316 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2317 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2318 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2319 | break; |
| 2320 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2321 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2322 | case OBJC_CATEGORIES_MAP: { |
| 2323 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2324 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2325 | return Failure; |
| 2326 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2327 | |
| 2328 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 2329 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2330 | break; |
| 2331 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2332 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2333 | case OBJC_CATEGORIES: |
| 2334 | F.ObjCCategories.swap(Record); |
| 2335 | break; |
| 2336 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2337 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2338 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2339 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2340 | return Failure; |
| 2341 | } |
| 2342 | |
| 2343 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2344 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2345 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2346 | break; |
| 2347 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2348 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2349 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2350 | if (Record.size() % 2 != 0) { |
| 2351 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2352 | return Failure; |
| 2353 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2354 | |
| 2355 | if (F.PragmaDiagMappings.empty()) |
| 2356 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2357 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2358 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2359 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2360 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2361 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2362 | case CUDA_SPECIAL_DECL_REFS: |
| 2363 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2364 | // FIXME: Modules will have trouble with this. |
| 2365 | CUDASpecialDeclRefs.clear(); |
| 2366 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2367 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2368 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2369 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2370 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2371 | F.HeaderFileInfoTableData = BlobStart; |
| 2372 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2373 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2374 | if (Record[0]) { |
| 2375 | F.HeaderFileInfoTable |
| 2376 | = HeaderFileInfoLookupTable::Create( |
| 2377 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2378 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2379 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2380 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2381 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2382 | |
| 2383 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2384 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2385 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2386 | } |
| 2387 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2390 | case FP_PRAGMA_OPTIONS: |
| 2391 | // Later tables overwrite earlier ones. |
| 2392 | FPPragmaOptions.swap(Record); |
| 2393 | break; |
| 2394 | |
| 2395 | case OPENCL_EXTENSIONS: |
| 2396 | // Later tables overwrite earlier ones. |
| 2397 | OpenCLExtensions.swap(Record); |
| 2398 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2399 | |
| 2400 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2401 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2402 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2403 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2404 | |
| 2405 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2406 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2407 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2408 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2409 | |
| 2410 | case IMPORTED_MODULES: { |
| 2411 | if (F.Kind != MK_Module) { |
| 2412 | // If we aren't loading a module (which has its own exports), make |
| 2413 | // all of the imported modules visible. |
| 2414 | // FIXME: Deal with macros-only imports. |
| 2415 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2416 | if (unsigned GlobalID = getGlobalSubmoduleID(F, Record[I])) |
| 2417 | ImportedModules.push_back(GlobalID); |
| 2418 | } |
| 2419 | } |
| 2420 | break; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2421 | } |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2422 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2423 | case LOCAL_REDECLARATIONS: { |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2424 | F.RedeclarationChains.swap(Record); |
| 2425 | break; |
| 2426 | } |
| 2427 | |
| 2428 | case LOCAL_REDECLARATIONS_MAP: { |
| 2429 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 2430 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2431 | return Failure; |
| 2432 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2433 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2434 | F.LocalNumRedeclarationsInMap = Record[0]; |
| 2435 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2436 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2437 | } |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 2438 | |
| 2439 | case MERGED_DECLARATIONS: { |
| 2440 | for (unsigned Idx = 0; Idx < Record.size(); /* increment in loop */) { |
| 2441 | GlobalDeclID CanonID = getGlobalDeclID(F, Record[Idx++]); |
| 2442 | SmallVectorImpl<GlobalDeclID> &Decls = StoredMergedDecls[CanonID]; |
| 2443 | for (unsigned N = Record[Idx++]; N > 0; --N) |
| 2444 | Decls.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2445 | } |
| 2446 | break; |
| 2447 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2448 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2449 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2450 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2451 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2454 | ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2455 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2456 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2457 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2458 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2459 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2460 | if (Code == llvm::bitc::END_BLOCK || |
| 2461 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2462 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2463 | Error("incorrectly-formatted source location entry in AST file"); |
| 2464 | return Failure; |
| 2465 | } |
| 2466 | |
| 2467 | RecordData Record; |
| 2468 | const char *BlobStart; |
| 2469 | unsigned BlobLen; |
| 2470 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2471 | default: |
| 2472 | Error("incorrectly-formatted source location entry in AST file"); |
| 2473 | return Failure; |
| 2474 | |
| 2475 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2476 | // If the buffer was overridden, the file need not exist. |
| 2477 | if (Record[6]) |
| 2478 | break; |
| 2479 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2480 | StringRef Filename(BlobStart, BlobLen); |
| 2481 | const FileEntry *File = getFileEntry(Filename); |
| 2482 | |
| 2483 | if (File == 0) { |
| 2484 | std::string ErrorStr = "could not find file '"; |
| 2485 | ErrorStr += Filename; |
| 2486 | ErrorStr += "' referenced by AST file"; |
| 2487 | Error(ErrorStr.c_str()); |
| 2488 | return IgnorePCH; |
| 2489 | } |
| 2490 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2491 | if (Record.size() < 7) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2492 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2493 | return Failure; |
| 2494 | } |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2495 | |
| 2496 | off_t StoredSize = (off_t)Record[4]; |
| 2497 | time_t StoredTime = (time_t)Record[5]; |
| 2498 | |
| 2499 | // Check if there was a request to override the contents of the file |
| 2500 | // that was part of the precompiled header. Overridding such a file |
| 2501 | // can lead to problems when lexing using the source locations from the |
| 2502 | // PCH. |
| 2503 | SourceManager &SM = getSourceManager(); |
| 2504 | if (SM.isFileOverridden(File)) { |
| 2505 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2506 | // After emitting the diagnostic, recover by disabling the override so |
| 2507 | // that the original file will be used. |
| 2508 | SM.disableFileContentsOverride(File); |
| 2509 | // The FileEntry is a virtual file entry with the size of the contents |
| 2510 | // that would override the original contents. Set it to the original's |
| 2511 | // size/time. |
| 2512 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2513 | StoredSize, StoredTime); |
| 2514 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2515 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2516 | // The stat info from the FileEntry came from the cached stat |
| 2517 | // info of the PCH, so we cannot trust it. |
| 2518 | struct stat StatBuf; |
| 2519 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2520 | StatBuf.st_size = File->getSize(); |
| 2521 | StatBuf.st_mtime = File->getModificationTime(); |
| 2522 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2523 | |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2524 | if ((StoredSize != StatBuf.st_size |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2525 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2526 | // In our regression testing, the Windows file system seems to |
| 2527 | // have inconsistent modification times that sometimes |
| 2528 | // erroneously trigger this error-handling path. |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2529 | || StoredTime != StatBuf.st_mtime |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2530 | #endif |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2531 | )) { |
| 2532 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2533 | return IgnorePCH; |
| 2534 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2535 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2536 | break; |
| 2537 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2538 | } |
| 2539 | } |
| 2540 | |
| 2541 | return Success; |
| 2542 | } |
| 2543 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2544 | void ASTReader::makeNamesVisible(const HiddenNames &Names) { |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2545 | for (unsigned I = 0, N = Names.size(); I != N; ++I) { |
| 2546 | if (Decl *D = Names[I].dyn_cast<Decl *>()) |
Douglas Gregor | f143ffc | 2012-01-06 16:22:39 +0000 | [diff] [blame] | 2547 | D->Hidden = false; |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2548 | else { |
| 2549 | IdentifierInfo *II = Names[I].get<IdentifierInfo *>(); |
| 2550 | if (!II->hasMacroDefinition()) { |
| 2551 | II->setHasMacroDefinition(true); |
| 2552 | if (DeserializationListener) |
| 2553 | DeserializationListener->MacroVisible(II); |
| 2554 | } |
| 2555 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2556 | } |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2559 | void ASTReader::makeModuleVisible(Module *Mod, |
| 2560 | Module::NameVisibilityKind NameVisibility) { |
| 2561 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 2562 | llvm::SmallVector<Module *, 4> Stack; |
| 2563 | Stack.push_back(Mod); |
| 2564 | while (!Stack.empty()) { |
| 2565 | Mod = Stack.back(); |
| 2566 | Stack.pop_back(); |
| 2567 | |
| 2568 | if (NameVisibility <= Mod->NameVisibility) { |
| 2569 | // This module already has this level of visibility (or greater), so |
| 2570 | // there is nothing more to do. |
| 2571 | continue; |
| 2572 | } |
| 2573 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2574 | if (!Mod->isAvailable()) { |
| 2575 | // Modules that aren't available cannot be made visible. |
| 2576 | continue; |
| 2577 | } |
| 2578 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2579 | // Update the module's name visibility. |
| 2580 | Mod->NameVisibility = NameVisibility; |
| 2581 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2582 | // If we've already deserialized any names from this module, |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2583 | // mark them as visible. |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2584 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 2585 | if (Hidden != HiddenNamesMap.end()) { |
| 2586 | makeNamesVisible(Hidden->second); |
| 2587 | HiddenNamesMap.erase(Hidden); |
| 2588 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2589 | |
| 2590 | // Push any non-explicit submodules onto the stack to be marked as |
| 2591 | // visible. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2592 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2593 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2594 | Sub != SubEnd; ++Sub) { |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2595 | if (!(*Sub)->IsExplicit && Visited.insert(*Sub)) |
| 2596 | Stack.push_back(*Sub); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2597 | } |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2598 | |
| 2599 | // Push any exported modules onto the stack to be marked as visible. |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2600 | bool AnyWildcard = false; |
| 2601 | bool UnrestrictedWildcard = false; |
| 2602 | llvm::SmallVector<Module *, 4> WildcardRestrictions; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2603 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
| 2604 | Module *Exported = Mod->Exports[I].getPointer(); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2605 | if (!Mod->Exports[I].getInt()) { |
| 2606 | // Export a named module directly; no wildcards involved. |
| 2607 | if (Visited.insert(Exported)) |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2608 | Stack.push_back(Exported); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2609 | |
| 2610 | continue; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2611 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2612 | |
| 2613 | // Wildcard export: export all of the imported modules that match |
| 2614 | // the given pattern. |
| 2615 | AnyWildcard = true; |
| 2616 | if (UnrestrictedWildcard) |
| 2617 | continue; |
| 2618 | |
| 2619 | if (Module *Restriction = Mod->Exports[I].getPointer()) |
| 2620 | WildcardRestrictions.push_back(Restriction); |
| 2621 | else { |
| 2622 | WildcardRestrictions.clear(); |
| 2623 | UnrestrictedWildcard = true; |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | // If there were any wildcards, push any imported modules that were |
| 2628 | // re-exported by the wildcard restriction. |
| 2629 | if (!AnyWildcard) |
| 2630 | continue; |
| 2631 | |
| 2632 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
| 2633 | Module *Imported = Mod->Imports[I]; |
Benjamin Kramer | d48bcb2 | 2012-08-22 15:37:55 +0000 | [diff] [blame^] | 2634 | if (!Visited.insert(Imported)) |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2635 | continue; |
| 2636 | |
| 2637 | bool Acceptable = UnrestrictedWildcard; |
| 2638 | if (!Acceptable) { |
| 2639 | // Check whether this module meets one of the restrictions. |
| 2640 | for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { |
| 2641 | Module *Restriction = WildcardRestrictions[R]; |
| 2642 | if (Imported == Restriction || Imported->isSubModuleOf(Restriction)) { |
| 2643 | Acceptable = true; |
| 2644 | break; |
| 2645 | } |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | if (!Acceptable) |
| 2650 | continue; |
| 2651 | |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2652 | Stack.push_back(Imported); |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2653 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2654 | } |
| 2655 | } |
| 2656 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2657 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2658 | ModuleKind Type) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2659 | // Bump the generation number. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2660 | unsigned PreviousGeneration = CurrentGeneration++; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2661 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2662 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2663 | case Failure: return Failure; |
| 2664 | case IgnorePCH: return IgnorePCH; |
| 2665 | case Success: break; |
| 2666 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2667 | |
| 2668 | // Here comes stuff that we only do once the entire chain is loaded. |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2669 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2670 | // Check the predefines buffers. |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 2671 | if (!DisableValidation && Type == MK_PCH && |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 2672 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2673 | // if DisableValidation is true, defines that were set on command-line |
| 2674 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2675 | CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2676 | return IgnorePCH; |
| 2677 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2678 | // Mark all of the identifiers in the identifier table as being out of date, |
| 2679 | // so that various accessors know to check the loaded modules when the |
| 2680 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2681 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2682 | IdEnd = PP.getIdentifierTable().end(); |
| 2683 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2684 | Id->second->setOutOfDate(true); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2685 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2686 | // Resolve any unresolved module exports. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2687 | for (unsigned I = 0, N = UnresolvedModuleImportExports.size(); I != N; ++I) { |
| 2688 | UnresolvedModuleImportExport &Unresolved = UnresolvedModuleImportExports[I]; |
| 2689 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2690 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 2691 | |
| 2692 | if (Unresolved.IsImport) { |
| 2693 | if (ResolvedMod) |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2694 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2695 | continue; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2696 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2697 | |
| 2698 | if (ResolvedMod || Unresolved.IsWildcard) |
| 2699 | Unresolved.Mod->Exports.push_back( |
| 2700 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2701 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2702 | UnresolvedModuleImportExports.clear(); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2703 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2704 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2705 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2706 | if (DeserializationListener) |
| 2707 | DeserializationListener->ReaderInitialized(this); |
| 2708 | |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2709 | if (!OriginalFileID.isInvalid()) { |
| 2710 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
| 2711 | + OriginalFileID.getOpaqueValue() - 1); |
| 2712 | |
| 2713 | // If this AST file is a precompiled preamble, then set the preamble file ID |
| 2714 | // of the source manager to the file source file from which the preamble was |
| 2715 | // built. |
| 2716 | if (Type == MK_Preamble) { |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2717 | SourceMgr.setPreambleFileID(OriginalFileID); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2718 | } else if (Type == MK_MainFile) { |
| 2719 | SourceMgr.setMainFileID(OriginalFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2720 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2721 | } |
| 2722 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2723 | // For any Objective-C class definitions we have already loaded, make sure |
| 2724 | // that we load any additional categories. |
| 2725 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 2726 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 2727 | ObjCClassesLoaded[I], |
| 2728 | PreviousGeneration); |
| 2729 | } |
| 2730 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2731 | return Success; |
| 2732 | } |
| 2733 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2734 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2735 | ModuleKind Type, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2736 | ModuleFile *ImportedBy) { |
| 2737 | ModuleFile *M; |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2738 | bool NewModule; |
| 2739 | std::string ErrorStr; |
| 2740 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2741 | CurrentGeneration, ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2742 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2743 | if (!M) { |
| 2744 | // We couldn't load the module. |
| 2745 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2746 | + ErrorStr; |
| 2747 | Error(Msg); |
| 2748 | return Failure; |
| 2749 | } |
| 2750 | |
| 2751 | if (!NewModule) { |
| 2752 | // We've already loaded this module. |
| 2753 | return Success; |
| 2754 | } |
| 2755 | |
| 2756 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2757 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2758 | if (FileName != "-") { |
| 2759 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2760 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2761 | } |
| 2762 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2763 | ModuleFile &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2764 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2765 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2766 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2767 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2768 | // Sniff for the signature. |
| 2769 | if (Stream.Read(8) != 'C' || |
| 2770 | Stream.Read(8) != 'P' || |
| 2771 | Stream.Read(8) != 'C' || |
| 2772 | Stream.Read(8) != 'H') { |
| 2773 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2774 | return Failure; |
| 2775 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2776 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2777 | while (!Stream.AtEndOfStream()) { |
| 2778 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2779 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2780 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2781 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2782 | return Failure; |
| 2783 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2784 | |
| 2785 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2786 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2787 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2788 | switch (BlockID) { |
| 2789 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2790 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2791 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2792 | return Failure; |
| 2793 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2794 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2795 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2796 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2797 | case Success: |
| 2798 | break; |
| 2799 | |
| 2800 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2801 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2802 | |
| 2803 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2804 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2805 | // AST block, skipping subblocks, to see if there are other |
| 2806 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2808 | // FIXME: We can't clear loaded slocentries anymore. |
| 2809 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2810 | |
| 2811 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2812 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2813 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2814 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2815 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2816 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2817 | break; |
| 2818 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2819 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2820 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2821 | return Failure; |
| 2822 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2823 | break; |
| 2824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2825 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2826 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2827 | // Once read, set the ModuleFile bit base offset and update the size in |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2828 | // bits of all files we've seen. |
| 2829 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2830 | TotalModulesSizeInBits += F.SizeInBits; |
| 2831 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2832 | |
| 2833 | // Make sure that the files this module was built against are still available. |
| 2834 | if (!DisableValidation) { |
| 2835 | switch(validateFileEntries(*M)) { |
| 2836 | case Failure: return Failure; |
| 2837 | case IgnorePCH: return IgnorePCH; |
| 2838 | case Success: break; |
| 2839 | } |
| 2840 | } |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2841 | |
| 2842 | // Preload SLocEntries. |
| 2843 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2844 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Argyrios Kyrtzidis | ac1ffcc | 2011-09-19 20:39:54 +0000 | [diff] [blame] | 2845 | // Load it through the SourceManager and don't call ReadSLocEntryRecord() |
| 2846 | // directly because the entry may have already been loaded in which case |
| 2847 | // calling ReadSLocEntryRecord() directly would trigger an assertion in |
| 2848 | // SourceManager. |
| 2849 | SourceMgr.getLoadedSLocEntryByID(Index); |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2852 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2853 | return Success; |
| 2854 | } |
| 2855 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2856 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2857 | // If there's a listener, notify them that we "read" the translation unit. |
| 2858 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2859 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2860 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2861 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2862 | // Make sure we load the declaration update records for the translation unit, |
| 2863 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2864 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2865 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2866 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2867 | // FIXME: Find a better way to deal with collisions between these |
| 2868 | // built-in types. Right now, we just ignore the problem. |
| 2869 | |
| 2870 | // Load the special types. |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 2871 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2872 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2873 | if (!Context.CFConstantStringTypeDecl) |
| 2874 | Context.setCFConstantStringType(GetType(String)); |
| 2875 | } |
| 2876 | |
| 2877 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2878 | QualType FileType = GetType(File); |
| 2879 | if (FileType.isNull()) { |
| 2880 | Error("FILE type is NULL"); |
| 2881 | return; |
| 2882 | } |
| 2883 | |
| 2884 | if (!Context.FILEDecl) { |
| 2885 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2886 | Context.setFILEDecl(Typedef->getDecl()); |
| 2887 | else { |
| 2888 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2889 | if (!Tag) { |
| 2890 | Error("Invalid FILE type in AST file"); |
| 2891 | return; |
| 2892 | } |
| 2893 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2894 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2895 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2896 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2897 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2898 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2899 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2900 | if (Jmp_bufType.isNull()) { |
| 2901 | Error("jmp_buf type is NULL"); |
| 2902 | return; |
| 2903 | } |
| 2904 | |
| 2905 | if (!Context.jmp_bufDecl) { |
| 2906 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2907 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2908 | else { |
| 2909 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2910 | if (!Tag) { |
| 2911 | Error("Invalid jmp_buf type in AST file"); |
| 2912 | return; |
| 2913 | } |
| 2914 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2915 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2916 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2917 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2918 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2919 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2920 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2921 | if (Sigjmp_bufType.isNull()) { |
| 2922 | Error("sigjmp_buf type is NULL"); |
| 2923 | return; |
| 2924 | } |
| 2925 | |
| 2926 | if (!Context.sigjmp_bufDecl) { |
| 2927 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2928 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2929 | else { |
| 2930 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2931 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2932 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2933 | } |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | if (unsigned ObjCIdRedef |
| 2938 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2939 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2940 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2941 | } |
| 2942 | |
| 2943 | if (unsigned ObjCClassRedef |
| 2944 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2945 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2946 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2947 | } |
| 2948 | |
| 2949 | if (unsigned ObjCSelRedef |
| 2950 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2951 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2952 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2953 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 2954 | |
| 2955 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 2956 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 2957 | if (Ucontext_tType.isNull()) { |
| 2958 | Error("ucontext_t type is NULL"); |
| 2959 | return; |
| 2960 | } |
| 2961 | |
| 2962 | if (!Context.ucontext_tDecl) { |
| 2963 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 2964 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 2965 | else { |
| 2966 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 2967 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 2968 | Context.setucontext_tDecl(Tag->getDecl()); |
| 2969 | } |
| 2970 | } |
| 2971 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2972 | } |
| 2973 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2974 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2975 | |
| 2976 | // If there were any CUDA special declarations, deserialize them. |
| 2977 | if (!CUDASpecialDeclRefs.empty()) { |
| 2978 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2979 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2980 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2981 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2982 | |
| 2983 | // Re-export any modules that were imported by a non-module AST file. |
| 2984 | for (unsigned I = 0, N = ImportedModules.size(); I != N; ++I) { |
| 2985 | if (Module *Imported = getSubmodule(ImportedModules[I])) |
| 2986 | makeModuleVisible(Imported, Module::AllVisible); |
| 2987 | } |
| 2988 | ImportedModules.clear(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2989 | } |
| 2990 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2991 | void ASTReader::finalizeForWriting() { |
| 2992 | for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(), |
| 2993 | HiddenEnd = HiddenNamesMap.end(); |
| 2994 | Hidden != HiddenEnd; ++Hidden) { |
| 2995 | makeNamesVisible(Hidden->second); |
| 2996 | } |
| 2997 | HiddenNamesMap.clear(); |
| 2998 | } |
| 2999 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3000 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3001 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3002 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3003 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3004 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3005 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3006 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3007 | std::string ErrStr; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 3008 | OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3009 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3010 | if (!Buffer) { |
Kaelyn Uhrain | da01f62 | 2012-06-20 00:36:03 +0000 | [diff] [blame] | 3011 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3012 | return std::string(); |
| 3013 | } |
| 3014 | |
| 3015 | // Initialize the stream |
| 3016 | llvm::BitstreamReader StreamFile; |
| 3017 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3019 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3020 | Stream.init(StreamFile); |
| 3021 | |
| 3022 | // Sniff for the signature. |
| 3023 | if (Stream.Read(8) != 'C' || |
| 3024 | Stream.Read(8) != 'P' || |
| 3025 | Stream.Read(8) != 'C' || |
| 3026 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3027 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3028 | return std::string(); |
| 3029 | } |
| 3030 | |
| 3031 | RecordData Record; |
| 3032 | while (!Stream.AtEndOfStream()) { |
| 3033 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3035 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3036 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3037 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3038 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3039 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3040 | case AST_BLOCK_ID: |
| 3041 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3042 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3043 | return std::string(); |
| 3044 | } |
| 3045 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3046 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3047 | default: |
| 3048 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3049 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3050 | return std::string(); |
| 3051 | } |
| 3052 | break; |
| 3053 | } |
| 3054 | continue; |
| 3055 | } |
| 3056 | |
| 3057 | if (Code == llvm::bitc::END_BLOCK) { |
| 3058 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3059 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3060 | return std::string(); |
| 3061 | } |
| 3062 | continue; |
| 3063 | } |
| 3064 | |
| 3065 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3066 | Stream.ReadAbbrevRecord(); |
| 3067 | continue; |
| 3068 | } |
| 3069 | |
| 3070 | Record.clear(); |
| 3071 | const char *BlobStart = 0; |
| 3072 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3073 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3074 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3075 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3076 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3077 | |
| 3078 | return std::string(); |
| 3079 | } |
| 3080 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3081 | ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3082 | // Enter the submodule block. |
| 3083 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 3084 | Error("malformed submodule block record in AST file"); |
| 3085 | return Failure; |
| 3086 | } |
| 3087 | |
| 3088 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3089 | bool First = true; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3090 | Module *CurrentModule = 0; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3091 | RecordData Record; |
| 3092 | while (true) { |
| 3093 | unsigned Code = F.Stream.ReadCode(); |
| 3094 | if (Code == llvm::bitc::END_BLOCK) { |
| 3095 | if (F.Stream.ReadBlockEnd()) { |
| 3096 | Error("error at end of submodule block in AST file"); |
| 3097 | return Failure; |
| 3098 | } |
| 3099 | return Success; |
| 3100 | } |
| 3101 | |
| 3102 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3103 | // No known subblocks, always skip them. |
| 3104 | F.Stream.ReadSubBlockID(); |
| 3105 | if (F.Stream.SkipBlock()) { |
| 3106 | Error("malformed block record in AST file"); |
| 3107 | return Failure; |
| 3108 | } |
| 3109 | continue; |
| 3110 | } |
| 3111 | |
| 3112 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3113 | F.Stream.ReadAbbrevRecord(); |
| 3114 | continue; |
| 3115 | } |
| 3116 | |
| 3117 | // Read a record. |
| 3118 | const char *BlobStart; |
| 3119 | unsigned BlobLen; |
| 3120 | Record.clear(); |
| 3121 | switch (F.Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 3122 | default: // Default behavior: ignore. |
| 3123 | break; |
| 3124 | |
| 3125 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3126 | if (First) { |
| 3127 | Error("missing submodule metadata record at beginning of block"); |
| 3128 | return Failure; |
| 3129 | } |
| 3130 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3131 | if (Record.size() < 7) { |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3132 | Error("malformed module definition"); |
| 3133 | return Failure; |
| 3134 | } |
| 3135 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3136 | StringRef Name(BlobStart, BlobLen); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3137 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); |
| 3138 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); |
| 3139 | bool IsFramework = Record[2]; |
| 3140 | bool IsExplicit = Record[3]; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3141 | bool IsSystem = Record[4]; |
| 3142 | bool InferSubmodules = Record[5]; |
| 3143 | bool InferExplicitSubmodules = Record[6]; |
| 3144 | bool InferExportWildcard = Record[7]; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3145 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3146 | Module *ParentModule = 0; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3147 | if (Parent) |
| 3148 | ParentModule = getSubmodule(Parent); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3149 | |
| 3150 | // Retrieve this (sub)module from the module map, creating it if |
| 3151 | // necessary. |
| 3152 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, |
| 3153 | IsFramework, |
| 3154 | IsExplicit).first; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3155 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 3156 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 3157 | SubmodulesLoaded[GlobalIndex]) { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3158 | Error("too many submodules"); |
| 3159 | return Failure; |
| 3160 | } |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3161 | |
Douglas Gregor | 305dc3e | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 3162 | CurrentModule->IsFromModuleFile = true; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3163 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3164 | CurrentModule->InferSubmodules = InferSubmodules; |
| 3165 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 3166 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3167 | if (DeserializationListener) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3168 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3169 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3170 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3171 | break; |
| 3172 | } |
| 3173 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3174 | case SUBMODULE_UMBRELLA_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3175 | if (First) { |
| 3176 | Error("missing submodule metadata record at beginning of block"); |
| 3177 | return Failure; |
| 3178 | } |
| 3179 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3180 | if (!CurrentModule) |
| 3181 | break; |
| 3182 | |
| 3183 | StringRef FileName(BlobStart, BlobLen); |
| 3184 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) { |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3185 | if (!CurrentModule->getUmbrellaHeader()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3186 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3187 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3188 | Error("mismatched umbrella headers in submodule"); |
| 3189 | return Failure; |
| 3190 | } |
| 3191 | } |
| 3192 | break; |
| 3193 | } |
| 3194 | |
| 3195 | case SUBMODULE_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3196 | if (First) { |
| 3197 | Error("missing submodule metadata record at beginning of block"); |
| 3198 | return Failure; |
| 3199 | } |
| 3200 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3201 | if (!CurrentModule) |
| 3202 | break; |
| 3203 | |
| 3204 | // FIXME: Be more lazy about this! |
| 3205 | StringRef FileName(BlobStart, BlobLen); |
| 3206 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3207 | if (std::find(CurrentModule->Headers.begin(), |
| 3208 | CurrentModule->Headers.end(), |
| 3209 | File) == CurrentModule->Headers.end()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3210 | ModMap.addHeader(CurrentModule, File); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3211 | } |
| 3212 | break; |
| 3213 | } |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3214 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3215 | case SUBMODULE_UMBRELLA_DIR: { |
| 3216 | if (First) { |
| 3217 | Error("missing submodule metadata record at beginning of block"); |
| 3218 | return Failure; |
| 3219 | } |
| 3220 | |
| 3221 | if (!CurrentModule) |
| 3222 | break; |
| 3223 | |
| 3224 | StringRef DirName(BlobStart, BlobLen); |
| 3225 | if (const DirectoryEntry *Umbrella |
| 3226 | = PP.getFileManager().getDirectory(DirName)) { |
| 3227 | if (!CurrentModule->getUmbrellaDir()) |
| 3228 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 3229 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
| 3230 | Error("mismatched umbrella directories in submodule"); |
| 3231 | return Failure; |
| 3232 | } |
| 3233 | } |
| 3234 | break; |
| 3235 | } |
| 3236 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3237 | case SUBMODULE_METADATA: { |
| 3238 | if (!First) { |
| 3239 | Error("submodule metadata record not at beginning of block"); |
| 3240 | return Failure; |
| 3241 | } |
| 3242 | First = false; |
| 3243 | |
| 3244 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3245 | F.LocalNumSubmodules = Record[0]; |
| 3246 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 3247 | if (F.LocalNumSubmodules > 0) { |
| 3248 | // Introduce the global -> local mapping for submodules within this |
| 3249 | // module. |
| 3250 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 3251 | |
| 3252 | // Introduce the local -> global mapping for submodules within this |
| 3253 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 3254 | F.SubmoduleRemap.insertOrReplace( |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3255 | std::make_pair(LocalBaseSubmoduleID, |
| 3256 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 3257 | |
| 3258 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 3259 | } |
| 3260 | break; |
| 3261 | } |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3262 | |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3263 | case SUBMODULE_IMPORTS: { |
| 3264 | if (First) { |
| 3265 | Error("missing submodule metadata record at beginning of block"); |
| 3266 | return Failure; |
| 3267 | } |
| 3268 | |
| 3269 | if (!CurrentModule) |
| 3270 | break; |
| 3271 | |
| 3272 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 3273 | UnresolvedModuleImportExport Unresolved; |
| 3274 | Unresolved.File = &F; |
| 3275 | Unresolved.Mod = CurrentModule; |
| 3276 | Unresolved.ID = Record[Idx]; |
| 3277 | Unresolved.IsImport = true; |
| 3278 | Unresolved.IsWildcard = false; |
| 3279 | UnresolvedModuleImportExports.push_back(Unresolved); |
| 3280 | } |
| 3281 | break; |
| 3282 | } |
| 3283 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3284 | case SUBMODULE_EXPORTS: { |
| 3285 | if (First) { |
| 3286 | Error("missing submodule metadata record at beginning of block"); |
| 3287 | return Failure; |
| 3288 | } |
| 3289 | |
| 3290 | if (!CurrentModule) |
| 3291 | break; |
| 3292 | |
| 3293 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3294 | UnresolvedModuleImportExport Unresolved; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3295 | Unresolved.File = &F; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3296 | Unresolved.Mod = CurrentModule; |
| 3297 | Unresolved.ID = Record[Idx]; |
| 3298 | Unresolved.IsImport = false; |
| 3299 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 3300 | UnresolvedModuleImportExports.push_back(Unresolved); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | // Once we've loaded the set of exports, there's no reason to keep |
| 3304 | // the parsed, unresolved exports around. |
| 3305 | CurrentModule->UnresolvedExports.clear(); |
| 3306 | break; |
| 3307 | } |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3308 | case SUBMODULE_REQUIRES: { |
| 3309 | if (First) { |
| 3310 | Error("missing submodule metadata record at beginning of block"); |
| 3311 | return Failure; |
| 3312 | } |
| 3313 | |
| 3314 | if (!CurrentModule) |
| 3315 | break; |
| 3316 | |
| 3317 | CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3318 | Context.getLangOpts(), |
Douglas Gregor | dc58aa7 | 2012-01-30 06:01:29 +0000 | [diff] [blame] | 3319 | Context.getTargetInfo()); |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3320 | break; |
| 3321 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3322 | } |
| 3323 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3324 | } |
| 3325 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3326 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3327 | /// structure. |
| 3328 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3329 | /// This routine parses the language options from the AST file and then gives |
| 3330 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3331 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3332 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3333 | bool ASTReader::ParseLanguageOptions(const RecordData &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3334 | if (Listener) { |
| 3335 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3336 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3337 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 3338 | LangOpts.Name = Record[Idx++]; |
| 3339 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 3340 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 3341 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3342 | |
| 3343 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 3344 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 3345 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3346 | |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 3347 | unsigned Length = Record[Idx++]; |
| 3348 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 3349 | Record.begin() + Idx + Length); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3350 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3351 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3352 | |
| 3353 | return false; |
| 3354 | } |
| 3355 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3356 | std::pair<ModuleFile *, unsigned> |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3357 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3358 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3359 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3360 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 3361 | "Corrupted global preprocessed entity map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3362 | ModuleFile *M = I->second; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3363 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 3364 | return std::make_pair(M, LocalIndex); |
| 3365 | } |
| 3366 | |
| 3367 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 3368 | PreprocessedEntityID PPID = Index+1; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3369 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3370 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3371 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3372 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3373 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3374 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3375 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3376 | |
| 3377 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 3378 | switch (Code) { |
| 3379 | case llvm::bitc::END_BLOCK: |
| 3380 | return 0; |
| 3381 | |
| 3382 | case llvm::bitc::ENTER_SUBBLOCK: |
| 3383 | Error("unexpected subblock record in preprocessor detail block"); |
| 3384 | return 0; |
| 3385 | |
| 3386 | case llvm::bitc::DEFINE_ABBREV: |
| 3387 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 3388 | return 0; |
| 3389 | |
| 3390 | default: |
| 3391 | break; |
| 3392 | } |
| 3393 | |
| 3394 | if (!PP.getPreprocessingRecord()) { |
| 3395 | Error("no preprocessing record"); |
| 3396 | return 0; |
| 3397 | } |
| 3398 | |
| 3399 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3400 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 3401 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3402 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 3403 | const char *BlobStart = 0; |
| 3404 | unsigned BlobLen = 0; |
| 3405 | RecordData Record; |
| 3406 | PreprocessorDetailRecordTypes RecType = |
| 3407 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 3408 | Code, Record, BlobStart, BlobLen); |
| 3409 | switch (RecType) { |
| 3410 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3411 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3412 | IdentifierInfo *Name = 0; |
| 3413 | MacroDefinition *Def = 0; |
| 3414 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3415 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3416 | else { |
| 3417 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3418 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3419 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 3420 | } |
| 3421 | |
| 3422 | MacroExpansion *ME; |
| 3423 | if (isBuiltin) |
| 3424 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 3425 | else |
| 3426 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 3427 | |
| 3428 | return ME; |
| 3429 | } |
| 3430 | |
| 3431 | case PPD_MACRO_DEFINITION: { |
| 3432 | // Decode the identifier info and then check again; if the macro is |
| 3433 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3434 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3435 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3436 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3437 | |
| 3438 | if (DeserializationListener) |
| 3439 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 3440 | |
| 3441 | return MD; |
| 3442 | } |
| 3443 | |
| 3444 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3445 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 3446 | StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]); |
| 3447 | const FileEntry *File = 0; |
| 3448 | if (!FullFileName.empty()) |
| 3449 | File = PP.getFileManager().getFile(FullFileName); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3450 | |
| 3451 | // FIXME: Stable encoding |
| 3452 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3453 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3454 | InclusionDirective *ID |
| 3455 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3456 | StringRef(BlobStart, Record[0]), |
| 3457 | Record[1], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3458 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3459 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3460 | return ID; |
| 3461 | } |
| 3462 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 3463 | |
| 3464 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3465 | } |
| 3466 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3467 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 3468 | /// preprocessed entities or the entities it contains are not the ones we are |
| 3469 | /// looking for. Find the next module that contains entities and return the ID |
| 3470 | /// of the first entry. |
| 3471 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 3472 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 3473 | ++SLocMapI; |
| 3474 | for (GlobalSLocOffsetMapType::const_iterator |
| 3475 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3476 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3477 | if (M.NumPreprocessedEntities) |
| 3478 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 3479 | } |
| 3480 | |
| 3481 | return getTotalNumPreprocessedEntities(); |
| 3482 | } |
| 3483 | |
| 3484 | namespace { |
| 3485 | |
| 3486 | template <unsigned PPEntityOffset::*PPLoc> |
| 3487 | struct PPEntityComp { |
| 3488 | const ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3489 | ModuleFile &M; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3490 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3491 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3492 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3493 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 3494 | SourceLocation LHS = getLoc(L); |
| 3495 | SourceLocation RHS = getLoc(R); |
| 3496 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3497 | } |
| 3498 | |
| 3499 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3500 | SourceLocation LHS = getLoc(L); |
| 3501 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3502 | } |
| 3503 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3504 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3505 | SourceLocation RHS = getLoc(R); |
| 3506 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3507 | } |
| 3508 | |
| 3509 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 3510 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 3511 | } |
| 3512 | }; |
| 3513 | |
| 3514 | } |
| 3515 | |
| 3516 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 3517 | PreprocessedEntityID |
| 3518 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 3519 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 3520 | return getTotalNumPreprocessedEntities(); |
| 3521 | |
| 3522 | GlobalSLocOffsetMapType::const_iterator |
| 3523 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3524 | BLoc.getOffset()); |
| 3525 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3526 | "Corrupted global sloc offset map"); |
| 3527 | |
| 3528 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3529 | return findNextPreprocessedEntity(SLocMapI); |
| 3530 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3531 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3532 | typedef const PPEntityOffset *pp_iterator; |
| 3533 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3534 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 3535 | |
| 3536 | size_t Count = M.NumPreprocessedEntities; |
| 3537 | size_t Half; |
| 3538 | pp_iterator First = pp_begin; |
| 3539 | pp_iterator PPI; |
| 3540 | |
| 3541 | // Do a binary search manually instead of using std::lower_bound because |
| 3542 | // The end locations of entities may be unordered (when a macro expansion |
| 3543 | // is inside another macro argument), but for this case it is not important |
| 3544 | // whether we get the first macro expansion or its containing macro. |
| 3545 | while (Count > 0) { |
| 3546 | Half = Count/2; |
| 3547 | PPI = First; |
| 3548 | std::advance(PPI, Half); |
| 3549 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 3550 | BLoc)){ |
| 3551 | First = PPI; |
| 3552 | ++First; |
| 3553 | Count = Count - Half - 1; |
| 3554 | } else |
| 3555 | Count = Half; |
| 3556 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3557 | |
| 3558 | if (PPI == pp_end) |
| 3559 | return findNextPreprocessedEntity(SLocMapI); |
| 3560 | |
| 3561 | return getGlobalPreprocessedEntityID(M, |
| 3562 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3563 | } |
| 3564 | |
| 3565 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 3566 | PreprocessedEntityID |
| 3567 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 3568 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 3569 | return getTotalNumPreprocessedEntities(); |
| 3570 | |
| 3571 | GlobalSLocOffsetMapType::const_iterator |
| 3572 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3573 | ELoc.getOffset()); |
| 3574 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3575 | "Corrupted global sloc offset map"); |
| 3576 | |
| 3577 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3578 | return findNextPreprocessedEntity(SLocMapI); |
| 3579 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3580 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3581 | typedef const PPEntityOffset *pp_iterator; |
| 3582 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3583 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 3584 | pp_iterator PPI = |
| 3585 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 3586 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 3587 | |
| 3588 | if (PPI == pp_end) |
| 3589 | return findNextPreprocessedEntity(SLocMapI); |
| 3590 | |
| 3591 | return getGlobalPreprocessedEntityID(M, |
| 3592 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3593 | } |
| 3594 | |
| 3595 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 3596 | /// preprocessed entities that \arg Range encompasses. |
| 3597 | std::pair<unsigned, unsigned> |
| 3598 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 3599 | if (Range.isInvalid()) |
| 3600 | return std::make_pair(0,0); |
| 3601 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 3602 | |
| 3603 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 3604 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 3605 | return std::make_pair(BeginID, EndID); |
| 3606 | } |
| 3607 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3608 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 3609 | /// entity with index \arg Index came from file \arg FID. |
| 3610 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 3611 | FileID FID) { |
| 3612 | if (FID.isInvalid()) |
| 3613 | return false; |
| 3614 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3615 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3616 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3617 | unsigned LocalIndex = PPInfo.second; |
| 3618 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 3619 | |
| 3620 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 3621 | if (Loc.isInvalid()) |
| 3622 | return false; |
| 3623 | |
| 3624 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 3625 | return true; |
| 3626 | else |
| 3627 | return false; |
| 3628 | } |
| 3629 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3630 | namespace { |
| 3631 | /// \brief Visitor used to search for information about a header file. |
| 3632 | class HeaderFileInfoVisitor { |
| 3633 | ASTReader &Reader; |
| 3634 | const FileEntry *FE; |
| 3635 | |
| 3636 | llvm::Optional<HeaderFileInfo> HFI; |
| 3637 | |
| 3638 | public: |
| 3639 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3640 | : Reader(Reader), FE(FE) { } |
| 3641 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3642 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3643 | HeaderFileInfoVisitor *This |
| 3644 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3645 | |
| 3646 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3647 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3648 | M.HeaderFileFrameworkStrings, |
| 3649 | This->FE->getName()); |
| 3650 | |
| 3651 | HeaderFileInfoLookupTable *Table |
| 3652 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3653 | if (!Table) |
| 3654 | return false; |
| 3655 | |
| 3656 | // Look in the on-disk hash table for an entry for this file name. |
| 3657 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3658 | &Trait); |
| 3659 | if (Pos == Table->end()) |
| 3660 | return false; |
| 3661 | |
| 3662 | This->HFI = *Pos; |
| 3663 | return true; |
| 3664 | } |
| 3665 | |
| 3666 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3667 | }; |
| 3668 | } |
| 3669 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3670 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3671 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3672 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3673 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3674 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3675 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3676 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | return HeaderFileInfo(); |
| 3680 | } |
| 3681 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3682 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3683 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3684 | ModuleFile &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3685 | unsigned Idx = 0; |
| 3686 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3687 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3688 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 3689 | Diag.DiagStatePoints.push_back( |
| 3690 | DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(), |
| 3691 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3692 | while (1) { |
| 3693 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3694 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3695 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3696 | break; // Something is messed up but at least avoid infinite loop in |
| 3697 | // release build. |
| 3698 | } |
| 3699 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3700 | if (DiagID == (unsigned)-1) { |
| 3701 | break; // no more diag/map pairs for this location. |
| 3702 | } |
| 3703 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3704 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 3705 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3706 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3707 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3708 | } |
| 3709 | } |
| 3710 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3711 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3712 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3713 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3714 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3715 | ModuleFile *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3716 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3720 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3721 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3722 | /// routine actually reads the record corresponding to the type at the given |
| 3723 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3724 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3725 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3726 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3727 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3728 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3729 | // Keep track of where we are in the stream, then jump back there |
| 3730 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3731 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3732 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3733 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3734 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3735 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3736 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3737 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3738 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3739 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3740 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3741 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3742 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3743 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3744 | if (Record.size() != 2) { |
| 3745 | Error("Incorrect encoding of extended qualifier type"); |
| 3746 | return QualType(); |
| 3747 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3748 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3749 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3750 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3751 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3752 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3753 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3754 | if (Record.size() != 1) { |
| 3755 | Error("Incorrect encoding of complex type"); |
| 3756 | return QualType(); |
| 3757 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3758 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3759 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3762 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3763 | if (Record.size() != 1) { |
| 3764 | Error("Incorrect encoding of pointer type"); |
| 3765 | return QualType(); |
| 3766 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3767 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3768 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3769 | } |
| 3770 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3771 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3772 | if (Record.size() != 1) { |
| 3773 | Error("Incorrect encoding of block pointer type"); |
| 3774 | return QualType(); |
| 3775 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3776 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3777 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3778 | } |
| 3779 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3780 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3781 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3782 | Error("Incorrect encoding of lvalue reference type"); |
| 3783 | return QualType(); |
| 3784 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3785 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3786 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3789 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3790 | if (Record.size() != 1) { |
| 3791 | Error("Incorrect encoding of rvalue reference type"); |
| 3792 | return QualType(); |
| 3793 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3794 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3795 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3798 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3799 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3800 | Error("Incorrect encoding of member pointer type"); |
| 3801 | return QualType(); |
| 3802 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3803 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3804 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3805 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3806 | return QualType(); |
| 3807 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3808 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3811 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3812 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3813 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3814 | unsigned IndexTypeQuals = Record[2]; |
| 3815 | unsigned Idx = 3; |
| 3816 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3817 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3818 | ASM, IndexTypeQuals); |
| 3819 | } |
| 3820 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3821 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3822 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3823 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3824 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3825 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3828 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3829 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3830 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3831 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3832 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3833 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3834 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3835 | ASM, IndexTypeQuals, |
| 3836 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3839 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3840 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3841 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3842 | return QualType(); |
| 3843 | } |
| 3844 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3845 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3846 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3847 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3848 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3849 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3852 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3853 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3854 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3855 | return QualType(); |
| 3856 | } |
| 3857 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3858 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3859 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3860 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3863 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3864 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3865 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3866 | return QualType(); |
| 3867 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3868 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3869 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3870 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3871 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3874 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3875 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3876 | |
| 3877 | FunctionProtoType::ExtProtoInfo EPI; |
| 3878 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3879 | /*hasregparm*/ Record[2], |
| 3880 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3881 | static_cast<CallingConv>(Record[4]), |
| 3882 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3883 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3884 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3885 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3886 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3887 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3888 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3889 | |
| 3890 | EPI.Variadic = Record[Idx++]; |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 3891 | EPI.HasTrailingReturn = Record[Idx++]; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3892 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3893 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3894 | ExceptionSpecificationType EST = |
| 3895 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3896 | EPI.ExceptionSpecType = EST; |
Douglas Gregor | b0d06e2 | 2012-04-04 00:34:49 +0000 | [diff] [blame] | 3897 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3898 | if (EST == EST_Dynamic) { |
| 3899 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3900 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3901 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3902 | EPI.Exceptions = Exceptions.data(); |
| 3903 | } else if (EST == EST_ComputedNoexcept) { |
| 3904 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 3905 | } else if (EST == EST_Uninstantiated) { |
| 3906 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
| 3907 | EPI.ExceptionSpecTemplate = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 3908 | } else if (EST == EST_Unevaluated) { |
| 3909 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3910 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3911 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3912 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3915 | case TYPE_UNRESOLVED_USING: { |
| 3916 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3917 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3918 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3919 | } |
| 3920 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3921 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3922 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3923 | Error("incorrect encoding of typedef type"); |
| 3924 | return QualType(); |
| 3925 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3926 | unsigned Idx = 0; |
| 3927 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3928 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3929 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3930 | Canonical = Context.getCanonicalType(Canonical); |
| 3931 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3932 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3933 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3934 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3935 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3936 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3937 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3938 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3939 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3940 | return QualType(); |
| 3941 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3942 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3943 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3944 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3945 | |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 3946 | case TYPE_DECLTYPE: { |
| 3947 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 3948 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 3949 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3950 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3951 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3952 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3953 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3954 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3955 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3956 | } |
| 3957 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3958 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3959 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3960 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3961 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3962 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3963 | Error("incorrect encoding of record type"); |
| 3964 | return QualType(); |
| 3965 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3966 | unsigned Idx = 0; |
| 3967 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 3968 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 3969 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 3970 | QualType T = Context.getRecordType(RD); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3971 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3972 | return T; |
| 3973 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3974 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3975 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3976 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3977 | Error("incorrect encoding of enum type"); |
| 3978 | return QualType(); |
| 3979 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3980 | unsigned Idx = 0; |
| 3981 | bool IsDependent = Record[Idx++]; |
| 3982 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3983 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3984 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3985 | return T; |
| 3986 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3987 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3988 | case TYPE_ATTRIBUTED: { |
| 3989 | if (Record.size() != 3) { |
| 3990 | Error("incorrect encoding of attributed type"); |
| 3991 | return QualType(); |
| 3992 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3993 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3994 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3995 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3996 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3997 | } |
| 3998 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3999 | case TYPE_PAREN: { |
| 4000 | if (Record.size() != 1) { |
| 4001 | Error("incorrect encoding of paren type"); |
| 4002 | return QualType(); |
| 4003 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4004 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4005 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4006 | } |
| 4007 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4008 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 4009 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4010 | Error("incorrect encoding of pack expansion type"); |
| 4011 | return QualType(); |
| 4012 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4013 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4014 | if (Pattern.isNull()) |
| 4015 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4016 | llvm::Optional<unsigned> NumExpansions; |
| 4017 | if (Record[1]) |
| 4018 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4019 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4020 | } |
| 4021 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4022 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4023 | unsigned Idx = 0; |
| 4024 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4025 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4026 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4027 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4028 | } |
| 4029 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4030 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4031 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4032 | ObjCInterfaceDecl *ItfD |
| 4033 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4034 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4035 | } |
| 4036 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4037 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4038 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4039 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4040 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4041 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4042 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4043 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4044 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4045 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4046 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4047 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4048 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4049 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4050 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4051 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4052 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4053 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4054 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4055 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 4056 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4057 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4058 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4059 | Replacement); |
| 4060 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4061 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4062 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 4063 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4064 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4065 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4066 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4067 | cast<TemplateTypeParmType>(Parm), |
| 4068 | ArgPack); |
| 4069 | } |
| 4070 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4071 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4072 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4073 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4074 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4075 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4076 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4077 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4078 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4079 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4080 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4081 | unsigned Idx = 0; |
| 4082 | unsigned Depth = Record[Idx++]; |
| 4083 | unsigned Index = Record[Idx++]; |
| 4084 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4085 | TemplateTypeParmDecl *D |
| 4086 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4087 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4088 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4089 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4090 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4091 | unsigned Idx = 0; |
| 4092 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4093 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4094 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4095 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4096 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4097 | Canon = Context.getCanonicalType(Canon); |
| 4098 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4099 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4100 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4101 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4102 | unsigned Idx = 0; |
| 4103 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4104 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4105 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4106 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4107 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4108 | Args.reserve(NumArgs); |
| 4109 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4110 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4111 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4112 | Args.size(), Args.data()); |
| 4113 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4114 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4115 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4116 | unsigned Idx = 0; |
| 4117 | |
| 4118 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4119 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4120 | ArrayType::ArraySizeModifier ASM |
| 4121 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 4122 | unsigned IndexTypeQuals = Record[Idx++]; |
| 4123 | |
| 4124 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4125 | Expr *NumElts = ReadExpr(*Loc.F); |
| 4126 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4127 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4128 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4129 | IndexTypeQuals, Brackets); |
| 4130 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4131 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4132 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4133 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4134 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4135 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4136 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4137 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4138 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4139 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4140 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4141 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4142 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4143 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4144 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4145 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4146 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4147 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4148 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4149 | |
| 4150 | case TYPE_ATOMIC: { |
| 4151 | if (Record.size() != 1) { |
| 4152 | Error("Incorrect encoding of atomic type"); |
| 4153 | return QualType(); |
| 4154 | } |
| 4155 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 4156 | return Context.getAtomicType(ValueType); |
| 4157 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4158 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4159 | llvm_unreachable("Invalid TypeCode!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4162 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4163 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4164 | ModuleFile &F; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4165 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4166 | unsigned &Idx; |
| 4167 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4168 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 4169 | unsigned &I) { |
| 4170 | return Reader.ReadSourceLocation(F, R, I); |
| 4171 | } |
| 4172 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4173 | template<typename T> |
| 4174 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 4175 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 4176 | } |
| 4177 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4178 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4179 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4180 | const ASTReader::RecordData &Record, unsigned &Idx) |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 4181 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4182 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4183 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4184 | // We want compile-time assurance that we've enumerated all of |
| 4185 | // these, so unfortunately we have to declare them first, then |
| 4186 | // define them out-of-line. |
| 4187 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4188 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4189 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4190 | #include "clang/AST/TypeLocNodes.def" |
| 4191 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4192 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 4193 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4194 | }; |
| 4195 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4196 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4197 | // nothing to do |
| 4198 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4199 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4200 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4201 | if (TL.needsExtraLocalData()) { |
| 4202 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 4203 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 4204 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 4205 | TL.setModeAttr(Record[Idx++]); |
| 4206 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4207 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4208 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4209 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4210 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4211 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4212 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4213 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4214 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4215 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4216 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4217 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4218 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4219 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4220 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4221 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4222 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4223 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4224 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4225 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4226 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4227 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4228 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 4229 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4230 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4231 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4232 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4233 | TL.setSizeExpr(0); |
| 4234 | } |
| 4235 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 4236 | VisitArrayTypeLoc(TL); |
| 4237 | } |
| 4238 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 4239 | VisitArrayTypeLoc(TL); |
| 4240 | } |
| 4241 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 4242 | VisitArrayTypeLoc(TL); |
| 4243 | } |
| 4244 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 4245 | DependentSizedArrayTypeLoc TL) { |
| 4246 | VisitArrayTypeLoc(TL); |
| 4247 | } |
| 4248 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 4249 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4250 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4251 | } |
| 4252 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4253 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4254 | } |
| 4255 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4256 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4257 | } |
| 4258 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4259 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 4260 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4261 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4262 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4263 | } |
| 4264 | } |
| 4265 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 4266 | VisitFunctionTypeLoc(TL); |
| 4267 | } |
| 4268 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 4269 | VisitFunctionTypeLoc(TL); |
| 4270 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4271 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4272 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4273 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4274 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4275 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4276 | } |
| 4277 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4278 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4279 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4280 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4281 | } |
| 4282 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4283 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4284 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4285 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4286 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4287 | } |
| 4288 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4289 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4290 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4291 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 4292 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4293 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4294 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4295 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 4296 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4297 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 4298 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4299 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4300 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4301 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4302 | } |
| 4303 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4304 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4305 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4306 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 4307 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 4308 | if (TL.hasAttrOperand()) { |
| 4309 | SourceRange range; |
| 4310 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 4311 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 4312 | TL.setAttrOperandParensRange(range); |
| 4313 | } |
| 4314 | if (TL.hasAttrExprOperand()) { |
| 4315 | if (Record[Idx++]) |
| 4316 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 4317 | else |
| 4318 | TL.setAttrExprOperand(0); |
| 4319 | } else if (TL.hasAttrEnumOperand()) |
| 4320 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 4321 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4322 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4323 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4324 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4325 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 4326 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4327 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4328 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4329 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 4330 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4331 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4332 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4333 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 4334 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4335 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4336 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 4337 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4338 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4339 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 4340 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4341 | Reader.GetTemplateArgumentLocInfo(F, |
| 4342 | TL.getTypePtr()->getArg(i).getKind(), |
| 4343 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4344 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4345 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 4346 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4347 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4348 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4349 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4350 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4351 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4352 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4353 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4354 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4355 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4356 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4357 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4358 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4359 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4360 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4361 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 4362 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4363 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4364 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4365 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4366 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4367 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4368 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4369 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4370 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4371 | Reader.GetTemplateArgumentLocInfo(F, |
| 4372 | TL.getTypePtr()->getArg(I).getKind(), |
| 4373 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4374 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4375 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 4376 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 4377 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4378 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4379 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4380 | } |
| 4381 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 4382 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4383 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4384 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4385 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4386 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4387 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4388 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4389 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4390 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4391 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 4392 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4393 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4394 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4395 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4396 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4397 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4398 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4399 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4400 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4401 | if (InfoTy.isNull()) |
| 4402 | return 0; |
| 4403 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4404 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4405 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4406 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4407 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4408 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4409 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4410 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4411 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4412 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4413 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4414 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4415 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4416 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4417 | switch ((PredefinedTypeIDs)Index) { |
| 4418 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4419 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 4420 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4421 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4422 | case PREDEF_TYPE_CHAR_U_ID: |
| 4423 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4424 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4425 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4426 | break; |
| 4427 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4428 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 4429 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 4430 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 4431 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 4432 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 4433 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 4434 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 4435 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 4436 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 4437 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 4438 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 4439 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 4440 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 4441 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4442 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 4443 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 4444 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 4445 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 4446 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 4447 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4448 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 4449 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 4450 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 4451 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 4452 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 4453 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 4454 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 4455 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 4456 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4457 | |
| 4458 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4459 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4460 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 4461 | |
| 4462 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 4463 | T = Context.ARCUnbridgedCastTy; |
| 4464 | break; |
| 4465 | |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 4466 | case PREDEF_TYPE_VA_LIST_TAG: |
| 4467 | T = Context.getVaListTagType(); |
| 4468 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4469 | } |
| 4470 | |
| 4471 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4472 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4473 | } |
| 4474 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4475 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4476 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4477 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4478 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4479 | if (TypesLoaded[Index].isNull()) |
| 4480 | return QualType(); |
| 4481 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4482 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4483 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4484 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4485 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4486 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4487 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4488 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4491 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4492 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4493 | } |
| 4494 | |
| 4495 | serialization::TypeID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4496 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4497 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4498 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4499 | |
| 4500 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4501 | return LocalID; |
| 4502 | |
| 4503 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4504 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4505 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4506 | |
| 4507 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4508 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4509 | } |
| 4510 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4511 | TemplateArgumentLocInfo |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4512 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4513 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4514 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4515 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4516 | switch (Kind) { |
| 4517 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4518 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4519 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4520 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4521 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4522 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4523 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4524 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4525 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4526 | SourceLocation()); |
| 4527 | } |
| 4528 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4529 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4530 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4531 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4532 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4533 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4534 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4535 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4536 | case TemplateArgument::Null: |
| 4537 | case TemplateArgument::Integral: |
| 4538 | case TemplateArgument::Declaration: |
| 4539 | case TemplateArgument::Pack: |
| 4540 | return TemplateArgumentLocInfo(); |
| 4541 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4542 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4543 | } |
| 4544 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4545 | TemplateArgumentLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4546 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4547 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4548 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4549 | |
| 4550 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4551 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4552 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4553 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4554 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4555 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4558 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4559 | return GetDecl(ID); |
| 4560 | } |
| 4561 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4562 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4563 | unsigned &Idx){ |
| 4564 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4565 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4566 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4567 | unsigned LocalID = Record[Idx++]; |
| 4568 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4572 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4573 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4574 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4575 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4576 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4577 | RecordData Record; |
| 4578 | unsigned Code = Cursor.ReadCode(); |
| 4579 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4580 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4581 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4582 | return 0; |
| 4583 | } |
| 4584 | |
| 4585 | unsigned Idx = 0; |
| 4586 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4587 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4588 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4589 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4590 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4591 | return Bases; |
| 4592 | } |
| 4593 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4594 | serialization::DeclID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4595 | ASTReader::getGlobalDeclID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4596 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4597 | return LocalID; |
| 4598 | |
| 4599 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4600 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4601 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4602 | |
| 4603 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4604 | } |
| 4605 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4606 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4607 | ModuleFile &M) const { |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4608 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4609 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4610 | return &M == I->second; |
| 4611 | } |
| 4612 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4613 | ModuleFile *ASTReader::getOwningModuleFile(Decl *D) { |
| 4614 | if (!D->isFromASTFile()) |
| 4615 | return 0; |
| 4616 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 4617 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4618 | return I->second; |
| 4619 | } |
| 4620 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4621 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 4622 | if (ID < NUM_PREDEF_DECL_IDS) |
| 4623 | return SourceLocation(); |
| 4624 | |
| 4625 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4626 | |
| 4627 | if (Index > DeclsLoaded.size()) { |
| 4628 | Error("declaration ID out-of-range for AST file"); |
| 4629 | return SourceLocation(); |
| 4630 | } |
| 4631 | |
| 4632 | if (Decl *D = DeclsLoaded[Index]) |
| 4633 | return D->getLocation(); |
| 4634 | |
| 4635 | unsigned RawLocation = 0; |
| 4636 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 4637 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 4638 | } |
| 4639 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4640 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4641 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4642 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4643 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4644 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4645 | |
| 4646 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4647 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4648 | |
| 4649 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4650 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4651 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4652 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4653 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4654 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4655 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4656 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 4658 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 4659 | return Context.getObjCProtocolDecl(); |
| 4660 | |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4661 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4662 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4663 | |
| 4664 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4665 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4666 | |
| 4667 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4668 | return Context.getObjCInstanceTypeDecl(); |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4669 | |
| 4670 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 4671 | return Context.getBuiltinVaListDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4672 | } |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4675 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4676 | |
Richard Smith | 2fbf373 | 2011-12-20 04:39:57 +0000 | [diff] [blame] | 4677 | if (Index >= DeclsLoaded.size()) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4678 | assert(0 && "declaration ID out-of-range for AST file"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4679 | Error("declaration ID out-of-range for AST file"); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4680 | return 0; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4681 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4682 | |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 4683 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4684 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4685 | if (DeserializationListener) |
| 4686 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4687 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4688 | |
| 4689 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4692 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 4693 | DeclID GlobalID) { |
| 4694 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 4695 | return GlobalID; |
| 4696 | |
| 4697 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 4698 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4699 | ModuleFile *Owner = I->second; |
| 4700 | |
| 4701 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 4702 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 4703 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 4704 | return 0; |
| 4705 | |
| 4706 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 4707 | } |
| 4708 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4709 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4710 | const RecordData &Record, |
| 4711 | unsigned &Idx) { |
| 4712 | if (Idx >= Record.size()) { |
| 4713 | Error("Corrupted AST file"); |
| 4714 | return 0; |
| 4715 | } |
| 4716 | |
| 4717 | return getGlobalDeclID(F, Record[Idx++]); |
| 4718 | } |
| 4719 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4720 | /// \brief Resolve the offset of a statement into a statement. |
| 4721 | /// |
| 4722 | /// This operation will read a new statement from the external |
| 4723 | /// source each time it is called, and is meant to be used via a |
| 4724 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4725 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4726 | // Switch case IDs are per Decl. |
| 4727 | ClearSwitchCaseIDs(); |
| 4728 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4729 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4730 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4731 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4732 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4733 | } |
| 4734 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4735 | namespace { |
| 4736 | class FindExternalLexicalDeclsVisitor { |
| 4737 | ASTReader &Reader; |
| 4738 | const DeclContext *DC; |
| 4739 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4740 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4741 | SmallVectorImpl<Decl*> &Decls; |
| 4742 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4743 | |
| 4744 | public: |
| 4745 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4746 | bool (*isKindWeWant)(Decl::Kind), |
| 4747 | SmallVectorImpl<Decl*> &Decls) |
| 4748 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4749 | { |
| 4750 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4751 | PredefsVisited[I] = false; |
| 4752 | } |
| 4753 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4754 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4755 | if (Preorder) |
| 4756 | return false; |
| 4757 | |
| 4758 | FindExternalLexicalDeclsVisitor *This |
| 4759 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4760 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4761 | ModuleFile::DeclContextInfosMap::iterator Info |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4762 | = M.DeclContextInfos.find(This->DC); |
| 4763 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4764 | return false; |
| 4765 | |
| 4766 | // Load all of the declaration IDs |
| 4767 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4768 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4769 | ID != IDE; ++ID) { |
| 4770 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4771 | continue; |
| 4772 | |
| 4773 | // Don't add predefined declarations to the lexical context more |
| 4774 | // than once. |
| 4775 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4776 | if (This->PredefsVisited[ID->second]) |
| 4777 | continue; |
| 4778 | |
| 4779 | This->PredefsVisited[ID->second] = true; |
| 4780 | } |
| 4781 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4782 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4783 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4784 | This->Decls.push_back(D); |
| 4785 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | return false; |
| 4789 | } |
| 4790 | }; |
| 4791 | } |
| 4792 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4793 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4794 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4795 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4796 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4797 | // least. Walk all of the modules in the order they were loaded. |
| 4798 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4799 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4800 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4801 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4804 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4805 | |
| 4806 | class DeclIDComp { |
| 4807 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4808 | ModuleFile &Mod; |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4809 | |
| 4810 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4811 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4812 | |
| 4813 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 4814 | SourceLocation LHS = getLocation(L); |
| 4815 | SourceLocation RHS = getLocation(R); |
| 4816 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4817 | } |
| 4818 | |
| 4819 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 4820 | SourceLocation RHS = getLocation(R); |
| 4821 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4822 | } |
| 4823 | |
| 4824 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 4825 | SourceLocation LHS = getLocation(L); |
| 4826 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4827 | } |
| 4828 | |
| 4829 | SourceLocation getLocation(LocalDeclID ID) const { |
| 4830 | return Reader.getSourceManager().getFileLoc( |
| 4831 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 4832 | } |
| 4833 | }; |
| 4834 | |
| 4835 | } |
| 4836 | |
| 4837 | void ASTReader::FindFileRegionDecls(FileID File, |
| 4838 | unsigned Offset, unsigned Length, |
| 4839 | SmallVectorImpl<Decl *> &Decls) { |
| 4840 | SourceManager &SM = getSourceManager(); |
| 4841 | |
| 4842 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 4843 | if (I == FileDeclIDs.end()) |
| 4844 | return; |
| 4845 | |
| 4846 | FileDeclsInfo &DInfo = I->second; |
| 4847 | if (DInfo.Decls.empty()) |
| 4848 | return; |
| 4849 | |
| 4850 | SourceLocation |
| 4851 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 4852 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 4853 | |
| 4854 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 4855 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4856 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4857 | BeginLoc, DIDComp); |
| 4858 | if (BeginIt != DInfo.Decls.begin()) |
| 4859 | --BeginIt; |
| 4860 | |
Argyrios Kyrtzidis | c14a03d | 2011-11-23 20:27:36 +0000 | [diff] [blame] | 4861 | // If we are pointing at a top-level decl inside an objc container, we need |
| 4862 | // to backtrack until we find it otherwise we will fail to report that the |
| 4863 | // region overlaps with an objc container. |
| 4864 | while (BeginIt != DInfo.Decls.begin() && |
| 4865 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 4866 | ->isTopLevelDeclInObjCContainer()) |
| 4867 | --BeginIt; |
| 4868 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4869 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4870 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4871 | EndLoc, DIDComp); |
| 4872 | if (EndIt != DInfo.Decls.end()) |
| 4873 | ++EndIt; |
| 4874 | |
| 4875 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 4876 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 4877 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 4878 | } |
| 4879 | |
| 4880 | namespace { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4881 | /// \brief ModuleFile visitor used to perform name lookup into a |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4882 | /// declaration context. |
| 4883 | class DeclContextNameLookupVisitor { |
| 4884 | ASTReader &Reader; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4885 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4886 | DeclarationName Name; |
| 4887 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4888 | |
| 4889 | public: |
| 4890 | DeclContextNameLookupVisitor(ASTReader &Reader, |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4891 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 4892 | DeclarationName Name, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4893 | SmallVectorImpl<NamedDecl *> &Decls) |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4894 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls) { } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4895 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4896 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4897 | DeclContextNameLookupVisitor *This |
| 4898 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4899 | |
| 4900 | // Check whether we have any visible declaration information for |
| 4901 | // this context in this module. |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4902 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 4903 | bool FoundInfo = false; |
| 4904 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 4905 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 4906 | if (Info != M.DeclContextInfos.end() && |
| 4907 | Info->second.NameLookupTableData) { |
| 4908 | FoundInfo = true; |
| 4909 | break; |
| 4910 | } |
| 4911 | } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4912 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4913 | if (!FoundInfo) |
| 4914 | return false; |
| 4915 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4916 | // Look for this name within this module. |
| 4917 | ASTDeclContextNameLookupTable *LookupTable = |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 4918 | Info->second.NameLookupTableData; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4919 | ASTDeclContextNameLookupTable::iterator Pos |
| 4920 | = LookupTable->find(This->Name); |
| 4921 | if (Pos == LookupTable->end()) |
| 4922 | return false; |
| 4923 | |
| 4924 | bool FoundAnything = false; |
| 4925 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4926 | for (; Data.first != Data.second; ++Data.first) { |
| 4927 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4928 | if (!ND) |
| 4929 | continue; |
| 4930 | |
| 4931 | if (ND->getDeclName() != This->Name) { |
| 4932 | assert(!This->Name.getCXXNameType().isNull() && |
| 4933 | "Name mismatch without a type"); |
| 4934 | continue; |
| 4935 | } |
| 4936 | |
| 4937 | // Record this declaration. |
| 4938 | FoundAnything = true; |
| 4939 | This->Decls.push_back(ND); |
| 4940 | } |
| 4941 | |
| 4942 | return FoundAnything; |
| 4943 | } |
| 4944 | }; |
| 4945 | } |
| 4946 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4947 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4948 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4949 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4951 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4952 | if (!Name) |
| 4953 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4954 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4955 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4956 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4957 | |
| 4958 | // Compute the declaration contexts we need to look into. Multiple such |
| 4959 | // declaration contexts occur when two declaration contexts from disjoint |
| 4960 | // modules get merged, e.g., when two namespaces with the same name are |
| 4961 | // independently defined in separate modules. |
| 4962 | SmallVector<const DeclContext *, 2> Contexts; |
| 4963 | Contexts.push_back(DC); |
| 4964 | |
| 4965 | if (DC->isNamespace()) { |
| 4966 | MergedDeclsMap::iterator Merged |
| 4967 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 4968 | if (Merged != MergedDecls.end()) { |
| 4969 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 4970 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 4971 | } |
| 4972 | } |
| 4973 | |
| 4974 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4975 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4976 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4977 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4978 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4981 | namespace { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4982 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4983 | /// declaration context. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4984 | class DeclContextAllNamesVisitor { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4985 | ASTReader &Reader; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4986 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4987 | llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4988 | |
| 4989 | public: |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4990 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 4991 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 4992 | llvm::DenseMap<DeclarationName, |
| 4993 | SmallVector<NamedDecl *, 8> > &Decls) |
| 4994 | : Reader(Reader), Contexts(Contexts), Decls(Decls) { } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4995 | |
| 4996 | static bool visit(ModuleFile &M, void *UserData) { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4997 | DeclContextAllNamesVisitor *This |
| 4998 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4999 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5000 | // Check whether we have any visible declaration information for |
| 5001 | // this context in this module. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5002 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5003 | bool FoundInfo = false; |
| 5004 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5005 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5006 | if (Info != M.DeclContextInfos.end() && |
| 5007 | Info->second.NameLookupTableData) { |
| 5008 | FoundInfo = true; |
| 5009 | break; |
| 5010 | } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5013 | if (!FoundInfo) |
| 5014 | return false; |
| 5015 | |
| 5016 | ASTDeclContextNameLookupTable *LookupTable = |
| 5017 | Info->second.NameLookupTableData; |
| 5018 | bool FoundAnything = false; |
| 5019 | for (ASTDeclContextNameLookupTable::data_iterator |
| 5020 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 5021 | I != E; ++I) { |
| 5022 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 5023 | for (; Data.first != Data.second; ++Data.first) { |
| 5024 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 5025 | *Data.first); |
| 5026 | if (!ND) |
| 5027 | continue; |
| 5028 | |
| 5029 | // Record this declaration. |
| 5030 | FoundAnything = true; |
| 5031 | This->Decls[ND->getDeclName()].push_back(ND); |
| 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | return FoundAnything; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5036 | } |
| 5037 | }; |
| 5038 | } |
| 5039 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5040 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5041 | if (!DC->hasExternalVisibleStorage()) |
| 5042 | return; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5043 | llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls; |
| 5044 | |
| 5045 | // Compute the declaration contexts we need to look into. Multiple such |
| 5046 | // declaration contexts occur when two declaration contexts from disjoint |
| 5047 | // modules get merged, e.g., when two namespaces with the same name are |
| 5048 | // independently defined in separate modules. |
| 5049 | SmallVector<const DeclContext *, 2> Contexts; |
| 5050 | Contexts.push_back(DC); |
| 5051 | |
| 5052 | if (DC->isNamespace()) { |
| 5053 | MergedDeclsMap::iterator Merged |
| 5054 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5055 | if (Merged != MergedDecls.end()) { |
| 5056 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5057 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5058 | } |
| 5059 | } |
| 5060 | |
| 5061 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); |
| 5062 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 5063 | ++NumVisibleDeclContextsRead; |
| 5064 | |
| 5065 | for (llvm::DenseMap<DeclarationName, |
| 5066 | llvm::SmallVector<NamedDecl*, 8> >::iterator |
| 5067 | I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 5068 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 5069 | } |
Argyrios Kyrtzidis | 394e539 | 2012-04-26 18:34:14 +0000 | [diff] [blame] | 5070 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5071 | } |
| 5072 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5073 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 5074 | /// before receiving the implementation, and codegen depends on this. |
| 5075 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 5076 | /// implementation before passing the deserialized implementation decl. |
| 5077 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 5078 | ASTConsumer *Consumer) { |
| 5079 | assert(ImplD && Consumer); |
| 5080 | |
| 5081 | for (ObjCImplDecl::method_iterator |
| 5082 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 5083 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5084 | |
| 5085 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 5086 | } |
| 5087 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5088 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5089 | assert(Consumer); |
| 5090 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5091 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5092 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5093 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5094 | PassInterestingDeclToConsumer(D); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5095 | } |
| 5096 | } |
| 5097 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5098 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 5099 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5100 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 5101 | else |
| 5102 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 5103 | } |
| 5104 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5105 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 5106 | this->Consumer = Consumer; |
| 5107 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5108 | if (!Consumer) |
| 5109 | return; |
| 5110 | |
| 5111 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5112 | // Force deserialization of this decl, which will cause it to be queued for |
| 5113 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 5114 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5115 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 5116 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 5117 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5118 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5121 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5122 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5123 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5124 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5125 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5126 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5127 | unsigned NumDeclsLoaded |
| 5128 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 5129 | (Decl *)0); |
| 5130 | unsigned NumIdentifiersLoaded |
| 5131 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 5132 | IdentifiersLoaded.end(), |
| 5133 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5134 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5135 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 5136 | SelectorsLoaded.end(), |
| 5137 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 5138 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 5139 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 5140 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 5141 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5142 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 5143 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 5144 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5145 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5146 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5147 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 5148 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 5149 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5150 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5151 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 5152 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5153 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5154 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5155 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 5156 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5157 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5158 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5159 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 5160 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5161 | if (TotalNumStatements) |
| 5162 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 5163 | NumStatementsRead, TotalNumStatements, |
| 5164 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 5165 | if (TotalNumMacros) |
| 5166 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5167 | NumMacrosRead, TotalNumMacros, |
| 5168 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 5169 | if (TotalLexicalDeclContexts) |
| 5170 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 5171 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 5172 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 5173 | * 100)); |
| 5174 | if (TotalVisibleDeclContexts) |
| 5175 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 5176 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 5177 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 5178 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5179 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5180 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5181 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 5182 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5183 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5184 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5185 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5186 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5187 | dump(); |
| 5188 | std::fprintf(stderr, "\n"); |
| 5189 | } |
| 5190 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5191 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5192 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5193 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5194 | const ContinuousRangeMap<Key, ModuleFile *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5195 | InitialCapacity> &Map) { |
| 5196 | if (Map.begin() == Map.end()) |
| 5197 | return; |
| 5198 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5199 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5200 | llvm::errs() << Name << ":\n"; |
| 5201 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5202 | I != IEnd; ++I) { |
| 5203 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 5204 | << "\n"; |
| 5205 | } |
| 5206 | } |
| 5207 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5208 | void ASTReader::dump() { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5209 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5210 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5211 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 5212 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5213 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5214 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5215 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5216 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5217 | dumpModuleIDMap("Global preprocessed entity map", |
| 5218 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5219 | |
| 5220 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 5221 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 5222 | MEnd = ModuleMgr.end(); |
| 5223 | M != MEnd; ++M) |
| 5224 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5227 | /// Return the amount of memory used by memory buffers, breaking down |
| 5228 | /// by heap-backed versus mmap'ed memory. |
| 5229 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5230 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 5231 | E = ModuleMgr.end(); I != E; ++I) { |
| 5232 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5233 | size_t bytes = buf->getBufferSize(); |
| 5234 | switch (buf->getBufferKind()) { |
| 5235 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 5236 | sizes.malloc_bytes += bytes; |
| 5237 | break; |
| 5238 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 5239 | sizes.mmap_bytes += bytes; |
| 5240 | break; |
| 5241 | } |
| 5242 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5243 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5244 | } |
| 5245 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5246 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5247 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5248 | S.ExternalSource = this; |
| 5249 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5250 | // Makes sure any declarations that were deserialized "too early" |
| 5251 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 5252 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5253 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 5254 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5255 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5256 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5257 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5258 | // Load the offsets of the declarations that Sema references. |
| 5259 | // They will be lazily deserialized when needed. |
| 5260 | if (!SemaDeclRefs.empty()) { |
| 5261 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 5262 | if (!SemaObj->StdNamespace) |
| 5263 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 5264 | if (!SemaObj->StdBadAlloc) |
| 5265 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5266 | } |
| 5267 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5268 | if (!FPPragmaOptions.empty()) { |
| 5269 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 5270 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 5271 | } |
| 5272 | |
| 5273 | if (!OpenCLExtensions.empty()) { |
| 5274 | unsigned I = 0; |
| 5275 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 5276 | #include "clang/Basic/OpenCLExtensions.def" |
| 5277 | |
| 5278 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 5279 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5280 | } |
| 5281 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5282 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5283 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart), |
| 5284 | /*PriorGeneration=*/0); |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5285 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5286 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5287 | markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5288 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5289 | } |
| 5290 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5291 | namespace clang { |
| 5292 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 5293 | /// identifiers stored within a set of AST files. |
| 5294 | class ASTIdentifierIterator : public IdentifierIterator { |
| 5295 | /// \brief The AST reader whose identifiers are being enumerated. |
| 5296 | const ASTReader &Reader; |
| 5297 | |
| 5298 | /// \brief The current index into the chain of AST files stored in |
| 5299 | /// the AST reader. |
| 5300 | unsigned Index; |
| 5301 | |
| 5302 | /// \brief The current position within the identifier lookup table |
| 5303 | /// of the current AST file. |
| 5304 | ASTIdentifierLookupTable::key_iterator Current; |
| 5305 | |
| 5306 | /// \brief The end position within the identifier lookup table of |
| 5307 | /// the current AST file. |
| 5308 | ASTIdentifierLookupTable::key_iterator End; |
| 5309 | |
| 5310 | public: |
| 5311 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 5312 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5313 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5314 | }; |
| 5315 | } |
| 5316 | |
| 5317 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5318 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5319 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5320 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5321 | Current = IdTable->key_begin(); |
| 5322 | End = IdTable->key_end(); |
| 5323 | } |
| 5324 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5325 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5326 | while (Current == End) { |
| 5327 | // If we have exhausted all of our AST files, we're done. |
| 5328 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5329 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5330 | |
| 5331 | --Index; |
| 5332 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5333 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 5334 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5335 | Current = IdTable->key_begin(); |
| 5336 | End = IdTable->key_end(); |
| 5337 | } |
| 5338 | |
| 5339 | // We have any identifiers remaining in the current AST file; return |
| 5340 | // the next one. |
| 5341 | std::pair<const char*, unsigned> Key = *Current; |
| 5342 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5343 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
| 5346 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 5347 | return new ASTIdentifierIterator(*this); |
| 5348 | } |
| 5349 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5350 | namespace clang { namespace serialization { |
| 5351 | class ReadMethodPoolVisitor { |
| 5352 | ASTReader &Reader; |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5353 | Selector Sel; |
| 5354 | unsigned PriorGeneration; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5355 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 5356 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5357 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5358 | public: |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5359 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 5360 | unsigned PriorGeneration) |
| 5361 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5362 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5363 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5364 | ReadMethodPoolVisitor *This |
| 5365 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 5366 | |
| 5367 | if (!M.SelectorLookupTable) |
| 5368 | return false; |
| 5369 | |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5370 | // If we've already searched this module file, skip it now. |
| 5371 | if (M.Generation <= This->PriorGeneration) |
| 5372 | return true; |
| 5373 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5374 | ASTSelectorLookupTable *PoolTable |
| 5375 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 5376 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 5377 | if (Pos == PoolTable->end()) |
| 5378 | return false; |
| 5379 | |
| 5380 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5381 | // FIXME: Not quite happy with the statistics here. We probably should |
| 5382 | // disable this tracking when called via LoadSelector. |
| 5383 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5384 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5385 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5386 | if (This->Reader.DeserializationListener) |
| 5387 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 5388 | This->Sel); |
| 5389 | |
| 5390 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 5391 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 5392 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5393 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5394 | |
| 5395 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5396 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 5397 | return InstanceMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5398 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5399 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5400 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5401 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 5402 | return FactoryMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5403 | } |
| 5404 | }; |
| 5405 | } } // end namespace clang::serialization |
| 5406 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5407 | /// \brief Add the given set of methods to the method list. |
| 5408 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 5409 | ObjCMethodList &List) { |
| 5410 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 5411 | S.addMethodToGlobalList(&List, Methods[I]); |
| 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | void ASTReader::ReadMethodPool(Selector Sel) { |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5416 | // Get the selector generation and update it to the current generation. |
| 5417 | unsigned &Generation = SelectorGeneration[Sel]; |
| 5418 | unsigned PriorGeneration = Generation; |
| 5419 | Generation = CurrentGeneration; |
| 5420 | |
| 5421 | // Search for methods defined with this selector. |
| 5422 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5423 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5424 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5425 | if (Visitor.getInstanceMethods().empty() && |
| 5426 | Visitor.getFactoryMethods().empty()) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5427 | ++NumMethodPoolMisses; |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5428 | return; |
| 5429 | } |
| 5430 | |
| 5431 | if (!getSema()) |
| 5432 | return; |
| 5433 | |
| 5434 | Sema &S = *getSema(); |
| 5435 | Sema::GlobalMethodPool::iterator Pos |
| 5436 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 5437 | |
| 5438 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 5439 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5442 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5443 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5444 | Namespaces.clear(); |
| 5445 | |
| 5446 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 5447 | if (NamespaceDecl *Namespace |
| 5448 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 5449 | Namespaces.push_back(Namespace); |
| 5450 | } |
| 5451 | } |
| 5452 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 5453 | void ASTReader::ReadTentativeDefinitions( |
| 5454 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 5455 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 5456 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 5457 | if (Var) |
| 5458 | TentativeDefs.push_back(Var); |
| 5459 | } |
| 5460 | TentativeDefinitions.clear(); |
| 5461 | } |
| 5462 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 5463 | void ASTReader::ReadUnusedFileScopedDecls( |
| 5464 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 5465 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 5466 | DeclaratorDecl *D |
| 5467 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 5468 | if (D) |
| 5469 | Decls.push_back(D); |
| 5470 | } |
| 5471 | UnusedFileScopedDecls.clear(); |
| 5472 | } |
| 5473 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 5474 | void ASTReader::ReadDelegatingConstructors( |
| 5475 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 5476 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 5477 | CXXConstructorDecl *D |
| 5478 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 5479 | if (D) |
| 5480 | Decls.push_back(D); |
| 5481 | } |
| 5482 | DelegatingCtorDecls.clear(); |
| 5483 | } |
| 5484 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 5485 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 5486 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 5487 | TypedefNameDecl *D |
| 5488 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 5489 | if (D) |
| 5490 | Decls.push_back(D); |
| 5491 | } |
| 5492 | ExtVectorDecls.clear(); |
| 5493 | } |
| 5494 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 5495 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 5496 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 5497 | CXXRecordDecl *D |
| 5498 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 5499 | if (D) |
| 5500 | Decls.push_back(D); |
| 5501 | } |
| 5502 | DynamicClasses.clear(); |
| 5503 | } |
| 5504 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 5505 | void |
| 5506 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 5507 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 5508 | NamedDecl *D |
| 5509 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 5510 | if (D) |
| 5511 | Decls.push_back(D); |
| 5512 | } |
| 5513 | LocallyScopedExternalDecls.clear(); |
| 5514 | } |
| 5515 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 5516 | void ASTReader::ReadReferencedSelectors( |
| 5517 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 5518 | if (ReferencedSelectorsData.empty()) |
| 5519 | return; |
| 5520 | |
| 5521 | // If there are @selector references added them to its pool. This is for |
| 5522 | // implementation of -Wselector. |
| 5523 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 5524 | unsigned I = 0; |
| 5525 | while (I < DataSize) { |
| 5526 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 5527 | SourceLocation SelLoc |
| 5528 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 5529 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 5530 | } |
| 5531 | ReferencedSelectorsData.clear(); |
| 5532 | } |
| 5533 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 5534 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 5535 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 5536 | if (WeakUndeclaredIdentifiers.empty()) |
| 5537 | return; |
| 5538 | |
| 5539 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 5540 | IdentifierInfo *WeakId |
| 5541 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5542 | IdentifierInfo *AliasId |
| 5543 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5544 | SourceLocation Loc |
| 5545 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 5546 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 5547 | WeakInfo WI(AliasId, Loc); |
| 5548 | WI.setUsed(Used); |
| 5549 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 5550 | } |
| 5551 | WeakUndeclaredIdentifiers.clear(); |
| 5552 | } |
| 5553 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 5554 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 5555 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 5556 | ExternalVTableUse VT; |
| 5557 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 5558 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 5559 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 5560 | VTables.push_back(VT); |
| 5561 | } |
| 5562 | |
| 5563 | VTableUses.clear(); |
| 5564 | } |
| 5565 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 5566 | void ASTReader::ReadPendingInstantiations( |
| 5567 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 5568 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 5569 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 5570 | SourceLocation Loc |
| 5571 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 5572 | Pending.push_back(std::make_pair(D, Loc)); |
| 5573 | } |
| 5574 | PendingInstantiations.clear(); |
| 5575 | } |
| 5576 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5577 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5578 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 5579 | ReadMethodPool(Sel); |
| 5580 | } |
| 5581 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5582 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5583 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 5584 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5585 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5586 | if (DeserializationListener) |
| 5587 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5588 | } |
| 5589 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5590 | /// \brief Set the globally-visible declarations associated with the given |
| 5591 | /// identifier. |
| 5592 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5593 | /// If the AST reader is currently in a state where the given declaration IDs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5594 | /// cannot safely be resolved, they are queued until it is safe to resolve |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5595 | /// them. |
| 5596 | /// |
| 5597 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 5598 | /// declarations. |
| 5599 | /// |
| 5600 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 5601 | /// visible at global scope. |
| 5602 | /// |
| 5603 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 5604 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 5605 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5606 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5607 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5608 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5609 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5610 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5611 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 5612 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 5613 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 5614 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5615 | return; |
| 5616 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5617 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5618 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 5619 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 5620 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5621 | // Introduce this declaration into the translation-unit scope |
| 5622 | // and add it to the declaration chain for this identifier, so |
| 5623 | // that (unqualified) name lookup will find it. |
| 5624 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5625 | } else { |
| 5626 | // Queue this declaration so that it will be added to the |
| 5627 | // translation unit scope and identifier's declaration chain |
| 5628 | // once a Sema object is known. |
| 5629 | PreloadedDecls.push_back(D); |
| 5630 | } |
| 5631 | } |
| 5632 | } |
| 5633 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5634 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5635 | if (ID == 0) |
| 5636 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5637 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5638 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5639 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5640 | return 0; |
| 5641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5642 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5643 | ID -= 1; |
| 5644 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 5645 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 5646 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5647 | ModuleFile *M = I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5648 | unsigned Index = ID - M->BaseIdentifierID; |
| 5649 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 5650 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5651 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 5652 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 5653 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 5654 | // unsigned integers. This is important to avoid integer overflow when |
| 5655 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 5656 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 5657 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 5658 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5659 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5660 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5661 | if (DeserializationListener) |
| 5662 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5664 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5665 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5666 | } |
| 5667 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5668 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5669 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 5670 | } |
| 5671 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5672 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 5673 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 5674 | return LocalID; |
| 5675 | |
| 5676 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5677 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 5678 | assert(I != M.IdentifierRemap.end() |
| 5679 | && "Invalid index into identifier index remap"); |
| 5680 | |
| 5681 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5682 | } |
| 5683 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5684 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 5685 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5688 | serialization::SubmoduleID |
| 5689 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 5690 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 5691 | return LocalID; |
| 5692 | |
| 5693 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5694 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 5695 | assert(I != M.SubmoduleRemap.end() |
| 5696 | && "Invalid index into identifier index remap"); |
| 5697 | |
| 5698 | return LocalID + I->second; |
| 5699 | } |
| 5700 | |
| 5701 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 5702 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 5703 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 5704 | return 0; |
| 5705 | } |
| 5706 | |
| 5707 | if (GlobalID > SubmodulesLoaded.size()) { |
| 5708 | Error("submodule ID out of range in AST file"); |
| 5709 | return 0; |
| 5710 | } |
| 5711 | |
| 5712 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 5713 | } |
| 5714 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5715 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5716 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 5717 | } |
| 5718 | |
| 5719 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5720 | if (ID == 0) |
| 5721 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5722 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5723 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5724 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5725 | return Selector(); |
| 5726 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5727 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5728 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5729 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5730 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 5731 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5732 | ModuleFile &M = *I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5733 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5734 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5735 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5736 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5737 | if (DeserializationListener) |
| 5738 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5739 | } |
| 5740 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5741 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5744 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5745 | return DecodeSelector(ID); |
| 5746 | } |
| 5747 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5748 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5749 | // ID 0 (the null selector) is considered an external selector. |
| 5750 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5751 | } |
| 5752 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5753 | serialization::SelectorID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5754 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5755 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 5756 | return LocalID; |
| 5757 | |
| 5758 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5759 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 5760 | assert(I != M.SelectorRemap.end() |
| 5761 | && "Invalid index into identifier index remap"); |
| 5762 | |
| 5763 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5766 | DeclarationName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5767 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5768 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5769 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 5770 | switch (Kind) { |
| 5771 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5772 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5773 | |
| 5774 | case DeclarationName::ObjCZeroArgSelector: |
| 5775 | case DeclarationName::ObjCOneArgSelector: |
| 5776 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5777 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5778 | |
| 5779 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5780 | return Context.DeclarationNames.getCXXConstructorName( |
| 5781 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5782 | |
| 5783 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5784 | return Context.DeclarationNames.getCXXDestructorName( |
| 5785 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5786 | |
| 5787 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5788 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 5789 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5790 | |
| 5791 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5792 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5793 | (OverloadedOperatorKind)Record[Idx++]); |
| 5794 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5795 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5796 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5797 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5798 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5799 | case DeclarationName::CXXUsingDirective: |
| 5800 | return DeclarationName::getUsingDirectiveName(); |
| 5801 | } |
| 5802 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 5803 | llvm_unreachable("Invalid NameKind!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5804 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5805 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5806 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5807 | DeclarationNameLoc &DNLoc, |
| 5808 | DeclarationName Name, |
| 5809 | const RecordData &Record, unsigned &Idx) { |
| 5810 | switch (Name.getNameKind()) { |
| 5811 | case DeclarationName::CXXConstructorName: |
| 5812 | case DeclarationName::CXXDestructorName: |
| 5813 | case DeclarationName::CXXConversionFunctionName: |
| 5814 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5815 | break; |
| 5816 | |
| 5817 | case DeclarationName::CXXOperatorName: |
| 5818 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5819 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5820 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5821 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5822 | break; |
| 5823 | |
| 5824 | case DeclarationName::CXXLiteralOperatorName: |
| 5825 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5826 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5827 | break; |
| 5828 | |
| 5829 | case DeclarationName::Identifier: |
| 5830 | case DeclarationName::ObjCZeroArgSelector: |
| 5831 | case DeclarationName::ObjCOneArgSelector: |
| 5832 | case DeclarationName::ObjCMultiArgSelector: |
| 5833 | case DeclarationName::CXXUsingDirective: |
| 5834 | break; |
| 5835 | } |
| 5836 | } |
| 5837 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5838 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5839 | DeclarationNameInfo &NameInfo, |
| 5840 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5841 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5842 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5843 | DeclarationNameLoc DNLoc; |
| 5844 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5845 | NameInfo.setInfo(DNLoc); |
| 5846 | } |
| 5847 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5848 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5849 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5850 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5851 | unsigned NumTPLists = Record[Idx++]; |
| 5852 | Info.NumTemplParamLists = NumTPLists; |
| 5853 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5854 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5855 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5856 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5857 | } |
| 5858 | } |
| 5859 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5860 | TemplateName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5861 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5862 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5863 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5864 | switch (Kind) { |
| 5865 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5866 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5867 | |
| 5868 | case TemplateName::OverloadedTemplate: { |
| 5869 | unsigned size = Record[Idx++]; |
| 5870 | UnresolvedSet<8> Decls; |
| 5871 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5872 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5873 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5874 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5875 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5876 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5877 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5878 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5879 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5880 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5881 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5882 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5883 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5884 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5885 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5886 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5887 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5888 | GetIdentifierInfo(F, Record, |
| 5889 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5890 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5891 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5892 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5893 | |
| 5894 | case TemplateName::SubstTemplateTemplateParm: { |
| 5895 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5896 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5897 | if (!param) return TemplateName(); |
| 5898 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5899 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5900 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5901 | |
| 5902 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5903 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5904 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5905 | if (!Param) |
| 5906 | return TemplateName(); |
| 5907 | |
| 5908 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5909 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5910 | return TemplateName(); |
| 5911 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5912 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5913 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5914 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5915 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5916 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
| 5919 | TemplateArgument |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5920 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5921 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5922 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5923 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5924 | case TemplateArgument::Null: |
| 5925 | return TemplateArgument(); |
| 5926 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5927 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5928 | case TemplateArgument::Declaration: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5929 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5930 | case TemplateArgument::Integral: { |
| 5931 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5932 | QualType T = readType(F, Record, Idx); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 5933 | return TemplateArgument(Context, Value, T); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5934 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5935 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5936 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5937 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5938 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5939 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5940 | if (unsigned NumExpansions = Record[Idx++]) |
| 5941 | NumTemplateExpansions = NumExpansions - 1; |
| 5942 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5943 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5944 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5945 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5946 | case TemplateArgument::Pack: { |
| 5947 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5948 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5949 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5950 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5951 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5952 | } |
| 5953 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5954 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5955 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5956 | } |
| 5957 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5958 | TemplateParameterList * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5959 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5960 | const RecordData &Record, unsigned &Idx) { |
| 5961 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5962 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5963 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5964 | |
| 5965 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5966 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5967 | Params.reserve(NumParams); |
| 5968 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5969 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5970 | |
| 5971 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5972 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5973 | Params.data(), Params.size(), RAngleLoc); |
| 5974 | return TemplateParams; |
| 5975 | } |
| 5976 | |
| 5977 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5978 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5979 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5980 | ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5981 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5982 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5983 | TemplArgs.reserve(NumTemplateArgs); |
| 5984 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5985 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5988 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5989 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5990 | const RecordData &Record, unsigned &Idx) { |
| 5991 | unsigned NumDecls = Record[Idx++]; |
| 5992 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5993 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5994 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5995 | Set.addDecl(D, AS); |
| 5996 | } |
| 5997 | } |
| 5998 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5999 | CXXBaseSpecifier |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6000 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6001 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6002 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 6003 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 6004 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6005 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6006 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6007 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6008 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6009 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6010 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6011 | Result.setInheritConstructors(inheritConstructors); |
| 6012 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6013 | } |
| 6014 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6015 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6016 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6017 | unsigned &Idx) { |
| 6018 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6019 | unsigned NumInitializers = Record[Idx++]; |
| 6020 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6021 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6022 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6023 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6024 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6025 | bool IsBaseVirtual = false; |
| 6026 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6027 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6028 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6029 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 6030 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6031 | case CTOR_INITIALIZER_BASE: |
| 6032 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6033 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6034 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6035 | |
| 6036 | case CTOR_INITIALIZER_DELEGATING: |
| 6037 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6038 | break; |
| 6039 | |
| 6040 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6041 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6042 | break; |
| 6043 | |
| 6044 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6045 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6046 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6047 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6048 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 6049 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6050 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6051 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 6052 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6053 | bool IsWritten = Record[Idx++]; |
| 6054 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6055 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6056 | if (IsWritten) { |
| 6057 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6058 | } else { |
| 6059 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6060 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 6061 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6062 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6063 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6064 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6065 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6066 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6067 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6068 | LParenLoc, Init, RParenLoc, |
| 6069 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6070 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6071 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 6072 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6073 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6074 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6075 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6076 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6077 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6078 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6079 | MemberOrEllipsisLoc, LParenLoc, |
| 6080 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6081 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6082 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6083 | LParenLoc, Init, RParenLoc, |
| 6084 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6085 | } |
| 6086 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 6087 | if (IsWritten) |
| 6088 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6089 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6090 | } |
| 6091 | } |
| 6092 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6093 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6096 | NestedNameSpecifier * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6097 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6098 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6099 | unsigned N = Record[Idx++]; |
| 6100 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 6101 | for (unsigned I = 0; I != N; ++I) { |
| 6102 | NestedNameSpecifier::SpecifierKind Kind |
| 6103 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6104 | switch (Kind) { |
| 6105 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6106 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6107 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6108 | break; |
| 6109 | } |
| 6110 | |
| 6111 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6112 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6113 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6114 | break; |
| 6115 | } |
| 6116 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6117 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6118 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6119 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6120 | break; |
| 6121 | } |
| 6122 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6123 | case NestedNameSpecifier::TypeSpec: |
| 6124 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6125 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 6126 | if (!T) |
| 6127 | return 0; |
| 6128 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6129 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6130 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6131 | break; |
| 6132 | } |
| 6133 | |
| 6134 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6135 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6136 | // No associated value, and there can't be a prefix. |
| 6137 | break; |
| 6138 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6139 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 6140 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6141 | } |
| 6142 | return NNS; |
| 6143 | } |
| 6144 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6145 | NestedNameSpecifierLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6146 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6147 | unsigned &Idx) { |
| 6148 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6149 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6150 | for (unsigned I = 0; I != N; ++I) { |
| 6151 | NestedNameSpecifier::SpecifierKind Kind |
| 6152 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6153 | switch (Kind) { |
| 6154 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6155 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6156 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6157 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6158 | break; |
| 6159 | } |
| 6160 | |
| 6161 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6162 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6163 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6164 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6165 | break; |
| 6166 | } |
| 6167 | |
| 6168 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6169 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6170 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6171 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6172 | break; |
| 6173 | } |
| 6174 | |
| 6175 | case NestedNameSpecifier::TypeSpec: |
| 6176 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6177 | bool Template = Record[Idx++]; |
| 6178 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 6179 | if (!T) |
| 6180 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6181 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6182 | |
| 6183 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6184 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6185 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 6186 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6187 | break; |
| 6188 | } |
| 6189 | |
| 6190 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6191 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6192 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6193 | break; |
| 6194 | } |
| 6195 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6196 | } |
| 6197 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6198 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6199 | } |
| 6200 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6201 | SourceRange |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6202 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6203 | unsigned &Idx) { |
| 6204 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 6205 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 6206 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6209 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6210 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6211 | unsigned BitWidth = Record[Idx++]; |
| 6212 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 6213 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 6214 | Idx += NumWords; |
| 6215 | return Result; |
| 6216 | } |
| 6217 | |
| 6218 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6219 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6220 | bool isUnsigned = Record[Idx++]; |
| 6221 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 6222 | } |
| 6223 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6224 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6225 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6226 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 6227 | } |
| 6228 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6229 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6230 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6231 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 6232 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6233 | Idx += Len; |
| 6234 | return Result; |
| 6235 | } |
| 6236 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 6237 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 6238 | unsigned &Idx) { |
| 6239 | unsigned Major = Record[Idx++]; |
| 6240 | unsigned Minor = Record[Idx++]; |
| 6241 | unsigned Subminor = Record[Idx++]; |
| 6242 | if (Minor == 0) |
| 6243 | return VersionTuple(Major); |
| 6244 | if (Subminor == 0) |
| 6245 | return VersionTuple(Major, Minor - 1); |
| 6246 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 6247 | } |
| 6248 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6249 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6250 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6251 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6252 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6253 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6254 | } |
| 6255 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6256 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 6257 | return Diag(SourceLocation(), DiagID); |
| 6258 | } |
| 6259 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6260 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6261 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6262 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6263 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6264 | /// \brief Retrieve the identifier table associated with the |
| 6265 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6266 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6267 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6268 | } |
| 6269 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6270 | /// \brief Record that the given ID maps to the given switch-case |
| 6271 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6272 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6273 | assert((*CurrSwitchCaseStmts)[ID] == 0 && |
| 6274 | "Already have a SwitchCase with this ID"); |
| 6275 | (*CurrSwitchCaseStmts)[ID] = SC; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6279 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6280 | assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID"); |
| 6281 | return (*CurrSwitchCaseStmts)[ID]; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6282 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 6283 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6284 | void ASTReader::ClearSwitchCaseIDs() { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6285 | CurrSwitchCaseStmts->clear(); |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6288 | void ASTReader::ReadComments() { |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6289 | std::vector<RawComment *> Comments; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6290 | for (SmallVectorImpl<std::pair<llvm::BitstreamCursor, |
| 6291 | serialization::ModuleFile *> >::iterator |
| 6292 | I = CommentsCursors.begin(), |
| 6293 | E = CommentsCursors.end(); |
| 6294 | I != E; ++I) { |
| 6295 | llvm::BitstreamCursor &Cursor = I->first; |
| 6296 | serialization::ModuleFile &F = *I->second; |
| 6297 | SavedStreamPosition SavedPosition(Cursor); |
| 6298 | |
| 6299 | RecordData Record; |
| 6300 | while (true) { |
| 6301 | unsigned Code = Cursor.ReadCode(); |
| 6302 | if (Code == llvm::bitc::END_BLOCK) |
| 6303 | break; |
| 6304 | |
| 6305 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 6306 | // No known subblocks, always skip them. |
| 6307 | Cursor.ReadSubBlockID(); |
| 6308 | if (Cursor.SkipBlock()) { |
| 6309 | Error("malformed block record in AST file"); |
| 6310 | return; |
| 6311 | } |
| 6312 | continue; |
| 6313 | } |
| 6314 | |
| 6315 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 6316 | Cursor.ReadAbbrevRecord(); |
| 6317 | continue; |
| 6318 | } |
| 6319 | |
| 6320 | // Read a record. |
| 6321 | Record.clear(); |
| 6322 | switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) { |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6323 | case COMMENTS_RAW_COMMENT: { |
| 6324 | unsigned Idx = 0; |
| 6325 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 6326 | RawComment::CommentKind Kind = |
| 6327 | (RawComment::CommentKind) Record[Idx++]; |
| 6328 | bool IsTrailingComment = Record[Idx++]; |
| 6329 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6330 | Comments.push_back(new (Context) RawComment(SR, Kind, |
| 6331 | IsTrailingComment, |
| 6332 | IsAlmostTrailingComment)); |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6333 | break; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6334 | } |
| 6335 | } |
| 6336 | } |
| 6337 | } |
| 6338 | Context.Comments.addCommentsToFront(Comments); |
| 6339 | } |
| 6340 | |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6341 | void ASTReader::finishPendingActions() { |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 6342 | while (!PendingIdentifierInfos.empty() || !PendingDeclChains.empty()) { |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6343 | // If any identifiers with corresponding top-level declarations have |
| 6344 | // been loaded, load those declarations now. |
| 6345 | while (!PendingIdentifierInfos.empty()) { |
| 6346 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 6347 | PendingIdentifierInfos.front().DeclIDs, true); |
| 6348 | PendingIdentifierInfos.pop_front(); |
| 6349 | } |
| 6350 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6351 | // Load pending declaration chains. |
| 6352 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
| 6353 | loadPendingDeclChain(PendingDeclChains[I]); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6354 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6355 | } |
| 6356 | PendingDeclChains.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6357 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6358 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6359 | // If we deserialized any C++ or Objective-C class definitions, any |
| 6360 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 6361 | // that all redeclarations point to the definitions. Note that this can only |
| 6362 | // happen now, after the redeclaration chains have been fully wired. |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6363 | for (llvm::SmallPtrSet<Decl *, 4>::iterator D = PendingDefinitions.begin(), |
| 6364 | DEnd = PendingDefinitions.end(); |
| 6365 | D != DEnd; ++D) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6366 | if (TagDecl *TD = dyn_cast<TagDecl>(*D)) { |
| 6367 | if (const TagType *TagT = dyn_cast<TagType>(TD->TypeForDecl)) { |
| 6368 | // Make sure that the TagType points at the definition. |
| 6369 | const_cast<TagType*>(TagT)->decl = TD; |
| 6370 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6371 | |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6372 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(*D)) { |
| 6373 | for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), |
| 6374 | REnd = RD->redecls_end(); |
| 6375 | R != REnd; ++R) |
| 6376 | cast<CXXRecordDecl>(*R)->DefinitionData = RD->DefinitionData; |
| 6377 | |
| 6378 | } |
| 6379 | |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6380 | continue; |
| 6381 | } |
| 6382 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6383 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(*D)) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6384 | // Make sure that the ObjCInterfaceType points at the definition. |
| 6385 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 6386 | ->Decl = ID; |
| 6387 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6388 | for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), |
| 6389 | REnd = ID->redecls_end(); |
| 6390 | R != REnd; ++R) |
| 6391 | R->Data = ID->Data; |
| 6392 | |
| 6393 | continue; |
| 6394 | } |
| 6395 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6396 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(*D)) { |
| 6397 | for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), |
| 6398 | REnd = PD->redecls_end(); |
| 6399 | R != REnd; ++R) |
| 6400 | R->Data = PD->Data; |
| 6401 | |
| 6402 | continue; |
| 6403 | } |
| 6404 | |
| 6405 | RedeclarableTemplateDecl *RTD |
| 6406 | = cast<RedeclarableTemplateDecl>(*D)->getCanonicalDecl(); |
| 6407 | for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), |
| 6408 | REnd = RTD->redecls_end(); |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6409 | R != REnd; ++R) |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6410 | R->Common = RTD->Common; |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6411 | } |
| 6412 | PendingDefinitions.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6413 | } |
| 6414 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6415 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6416 | assert(NumCurrentElementsDeserializing && |
| 6417 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 6418 | if (NumCurrentElementsDeserializing == 1) { |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6419 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 6420 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 6421 | finishPendingActions(); |
| 6422 | } |
| 6423 | --NumCurrentElementsDeserializing; |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6424 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6425 | if (NumCurrentElementsDeserializing == 0 && |
| 6426 | Consumer && !PassingDeclsToConsumer) { |
| 6427 | // Guard variable to avoid recursively redoing the process of passing |
| 6428 | // decls to consumer. |
| 6429 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 6430 | true); |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6431 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6432 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 6433 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 6434 | // decls to the consumer. |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6435 | Decl *D = InterestingDecls.front(); |
| 6436 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6437 | PassInterestingDeclToConsumer(D); |
| 6438 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6439 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6440 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 6441 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 6442 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 6443 | StringRef isysroot, bool DisableValidation, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6444 | bool DisableStatCache, bool AllowASTWithCompilerErrors) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6445 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 6446 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6447 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Jonathan D. Turner | 1afb661 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 6448 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 6449 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6450 | DisableValidation(DisableValidation), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6451 | DisableStatCache(DisableStatCache), |
| 6452 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6453 | CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), |
| 6454 | NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6455 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6456 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 6457 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 6458 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 6459 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6460 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 6461 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6462 | PassingDeclsToConsumer(false), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6463 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6464 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6465 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6466 | } |
| 6467 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6468 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6469 | for (DeclContextVisibleUpdatesPending::iterator |
| 6470 | I = PendingVisibleUpdates.begin(), |
| 6471 | E = PendingVisibleUpdates.end(); |
| 6472 | I != E; ++I) { |
| 6473 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 6474 | F = I->second.end(); |
| 6475 | J != F; ++J) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 6476 | delete J->first; |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6477 | } |
| 6478 | } |