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" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 17 | #include "ASTCommon.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 18 | #include "ASTReaderInternals.h" |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 22 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 24 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 26 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 27 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 28 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 29 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 30 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 31 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 32 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 34 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 37 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 39 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 40 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 41 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 42 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 43 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 46 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 47 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 48 | #include "llvm/Support/Path.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) { |
| 67 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
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" |
| 93 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 94 | return false; |
| 95 | } |
| 96 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 97 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 98 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 99 | return false; |
| 100 | |
| 101 | Reader.Diag(diag::warn_pch_target_triple) |
| 102 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 103 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 106 | namespace { |
| 107 | struct EmptyStringRef { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 108 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 109 | }; |
| 110 | struct EmptyBlock { |
| 111 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 112 | }; |
| 113 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 114 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 115 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 116 | PCHPredefinesBlocks R) { |
| 117 | // First, sum up the lengths. |
| 118 | unsigned LL = 0, RL = 0; |
| 119 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 120 | LL += L[I].size(); |
| 121 | } |
| 122 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 123 | RL += R[I].Data.size(); |
| 124 | } |
| 125 | if (LL != RL) |
| 126 | return false; |
| 127 | if (LL == 0 && RL == 0) |
| 128 | return true; |
| 129 | |
| 130 | // Kick out empty parts, they confuse the algorithm below. |
| 131 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 132 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 133 | |
| 134 | // 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] | 135 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 136 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 137 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 138 | for (;;) { |
| 139 | // Compare the current pieces. |
| 140 | if (LR.size() == RR.size()) { |
| 141 | // If they're the same length, it's pretty easy. |
| 142 | if (LR != RR) |
| 143 | return false; |
| 144 | // Both pieces are done, advance. |
| 145 | ++LI; |
| 146 | ++RI; |
| 147 | // If either string is done, they're both done, since they're the same |
| 148 | // length. |
| 149 | if (LI == LN) { |
| 150 | assert(RI == RN && "Strings not the same length after all?"); |
| 151 | return true; |
| 152 | } |
| 153 | LR = L[LI]; |
| 154 | RR = R[RI].Data; |
| 155 | } else if (LR.size() < RR.size()) { |
| 156 | // Right piece is longer. |
| 157 | if (!RR.startswith(LR)) |
| 158 | return false; |
| 159 | ++LI; |
| 160 | assert(LI != LN && "Strings not the same length after all?"); |
| 161 | RR = RR.substr(LR.size()); |
| 162 | LR = L[LI]; |
| 163 | } else { |
| 164 | // Left piece is longer. |
| 165 | if (!LR.startswith(RR)) |
| 166 | return false; |
| 167 | ++RI; |
| 168 | assert(RI != RN && "Strings not the same length after all?"); |
| 169 | LR = LR.substr(RR.size()); |
| 170 | RR = R[RI].Data; |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 175 | static std::pair<FileID, StringRef::size_type> |
| 176 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 177 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 178 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 179 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 180 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 181 | Res.first = Buffers[I].BufferID; |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | return Res; |
| 186 | } |
| 187 | |
| 188 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 189 | StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 190 | std::string &SuggestedPredefines, |
| 191 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 192 | // We are in the context of an implicit include, so the predefines buffer will |
| 193 | // have a #include entry for the PCH file itself (as normalized by the |
| 194 | // preprocessor initialization). Find it and skip over it in the checking |
| 195 | // below. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 196 | llvm::SmallString<256> PCHInclude; |
| 197 | PCHInclude += "#include \""; |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 198 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 199 | PCHInclude += "\"\n"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 200 | std::pair<StringRef,StringRef> Split = |
| 201 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 202 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 203 | if (Left == PP.getPredefines()) { |
| 204 | Error("Missing PCH include entry!"); |
| 205 | return true; |
| 206 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 207 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 208 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 209 | // command line, we're done. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 210 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 211 | CommandLine.push_back(Left); |
| 212 | CommandLine.push_back(Right); |
| 213 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 214 | return false; |
| 215 | |
| 216 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 218 | // The predefines buffers are different. Determine what the differences are, |
| 219 | // and whether they require us to reject the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 220 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 221 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 222 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 224 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 225 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 226 | |
| 227 | // Pick out implicit #includes after the PCH and don't consider them for |
| 228 | // validation; we will insert them into SuggestedPredefines so that the |
| 229 | // preprocessor includes them. |
| 230 | std::string IncludesAfterPCH; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 231 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 232 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 233 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 234 | if (AfterPCHLines[i].startswith("#include ")) { |
| 235 | IncludesAfterPCH += AfterPCHLines[i]; |
| 236 | IncludesAfterPCH += '\n'; |
| 237 | } else { |
| 238 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | // Make sure we add the includes last into SuggestedPredefines before we |
| 243 | // exit this function. |
| 244 | struct AddIncludesRAII { |
| 245 | std::string &SuggestedPredefines; |
| 246 | std::string &IncludesAfterPCH; |
| 247 | |
| 248 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 249 | std::string &IncludesAfterPCH) |
| 250 | : SuggestedPredefines(SuggestedPredefines), |
| 251 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 252 | ~AddIncludesRAII() { |
| 253 | SuggestedPredefines += IncludesAfterPCH; |
| 254 | } |
| 255 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 256 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 257 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 258 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 259 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 260 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 261 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 262 | // Determine which predefines that were used to build the PCH file are missing |
| 263 | // from the command line. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 264 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 265 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 266 | CmdLineLines.begin(), CmdLineLines.end(), |
| 267 | std::back_inserter(MissingPredefines)); |
| 268 | |
| 269 | bool MissingDefines = false; |
| 270 | bool ConflictingDefines = false; |
| 271 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 272 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 273 | if (Missing.startswith("#include ")) { |
| 274 | // An -include was specified when generating the PCH; it is included in |
| 275 | // the PCH, just ignore it. |
| 276 | continue; |
| 277 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 278 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 279 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 280 | return true; |
| 281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 283 | // This is a macro definition. Determine the name of the macro we're |
| 284 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 285 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 287 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 288 | assert(EndOfMacroName != std::string::npos && |
| 289 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 290 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 291 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 292 | // Determine whether this macro was given a different definition on the |
| 293 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 294 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 295 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 296 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 297 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 298 | MacroDefStart); |
| 299 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 300 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 301 | // Different macro; we're done. |
| 302 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 303 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 304 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | |
| 306 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 307 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 309 | (*ConflictPos)[MacroDefLen] != '(') |
| 310 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 311 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 312 | // We found a conflicting macro definition. |
| 313 | break; |
| 314 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 316 | if (ConflictPos != CmdLineLines.end()) { |
| 317 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 318 | << MacroName; |
| 319 | |
| 320 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 321 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 322 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 323 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 324 | SourceLocation PCHMissingLoc = |
| 325 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 326 | .getLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 327 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 328 | |
| 329 | ConflictingDefines = true; |
| 330 | continue; |
| 331 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 333 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 334 | // 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] | 335 | if (ConflictingDefines) |
| 336 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 337 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 338 | if (!MissingDefines) { |
| 339 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 340 | MissingDefines = true; |
| 341 | } |
| 342 | |
| 343 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 344 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 345 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 346 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 347 | SourceLocation PCHMissingLoc = |
| 348 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 349 | .getLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 350 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 351 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 353 | if (ConflictingDefines) |
| 354 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 355 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 356 | // Determine what predefines were introduced based on command-line |
| 357 | // parameters that were not present when building the PCH |
| 358 | // file. Extra #defines are okay, so long as the identifiers being |
| 359 | // defined were not used within the precompiled header. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 360 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 362 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 364 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 365 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 366 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 367 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 368 | return true; |
| 369 | } |
| 370 | |
| 371 | // This is an extra macro definition. Determine the name of the |
| 372 | // macro we're defining. |
| 373 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 375 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 376 | assert(EndOfMacroName != std::string::npos && |
| 377 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 378 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 379 | |
| 380 | // Check whether this name was used somewhere in the PCH file. If |
| 381 | // so, defining it as a macro could change behavior, so we reject |
| 382 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 383 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 384 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 385 | return true; |
| 386 | } |
| 387 | |
| 388 | // Add this definition to the suggested predefines buffer. |
| 389 | SuggestedPredefines += Extra; |
| 390 | SuggestedPredefines += '\n'; |
| 391 | } |
| 392 | |
| 393 | // If we get here, it's because the predefines buffer had compatible |
| 394 | // contents. Accept the PCH file. |
| 395 | return false; |
| 396 | } |
| 397 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 398 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 399 | unsigned ID) { |
| 400 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 401 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void PCHValidator::ReadCounter(unsigned Value) { |
| 405 | PP.setCounterValue(Value); |
| 406 | } |
| 407 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 408 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 409 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 410 | //===----------------------------------------------------------------------===// |
| 411 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 412 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 413 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 414 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 417 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 418 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 419 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 420 | return serialization::ComputeHash(Sel); |
| 421 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 422 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 424 | std::pair<unsigned, unsigned> |
| 425 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 426 | using namespace clang::io; |
| 427 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 428 | unsigned DataLen = ReadUnalignedLE16(d); |
| 429 | return std::make_pair(KeyLen, DataLen); |
| 430 | } |
| 431 | |
| 432 | ASTSelectorLookupTrait::internal_key_type |
| 433 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 434 | using namespace clang::io; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 435 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 436 | unsigned N = ReadUnalignedLE16(d); |
| 437 | IdentifierInfo *FirstII |
| 438 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 439 | if (N == 0) |
| 440 | return SelTable.getNullarySelector(FirstII); |
| 441 | else if (N == 1) |
| 442 | return SelTable.getUnarySelector(FirstII); |
| 443 | |
| 444 | SmallVector<IdentifierInfo *, 16> Args; |
| 445 | Args.push_back(FirstII); |
| 446 | for (unsigned I = 1; I != N; ++I) |
| 447 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 448 | |
| 449 | return SelTable.getSelector(N, Args.data()); |
| 450 | } |
| 451 | |
| 452 | ASTSelectorLookupTrait::data_type |
| 453 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 454 | unsigned DataLen) { |
| 455 | using namespace clang::io; |
| 456 | |
| 457 | data_type Result; |
| 458 | |
| 459 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 460 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 461 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 462 | |
| 463 | // Load instance methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 464 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 465 | if (ObjCMethodDecl *Method |
| 466 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 467 | Result.Instance.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 470 | // Load factory methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 471 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 472 | if (ObjCMethodDecl *Method |
| 473 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 474 | Result.Factory.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 | return Result; |
| 478 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 480 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 481 | return llvm::HashString(StringRef(a.first, a.second)); |
| 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 | std::pair<unsigned, unsigned> |
| 485 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 486 | using namespace clang::io; |
| 487 | unsigned DataLen = ReadUnalignedLE16(d); |
| 488 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 489 | return std::make_pair(KeyLen, DataLen); |
| 490 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 491 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 492 | std::pair<const char*, unsigned> |
| 493 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 494 | assert(n >= 2 && d[n-1] == '\0'); |
| 495 | return std::make_pair((const char*) d, n-1); |
| 496 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 497 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 498 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 499 | const unsigned char* d, |
| 500 | unsigned DataLen) { |
| 501 | using namespace clang::io; |
| 502 | unsigned RawID = ReadUnalignedLE32(d); |
| 503 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 505 | // Wipe out the "is interesting" bit. |
| 506 | RawID = RawID >> 1; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 507 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 508 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 509 | if (!IsInteresting) { |
| 510 | // For uninteresting identifiers, just build the IdentifierInfo |
| 511 | // and associate it with the persistent ID. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 512 | IdentifierInfo *II = KnownII; |
| 513 | if (!II) |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 514 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 515 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 516 | II->setIsFromAST(); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 517 | II->setOutOfDate(false); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 518 | return II; |
| 519 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 521 | unsigned Bits = ReadUnalignedLE16(d); |
| 522 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 523 | Bits >>= 1; |
| 524 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 525 | Bits >>= 1; |
| 526 | bool Poisoned = Bits & 0x01; |
| 527 | Bits >>= 1; |
| 528 | bool ExtensionToken = Bits & 0x01; |
| 529 | Bits >>= 1; |
| 530 | bool hasMacroDefinition = Bits & 0x01; |
| 531 | Bits >>= 1; |
| 532 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 533 | Bits >>= 10; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 534 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 535 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 536 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 537 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 538 | // Build the IdentifierInfo itself and link the identifier ID with |
| 539 | // the new IdentifierInfo. |
| 540 | IdentifierInfo *II = KnownII; |
| 541 | if (!II) |
| 542 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 543 | II->setOutOfDate(false); |
| 544 | II->setIsFromAST(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 545 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 546 | // Set or check the various bits in the IdentifierInfo structure. |
| 547 | // Token IDs are read-only. |
| 548 | if (HasRevertedTokenIDToIdentifier) |
| 549 | II->RevertTokenIDToIdentifier(); |
| 550 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 551 | assert(II->isExtensionToken() == ExtensionToken && |
| 552 | "Incorrect extension token flag"); |
| 553 | (void)ExtensionToken; |
| 554 | if (Poisoned) |
| 555 | II->setIsPoisoned(true); |
| 556 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 557 | "Incorrect C++ operator keyword flag"); |
| 558 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 559 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 560 | // If this identifier is a macro, deserialize the macro |
| 561 | // definition. |
| 562 | if (hasMacroDefinition) { |
| 563 | // FIXME: Check for conflicts? |
| 564 | uint32_t Offset = ReadUnalignedLE32(d); |
| 565 | Reader.SetIdentifierIsMacro(II, F, Offset); |
| 566 | DataLen -= 4; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 569 | Reader.SetIdentifierInfo(ID, II); |
| 570 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 571 | // Read all of the declarations visible at global scope with this |
| 572 | // name. |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 573 | if (DataLen > 0) { |
| 574 | SmallVector<uint32_t, 4> DeclIDs; |
| 575 | for (; DataLen > 0; DataLen -= 4) |
| 576 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 577 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 580 | return II; |
| 581 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 582 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 583 | unsigned |
| 584 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 585 | llvm::FoldingSetNodeID ID; |
| 586 | ID.AddInteger(Key.Kind); |
| 587 | |
| 588 | switch (Key.Kind) { |
| 589 | case DeclarationName::Identifier: |
| 590 | case DeclarationName::CXXLiteralOperatorName: |
| 591 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 592 | break; |
| 593 | case DeclarationName::ObjCZeroArgSelector: |
| 594 | case DeclarationName::ObjCOneArgSelector: |
| 595 | case DeclarationName::ObjCMultiArgSelector: |
| 596 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 597 | break; |
| 598 | case DeclarationName::CXXOperatorName: |
| 599 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 600 | break; |
| 601 | case DeclarationName::CXXConstructorName: |
| 602 | case DeclarationName::CXXDestructorName: |
| 603 | case DeclarationName::CXXConversionFunctionName: |
| 604 | case DeclarationName::CXXUsingDirective: |
| 605 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 608 | return ID.ComputeHash(); |
| 609 | } |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 610 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 611 | ASTDeclContextNameLookupTrait::internal_key_type |
| 612 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 613 | const external_key_type& Name) const { |
| 614 | DeclNameKey Key; |
| 615 | Key.Kind = Name.getNameKind(); |
| 616 | switch (Name.getNameKind()) { |
| 617 | case DeclarationName::Identifier: |
| 618 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 619 | break; |
| 620 | case DeclarationName::ObjCZeroArgSelector: |
| 621 | case DeclarationName::ObjCOneArgSelector: |
| 622 | case DeclarationName::ObjCMultiArgSelector: |
| 623 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 624 | break; |
| 625 | case DeclarationName::CXXOperatorName: |
| 626 | Key.Data = Name.getCXXOverloadedOperator(); |
| 627 | break; |
| 628 | case DeclarationName::CXXLiteralOperatorName: |
| 629 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 630 | break; |
| 631 | case DeclarationName::CXXConstructorName: |
| 632 | case DeclarationName::CXXDestructorName: |
| 633 | case DeclarationName::CXXConversionFunctionName: |
| 634 | case DeclarationName::CXXUsingDirective: |
| 635 | Key.Data = 0; |
| 636 | break; |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 639 | return Key; |
| 640 | } |
| 641 | |
| 642 | ASTDeclContextNameLookupTrait::external_key_type |
| 643 | ASTDeclContextNameLookupTrait::GetExternalKey( |
| 644 | const internal_key_type& Key) const { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 645 | ASTContext &Context = Reader.getContext(); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 646 | switch (Key.Kind) { |
| 647 | case DeclarationName::Identifier: |
| 648 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 649 | |
| 650 | case DeclarationName::ObjCZeroArgSelector: |
| 651 | case DeclarationName::ObjCOneArgSelector: |
| 652 | case DeclarationName::ObjCMultiArgSelector: |
| 653 | return DeclarationName(Selector(Key.Data)); |
| 654 | |
| 655 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 656 | return Context.DeclarationNames.getCXXConstructorName( |
| 657 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 658 | |
| 659 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 660 | return Context.DeclarationNames.getCXXDestructorName( |
| 661 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 662 | |
| 663 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 664 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 665 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 666 | |
| 667 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 668 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 669 | (OverloadedOperatorKind)Key.Data); |
| 670 | |
| 671 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 672 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 673 | (IdentifierInfo*)Key.Data); |
| 674 | |
| 675 | case DeclarationName::CXXUsingDirective: |
| 676 | return DeclarationName::getUsingDirectiveName(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 679 | llvm_unreachable("Invalid Name Kind ?"); |
| 680 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 682 | std::pair<unsigned, unsigned> |
| 683 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 684 | using namespace clang::io; |
| 685 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 686 | unsigned DataLen = ReadUnalignedLE16(d); |
| 687 | return std::make_pair(KeyLen, DataLen); |
| 688 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 689 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 690 | ASTDeclContextNameLookupTrait::internal_key_type |
| 691 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 692 | using namespace clang::io; |
| 693 | |
| 694 | DeclNameKey Key; |
| 695 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 696 | switch (Key.Kind) { |
| 697 | case DeclarationName::Identifier: |
| 698 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 699 | break; |
| 700 | case DeclarationName::ObjCZeroArgSelector: |
| 701 | case DeclarationName::ObjCOneArgSelector: |
| 702 | case DeclarationName::ObjCMultiArgSelector: |
| 703 | Key.Data = |
| 704 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 705 | .getAsOpaquePtr(); |
| 706 | break; |
| 707 | case DeclarationName::CXXOperatorName: |
| 708 | Key.Data = *d++; // OverloadedOperatorKind |
| 709 | break; |
| 710 | case DeclarationName::CXXLiteralOperatorName: |
| 711 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 712 | break; |
| 713 | case DeclarationName::CXXConstructorName: |
| 714 | case DeclarationName::CXXDestructorName: |
| 715 | case DeclarationName::CXXConversionFunctionName: |
| 716 | case DeclarationName::CXXUsingDirective: |
| 717 | Key.Data = 0; |
| 718 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 719 | } |
| 720 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 721 | return Key; |
| 722 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 723 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 724 | ASTDeclContextNameLookupTrait::data_type |
| 725 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 726 | const unsigned char* d, |
| 727 | unsigned DataLen) { |
| 728 | using namespace clang::io; |
| 729 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 730 | DeclID *Start = (DeclID *)d; |
| 731 | return std::make_pair(Start, Start + NumDecls); |
| 732 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 733 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 734 | bool ASTReader::ReadDeclContextStorage(Module &M, |
| 735 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 736 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 737 | DeclContextInfo &Info) { |
| 738 | SavedStreamPosition SavedPosition(Cursor); |
| 739 | // First the lexical decls. |
| 740 | if (Offsets.first != 0) { |
| 741 | Cursor.JumpToBit(Offsets.first); |
| 742 | |
| 743 | RecordData Record; |
| 744 | const char *Blob; |
| 745 | unsigned BlobLen; |
| 746 | unsigned Code = Cursor.ReadCode(); |
| 747 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 748 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 749 | Error("Expected lexical block"); |
| 750 | return true; |
| 751 | } |
| 752 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 753 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 754 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | // Now the lookup table. |
| 758 | if (Offsets.second != 0) { |
| 759 | Cursor.JumpToBit(Offsets.second); |
| 760 | |
| 761 | RecordData Record; |
| 762 | const char *Blob; |
| 763 | unsigned BlobLen; |
| 764 | unsigned Code = Cursor.ReadCode(); |
| 765 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 766 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 767 | Error("Expected visible lookup table block"); |
| 768 | return true; |
| 769 | } |
| 770 | Info.NameLookupTableData |
| 771 | = ASTDeclContextNameLookupTable::Create( |
| 772 | (const unsigned char *)Blob + Record[0], |
| 773 | (const unsigned char *)Blob, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 774 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | return false; |
| 778 | } |
| 779 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 780 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 781 | Error(diag::err_fe_pch_malformed, Msg); |
| 782 | } |
| 783 | |
| 784 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 785 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 786 | if (Diags.isDiagnosticInFlight()) |
| 787 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 788 | else |
| 789 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 792 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 793 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 794 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 795 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 796 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 797 | SuggestedPredefines, |
| 798 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 799 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 802 | //===----------------------------------------------------------------------===// |
| 803 | // Source Manager Deserialization |
| 804 | //===----------------------------------------------------------------------===// |
| 805 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 806 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 807 | /// \returns true if there was an error. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 808 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 809 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 810 | unsigned Idx = 0; |
| 811 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 812 | |
| 813 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 814 | std::map<int, int> FileIDs; |
| 815 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 816 | // Extract the file name |
| 817 | unsigned FilenameLen = Record[Idx++]; |
| 818 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 819 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 820 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 821 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | // Parse the line entries |
| 825 | std::vector<LineEntry> Entries; |
| 826 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 827 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 828 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 829 | // Remap FileID from 1-based old view. |
| 830 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 831 | |
| 832 | // Extract the line entries |
| 833 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 834 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 835 | Entries.clear(); |
| 836 | Entries.reserve(NumEntries); |
| 837 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 838 | unsigned FileOffset = Record[Idx++]; |
| 839 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 840 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 841 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 842 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 843 | unsigned IncludeOffset = Record[Idx++]; |
| 844 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 845 | FileKind, IncludeOffset)); |
| 846 | } |
| 847 | LineTable.AddEntry(FID, Entries); |
| 848 | } |
| 849 | |
| 850 | return false; |
| 851 | } |
| 852 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 853 | namespace { |
| 854 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 855 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 856 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 857 | const ino_t ino; |
| 858 | const dev_t dev; |
| 859 | const mode_t mode; |
| 860 | const time_t mtime; |
| 861 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 863 | 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] | 864 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 865 | }; |
| 866 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 867 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 868 | public: |
| 869 | typedef const char *external_key_type; |
| 870 | typedef const char *internal_key_type; |
| 871 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 872 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 873 | |
| 874 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 875 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 879 | |
| 880 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 881 | return strcmp(a, b) == 0; |
| 882 | } |
| 883 | |
| 884 | static std::pair<unsigned, unsigned> |
| 885 | ReadKeyDataLength(const unsigned char*& d) { |
| 886 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 887 | unsigned DataLen = (unsigned) *d++; |
| 888 | return std::make_pair(KeyLen + 1, DataLen); |
| 889 | } |
| 890 | |
| 891 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 892 | return (const char *)d; |
| 893 | } |
| 894 | |
| 895 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 896 | unsigned /*DataLen*/) { |
| 897 | using namespace clang::io; |
| 898 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 899 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 900 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 901 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 903 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 904 | return data_type(ino, dev, mode, mtime, size); |
| 905 | } |
| 906 | }; |
| 907 | |
| 908 | /// \brief stat() cache for precompiled headers. |
| 909 | /// |
| 910 | /// This cache is very similar to the stat cache used by pretokenized |
| 911 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 912 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 913 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 914 | CacheTy *Cache; |
| 915 | |
| 916 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 918 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 919 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 920 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 921 | Cache = CacheTy::Create(Buckets, Base); |
| 922 | } |
| 923 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 924 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 926 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 927 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 928 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 929 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 930 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 931 | // 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] | 932 | if (I == Cache->end()) { |
| 933 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 934 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 935 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 937 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 938 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 939 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 940 | StatBuf.st_ino = Data.ino; |
| 941 | StatBuf.st_dev = Data.dev; |
| 942 | StatBuf.st_mtime = Data.mtime; |
| 943 | StatBuf.st_mode = Data.mode; |
| 944 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 945 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 946 | } |
| 947 | }; |
| 948 | } // end anonymous namespace |
| 949 | |
| 950 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 951 | /// \brief Read a source manager block |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 952 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 953 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 954 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 955 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 956 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 957 | // Set the source-location entry cursor to the current position in |
| 958 | // the stream. This cursor will be used to read the contents of the |
| 959 | // source manager block initially, and then lazily read |
| 960 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 961 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 962 | |
| 963 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 964 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 965 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 966 | return Failure; |
| 967 | } |
| 968 | |
| 969 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 970 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 971 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 972 | return Failure; |
| 973 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 974 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 975 | RecordData Record; |
| 976 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 977 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 978 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 979 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 980 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 981 | return Failure; |
| 982 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 983 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 984 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 985 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 986 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 987 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 988 | SLocEntryCursor.ReadSubBlockID(); |
| 989 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 990 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 991 | return Failure; |
| 992 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 993 | continue; |
| 994 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 995 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 996 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 997 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 998 | continue; |
| 999 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1001 | // Read a record. |
| 1002 | const char *BlobStart; |
| 1003 | unsigned BlobLen; |
| 1004 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1005 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1006 | default: // Default behavior: ignore. |
| 1007 | break; |
| 1008 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1009 | case SM_SLOC_FILE_ENTRY: |
| 1010 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1011 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1012 | // Once we hit one of the source location entries, we're done. |
| 1013 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | } |
| 1017 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1018 | /// \brief If a header file is not found at the path that we expect it to be |
| 1019 | /// and the PCH file was moved from its original location, try to resolve the |
| 1020 | /// file by assuming that header+PCH were moved together and the header is in |
| 1021 | /// the same place relative to the PCH. |
| 1022 | static std::string |
| 1023 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1024 | const std::string &OriginalDir, |
| 1025 | const std::string &CurrDir) { |
| 1026 | assert(OriginalDir != CurrDir && |
| 1027 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1028 | using namespace llvm::sys; |
| 1029 | llvm::SmallString<128> filePath(Filename); |
| 1030 | fs::make_absolute(filePath); |
| 1031 | assert(path::is_absolute(OriginalDir)); |
| 1032 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1033 | |
| 1034 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1035 | fileDirE = path::end(path::parent_path(filePath)); |
| 1036 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1037 | origDirE = path::end(OriginalDir); |
| 1038 | // Skip the common path components from filePath and OriginalDir. |
| 1039 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1040 | *fileDirI == *origDirI) { |
| 1041 | ++fileDirI; |
| 1042 | ++origDirI; |
| 1043 | } |
| 1044 | for (; origDirI != origDirE; ++origDirI) |
| 1045 | path::append(currPCHPath, ".."); |
| 1046 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1047 | path::append(currPCHPath, path::filename(Filename)); |
| 1048 | return currPCHPath.str(); |
| 1049 | } |
| 1050 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1051 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1052 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1053 | if (ID == 0) |
| 1054 | return Success; |
| 1055 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1056 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1057 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1058 | return Failure; |
| 1059 | } |
| 1060 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1061 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1062 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1063 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1064 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1065 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1066 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1067 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1068 | if (Code == llvm::bitc::END_BLOCK || |
| 1069 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1070 | Code == llvm::bitc::DEFINE_ABBREV) { |
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 | } |
| 1074 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1075 | RecordData Record; |
| 1076 | const char *BlobStart; |
| 1077 | unsigned BlobLen; |
| 1078 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1079 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1080 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1081 | return Failure; |
| 1082 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1083 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1084 | if (Record.size() < 7) { |
| 1085 | Error("source location entry is incorrect"); |
| 1086 | return Failure; |
| 1087 | } |
| 1088 | |
| 1089 | bool OverriddenBuffer = Record[6]; |
| 1090 | |
| 1091 | std::string OrigFilename(BlobStart, BlobStart + BlobLen); |
| 1092 | std::string Filename = OrigFilename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1093 | MaybeAddSystemRootToFilename(Filename); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1094 | const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false, |
| 1095 | /*CacheFailure=*/!OverriddenBuffer); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1096 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1097 | OriginalDir != CurrentDir) { |
| 1098 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1099 | OriginalDir, |
| 1100 | CurrentDir); |
| 1101 | if (!resolved.empty()) |
| 1102 | File = FileMgr.getFile(resolved); |
| 1103 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1104 | if (File == 0) |
| 1105 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1106 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1107 | if (File == 0) { |
| 1108 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1109 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1110 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1111 | Error(ErrorStr.c_str()); |
| 1112 | return Failure; |
| 1113 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1115 | if (!DisableValidation && |
| 1116 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1117 | #if !defined(LLVM_ON_WIN32) |
| 1118 | // In our regression testing, the Windows file system seems to |
| 1119 | // have inconsistent modification times that sometimes |
| 1120 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1121 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1122 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1123 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1124 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1125 | return Failure; |
| 1126 | } |
| 1127 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1128 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1129 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1130 | // This is the module's main file. |
| 1131 | IncludeLoc = getImportLocation(F); |
| 1132 | } |
| 1133 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1134 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1135 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1136 | SrcMgr::FileInfo &FileInfo = |
| 1137 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1138 | FileInfo.NumCreatedFIDs = Record[7]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1140 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1141 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1142 | const DeclID *FirstDecl = F->FileSortedDecls + Record[8]; |
| 1143 | unsigned NumFileDecls = Record[9]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1144 | if (NumFileDecls) { |
| 1145 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 1146 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1147 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1148 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1149 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame^] | 1150 | const SrcMgr::ContentCache *ContentCache |
| 1151 | = SourceMgr.getOrCreateContentCache(File); |
| 1152 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1153 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1154 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1155 | Record.clear(); |
| 1156 | unsigned RecCode |
| 1157 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1158 | |
| 1159 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1160 | Error("AST record has invalid code"); |
| 1161 | return Failure; |
| 1162 | } |
| 1163 | |
| 1164 | llvm::MemoryBuffer *Buffer |
| 1165 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1166 | Filename); |
| 1167 | SourceMgr.overrideFileContents(File, Buffer); |
| 1168 | } |
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 | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1191 | if (strcmp(Name, "<built-in>") == 0) { |
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 | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1218 | SourceLocation ASTReader::getImportLocation(Module *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 | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1259 | void ASTReader::ReadMacroRecord(Module &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 | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1343 | PP.setMacroInfo(II, MI); |
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 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1379 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1380 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1381 | |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1382 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1385 | PreprocessedEntityID |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1386 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) const { |
| 1387 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1388 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1389 | assert(I != M.PreprocessedEntityRemap.end() |
| 1390 | && "Invalid index into preprocessed entity index remap"); |
| 1391 | |
| 1392 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1395 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1396 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1397 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1398 | |
| 1399 | HeaderFileInfoTrait::internal_key_type |
| 1400 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1401 | |
| 1402 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1403 | if (strcmp(a, b) == 0) |
| 1404 | return true; |
| 1405 | |
| 1406 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1407 | return false; |
| 1408 | |
| 1409 | // The file names match, but the path names don't. stat() the files to |
| 1410 | // see if they are the same. |
| 1411 | struct stat StatBufA, StatBufB; |
| 1412 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1413 | return false; |
| 1414 | |
| 1415 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1416 | } |
| 1417 | |
| 1418 | std::pair<unsigned, unsigned> |
| 1419 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1420 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1421 | unsigned DataLen = (unsigned) *d++; |
| 1422 | return std::make_pair(KeyLen + 1, DataLen); |
| 1423 | } |
| 1424 | |
| 1425 | HeaderFileInfoTrait::data_type |
| 1426 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1427 | unsigned DataLen) { |
| 1428 | const unsigned char *End = d + DataLen; |
| 1429 | using namespace clang::io; |
| 1430 | HeaderFileInfo HFI; |
| 1431 | unsigned Flags = *d++; |
| 1432 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1433 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1434 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1435 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1436 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1437 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1438 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1439 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1440 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1441 | // The framework offset is 1 greater than the actual offset, |
| 1442 | // since 0 is used as an indicator for "no framework name". |
| 1443 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1444 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1445 | } |
| 1446 | |
| 1447 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1448 | (void)End; |
| 1449 | |
| 1450 | // This HeaderFileInfo was externally loaded. |
| 1451 | HFI.External = true; |
| 1452 | return HFI; |
| 1453 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1454 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1455 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1456 | uint64_t LocalOffset) { |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1457 | // Note that this identifier has a macro definition. |
| 1458 | II->setHasMacroDefinition(true); |
| 1459 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1460 | // Adjust the offset to a global offset. |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1461 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1464 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1465 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1466 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1467 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1468 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1469 | // If there was no preprocessor block, skip this file. |
| 1470 | if (!MacroCursor.getBitStreamReader()) |
| 1471 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1472 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1473 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1474 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1475 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1476 | RecordData Record; |
| 1477 | while (true) { |
| 1478 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1479 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1480 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1481 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1482 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1483 | // No known subblocks, always skip them. |
| 1484 | Cursor.ReadSubBlockID(); |
| 1485 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1486 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1487 | return; |
| 1488 | } |
| 1489 | continue; |
| 1490 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1491 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1492 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1493 | Cursor.ReadAbbrevRecord(); |
| 1494 | continue; |
| 1495 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1496 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1497 | // Read a record. |
| 1498 | const char *BlobStart; |
| 1499 | unsigned BlobLen; |
| 1500 | Record.clear(); |
| 1501 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1502 | default: // Default behavior: ignore. |
| 1503 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1504 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1505 | case PP_MACRO_OBJECT_LIKE: |
| 1506 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1507 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1508 | break; |
| 1509 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1510 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1511 | // Ignore tokens. |
| 1512 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1513 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1514 | } |
| 1515 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1516 | |
| 1517 | // Drain the unread macro-record offsets map. |
| 1518 | while (!UnreadMacroRecordOffsets.empty()) |
| 1519 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1520 | } |
| 1521 | |
| 1522 | void ASTReader::LoadMacroDefinition( |
| 1523 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1524 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1525 | uint64_t Offset = Pos->second; |
| 1526 | UnreadMacroRecordOffsets.erase(Pos); |
| 1527 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1528 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1529 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1533 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1534 | = UnreadMacroRecordOffsets.find(II); |
| 1535 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1538 | namespace { |
| 1539 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1540 | class IdentifierLookupVisitor { |
| 1541 | StringRef Name; |
| 1542 | IdentifierInfo *Found; |
| 1543 | public: |
| 1544 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
| 1545 | |
| 1546 | static bool visit(Module &M, void *UserData) { |
| 1547 | IdentifierLookupVisitor *This |
| 1548 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1549 | |
| 1550 | ASTIdentifierLookupTable *IdTable |
| 1551 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1552 | if (!IdTable) |
| 1553 | return false; |
| 1554 | |
| 1555 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1556 | This->Name.size()); |
| 1557 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 1558 | if (Pos == IdTable->end()) |
| 1559 | return false; |
| 1560 | |
| 1561 | // Dereferencing the iterator has the effect of building the |
| 1562 | // IdentifierInfo node and populating it with the various |
| 1563 | // declarations it needs. |
| 1564 | This->Found = *Pos; |
| 1565 | return true; |
| 1566 | } |
| 1567 | |
| 1568 | // \brief Retrieve the identifier info found within the module |
| 1569 | // files. |
| 1570 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1571 | }; |
| 1572 | } |
| 1573 | |
| 1574 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1575 | get(II.getName()); |
| 1576 | } |
| 1577 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1578 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1579 | std::string Filename = filenameStrRef; |
| 1580 | MaybeAddSystemRootToFilename(Filename); |
| 1581 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1582 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1583 | OriginalDir != CurrentDir) { |
| 1584 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1585 | OriginalDir, |
| 1586 | CurrentDir); |
| 1587 | if (!resolved.empty()) |
| 1588 | File = FileMgr.getFile(resolved); |
| 1589 | } |
| 1590 | |
| 1591 | return File; |
| 1592 | } |
| 1593 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1594 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1595 | /// not an absolute path, add the system root to the beginning of the file |
| 1596 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1597 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1598 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1599 | if (!RelocatablePCH) |
| 1600 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1602 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1603 | return; |
| 1604 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1605 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1606 | // If no system root was given, default to '/' |
| 1607 | Filename.insert(Filename.begin(), '/'); |
| 1608 | return; |
| 1609 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1610 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1611 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1612 | if (isysroot[Length - 1] != '/') |
| 1613 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1614 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1615 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1618 | ASTReader::ASTReadResult |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1619 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1620 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1621 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1622 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1623 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1624 | return Failure; |
| 1625 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1626 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1627 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1628 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1629 | while (!Stream.AtEndOfStream()) { |
| 1630 | unsigned Code = Stream.ReadCode(); |
| 1631 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1632 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1633 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1634 | return Failure; |
| 1635 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1636 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1637 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1641 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1642 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1643 | // We lazily load the decls block, but we want to set up the |
| 1644 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1645 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1646 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1647 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1648 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1649 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1650 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1651 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1652 | return Failure; |
| 1653 | } |
| 1654 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1655 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1656 | case DECL_UPDATES_BLOCK_ID: |
| 1657 | if (Stream.SkipBlock()) { |
| 1658 | Error("malformed block record in AST file"); |
| 1659 | return Failure; |
| 1660 | } |
| 1661 | break; |
| 1662 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1663 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1664 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1665 | if (!PP.getExternalSource()) |
| 1666 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1667 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1668 | if (Stream.SkipBlock() || |
| 1669 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1670 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1671 | return Failure; |
| 1672 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1673 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1674 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1676 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1677 | F.PreprocessorDetailCursor = Stream; |
| 1678 | if (Stream.SkipBlock() || |
| 1679 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1680 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1681 | Error("malformed preprocessor detail record in AST file"); |
| 1682 | return Failure; |
| 1683 | } |
| 1684 | F.PreprocessorDetailStartOffset |
| 1685 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1686 | |
| 1687 | if (!PP.getPreprocessingRecord()) |
| 1688 | PP.createPreprocessingRecord(true); |
| 1689 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1690 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1691 | break; |
| 1692 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1693 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1694 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1695 | case Success: |
| 1696 | break; |
| 1697 | |
| 1698 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1699 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1700 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1701 | |
| 1702 | case IgnorePCH: |
| 1703 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1704 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1705 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1706 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1707 | continue; |
| 1708 | } |
| 1709 | |
| 1710 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1711 | Stream.ReadAbbrevRecord(); |
| 1712 | continue; |
| 1713 | } |
| 1714 | |
| 1715 | // Read and process a record. |
| 1716 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1717 | const char *BlobStart = 0; |
| 1718 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1719 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1720 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1721 | default: // Default behavior: ignore. |
| 1722 | break; |
| 1723 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1724 | case METADATA: { |
| 1725 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1726 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1727 | : diag::warn_pch_version_too_new); |
| 1728 | return IgnorePCH; |
| 1729 | } |
| 1730 | |
| 1731 | RelocatablePCH = Record[4]; |
| 1732 | if (Listener) { |
| 1733 | std::string TargetTriple(BlobStart, BlobLen); |
| 1734 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1735 | return IgnorePCH; |
| 1736 | } |
| 1737 | break; |
| 1738 | } |
| 1739 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1740 | case IMPORTS: { |
| 1741 | // Load each of the imported PCH files. |
| 1742 | unsigned Idx = 0, N = Record.size(); |
| 1743 | while (Idx < N) { |
| 1744 | // Read information about the AST file. |
| 1745 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1746 | unsigned Length = Record[Idx++]; |
| 1747 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1748 | Record.begin() + Idx + Length); |
| 1749 | Idx += Length; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1750 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1751 | // Load the AST file. |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1752 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1753 | case Failure: return Failure; |
| 1754 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1755 | case IgnorePCH: return IgnorePCH; |
| 1756 | case Success: break; |
| 1757 | } |
| 1758 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1759 | break; |
| 1760 | } |
| 1761 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1762 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1763 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1764 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1765 | return Failure; |
| 1766 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1767 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1768 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1769 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1770 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1771 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1772 | if (F.LocalNumTypes > 0) { |
| 1773 | // Introduce the global -> local mapping for types within this module. |
| 1774 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1775 | |
| 1776 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1777 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 1778 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1779 | |
| 1780 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1781 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1782 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1785 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1786 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1787 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1788 | return Failure; |
| 1789 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 1790 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1791 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1792 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1793 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1795 | if (F.LocalNumDecls > 0) { |
| 1796 | // Introduce the global -> local mapping for declarations within this |
| 1797 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1798 | GlobalDeclMap.insert( |
| 1799 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1800 | |
| 1801 | // Introduce the local -> global mapping for declarations within this |
| 1802 | // module. |
| 1803 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 1804 | F.BaseDeclID - LocalBaseDeclID)); |
| 1805 | |
| 1806 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1807 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1808 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1811 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1812 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1813 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1814 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1815 | Info.NumLexicalDecls |
| 1816 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1817 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1818 | break; |
| 1819 | } |
| 1820 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1821 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1822 | unsigned Idx = 0; |
| 1823 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1824 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1825 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1826 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1827 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1828 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1829 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1830 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1831 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1832 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1833 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1834 | break; |
| 1835 | } |
| 1836 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1837 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1838 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1839 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 1840 | DeclID First = ReadDeclID(F, Record, i); |
| 1841 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1842 | FirstLatestDeclIDs[First] = Latest; |
| 1843 | } |
| 1844 | break; |
| 1845 | } |
| 1846 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1847 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1848 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1849 | return IgnorePCH; |
| 1850 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1851 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1852 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1853 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1854 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1855 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1856 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1857 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1858 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1859 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1860 | |
| 1861 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1862 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1863 | break; |
| 1864 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1865 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1866 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1867 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1868 | return Failure; |
| 1869 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1870 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1871 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1872 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1873 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 1874 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1875 | if (F.LocalNumIdentifiers > 0) { |
| 1876 | // Introduce the global -> local mapping for identifiers within this |
| 1877 | // module. |
| 1878 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 1879 | &F)); |
| 1880 | |
| 1881 | // Introduce the local -> global mapping for identifiers within this |
| 1882 | // module. |
| 1883 | F.IdentifierRemap.insert( |
| 1884 | std::make_pair(LocalBaseIdentifierID, |
| 1885 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 1886 | |
| 1887 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 1888 | + F.LocalNumIdentifiers); |
| 1889 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1890 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1893 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1894 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1895 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1896 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1897 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1898 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1899 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1900 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1901 | break; |
| 1902 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1903 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1904 | TotalNumStatements += Record[0]; |
| 1905 | TotalNumMacros += Record[1]; |
| 1906 | TotalLexicalDeclContexts += Record[2]; |
| 1907 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1908 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1909 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1910 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1911 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1912 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1913 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1914 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1915 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1916 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1917 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1918 | break; |
| 1919 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1920 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 1921 | if (Record.size() % 4 != 0) { |
| 1922 | Error("invalid weak identifiers record"); |
| 1923 | return Failure; |
| 1924 | } |
| 1925 | |
| 1926 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 1927 | // files. This isn't the way to do it :) |
| 1928 | WeakUndeclaredIdentifiers.clear(); |
| 1929 | |
| 1930 | // Translate the weak, undeclared identifiers into global IDs. |
| 1931 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 1932 | WeakUndeclaredIdentifiers.push_back( |
| 1933 | getGlobalIdentifierID(F, Record[I++])); |
| 1934 | WeakUndeclaredIdentifiers.push_back( |
| 1935 | getGlobalIdentifierID(F, Record[I++])); |
| 1936 | WeakUndeclaredIdentifiers.push_back( |
| 1937 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 1938 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 1939 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1940 | break; |
| 1941 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1942 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1943 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1944 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1945 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1946 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1947 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1948 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1949 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1950 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1951 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 1952 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1953 | if (F.LocalNumSelectors > 0) { |
| 1954 | // Introduce the global -> local mapping for selectors within this |
| 1955 | // module. |
| 1956 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 1957 | |
| 1958 | // Introduce the local -> global mapping for selectors within this |
| 1959 | // module. |
| 1960 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 1961 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1962 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1963 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 1964 | } |
| 1965 | break; |
| 1966 | } |
| 1967 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1968 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1969 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1970 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1971 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1972 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1973 | F.SelectorLookupTableData + Record[0], |
| 1974 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1975 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 1976 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1977 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1978 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 1979 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 1980 | if (!Record.empty()) { |
| 1981 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 1982 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 1983 | Record[Idx++])); |
| 1984 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 1985 | getRawEncoding()); |
| 1986 | } |
| 1987 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1988 | break; |
| 1989 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1990 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1991 | if (!Record.empty() && Listener) |
| 1992 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1993 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1994 | |
| 1995 | case FILE_SORTED_DECLS: |
| 1996 | F.FileSortedDecls = (const DeclID *)BlobStart; |
| 1997 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1998 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1999 | case SOURCE_LOCATION_OFFSETS: { |
| 2000 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2001 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2002 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2003 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2004 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2005 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2006 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2007 | // we invert it. Because we invert it, though, we need the other end of |
| 2008 | // the range. |
| 2009 | unsigned RangeStart = |
| 2010 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2011 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2012 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2013 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2014 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2015 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2016 | GlobalSLocOffsetMap.insert( |
| 2017 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2018 | - SLocSpaceSize,&F)); |
| 2019 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2020 | // Initialize the remapping table. |
| 2021 | // Invalid stays invalid. |
| 2022 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2023 | // This module. Base was 2 when being compiled. |
| 2024 | F.SLocRemap.insert(std::make_pair(2U, |
| 2025 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2026 | |
| 2027 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2028 | break; |
| 2029 | } |
| 2030 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2031 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2032 | // Additional remapping information. |
| 2033 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2034 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2035 | |
| 2036 | // Continuous range maps we may be updating in our module. |
| 2037 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2038 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2039 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2040 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2041 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2042 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2043 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2044 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2045 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2046 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2047 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2048 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2049 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2050 | Data += Len; |
Jonathan D. Turner | 48d2c3f | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2051 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2052 | if (!OM) { |
| 2053 | Error("SourceLocation remap refers to unknown module"); |
| 2054 | return Failure; |
| 2055 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2056 | |
| 2057 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2058 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2059 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2060 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2061 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2062 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2063 | |
| 2064 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2065 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2066 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2067 | IdentifierRemap.insert( |
| 2068 | std::make_pair(IdentifierIDOffset, |
| 2069 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2070 | PreprocessedEntityRemap.insert( |
| 2071 | std::make_pair(PreprocessedEntityIDOffset, |
| 2072 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2073 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2074 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2075 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2076 | OM->BaseDeclID - DeclIDOffset)); |
| 2077 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2078 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2079 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2080 | } |
| 2081 | break; |
| 2082 | } |
| 2083 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2084 | case SOURCE_MANAGER_LINE_TABLE: |
| 2085 | if (ParseLineTable(F, Record)) |
| 2086 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2087 | break; |
| 2088 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2089 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2090 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2091 | F.LocalNumSLocFileEntries = Record[0]; |
| 2092 | break; |
| 2093 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2094 | case SOURCE_LOCATION_PRELOADS: { |
| 2095 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2096 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2097 | if (!F.PreloadSLocEntries.empty()) { |
| 2098 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2099 | return Failure; |
| 2100 | } |
| 2101 | |
| 2102 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2103 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2104 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2105 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2106 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2107 | if (!DisableStatCache) { |
| 2108 | ASTStatCache *MyStatCache = |
| 2109 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2110 | (const unsigned char *)BlobStart, |
| 2111 | NumStatHits, NumStatMisses); |
| 2112 | FileMgr.addStatCache(MyStatCache); |
| 2113 | F.StatCache = MyStatCache; |
| 2114 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2115 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2116 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2117 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2118 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2119 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2120 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2121 | break; |
| 2122 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2123 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2124 | if (Record.size() % 3 != 0) { |
| 2125 | Error("Invalid VTABLE_USES record"); |
| 2126 | return Failure; |
| 2127 | } |
| 2128 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2129 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2130 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2131 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2132 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2133 | |
| 2134 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2135 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2136 | VTableUses.push_back( |
| 2137 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2138 | VTableUses.push_back(Record[Idx++]); |
| 2139 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2140 | break; |
| 2141 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2142 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2143 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2144 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2145 | break; |
| 2146 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2147 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2148 | if (PendingInstantiations.size() % 2 != 0) { |
| 2149 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2150 | return Failure; |
| 2151 | } |
| 2152 | |
| 2153 | // Later lists of pending instantiations overwrite earlier ones. |
| 2154 | // FIXME: This is most certainly wrong for modules. |
| 2155 | PendingInstantiations.clear(); |
| 2156 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2157 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2158 | PendingInstantiations.push_back( |
| 2159 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2160 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2161 | break; |
| 2162 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2163 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2164 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2165 | // FIXME: Modules will have some trouble with this. |
| 2166 | SemaDeclRefs.clear(); |
| 2167 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2168 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2169 | break; |
| 2170 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2171 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2172 | // 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] | 2173 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2174 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2175 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2176 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2177 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2178 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2179 | case ORIGINAL_FILE_ID: |
| 2180 | OriginalFileID = FileID::get(Record[0]); |
| 2181 | break; |
| 2182 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2183 | case ORIGINAL_PCH_DIR: |
| 2184 | // The primary AST will be the last to get here, so it will be the one |
| 2185 | // that's used. |
| 2186 | OriginalDir.assign(BlobStart, BlobLen); |
| 2187 | break; |
| 2188 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2189 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2190 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2191 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2192 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2193 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2194 | return IgnorePCH; |
| 2195 | } |
| 2196 | break; |
| 2197 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2198 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2199 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2200 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2201 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2202 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2203 | |
| 2204 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2205 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2206 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2207 | if (!PP.getPreprocessingRecord()) |
| 2208 | PP.createPreprocessingRecord(true); |
| 2209 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2210 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2211 | StartingID |
| 2212 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2213 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2214 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2215 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2216 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2217 | // Introduce the global -> local mapping for preprocessed entities in |
| 2218 | // this module. |
| 2219 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2220 | |
| 2221 | // Introduce the local -> global mapping for preprocessed entities in |
| 2222 | // this module. |
| 2223 | F.PreprocessedEntityRemap.insert( |
| 2224 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2225 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2226 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2227 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2228 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2231 | case DECL_UPDATE_OFFSETS: { |
| 2232 | if (Record.size() % 2 != 0) { |
| 2233 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2234 | return Failure; |
| 2235 | } |
| 2236 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2237 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2238 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2239 | break; |
| 2240 | } |
| 2241 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2242 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2243 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2244 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2245 | return Failure; |
| 2246 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2247 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2248 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2249 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2250 | break; |
| 2251 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2252 | |
| 2253 | case OBJC_CHAINED_CATEGORIES: { |
| 2254 | if (Record.size() % 3 != 0) { |
| 2255 | Error("invalid OBJC_CHAINED_CATEGORIES block in AST file"); |
| 2256 | return Failure; |
| 2257 | } |
| 2258 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) { |
| 2259 | serialization::GlobalDeclID GlobID = getGlobalDeclID(F, Record[I]); |
| 2260 | F.ChainedObjCCategories[GlobID] = std::make_pair(Record[I+1], |
| 2261 | Record[I+2]); |
| 2262 | ObjCChainedCategoriesInterfaces.insert(GlobID); |
| 2263 | } |
| 2264 | break; |
| 2265 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2266 | |
| 2267 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2268 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2269 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2270 | return Failure; |
| 2271 | } |
| 2272 | |
| 2273 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2274 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2275 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2276 | break; |
| 2277 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2278 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2279 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2280 | if (Record.size() % 2 != 0) { |
| 2281 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2282 | return Failure; |
| 2283 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2284 | |
| 2285 | if (F.PragmaDiagMappings.empty()) |
| 2286 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2287 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2288 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2289 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2290 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2291 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2292 | case CUDA_SPECIAL_DECL_REFS: |
| 2293 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2294 | // FIXME: Modules will have trouble with this. |
| 2295 | CUDASpecialDeclRefs.clear(); |
| 2296 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2297 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2298 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2299 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2300 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2301 | F.HeaderFileInfoTableData = BlobStart; |
| 2302 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2303 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2304 | if (Record[0]) { |
| 2305 | F.HeaderFileInfoTable |
| 2306 | = HeaderFileInfoLookupTable::Create( |
| 2307 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2308 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2309 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2310 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2311 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2312 | |
| 2313 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2314 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2315 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2316 | } |
| 2317 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2318 | } |
| 2319 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2320 | case FP_PRAGMA_OPTIONS: |
| 2321 | // Later tables overwrite earlier ones. |
| 2322 | FPPragmaOptions.swap(Record); |
| 2323 | break; |
| 2324 | |
| 2325 | case OPENCL_EXTENSIONS: |
| 2326 | // Later tables overwrite earlier ones. |
| 2327 | OpenCLExtensions.swap(Record); |
| 2328 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2329 | |
| 2330 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2331 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2332 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2333 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2334 | |
| 2335 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2336 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2337 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2338 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2339 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2340 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2341 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2342 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2345 | ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) { |
| 2346 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2347 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2348 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2349 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2350 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2351 | if (Code == llvm::bitc::END_BLOCK || |
| 2352 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2353 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2354 | Error("incorrectly-formatted source location entry in AST file"); |
| 2355 | return Failure; |
| 2356 | } |
| 2357 | |
| 2358 | RecordData Record; |
| 2359 | const char *BlobStart; |
| 2360 | unsigned BlobLen; |
| 2361 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2362 | default: |
| 2363 | Error("incorrectly-formatted source location entry in AST file"); |
| 2364 | return Failure; |
| 2365 | |
| 2366 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2367 | // If the buffer was overridden, the file need not exist. |
| 2368 | if (Record[6]) |
| 2369 | break; |
| 2370 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2371 | StringRef Filename(BlobStart, BlobLen); |
| 2372 | const FileEntry *File = getFileEntry(Filename); |
| 2373 | |
| 2374 | if (File == 0) { |
| 2375 | std::string ErrorStr = "could not find file '"; |
| 2376 | ErrorStr += Filename; |
| 2377 | ErrorStr += "' referenced by AST file"; |
| 2378 | Error(ErrorStr.c_str()); |
| 2379 | return IgnorePCH; |
| 2380 | } |
| 2381 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2382 | if (Record.size() < 7) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2383 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2384 | return Failure; |
| 2385 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2386 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2387 | // The stat info from the FileEntry came from the cached stat |
| 2388 | // info of the PCH, so we cannot trust it. |
| 2389 | struct stat StatBuf; |
| 2390 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2391 | StatBuf.st_size = File->getSize(); |
| 2392 | StatBuf.st_mtime = File->getModificationTime(); |
| 2393 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2394 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2395 | if (((off_t)Record[4] != StatBuf.st_size |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2396 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2397 | // In our regression testing, the Windows file system seems to |
| 2398 | // have inconsistent modification times that sometimes |
| 2399 | // erroneously trigger this error-handling path. |
| 2400 | || (time_t)Record[5] != StatBuf.st_mtime |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2401 | #endif |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2402 | )) { |
| 2403 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2404 | return IgnorePCH; |
| 2405 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2406 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2407 | break; |
| 2408 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | return Success; |
| 2413 | } |
| 2414 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2415 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2416 | ModuleKind Type) { |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2417 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2418 | case Failure: return Failure; |
| 2419 | case IgnorePCH: return IgnorePCH; |
| 2420 | case Success: break; |
| 2421 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2422 | |
| 2423 | // Here comes stuff that we only do once the entire chain is loaded. |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2424 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2425 | // Check the predefines buffers. |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 2426 | if (!DisableValidation && Type != MK_Module && Type != MK_Preamble && |
| 2427 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2428 | // if DisableValidation is true, defines that were set on command-line |
| 2429 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2430 | CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2431 | return IgnorePCH; |
| 2432 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2433 | // Mark all of the identifiers in the identifier table as being out of date, |
| 2434 | // so that various accessors know to check the loaded modules when the |
| 2435 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2436 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2437 | IdEnd = PP.getIdentifierTable().end(); |
| 2438 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2439 | Id->second->setOutOfDate(true); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2440 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2441 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2442 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2443 | if (DeserializationListener) |
| 2444 | DeserializationListener->ReaderInitialized(this); |
| 2445 | |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2446 | // If this AST file is a precompiled preamble, then set the preamble file ID |
| 2447 | // of the source manager to the file source file from which the preamble was |
| 2448 | // built. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2449 | if (Type == MK_Preamble) { |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2450 | if (!OriginalFileID.isInvalid()) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2451 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2452 | + OriginalFileID.getOpaqueValue() - 1); |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2453 | SourceMgr.setPreambleFileID(OriginalFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2454 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2457 | return Success; |
| 2458 | } |
| 2459 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2460 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2461 | ModuleKind Type, |
| 2462 | Module *ImportedBy) { |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2463 | Module *M; |
| 2464 | bool NewModule; |
| 2465 | std::string ErrorStr; |
| 2466 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2467 | ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2468 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2469 | if (!M) { |
| 2470 | // We couldn't load the module. |
| 2471 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2472 | + ErrorStr; |
| 2473 | Error(Msg); |
| 2474 | return Failure; |
| 2475 | } |
| 2476 | |
| 2477 | if (!NewModule) { |
| 2478 | // We've already loaded this module. |
| 2479 | return Success; |
| 2480 | } |
| 2481 | |
| 2482 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2483 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2484 | if (FileName != "-") { |
| 2485 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2486 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2487 | } |
| 2488 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2489 | Module &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2490 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2491 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2492 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2493 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2494 | // Sniff for the signature. |
| 2495 | if (Stream.Read(8) != 'C' || |
| 2496 | Stream.Read(8) != 'P' || |
| 2497 | Stream.Read(8) != 'C' || |
| 2498 | Stream.Read(8) != 'H') { |
| 2499 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2500 | return Failure; |
| 2501 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2502 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2503 | while (!Stream.AtEndOfStream()) { |
| 2504 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2505 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2506 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2507 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2508 | return Failure; |
| 2509 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2510 | |
| 2511 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2512 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2513 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2514 | switch (BlockID) { |
| 2515 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2516 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2517 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2518 | return Failure; |
| 2519 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2520 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2521 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2522 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2523 | case Success: |
| 2524 | break; |
| 2525 | |
| 2526 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2527 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2528 | |
| 2529 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2530 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2531 | // AST block, skipping subblocks, to see if there are other |
| 2532 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2533 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2534 | // FIXME: We can't clear loaded slocentries anymore. |
| 2535 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2536 | |
| 2537 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2538 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2539 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2540 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2541 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2542 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2543 | break; |
| 2544 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2545 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2546 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2547 | return Failure; |
| 2548 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2551 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2552 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2553 | // Once read, set the Module bit base offset and update the size in |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2554 | // bits of all files we've seen. |
| 2555 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2556 | TotalModulesSizeInBits += F.SizeInBits; |
| 2557 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2558 | |
| 2559 | // Make sure that the files this module was built against are still available. |
| 2560 | if (!DisableValidation) { |
| 2561 | switch(validateFileEntries(*M)) { |
| 2562 | case Failure: return Failure; |
| 2563 | case IgnorePCH: return IgnorePCH; |
| 2564 | case Success: break; |
| 2565 | } |
| 2566 | } |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2567 | |
| 2568 | // Preload SLocEntries. |
| 2569 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2570 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Argyrios Kyrtzidis | ac1ffcc | 2011-09-19 20:39:54 +0000 | [diff] [blame] | 2571 | // Load it through the SourceManager and don't call ReadSLocEntryRecord() |
| 2572 | // directly because the entry may have already been loaded in which case |
| 2573 | // calling ReadSLocEntryRecord() directly would trigger an assertion in |
| 2574 | // SourceManager. |
| 2575 | SourceMgr.getLoadedSLocEntryByID(Index); |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2578 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2579 | return Success; |
| 2580 | } |
| 2581 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2582 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2583 | // If there's a listener, notify them that we "read" the translation unit. |
| 2584 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2585 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2586 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2587 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2588 | // Make sure we load the declaration update records for the translation unit, |
| 2589 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2590 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2591 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2592 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2593 | // FIXME: Find a better way to deal with collisions between these |
| 2594 | // built-in types. Right now, we just ignore the problem. |
| 2595 | |
| 2596 | // Load the special types. |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2597 | if (SpecialTypes.size() > NumSpecialTypeIDs) { |
| 2598 | if (Context.getBuiltinVaListType().isNull()) { |
| 2599 | Context.setBuiltinVaListType( |
| 2600 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2601 | } |
| 2602 | |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2603 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2604 | if (Context.ObjCProtoType.isNull()) |
| 2605 | Context.ObjCProtoType = GetType(Proto); |
| 2606 | } |
| 2607 | |
| 2608 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2609 | if (!Context.CFConstantStringTypeDecl) |
| 2610 | Context.setCFConstantStringType(GetType(String)); |
| 2611 | } |
| 2612 | |
| 2613 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2614 | QualType FileType = GetType(File); |
| 2615 | if (FileType.isNull()) { |
| 2616 | Error("FILE type is NULL"); |
| 2617 | return; |
| 2618 | } |
| 2619 | |
| 2620 | if (!Context.FILEDecl) { |
| 2621 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2622 | Context.setFILEDecl(Typedef->getDecl()); |
| 2623 | else { |
| 2624 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2625 | if (!Tag) { |
| 2626 | Error("Invalid FILE type in AST file"); |
| 2627 | return; |
| 2628 | } |
| 2629 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2630 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2631 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2632 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2633 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2634 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2635 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2636 | if (Jmp_bufType.isNull()) { |
| 2637 | Error("jmp_buf type is NULL"); |
| 2638 | return; |
| 2639 | } |
| 2640 | |
| 2641 | if (!Context.jmp_bufDecl) { |
| 2642 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2643 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2644 | else { |
| 2645 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2646 | if (!Tag) { |
| 2647 | Error("Invalid jmp_buf type in AST file"); |
| 2648 | return; |
| 2649 | } |
| 2650 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2651 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2652 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2653 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2654 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2655 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2656 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2657 | if (Sigjmp_bufType.isNull()) { |
| 2658 | Error("sigjmp_buf type is NULL"); |
| 2659 | return; |
| 2660 | } |
| 2661 | |
| 2662 | if (!Context.sigjmp_bufDecl) { |
| 2663 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2664 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2665 | else { |
| 2666 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2667 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2668 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | if (unsigned ObjCIdRedef |
| 2674 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2675 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2676 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2677 | } |
| 2678 | |
| 2679 | if (unsigned ObjCClassRedef |
| 2680 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2681 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2682 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2683 | } |
| 2684 | |
| 2685 | if (unsigned ObjCSelRedef |
| 2686 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2687 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2688 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2689 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 2690 | |
| 2691 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 2692 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 2693 | if (Ucontext_tType.isNull()) { |
| 2694 | Error("ucontext_t type is NULL"); |
| 2695 | return; |
| 2696 | } |
| 2697 | |
| 2698 | if (!Context.ucontext_tDecl) { |
| 2699 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 2700 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 2701 | else { |
| 2702 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 2703 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 2704 | Context.setucontext_tDecl(Tag->getDecl()); |
| 2705 | } |
| 2706 | } |
| 2707 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2710 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2711 | |
| 2712 | // If there were any CUDA special declarations, deserialize them. |
| 2713 | if (!CUDASpecialDeclRefs.empty()) { |
| 2714 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2715 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2716 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2717 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2720 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2721 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2722 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2723 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2724 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2725 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2726 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2727 | std::string ErrStr; |
| 2728 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2729 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2730 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2731 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2732 | return std::string(); |
| 2733 | } |
| 2734 | |
| 2735 | // Initialize the stream |
| 2736 | llvm::BitstreamReader StreamFile; |
| 2737 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2738 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2739 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2740 | Stream.init(StreamFile); |
| 2741 | |
| 2742 | // Sniff for the signature. |
| 2743 | if (Stream.Read(8) != 'C' || |
| 2744 | Stream.Read(8) != 'P' || |
| 2745 | Stream.Read(8) != 'C' || |
| 2746 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2747 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2748 | return std::string(); |
| 2749 | } |
| 2750 | |
| 2751 | RecordData Record; |
| 2752 | while (!Stream.AtEndOfStream()) { |
| 2753 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2754 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2755 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2756 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2757 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2758 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2759 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2760 | case AST_BLOCK_ID: |
| 2761 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2762 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2763 | return std::string(); |
| 2764 | } |
| 2765 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2766 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2767 | default: |
| 2768 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2769 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2770 | return std::string(); |
| 2771 | } |
| 2772 | break; |
| 2773 | } |
| 2774 | continue; |
| 2775 | } |
| 2776 | |
| 2777 | if (Code == llvm::bitc::END_BLOCK) { |
| 2778 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2779 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2780 | return std::string(); |
| 2781 | } |
| 2782 | continue; |
| 2783 | } |
| 2784 | |
| 2785 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2786 | Stream.ReadAbbrevRecord(); |
| 2787 | continue; |
| 2788 | } |
| 2789 | |
| 2790 | Record.clear(); |
| 2791 | const char *BlobStart = 0; |
| 2792 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2793 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2794 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2795 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2796 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2797 | |
| 2798 | return std::string(); |
| 2799 | } |
| 2800 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2801 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2802 | /// structure. |
| 2803 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2804 | /// This routine parses the language options from the AST file and then gives |
| 2805 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2806 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2807 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2808 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2809 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2810 | if (Listener) { |
| 2811 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2812 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 2813 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 2814 | LangOpts.Name = Record[Idx++]; |
| 2815 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 2816 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 2817 | #include "clang/Basic/LangOptions.def" |
| 2818 | |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 2819 | unsigned Length = Record[Idx++]; |
| 2820 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 2821 | Record.begin() + Idx + Length); |
| 2822 | Idx += Length; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2823 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2824 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2825 | |
| 2826 | return false; |
| 2827 | } |
| 2828 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 2829 | std::pair<Module *, unsigned> |
| 2830 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2831 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 2832 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2833 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 2834 | "Corrupted global preprocessed entity map"); |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 2835 | Module *M = I->second; |
| 2836 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 2837 | return std::make_pair(M, LocalIndex); |
| 2838 | } |
| 2839 | |
| 2840 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 2841 | PreprocessedEntityID PPID = Index+1; |
| 2842 | std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 2843 | Module &M = *PPInfo.first; |
| 2844 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2845 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2846 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2847 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2848 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2849 | |
| 2850 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 2851 | switch (Code) { |
| 2852 | case llvm::bitc::END_BLOCK: |
| 2853 | return 0; |
| 2854 | |
| 2855 | case llvm::bitc::ENTER_SUBBLOCK: |
| 2856 | Error("unexpected subblock record in preprocessor detail block"); |
| 2857 | return 0; |
| 2858 | |
| 2859 | case llvm::bitc::DEFINE_ABBREV: |
| 2860 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 2861 | return 0; |
| 2862 | |
| 2863 | default: |
| 2864 | break; |
| 2865 | } |
| 2866 | |
| 2867 | if (!PP.getPreprocessingRecord()) { |
| 2868 | Error("no preprocessing record"); |
| 2869 | return 0; |
| 2870 | } |
| 2871 | |
| 2872 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2873 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 2874 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2875 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 2876 | const char *BlobStart = 0; |
| 2877 | unsigned BlobLen = 0; |
| 2878 | RecordData Record; |
| 2879 | PreprocessorDetailRecordTypes RecType = |
| 2880 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 2881 | Code, Record, BlobStart, BlobLen); |
| 2882 | switch (RecType) { |
| 2883 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2884 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2885 | IdentifierInfo *Name = 0; |
| 2886 | MacroDefinition *Def = 0; |
| 2887 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2888 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2889 | else { |
| 2890 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2891 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2892 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 2893 | } |
| 2894 | |
| 2895 | MacroExpansion *ME; |
| 2896 | if (isBuiltin) |
| 2897 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 2898 | else |
| 2899 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 2900 | |
| 2901 | return ME; |
| 2902 | } |
| 2903 | |
| 2904 | case PPD_MACRO_DEFINITION: { |
| 2905 | // Decode the identifier info and then check again; if the macro is |
| 2906 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2907 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2908 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2909 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2910 | |
| 2911 | if (DeserializationListener) |
| 2912 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 2913 | |
| 2914 | return MD; |
| 2915 | } |
| 2916 | |
| 2917 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2918 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2919 | const FileEntry *File |
| 2920 | = PP.getFileManager().getFile(StringRef(FullFileNameStart, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2921 | BlobLen - Record[0])); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2922 | |
| 2923 | // FIXME: Stable encoding |
| 2924 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2925 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2926 | InclusionDirective *ID |
| 2927 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2928 | StringRef(BlobStart, Record[0]), |
| 2929 | Record[1], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2930 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2931 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2932 | return ID; |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | Error("invalid offset in preprocessor detail block"); |
| 2937 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2938 | } |
| 2939 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2940 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 2941 | /// preprocessed entities or the entities it contains are not the ones we are |
| 2942 | /// looking for. Find the next module that contains entities and return the ID |
| 2943 | /// of the first entry. |
| 2944 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 2945 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 2946 | ++SLocMapI; |
| 2947 | for (GlobalSLocOffsetMapType::const_iterator |
| 2948 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 2949 | Module &M = *SLocMapI->second; |
| 2950 | if (M.NumPreprocessedEntities) |
| 2951 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 2952 | } |
| 2953 | |
| 2954 | return getTotalNumPreprocessedEntities(); |
| 2955 | } |
| 2956 | |
| 2957 | namespace { |
| 2958 | |
| 2959 | template <unsigned PPEntityOffset::*PPLoc> |
| 2960 | struct PPEntityComp { |
| 2961 | const ASTReader &Reader; |
| 2962 | Module &M; |
| 2963 | |
| 2964 | PPEntityComp(const ASTReader &Reader, Module &M) : Reader(Reader), M(M) { } |
| 2965 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 2966 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 2967 | SourceLocation LHS = getLoc(L); |
| 2968 | SourceLocation RHS = getLoc(R); |
| 2969 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 2970 | } |
| 2971 | |
| 2972 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2973 | SourceLocation LHS = getLoc(L); |
| 2974 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 2975 | } |
| 2976 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 2977 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2978 | SourceLocation RHS = getLoc(R); |
| 2979 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 2980 | } |
| 2981 | |
| 2982 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 2983 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 2984 | } |
| 2985 | }; |
| 2986 | |
| 2987 | } |
| 2988 | |
| 2989 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 2990 | PreprocessedEntityID |
| 2991 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 2992 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 2993 | return getTotalNumPreprocessedEntities(); |
| 2994 | |
| 2995 | GlobalSLocOffsetMapType::const_iterator |
| 2996 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 2997 | BLoc.getOffset()); |
| 2998 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 2999 | "Corrupted global sloc offset map"); |
| 3000 | |
| 3001 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3002 | return findNextPreprocessedEntity(SLocMapI); |
| 3003 | |
| 3004 | Module &M = *SLocMapI->second; |
| 3005 | typedef const PPEntityOffset *pp_iterator; |
| 3006 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3007 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 3008 | |
| 3009 | size_t Count = M.NumPreprocessedEntities; |
| 3010 | size_t Half; |
| 3011 | pp_iterator First = pp_begin; |
| 3012 | pp_iterator PPI; |
| 3013 | |
| 3014 | // Do a binary search manually instead of using std::lower_bound because |
| 3015 | // The end locations of entities may be unordered (when a macro expansion |
| 3016 | // is inside another macro argument), but for this case it is not important |
| 3017 | // whether we get the first macro expansion or its containing macro. |
| 3018 | while (Count > 0) { |
| 3019 | Half = Count/2; |
| 3020 | PPI = First; |
| 3021 | std::advance(PPI, Half); |
| 3022 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 3023 | BLoc)){ |
| 3024 | First = PPI; |
| 3025 | ++First; |
| 3026 | Count = Count - Half - 1; |
| 3027 | } else |
| 3028 | Count = Half; |
| 3029 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3030 | |
| 3031 | if (PPI == pp_end) |
| 3032 | return findNextPreprocessedEntity(SLocMapI); |
| 3033 | |
| 3034 | return getGlobalPreprocessedEntityID(M, |
| 3035 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3036 | } |
| 3037 | |
| 3038 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 3039 | PreprocessedEntityID |
| 3040 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 3041 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 3042 | return getTotalNumPreprocessedEntities(); |
| 3043 | |
| 3044 | GlobalSLocOffsetMapType::const_iterator |
| 3045 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3046 | ELoc.getOffset()); |
| 3047 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3048 | "Corrupted global sloc offset map"); |
| 3049 | |
| 3050 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3051 | return findNextPreprocessedEntity(SLocMapI); |
| 3052 | |
| 3053 | Module &M = *SLocMapI->second; |
| 3054 | typedef const PPEntityOffset *pp_iterator; |
| 3055 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3056 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 3057 | pp_iterator PPI = |
| 3058 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 3059 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 3060 | |
| 3061 | if (PPI == pp_end) |
| 3062 | return findNextPreprocessedEntity(SLocMapI); |
| 3063 | |
| 3064 | return getGlobalPreprocessedEntityID(M, |
| 3065 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3066 | } |
| 3067 | |
| 3068 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 3069 | /// preprocessed entities that \arg Range encompasses. |
| 3070 | std::pair<unsigned, unsigned> |
| 3071 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 3072 | if (Range.isInvalid()) |
| 3073 | return std::make_pair(0,0); |
| 3074 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 3075 | |
| 3076 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 3077 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 3078 | return std::make_pair(BeginID, EndID); |
| 3079 | } |
| 3080 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3081 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 3082 | /// entity with index \arg Index came from file \arg FID. |
| 3083 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 3084 | FileID FID) { |
| 3085 | if (FID.isInvalid()) |
| 3086 | return false; |
| 3087 | |
| 3088 | std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3089 | Module &M = *PPInfo.first; |
| 3090 | unsigned LocalIndex = PPInfo.second; |
| 3091 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 3092 | |
| 3093 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 3094 | if (Loc.isInvalid()) |
| 3095 | return false; |
| 3096 | |
| 3097 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 3098 | return true; |
| 3099 | else |
| 3100 | return false; |
| 3101 | } |
| 3102 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3103 | namespace { |
| 3104 | /// \brief Visitor used to search for information about a header file. |
| 3105 | class HeaderFileInfoVisitor { |
| 3106 | ASTReader &Reader; |
| 3107 | const FileEntry *FE; |
| 3108 | |
| 3109 | llvm::Optional<HeaderFileInfo> HFI; |
| 3110 | |
| 3111 | public: |
| 3112 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3113 | : Reader(Reader), FE(FE) { } |
| 3114 | |
| 3115 | static bool visit(Module &M, void *UserData) { |
| 3116 | HeaderFileInfoVisitor *This |
| 3117 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3118 | |
| 3119 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3120 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3121 | M.HeaderFileFrameworkStrings, |
| 3122 | This->FE->getName()); |
| 3123 | |
| 3124 | HeaderFileInfoLookupTable *Table |
| 3125 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3126 | if (!Table) |
| 3127 | return false; |
| 3128 | |
| 3129 | // Look in the on-disk hash table for an entry for this file name. |
| 3130 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3131 | &Trait); |
| 3132 | if (Pos == Table->end()) |
| 3133 | return false; |
| 3134 | |
| 3135 | This->HFI = *Pos; |
| 3136 | return true; |
| 3137 | } |
| 3138 | |
| 3139 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3140 | }; |
| 3141 | } |
| 3142 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3143 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3144 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3145 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3146 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3147 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3148 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3149 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | return HeaderFileInfo(); |
| 3153 | } |
| 3154 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3155 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3156 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3157 | Module &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3158 | unsigned Idx = 0; |
| 3159 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3160 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3161 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 3162 | Diag.DiagStatePoints.push_back( |
| 3163 | DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(), |
| 3164 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3165 | while (1) { |
| 3166 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3167 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3168 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3169 | break; // Something is messed up but at least avoid infinite loop in |
| 3170 | // release build. |
| 3171 | } |
| 3172 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3173 | if (DiagID == (unsigned)-1) { |
| 3174 | break; // no more diag/map pairs for this location. |
| 3175 | } |
| 3176 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3177 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 3178 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3179 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3180 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3181 | } |
| 3182 | } |
| 3183 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3184 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3185 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3186 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3187 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3188 | Module *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3189 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3193 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3194 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3195 | /// routine actually reads the record corresponding to the type at the given |
| 3196 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3197 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3198 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3199 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3200 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3201 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3202 | // Keep track of where we are in the stream, then jump back there |
| 3203 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3204 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3205 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3206 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3207 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3208 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3209 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3210 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3211 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3212 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3213 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3214 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3215 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3216 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3217 | if (Record.size() != 2) { |
| 3218 | Error("Incorrect encoding of extended qualifier type"); |
| 3219 | return QualType(); |
| 3220 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3221 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3222 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3223 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3224 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3225 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3226 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3227 | if (Record.size() != 1) { |
| 3228 | Error("Incorrect encoding of complex type"); |
| 3229 | return QualType(); |
| 3230 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3231 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3232 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3233 | } |
| 3234 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3235 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3236 | if (Record.size() != 1) { |
| 3237 | Error("Incorrect encoding of pointer type"); |
| 3238 | return QualType(); |
| 3239 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3240 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3241 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3244 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3245 | if (Record.size() != 1) { |
| 3246 | Error("Incorrect encoding of block pointer type"); |
| 3247 | return QualType(); |
| 3248 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3249 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3250 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3251 | } |
| 3252 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3253 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3254 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3255 | Error("Incorrect encoding of lvalue reference type"); |
| 3256 | return QualType(); |
| 3257 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3258 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3259 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3260 | } |
| 3261 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3262 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3263 | if (Record.size() != 1) { |
| 3264 | Error("Incorrect encoding of rvalue reference type"); |
| 3265 | return QualType(); |
| 3266 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3267 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3268 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3269 | } |
| 3270 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3271 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3272 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3273 | Error("Incorrect encoding of member pointer type"); |
| 3274 | return QualType(); |
| 3275 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3276 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3277 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3278 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3279 | return QualType(); |
| 3280 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3281 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3284 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3285 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3286 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3287 | unsigned IndexTypeQuals = Record[2]; |
| 3288 | unsigned Idx = 3; |
| 3289 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3290 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3291 | ASM, IndexTypeQuals); |
| 3292 | } |
| 3293 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3294 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3295 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3296 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3297 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3298 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3299 | } |
| 3300 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3301 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3302 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3303 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3304 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3305 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3306 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3307 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3308 | ASM, IndexTypeQuals, |
| 3309 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3312 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3313 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3314 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3315 | return QualType(); |
| 3316 | } |
| 3317 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3318 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3319 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3320 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3321 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3322 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3323 | } |
| 3324 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3325 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3326 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3327 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3328 | return QualType(); |
| 3329 | } |
| 3330 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3331 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3332 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3333 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3334 | } |
| 3335 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3336 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3337 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3338 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3339 | return QualType(); |
| 3340 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3341 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3342 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3343 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3344 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3347 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3348 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3349 | |
| 3350 | FunctionProtoType::ExtProtoInfo EPI; |
| 3351 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3352 | /*hasregparm*/ Record[2], |
| 3353 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3354 | static_cast<CallingConv>(Record[4]), |
| 3355 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3356 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3357 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3358 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3359 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3360 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3361 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3362 | |
| 3363 | EPI.Variadic = Record[Idx++]; |
| 3364 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3365 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3366 | ExceptionSpecificationType EST = |
| 3367 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3368 | EPI.ExceptionSpecType = EST; |
| 3369 | if (EST == EST_Dynamic) { |
| 3370 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3371 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3372 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3373 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3374 | EPI.Exceptions = Exceptions.data(); |
| 3375 | } else if (EST == EST_ComputedNoexcept) { |
| 3376 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3377 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3378 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3379 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3382 | case TYPE_UNRESOLVED_USING: { |
| 3383 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3384 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3385 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3386 | } |
| 3387 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3388 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3389 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3390 | Error("incorrect encoding of typedef type"); |
| 3391 | return QualType(); |
| 3392 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3393 | unsigned Idx = 0; |
| 3394 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3395 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3396 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3397 | Canonical = Context.getCanonicalType(Canonical); |
| 3398 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3399 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3400 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3401 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3402 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3403 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3404 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3405 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3406 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3407 | return QualType(); |
| 3408 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3409 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3410 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3411 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3412 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3413 | case TYPE_DECLTYPE: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3414 | return Context.getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3415 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3416 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3417 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3418 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3419 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3420 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3421 | } |
| 3422 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3423 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3424 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3425 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3426 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3427 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3428 | Error("incorrect encoding of record type"); |
| 3429 | return QualType(); |
| 3430 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3431 | unsigned Idx = 0; |
| 3432 | bool IsDependent = Record[Idx++]; |
| 3433 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3434 | = Context.getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3435 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3436 | return T; |
| 3437 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3438 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3439 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3440 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3441 | Error("incorrect encoding of enum type"); |
| 3442 | return QualType(); |
| 3443 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3444 | unsigned Idx = 0; |
| 3445 | bool IsDependent = Record[Idx++]; |
| 3446 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3447 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3448 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3449 | return T; |
| 3450 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3451 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3452 | case TYPE_ATTRIBUTED: { |
| 3453 | if (Record.size() != 3) { |
| 3454 | Error("incorrect encoding of attributed type"); |
| 3455 | return QualType(); |
| 3456 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3457 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3458 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3459 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3460 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3461 | } |
| 3462 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3463 | case TYPE_PAREN: { |
| 3464 | if (Record.size() != 1) { |
| 3465 | Error("incorrect encoding of paren type"); |
| 3466 | return QualType(); |
| 3467 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3468 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3469 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3470 | } |
| 3471 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3472 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3473 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3474 | Error("incorrect encoding of pack expansion type"); |
| 3475 | return QualType(); |
| 3476 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3477 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3478 | if (Pattern.isNull()) |
| 3479 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3480 | llvm::Optional<unsigned> NumExpansions; |
| 3481 | if (Record[1]) |
| 3482 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3483 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3486 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3487 | unsigned Idx = 0; |
| 3488 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3489 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3490 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3491 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3494 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3495 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3496 | ObjCInterfaceDecl *ItfD |
| 3497 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3498 | return Context.getObjCInterfaceType(ItfD); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3499 | } |
| 3500 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3501 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3502 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3503 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3504 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3505 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3506 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3507 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3508 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3509 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3510 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3511 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3512 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3513 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3514 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3515 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3516 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3517 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3518 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3519 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3520 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3521 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3522 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3523 | Replacement); |
| 3524 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3525 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3526 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3527 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3528 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3529 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3530 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3531 | cast<TemplateTypeParmType>(Parm), |
| 3532 | ArgPack); |
| 3533 | } |
| 3534 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3535 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3536 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3537 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3538 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3539 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3540 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3541 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3542 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3543 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3544 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3545 | unsigned Idx = 0; |
| 3546 | unsigned Depth = Record[Idx++]; |
| 3547 | unsigned Index = Record[Idx++]; |
| 3548 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3549 | TemplateTypeParmDecl *D |
| 3550 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3551 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3552 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3553 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3554 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3555 | unsigned Idx = 0; |
| 3556 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3557 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3558 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3559 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3560 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3561 | Canon = Context.getCanonicalType(Canon); |
| 3562 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3563 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3564 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3565 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3566 | unsigned Idx = 0; |
| 3567 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3568 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3569 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3570 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3571 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3572 | Args.reserve(NumArgs); |
| 3573 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3574 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3575 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3576 | Args.size(), Args.data()); |
| 3577 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3578 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3579 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3580 | unsigned Idx = 0; |
| 3581 | |
| 3582 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3583 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3584 | ArrayType::ArraySizeModifier ASM |
| 3585 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3586 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3587 | |
| 3588 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3589 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3590 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3591 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3592 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3593 | IndexTypeQuals, Brackets); |
| 3594 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3595 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3596 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3597 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3598 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3599 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3600 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3601 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3602 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3603 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3604 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3605 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3606 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3607 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3608 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3609 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3610 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3611 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3612 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 3613 | |
| 3614 | case TYPE_ATOMIC: { |
| 3615 | if (Record.size() != 1) { |
| 3616 | Error("Incorrect encoding of atomic type"); |
| 3617 | return QualType(); |
| 3618 | } |
| 3619 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 3620 | return Context.getAtomicType(ValueType); |
| 3621 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3622 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3623 | // Suppress a GCC warning |
| 3624 | return QualType(); |
| 3625 | } |
| 3626 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3627 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3628 | ASTReader &Reader; |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3629 | Module &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3630 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3631 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3632 | unsigned &Idx; |
| 3633 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3634 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3635 | unsigned &I) { |
| 3636 | return Reader.ReadSourceLocation(F, R, I); |
| 3637 | } |
| 3638 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3639 | template<typename T> |
| 3640 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3641 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3642 | } |
| 3643 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3644 | public: |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3645 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3646 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3647 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3648 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3649 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3650 | // We want compile-time assurance that we've enumerated all of |
| 3651 | // these, so unfortunately we have to declare them first, then |
| 3652 | // define them out-of-line. |
| 3653 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3654 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3655 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3656 | #include "clang/AST/TypeLocNodes.def" |
| 3657 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3658 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3659 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3660 | }; |
| 3661 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3662 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3663 | // nothing to do |
| 3664 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3665 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3666 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3667 | if (TL.needsExtraLocalData()) { |
| 3668 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3669 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3670 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3671 | TL.setModeAttr(Record[Idx++]); |
| 3672 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3673 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3674 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3675 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3676 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3677 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3678 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3679 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3680 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3681 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3682 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3683 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3684 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3685 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3686 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3687 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3688 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3689 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3690 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3691 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3692 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3693 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3694 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3695 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3696 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3697 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3698 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3699 | TL.setSizeExpr(0); |
| 3700 | } |
| 3701 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3702 | VisitArrayTypeLoc(TL); |
| 3703 | } |
| 3704 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3705 | VisitArrayTypeLoc(TL); |
| 3706 | } |
| 3707 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3708 | VisitArrayTypeLoc(TL); |
| 3709 | } |
| 3710 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3711 | DependentSizedArrayTypeLoc TL) { |
| 3712 | VisitArrayTypeLoc(TL); |
| 3713 | } |
| 3714 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3715 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3716 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3717 | } |
| 3718 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3719 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3720 | } |
| 3721 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3722 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3723 | } |
| 3724 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3725 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3726 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3727 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3728 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3729 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3730 | } |
| 3731 | } |
| 3732 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3733 | VisitFunctionTypeLoc(TL); |
| 3734 | } |
| 3735 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3736 | VisitFunctionTypeLoc(TL); |
| 3737 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3738 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3739 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3740 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3741 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3742 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3743 | } |
| 3744 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3745 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3746 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3747 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3748 | } |
| 3749 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3750 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3751 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3752 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3753 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3754 | } |
| 3755 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3756 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3757 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3758 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3759 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3760 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3761 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3762 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3763 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3764 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3765 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3766 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3767 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3768 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3769 | } |
| 3770 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3771 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3772 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3773 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3774 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3775 | if (TL.hasAttrOperand()) { |
| 3776 | SourceRange range; |
| 3777 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3778 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3779 | TL.setAttrOperandParensRange(range); |
| 3780 | } |
| 3781 | if (TL.hasAttrExprOperand()) { |
| 3782 | if (Record[Idx++]) |
| 3783 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3784 | else |
| 3785 | TL.setAttrExprOperand(0); |
| 3786 | } else if (TL.hasAttrEnumOperand()) |
| 3787 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3788 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3789 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3790 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3791 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3792 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3793 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3794 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3795 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3796 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3797 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3798 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3799 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3800 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3801 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3802 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3803 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3804 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3805 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3806 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3807 | Reader.GetTemplateArgumentLocInfo(F, |
| 3808 | TL.getTypePtr()->getArg(i).getKind(), |
| 3809 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3810 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3811 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3812 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3813 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3814 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3815 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3816 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3817 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3818 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3819 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3820 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3821 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3822 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3823 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3824 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3825 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3826 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3827 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3828 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3829 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3830 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3831 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3832 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3833 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3834 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3835 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3836 | Reader.GetTemplateArgumentLocInfo(F, |
| 3837 | TL.getTypePtr()->getArg(I).getKind(), |
| 3838 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3839 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3840 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3841 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3842 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3843 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3844 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3845 | } |
| 3846 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3847 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3848 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3849 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3850 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3851 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3852 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3853 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3854 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3855 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 3856 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 3857 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3858 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3859 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3860 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3861 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3862 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3863 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3864 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3865 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3866 | if (InfoTy.isNull()) |
| 3867 | return 0; |
| 3868 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3869 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3870 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3871 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3872 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3873 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3874 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3875 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3876 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3877 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3878 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3879 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3880 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3881 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3882 | switch ((PredefinedTypeIDs)Index) { |
| 3883 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3884 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 3885 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3886 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3887 | case PREDEF_TYPE_CHAR_U_ID: |
| 3888 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3889 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3890 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3891 | break; |
| 3892 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3893 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 3894 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 3895 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 3896 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 3897 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 3898 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 3899 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 3900 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 3901 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 3902 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 3903 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 3904 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 3905 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 3906 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3907 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 3908 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 3909 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 3910 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 3911 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 3912 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3913 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 3914 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 3915 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 3916 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 3917 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 3918 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 3919 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 3920 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 3921 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3922 | |
| 3923 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3924 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3925 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 3926 | |
| 3927 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 3928 | T = Context.ARCUnbridgedCastTy; |
| 3929 | break; |
| 3930 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3934 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3937 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3938 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3939 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3940 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3941 | if (TypesLoaded[Index].isNull()) |
| 3942 | return QualType(); |
| 3943 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3944 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3945 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3946 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3947 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3948 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3949 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3950 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3953 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3954 | return GetType(getGlobalTypeID(F, LocalID)); |
| 3955 | } |
| 3956 | |
| 3957 | serialization::TypeID |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3958 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3959 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 3960 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 3961 | |
| 3962 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 3963 | return LocalID; |
| 3964 | |
| 3965 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 3966 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 3967 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 3968 | |
| 3969 | unsigned GlobalIndex = LocalIndex + I->second; |
| 3970 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 3971 | } |
| 3972 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3973 | TemplateArgumentLocInfo |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3974 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3975 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3976 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3977 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3978 | switch (Kind) { |
| 3979 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3980 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3981 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3982 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3983 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3984 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3985 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3986 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3987 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3988 | SourceLocation()); |
| 3989 | } |
| 3990 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3991 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3992 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3993 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3994 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3995 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3996 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3997 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3998 | case TemplateArgument::Null: |
| 3999 | case TemplateArgument::Integral: |
| 4000 | case TemplateArgument::Declaration: |
| 4001 | case TemplateArgument::Pack: |
| 4002 | return TemplateArgumentLocInfo(); |
| 4003 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4004 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4005 | return TemplateArgumentLocInfo(); |
| 4006 | } |
| 4007 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4008 | TemplateArgumentLoc |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4009 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4010 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4011 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4012 | |
| 4013 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4014 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4015 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4016 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4017 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4018 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4021 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4022 | return GetDecl(ID); |
| 4023 | } |
| 4024 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4025 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 4026 | unsigned &Idx){ |
| 4027 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4028 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4029 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4030 | unsigned LocalID = Record[Idx++]; |
| 4031 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4035 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4036 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4037 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4038 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4039 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4040 | RecordData Record; |
| 4041 | unsigned Code = Cursor.ReadCode(); |
| 4042 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4043 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4044 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4045 | return 0; |
| 4046 | } |
| 4047 | |
| 4048 | unsigned Idx = 0; |
| 4049 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4050 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4051 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4052 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4053 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4054 | return Bases; |
| 4055 | } |
| 4056 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4057 | serialization::DeclID |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4058 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4059 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4060 | return LocalID; |
| 4061 | |
| 4062 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4063 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4064 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4065 | |
| 4066 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4069 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 4070 | Module &M) const { |
| 4071 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4072 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4073 | return &M == I->second; |
| 4074 | } |
| 4075 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4076 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 4077 | if (ID < NUM_PREDEF_DECL_IDS) |
| 4078 | return SourceLocation(); |
| 4079 | |
| 4080 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4081 | |
| 4082 | if (Index > DeclsLoaded.size()) { |
| 4083 | Error("declaration ID out-of-range for AST file"); |
| 4084 | return SourceLocation(); |
| 4085 | } |
| 4086 | |
| 4087 | if (Decl *D = DeclsLoaded[Index]) |
| 4088 | return D->getLocation(); |
| 4089 | |
| 4090 | unsigned RawLocation = 0; |
| 4091 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 4092 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 4093 | } |
| 4094 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4095 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4096 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4097 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4098 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4099 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4100 | |
| 4101 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4102 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4103 | |
| 4104 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4105 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4106 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4107 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4108 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4109 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4110 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4111 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4112 | |
| 4113 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4114 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4115 | |
| 4116 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4117 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4118 | |
| 4119 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4120 | return Context.getObjCInstanceTypeDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4121 | } |
| 4122 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4123 | return 0; |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4124 | } |
| 4125 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4126 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4127 | |
| 4128 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4129 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4130 | return 0; |
| 4131 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4132 | |
| 4133 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4134 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4135 | if (DeserializationListener) |
| 4136 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4137 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4138 | |
| 4139 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4140 | } |
| 4141 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4142 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4143 | const RecordData &Record, |
| 4144 | unsigned &Idx) { |
| 4145 | if (Idx >= Record.size()) { |
| 4146 | Error("Corrupted AST file"); |
| 4147 | return 0; |
| 4148 | } |
| 4149 | |
| 4150 | return getGlobalDeclID(F, Record[Idx++]); |
| 4151 | } |
| 4152 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4153 | /// \brief Resolve the offset of a statement into a statement. |
| 4154 | /// |
| 4155 | /// This operation will read a new statement from the external |
| 4156 | /// source each time it is called, and is meant to be used via a |
| 4157 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4158 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4159 | // Switch case IDs are per Decl. |
| 4160 | ClearSwitchCaseIDs(); |
| 4161 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4162 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4163 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4164 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4165 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4168 | namespace { |
| 4169 | class FindExternalLexicalDeclsVisitor { |
| 4170 | ASTReader &Reader; |
| 4171 | const DeclContext *DC; |
| 4172 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4173 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4174 | SmallVectorImpl<Decl*> &Decls; |
| 4175 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4176 | |
| 4177 | public: |
| 4178 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4179 | bool (*isKindWeWant)(Decl::Kind), |
| 4180 | SmallVectorImpl<Decl*> &Decls) |
| 4181 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4182 | { |
| 4183 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4184 | PredefsVisited[I] = false; |
| 4185 | } |
| 4186 | |
| 4187 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4188 | if (Preorder) |
| 4189 | return false; |
| 4190 | |
| 4191 | FindExternalLexicalDeclsVisitor *This |
| 4192 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4193 | |
| 4194 | Module::DeclContextInfosMap::iterator Info |
| 4195 | = M.DeclContextInfos.find(This->DC); |
| 4196 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4197 | return false; |
| 4198 | |
| 4199 | // Load all of the declaration IDs |
| 4200 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4201 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4202 | ID != IDE; ++ID) { |
| 4203 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4204 | continue; |
| 4205 | |
| 4206 | // Don't add predefined declarations to the lexical context more |
| 4207 | // than once. |
| 4208 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4209 | if (This->PredefsVisited[ID->second]) |
| 4210 | continue; |
| 4211 | |
| 4212 | This->PredefsVisited[ID->second] = true; |
| 4213 | } |
| 4214 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4215 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4216 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4217 | This->Decls.push_back(D); |
| 4218 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4219 | } |
| 4220 | |
| 4221 | return false; |
| 4222 | } |
| 4223 | }; |
| 4224 | } |
| 4225 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4226 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4227 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4228 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4229 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4230 | // least. Walk all of the modules in the order they were loaded. |
| 4231 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4232 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4233 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4234 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4235 | } |
| 4236 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4237 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4238 | |
| 4239 | class DeclIDComp { |
| 4240 | ASTReader &Reader; |
| 4241 | Module &Mod; |
| 4242 | |
| 4243 | public: |
| 4244 | DeclIDComp(ASTReader &Reader, Module &M) : Reader(Reader), Mod(M) {} |
| 4245 | |
| 4246 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 4247 | SourceLocation LHS = getLocation(L); |
| 4248 | SourceLocation RHS = getLocation(R); |
| 4249 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4250 | } |
| 4251 | |
| 4252 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 4253 | SourceLocation RHS = getLocation(R); |
| 4254 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4255 | } |
| 4256 | |
| 4257 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 4258 | SourceLocation LHS = getLocation(L); |
| 4259 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4260 | } |
| 4261 | |
| 4262 | SourceLocation getLocation(LocalDeclID ID) const { |
| 4263 | return Reader.getSourceManager().getFileLoc( |
| 4264 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 4265 | } |
| 4266 | }; |
| 4267 | |
| 4268 | } |
| 4269 | |
| 4270 | void ASTReader::FindFileRegionDecls(FileID File, |
| 4271 | unsigned Offset, unsigned Length, |
| 4272 | SmallVectorImpl<Decl *> &Decls) { |
| 4273 | SourceManager &SM = getSourceManager(); |
| 4274 | |
| 4275 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 4276 | if (I == FileDeclIDs.end()) |
| 4277 | return; |
| 4278 | |
| 4279 | FileDeclsInfo &DInfo = I->second; |
| 4280 | if (DInfo.Decls.empty()) |
| 4281 | return; |
| 4282 | |
| 4283 | SourceLocation |
| 4284 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 4285 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 4286 | |
| 4287 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 4288 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4289 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4290 | BeginLoc, DIDComp); |
| 4291 | if (BeginIt != DInfo.Decls.begin()) |
| 4292 | --BeginIt; |
| 4293 | |
| 4294 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4295 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4296 | EndLoc, DIDComp); |
| 4297 | if (EndIt != DInfo.Decls.end()) |
| 4298 | ++EndIt; |
| 4299 | |
| 4300 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 4301 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 4302 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 4303 | } |
| 4304 | |
| 4305 | namespace { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4306 | /// \brief Module visitor used to perform name lookup into a |
| 4307 | /// declaration context. |
| 4308 | class DeclContextNameLookupVisitor { |
| 4309 | ASTReader &Reader; |
| 4310 | const DeclContext *DC; |
| 4311 | DeclarationName Name; |
| 4312 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4313 | |
| 4314 | public: |
| 4315 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4316 | const DeclContext *DC, DeclarationName Name, |
| 4317 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4318 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4319 | |
| 4320 | static bool visit(Module &M, void *UserData) { |
| 4321 | DeclContextNameLookupVisitor *This |
| 4322 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4323 | |
| 4324 | // Check whether we have any visible declaration information for |
| 4325 | // this context in this module. |
| 4326 | Module::DeclContextInfosMap::iterator Info |
| 4327 | = M.DeclContextInfos.find(This->DC); |
| 4328 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4329 | return false; |
| 4330 | |
| 4331 | // Look for this name within this module. |
| 4332 | ASTDeclContextNameLookupTable *LookupTable = |
| 4333 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4334 | ASTDeclContextNameLookupTable::iterator Pos |
| 4335 | = LookupTable->find(This->Name); |
| 4336 | if (Pos == LookupTable->end()) |
| 4337 | return false; |
| 4338 | |
| 4339 | bool FoundAnything = false; |
| 4340 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4341 | for (; Data.first != Data.second; ++Data.first) { |
| 4342 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4343 | if (!ND) |
| 4344 | continue; |
| 4345 | |
| 4346 | if (ND->getDeclName() != This->Name) { |
| 4347 | assert(!This->Name.getCXXNameType().isNull() && |
| 4348 | "Name mismatch without a type"); |
| 4349 | continue; |
| 4350 | } |
| 4351 | |
| 4352 | // Record this declaration. |
| 4353 | FoundAnything = true; |
| 4354 | This->Decls.push_back(ND); |
| 4355 | } |
| 4356 | |
| 4357 | return FoundAnything; |
| 4358 | } |
| 4359 | }; |
| 4360 | } |
| 4361 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4362 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4363 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4364 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4366 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4367 | if (!Name) |
| 4368 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4369 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4370 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4371 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4372 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4373 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4374 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4375 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4376 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4379 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 4380 | /// before receiving the implementation, and codegen depends on this. |
| 4381 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 4382 | /// implementation before passing the deserialized implementation decl. |
| 4383 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 4384 | ASTConsumer *Consumer) { |
| 4385 | assert(ImplD && Consumer); |
| 4386 | |
| 4387 | for (ObjCImplDecl::method_iterator |
| 4388 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
| 4389 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
| 4390 | |
| 4391 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 4392 | } |
| 4393 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4394 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4395 | assert(Consumer); |
| 4396 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4397 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4398 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4399 | |
| 4400 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 4401 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 4402 | else |
| 4403 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4404 | } |
| 4405 | } |
| 4406 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4407 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4408 | this->Consumer = Consumer; |
| 4409 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4410 | if (!Consumer) |
| 4411 | return; |
| 4412 | |
| 4413 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4414 | // Force deserialization of this decl, which will cause it to be queued for |
| 4415 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4416 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4417 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 4418 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4419 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4420 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4423 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4424 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4425 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4426 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4427 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4428 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4429 | unsigned NumDeclsLoaded |
| 4430 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4431 | (Decl *)0); |
| 4432 | unsigned NumIdentifiersLoaded |
| 4433 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4434 | IdentifiersLoaded.end(), |
| 4435 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4436 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4437 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4438 | SelectorsLoaded.end(), |
| 4439 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4440 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4441 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4442 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4443 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4444 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4445 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4446 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4447 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4448 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4449 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4450 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4451 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4452 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4453 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4454 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4455 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4456 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4457 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4458 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4459 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4460 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4461 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4462 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4463 | if (TotalNumStatements) |
| 4464 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4465 | NumStatementsRead, TotalNumStatements, |
| 4466 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4467 | if (TotalNumMacros) |
| 4468 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4469 | NumMacrosRead, TotalNumMacros, |
| 4470 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4471 | if (TotalLexicalDeclContexts) |
| 4472 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4473 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4474 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4475 | * 100)); |
| 4476 | if (TotalVisibleDeclContexts) |
| 4477 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4478 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4479 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4480 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4481 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4482 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4483 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4484 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4485 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4486 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4487 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4488 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4489 | dump(); |
| 4490 | std::fprintf(stderr, "\n"); |
| 4491 | } |
| 4492 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4493 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4494 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4495 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4496 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4497 | InitialCapacity> &Map) { |
| 4498 | if (Map.begin() == Map.end()) |
| 4499 | return; |
| 4500 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4501 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4502 | llvm::errs() << Name << ":\n"; |
| 4503 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4504 | I != IEnd; ++I) { |
| 4505 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4506 | << "\n"; |
| 4507 | } |
| 4508 | } |
| 4509 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4510 | void ASTReader::dump() { |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4511 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4512 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4513 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4514 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4515 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4516 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4517 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4518 | dumpModuleIDMap("Global preprocessed entity map", |
| 4519 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4520 | |
| 4521 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4522 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4523 | MEnd = ModuleMgr.end(); |
| 4524 | M != MEnd; ++M) |
| 4525 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4528 | /// Return the amount of memory used by memory buffers, breaking down |
| 4529 | /// by heap-backed versus mmap'ed memory. |
| 4530 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4531 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4532 | E = ModuleMgr.end(); I != E; ++I) { |
| 4533 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4534 | size_t bytes = buf->getBufferSize(); |
| 4535 | switch (buf->getBufferKind()) { |
| 4536 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4537 | sizes.malloc_bytes += bytes; |
| 4538 | break; |
| 4539 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4540 | sizes.mmap_bytes += bytes; |
| 4541 | break; |
| 4542 | } |
| 4543 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4544 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4547 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4548 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4549 | S.ExternalSource = this; |
| 4550 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4551 | // Makes sure any declarations that were deserialized "too early" |
| 4552 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4553 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 4554 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 4555 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4556 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4557 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4558 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4559 | // Load the offsets of the declarations that Sema references. |
| 4560 | // They will be lazily deserialized when needed. |
| 4561 | if (!SemaDeclRefs.empty()) { |
| 4562 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4563 | if (!SemaObj->StdNamespace) |
| 4564 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4565 | if (!SemaObj->StdBadAlloc) |
| 4566 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4567 | } |
| 4568 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4569 | if (!FPPragmaOptions.empty()) { |
| 4570 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4571 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4572 | } |
| 4573 | |
| 4574 | if (!OpenCLExtensions.empty()) { |
| 4575 | unsigned I = 0; |
| 4576 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4577 | #include "clang/Basic/OpenCLExtensions.def" |
| 4578 | |
| 4579 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4580 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4583 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4584 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4585 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 4586 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 4587 | if (II) |
| 4588 | II->setOutOfDate(false); |
| 4589 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4590 | } |
| 4591 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4592 | namespace clang { |
| 4593 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4594 | /// identifiers stored within a set of AST files. |
| 4595 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4596 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4597 | const ASTReader &Reader; |
| 4598 | |
| 4599 | /// \brief The current index into the chain of AST files stored in |
| 4600 | /// the AST reader. |
| 4601 | unsigned Index; |
| 4602 | |
| 4603 | /// \brief The current position within the identifier lookup table |
| 4604 | /// of the current AST file. |
| 4605 | ASTIdentifierLookupTable::key_iterator Current; |
| 4606 | |
| 4607 | /// \brief The end position within the identifier lookup table of |
| 4608 | /// the current AST file. |
| 4609 | ASTIdentifierLookupTable::key_iterator End; |
| 4610 | |
| 4611 | public: |
| 4612 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4613 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4614 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4615 | }; |
| 4616 | } |
| 4617 | |
| 4618 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4619 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4620 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4621 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4622 | Current = IdTable->key_begin(); |
| 4623 | End = IdTable->key_end(); |
| 4624 | } |
| 4625 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4626 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4627 | while (Current == End) { |
| 4628 | // If we have exhausted all of our AST files, we're done. |
| 4629 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4630 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4631 | |
| 4632 | --Index; |
| 4633 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4634 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4635 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4636 | Current = IdTable->key_begin(); |
| 4637 | End = IdTable->key_end(); |
| 4638 | } |
| 4639 | |
| 4640 | // We have any identifiers remaining in the current AST file; return |
| 4641 | // the next one. |
| 4642 | std::pair<const char*, unsigned> Key = *Current; |
| 4643 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4644 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4648 | return new ASTIdentifierIterator(*this); |
| 4649 | } |
| 4650 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4651 | namespace clang { namespace serialization { |
| 4652 | class ReadMethodPoolVisitor { |
| 4653 | ASTReader &Reader; |
| 4654 | Selector Sel; |
| 4655 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4656 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4657 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4658 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4659 | /// declarations. |
| 4660 | ObjCMethodList |
| 4661 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4662 | { |
| 4663 | ObjCMethodList List; |
| 4664 | ObjCMethodList *Prev = 0; |
| 4665 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4666 | if (!List.Method) { |
| 4667 | // This is the first method, which is the easy case. |
| 4668 | List.Method = Vec[I]; |
| 4669 | Prev = &List; |
| 4670 | continue; |
| 4671 | } |
| 4672 | |
| 4673 | ObjCMethodList *Mem = |
| 4674 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4675 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4676 | Prev = Prev->Next; |
| 4677 | } |
| 4678 | |
| 4679 | return List; |
| 4680 | } |
| 4681 | |
| 4682 | public: |
| 4683 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4684 | : Reader(Reader), Sel(Sel) { } |
| 4685 | |
| 4686 | static bool visit(Module &M, void *UserData) { |
| 4687 | ReadMethodPoolVisitor *This |
| 4688 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4689 | |
| 4690 | if (!M.SelectorLookupTable) |
| 4691 | return false; |
| 4692 | |
| 4693 | ASTSelectorLookupTable *PoolTable |
| 4694 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4695 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4696 | if (Pos == PoolTable->end()) |
| 4697 | return false; |
| 4698 | |
| 4699 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4700 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4701 | // disable this tracking when called via LoadSelector. |
| 4702 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4703 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4704 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4705 | if (This->Reader.DeserializationListener) |
| 4706 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4707 | This->Sel); |
| 4708 | |
| 4709 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4710 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4711 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4712 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4713 | |
| 4714 | /// \brief Retrieve the instance methods found by this visitor. |
| 4715 | ObjCMethodList getInstanceMethods() const { |
| 4716 | return buildObjCMethodList(InstanceMethods); |
| 4717 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4718 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4719 | /// \brief Retrieve the instance methods found by this visitor. |
| 4720 | ObjCMethodList getFactoryMethods() const { |
| 4721 | return buildObjCMethodList(FactoryMethods); |
| 4722 | } |
| 4723 | }; |
| 4724 | } } // end namespace clang::serialization |
| 4725 | |
| 4726 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4727 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4728 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4729 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4730 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4731 | Result.first = Visitor.getInstanceMethods(); |
| 4732 | Result.second = Visitor.getFactoryMethods(); |
| 4733 | |
| 4734 | if (!Result.first.Method && !Result.second.Method) |
| 4735 | ++NumMethodPoolMisses; |
| 4736 | return Result; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4739 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4740 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4741 | Namespaces.clear(); |
| 4742 | |
| 4743 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4744 | if (NamespaceDecl *Namespace |
| 4745 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4746 | Namespaces.push_back(Namespace); |
| 4747 | } |
| 4748 | } |
| 4749 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4750 | void ASTReader::ReadTentativeDefinitions( |
| 4751 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4752 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4753 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4754 | if (Var) |
| 4755 | TentativeDefs.push_back(Var); |
| 4756 | } |
| 4757 | TentativeDefinitions.clear(); |
| 4758 | } |
| 4759 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4760 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4761 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4762 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4763 | DeclaratorDecl *D |
| 4764 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4765 | if (D) |
| 4766 | Decls.push_back(D); |
| 4767 | } |
| 4768 | UnusedFileScopedDecls.clear(); |
| 4769 | } |
| 4770 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4771 | void ASTReader::ReadDelegatingConstructors( |
| 4772 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4773 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4774 | CXXConstructorDecl *D |
| 4775 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4776 | if (D) |
| 4777 | Decls.push_back(D); |
| 4778 | } |
| 4779 | DelegatingCtorDecls.clear(); |
| 4780 | } |
| 4781 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4782 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4783 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4784 | TypedefNameDecl *D |
| 4785 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4786 | if (D) |
| 4787 | Decls.push_back(D); |
| 4788 | } |
| 4789 | ExtVectorDecls.clear(); |
| 4790 | } |
| 4791 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4792 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4793 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4794 | CXXRecordDecl *D |
| 4795 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4796 | if (D) |
| 4797 | Decls.push_back(D); |
| 4798 | } |
| 4799 | DynamicClasses.clear(); |
| 4800 | } |
| 4801 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4802 | void |
| 4803 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4804 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4805 | NamedDecl *D |
| 4806 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4807 | if (D) |
| 4808 | Decls.push_back(D); |
| 4809 | } |
| 4810 | LocallyScopedExternalDecls.clear(); |
| 4811 | } |
| 4812 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4813 | void ASTReader::ReadReferencedSelectors( |
| 4814 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4815 | if (ReferencedSelectorsData.empty()) |
| 4816 | return; |
| 4817 | |
| 4818 | // If there are @selector references added them to its pool. This is for |
| 4819 | // implementation of -Wselector. |
| 4820 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4821 | unsigned I = 0; |
| 4822 | while (I < DataSize) { |
| 4823 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4824 | SourceLocation SelLoc |
| 4825 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4826 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4827 | } |
| 4828 | ReferencedSelectorsData.clear(); |
| 4829 | } |
| 4830 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4831 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4832 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4833 | if (WeakUndeclaredIdentifiers.empty()) |
| 4834 | return; |
| 4835 | |
| 4836 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4837 | IdentifierInfo *WeakId |
| 4838 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4839 | IdentifierInfo *AliasId |
| 4840 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4841 | SourceLocation Loc |
| 4842 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4843 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4844 | WeakInfo WI(AliasId, Loc); |
| 4845 | WI.setUsed(Used); |
| 4846 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4847 | } |
| 4848 | WeakUndeclaredIdentifiers.clear(); |
| 4849 | } |
| 4850 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4851 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4852 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4853 | ExternalVTableUse VT; |
| 4854 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4855 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4856 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4857 | VTables.push_back(VT); |
| 4858 | } |
| 4859 | |
| 4860 | VTableUses.clear(); |
| 4861 | } |
| 4862 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4863 | void ASTReader::ReadPendingInstantiations( |
| 4864 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4865 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4866 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4867 | SourceLocation Loc |
| 4868 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4869 | Pending.push_back(std::make_pair(D, Loc)); |
| 4870 | } |
| 4871 | PendingInstantiations.clear(); |
| 4872 | } |
| 4873 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4874 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4875 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4876 | ReadMethodPool(Sel); |
| 4877 | } |
| 4878 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4879 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4880 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4881 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4882 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4883 | if (DeserializationListener) |
| 4884 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4885 | } |
| 4886 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4887 | /// \brief Set the globally-visible declarations associated with the given |
| 4888 | /// identifier. |
| 4889 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4890 | /// 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] | 4891 | /// 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] | 4892 | /// them. |
| 4893 | /// |
| 4894 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4895 | /// declarations. |
| 4896 | /// |
| 4897 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4898 | /// visible at global scope. |
| 4899 | /// |
| 4900 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4901 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4902 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4903 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4904 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4905 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4906 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4907 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4908 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4909 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4910 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4911 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4912 | return; |
| 4913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4914 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4915 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4916 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4917 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 4918 | // Introduce this declaration into the translation-unit scope |
| 4919 | // and add it to the declaration chain for this identifier, so |
| 4920 | // that (unqualified) name lookup will find it. |
| 4921 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4922 | } else { |
| 4923 | // Queue this declaration so that it will be added to the |
| 4924 | // translation unit scope and identifier's declaration chain |
| 4925 | // once a Sema object is known. |
| 4926 | PreloadedDecls.push_back(D); |
| 4927 | } |
| 4928 | } |
| 4929 | } |
| 4930 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4931 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4932 | if (ID == 0) |
| 4933 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4934 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4935 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4936 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4937 | return 0; |
| 4938 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4939 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4940 | ID -= 1; |
| 4941 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4942 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4943 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4944 | Module *M = I->second; |
| 4945 | unsigned Index = ID - M->BaseIdentifierID; |
| 4946 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4947 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4948 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4949 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4950 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4951 | // unsigned integers. This is important to avoid integer overflow when |
| 4952 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4953 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4954 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4955 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4956 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 4957 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4958 | if (DeserializationListener) |
| 4959 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4960 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4961 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4962 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4965 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4966 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4967 | } |
| 4968 | |
| 4969 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4970 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4971 | return LocalID; |
| 4972 | |
| 4973 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4974 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4975 | assert(I != M.IdentifierRemap.end() |
| 4976 | && "Invalid index into identifier index remap"); |
| 4977 | |
| 4978 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4981 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4982 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4983 | } |
| 4984 | |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4985 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4986 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4987 | } |
| 4988 | |
| 4989 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4990 | if (ID == 0) |
| 4991 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4992 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4993 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4994 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4995 | return Selector(); |
| 4996 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4997 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4998 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4999 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5000 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 5001 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5002 | Module &M = *I->second; |
| 5003 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5004 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5005 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5006 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5007 | if (DeserializationListener) |
| 5008 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5011 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5014 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5015 | return DecodeSelector(ID); |
| 5016 | } |
| 5017 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5018 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5019 | // ID 0 (the null selector) is considered an external selector. |
| 5020 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5021 | } |
| 5022 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5023 | serialization::SelectorID |
| 5024 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 5025 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 5026 | return LocalID; |
| 5027 | |
| 5028 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5029 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 5030 | assert(I != M.SelectorRemap.end() |
| 5031 | && "Invalid index into identifier index remap"); |
| 5032 | |
| 5033 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5036 | DeclarationName |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5037 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5038 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5039 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 5040 | switch (Kind) { |
| 5041 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5042 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5043 | |
| 5044 | case DeclarationName::ObjCZeroArgSelector: |
| 5045 | case DeclarationName::ObjCOneArgSelector: |
| 5046 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5047 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5048 | |
| 5049 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5050 | return Context.DeclarationNames.getCXXConstructorName( |
| 5051 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5052 | |
| 5053 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5054 | return Context.DeclarationNames.getCXXDestructorName( |
| 5055 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5056 | |
| 5057 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5058 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 5059 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5060 | |
| 5061 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5062 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5063 | (OverloadedOperatorKind)Record[Idx++]); |
| 5064 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5065 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5066 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5067 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5068 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5069 | case DeclarationName::CXXUsingDirective: |
| 5070 | return DeclarationName::getUsingDirectiveName(); |
| 5071 | } |
| 5072 | |
| 5073 | // Required to silence GCC warning |
| 5074 | return DeclarationName(); |
| 5075 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5076 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5077 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5078 | DeclarationNameLoc &DNLoc, |
| 5079 | DeclarationName Name, |
| 5080 | const RecordData &Record, unsigned &Idx) { |
| 5081 | switch (Name.getNameKind()) { |
| 5082 | case DeclarationName::CXXConstructorName: |
| 5083 | case DeclarationName::CXXDestructorName: |
| 5084 | case DeclarationName::CXXConversionFunctionName: |
| 5085 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5086 | break; |
| 5087 | |
| 5088 | case DeclarationName::CXXOperatorName: |
| 5089 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5090 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5091 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5092 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5093 | break; |
| 5094 | |
| 5095 | case DeclarationName::CXXLiteralOperatorName: |
| 5096 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5097 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5098 | break; |
| 5099 | |
| 5100 | case DeclarationName::Identifier: |
| 5101 | case DeclarationName::ObjCZeroArgSelector: |
| 5102 | case DeclarationName::ObjCOneArgSelector: |
| 5103 | case DeclarationName::ObjCMultiArgSelector: |
| 5104 | case DeclarationName::CXXUsingDirective: |
| 5105 | break; |
| 5106 | } |
| 5107 | } |
| 5108 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5109 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5110 | DeclarationNameInfo &NameInfo, |
| 5111 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5112 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5113 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5114 | DeclarationNameLoc DNLoc; |
| 5115 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5116 | NameInfo.setInfo(DNLoc); |
| 5117 | } |
| 5118 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5119 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5120 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5121 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5122 | unsigned NumTPLists = Record[Idx++]; |
| 5123 | Info.NumTemplParamLists = NumTPLists; |
| 5124 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5125 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5126 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5127 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5128 | } |
| 5129 | } |
| 5130 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5131 | TemplateName |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5132 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5133 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5134 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5135 | switch (Kind) { |
| 5136 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5137 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5138 | |
| 5139 | case TemplateName::OverloadedTemplate: { |
| 5140 | unsigned size = Record[Idx++]; |
| 5141 | UnresolvedSet<8> Decls; |
| 5142 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5143 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5144 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5145 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5146 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5147 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5148 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5149 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5150 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5151 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5152 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5153 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5154 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5155 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5156 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5157 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5158 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5159 | GetIdentifierInfo(F, Record, |
| 5160 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5161 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5162 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5163 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5164 | |
| 5165 | case TemplateName::SubstTemplateTemplateParm: { |
| 5166 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5167 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5168 | if (!param) return TemplateName(); |
| 5169 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5170 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5171 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5172 | |
| 5173 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5174 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5175 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5176 | if (!Param) |
| 5177 | return TemplateName(); |
| 5178 | |
| 5179 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5180 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5181 | return TemplateName(); |
| 5182 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5183 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5184 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5185 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5186 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5187 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | TemplateArgument |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5191 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5192 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5193 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5194 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5195 | case TemplateArgument::Null: |
| 5196 | return TemplateArgument(); |
| 5197 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5198 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5199 | case TemplateArgument::Declaration: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5200 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5201 | case TemplateArgument::Integral: { |
| 5202 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5203 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5204 | return TemplateArgument(Value, T); |
| 5205 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5206 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5207 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5208 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5209 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5210 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5211 | if (unsigned NumExpansions = Record[Idx++]) |
| 5212 | NumTemplateExpansions = NumExpansions - 1; |
| 5213 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5214 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5215 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5216 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5217 | case TemplateArgument::Pack: { |
| 5218 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5219 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5220 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5221 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5222 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5223 | } |
| 5224 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5225 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5226 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5227 | } |
| 5228 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5229 | TemplateParameterList * |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5230 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5231 | const RecordData &Record, unsigned &Idx) { |
| 5232 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5233 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5234 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5235 | |
| 5236 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5237 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5238 | Params.reserve(NumParams); |
| 5239 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5240 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5241 | |
| 5242 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5243 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5244 | Params.data(), Params.size(), RAngleLoc); |
| 5245 | return TemplateParams; |
| 5246 | } |
| 5247 | |
| 5248 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5249 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5250 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5251 | Module &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5252 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5253 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5254 | TemplArgs.reserve(NumTemplateArgs); |
| 5255 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5256 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5257 | } |
| 5258 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5259 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5260 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5261 | const RecordData &Record, unsigned &Idx) { |
| 5262 | unsigned NumDecls = Record[Idx++]; |
| 5263 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5264 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5265 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5266 | Set.addDecl(D, AS); |
| 5267 | } |
| 5268 | } |
| 5269 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5270 | CXXBaseSpecifier |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5271 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5272 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5273 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5274 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5275 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5276 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5277 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5278 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5279 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5280 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5281 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5282 | Result.setInheritConstructors(inheritConstructors); |
| 5283 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5286 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5287 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5288 | unsigned &Idx) { |
| 5289 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5290 | unsigned NumInitializers = Record[Idx++]; |
| 5291 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5292 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5293 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5294 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5295 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5296 | bool IsBaseVirtual = false; |
| 5297 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5298 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5299 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5300 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5301 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5302 | case CTOR_INITIALIZER_BASE: |
| 5303 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5304 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5305 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5306 | |
| 5307 | case CTOR_INITIALIZER_DELEGATING: |
| 5308 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5309 | break; |
| 5310 | |
| 5311 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5312 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5313 | break; |
| 5314 | |
| 5315 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5316 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5317 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5318 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5319 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5320 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5321 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5322 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5323 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5324 | bool IsWritten = Record[Idx++]; |
| 5325 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5326 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5327 | if (IsWritten) { |
| 5328 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5329 | } else { |
| 5330 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5331 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5332 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5333 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5334 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5335 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5336 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5337 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5338 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5339 | LParenLoc, Init, RParenLoc, |
| 5340 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5341 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 5342 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 5343 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5344 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5345 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5346 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5347 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5348 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5349 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5350 | MemberOrEllipsisLoc, LParenLoc, |
| 5351 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5352 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5353 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5354 | LParenLoc, Init, RParenLoc, |
| 5355 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5358 | if (IsWritten) |
| 5359 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5360 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5361 | } |
| 5362 | } |
| 5363 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5364 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5365 | } |
| 5366 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5367 | NestedNameSpecifier * |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5368 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5369 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5370 | unsigned N = Record[Idx++]; |
| 5371 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5372 | for (unsigned I = 0; I != N; ++I) { |
| 5373 | NestedNameSpecifier::SpecifierKind Kind |
| 5374 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5375 | switch (Kind) { |
| 5376 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5377 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5378 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5379 | break; |
| 5380 | } |
| 5381 | |
| 5382 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5383 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5384 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5385 | break; |
| 5386 | } |
| 5387 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5388 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5389 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5390 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5391 | break; |
| 5392 | } |
| 5393 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5394 | case NestedNameSpecifier::TypeSpec: |
| 5395 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5396 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5397 | if (!T) |
| 5398 | return 0; |
| 5399 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5400 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5401 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5402 | break; |
| 5403 | } |
| 5404 | |
| 5405 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5406 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5407 | // No associated value, and there can't be a prefix. |
| 5408 | break; |
| 5409 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5410 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5411 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5412 | } |
| 5413 | return NNS; |
| 5414 | } |
| 5415 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5416 | NestedNameSpecifierLoc |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5417 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5418 | unsigned &Idx) { |
| 5419 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5420 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5421 | for (unsigned I = 0; I != N; ++I) { |
| 5422 | NestedNameSpecifier::SpecifierKind Kind |
| 5423 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5424 | switch (Kind) { |
| 5425 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5426 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5427 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5428 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5429 | break; |
| 5430 | } |
| 5431 | |
| 5432 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5433 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5434 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5435 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5436 | break; |
| 5437 | } |
| 5438 | |
| 5439 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5440 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5441 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5442 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5443 | break; |
| 5444 | } |
| 5445 | |
| 5446 | case NestedNameSpecifier::TypeSpec: |
| 5447 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5448 | bool Template = Record[Idx++]; |
| 5449 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5450 | if (!T) |
| 5451 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5452 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5453 | |
| 5454 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5455 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5456 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5457 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5458 | break; |
| 5459 | } |
| 5460 | |
| 5461 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5462 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5463 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5464 | break; |
| 5465 | } |
| 5466 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5469 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5472 | SourceRange |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5473 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5474 | unsigned &Idx) { |
| 5475 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5476 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5477 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5478 | } |
| 5479 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5480 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5481 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5482 | unsigned BitWidth = Record[Idx++]; |
| 5483 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5484 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5485 | Idx += NumWords; |
| 5486 | return Result; |
| 5487 | } |
| 5488 | |
| 5489 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5490 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5491 | bool isUnsigned = Record[Idx++]; |
| 5492 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5493 | } |
| 5494 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5495 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5496 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5497 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5498 | } |
| 5499 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5500 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5501 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5502 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5503 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5504 | Idx += Len; |
| 5505 | return Result; |
| 5506 | } |
| 5507 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5508 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5509 | unsigned &Idx) { |
| 5510 | unsigned Major = Record[Idx++]; |
| 5511 | unsigned Minor = Record[Idx++]; |
| 5512 | unsigned Subminor = Record[Idx++]; |
| 5513 | if (Minor == 0) |
| 5514 | return VersionTuple(Major); |
| 5515 | if (Subminor == 0) |
| 5516 | return VersionTuple(Major, Minor - 1); |
| 5517 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5518 | } |
| 5519 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5520 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5521 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5522 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5523 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5524 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5525 | } |
| 5526 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5527 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5528 | return Diag(SourceLocation(), DiagID); |
| 5529 | } |
| 5530 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5531 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5532 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5533 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5534 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5535 | /// \brief Retrieve the identifier table associated with the |
| 5536 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5537 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5538 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5539 | } |
| 5540 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5541 | /// \brief Record that the given ID maps to the given switch-case |
| 5542 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5543 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5544 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5545 | SwitchCaseStmts[ID] = SC; |
| 5546 | } |
| 5547 | |
| 5548 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5549 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5550 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5551 | return SwitchCaseStmts[ID]; |
| 5552 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5553 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5554 | void ASTReader::ClearSwitchCaseIDs() { |
| 5555 | SwitchCaseStmts.clear(); |
| 5556 | } |
| 5557 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5558 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5559 | assert(NumCurrentElementsDeserializing && |
| 5560 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5561 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5562 | // If any identifiers with corresponding top-level declarations have |
| 5563 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5564 | while (!PendingIdentifierInfos.empty()) { |
| 5565 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5566 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5567 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5568 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5569 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5570 | // Ready to load previous declarations of Decls that were delayed. |
| 5571 | while (!PendingPreviousDecls.empty()) { |
| 5572 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5573 | PendingPreviousDecls.front().second); |
| 5574 | PendingPreviousDecls.pop_front(); |
| 5575 | } |
| 5576 | |
Argyrios Kyrtzidis | 5a17499 | 2011-11-14 07:07:59 +0000 | [diff] [blame] | 5577 | for (std::vector<std::pair<ObjCInterfaceDecl *, |
| 5578 | serialization::DeclID> >::iterator |
| 5579 | I = PendingChainedObjCCategories.begin(), |
| 5580 | E = PendingChainedObjCCategories.end(); I != E; ++I) { |
| 5581 | loadObjCChainedCategories(I->second, I->first); |
| 5582 | } |
| 5583 | PendingChainedObjCCategories.clear(); |
| 5584 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5585 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5586 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5587 | if (Consumer) |
| 5588 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5589 | |
| 5590 | assert(PendingForwardRefs.size() == 0 && |
| 5591 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5592 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5593 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5594 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5595 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 5596 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5597 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5598 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5599 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5600 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5601 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Jonathan D. Turner | 1afb661 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5602 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5603 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5604 | DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5605 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5606 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5607 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5608 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5609 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5610 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5611 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5612 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5613 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5614 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5615 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5616 | } |
| 5617 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5618 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5619 | for (DeclContextVisibleUpdatesPending::iterator |
| 5620 | I = PendingVisibleUpdates.begin(), |
| 5621 | E = PendingVisibleUpdates.end(); |
| 5622 | I != E; ++I) { |
| 5623 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5624 | F = I->second.end(); |
| 5625 | J != F; ++J) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5626 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5627 | } |
| 5628 | } |