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 | } |
| 1130 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1131 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1132 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1133 | SrcMgr::FileInfo &FileInfo = |
| 1134 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1135 | FileInfo.NumCreatedFIDs = Record[7]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1136 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1137 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1138 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1139 | const DeclID *FirstDecl = F->FileSortedDecls + Record[8]; |
| 1140 | unsigned NumFileDecls = Record[9]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1141 | if (NumFileDecls) { |
| 1142 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 1143 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1144 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1145 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1146 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1147 | const SrcMgr::ContentCache *ContentCache |
| 1148 | = SourceMgr.getOrCreateContentCache(File); |
| 1149 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1150 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1151 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1152 | Record.clear(); |
| 1153 | unsigned RecCode |
| 1154 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1155 | |
| 1156 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1157 | Error("AST record has invalid code"); |
| 1158 | return Failure; |
| 1159 | } |
| 1160 | |
| 1161 | llvm::MemoryBuffer *Buffer |
| 1162 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1163 | Filename); |
| 1164 | SourceMgr.overrideFileContents(File, Buffer); |
| 1165 | } |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1166 | |
| 1167 | if (Result == Failure) |
| 1168 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1172 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1173 | const char *Name = BlobStart; |
| 1174 | unsigned Offset = Record[0]; |
| 1175 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1176 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1178 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1179 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1180 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1181 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1182 | return Failure; |
| 1183 | } |
| 1184 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1185 | llvm::MemoryBuffer *Buffer |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1186 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1187 | Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1188 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1189 | BaseOffset + Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1190 | |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 1191 | if (strcmp(Name, "<built-in>") == 0 && F->Kind == MK_PCH) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1192 | PCHPredefinesBlock Block = { |
| 1193 | BufferID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1194 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1195 | }; |
| 1196 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1197 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1198 | |
| 1199 | break; |
| 1200 | } |
| 1201 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1202 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1203 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1204 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1205 | ReadSourceLocation(*F, Record[2]), |
| 1206 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1207 | Record[4], |
| 1208 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1209 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1210 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | return Success; |
| 1215 | } |
| 1216 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1217 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1218 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1219 | if (F->ImportLoc.isValid()) |
| 1220 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1221 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1222 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1223 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1224 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1225 | // Main file is the importer. We assume that it is the first entry in the |
| 1226 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1227 | // the main file entry doesn't exist yet. |
| 1228 | // The very first entry is the invalid instantiation loc, which takes up |
| 1229 | // offsets 0 and 1. |
| 1230 | return SourceLocation::getFromRawEncoding(2U); |
| 1231 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1232 | //return F->Loaders[0]->FirstLoc; |
| 1233 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1236 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1237 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1238 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1239 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1240 | unsigned BlockID) { |
| 1241 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1242 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1243 | return Failure; |
| 1244 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1245 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1246 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1247 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1248 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1249 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1250 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1251 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1252 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1253 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1254 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1255 | Cursor.ReadAbbrevRecord(); |
| 1256 | } |
| 1257 | } |
| 1258 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1259 | void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1260 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1261 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1262 | // Keep track of where we are in the stream, then jump back there |
| 1263 | // after reading this macro. |
| 1264 | SavedStreamPosition SavedPosition(Stream); |
| 1265 | |
| 1266 | Stream.JumpToBit(Offset); |
| 1267 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1268 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1269 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1270 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1271 | while (true) { |
| 1272 | unsigned Code = Stream.ReadCode(); |
| 1273 | switch (Code) { |
| 1274 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1275 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1276 | |
| 1277 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1278 | // No known subblocks, always skip them. |
| 1279 | Stream.ReadSubBlockID(); |
| 1280 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1281 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1282 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1283 | } |
| 1284 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1286 | case llvm::bitc::DEFINE_ABBREV: |
| 1287 | Stream.ReadAbbrevRecord(); |
| 1288 | continue; |
| 1289 | default: break; |
| 1290 | } |
| 1291 | |
| 1292 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1293 | const char *BlobStart = 0; |
| 1294 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1295 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1296 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1297 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1298 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1299 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1300 | case PP_MACRO_OBJECT_LIKE: |
| 1301 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1302 | // If we already have a macro, that means that we've hit the end |
| 1303 | // of the definition of the macro we were looking for. We're |
| 1304 | // done. |
| 1305 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1306 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1307 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1308 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1309 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1310 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1311 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1312 | } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1313 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1314 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1315 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1316 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1317 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1318 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1319 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1320 | |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1321 | bool IsPublic = Record[3]; |
| 1322 | unsigned NextIndex = 4; |
| 1323 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1324 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1325 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1326 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1327 | bool isC99VarArgs = Record[NextIndex++]; |
| 1328 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1329 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1330 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1331 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1332 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1333 | |
| 1334 | // Install function-like macro info. |
| 1335 | MI->setIsFunctionLike(); |
| 1336 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1337 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1338 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1339 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | // Finally, install the macro. |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1343 | PP.setMacroInfo(II, MI, /*LoadedFromAST=*/true); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1344 | |
| 1345 | // Remember that we saw this macro last so that we add the tokens that |
| 1346 | // form its body to it. |
| 1347 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1348 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1349 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1350 | Record[NextIndex]) { |
| 1351 | // We have a macro definition. Register the association |
| 1352 | PreprocessedEntityID |
| 1353 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1354 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1355 | PPRec.RegisterMacroDefinition(Macro, |
| 1356 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1357 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1358 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1359 | ++NumMacrosRead; |
| 1360 | break; |
| 1361 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1362 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1363 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1364 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1365 | // erroneous, just pretend we didn't see this. |
| 1366 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1368 | Token Tok; |
| 1369 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1370 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1371 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1372 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1373 | Tok.setIdentifierInfo(II); |
| 1374 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1375 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1376 | Macro->AddTokenToBody(Tok); |
| 1377 | break; |
| 1378 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 1379 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1380 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1383 | PreprocessedEntityID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1384 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1385 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1386 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1387 | assert(I != M.PreprocessedEntityRemap.end() |
| 1388 | && "Invalid index into preprocessed entity index remap"); |
| 1389 | |
| 1390 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1393 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1394 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1395 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1396 | |
| 1397 | HeaderFileInfoTrait::internal_key_type |
| 1398 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1399 | |
| 1400 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1401 | if (strcmp(a, b) == 0) |
| 1402 | return true; |
| 1403 | |
| 1404 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1405 | return false; |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1406 | |
| 1407 | // Determine whether the actual files are equivalent. |
| 1408 | bool Result = false; |
| 1409 | if (llvm::sys::fs::equivalent(a, b, Result)) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1410 | return false; |
| 1411 | |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1412 | return Result; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | std::pair<unsigned, unsigned> |
| 1416 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1417 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1418 | unsigned DataLen = (unsigned) *d++; |
| 1419 | return std::make_pair(KeyLen + 1, DataLen); |
| 1420 | } |
| 1421 | |
| 1422 | HeaderFileInfoTrait::data_type |
| 1423 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1424 | unsigned DataLen) { |
| 1425 | const unsigned char *End = d + DataLen; |
| 1426 | using namespace clang::io; |
| 1427 | HeaderFileInfo HFI; |
| 1428 | unsigned Flags = *d++; |
| 1429 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1430 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1431 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1432 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1433 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1434 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1435 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1436 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1437 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1438 | // The framework offset is 1 greater than the actual offset, |
| 1439 | // since 0 is used as an indicator for "no framework name". |
| 1440 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1441 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1442 | } |
| 1443 | |
| 1444 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1445 | (void)End; |
| 1446 | |
| 1447 | // This HeaderFileInfo was externally loaded. |
| 1448 | HFI.External = true; |
| 1449 | return HFI; |
| 1450 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1451 | |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 1452 | void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F, |
| 1453 | uint64_t LocalOffset, bool Visible) { |
| 1454 | if (Visible) { |
| 1455 | // Note that this identifier has a macro definition. |
| 1456 | II->setHasMacroDefinition(true); |
| 1457 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1458 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1459 | // Adjust the offset to a global offset. |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1460 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1463 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1464 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1465 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1466 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1467 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1468 | // If there was no preprocessor block, skip this file. |
| 1469 | if (!MacroCursor.getBitStreamReader()) |
| 1470 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1471 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1472 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1473 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1474 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1475 | RecordData Record; |
| 1476 | while (true) { |
| 1477 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1478 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1479 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1480 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1481 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1482 | // No known subblocks, always skip them. |
| 1483 | Cursor.ReadSubBlockID(); |
| 1484 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1485 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1486 | return; |
| 1487 | } |
| 1488 | continue; |
| 1489 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1490 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1491 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1492 | Cursor.ReadAbbrevRecord(); |
| 1493 | continue; |
| 1494 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1495 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1496 | // Read a record. |
| 1497 | const char *BlobStart; |
| 1498 | unsigned BlobLen; |
| 1499 | Record.clear(); |
| 1500 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1501 | default: // Default behavior: ignore. |
| 1502 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1503 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1504 | case PP_MACRO_OBJECT_LIKE: |
| 1505 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1506 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1509 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1510 | // Ignore tokens. |
| 1511 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1512 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1513 | } |
| 1514 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1515 | |
| 1516 | // Drain the unread macro-record offsets map. |
| 1517 | while (!UnreadMacroRecordOffsets.empty()) |
| 1518 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1519 | } |
| 1520 | |
| 1521 | void ASTReader::LoadMacroDefinition( |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1522 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1523 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1524 | uint64_t Offset = Pos->second; |
| 1525 | UnreadMacroRecordOffsets.erase(Pos); |
| 1526 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1527 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1528 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1532 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1533 | = UnreadMacroRecordOffsets.find(II); |
| 1534 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1537 | namespace { |
| 1538 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1539 | class IdentifierLookupVisitor { |
| 1540 | StringRef Name; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1541 | unsigned PriorGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1542 | IdentifierInfo *Found; |
| 1543 | public: |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1544 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration) |
| 1545 | : Name(Name), PriorGeneration(PriorGeneration), Found() { } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1546 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1547 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1548 | IdentifierLookupVisitor *This |
| 1549 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1550 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1551 | // If we've already searched this module file, skip it now. |
| 1552 | if (M.Generation <= This->PriorGeneration) |
| 1553 | return true; |
| 1554 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1555 | ASTIdentifierLookupTable *IdTable |
| 1556 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1557 | if (!IdTable) |
| 1558 | return false; |
| 1559 | |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1560 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1561 | M, This->Found); |
| 1562 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1563 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1564 | This->Name.size()); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1565 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1566 | if (Pos == IdTable->end()) |
| 1567 | return false; |
| 1568 | |
| 1569 | // Dereferencing the iterator has the effect of building the |
| 1570 | // IdentifierInfo node and populating it with the various |
| 1571 | // declarations it needs. |
| 1572 | This->Found = *Pos; |
| 1573 | return true; |
| 1574 | } |
| 1575 | |
| 1576 | // \brief Retrieve the identifier info found within the module |
| 1577 | // files. |
| 1578 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1579 | }; |
| 1580 | } |
| 1581 | |
| 1582 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1583 | unsigned PriorGeneration = 0; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1584 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1585 | PriorGeneration = IdentifierGeneration[&II]; |
| 1586 | |
| 1587 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration); |
| 1588 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 1589 | markIdentifierUpToDate(&II); |
| 1590 | } |
| 1591 | |
| 1592 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1593 | if (!II) |
| 1594 | return; |
| 1595 | |
| 1596 | II->setOutOfDate(false); |
| 1597 | |
| 1598 | // Update the generation for this identifier. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1599 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1600 | IdentifierGeneration[II] = CurrentGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1603 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1604 | std::string Filename = filenameStrRef; |
| 1605 | MaybeAddSystemRootToFilename(Filename); |
| 1606 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1607 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1608 | OriginalDir != CurrentDir) { |
| 1609 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1610 | OriginalDir, |
| 1611 | CurrentDir); |
| 1612 | if (!resolved.empty()) |
| 1613 | File = FileMgr.getFile(resolved); |
| 1614 | } |
| 1615 | |
| 1616 | return File; |
| 1617 | } |
| 1618 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1619 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1620 | /// not an absolute path, add the system root to the beginning of the file |
| 1621 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1622 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1623 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1624 | if (!RelocatablePCH) |
| 1625 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1626 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1627 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1628 | return; |
| 1629 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1630 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1631 | // If no system root was given, default to '/' |
| 1632 | Filename.insert(Filename.begin(), '/'); |
| 1633 | return; |
| 1634 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1636 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1637 | if (isysroot[Length - 1] != '/') |
| 1638 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1639 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1640 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1643 | ASTReader::ASTReadResult |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1644 | ASTReader::ReadASTBlock(ModuleFile &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1645 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1646 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1647 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1648 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1649 | return Failure; |
| 1650 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1651 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1652 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1653 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1654 | while (!Stream.AtEndOfStream()) { |
| 1655 | unsigned Code = Stream.ReadCode(); |
| 1656 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1657 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1658 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1659 | return Failure; |
| 1660 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1661 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1662 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1666 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1667 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1668 | // We lazily load the decls block, but we want to set up the |
| 1669 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1670 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1671 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1672 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1673 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1674 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1675 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1676 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1677 | return Failure; |
| 1678 | } |
| 1679 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1680 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1681 | case DECL_UPDATES_BLOCK_ID: |
| 1682 | if (Stream.SkipBlock()) { |
| 1683 | Error("malformed block record in AST file"); |
| 1684 | return Failure; |
| 1685 | } |
| 1686 | break; |
| 1687 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1688 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1689 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1690 | if (!PP.getExternalSource()) |
| 1691 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1692 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1693 | if (Stream.SkipBlock() || |
| 1694 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1695 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1696 | return Failure; |
| 1697 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1698 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1699 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1700 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1701 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1702 | F.PreprocessorDetailCursor = Stream; |
| 1703 | if (Stream.SkipBlock() || |
| 1704 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1705 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1706 | Error("malformed preprocessor detail record in AST file"); |
| 1707 | return Failure; |
| 1708 | } |
| 1709 | F.PreprocessorDetailStartOffset |
| 1710 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1711 | |
| 1712 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 1713 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1714 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1715 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1716 | break; |
| 1717 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1718 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1719 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1720 | case Success: |
| 1721 | break; |
| 1722 | |
| 1723 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1724 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1725 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1726 | |
| 1727 | case IgnorePCH: |
| 1728 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1729 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1730 | break; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1731 | |
| 1732 | case SUBMODULE_BLOCK_ID: |
| 1733 | switch (ReadSubmoduleBlock(F)) { |
| 1734 | case Success: |
| 1735 | break; |
| 1736 | |
| 1737 | case Failure: |
| 1738 | Error("malformed submodule block in AST file"); |
| 1739 | return Failure; |
| 1740 | |
| 1741 | case IgnorePCH: |
| 1742 | return IgnorePCH; |
| 1743 | } |
| 1744 | break; |
| 1745 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1746 | case COMMENTS_BLOCK_ID: { |
| 1747 | llvm::BitstreamCursor C = Stream; |
| 1748 | if (Stream.SkipBlock() || |
| 1749 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 1750 | Error("malformed comments block in AST file"); |
| 1751 | return Failure; |
| 1752 | } |
| 1753 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 1754 | break; |
| 1755 | } |
| 1756 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1757 | default: |
| 1758 | if (!Stream.SkipBlock()) |
| 1759 | break; |
| 1760 | Error("malformed block record in AST file"); |
| 1761 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1762 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1763 | continue; |
| 1764 | } |
| 1765 | |
| 1766 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1767 | Stream.ReadAbbrevRecord(); |
| 1768 | continue; |
| 1769 | } |
| 1770 | |
| 1771 | // Read and process a record. |
| 1772 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1773 | const char *BlobStart = 0; |
| 1774 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1775 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1776 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1777 | default: // Default behavior: ignore. |
| 1778 | break; |
| 1779 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1780 | case METADATA: { |
| 1781 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1782 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1783 | : diag::warn_pch_version_too_new); |
| 1784 | return IgnorePCH; |
| 1785 | } |
| 1786 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1787 | bool hasErrors = Record[5]; |
| 1788 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 1789 | Diag(diag::err_pch_with_compiler_errors); |
| 1790 | return IgnorePCH; |
| 1791 | } |
| 1792 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1793 | RelocatablePCH = Record[4]; |
| 1794 | if (Listener) { |
| 1795 | std::string TargetTriple(BlobStart, BlobLen); |
| 1796 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1797 | return IgnorePCH; |
| 1798 | } |
| 1799 | break; |
| 1800 | } |
| 1801 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1802 | case IMPORTS: { |
| 1803 | // Load each of the imported PCH files. |
| 1804 | unsigned Idx = 0, N = Record.size(); |
| 1805 | while (Idx < N) { |
| 1806 | // Read information about the AST file. |
| 1807 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1808 | unsigned Length = Record[Idx++]; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1809 | SmallString<128> ImportedFile(Record.begin() + Idx, |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1810 | Record.begin() + Idx + Length); |
| 1811 | Idx += Length; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1812 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1813 | // Load the AST file. |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1814 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1815 | case Failure: return Failure; |
| 1816 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1817 | case IgnorePCH: return IgnorePCH; |
| 1818 | case Success: break; |
| 1819 | } |
| 1820 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1821 | break; |
| 1822 | } |
| 1823 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1824 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1825 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1826 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1827 | return Failure; |
| 1828 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1829 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1830 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1831 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1832 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1833 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1834 | if (F.LocalNumTypes > 0) { |
| 1835 | // Introduce the global -> local mapping for types within this module. |
| 1836 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1837 | |
| 1838 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1839 | F.TypeRemap.insertOrReplace( |
| 1840 | std::make_pair(LocalBaseTypeIndex, |
| 1841 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1842 | |
| 1843 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1844 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1845 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1848 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1849 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1850 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1851 | return Failure; |
| 1852 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 1853 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1854 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1855 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1856 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1857 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1858 | if (F.LocalNumDecls > 0) { |
| 1859 | // Introduce the global -> local mapping for declarations within this |
| 1860 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1861 | GlobalDeclMap.insert( |
| 1862 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1863 | |
| 1864 | // Introduce the local -> global mapping for declarations within this |
| 1865 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1866 | F.DeclRemap.insertOrReplace( |
| 1867 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1868 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 1869 | // Introduce the global -> local mapping for declarations within this |
| 1870 | // module. |
| 1871 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 1872 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1873 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1874 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1875 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1878 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1879 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1880 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1881 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1882 | Info.NumLexicalDecls |
| 1883 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1884 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1885 | break; |
| 1886 | } |
| 1887 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1888 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1889 | unsigned Idx = 0; |
| 1890 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 1891 | ASTDeclContextNameLookupTable *Table = |
| 1892 | ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1893 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1894 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1895 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1896 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1897 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1898 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1899 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1900 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1901 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1902 | break; |
| 1903 | } |
| 1904 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1905 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1906 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1907 | return IgnorePCH; |
| 1908 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1909 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1910 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1911 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1912 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1913 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1914 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1915 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1916 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1917 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1918 | |
| 1919 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1920 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1921 | break; |
| 1922 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1923 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1924 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1925 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1926 | return Failure; |
| 1927 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1928 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1929 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1930 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1931 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 1932 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1933 | if (F.LocalNumIdentifiers > 0) { |
| 1934 | // Introduce the global -> local mapping for identifiers within this |
| 1935 | // module. |
| 1936 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 1937 | &F)); |
| 1938 | |
| 1939 | // Introduce the local -> global mapping for identifiers within this |
| 1940 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1941 | F.IdentifierRemap.insertOrReplace( |
| 1942 | std::make_pair(LocalBaseIdentifierID, |
| 1943 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1944 | |
| 1945 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 1946 | + F.LocalNumIdentifiers); |
| 1947 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1948 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1951 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1952 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1953 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1954 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1955 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1956 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1957 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1958 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1959 | break; |
| 1960 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1961 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1962 | TotalNumStatements += Record[0]; |
| 1963 | TotalNumMacros += Record[1]; |
| 1964 | TotalLexicalDeclContexts += Record[2]; |
| 1965 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1966 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1967 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1968 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1969 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1970 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1971 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1972 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1973 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1974 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1975 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1976 | break; |
| 1977 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1978 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 1979 | if (Record.size() % 4 != 0) { |
| 1980 | Error("invalid weak identifiers record"); |
| 1981 | return Failure; |
| 1982 | } |
| 1983 | |
| 1984 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 1985 | // files. This isn't the way to do it :) |
| 1986 | WeakUndeclaredIdentifiers.clear(); |
| 1987 | |
| 1988 | // Translate the weak, undeclared identifiers into global IDs. |
| 1989 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 1990 | WeakUndeclaredIdentifiers.push_back( |
| 1991 | getGlobalIdentifierID(F, Record[I++])); |
| 1992 | WeakUndeclaredIdentifiers.push_back( |
| 1993 | getGlobalIdentifierID(F, Record[I++])); |
| 1994 | WeakUndeclaredIdentifiers.push_back( |
| 1995 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 1996 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 1997 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1998 | break; |
| 1999 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2000 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2001 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2002 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2003 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2004 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2005 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2006 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2007 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2008 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2009 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2010 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2011 | if (F.LocalNumSelectors > 0) { |
| 2012 | // Introduce the global -> local mapping for selectors within this |
| 2013 | // module. |
| 2014 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2015 | |
| 2016 | // Introduce the local -> global mapping for selectors within this |
| 2017 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2018 | F.SelectorRemap.insertOrReplace( |
| 2019 | std::make_pair(LocalBaseSelectorID, |
| 2020 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2021 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2022 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2023 | } |
| 2024 | break; |
| 2025 | } |
| 2026 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2027 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2028 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2029 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2030 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2031 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2032 | F.SelectorLookupTableData + Record[0], |
| 2033 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2034 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2035 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2036 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2037 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2038 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2039 | if (!Record.empty()) { |
| 2040 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2041 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2042 | Record[Idx++])); |
| 2043 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2044 | getRawEncoding()); |
| 2045 | } |
| 2046 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2047 | break; |
| 2048 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2049 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2050 | if (!Record.empty() && Listener) |
| 2051 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2052 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2053 | |
| 2054 | case FILE_SORTED_DECLS: |
| 2055 | F.FileSortedDecls = (const DeclID *)BlobStart; |
| 2056 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2057 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2058 | case SOURCE_LOCATION_OFFSETS: { |
| 2059 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2060 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2061 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2062 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2063 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2064 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2065 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2066 | // we invert it. Because we invert it, though, we need the other end of |
| 2067 | // the range. |
| 2068 | unsigned RangeStart = |
| 2069 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2070 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2071 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2072 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2073 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2074 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2075 | GlobalSLocOffsetMap.insert( |
| 2076 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2077 | - SLocSpaceSize,&F)); |
| 2078 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2079 | // Initialize the remapping table. |
| 2080 | // Invalid stays invalid. |
| 2081 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2082 | // This module. Base was 2 when being compiled. |
| 2083 | F.SLocRemap.insert(std::make_pair(2U, |
| 2084 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2085 | |
| 2086 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2087 | break; |
| 2088 | } |
| 2089 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2090 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2091 | // Additional remapping information. |
| 2092 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2093 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2094 | |
| 2095 | // Continuous range maps we may be updating in our module. |
| 2096 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2097 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2098 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2099 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2100 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2101 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2102 | SubmoduleRemap(F.SubmoduleRemap); |
| 2103 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2104 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2105 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2106 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2107 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2108 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2109 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2110 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2111 | Data += Len; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2112 | ModuleFile *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2113 | if (!OM) { |
| 2114 | Error("SourceLocation remap refers to unknown module"); |
| 2115 | return Failure; |
| 2116 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2117 | |
| 2118 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2119 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2120 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2121 | uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2122 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2123 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2124 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2125 | |
| 2126 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2127 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2128 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2129 | IdentifierRemap.insert( |
| 2130 | std::make_pair(IdentifierIDOffset, |
| 2131 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2132 | PreprocessedEntityRemap.insert( |
| 2133 | std::make_pair(PreprocessedEntityIDOffset, |
| 2134 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2135 | SubmoduleRemap.insert(std::make_pair(SubmoduleIDOffset, |
| 2136 | OM->BaseSubmoduleID - SubmoduleIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2137 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2138 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2139 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2140 | OM->BaseDeclID - DeclIDOffset)); |
| 2141 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2142 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2143 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2144 | |
| 2145 | // Global -> local mappings. |
| 2146 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2147 | } |
| 2148 | break; |
| 2149 | } |
| 2150 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2151 | case SOURCE_MANAGER_LINE_TABLE: |
| 2152 | if (ParseLineTable(F, Record)) |
| 2153 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2154 | break; |
| 2155 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2156 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2157 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2158 | F.LocalNumSLocFileEntries = Record[0]; |
| 2159 | break; |
| 2160 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2161 | case SOURCE_LOCATION_PRELOADS: { |
| 2162 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2163 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2164 | if (!F.PreloadSLocEntries.empty()) { |
| 2165 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2166 | return Failure; |
| 2167 | } |
| 2168 | |
| 2169 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2170 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2171 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2172 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2173 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2174 | if (!DisableStatCache) { |
| 2175 | ASTStatCache *MyStatCache = |
| 2176 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2177 | (const unsigned char *)BlobStart, |
| 2178 | NumStatHits, NumStatMisses); |
| 2179 | FileMgr.addStatCache(MyStatCache); |
| 2180 | F.StatCache = MyStatCache; |
| 2181 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2182 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2183 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2184 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2185 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2186 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2187 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2188 | break; |
| 2189 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2190 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2191 | if (Record.size() % 3 != 0) { |
| 2192 | Error("Invalid VTABLE_USES record"); |
| 2193 | return Failure; |
| 2194 | } |
| 2195 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2196 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2197 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2198 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2199 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2200 | |
| 2201 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2202 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2203 | VTableUses.push_back( |
| 2204 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2205 | VTableUses.push_back(Record[Idx++]); |
| 2206 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2207 | break; |
| 2208 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2209 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2210 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2211 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2212 | break; |
| 2213 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2214 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2215 | if (PendingInstantiations.size() % 2 != 0) { |
| 2216 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2217 | return Failure; |
| 2218 | } |
| 2219 | |
| 2220 | // Later lists of pending instantiations overwrite earlier ones. |
| 2221 | // FIXME: This is most certainly wrong for modules. |
| 2222 | PendingInstantiations.clear(); |
| 2223 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2224 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2225 | PendingInstantiations.push_back( |
| 2226 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2227 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2228 | break; |
| 2229 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2230 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2231 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2232 | // FIXME: Modules will have some trouble with this. |
| 2233 | SemaDeclRefs.clear(); |
| 2234 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2235 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2236 | break; |
| 2237 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2238 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2239 | // 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] | 2240 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2241 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2242 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2243 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2244 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2245 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2246 | case ORIGINAL_FILE_ID: |
| 2247 | OriginalFileID = FileID::get(Record[0]); |
| 2248 | break; |
| 2249 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2250 | case ORIGINAL_PCH_DIR: |
| 2251 | // The primary AST will be the last to get here, so it will be the one |
| 2252 | // that's used. |
| 2253 | OriginalDir.assign(BlobStart, BlobLen); |
| 2254 | break; |
| 2255 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2256 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2257 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2258 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2259 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2260 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2261 | return IgnorePCH; |
| 2262 | } |
| 2263 | break; |
| 2264 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2265 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2266 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2267 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2268 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2269 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2270 | |
| 2271 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2272 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2273 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2274 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2275 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2276 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2277 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2278 | StartingID |
| 2279 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2280 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2281 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2282 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2283 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2284 | // Introduce the global -> local mapping for preprocessed entities in |
| 2285 | // this module. |
| 2286 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2287 | |
| 2288 | // Introduce the local -> global mapping for preprocessed entities in |
| 2289 | // this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2290 | F.PreprocessedEntityRemap.insertOrReplace( |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2291 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2292 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2293 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2294 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2295 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2298 | case DECL_UPDATE_OFFSETS: { |
| 2299 | if (Record.size() % 2 != 0) { |
| 2300 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2301 | return Failure; |
| 2302 | } |
| 2303 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2304 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2305 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2306 | break; |
| 2307 | } |
| 2308 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2309 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2310 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2311 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2312 | return Failure; |
| 2313 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2314 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2315 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2316 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2317 | break; |
| 2318 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2319 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2320 | case OBJC_CATEGORIES_MAP: { |
| 2321 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2322 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2323 | return Failure; |
| 2324 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2325 | |
| 2326 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 2327 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2328 | break; |
| 2329 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2330 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2331 | case OBJC_CATEGORIES: |
| 2332 | F.ObjCCategories.swap(Record); |
| 2333 | break; |
| 2334 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2335 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2336 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2337 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2338 | return Failure; |
| 2339 | } |
| 2340 | |
| 2341 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2342 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2343 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2344 | break; |
| 2345 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2346 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2347 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2348 | if (Record.size() % 2 != 0) { |
| 2349 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2350 | return Failure; |
| 2351 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2352 | |
| 2353 | if (F.PragmaDiagMappings.empty()) |
| 2354 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2355 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2356 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2357 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2358 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2359 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2360 | case CUDA_SPECIAL_DECL_REFS: |
| 2361 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2362 | // FIXME: Modules will have trouble with this. |
| 2363 | CUDASpecialDeclRefs.clear(); |
| 2364 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2365 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2366 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2367 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2368 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2369 | F.HeaderFileInfoTableData = BlobStart; |
| 2370 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2371 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2372 | if (Record[0]) { |
| 2373 | F.HeaderFileInfoTable |
| 2374 | = HeaderFileInfoLookupTable::Create( |
| 2375 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2376 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2377 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2378 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2379 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2380 | |
| 2381 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2382 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2383 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2384 | } |
| 2385 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2388 | case FP_PRAGMA_OPTIONS: |
| 2389 | // Later tables overwrite earlier ones. |
| 2390 | FPPragmaOptions.swap(Record); |
| 2391 | break; |
| 2392 | |
| 2393 | case OPENCL_EXTENSIONS: |
| 2394 | // Later tables overwrite earlier ones. |
| 2395 | OpenCLExtensions.swap(Record); |
| 2396 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2397 | |
| 2398 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2399 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2400 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2401 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2402 | |
| 2403 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2404 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2405 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2406 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2407 | |
| 2408 | case IMPORTED_MODULES: { |
| 2409 | if (F.Kind != MK_Module) { |
| 2410 | // If we aren't loading a module (which has its own exports), make |
| 2411 | // all of the imported modules visible. |
| 2412 | // FIXME: Deal with macros-only imports. |
| 2413 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2414 | if (unsigned GlobalID = getGlobalSubmoduleID(F, Record[I])) |
| 2415 | ImportedModules.push_back(GlobalID); |
| 2416 | } |
| 2417 | } |
| 2418 | break; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2419 | } |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2420 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2421 | case LOCAL_REDECLARATIONS: { |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2422 | F.RedeclarationChains.swap(Record); |
| 2423 | break; |
| 2424 | } |
| 2425 | |
| 2426 | case LOCAL_REDECLARATIONS_MAP: { |
| 2427 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 2428 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2429 | return Failure; |
| 2430 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2431 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2432 | F.LocalNumRedeclarationsInMap = Record[0]; |
| 2433 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2434 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2435 | } |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 2436 | |
| 2437 | case MERGED_DECLARATIONS: { |
| 2438 | for (unsigned Idx = 0; Idx < Record.size(); /* increment in loop */) { |
| 2439 | GlobalDeclID CanonID = getGlobalDeclID(F, Record[Idx++]); |
| 2440 | SmallVectorImpl<GlobalDeclID> &Decls = StoredMergedDecls[CanonID]; |
| 2441 | for (unsigned N = Record[Idx++]; N > 0; --N) |
| 2442 | Decls.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2443 | } |
| 2444 | break; |
| 2445 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2446 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2447 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2448 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2449 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2452 | ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2453 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2454 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2455 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2456 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2457 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2458 | if (Code == llvm::bitc::END_BLOCK || |
| 2459 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2460 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2461 | Error("incorrectly-formatted source location entry in AST file"); |
| 2462 | return Failure; |
| 2463 | } |
| 2464 | |
| 2465 | RecordData Record; |
| 2466 | const char *BlobStart; |
| 2467 | unsigned BlobLen; |
| 2468 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2469 | default: |
| 2470 | Error("incorrectly-formatted source location entry in AST file"); |
| 2471 | return Failure; |
| 2472 | |
| 2473 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2474 | // If the buffer was overridden, the file need not exist. |
| 2475 | if (Record[6]) |
| 2476 | break; |
| 2477 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2478 | StringRef Filename(BlobStart, BlobLen); |
| 2479 | const FileEntry *File = getFileEntry(Filename); |
| 2480 | |
| 2481 | if (File == 0) { |
| 2482 | std::string ErrorStr = "could not find file '"; |
| 2483 | ErrorStr += Filename; |
| 2484 | ErrorStr += "' referenced by AST file"; |
| 2485 | Error(ErrorStr.c_str()); |
| 2486 | return IgnorePCH; |
| 2487 | } |
| 2488 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2489 | if (Record.size() < 7) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2490 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2491 | return Failure; |
| 2492 | } |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2493 | |
| 2494 | off_t StoredSize = (off_t)Record[4]; |
| 2495 | time_t StoredTime = (time_t)Record[5]; |
| 2496 | |
| 2497 | // Check if there was a request to override the contents of the file |
| 2498 | // that was part of the precompiled header. Overridding such a file |
| 2499 | // can lead to problems when lexing using the source locations from the |
| 2500 | // PCH. |
| 2501 | SourceManager &SM = getSourceManager(); |
| 2502 | if (SM.isFileOverridden(File)) { |
| 2503 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2504 | // After emitting the diagnostic, recover by disabling the override so |
| 2505 | // that the original file will be used. |
| 2506 | SM.disableFileContentsOverride(File); |
| 2507 | // The FileEntry is a virtual file entry with the size of the contents |
| 2508 | // that would override the original contents. Set it to the original's |
| 2509 | // size/time. |
| 2510 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2511 | StoredSize, StoredTime); |
| 2512 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2513 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2514 | // The stat info from the FileEntry came from the cached stat |
| 2515 | // info of the PCH, so we cannot trust it. |
| 2516 | struct stat StatBuf; |
| 2517 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2518 | StatBuf.st_size = File->getSize(); |
| 2519 | StatBuf.st_mtime = File->getModificationTime(); |
| 2520 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2521 | |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2522 | if ((StoredSize != StatBuf.st_size |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2523 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2524 | // In our regression testing, the Windows file system seems to |
| 2525 | // have inconsistent modification times that sometimes |
| 2526 | // erroneously trigger this error-handling path. |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2527 | || StoredTime != StatBuf.st_mtime |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2528 | #endif |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2529 | )) { |
| 2530 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2531 | return IgnorePCH; |
| 2532 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2533 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2534 | break; |
| 2535 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | return Success; |
| 2540 | } |
| 2541 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2542 | void ASTReader::makeNamesVisible(const HiddenNames &Names) { |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2543 | for (unsigned I = 0, N = Names.size(); I != N; ++I) { |
| 2544 | if (Decl *D = Names[I].dyn_cast<Decl *>()) |
Douglas Gregor | f143ffc | 2012-01-06 16:22:39 +0000 | [diff] [blame] | 2545 | D->Hidden = false; |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2546 | else { |
| 2547 | IdentifierInfo *II = Names[I].get<IdentifierInfo *>(); |
| 2548 | if (!II->hasMacroDefinition()) { |
| 2549 | II->setHasMacroDefinition(true); |
| 2550 | if (DeserializationListener) |
| 2551 | DeserializationListener->MacroVisible(II); |
| 2552 | } |
| 2553 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2554 | } |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2557 | void ASTReader::makeModuleVisible(Module *Mod, |
| 2558 | Module::NameVisibilityKind NameVisibility) { |
| 2559 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 2560 | llvm::SmallVector<Module *, 4> Stack; |
| 2561 | Stack.push_back(Mod); |
| 2562 | while (!Stack.empty()) { |
| 2563 | Mod = Stack.back(); |
| 2564 | Stack.pop_back(); |
| 2565 | |
| 2566 | if (NameVisibility <= Mod->NameVisibility) { |
| 2567 | // This module already has this level of visibility (or greater), so |
| 2568 | // there is nothing more to do. |
| 2569 | continue; |
| 2570 | } |
| 2571 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2572 | if (!Mod->isAvailable()) { |
| 2573 | // Modules that aren't available cannot be made visible. |
| 2574 | continue; |
| 2575 | } |
| 2576 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2577 | // Update the module's name visibility. |
| 2578 | Mod->NameVisibility = NameVisibility; |
| 2579 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2580 | // If we've already deserialized any names from this module, |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2581 | // mark them as visible. |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2582 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 2583 | if (Hidden != HiddenNamesMap.end()) { |
| 2584 | makeNamesVisible(Hidden->second); |
| 2585 | HiddenNamesMap.erase(Hidden); |
| 2586 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2587 | |
| 2588 | // Push any non-explicit submodules onto the stack to be marked as |
| 2589 | // visible. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2590 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2591 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2592 | Sub != SubEnd; ++Sub) { |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2593 | if (!(*Sub)->IsExplicit && Visited.insert(*Sub)) |
| 2594 | Stack.push_back(*Sub); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2595 | } |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2596 | |
| 2597 | // Push any exported modules onto the stack to be marked as visible. |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2598 | bool AnyWildcard = false; |
| 2599 | bool UnrestrictedWildcard = false; |
| 2600 | llvm::SmallVector<Module *, 4> WildcardRestrictions; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2601 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
| 2602 | Module *Exported = Mod->Exports[I].getPointer(); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2603 | if (!Mod->Exports[I].getInt()) { |
| 2604 | // Export a named module directly; no wildcards involved. |
| 2605 | if (Visited.insert(Exported)) |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2606 | Stack.push_back(Exported); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2607 | |
| 2608 | continue; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2609 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2610 | |
| 2611 | // Wildcard export: export all of the imported modules that match |
| 2612 | // the given pattern. |
| 2613 | AnyWildcard = true; |
| 2614 | if (UnrestrictedWildcard) |
| 2615 | continue; |
| 2616 | |
| 2617 | if (Module *Restriction = Mod->Exports[I].getPointer()) |
| 2618 | WildcardRestrictions.push_back(Restriction); |
| 2619 | else { |
| 2620 | WildcardRestrictions.clear(); |
| 2621 | UnrestrictedWildcard = true; |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | // If there were any wildcards, push any imported modules that were |
| 2626 | // re-exported by the wildcard restriction. |
| 2627 | if (!AnyWildcard) |
| 2628 | continue; |
| 2629 | |
| 2630 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
| 2631 | Module *Imported = Mod->Imports[I]; |
| 2632 | if (Visited.count(Imported)) |
| 2633 | continue; |
| 2634 | |
| 2635 | bool Acceptable = UnrestrictedWildcard; |
| 2636 | if (!Acceptable) { |
| 2637 | // Check whether this module meets one of the restrictions. |
| 2638 | for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { |
| 2639 | Module *Restriction = WildcardRestrictions[R]; |
| 2640 | if (Imported == Restriction || Imported->isSubModuleOf(Restriction)) { |
| 2641 | Acceptable = true; |
| 2642 | break; |
| 2643 | } |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | if (!Acceptable) |
| 2648 | continue; |
| 2649 | |
| 2650 | Visited.insert(Imported); |
| 2651 | Stack.push_back(Imported); |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2652 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2656 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2657 | ModuleKind Type) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2658 | // Bump the generation number. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2659 | unsigned PreviousGeneration = CurrentGeneration++; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2660 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2661 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2662 | case Failure: return Failure; |
| 2663 | case IgnorePCH: return IgnorePCH; |
| 2664 | case Success: break; |
| 2665 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2666 | |
| 2667 | // 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] | 2668 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2669 | // Check the predefines buffers. |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 2670 | if (!DisableValidation && Type == MK_PCH && |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 2671 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2672 | // if DisableValidation is true, defines that were set on command-line |
| 2673 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2674 | CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2675 | return IgnorePCH; |
| 2676 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2677 | // Mark all of the identifiers in the identifier table as being out of date, |
| 2678 | // so that various accessors know to check the loaded modules when the |
| 2679 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2680 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2681 | IdEnd = PP.getIdentifierTable().end(); |
| 2682 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2683 | Id->second->setOutOfDate(true); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2684 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2685 | // Resolve any unresolved module exports. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2686 | for (unsigned I = 0, N = UnresolvedModuleImportExports.size(); I != N; ++I) { |
| 2687 | UnresolvedModuleImportExport &Unresolved = UnresolvedModuleImportExports[I]; |
| 2688 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2689 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 2690 | |
| 2691 | if (Unresolved.IsImport) { |
| 2692 | if (ResolvedMod) |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2693 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2694 | continue; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2695 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2696 | |
| 2697 | if (ResolvedMod || Unresolved.IsWildcard) |
| 2698 | Unresolved.Mod->Exports.push_back( |
| 2699 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2700 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2701 | UnresolvedModuleImportExports.clear(); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2703 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2704 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2705 | if (DeserializationListener) |
| 2706 | DeserializationListener->ReaderInitialized(this); |
| 2707 | |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2708 | if (!OriginalFileID.isInvalid()) { |
| 2709 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
| 2710 | + OriginalFileID.getOpaqueValue() - 1); |
| 2711 | |
| 2712 | // If this AST file is a precompiled preamble, then set the preamble file ID |
| 2713 | // of the source manager to the file source file from which the preamble was |
| 2714 | // built. |
| 2715 | if (Type == MK_Preamble) { |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2716 | SourceMgr.setPreambleFileID(OriginalFileID); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2717 | } else if (Type == MK_MainFile) { |
| 2718 | SourceMgr.setMainFileID(OriginalFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2719 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2722 | // For any Objective-C class definitions we have already loaded, make sure |
| 2723 | // that we load any additional categories. |
| 2724 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 2725 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 2726 | ObjCClassesLoaded[I], |
| 2727 | PreviousGeneration); |
| 2728 | } |
| 2729 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2730 | return Success; |
| 2731 | } |
| 2732 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2733 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2734 | ModuleKind Type, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2735 | ModuleFile *ImportedBy) { |
| 2736 | ModuleFile *M; |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2737 | bool NewModule; |
| 2738 | std::string ErrorStr; |
| 2739 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2740 | CurrentGeneration, ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2741 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2742 | if (!M) { |
| 2743 | // We couldn't load the module. |
| 2744 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2745 | + ErrorStr; |
| 2746 | Error(Msg); |
| 2747 | return Failure; |
| 2748 | } |
| 2749 | |
| 2750 | if (!NewModule) { |
| 2751 | // We've already loaded this module. |
| 2752 | return Success; |
| 2753 | } |
| 2754 | |
| 2755 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2756 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2757 | if (FileName != "-") { |
| 2758 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2759 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2760 | } |
| 2761 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2762 | ModuleFile &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2763 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2764 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2765 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2766 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2767 | // Sniff for the signature. |
| 2768 | if (Stream.Read(8) != 'C' || |
| 2769 | Stream.Read(8) != 'P' || |
| 2770 | Stream.Read(8) != 'C' || |
| 2771 | Stream.Read(8) != 'H') { |
| 2772 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2773 | return Failure; |
| 2774 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2775 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2776 | while (!Stream.AtEndOfStream()) { |
| 2777 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2778 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2779 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2780 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2781 | return Failure; |
| 2782 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2783 | |
| 2784 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2785 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2786 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2787 | switch (BlockID) { |
| 2788 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2789 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2790 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2791 | return Failure; |
| 2792 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2793 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2794 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2795 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2796 | case Success: |
| 2797 | break; |
| 2798 | |
| 2799 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2800 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2801 | |
| 2802 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2803 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2804 | // AST block, skipping subblocks, to see if there are other |
| 2805 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2806 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2807 | // FIXME: We can't clear loaded slocentries anymore. |
| 2808 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2809 | |
| 2810 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2811 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2812 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2813 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2814 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2815 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2816 | break; |
| 2817 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2818 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2819 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2820 | return Failure; |
| 2821 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2822 | break; |
| 2823 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2824 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2825 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2826 | // 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] | 2827 | // bits of all files we've seen. |
| 2828 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2829 | TotalModulesSizeInBits += F.SizeInBits; |
| 2830 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2831 | |
| 2832 | // Make sure that the files this module was built against are still available. |
| 2833 | if (!DisableValidation) { |
| 2834 | switch(validateFileEntries(*M)) { |
| 2835 | case Failure: return Failure; |
| 2836 | case IgnorePCH: return IgnorePCH; |
| 2837 | case Success: break; |
| 2838 | } |
| 2839 | } |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2840 | |
| 2841 | // Preload SLocEntries. |
| 2842 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2843 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Argyrios Kyrtzidis | ac1ffcc | 2011-09-19 20:39:54 +0000 | [diff] [blame] | 2844 | // Load it through the SourceManager and don't call ReadSLocEntryRecord() |
| 2845 | // directly because the entry may have already been loaded in which case |
| 2846 | // calling ReadSLocEntryRecord() directly would trigger an assertion in |
| 2847 | // SourceManager. |
| 2848 | SourceMgr.getLoadedSLocEntryByID(Index); |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2851 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2852 | return Success; |
| 2853 | } |
| 2854 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2855 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2856 | // If there's a listener, notify them that we "read" the translation unit. |
| 2857 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2858 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2859 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2860 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2861 | // Make sure we load the declaration update records for the translation unit, |
| 2862 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2863 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2864 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2865 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2866 | // FIXME: Find a better way to deal with collisions between these |
| 2867 | // built-in types. Right now, we just ignore the problem. |
| 2868 | |
| 2869 | // Load the special types. |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 2870 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2871 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2872 | if (!Context.CFConstantStringTypeDecl) |
| 2873 | Context.setCFConstantStringType(GetType(String)); |
| 2874 | } |
| 2875 | |
| 2876 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2877 | QualType FileType = GetType(File); |
| 2878 | if (FileType.isNull()) { |
| 2879 | Error("FILE type is NULL"); |
| 2880 | return; |
| 2881 | } |
| 2882 | |
| 2883 | if (!Context.FILEDecl) { |
| 2884 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2885 | Context.setFILEDecl(Typedef->getDecl()); |
| 2886 | else { |
| 2887 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2888 | if (!Tag) { |
| 2889 | Error("Invalid FILE type in AST file"); |
| 2890 | return; |
| 2891 | } |
| 2892 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2893 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2894 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2895 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2896 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2897 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2898 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2899 | if (Jmp_bufType.isNull()) { |
| 2900 | Error("jmp_buf type is NULL"); |
| 2901 | return; |
| 2902 | } |
| 2903 | |
| 2904 | if (!Context.jmp_bufDecl) { |
| 2905 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2906 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2907 | else { |
| 2908 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2909 | if (!Tag) { |
| 2910 | Error("Invalid jmp_buf type in AST file"); |
| 2911 | return; |
| 2912 | } |
| 2913 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2914 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2915 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2916 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2917 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2918 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2919 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2920 | if (Sigjmp_bufType.isNull()) { |
| 2921 | Error("sigjmp_buf type is NULL"); |
| 2922 | return; |
| 2923 | } |
| 2924 | |
| 2925 | if (!Context.sigjmp_bufDecl) { |
| 2926 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2927 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2928 | else { |
| 2929 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2930 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2931 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2932 | } |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | if (unsigned ObjCIdRedef |
| 2937 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2938 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2939 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2940 | } |
| 2941 | |
| 2942 | if (unsigned ObjCClassRedef |
| 2943 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2944 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2945 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2946 | } |
| 2947 | |
| 2948 | if (unsigned ObjCSelRedef |
| 2949 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2950 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2951 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2952 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 2953 | |
| 2954 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 2955 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 2956 | if (Ucontext_tType.isNull()) { |
| 2957 | Error("ucontext_t type is NULL"); |
| 2958 | return; |
| 2959 | } |
| 2960 | |
| 2961 | if (!Context.ucontext_tDecl) { |
| 2962 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 2963 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 2964 | else { |
| 2965 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 2966 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 2967 | Context.setucontext_tDecl(Tag->getDecl()); |
| 2968 | } |
| 2969 | } |
| 2970 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2971 | } |
| 2972 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2973 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2974 | |
| 2975 | // If there were any CUDA special declarations, deserialize them. |
| 2976 | if (!CUDASpecialDeclRefs.empty()) { |
| 2977 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2978 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2979 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2980 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2981 | |
| 2982 | // Re-export any modules that were imported by a non-module AST file. |
| 2983 | for (unsigned I = 0, N = ImportedModules.size(); I != N; ++I) { |
| 2984 | if (Module *Imported = getSubmodule(ImportedModules[I])) |
| 2985 | makeModuleVisible(Imported, Module::AllVisible); |
| 2986 | } |
| 2987 | ImportedModules.clear(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2988 | } |
| 2989 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2990 | void ASTReader::finalizeForWriting() { |
| 2991 | for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(), |
| 2992 | HiddenEnd = HiddenNamesMap.end(); |
| 2993 | Hidden != HiddenEnd; ++Hidden) { |
| 2994 | makeNamesVisible(Hidden->second); |
| 2995 | } |
| 2996 | HiddenNamesMap.clear(); |
| 2997 | } |
| 2998 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2999 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3000 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3001 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3002 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3003 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3004 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3005 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3006 | std::string ErrStr; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 3007 | OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3008 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3009 | if (!Buffer) { |
Kaelyn Uhrain | da01f62 | 2012-06-20 00:36:03 +0000 | [diff] [blame] | 3010 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3011 | return std::string(); |
| 3012 | } |
| 3013 | |
| 3014 | // Initialize the stream |
| 3015 | llvm::BitstreamReader StreamFile; |
| 3016 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3017 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3018 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3019 | Stream.init(StreamFile); |
| 3020 | |
| 3021 | // Sniff for the signature. |
| 3022 | if (Stream.Read(8) != 'C' || |
| 3023 | Stream.Read(8) != 'P' || |
| 3024 | Stream.Read(8) != 'C' || |
| 3025 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3026 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3027 | return std::string(); |
| 3028 | } |
| 3029 | |
| 3030 | RecordData Record; |
| 3031 | while (!Stream.AtEndOfStream()) { |
| 3032 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3033 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3034 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3035 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3036 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3037 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3038 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3039 | case AST_BLOCK_ID: |
| 3040 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3041 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3042 | return std::string(); |
| 3043 | } |
| 3044 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3045 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3046 | default: |
| 3047 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3048 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3049 | return std::string(); |
| 3050 | } |
| 3051 | break; |
| 3052 | } |
| 3053 | continue; |
| 3054 | } |
| 3055 | |
| 3056 | if (Code == llvm::bitc::END_BLOCK) { |
| 3057 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3058 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3059 | return std::string(); |
| 3060 | } |
| 3061 | continue; |
| 3062 | } |
| 3063 | |
| 3064 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3065 | Stream.ReadAbbrevRecord(); |
| 3066 | continue; |
| 3067 | } |
| 3068 | |
| 3069 | Record.clear(); |
| 3070 | const char *BlobStart = 0; |
| 3071 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3072 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3073 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3074 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3075 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3076 | |
| 3077 | return std::string(); |
| 3078 | } |
| 3079 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3080 | ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3081 | // Enter the submodule block. |
| 3082 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 3083 | Error("malformed submodule block record in AST file"); |
| 3084 | return Failure; |
| 3085 | } |
| 3086 | |
| 3087 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3088 | bool First = true; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3089 | Module *CurrentModule = 0; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3090 | RecordData Record; |
| 3091 | while (true) { |
| 3092 | unsigned Code = F.Stream.ReadCode(); |
| 3093 | if (Code == llvm::bitc::END_BLOCK) { |
| 3094 | if (F.Stream.ReadBlockEnd()) { |
| 3095 | Error("error at end of submodule block in AST file"); |
| 3096 | return Failure; |
| 3097 | } |
| 3098 | return Success; |
| 3099 | } |
| 3100 | |
| 3101 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3102 | // No known subblocks, always skip them. |
| 3103 | F.Stream.ReadSubBlockID(); |
| 3104 | if (F.Stream.SkipBlock()) { |
| 3105 | Error("malformed block record in AST file"); |
| 3106 | return Failure; |
| 3107 | } |
| 3108 | continue; |
| 3109 | } |
| 3110 | |
| 3111 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3112 | F.Stream.ReadAbbrevRecord(); |
| 3113 | continue; |
| 3114 | } |
| 3115 | |
| 3116 | // Read a record. |
| 3117 | const char *BlobStart; |
| 3118 | unsigned BlobLen; |
| 3119 | Record.clear(); |
| 3120 | switch (F.Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 3121 | default: // Default behavior: ignore. |
| 3122 | break; |
| 3123 | |
| 3124 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3125 | if (First) { |
| 3126 | Error("missing submodule metadata record at beginning of block"); |
| 3127 | return Failure; |
| 3128 | } |
| 3129 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3130 | if (Record.size() < 7) { |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3131 | Error("malformed module definition"); |
| 3132 | return Failure; |
| 3133 | } |
| 3134 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3135 | StringRef Name(BlobStart, BlobLen); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3136 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); |
| 3137 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); |
| 3138 | bool IsFramework = Record[2]; |
| 3139 | bool IsExplicit = Record[3]; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3140 | bool IsSystem = Record[4]; |
| 3141 | bool InferSubmodules = Record[5]; |
| 3142 | bool InferExplicitSubmodules = Record[6]; |
| 3143 | bool InferExportWildcard = Record[7]; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3144 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3145 | Module *ParentModule = 0; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3146 | if (Parent) |
| 3147 | ParentModule = getSubmodule(Parent); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3148 | |
| 3149 | // Retrieve this (sub)module from the module map, creating it if |
| 3150 | // necessary. |
| 3151 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, |
| 3152 | IsFramework, |
| 3153 | IsExplicit).first; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3154 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 3155 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 3156 | SubmodulesLoaded[GlobalIndex]) { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3157 | Error("too many submodules"); |
| 3158 | return Failure; |
| 3159 | } |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3160 | |
Douglas Gregor | 305dc3e | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 3161 | CurrentModule->IsFromModuleFile = true; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3162 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3163 | CurrentModule->InferSubmodules = InferSubmodules; |
| 3164 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 3165 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3166 | if (DeserializationListener) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3167 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3168 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3169 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3170 | break; |
| 3171 | } |
| 3172 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3173 | case SUBMODULE_UMBRELLA_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3174 | if (First) { |
| 3175 | Error("missing submodule metadata record at beginning of block"); |
| 3176 | return Failure; |
| 3177 | } |
| 3178 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3179 | if (!CurrentModule) |
| 3180 | break; |
| 3181 | |
| 3182 | StringRef FileName(BlobStart, BlobLen); |
| 3183 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) { |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3184 | if (!CurrentModule->getUmbrellaHeader()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3185 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3186 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3187 | Error("mismatched umbrella headers in submodule"); |
| 3188 | return Failure; |
| 3189 | } |
| 3190 | } |
| 3191 | break; |
| 3192 | } |
| 3193 | |
| 3194 | case SUBMODULE_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3195 | if (First) { |
| 3196 | Error("missing submodule metadata record at beginning of block"); |
| 3197 | return Failure; |
| 3198 | } |
| 3199 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3200 | if (!CurrentModule) |
| 3201 | break; |
| 3202 | |
| 3203 | // FIXME: Be more lazy about this! |
| 3204 | StringRef FileName(BlobStart, BlobLen); |
| 3205 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3206 | if (std::find(CurrentModule->Headers.begin(), |
| 3207 | CurrentModule->Headers.end(), |
| 3208 | File) == CurrentModule->Headers.end()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3209 | ModMap.addHeader(CurrentModule, File); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3210 | } |
| 3211 | break; |
| 3212 | } |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3213 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3214 | case SUBMODULE_UMBRELLA_DIR: { |
| 3215 | if (First) { |
| 3216 | Error("missing submodule metadata record at beginning of block"); |
| 3217 | return Failure; |
| 3218 | } |
| 3219 | |
| 3220 | if (!CurrentModule) |
| 3221 | break; |
| 3222 | |
| 3223 | StringRef DirName(BlobStart, BlobLen); |
| 3224 | if (const DirectoryEntry *Umbrella |
| 3225 | = PP.getFileManager().getDirectory(DirName)) { |
| 3226 | if (!CurrentModule->getUmbrellaDir()) |
| 3227 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 3228 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
| 3229 | Error("mismatched umbrella directories in submodule"); |
| 3230 | return Failure; |
| 3231 | } |
| 3232 | } |
| 3233 | break; |
| 3234 | } |
| 3235 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3236 | case SUBMODULE_METADATA: { |
| 3237 | if (!First) { |
| 3238 | Error("submodule metadata record not at beginning of block"); |
| 3239 | return Failure; |
| 3240 | } |
| 3241 | First = false; |
| 3242 | |
| 3243 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3244 | F.LocalNumSubmodules = Record[0]; |
| 3245 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 3246 | if (F.LocalNumSubmodules > 0) { |
| 3247 | // Introduce the global -> local mapping for submodules within this |
| 3248 | // module. |
| 3249 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 3250 | |
| 3251 | // Introduce the local -> global mapping for submodules within this |
| 3252 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 3253 | F.SubmoduleRemap.insertOrReplace( |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3254 | std::make_pair(LocalBaseSubmoduleID, |
| 3255 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 3256 | |
| 3257 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 3258 | } |
| 3259 | break; |
| 3260 | } |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3261 | |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3262 | case SUBMODULE_IMPORTS: { |
| 3263 | if (First) { |
| 3264 | Error("missing submodule metadata record at beginning of block"); |
| 3265 | return Failure; |
| 3266 | } |
| 3267 | |
| 3268 | if (!CurrentModule) |
| 3269 | break; |
| 3270 | |
| 3271 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 3272 | UnresolvedModuleImportExport Unresolved; |
| 3273 | Unresolved.File = &F; |
| 3274 | Unresolved.Mod = CurrentModule; |
| 3275 | Unresolved.ID = Record[Idx]; |
| 3276 | Unresolved.IsImport = true; |
| 3277 | Unresolved.IsWildcard = false; |
| 3278 | UnresolvedModuleImportExports.push_back(Unresolved); |
| 3279 | } |
| 3280 | break; |
| 3281 | } |
| 3282 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3283 | case SUBMODULE_EXPORTS: { |
| 3284 | if (First) { |
| 3285 | Error("missing submodule metadata record at beginning of block"); |
| 3286 | return Failure; |
| 3287 | } |
| 3288 | |
| 3289 | if (!CurrentModule) |
| 3290 | break; |
| 3291 | |
| 3292 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3293 | UnresolvedModuleImportExport Unresolved; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3294 | Unresolved.File = &F; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3295 | Unresolved.Mod = CurrentModule; |
| 3296 | Unresolved.ID = Record[Idx]; |
| 3297 | Unresolved.IsImport = false; |
| 3298 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 3299 | UnresolvedModuleImportExports.push_back(Unresolved); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | // Once we've loaded the set of exports, there's no reason to keep |
| 3303 | // the parsed, unresolved exports around. |
| 3304 | CurrentModule->UnresolvedExports.clear(); |
| 3305 | break; |
| 3306 | } |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3307 | case SUBMODULE_REQUIRES: { |
| 3308 | if (First) { |
| 3309 | Error("missing submodule metadata record at beginning of block"); |
| 3310 | return Failure; |
| 3311 | } |
| 3312 | |
| 3313 | if (!CurrentModule) |
| 3314 | break; |
| 3315 | |
| 3316 | CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3317 | Context.getLangOpts(), |
Douglas Gregor | dc58aa7 | 2012-01-30 06:01:29 +0000 | [diff] [blame] | 3318 | Context.getTargetInfo()); |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3319 | break; |
| 3320 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3321 | } |
| 3322 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3325 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3326 | /// structure. |
| 3327 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3328 | /// This routine parses the language options from the AST file and then gives |
| 3329 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3330 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3331 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3332 | bool ASTReader::ParseLanguageOptions(const RecordData &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3333 | if (Listener) { |
| 3334 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3335 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3336 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 3337 | LangOpts.Name = Record[Idx++]; |
| 3338 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 3339 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 3340 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3341 | |
| 3342 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 3343 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 3344 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3345 | |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 3346 | unsigned Length = Record[Idx++]; |
| 3347 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 3348 | Record.begin() + Idx + Length); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3349 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3350 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3351 | |
| 3352 | return false; |
| 3353 | } |
| 3354 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3355 | std::pair<ModuleFile *, unsigned> |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3356 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3357 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3358 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3359 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 3360 | "Corrupted global preprocessed entity map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3361 | ModuleFile *M = I->second; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3362 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 3363 | return std::make_pair(M, LocalIndex); |
| 3364 | } |
| 3365 | |
| 3366 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 3367 | PreprocessedEntityID PPID = Index+1; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3368 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3369 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3370 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3371 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3372 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3373 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3374 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3375 | |
| 3376 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 3377 | switch (Code) { |
| 3378 | case llvm::bitc::END_BLOCK: |
| 3379 | return 0; |
| 3380 | |
| 3381 | case llvm::bitc::ENTER_SUBBLOCK: |
| 3382 | Error("unexpected subblock record in preprocessor detail block"); |
| 3383 | return 0; |
| 3384 | |
| 3385 | case llvm::bitc::DEFINE_ABBREV: |
| 3386 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 3387 | return 0; |
| 3388 | |
| 3389 | default: |
| 3390 | break; |
| 3391 | } |
| 3392 | |
| 3393 | if (!PP.getPreprocessingRecord()) { |
| 3394 | Error("no preprocessing record"); |
| 3395 | return 0; |
| 3396 | } |
| 3397 | |
| 3398 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3399 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 3400 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3401 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 3402 | const char *BlobStart = 0; |
| 3403 | unsigned BlobLen = 0; |
| 3404 | RecordData Record; |
| 3405 | PreprocessorDetailRecordTypes RecType = |
| 3406 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 3407 | Code, Record, BlobStart, BlobLen); |
| 3408 | switch (RecType) { |
| 3409 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3410 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3411 | IdentifierInfo *Name = 0; |
| 3412 | MacroDefinition *Def = 0; |
| 3413 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3414 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3415 | else { |
| 3416 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3417 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3418 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 3419 | } |
| 3420 | |
| 3421 | MacroExpansion *ME; |
| 3422 | if (isBuiltin) |
| 3423 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 3424 | else |
| 3425 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 3426 | |
| 3427 | return ME; |
| 3428 | } |
| 3429 | |
| 3430 | case PPD_MACRO_DEFINITION: { |
| 3431 | // Decode the identifier info and then check again; if the macro is |
| 3432 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3433 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3434 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3435 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3436 | |
| 3437 | if (DeserializationListener) |
| 3438 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 3439 | |
| 3440 | return MD; |
| 3441 | } |
| 3442 | |
| 3443 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3444 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 3445 | StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]); |
| 3446 | const FileEntry *File = 0; |
| 3447 | if (!FullFileName.empty()) |
| 3448 | File = PP.getFileManager().getFile(FullFileName); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3449 | |
| 3450 | // FIXME: Stable encoding |
| 3451 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3452 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3453 | InclusionDirective *ID |
| 3454 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3455 | StringRef(BlobStart, Record[0]), |
| 3456 | Record[1], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3457 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3458 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3459 | return ID; |
| 3460 | } |
| 3461 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 3462 | |
| 3463 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3464 | } |
| 3465 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3466 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 3467 | /// preprocessed entities or the entities it contains are not the ones we are |
| 3468 | /// looking for. Find the next module that contains entities and return the ID |
| 3469 | /// of the first entry. |
| 3470 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 3471 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 3472 | ++SLocMapI; |
| 3473 | for (GlobalSLocOffsetMapType::const_iterator |
| 3474 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3475 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3476 | if (M.NumPreprocessedEntities) |
| 3477 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 3478 | } |
| 3479 | |
| 3480 | return getTotalNumPreprocessedEntities(); |
| 3481 | } |
| 3482 | |
| 3483 | namespace { |
| 3484 | |
| 3485 | template <unsigned PPEntityOffset::*PPLoc> |
| 3486 | struct PPEntityComp { |
| 3487 | const ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3488 | ModuleFile &M; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3489 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3490 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3491 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3492 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 3493 | SourceLocation LHS = getLoc(L); |
| 3494 | SourceLocation RHS = getLoc(R); |
| 3495 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3496 | } |
| 3497 | |
| 3498 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3499 | SourceLocation LHS = getLoc(L); |
| 3500 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3501 | } |
| 3502 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3503 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3504 | SourceLocation RHS = getLoc(R); |
| 3505 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3506 | } |
| 3507 | |
| 3508 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 3509 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 3510 | } |
| 3511 | }; |
| 3512 | |
| 3513 | } |
| 3514 | |
| 3515 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 3516 | PreprocessedEntityID |
| 3517 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 3518 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 3519 | return getTotalNumPreprocessedEntities(); |
| 3520 | |
| 3521 | GlobalSLocOffsetMapType::const_iterator |
| 3522 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3523 | BLoc.getOffset()); |
| 3524 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3525 | "Corrupted global sloc offset map"); |
| 3526 | |
| 3527 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3528 | return findNextPreprocessedEntity(SLocMapI); |
| 3529 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3530 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3531 | typedef const PPEntityOffset *pp_iterator; |
| 3532 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3533 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 3534 | |
| 3535 | size_t Count = M.NumPreprocessedEntities; |
| 3536 | size_t Half; |
| 3537 | pp_iterator First = pp_begin; |
| 3538 | pp_iterator PPI; |
| 3539 | |
| 3540 | // Do a binary search manually instead of using std::lower_bound because |
| 3541 | // The end locations of entities may be unordered (when a macro expansion |
| 3542 | // is inside another macro argument), but for this case it is not important |
| 3543 | // whether we get the first macro expansion or its containing macro. |
| 3544 | while (Count > 0) { |
| 3545 | Half = Count/2; |
| 3546 | PPI = First; |
| 3547 | std::advance(PPI, Half); |
| 3548 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 3549 | BLoc)){ |
| 3550 | First = PPI; |
| 3551 | ++First; |
| 3552 | Count = Count - Half - 1; |
| 3553 | } else |
| 3554 | Count = Half; |
| 3555 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3556 | |
| 3557 | if (PPI == pp_end) |
| 3558 | return findNextPreprocessedEntity(SLocMapI); |
| 3559 | |
| 3560 | return getGlobalPreprocessedEntityID(M, |
| 3561 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3562 | } |
| 3563 | |
| 3564 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 3565 | PreprocessedEntityID |
| 3566 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 3567 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 3568 | return getTotalNumPreprocessedEntities(); |
| 3569 | |
| 3570 | GlobalSLocOffsetMapType::const_iterator |
| 3571 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3572 | ELoc.getOffset()); |
| 3573 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3574 | "Corrupted global sloc offset map"); |
| 3575 | |
| 3576 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3577 | return findNextPreprocessedEntity(SLocMapI); |
| 3578 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3579 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3580 | typedef const PPEntityOffset *pp_iterator; |
| 3581 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3582 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 3583 | pp_iterator PPI = |
| 3584 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 3585 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 3586 | |
| 3587 | if (PPI == pp_end) |
| 3588 | return findNextPreprocessedEntity(SLocMapI); |
| 3589 | |
| 3590 | return getGlobalPreprocessedEntityID(M, |
| 3591 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3592 | } |
| 3593 | |
| 3594 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 3595 | /// preprocessed entities that \arg Range encompasses. |
| 3596 | std::pair<unsigned, unsigned> |
| 3597 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 3598 | if (Range.isInvalid()) |
| 3599 | return std::make_pair(0,0); |
| 3600 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 3601 | |
| 3602 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 3603 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 3604 | return std::make_pair(BeginID, EndID); |
| 3605 | } |
| 3606 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3607 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 3608 | /// entity with index \arg Index came from file \arg FID. |
| 3609 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 3610 | FileID FID) { |
| 3611 | if (FID.isInvalid()) |
| 3612 | return false; |
| 3613 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3614 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3615 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3616 | unsigned LocalIndex = PPInfo.second; |
| 3617 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 3618 | |
| 3619 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 3620 | if (Loc.isInvalid()) |
| 3621 | return false; |
| 3622 | |
| 3623 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 3624 | return true; |
| 3625 | else |
| 3626 | return false; |
| 3627 | } |
| 3628 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3629 | namespace { |
| 3630 | /// \brief Visitor used to search for information about a header file. |
| 3631 | class HeaderFileInfoVisitor { |
| 3632 | ASTReader &Reader; |
| 3633 | const FileEntry *FE; |
| 3634 | |
| 3635 | llvm::Optional<HeaderFileInfo> HFI; |
| 3636 | |
| 3637 | public: |
| 3638 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3639 | : Reader(Reader), FE(FE) { } |
| 3640 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3641 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3642 | HeaderFileInfoVisitor *This |
| 3643 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3644 | |
| 3645 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3646 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3647 | M.HeaderFileFrameworkStrings, |
| 3648 | This->FE->getName()); |
| 3649 | |
| 3650 | HeaderFileInfoLookupTable *Table |
| 3651 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3652 | if (!Table) |
| 3653 | return false; |
| 3654 | |
| 3655 | // Look in the on-disk hash table for an entry for this file name. |
| 3656 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3657 | &Trait); |
| 3658 | if (Pos == Table->end()) |
| 3659 | return false; |
| 3660 | |
| 3661 | This->HFI = *Pos; |
| 3662 | return true; |
| 3663 | } |
| 3664 | |
| 3665 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3666 | }; |
| 3667 | } |
| 3668 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3669 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3670 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3671 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3672 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3673 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3674 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3675 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3676 | } |
| 3677 | |
| 3678 | return HeaderFileInfo(); |
| 3679 | } |
| 3680 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3681 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3682 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3683 | ModuleFile &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3684 | unsigned Idx = 0; |
| 3685 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3686 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3687 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 3688 | Diag.DiagStatePoints.push_back( |
| 3689 | DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(), |
| 3690 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3691 | while (1) { |
| 3692 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3693 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3694 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3695 | break; // Something is messed up but at least avoid infinite loop in |
| 3696 | // release build. |
| 3697 | } |
| 3698 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3699 | if (DiagID == (unsigned)-1) { |
| 3700 | break; // no more diag/map pairs for this location. |
| 3701 | } |
| 3702 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3703 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 3704 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3705 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3706 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3707 | } |
| 3708 | } |
| 3709 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3710 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3711 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3712 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3713 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3714 | ModuleFile *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3715 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3719 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3720 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3721 | /// routine actually reads the record corresponding to the type at the given |
| 3722 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3723 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3724 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3725 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3726 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3727 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3728 | // Keep track of where we are in the stream, then jump back there |
| 3729 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3730 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3731 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3732 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3733 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3734 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3735 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3736 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3737 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3738 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3739 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3740 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3741 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3742 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3743 | if (Record.size() != 2) { |
| 3744 | Error("Incorrect encoding of extended qualifier type"); |
| 3745 | return QualType(); |
| 3746 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3747 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3748 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3749 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3750 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3751 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3752 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3753 | if (Record.size() != 1) { |
| 3754 | Error("Incorrect encoding of complex type"); |
| 3755 | return QualType(); |
| 3756 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3757 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3758 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3759 | } |
| 3760 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3761 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3762 | if (Record.size() != 1) { |
| 3763 | Error("Incorrect encoding of pointer type"); |
| 3764 | return QualType(); |
| 3765 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3766 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3767 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3768 | } |
| 3769 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3770 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3771 | if (Record.size() != 1) { |
| 3772 | Error("Incorrect encoding of block pointer type"); |
| 3773 | return QualType(); |
| 3774 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3775 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3776 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3777 | } |
| 3778 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3779 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3780 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3781 | Error("Incorrect encoding of lvalue reference type"); |
| 3782 | return QualType(); |
| 3783 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3784 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3785 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3786 | } |
| 3787 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3788 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3789 | if (Record.size() != 1) { |
| 3790 | Error("Incorrect encoding of rvalue reference type"); |
| 3791 | return QualType(); |
| 3792 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3793 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3794 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3797 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3798 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3799 | Error("Incorrect encoding of member pointer type"); |
| 3800 | return QualType(); |
| 3801 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3802 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3803 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3804 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3805 | return QualType(); |
| 3806 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3807 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3810 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3811 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3812 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3813 | unsigned IndexTypeQuals = Record[2]; |
| 3814 | unsigned Idx = 3; |
| 3815 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3816 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3817 | ASM, IndexTypeQuals); |
| 3818 | } |
| 3819 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3820 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3821 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3822 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3823 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3824 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3827 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3828 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3829 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3830 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3831 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3832 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3833 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3834 | ASM, IndexTypeQuals, |
| 3835 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3838 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3839 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3840 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3841 | return QualType(); |
| 3842 | } |
| 3843 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3844 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3845 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3846 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3847 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3848 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3851 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3852 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3853 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3854 | return QualType(); |
| 3855 | } |
| 3856 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3857 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3858 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3859 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3862 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3863 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3864 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3865 | return QualType(); |
| 3866 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3867 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3868 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3869 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3870 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3873 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3874 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3875 | |
| 3876 | FunctionProtoType::ExtProtoInfo EPI; |
| 3877 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3878 | /*hasregparm*/ Record[2], |
| 3879 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3880 | static_cast<CallingConv>(Record[4]), |
| 3881 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3882 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3883 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3884 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3885 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3886 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3887 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3888 | |
| 3889 | EPI.Variadic = Record[Idx++]; |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 3890 | EPI.HasTrailingReturn = Record[Idx++]; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3891 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3892 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3893 | ExceptionSpecificationType EST = |
| 3894 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3895 | EPI.ExceptionSpecType = EST; |
Douglas Gregor | b0d06e2 | 2012-04-04 00:34:49 +0000 | [diff] [blame] | 3896 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3897 | if (EST == EST_Dynamic) { |
| 3898 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3899 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3900 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3901 | EPI.Exceptions = Exceptions.data(); |
| 3902 | } else if (EST == EST_ComputedNoexcept) { |
| 3903 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 3904 | } else if (EST == EST_Uninstantiated) { |
| 3905 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
| 3906 | EPI.ExceptionSpecTemplate = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3907 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3908 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3909 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3910 | } |
| 3911 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3912 | case TYPE_UNRESOLVED_USING: { |
| 3913 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3914 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3915 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3916 | } |
| 3917 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3918 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3919 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3920 | Error("incorrect encoding of typedef type"); |
| 3921 | return QualType(); |
| 3922 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3923 | unsigned Idx = 0; |
| 3924 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3925 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3926 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3927 | Canonical = Context.getCanonicalType(Canonical); |
| 3928 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3929 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3930 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3931 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3932 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
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: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3935 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3936 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3937 | return QualType(); |
| 3938 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3939 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3940 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3941 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3942 | |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 3943 | case TYPE_DECLTYPE: { |
| 3944 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 3945 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 3946 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3947 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3948 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3949 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3950 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3951 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3952 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3955 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3956 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3957 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3958 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3959 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3960 | Error("incorrect encoding of record type"); |
| 3961 | return QualType(); |
| 3962 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3963 | unsigned Idx = 0; |
| 3964 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 3965 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 3966 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 3967 | QualType T = Context.getRecordType(RD); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3968 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3969 | return T; |
| 3970 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3971 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3972 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3973 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3974 | Error("incorrect encoding of enum type"); |
| 3975 | return QualType(); |
| 3976 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3977 | unsigned Idx = 0; |
| 3978 | bool IsDependent = Record[Idx++]; |
| 3979 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3980 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3981 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3982 | return T; |
| 3983 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3984 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3985 | case TYPE_ATTRIBUTED: { |
| 3986 | if (Record.size() != 3) { |
| 3987 | Error("incorrect encoding of attributed type"); |
| 3988 | return QualType(); |
| 3989 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3990 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3991 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3992 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3993 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3994 | } |
| 3995 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3996 | case TYPE_PAREN: { |
| 3997 | if (Record.size() != 1) { |
| 3998 | Error("incorrect encoding of paren type"); |
| 3999 | return QualType(); |
| 4000 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4001 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4002 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4003 | } |
| 4004 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4005 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 4006 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4007 | Error("incorrect encoding of pack expansion type"); |
| 4008 | return QualType(); |
| 4009 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4010 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4011 | if (Pattern.isNull()) |
| 4012 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4013 | llvm::Optional<unsigned> NumExpansions; |
| 4014 | if (Record[1]) |
| 4015 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4016 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4019 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4020 | unsigned Idx = 0; |
| 4021 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4022 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4023 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4024 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4025 | } |
| 4026 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4027 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4028 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4029 | ObjCInterfaceDecl *ItfD |
| 4030 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4031 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4034 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4035 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4036 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4037 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4038 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4039 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4040 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4041 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4042 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4043 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4044 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4045 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4046 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4047 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4048 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4049 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4050 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4051 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4052 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 4053 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4054 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4055 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4056 | Replacement); |
| 4057 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4059 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 4060 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4061 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4062 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4063 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4064 | cast<TemplateTypeParmType>(Parm), |
| 4065 | ArgPack); |
| 4066 | } |
| 4067 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4068 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4069 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4070 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4071 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4072 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4073 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4074 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4075 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4076 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4077 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4078 | unsigned Idx = 0; |
| 4079 | unsigned Depth = Record[Idx++]; |
| 4080 | unsigned Index = Record[Idx++]; |
| 4081 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4082 | TemplateTypeParmDecl *D |
| 4083 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4084 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4085 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4086 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4087 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4088 | unsigned Idx = 0; |
| 4089 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4090 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4091 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4092 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4093 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4094 | Canon = Context.getCanonicalType(Canon); |
| 4095 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4096 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4097 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4098 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4099 | unsigned Idx = 0; |
| 4100 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4101 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4102 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4103 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4104 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4105 | Args.reserve(NumArgs); |
| 4106 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4107 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4108 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4109 | Args.size(), Args.data()); |
| 4110 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4111 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4112 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4113 | unsigned Idx = 0; |
| 4114 | |
| 4115 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4116 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4117 | ArrayType::ArraySizeModifier ASM |
| 4118 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 4119 | unsigned IndexTypeQuals = Record[Idx++]; |
| 4120 | |
| 4121 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4122 | Expr *NumElts = ReadExpr(*Loc.F); |
| 4123 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4124 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4125 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4126 | IndexTypeQuals, Brackets); |
| 4127 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4128 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4129 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4130 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4131 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4132 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4133 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4134 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4135 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4136 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4137 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4138 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4139 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4140 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4141 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4142 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4143 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4144 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4145 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4146 | |
| 4147 | case TYPE_ATOMIC: { |
| 4148 | if (Record.size() != 1) { |
| 4149 | Error("Incorrect encoding of atomic type"); |
| 4150 | return QualType(); |
| 4151 | } |
| 4152 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 4153 | return Context.getAtomicType(ValueType); |
| 4154 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4155 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4156 | llvm_unreachable("Invalid TypeCode!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4159 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4160 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4161 | ModuleFile &F; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4162 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4163 | unsigned &Idx; |
| 4164 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4165 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 4166 | unsigned &I) { |
| 4167 | return Reader.ReadSourceLocation(F, R, I); |
| 4168 | } |
| 4169 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4170 | template<typename T> |
| 4171 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 4172 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 4173 | } |
| 4174 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4175 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4176 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4177 | const ASTReader::RecordData &Record, unsigned &Idx) |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 4178 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4179 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4180 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4181 | // We want compile-time assurance that we've enumerated all of |
| 4182 | // these, so unfortunately we have to declare them first, then |
| 4183 | // define them out-of-line. |
| 4184 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4185 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4186 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4187 | #include "clang/AST/TypeLocNodes.def" |
| 4188 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4189 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 4190 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4191 | }; |
| 4192 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4193 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4194 | // nothing to do |
| 4195 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4196 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4197 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4198 | if (TL.needsExtraLocalData()) { |
| 4199 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 4200 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 4201 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 4202 | TL.setModeAttr(Record[Idx++]); |
| 4203 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4204 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4205 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4206 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
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::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4209 | TL.setStarLoc(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::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4212 | TL.setCaretLoc(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::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4215 | TL.setAmpLoc(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::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4218 | TL.setAmpAmpLoc(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::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4221 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4222 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4223 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4224 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4225 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 4226 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4227 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4228 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4229 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4230 | TL.setSizeExpr(0); |
| 4231 | } |
| 4232 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 4233 | VisitArrayTypeLoc(TL); |
| 4234 | } |
| 4235 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 4236 | VisitArrayTypeLoc(TL); |
| 4237 | } |
| 4238 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 4239 | VisitArrayTypeLoc(TL); |
| 4240 | } |
| 4241 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 4242 | DependentSizedArrayTypeLoc TL) { |
| 4243 | VisitArrayTypeLoc(TL); |
| 4244 | } |
| 4245 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 4246 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4247 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4248 | } |
| 4249 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc 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::VisitExtVectorTypeLoc(ExtVectorTypeLoc 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::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4256 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 4257 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 4258 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4259 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4260 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4261 | } |
| 4262 | } |
| 4263 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 4264 | VisitFunctionTypeLoc(TL); |
| 4265 | } |
| 4266 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 4267 | VisitFunctionTypeLoc(TL); |
| 4268 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4269 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4270 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4271 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4272 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4273 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4274 | } |
| 4275 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4276 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4277 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4278 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4279 | } |
| 4280 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4281 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4282 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4283 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4284 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4285 | } |
| 4286 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4287 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4288 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4289 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 4290 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4291 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4292 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4293 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 4294 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4295 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 4296 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4297 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4298 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4299 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4300 | } |
| 4301 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4302 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4303 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4304 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 4305 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 4306 | if (TL.hasAttrOperand()) { |
| 4307 | SourceRange range; |
| 4308 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 4309 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 4310 | TL.setAttrOperandParensRange(range); |
| 4311 | } |
| 4312 | if (TL.hasAttrExprOperand()) { |
| 4313 | if (Record[Idx++]) |
| 4314 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 4315 | else |
| 4316 | TL.setAttrExprOperand(0); |
| 4317 | } else if (TL.hasAttrEnumOperand()) |
| 4318 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 4319 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4320 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4321 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4322 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4323 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 4324 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4325 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4326 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4327 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 4328 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4329 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4330 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4331 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 4332 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4333 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4334 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 4335 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4336 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4337 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 4338 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4339 | Reader.GetTemplateArgumentLocInfo(F, |
| 4340 | TL.getTypePtr()->getArg(i).getKind(), |
| 4341 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4342 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4343 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 4344 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4345 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4346 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4347 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4348 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4349 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4350 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4351 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4352 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4353 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4354 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4355 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4356 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4357 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4358 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4359 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 4360 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4361 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4362 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4363 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4364 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4365 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4366 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4367 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4368 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4369 | Reader.GetTemplateArgumentLocInfo(F, |
| 4370 | TL.getTypePtr()->getArg(I).getKind(), |
| 4371 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4372 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4373 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 4374 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 4375 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4376 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4377 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4378 | } |
| 4379 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 4380 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4381 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4382 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4383 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4384 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4385 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4386 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4387 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4388 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4389 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 4390 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4391 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4392 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4393 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4394 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4395 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4396 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4397 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4398 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4399 | if (InfoTy.isNull()) |
| 4400 | return 0; |
| 4401 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4402 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4403 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4404 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4405 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4406 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4407 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4408 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4409 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4410 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4411 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4412 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4413 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4414 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4415 | switch ((PredefinedTypeIDs)Index) { |
| 4416 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4417 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 4418 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4419 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4420 | case PREDEF_TYPE_CHAR_U_ID: |
| 4421 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4422 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4423 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4424 | break; |
| 4425 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4426 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 4427 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 4428 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 4429 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 4430 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 4431 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 4432 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 4433 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 4434 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 4435 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 4436 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 4437 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 4438 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 4439 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4440 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 4441 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 4442 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 4443 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 4444 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 4445 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4446 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 4447 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 4448 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 4449 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 4450 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 4451 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 4452 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 4453 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 4454 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4455 | |
| 4456 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4457 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4458 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 4459 | |
| 4460 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 4461 | T = Context.ARCUnbridgedCastTy; |
| 4462 | break; |
| 4463 | |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 4464 | case PREDEF_TYPE_VA_LIST_TAG: |
| 4465 | T = Context.getVaListTagType(); |
| 4466 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4470 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4473 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4474 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4475 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4476 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4477 | if (TypesLoaded[Index].isNull()) |
| 4478 | return QualType(); |
| 4479 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4480 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4481 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4482 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4483 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4484 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4485 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4486 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4489 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4490 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4491 | } |
| 4492 | |
| 4493 | serialization::TypeID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4494 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4495 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4496 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4497 | |
| 4498 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4499 | return LocalID; |
| 4500 | |
| 4501 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4502 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4503 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4504 | |
| 4505 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4506 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4507 | } |
| 4508 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4509 | TemplateArgumentLocInfo |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4510 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4511 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4512 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4513 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4514 | switch (Kind) { |
| 4515 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4516 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4517 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4518 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4519 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4520 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4521 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4522 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4523 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4524 | SourceLocation()); |
| 4525 | } |
| 4526 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4527 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4528 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4529 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4530 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4531 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4532 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4533 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4534 | case TemplateArgument::Null: |
| 4535 | case TemplateArgument::Integral: |
| 4536 | case TemplateArgument::Declaration: |
| 4537 | case TemplateArgument::Pack: |
| 4538 | return TemplateArgumentLocInfo(); |
| 4539 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4540 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4541 | } |
| 4542 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4543 | TemplateArgumentLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4544 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4545 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4546 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4547 | |
| 4548 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4549 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4550 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4551 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4552 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4553 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4556 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4557 | return GetDecl(ID); |
| 4558 | } |
| 4559 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4560 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4561 | unsigned &Idx){ |
| 4562 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4563 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4564 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4565 | unsigned LocalID = Record[Idx++]; |
| 4566 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4570 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4571 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4572 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4573 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4574 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4575 | RecordData Record; |
| 4576 | unsigned Code = Cursor.ReadCode(); |
| 4577 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4578 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4579 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4580 | return 0; |
| 4581 | } |
| 4582 | |
| 4583 | unsigned Idx = 0; |
| 4584 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4585 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4586 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4587 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4588 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4589 | return Bases; |
| 4590 | } |
| 4591 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4592 | serialization::DeclID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4593 | ASTReader::getGlobalDeclID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4594 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4595 | return LocalID; |
| 4596 | |
| 4597 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4598 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4599 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4600 | |
| 4601 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4602 | } |
| 4603 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4604 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4605 | ModuleFile &M) const { |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4606 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4607 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4608 | return &M == I->second; |
| 4609 | } |
| 4610 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4611 | ModuleFile *ASTReader::getOwningModuleFile(Decl *D) { |
| 4612 | if (!D->isFromASTFile()) |
| 4613 | return 0; |
| 4614 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 4615 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4616 | return I->second; |
| 4617 | } |
| 4618 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4619 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 4620 | if (ID < NUM_PREDEF_DECL_IDS) |
| 4621 | return SourceLocation(); |
| 4622 | |
| 4623 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4624 | |
| 4625 | if (Index > DeclsLoaded.size()) { |
| 4626 | Error("declaration ID out-of-range for AST file"); |
| 4627 | return SourceLocation(); |
| 4628 | } |
| 4629 | |
| 4630 | if (Decl *D = DeclsLoaded[Index]) |
| 4631 | return D->getLocation(); |
| 4632 | |
| 4633 | unsigned RawLocation = 0; |
| 4634 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 4635 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 4636 | } |
| 4637 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4638 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4639 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4640 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4641 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4642 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4643 | |
| 4644 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4645 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4646 | |
| 4647 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4648 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4649 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4650 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4651 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4652 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4653 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4654 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4655 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 4656 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 4657 | return Context.getObjCProtocolDecl(); |
| 4658 | |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4659 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4660 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4661 | |
| 4662 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4663 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4664 | |
| 4665 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4666 | return Context.getObjCInstanceTypeDecl(); |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4667 | |
| 4668 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 4669 | return Context.getBuiltinVaListDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4670 | } |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4671 | } |
| 4672 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4673 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4674 | |
Richard Smith | 2fbf373 | 2011-12-20 04:39:57 +0000 | [diff] [blame] | 4675 | if (Index >= DeclsLoaded.size()) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame^] | 4676 | assert(0 && "declaration ID out-of-range for AST file"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4677 | Error("declaration ID out-of-range for AST file"); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame^] | 4678 | return 0; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4679 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4680 | |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 4681 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4682 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4683 | if (DeserializationListener) |
| 4684 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4685 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4686 | |
| 4687 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4688 | } |
| 4689 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4690 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 4691 | DeclID GlobalID) { |
| 4692 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 4693 | return GlobalID; |
| 4694 | |
| 4695 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 4696 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4697 | ModuleFile *Owner = I->second; |
| 4698 | |
| 4699 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 4700 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 4701 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 4702 | return 0; |
| 4703 | |
| 4704 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 4705 | } |
| 4706 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4707 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4708 | const RecordData &Record, |
| 4709 | unsigned &Idx) { |
| 4710 | if (Idx >= Record.size()) { |
| 4711 | Error("Corrupted AST file"); |
| 4712 | return 0; |
| 4713 | } |
| 4714 | |
| 4715 | return getGlobalDeclID(F, Record[Idx++]); |
| 4716 | } |
| 4717 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4718 | /// \brief Resolve the offset of a statement into a statement. |
| 4719 | /// |
| 4720 | /// This operation will read a new statement from the external |
| 4721 | /// source each time it is called, and is meant to be used via a |
| 4722 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4723 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4724 | // Switch case IDs are per Decl. |
| 4725 | ClearSwitchCaseIDs(); |
| 4726 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4727 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4728 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4729 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4730 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4733 | namespace { |
| 4734 | class FindExternalLexicalDeclsVisitor { |
| 4735 | ASTReader &Reader; |
| 4736 | const DeclContext *DC; |
| 4737 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4738 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4739 | SmallVectorImpl<Decl*> &Decls; |
| 4740 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4741 | |
| 4742 | public: |
| 4743 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4744 | bool (*isKindWeWant)(Decl::Kind), |
| 4745 | SmallVectorImpl<Decl*> &Decls) |
| 4746 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4747 | { |
| 4748 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4749 | PredefsVisited[I] = false; |
| 4750 | } |
| 4751 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4752 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4753 | if (Preorder) |
| 4754 | return false; |
| 4755 | |
| 4756 | FindExternalLexicalDeclsVisitor *This |
| 4757 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4758 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4759 | ModuleFile::DeclContextInfosMap::iterator Info |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4760 | = M.DeclContextInfos.find(This->DC); |
| 4761 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4762 | return false; |
| 4763 | |
| 4764 | // Load all of the declaration IDs |
| 4765 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4766 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4767 | ID != IDE; ++ID) { |
| 4768 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4769 | continue; |
| 4770 | |
| 4771 | // Don't add predefined declarations to the lexical context more |
| 4772 | // than once. |
| 4773 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4774 | if (This->PredefsVisited[ID->second]) |
| 4775 | continue; |
| 4776 | |
| 4777 | This->PredefsVisited[ID->second] = true; |
| 4778 | } |
| 4779 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4780 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4781 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4782 | This->Decls.push_back(D); |
| 4783 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | return false; |
| 4787 | } |
| 4788 | }; |
| 4789 | } |
| 4790 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4791 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4792 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4793 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4794 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4795 | // least. Walk all of the modules in the order they were loaded. |
| 4796 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4797 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4798 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4799 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4802 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4803 | |
| 4804 | class DeclIDComp { |
| 4805 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4806 | ModuleFile &Mod; |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4807 | |
| 4808 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4809 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4810 | |
| 4811 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 4812 | SourceLocation LHS = getLocation(L); |
| 4813 | SourceLocation RHS = getLocation(R); |
| 4814 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4815 | } |
| 4816 | |
| 4817 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 4818 | SourceLocation RHS = getLocation(R); |
| 4819 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4820 | } |
| 4821 | |
| 4822 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 4823 | SourceLocation LHS = getLocation(L); |
| 4824 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4825 | } |
| 4826 | |
| 4827 | SourceLocation getLocation(LocalDeclID ID) const { |
| 4828 | return Reader.getSourceManager().getFileLoc( |
| 4829 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 4830 | } |
| 4831 | }; |
| 4832 | |
| 4833 | } |
| 4834 | |
| 4835 | void ASTReader::FindFileRegionDecls(FileID File, |
| 4836 | unsigned Offset, unsigned Length, |
| 4837 | SmallVectorImpl<Decl *> &Decls) { |
| 4838 | SourceManager &SM = getSourceManager(); |
| 4839 | |
| 4840 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 4841 | if (I == FileDeclIDs.end()) |
| 4842 | return; |
| 4843 | |
| 4844 | FileDeclsInfo &DInfo = I->second; |
| 4845 | if (DInfo.Decls.empty()) |
| 4846 | return; |
| 4847 | |
| 4848 | SourceLocation |
| 4849 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 4850 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 4851 | |
| 4852 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 4853 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4854 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4855 | BeginLoc, DIDComp); |
| 4856 | if (BeginIt != DInfo.Decls.begin()) |
| 4857 | --BeginIt; |
| 4858 | |
Argyrios Kyrtzidis | c14a03d | 2011-11-23 20:27:36 +0000 | [diff] [blame] | 4859 | // If we are pointing at a top-level decl inside an objc container, we need |
| 4860 | // to backtrack until we find it otherwise we will fail to report that the |
| 4861 | // region overlaps with an objc container. |
| 4862 | while (BeginIt != DInfo.Decls.begin() && |
| 4863 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 4864 | ->isTopLevelDeclInObjCContainer()) |
| 4865 | --BeginIt; |
| 4866 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4867 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4868 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4869 | EndLoc, DIDComp); |
| 4870 | if (EndIt != DInfo.Decls.end()) |
| 4871 | ++EndIt; |
| 4872 | |
| 4873 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 4874 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 4875 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 4876 | } |
| 4877 | |
| 4878 | namespace { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4879 | /// \brief ModuleFile visitor used to perform name lookup into a |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4880 | /// declaration context. |
| 4881 | class DeclContextNameLookupVisitor { |
| 4882 | ASTReader &Reader; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4883 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4884 | DeclarationName Name; |
| 4885 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4886 | |
| 4887 | public: |
| 4888 | DeclContextNameLookupVisitor(ASTReader &Reader, |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4889 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 4890 | DeclarationName Name, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4891 | SmallVectorImpl<NamedDecl *> &Decls) |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4892 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls) { } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4893 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4894 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4895 | DeclContextNameLookupVisitor *This |
| 4896 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4897 | |
| 4898 | // Check whether we have any visible declaration information for |
| 4899 | // this context in this module. |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4900 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 4901 | bool FoundInfo = false; |
| 4902 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 4903 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 4904 | if (Info != M.DeclContextInfos.end() && |
| 4905 | Info->second.NameLookupTableData) { |
| 4906 | FoundInfo = true; |
| 4907 | break; |
| 4908 | } |
| 4909 | } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4910 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4911 | if (!FoundInfo) |
| 4912 | return false; |
| 4913 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4914 | // Look for this name within this module. |
| 4915 | ASTDeclContextNameLookupTable *LookupTable = |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 4916 | Info->second.NameLookupTableData; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4917 | ASTDeclContextNameLookupTable::iterator Pos |
| 4918 | = LookupTable->find(This->Name); |
| 4919 | if (Pos == LookupTable->end()) |
| 4920 | return false; |
| 4921 | |
| 4922 | bool FoundAnything = false; |
| 4923 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4924 | for (; Data.first != Data.second; ++Data.first) { |
| 4925 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4926 | if (!ND) |
| 4927 | continue; |
| 4928 | |
| 4929 | if (ND->getDeclName() != This->Name) { |
| 4930 | assert(!This->Name.getCXXNameType().isNull() && |
| 4931 | "Name mismatch without a type"); |
| 4932 | continue; |
| 4933 | } |
| 4934 | |
| 4935 | // Record this declaration. |
| 4936 | FoundAnything = true; |
| 4937 | This->Decls.push_back(ND); |
| 4938 | } |
| 4939 | |
| 4940 | return FoundAnything; |
| 4941 | } |
| 4942 | }; |
| 4943 | } |
| 4944 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4945 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4946 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4947 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4948 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4949 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4950 | if (!Name) |
| 4951 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4952 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4953 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4954 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4955 | |
| 4956 | // Compute the declaration contexts we need to look into. Multiple such |
| 4957 | // declaration contexts occur when two declaration contexts from disjoint |
| 4958 | // modules get merged, e.g., when two namespaces with the same name are |
| 4959 | // independently defined in separate modules. |
| 4960 | SmallVector<const DeclContext *, 2> Contexts; |
| 4961 | Contexts.push_back(DC); |
| 4962 | |
| 4963 | if (DC->isNamespace()) { |
| 4964 | MergedDeclsMap::iterator Merged |
| 4965 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 4966 | if (Merged != MergedDecls.end()) { |
| 4967 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 4968 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 4969 | } |
| 4970 | } |
| 4971 | |
| 4972 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4973 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4974 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4975 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4976 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4977 | } |
| 4978 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4979 | namespace { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4980 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4981 | /// declaration context. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4982 | class DeclContextAllNamesVisitor { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4983 | ASTReader &Reader; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4984 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4985 | llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4986 | |
| 4987 | public: |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4988 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 4989 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 4990 | llvm::DenseMap<DeclarationName, |
| 4991 | SmallVector<NamedDecl *, 8> > &Decls) |
| 4992 | : Reader(Reader), Contexts(Contexts), Decls(Decls) { } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4993 | |
| 4994 | static bool visit(ModuleFile &M, void *UserData) { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 4995 | DeclContextAllNamesVisitor *This |
| 4996 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4997 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 4998 | // Check whether we have any visible declaration information for |
| 4999 | // this context in this module. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5000 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5001 | bool FoundInfo = false; |
| 5002 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5003 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5004 | if (Info != M.DeclContextInfos.end() && |
| 5005 | Info->second.NameLookupTableData) { |
| 5006 | FoundInfo = true; |
| 5007 | break; |
| 5008 | } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5011 | if (!FoundInfo) |
| 5012 | return false; |
| 5013 | |
| 5014 | ASTDeclContextNameLookupTable *LookupTable = |
| 5015 | Info->second.NameLookupTableData; |
| 5016 | bool FoundAnything = false; |
| 5017 | for (ASTDeclContextNameLookupTable::data_iterator |
| 5018 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 5019 | I != E; ++I) { |
| 5020 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 5021 | for (; Data.first != Data.second; ++Data.first) { |
| 5022 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 5023 | *Data.first); |
| 5024 | if (!ND) |
| 5025 | continue; |
| 5026 | |
| 5027 | // Record this declaration. |
| 5028 | FoundAnything = true; |
| 5029 | This->Decls[ND->getDeclName()].push_back(ND); |
| 5030 | } |
| 5031 | } |
| 5032 | |
| 5033 | return FoundAnything; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5034 | } |
| 5035 | }; |
| 5036 | } |
| 5037 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5038 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5039 | if (!DC->hasExternalVisibleStorage()) |
| 5040 | return; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5041 | llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls; |
| 5042 | |
| 5043 | // Compute the declaration contexts we need to look into. Multiple such |
| 5044 | // declaration contexts occur when two declaration contexts from disjoint |
| 5045 | // modules get merged, e.g., when two namespaces with the same name are |
| 5046 | // independently defined in separate modules. |
| 5047 | SmallVector<const DeclContext *, 2> Contexts; |
| 5048 | Contexts.push_back(DC); |
| 5049 | |
| 5050 | if (DC->isNamespace()) { |
| 5051 | MergedDeclsMap::iterator Merged |
| 5052 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5053 | if (Merged != MergedDecls.end()) { |
| 5054 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5055 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5056 | } |
| 5057 | } |
| 5058 | |
| 5059 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); |
| 5060 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 5061 | ++NumVisibleDeclContextsRead; |
| 5062 | |
| 5063 | for (llvm::DenseMap<DeclarationName, |
| 5064 | llvm::SmallVector<NamedDecl*, 8> >::iterator |
| 5065 | I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 5066 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 5067 | } |
Argyrios Kyrtzidis | 394e539 | 2012-04-26 18:34:14 +0000 | [diff] [blame] | 5068 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5071 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 5072 | /// before receiving the implementation, and codegen depends on this. |
| 5073 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 5074 | /// implementation before passing the deserialized implementation decl. |
| 5075 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 5076 | ASTConsumer *Consumer) { |
| 5077 | assert(ImplD && Consumer); |
| 5078 | |
| 5079 | for (ObjCImplDecl::method_iterator |
| 5080 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 5081 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5082 | |
| 5083 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 5084 | } |
| 5085 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5086 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5087 | assert(Consumer); |
| 5088 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5089 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5090 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5091 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5092 | PassInterestingDeclToConsumer(D); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5096 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 5097 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5098 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 5099 | else |
| 5100 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 5101 | } |
| 5102 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5103 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 5104 | this->Consumer = Consumer; |
| 5105 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5106 | if (!Consumer) |
| 5107 | return; |
| 5108 | |
| 5109 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5110 | // Force deserialization of this decl, which will cause it to be queued for |
| 5111 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 5112 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5113 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 5114 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 5115 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5116 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5119 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5120 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5121 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5122 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5123 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5124 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5125 | unsigned NumDeclsLoaded |
| 5126 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 5127 | (Decl *)0); |
| 5128 | unsigned NumIdentifiersLoaded |
| 5129 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 5130 | IdentifiersLoaded.end(), |
| 5131 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5132 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5133 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 5134 | SelectorsLoaded.end(), |
| 5135 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 5136 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 5137 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 5138 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 5139 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5140 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 5141 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 5142 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5143 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5144 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5145 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 5146 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 5147 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5148 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5149 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 5150 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5151 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5152 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5153 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 5154 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5155 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5156 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5157 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 5158 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5159 | if (TotalNumStatements) |
| 5160 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 5161 | NumStatementsRead, TotalNumStatements, |
| 5162 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 5163 | if (TotalNumMacros) |
| 5164 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5165 | NumMacrosRead, TotalNumMacros, |
| 5166 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 5167 | if (TotalLexicalDeclContexts) |
| 5168 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 5169 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 5170 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 5171 | * 100)); |
| 5172 | if (TotalVisibleDeclContexts) |
| 5173 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 5174 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 5175 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 5176 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5177 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5178 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5179 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 5180 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5181 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5182 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5183 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5184 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5185 | dump(); |
| 5186 | std::fprintf(stderr, "\n"); |
| 5187 | } |
| 5188 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5189 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5190 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5191 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5192 | const ContinuousRangeMap<Key, ModuleFile *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5193 | InitialCapacity> &Map) { |
| 5194 | if (Map.begin() == Map.end()) |
| 5195 | return; |
| 5196 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5197 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5198 | llvm::errs() << Name << ":\n"; |
| 5199 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5200 | I != IEnd; ++I) { |
| 5201 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 5202 | << "\n"; |
| 5203 | } |
| 5204 | } |
| 5205 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5206 | void ASTReader::dump() { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5207 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5208 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5209 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 5210 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5211 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5212 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5213 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5214 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5215 | dumpModuleIDMap("Global preprocessed entity map", |
| 5216 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5217 | |
| 5218 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 5219 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 5220 | MEnd = ModuleMgr.end(); |
| 5221 | M != MEnd; ++M) |
| 5222 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5225 | /// Return the amount of memory used by memory buffers, breaking down |
| 5226 | /// by heap-backed versus mmap'ed memory. |
| 5227 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5228 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 5229 | E = ModuleMgr.end(); I != E; ++I) { |
| 5230 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5231 | size_t bytes = buf->getBufferSize(); |
| 5232 | switch (buf->getBufferKind()) { |
| 5233 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 5234 | sizes.malloc_bytes += bytes; |
| 5235 | break; |
| 5236 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 5237 | sizes.mmap_bytes += bytes; |
| 5238 | break; |
| 5239 | } |
| 5240 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5241 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5244 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5245 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5246 | S.ExternalSource = this; |
| 5247 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5248 | // Makes sure any declarations that were deserialized "too early" |
| 5249 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 5250 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5251 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 5252 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5253 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5254 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5255 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5256 | // Load the offsets of the declarations that Sema references. |
| 5257 | // They will be lazily deserialized when needed. |
| 5258 | if (!SemaDeclRefs.empty()) { |
| 5259 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 5260 | if (!SemaObj->StdNamespace) |
| 5261 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 5262 | if (!SemaObj->StdBadAlloc) |
| 5263 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5264 | } |
| 5265 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5266 | if (!FPPragmaOptions.empty()) { |
| 5267 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 5268 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 5269 | } |
| 5270 | |
| 5271 | if (!OpenCLExtensions.empty()) { |
| 5272 | unsigned I = 0; |
| 5273 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 5274 | #include "clang/Basic/OpenCLExtensions.def" |
| 5275 | |
| 5276 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 5277 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5278 | } |
| 5279 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5280 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5281 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart), |
| 5282 | /*PriorGeneration=*/0); |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5283 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5284 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5285 | markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5286 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5287 | } |
| 5288 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5289 | namespace clang { |
| 5290 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 5291 | /// identifiers stored within a set of AST files. |
| 5292 | class ASTIdentifierIterator : public IdentifierIterator { |
| 5293 | /// \brief The AST reader whose identifiers are being enumerated. |
| 5294 | const ASTReader &Reader; |
| 5295 | |
| 5296 | /// \brief The current index into the chain of AST files stored in |
| 5297 | /// the AST reader. |
| 5298 | unsigned Index; |
| 5299 | |
| 5300 | /// \brief The current position within the identifier lookup table |
| 5301 | /// of the current AST file. |
| 5302 | ASTIdentifierLookupTable::key_iterator Current; |
| 5303 | |
| 5304 | /// \brief The end position within the identifier lookup table of |
| 5305 | /// the current AST file. |
| 5306 | ASTIdentifierLookupTable::key_iterator End; |
| 5307 | |
| 5308 | public: |
| 5309 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 5310 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5311 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5312 | }; |
| 5313 | } |
| 5314 | |
| 5315 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5316 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5317 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5318 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5319 | Current = IdTable->key_begin(); |
| 5320 | End = IdTable->key_end(); |
| 5321 | } |
| 5322 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5323 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5324 | while (Current == End) { |
| 5325 | // If we have exhausted all of our AST files, we're done. |
| 5326 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5327 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5328 | |
| 5329 | --Index; |
| 5330 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5331 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 5332 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5333 | Current = IdTable->key_begin(); |
| 5334 | End = IdTable->key_end(); |
| 5335 | } |
| 5336 | |
| 5337 | // We have any identifiers remaining in the current AST file; return |
| 5338 | // the next one. |
| 5339 | std::pair<const char*, unsigned> Key = *Current; |
| 5340 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5341 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 5345 | return new ASTIdentifierIterator(*this); |
| 5346 | } |
| 5347 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5348 | namespace clang { namespace serialization { |
| 5349 | class ReadMethodPoolVisitor { |
| 5350 | ASTReader &Reader; |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5351 | Selector Sel; |
| 5352 | unsigned PriorGeneration; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5353 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 5354 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5355 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5356 | public: |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5357 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 5358 | unsigned PriorGeneration) |
| 5359 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5360 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5361 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5362 | ReadMethodPoolVisitor *This |
| 5363 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 5364 | |
| 5365 | if (!M.SelectorLookupTable) |
| 5366 | return false; |
| 5367 | |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5368 | // If we've already searched this module file, skip it now. |
| 5369 | if (M.Generation <= This->PriorGeneration) |
| 5370 | return true; |
| 5371 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5372 | ASTSelectorLookupTable *PoolTable |
| 5373 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 5374 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 5375 | if (Pos == PoolTable->end()) |
| 5376 | return false; |
| 5377 | |
| 5378 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5379 | // FIXME: Not quite happy with the statistics here. We probably should |
| 5380 | // disable this tracking when called via LoadSelector. |
| 5381 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5382 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5383 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5384 | if (This->Reader.DeserializationListener) |
| 5385 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 5386 | This->Sel); |
| 5387 | |
| 5388 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 5389 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 5390 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5391 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5392 | |
| 5393 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5394 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 5395 | return InstanceMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5396 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5397 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5398 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5399 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 5400 | return FactoryMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5401 | } |
| 5402 | }; |
| 5403 | } } // end namespace clang::serialization |
| 5404 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5405 | /// \brief Add the given set of methods to the method list. |
| 5406 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 5407 | ObjCMethodList &List) { |
| 5408 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 5409 | S.addMethodToGlobalList(&List, Methods[I]); |
| 5410 | } |
| 5411 | } |
| 5412 | |
| 5413 | void ASTReader::ReadMethodPool(Selector Sel) { |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5414 | // Get the selector generation and update it to the current generation. |
| 5415 | unsigned &Generation = SelectorGeneration[Sel]; |
| 5416 | unsigned PriorGeneration = Generation; |
| 5417 | Generation = CurrentGeneration; |
| 5418 | |
| 5419 | // Search for methods defined with this selector. |
| 5420 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5421 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5422 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5423 | if (Visitor.getInstanceMethods().empty() && |
| 5424 | Visitor.getFactoryMethods().empty()) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5425 | ++NumMethodPoolMisses; |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5426 | return; |
| 5427 | } |
| 5428 | |
| 5429 | if (!getSema()) |
| 5430 | return; |
| 5431 | |
| 5432 | Sema &S = *getSema(); |
| 5433 | Sema::GlobalMethodPool::iterator Pos |
| 5434 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 5435 | |
| 5436 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 5437 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5438 | } |
| 5439 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5440 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5441 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5442 | Namespaces.clear(); |
| 5443 | |
| 5444 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 5445 | if (NamespaceDecl *Namespace |
| 5446 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 5447 | Namespaces.push_back(Namespace); |
| 5448 | } |
| 5449 | } |
| 5450 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 5451 | void ASTReader::ReadTentativeDefinitions( |
| 5452 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 5453 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 5454 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 5455 | if (Var) |
| 5456 | TentativeDefs.push_back(Var); |
| 5457 | } |
| 5458 | TentativeDefinitions.clear(); |
| 5459 | } |
| 5460 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 5461 | void ASTReader::ReadUnusedFileScopedDecls( |
| 5462 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 5463 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 5464 | DeclaratorDecl *D |
| 5465 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 5466 | if (D) |
| 5467 | Decls.push_back(D); |
| 5468 | } |
| 5469 | UnusedFileScopedDecls.clear(); |
| 5470 | } |
| 5471 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 5472 | void ASTReader::ReadDelegatingConstructors( |
| 5473 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 5474 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 5475 | CXXConstructorDecl *D |
| 5476 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 5477 | if (D) |
| 5478 | Decls.push_back(D); |
| 5479 | } |
| 5480 | DelegatingCtorDecls.clear(); |
| 5481 | } |
| 5482 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 5483 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 5484 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 5485 | TypedefNameDecl *D |
| 5486 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 5487 | if (D) |
| 5488 | Decls.push_back(D); |
| 5489 | } |
| 5490 | ExtVectorDecls.clear(); |
| 5491 | } |
| 5492 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 5493 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 5494 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 5495 | CXXRecordDecl *D |
| 5496 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 5497 | if (D) |
| 5498 | Decls.push_back(D); |
| 5499 | } |
| 5500 | DynamicClasses.clear(); |
| 5501 | } |
| 5502 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 5503 | void |
| 5504 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 5505 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 5506 | NamedDecl *D |
| 5507 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 5508 | if (D) |
| 5509 | Decls.push_back(D); |
| 5510 | } |
| 5511 | LocallyScopedExternalDecls.clear(); |
| 5512 | } |
| 5513 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 5514 | void ASTReader::ReadReferencedSelectors( |
| 5515 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 5516 | if (ReferencedSelectorsData.empty()) |
| 5517 | return; |
| 5518 | |
| 5519 | // If there are @selector references added them to its pool. This is for |
| 5520 | // implementation of -Wselector. |
| 5521 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 5522 | unsigned I = 0; |
| 5523 | while (I < DataSize) { |
| 5524 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 5525 | SourceLocation SelLoc |
| 5526 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 5527 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 5528 | } |
| 5529 | ReferencedSelectorsData.clear(); |
| 5530 | } |
| 5531 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 5532 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 5533 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 5534 | if (WeakUndeclaredIdentifiers.empty()) |
| 5535 | return; |
| 5536 | |
| 5537 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 5538 | IdentifierInfo *WeakId |
| 5539 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5540 | IdentifierInfo *AliasId |
| 5541 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5542 | SourceLocation Loc |
| 5543 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 5544 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 5545 | WeakInfo WI(AliasId, Loc); |
| 5546 | WI.setUsed(Used); |
| 5547 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 5548 | } |
| 5549 | WeakUndeclaredIdentifiers.clear(); |
| 5550 | } |
| 5551 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 5552 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 5553 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 5554 | ExternalVTableUse VT; |
| 5555 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 5556 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 5557 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 5558 | VTables.push_back(VT); |
| 5559 | } |
| 5560 | |
| 5561 | VTableUses.clear(); |
| 5562 | } |
| 5563 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 5564 | void ASTReader::ReadPendingInstantiations( |
| 5565 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 5566 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 5567 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 5568 | SourceLocation Loc |
| 5569 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 5570 | Pending.push_back(std::make_pair(D, Loc)); |
| 5571 | } |
| 5572 | PendingInstantiations.clear(); |
| 5573 | } |
| 5574 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5575 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5576 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 5577 | ReadMethodPool(Sel); |
| 5578 | } |
| 5579 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5580 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5581 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 5582 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5583 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5584 | if (DeserializationListener) |
| 5585 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5586 | } |
| 5587 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5588 | /// \brief Set the globally-visible declarations associated with the given |
| 5589 | /// identifier. |
| 5590 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5591 | /// 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] | 5592 | /// 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] | 5593 | /// them. |
| 5594 | /// |
| 5595 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 5596 | /// declarations. |
| 5597 | /// |
| 5598 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 5599 | /// visible at global scope. |
| 5600 | /// |
| 5601 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 5602 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 5603 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5604 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5605 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5606 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5607 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5608 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5609 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 5610 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 5611 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 5612 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5613 | return; |
| 5614 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5615 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5616 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 5617 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 5618 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5619 | // Introduce this declaration into the translation-unit scope |
| 5620 | // and add it to the declaration chain for this identifier, so |
| 5621 | // that (unqualified) name lookup will find it. |
| 5622 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5623 | } else { |
| 5624 | // Queue this declaration so that it will be added to the |
| 5625 | // translation unit scope and identifier's declaration chain |
| 5626 | // once a Sema object is known. |
| 5627 | PreloadedDecls.push_back(D); |
| 5628 | } |
| 5629 | } |
| 5630 | } |
| 5631 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5632 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5633 | if (ID == 0) |
| 5634 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5635 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5636 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5637 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5638 | return 0; |
| 5639 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5640 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5641 | ID -= 1; |
| 5642 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 5643 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 5644 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5645 | ModuleFile *M = I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5646 | unsigned Index = ID - M->BaseIdentifierID; |
| 5647 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 5648 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5649 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 5650 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 5651 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 5652 | // unsigned integers. This is important to avoid integer overflow when |
| 5653 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 5654 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 5655 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 5656 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5657 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5658 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5659 | if (DeserializationListener) |
| 5660 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5661 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5662 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5663 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5664 | } |
| 5665 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5666 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5667 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 5668 | } |
| 5669 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5670 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 5671 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 5672 | return LocalID; |
| 5673 | |
| 5674 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5675 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 5676 | assert(I != M.IdentifierRemap.end() |
| 5677 | && "Invalid index into identifier index remap"); |
| 5678 | |
| 5679 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5680 | } |
| 5681 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5682 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 5683 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5684 | } |
| 5685 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5686 | serialization::SubmoduleID |
| 5687 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 5688 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 5689 | return LocalID; |
| 5690 | |
| 5691 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5692 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 5693 | assert(I != M.SubmoduleRemap.end() |
| 5694 | && "Invalid index into identifier index remap"); |
| 5695 | |
| 5696 | return LocalID + I->second; |
| 5697 | } |
| 5698 | |
| 5699 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 5700 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 5701 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 5702 | return 0; |
| 5703 | } |
| 5704 | |
| 5705 | if (GlobalID > SubmodulesLoaded.size()) { |
| 5706 | Error("submodule ID out of range in AST file"); |
| 5707 | return 0; |
| 5708 | } |
| 5709 | |
| 5710 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 5711 | } |
| 5712 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5713 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5714 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 5715 | } |
| 5716 | |
| 5717 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5718 | if (ID == 0) |
| 5719 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5720 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5721 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5722 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5723 | return Selector(); |
| 5724 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5725 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5726 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5727 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5728 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 5729 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5730 | ModuleFile &M = *I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5731 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5732 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5733 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5734 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5735 | if (DeserializationListener) |
| 5736 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5737 | } |
| 5738 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5739 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5740 | } |
| 5741 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5742 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5743 | return DecodeSelector(ID); |
| 5744 | } |
| 5745 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5746 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5747 | // ID 0 (the null selector) is considered an external selector. |
| 5748 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5749 | } |
| 5750 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5751 | serialization::SelectorID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5752 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5753 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 5754 | return LocalID; |
| 5755 | |
| 5756 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5757 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 5758 | assert(I != M.SelectorRemap.end() |
| 5759 | && "Invalid index into identifier index remap"); |
| 5760 | |
| 5761 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5764 | DeclarationName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5765 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5766 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5767 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 5768 | switch (Kind) { |
| 5769 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5770 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5771 | |
| 5772 | case DeclarationName::ObjCZeroArgSelector: |
| 5773 | case DeclarationName::ObjCOneArgSelector: |
| 5774 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5775 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5776 | |
| 5777 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5778 | return Context.DeclarationNames.getCXXConstructorName( |
| 5779 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5780 | |
| 5781 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5782 | return Context.DeclarationNames.getCXXDestructorName( |
| 5783 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5784 | |
| 5785 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5786 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 5787 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5788 | |
| 5789 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5790 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5791 | (OverloadedOperatorKind)Record[Idx++]); |
| 5792 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5793 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5794 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5795 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5796 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5797 | case DeclarationName::CXXUsingDirective: |
| 5798 | return DeclarationName::getUsingDirectiveName(); |
| 5799 | } |
| 5800 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 5801 | llvm_unreachable("Invalid NameKind!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5802 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5803 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5804 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5805 | DeclarationNameLoc &DNLoc, |
| 5806 | DeclarationName Name, |
| 5807 | const RecordData &Record, unsigned &Idx) { |
| 5808 | switch (Name.getNameKind()) { |
| 5809 | case DeclarationName::CXXConstructorName: |
| 5810 | case DeclarationName::CXXDestructorName: |
| 5811 | case DeclarationName::CXXConversionFunctionName: |
| 5812 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5813 | break; |
| 5814 | |
| 5815 | case DeclarationName::CXXOperatorName: |
| 5816 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5817 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5818 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5819 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5820 | break; |
| 5821 | |
| 5822 | case DeclarationName::CXXLiteralOperatorName: |
| 5823 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5824 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5825 | break; |
| 5826 | |
| 5827 | case DeclarationName::Identifier: |
| 5828 | case DeclarationName::ObjCZeroArgSelector: |
| 5829 | case DeclarationName::ObjCOneArgSelector: |
| 5830 | case DeclarationName::ObjCMultiArgSelector: |
| 5831 | case DeclarationName::CXXUsingDirective: |
| 5832 | break; |
| 5833 | } |
| 5834 | } |
| 5835 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5836 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5837 | DeclarationNameInfo &NameInfo, |
| 5838 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5839 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5840 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5841 | DeclarationNameLoc DNLoc; |
| 5842 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5843 | NameInfo.setInfo(DNLoc); |
| 5844 | } |
| 5845 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5846 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5847 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5848 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5849 | unsigned NumTPLists = Record[Idx++]; |
| 5850 | Info.NumTemplParamLists = NumTPLists; |
| 5851 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5852 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5853 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5854 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5855 | } |
| 5856 | } |
| 5857 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5858 | TemplateName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5859 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5860 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5861 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5862 | switch (Kind) { |
| 5863 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5864 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5865 | |
| 5866 | case TemplateName::OverloadedTemplate: { |
| 5867 | unsigned size = Record[Idx++]; |
| 5868 | UnresolvedSet<8> Decls; |
| 5869 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5870 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5871 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5872 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5873 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5874 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5875 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5876 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5877 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5878 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5879 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5880 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5881 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5882 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5883 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5884 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5885 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5886 | GetIdentifierInfo(F, Record, |
| 5887 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5888 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5889 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5890 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5891 | |
| 5892 | case TemplateName::SubstTemplateTemplateParm: { |
| 5893 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5894 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5895 | if (!param) return TemplateName(); |
| 5896 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5897 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5898 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5899 | |
| 5900 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5901 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5902 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5903 | if (!Param) |
| 5904 | return TemplateName(); |
| 5905 | |
| 5906 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5907 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5908 | return TemplateName(); |
| 5909 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5910 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5911 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5912 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5913 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5914 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5915 | } |
| 5916 | |
| 5917 | TemplateArgument |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5918 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5919 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5920 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5921 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5922 | case TemplateArgument::Null: |
| 5923 | return TemplateArgument(); |
| 5924 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5925 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5926 | case TemplateArgument::Declaration: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5927 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5928 | case TemplateArgument::Integral: { |
| 5929 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5930 | QualType T = readType(F, Record, Idx); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 5931 | return TemplateArgument(Context, Value, T); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5932 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5933 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5934 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5935 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5936 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5937 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5938 | if (unsigned NumExpansions = Record[Idx++]) |
| 5939 | NumTemplateExpansions = NumExpansions - 1; |
| 5940 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5941 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5942 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5943 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5944 | case TemplateArgument::Pack: { |
| 5945 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5946 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5947 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5948 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5949 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5950 | } |
| 5951 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5952 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5953 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5954 | } |
| 5955 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5956 | TemplateParameterList * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5957 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5958 | const RecordData &Record, unsigned &Idx) { |
| 5959 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5960 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5961 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5962 | |
| 5963 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5964 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5965 | Params.reserve(NumParams); |
| 5966 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5967 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5968 | |
| 5969 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5970 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5971 | Params.data(), Params.size(), RAngleLoc); |
| 5972 | return TemplateParams; |
| 5973 | } |
| 5974 | |
| 5975 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5976 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5977 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5978 | ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5979 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5980 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5981 | TemplArgs.reserve(NumTemplateArgs); |
| 5982 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5983 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5984 | } |
| 5985 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5986 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5987 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5988 | const RecordData &Record, unsigned &Idx) { |
| 5989 | unsigned NumDecls = Record[Idx++]; |
| 5990 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5991 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5992 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5993 | Set.addDecl(D, AS); |
| 5994 | } |
| 5995 | } |
| 5996 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5997 | CXXBaseSpecifier |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5998 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5999 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6000 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 6001 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 6002 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6003 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6004 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6005 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6006 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6007 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6008 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6009 | Result.setInheritConstructors(inheritConstructors); |
| 6010 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6011 | } |
| 6012 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6013 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6014 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6015 | unsigned &Idx) { |
| 6016 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6017 | unsigned NumInitializers = Record[Idx++]; |
| 6018 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6019 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6020 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6021 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6022 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6023 | bool IsBaseVirtual = false; |
| 6024 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6025 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6026 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6027 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 6028 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6029 | case CTOR_INITIALIZER_BASE: |
| 6030 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6031 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6032 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6033 | |
| 6034 | case CTOR_INITIALIZER_DELEGATING: |
| 6035 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6036 | break; |
| 6037 | |
| 6038 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6039 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6040 | break; |
| 6041 | |
| 6042 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6043 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6044 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6045 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6046 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 6047 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6048 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6049 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 6050 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6051 | bool IsWritten = Record[Idx++]; |
| 6052 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6053 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6054 | if (IsWritten) { |
| 6055 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6056 | } else { |
| 6057 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6058 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 6059 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6060 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6061 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6062 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6063 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6064 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6065 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6066 | LParenLoc, Init, RParenLoc, |
| 6067 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6068 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6069 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 6070 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6071 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6072 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6073 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6074 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6075 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6076 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6077 | MemberOrEllipsisLoc, LParenLoc, |
| 6078 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6079 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6080 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6081 | LParenLoc, Init, RParenLoc, |
| 6082 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 6085 | if (IsWritten) |
| 6086 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6087 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6088 | } |
| 6089 | } |
| 6090 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6091 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6092 | } |
| 6093 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6094 | NestedNameSpecifier * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6095 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6096 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6097 | unsigned N = Record[Idx++]; |
| 6098 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 6099 | for (unsigned I = 0; I != N; ++I) { |
| 6100 | NestedNameSpecifier::SpecifierKind Kind |
| 6101 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6102 | switch (Kind) { |
| 6103 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6104 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6105 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6106 | break; |
| 6107 | } |
| 6108 | |
| 6109 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6110 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6111 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6112 | break; |
| 6113 | } |
| 6114 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6115 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6116 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6117 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6118 | break; |
| 6119 | } |
| 6120 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6121 | case NestedNameSpecifier::TypeSpec: |
| 6122 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6123 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 6124 | if (!T) |
| 6125 | return 0; |
| 6126 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6127 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6128 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6129 | break; |
| 6130 | } |
| 6131 | |
| 6132 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6133 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6134 | // No associated value, and there can't be a prefix. |
| 6135 | break; |
| 6136 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6137 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 6138 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6139 | } |
| 6140 | return NNS; |
| 6141 | } |
| 6142 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6143 | NestedNameSpecifierLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6144 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6145 | unsigned &Idx) { |
| 6146 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6147 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6148 | for (unsigned I = 0; I != N; ++I) { |
| 6149 | NestedNameSpecifier::SpecifierKind Kind |
| 6150 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6151 | switch (Kind) { |
| 6152 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6153 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6154 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6155 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6156 | break; |
| 6157 | } |
| 6158 | |
| 6159 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6160 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6161 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6162 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6163 | break; |
| 6164 | } |
| 6165 | |
| 6166 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6167 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6168 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6169 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6170 | break; |
| 6171 | } |
| 6172 | |
| 6173 | case NestedNameSpecifier::TypeSpec: |
| 6174 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6175 | bool Template = Record[Idx++]; |
| 6176 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 6177 | if (!T) |
| 6178 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6179 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6180 | |
| 6181 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6182 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6183 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 6184 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6185 | break; |
| 6186 | } |
| 6187 | |
| 6188 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6189 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6190 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6191 | break; |
| 6192 | } |
| 6193 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6196 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6197 | } |
| 6198 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6199 | SourceRange |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6200 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6201 | unsigned &Idx) { |
| 6202 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 6203 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 6204 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6207 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6208 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6209 | unsigned BitWidth = Record[Idx++]; |
| 6210 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 6211 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 6212 | Idx += NumWords; |
| 6213 | return Result; |
| 6214 | } |
| 6215 | |
| 6216 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6217 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6218 | bool isUnsigned = Record[Idx++]; |
| 6219 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 6220 | } |
| 6221 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6222 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6223 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6224 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 6225 | } |
| 6226 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6227 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6228 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6229 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 6230 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6231 | Idx += Len; |
| 6232 | return Result; |
| 6233 | } |
| 6234 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 6235 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 6236 | unsigned &Idx) { |
| 6237 | unsigned Major = Record[Idx++]; |
| 6238 | unsigned Minor = Record[Idx++]; |
| 6239 | unsigned Subminor = Record[Idx++]; |
| 6240 | if (Minor == 0) |
| 6241 | return VersionTuple(Major); |
| 6242 | if (Subminor == 0) |
| 6243 | return VersionTuple(Major, Minor - 1); |
| 6244 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 6245 | } |
| 6246 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6247 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6248 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6249 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6250 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6251 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6254 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 6255 | return Diag(SourceLocation(), DiagID); |
| 6256 | } |
| 6257 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6258 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6259 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6260 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6261 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6262 | /// \brief Retrieve the identifier table associated with the |
| 6263 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6264 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6265 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6266 | } |
| 6267 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6268 | /// \brief Record that the given ID maps to the given switch-case |
| 6269 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6270 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6271 | assert((*CurrSwitchCaseStmts)[ID] == 0 && |
| 6272 | "Already have a SwitchCase with this ID"); |
| 6273 | (*CurrSwitchCaseStmts)[ID] = SC; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6277 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6278 | assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID"); |
| 6279 | return (*CurrSwitchCaseStmts)[ID]; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6280 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 6281 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6282 | void ASTReader::ClearSwitchCaseIDs() { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6283 | CurrSwitchCaseStmts->clear(); |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6284 | } |
| 6285 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6286 | void ASTReader::ReadComments() { |
| 6287 | std::vector<RawComment> Comments; |
| 6288 | for (SmallVectorImpl<std::pair<llvm::BitstreamCursor, |
| 6289 | serialization::ModuleFile *> >::iterator |
| 6290 | I = CommentsCursors.begin(), |
| 6291 | E = CommentsCursors.end(); |
| 6292 | I != E; ++I) { |
| 6293 | llvm::BitstreamCursor &Cursor = I->first; |
| 6294 | serialization::ModuleFile &F = *I->second; |
| 6295 | SavedStreamPosition SavedPosition(Cursor); |
| 6296 | |
| 6297 | RecordData Record; |
| 6298 | while (true) { |
| 6299 | unsigned Code = Cursor.ReadCode(); |
| 6300 | if (Code == llvm::bitc::END_BLOCK) |
| 6301 | break; |
| 6302 | |
| 6303 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 6304 | // No known subblocks, always skip them. |
| 6305 | Cursor.ReadSubBlockID(); |
| 6306 | if (Cursor.SkipBlock()) { |
| 6307 | Error("malformed block record in AST file"); |
| 6308 | return; |
| 6309 | } |
| 6310 | continue; |
| 6311 | } |
| 6312 | |
| 6313 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 6314 | Cursor.ReadAbbrevRecord(); |
| 6315 | continue; |
| 6316 | } |
| 6317 | |
| 6318 | // Read a record. |
| 6319 | Record.clear(); |
| 6320 | switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) { |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6321 | case COMMENTS_RAW_COMMENT: { |
| 6322 | unsigned Idx = 0; |
| 6323 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 6324 | RawComment::CommentKind Kind = |
| 6325 | (RawComment::CommentKind) Record[Idx++]; |
| 6326 | bool IsTrailingComment = Record[Idx++]; |
| 6327 | bool IsAlmostTrailingComment = Record[Idx++]; |
| 6328 | Comments.push_back(RawComment(SR, Kind, IsTrailingComment, |
| 6329 | IsAlmostTrailingComment)); |
| 6330 | break; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6331 | } |
| 6332 | } |
| 6333 | } |
| 6334 | } |
| 6335 | Context.Comments.addCommentsToFront(Comments); |
| 6336 | } |
| 6337 | |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6338 | void ASTReader::finishPendingActions() { |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 6339 | while (!PendingIdentifierInfos.empty() || !PendingDeclChains.empty()) { |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6340 | // If any identifiers with corresponding top-level declarations have |
| 6341 | // been loaded, load those declarations now. |
| 6342 | while (!PendingIdentifierInfos.empty()) { |
| 6343 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 6344 | PendingIdentifierInfos.front().DeclIDs, true); |
| 6345 | PendingIdentifierInfos.pop_front(); |
| 6346 | } |
| 6347 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6348 | // Load pending declaration chains. |
| 6349 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
| 6350 | loadPendingDeclChain(PendingDeclChains[I]); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6351 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6352 | } |
| 6353 | PendingDeclChains.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6354 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6355 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6356 | // If we deserialized any C++ or Objective-C class definitions, any |
| 6357 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 6358 | // that all redeclarations point to the definitions. Note that this can only |
| 6359 | // happen now, after the redeclaration chains have been fully wired. |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6360 | for (llvm::SmallPtrSet<Decl *, 4>::iterator D = PendingDefinitions.begin(), |
| 6361 | DEnd = PendingDefinitions.end(); |
| 6362 | D != DEnd; ++D) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6363 | if (TagDecl *TD = dyn_cast<TagDecl>(*D)) { |
| 6364 | if (const TagType *TagT = dyn_cast<TagType>(TD->TypeForDecl)) { |
| 6365 | // Make sure that the TagType points at the definition. |
| 6366 | const_cast<TagType*>(TagT)->decl = TD; |
| 6367 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6368 | |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6369 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(*D)) { |
| 6370 | for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), |
| 6371 | REnd = RD->redecls_end(); |
| 6372 | R != REnd; ++R) |
| 6373 | cast<CXXRecordDecl>(*R)->DefinitionData = RD->DefinitionData; |
| 6374 | |
| 6375 | } |
| 6376 | |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6377 | continue; |
| 6378 | } |
| 6379 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6380 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(*D)) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6381 | // Make sure that the ObjCInterfaceType points at the definition. |
| 6382 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 6383 | ->Decl = ID; |
| 6384 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6385 | for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), |
| 6386 | REnd = ID->redecls_end(); |
| 6387 | R != REnd; ++R) |
| 6388 | R->Data = ID->Data; |
| 6389 | |
| 6390 | continue; |
| 6391 | } |
| 6392 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6393 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(*D)) { |
| 6394 | for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), |
| 6395 | REnd = PD->redecls_end(); |
| 6396 | R != REnd; ++R) |
| 6397 | R->Data = PD->Data; |
| 6398 | |
| 6399 | continue; |
| 6400 | } |
| 6401 | |
| 6402 | RedeclarableTemplateDecl *RTD |
| 6403 | = cast<RedeclarableTemplateDecl>(*D)->getCanonicalDecl(); |
| 6404 | for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), |
| 6405 | REnd = RTD->redecls_end(); |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6406 | R != REnd; ++R) |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6407 | R->Common = RTD->Common; |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6408 | } |
| 6409 | PendingDefinitions.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6410 | } |
| 6411 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6412 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6413 | assert(NumCurrentElementsDeserializing && |
| 6414 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 6415 | if (NumCurrentElementsDeserializing == 1) { |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6416 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 6417 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 6418 | finishPendingActions(); |
| 6419 | } |
| 6420 | --NumCurrentElementsDeserializing; |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6421 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6422 | if (NumCurrentElementsDeserializing == 0 && |
| 6423 | Consumer && !PassingDeclsToConsumer) { |
| 6424 | // Guard variable to avoid recursively redoing the process of passing |
| 6425 | // decls to consumer. |
| 6426 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 6427 | true); |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6428 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6429 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 6430 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 6431 | // decls to the consumer. |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6432 | Decl *D = InterestingDecls.front(); |
| 6433 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6434 | PassInterestingDeclToConsumer(D); |
| 6435 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6436 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6437 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 6438 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 6439 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 6440 | StringRef isysroot, bool DisableValidation, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6441 | bool DisableStatCache, bool AllowASTWithCompilerErrors) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6442 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 6443 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6444 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Jonathan D. Turner | 1afb661 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 6445 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 6446 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6447 | DisableValidation(DisableValidation), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6448 | DisableStatCache(DisableStatCache), |
| 6449 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6450 | CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), |
| 6451 | NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6452 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6453 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 6454 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 6455 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 6456 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6457 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 6458 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6459 | PassingDeclsToConsumer(false), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6460 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6461 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6462 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6463 | } |
| 6464 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6465 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6466 | for (DeclContextVisibleUpdatesPending::iterator |
| 6467 | I = PendingVisibleUpdates.begin(), |
| 6468 | E = PendingVisibleUpdates.end(); |
| 6469 | I != E; ++I) { |
| 6470 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 6471 | F = I->second.end(); |
| 6472 | J != F; ++J) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 6473 | delete J->first; |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6474 | } |
| 6475 | } |