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 | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 517 | return II; |
| 518 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 520 | unsigned Bits = ReadUnalignedLE16(d); |
| 521 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 522 | Bits >>= 1; |
| 523 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 524 | Bits >>= 1; |
| 525 | bool Poisoned = Bits & 0x01; |
| 526 | Bits >>= 1; |
| 527 | bool ExtensionToken = Bits & 0x01; |
| 528 | Bits >>= 1; |
| 529 | bool hasMacroDefinition = Bits & 0x01; |
| 530 | Bits >>= 1; |
| 531 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 532 | Bits >>= 10; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 533 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 534 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 535 | DataLen -= 6; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 536 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 537 | // Build the IdentifierInfo itself and link the identifier ID with |
| 538 | // the new IdentifierInfo. |
| 539 | IdentifierInfo *II = KnownII; |
| 540 | if (!II) |
| 541 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
| 542 | Reader.SetIdentifierInfo(ID, II); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 543 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 544 | // Set or check the various bits in the IdentifierInfo structure. |
| 545 | // Token IDs are read-only. |
| 546 | if (HasRevertedTokenIDToIdentifier) |
| 547 | II->RevertTokenIDToIdentifier(); |
| 548 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 549 | assert(II->isExtensionToken() == ExtensionToken && |
| 550 | "Incorrect extension token flag"); |
| 551 | (void)ExtensionToken; |
| 552 | if (Poisoned) |
| 553 | II->setIsPoisoned(true); |
| 554 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 555 | "Incorrect C++ operator keyword flag"); |
| 556 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 557 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 558 | // If this identifier is a macro, deserialize the macro |
| 559 | // definition. |
| 560 | if (hasMacroDefinition) { |
| 561 | // FIXME: Check for conflicts? |
| 562 | uint32_t Offset = ReadUnalignedLE32(d); |
| 563 | Reader.SetIdentifierIsMacro(II, F, Offset); |
| 564 | DataLen -= 4; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 567 | // Read all of the declarations visible at global scope with this |
| 568 | // name. |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 569 | if (DataLen > 0) { |
| 570 | SmallVector<uint32_t, 4> DeclIDs; |
| 571 | for (; DataLen > 0; DataLen -= 4) |
| 572 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 573 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 574 | } |
| 575 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 576 | II->setIsFromAST(); |
| 577 | return II; |
| 578 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 579 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 580 | unsigned |
| 581 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 582 | llvm::FoldingSetNodeID ID; |
| 583 | ID.AddInteger(Key.Kind); |
| 584 | |
| 585 | switch (Key.Kind) { |
| 586 | case DeclarationName::Identifier: |
| 587 | case DeclarationName::CXXLiteralOperatorName: |
| 588 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 589 | break; |
| 590 | case DeclarationName::ObjCZeroArgSelector: |
| 591 | case DeclarationName::ObjCOneArgSelector: |
| 592 | case DeclarationName::ObjCMultiArgSelector: |
| 593 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 594 | break; |
| 595 | case DeclarationName::CXXOperatorName: |
| 596 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 597 | break; |
| 598 | case DeclarationName::CXXConstructorName: |
| 599 | case DeclarationName::CXXDestructorName: |
| 600 | case DeclarationName::CXXConversionFunctionName: |
| 601 | case DeclarationName::CXXUsingDirective: |
| 602 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 605 | return ID.ComputeHash(); |
| 606 | } |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 607 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 608 | ASTDeclContextNameLookupTrait::internal_key_type |
| 609 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 610 | const external_key_type& Name) const { |
| 611 | DeclNameKey Key; |
| 612 | Key.Kind = Name.getNameKind(); |
| 613 | switch (Name.getNameKind()) { |
| 614 | case DeclarationName::Identifier: |
| 615 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 616 | break; |
| 617 | case DeclarationName::ObjCZeroArgSelector: |
| 618 | case DeclarationName::ObjCOneArgSelector: |
| 619 | case DeclarationName::ObjCMultiArgSelector: |
| 620 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 621 | break; |
| 622 | case DeclarationName::CXXOperatorName: |
| 623 | Key.Data = Name.getCXXOverloadedOperator(); |
| 624 | break; |
| 625 | case DeclarationName::CXXLiteralOperatorName: |
| 626 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 627 | break; |
| 628 | case DeclarationName::CXXConstructorName: |
| 629 | case DeclarationName::CXXDestructorName: |
| 630 | case DeclarationName::CXXConversionFunctionName: |
| 631 | case DeclarationName::CXXUsingDirective: |
| 632 | Key.Data = 0; |
| 633 | break; |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 636 | return Key; |
| 637 | } |
| 638 | |
| 639 | ASTDeclContextNameLookupTrait::external_key_type |
| 640 | ASTDeclContextNameLookupTrait::GetExternalKey( |
| 641 | const internal_key_type& Key) const { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 642 | ASTContext &Context = Reader.getContext(); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 643 | switch (Key.Kind) { |
| 644 | case DeclarationName::Identifier: |
| 645 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 646 | |
| 647 | case DeclarationName::ObjCZeroArgSelector: |
| 648 | case DeclarationName::ObjCOneArgSelector: |
| 649 | case DeclarationName::ObjCMultiArgSelector: |
| 650 | return DeclarationName(Selector(Key.Data)); |
| 651 | |
| 652 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 653 | return Context.DeclarationNames.getCXXConstructorName( |
| 654 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 655 | |
| 656 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 657 | return Context.DeclarationNames.getCXXDestructorName( |
| 658 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 659 | |
| 660 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 661 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 662 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 663 | |
| 664 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 665 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 666 | (OverloadedOperatorKind)Key.Data); |
| 667 | |
| 668 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 669 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 670 | (IdentifierInfo*)Key.Data); |
| 671 | |
| 672 | case DeclarationName::CXXUsingDirective: |
| 673 | return DeclarationName::getUsingDirectiveName(); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 676 | llvm_unreachable("Invalid Name Kind ?"); |
| 677 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 678 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 679 | std::pair<unsigned, unsigned> |
| 680 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 681 | using namespace clang::io; |
| 682 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 683 | unsigned DataLen = ReadUnalignedLE16(d); |
| 684 | return std::make_pair(KeyLen, DataLen); |
| 685 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 686 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 687 | ASTDeclContextNameLookupTrait::internal_key_type |
| 688 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 689 | using namespace clang::io; |
| 690 | |
| 691 | DeclNameKey Key; |
| 692 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 693 | switch (Key.Kind) { |
| 694 | case DeclarationName::Identifier: |
| 695 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 696 | break; |
| 697 | case DeclarationName::ObjCZeroArgSelector: |
| 698 | case DeclarationName::ObjCOneArgSelector: |
| 699 | case DeclarationName::ObjCMultiArgSelector: |
| 700 | Key.Data = |
| 701 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 702 | .getAsOpaquePtr(); |
| 703 | break; |
| 704 | case DeclarationName::CXXOperatorName: |
| 705 | Key.Data = *d++; // OverloadedOperatorKind |
| 706 | break; |
| 707 | case DeclarationName::CXXLiteralOperatorName: |
| 708 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 709 | break; |
| 710 | case DeclarationName::CXXConstructorName: |
| 711 | case DeclarationName::CXXDestructorName: |
| 712 | case DeclarationName::CXXConversionFunctionName: |
| 713 | case DeclarationName::CXXUsingDirective: |
| 714 | Key.Data = 0; |
| 715 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 718 | return Key; |
| 719 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 720 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 721 | ASTDeclContextNameLookupTrait::data_type |
| 722 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 723 | const unsigned char* d, |
| 724 | unsigned DataLen) { |
| 725 | using namespace clang::io; |
| 726 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 727 | DeclID *Start = (DeclID *)d; |
| 728 | return std::make_pair(Start, Start + NumDecls); |
| 729 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 730 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 731 | bool ASTReader::ReadDeclContextStorage(Module &M, |
| 732 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 733 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 734 | DeclContextInfo &Info) { |
| 735 | SavedStreamPosition SavedPosition(Cursor); |
| 736 | // First the lexical decls. |
| 737 | if (Offsets.first != 0) { |
| 738 | Cursor.JumpToBit(Offsets.first); |
| 739 | |
| 740 | RecordData Record; |
| 741 | const char *Blob; |
| 742 | unsigned BlobLen; |
| 743 | unsigned Code = Cursor.ReadCode(); |
| 744 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 745 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 746 | Error("Expected lexical block"); |
| 747 | return true; |
| 748 | } |
| 749 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 750 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 751 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | // Now the lookup table. |
| 755 | if (Offsets.second != 0) { |
| 756 | Cursor.JumpToBit(Offsets.second); |
| 757 | |
| 758 | RecordData Record; |
| 759 | const char *Blob; |
| 760 | unsigned BlobLen; |
| 761 | unsigned Code = Cursor.ReadCode(); |
| 762 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 763 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 764 | Error("Expected visible lookup table block"); |
| 765 | return true; |
| 766 | } |
| 767 | Info.NameLookupTableData |
| 768 | = ASTDeclContextNameLookupTable::Create( |
| 769 | (const unsigned char *)Blob + Record[0], |
| 770 | (const unsigned char *)Blob, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 771 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | return false; |
| 775 | } |
| 776 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 777 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 778 | Error(diag::err_fe_pch_malformed, Msg); |
| 779 | } |
| 780 | |
| 781 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 782 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 783 | if (Diags.isDiagnosticInFlight()) |
| 784 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 785 | else |
| 786 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 787 | } |
| 788 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 789 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 790 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 791 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 792 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 793 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 794 | SuggestedPredefines, |
| 795 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 796 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 797 | } |
| 798 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 799 | //===----------------------------------------------------------------------===// |
| 800 | // Source Manager Deserialization |
| 801 | //===----------------------------------------------------------------------===// |
| 802 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 803 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 804 | /// \returns true if there was an error. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 805 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 806 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 807 | unsigned Idx = 0; |
| 808 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 809 | |
| 810 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 811 | std::map<int, int> FileIDs; |
| 812 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 813 | // Extract the file name |
| 814 | unsigned FilenameLen = Record[Idx++]; |
| 815 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 816 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 817 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 818 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | // Parse the line entries |
| 822 | std::vector<LineEntry> Entries; |
| 823 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 824 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 825 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 826 | // Remap FileID from 1-based old view. |
| 827 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 828 | |
| 829 | // Extract the line entries |
| 830 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 831 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 832 | Entries.clear(); |
| 833 | Entries.reserve(NumEntries); |
| 834 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 835 | unsigned FileOffset = Record[Idx++]; |
| 836 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 837 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 839 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 840 | unsigned IncludeOffset = Record[Idx++]; |
| 841 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 842 | FileKind, IncludeOffset)); |
| 843 | } |
| 844 | LineTable.AddEntry(FID, Entries); |
| 845 | } |
| 846 | |
| 847 | return false; |
| 848 | } |
| 849 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 850 | namespace { |
| 851 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 852 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 853 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 854 | const ino_t ino; |
| 855 | const dev_t dev; |
| 856 | const mode_t mode; |
| 857 | const time_t mtime; |
| 858 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 859 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 860 | 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] | 861 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 862 | }; |
| 863 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 864 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 865 | public: |
| 866 | typedef const char *external_key_type; |
| 867 | typedef const char *internal_key_type; |
| 868 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 869 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 870 | |
| 871 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 872 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 876 | |
| 877 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 878 | return strcmp(a, b) == 0; |
| 879 | } |
| 880 | |
| 881 | static std::pair<unsigned, unsigned> |
| 882 | ReadKeyDataLength(const unsigned char*& d) { |
| 883 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 884 | unsigned DataLen = (unsigned) *d++; |
| 885 | return std::make_pair(KeyLen + 1, DataLen); |
| 886 | } |
| 887 | |
| 888 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 889 | return (const char *)d; |
| 890 | } |
| 891 | |
| 892 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 893 | unsigned /*DataLen*/) { |
| 894 | using namespace clang::io; |
| 895 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 896 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 897 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 898 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 899 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 900 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 901 | return data_type(ino, dev, mode, mtime, size); |
| 902 | } |
| 903 | }; |
| 904 | |
| 905 | /// \brief stat() cache for precompiled headers. |
| 906 | /// |
| 907 | /// This cache is very similar to the stat cache used by pretokenized |
| 908 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 909 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 910 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 911 | CacheTy *Cache; |
| 912 | |
| 913 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 915 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 916 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 917 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 918 | Cache = CacheTy::Create(Buckets, Base); |
| 919 | } |
| 920 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 921 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 922 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 923 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 924 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 925 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 926 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 927 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 928 | // 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] | 929 | if (I == Cache->end()) { |
| 930 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 931 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 932 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 933 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 934 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 935 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 937 | StatBuf.st_ino = Data.ino; |
| 938 | StatBuf.st_dev = Data.dev; |
| 939 | StatBuf.st_mtime = Data.mtime; |
| 940 | StatBuf.st_mode = Data.mode; |
| 941 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 942 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 943 | } |
| 944 | }; |
| 945 | } // end anonymous namespace |
| 946 | |
| 947 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 948 | /// \brief Read a source manager block |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 949 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 950 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 951 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 952 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 953 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 954 | // Set the source-location entry cursor to the current position in |
| 955 | // the stream. This cursor will be used to read the contents of the |
| 956 | // source manager block initially, and then lazily read |
| 957 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 958 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 959 | |
| 960 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 961 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 962 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 963 | return Failure; |
| 964 | } |
| 965 | |
| 966 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 967 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 968 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 969 | return Failure; |
| 970 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 971 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 972 | RecordData Record; |
| 973 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 974 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 975 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 976 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 977 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 978 | return Failure; |
| 979 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 980 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 981 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 982 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 983 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 984 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 985 | SLocEntryCursor.ReadSubBlockID(); |
| 986 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 987 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 988 | return Failure; |
| 989 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 990 | continue; |
| 991 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 993 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 994 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 995 | continue; |
| 996 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 997 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 998 | // Read a record. |
| 999 | const char *BlobStart; |
| 1000 | unsigned BlobLen; |
| 1001 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1002 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1003 | default: // Default behavior: ignore. |
| 1004 | break; |
| 1005 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1006 | case SM_SLOC_FILE_ENTRY: |
| 1007 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1008 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1009 | // Once we hit one of the source location entries, we're done. |
| 1010 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1015 | /// \brief If a header file is not found at the path that we expect it to be |
| 1016 | /// and the PCH file was moved from its original location, try to resolve the |
| 1017 | /// file by assuming that header+PCH were moved together and the header is in |
| 1018 | /// the same place relative to the PCH. |
| 1019 | static std::string |
| 1020 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1021 | const std::string &OriginalDir, |
| 1022 | const std::string &CurrDir) { |
| 1023 | assert(OriginalDir != CurrDir && |
| 1024 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1025 | using namespace llvm::sys; |
| 1026 | llvm::SmallString<128> filePath(Filename); |
| 1027 | fs::make_absolute(filePath); |
| 1028 | assert(path::is_absolute(OriginalDir)); |
| 1029 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1030 | |
| 1031 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1032 | fileDirE = path::end(path::parent_path(filePath)); |
| 1033 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1034 | origDirE = path::end(OriginalDir); |
| 1035 | // Skip the common path components from filePath and OriginalDir. |
| 1036 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1037 | *fileDirI == *origDirI) { |
| 1038 | ++fileDirI; |
| 1039 | ++origDirI; |
| 1040 | } |
| 1041 | for (; origDirI != origDirE; ++origDirI) |
| 1042 | path::append(currPCHPath, ".."); |
| 1043 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1044 | path::append(currPCHPath, path::filename(Filename)); |
| 1045 | return currPCHPath.str(); |
| 1046 | } |
| 1047 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1048 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1049 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1050 | if (ID == 0) |
| 1051 | return Success; |
| 1052 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1053 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1054 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1055 | return Failure; |
| 1056 | } |
| 1057 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1058 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1059 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1060 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1061 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1063 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1064 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1065 | if (Code == llvm::bitc::END_BLOCK || |
| 1066 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1067 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1068 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1069 | return Failure; |
| 1070 | } |
| 1071 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1072 | RecordData Record; |
| 1073 | const char *BlobStart; |
| 1074 | unsigned BlobLen; |
| 1075 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1076 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1077 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1078 | return Failure; |
| 1079 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1080 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1081 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1082 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1083 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1084 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1085 | OriginalDir != CurrentDir) { |
| 1086 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1087 | OriginalDir, |
| 1088 | CurrentDir); |
| 1089 | if (!resolved.empty()) |
| 1090 | File = FileMgr.getFile(resolved); |
| 1091 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1092 | if (File == 0) |
| 1093 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1094 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1095 | if (File == 0) { |
| 1096 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1097 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1098 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1099 | Error(ErrorStr.c_str()); |
| 1100 | return Failure; |
| 1101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1103 | if (Record.size() < 6) { |
Ted Kremenek | 1857f62 | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1104 | Error("source location entry is incorrect"); |
| 1105 | return Failure; |
| 1106 | } |
| 1107 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1108 | if (!DisableValidation && |
| 1109 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1110 | #if !defined(LLVM_ON_WIN32) |
| 1111 | // In our regression testing, the Windows file system seems to |
| 1112 | // have inconsistent modification times that sometimes |
| 1113 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1114 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1115 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1116 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1117 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1118 | return Failure; |
| 1119 | } |
| 1120 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1121 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1122 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1123 | // This is the module's main file. |
| 1124 | IncludeLoc = getImportLocation(F); |
| 1125 | } |
| 1126 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 75dfb65 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1127 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1128 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1129 | SrcMgr::FileInfo &FileInfo = |
| 1130 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1131 | FileInfo.NumCreatedFIDs = Record[6]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1132 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1133 | FileInfo.setHasLineDirectives(); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1134 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1135 | break; |
| 1136 | } |
| 1137 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1138 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | const char *Name = BlobStart; |
| 1140 | unsigned Offset = Record[0]; |
| 1141 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1142 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1143 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1144 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1145 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1146 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1147 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1148 | return Failure; |
| 1149 | } |
| 1150 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1151 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1152 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Chris Lattner | a0a270c | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1153 | Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1154 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1155 | BaseOffset + Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1156 | |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1157 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1158 | PCHPredefinesBlock Block = { |
| 1159 | BufferID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1160 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1161 | }; |
| 1162 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1163 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1164 | |
| 1165 | break; |
| 1166 | } |
| 1167 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1168 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1169 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1170 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1171 | ReadSourceLocation(*F, Record[2]), |
| 1172 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1173 | Record[4], |
| 1174 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1175 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1176 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1177 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | return Success; |
| 1181 | } |
| 1182 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1183 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1184 | SourceLocation ASTReader::getImportLocation(Module *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1185 | if (F->ImportLoc.isValid()) |
| 1186 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1187 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1188 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1189 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1190 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1191 | // Main file is the importer. We assume that it is the first entry in the |
| 1192 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1193 | // the main file entry doesn't exist yet. |
| 1194 | // The very first entry is the invalid instantiation loc, which takes up |
| 1195 | // offsets 0 and 1. |
| 1196 | return SourceLocation::getFromRawEncoding(2U); |
| 1197 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1198 | //return F->Loaders[0]->FirstLoc; |
| 1199 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1202 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1203 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1204 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1205 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1206 | unsigned BlockID) { |
| 1207 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1208 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1209 | return Failure; |
| 1210 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1211 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1212 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1213 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1214 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1215 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1216 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1217 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1218 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1219 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1220 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1221 | Cursor.ReadAbbrevRecord(); |
| 1222 | } |
| 1223 | } |
| 1224 | |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1225 | void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1226 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1227 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1228 | // Keep track of where we are in the stream, then jump back there |
| 1229 | // after reading this macro. |
| 1230 | SavedStreamPosition SavedPosition(Stream); |
| 1231 | |
| 1232 | Stream.JumpToBit(Offset); |
| 1233 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1234 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1235 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1236 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1237 | while (true) { |
| 1238 | unsigned Code = Stream.ReadCode(); |
| 1239 | switch (Code) { |
| 1240 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1241 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1242 | |
| 1243 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1244 | // No known subblocks, always skip them. |
| 1245 | Stream.ReadSubBlockID(); |
| 1246 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1247 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1248 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1249 | } |
| 1250 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1251 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1252 | case llvm::bitc::DEFINE_ABBREV: |
| 1253 | Stream.ReadAbbrevRecord(); |
| 1254 | continue; |
| 1255 | default: break; |
| 1256 | } |
| 1257 | |
| 1258 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1259 | const char *BlobStart = 0; |
| 1260 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1261 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1262 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1263 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1264 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1265 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1266 | case PP_MACRO_OBJECT_LIKE: |
| 1267 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1268 | // If we already have a macro, that means that we've hit the end |
| 1269 | // of the definition of the macro we were looking for. We're |
| 1270 | // done. |
| 1271 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1272 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1274 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1275 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1276 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1277 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1278 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1279 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1280 | bool isUsed = Record[2]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1281 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1282 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1283 | MI->setIsUsed(isUsed); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1284 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1286 | bool IsPublic = Record[3]; |
| 1287 | unsigned NextIndex = 4; |
| 1288 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1289 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1290 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1291 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1292 | bool isC99VarArgs = Record[NextIndex++]; |
| 1293 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1294 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1295 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1296 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1297 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1298 | |
| 1299 | // Install function-like macro info. |
| 1300 | MI->setIsFunctionLike(); |
| 1301 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1302 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1303 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1304 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | // Finally, install the macro. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1308 | PP.setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1309 | |
| 1310 | // Remember that we saw this macro last so that we add the tokens that |
| 1311 | // form its body to it. |
| 1312 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1313 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1314 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1315 | Record[NextIndex]) { |
| 1316 | // We have a macro definition. Register the association |
| 1317 | PreprocessedEntityID |
| 1318 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1319 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1320 | PPRec.RegisterMacroDefinition(Macro, |
| 1321 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1322 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1323 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1324 | ++NumMacrosRead; |
| 1325 | break; |
| 1326 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1328 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1329 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1330 | // erroneous, just pretend we didn't see this. |
| 1331 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1332 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1333 | Token Tok; |
| 1334 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1335 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1336 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1337 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1338 | Tok.setIdentifierInfo(II); |
| 1339 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1340 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1341 | Macro->AddTokenToBody(Tok); |
| 1342 | break; |
| 1343 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1344 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1345 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1346 | |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1347 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1350 | PreprocessedEntityID |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1351 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) const { |
| 1352 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1353 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1354 | assert(I != M.PreprocessedEntityRemap.end() |
| 1355 | && "Invalid index into preprocessed entity index remap"); |
| 1356 | |
| 1357 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1360 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1361 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1362 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1363 | |
| 1364 | HeaderFileInfoTrait::internal_key_type |
| 1365 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1366 | |
| 1367 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1368 | if (strcmp(a, b) == 0) |
| 1369 | return true; |
| 1370 | |
| 1371 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1372 | return false; |
| 1373 | |
| 1374 | // The file names match, but the path names don't. stat() the files to |
| 1375 | // see if they are the same. |
| 1376 | struct stat StatBufA, StatBufB; |
| 1377 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1378 | return false; |
| 1379 | |
| 1380 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1381 | } |
| 1382 | |
| 1383 | std::pair<unsigned, unsigned> |
| 1384 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1385 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1386 | unsigned DataLen = (unsigned) *d++; |
| 1387 | return std::make_pair(KeyLen + 1, DataLen); |
| 1388 | } |
| 1389 | |
| 1390 | HeaderFileInfoTrait::data_type |
| 1391 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1392 | unsigned DataLen) { |
| 1393 | const unsigned char *End = d + DataLen; |
| 1394 | using namespace clang::io; |
| 1395 | HeaderFileInfo HFI; |
| 1396 | unsigned Flags = *d++; |
| 1397 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1398 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1399 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1400 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1401 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1402 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1403 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1404 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1405 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1406 | // The framework offset is 1 greater than the actual offset, |
| 1407 | // since 0 is used as an indicator for "no framework name". |
| 1408 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1409 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1410 | } |
| 1411 | |
| 1412 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1413 | (void)End; |
| 1414 | |
| 1415 | // This HeaderFileInfo was externally loaded. |
| 1416 | HFI.External = true; |
| 1417 | return HFI; |
| 1418 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1419 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1420 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1421 | uint64_t LocalOffset) { |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1422 | // Note that this identifier has a macro definition. |
| 1423 | II->setHasMacroDefinition(true); |
| 1424 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1425 | // Adjust the offset to a global offset. |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1426 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1429 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1430 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1431 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1432 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1433 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1434 | // If there was no preprocessor block, skip this file. |
| 1435 | if (!MacroCursor.getBitStreamReader()) |
| 1436 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1437 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1438 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1439 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1440 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1441 | RecordData Record; |
| 1442 | while (true) { |
| 1443 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1444 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1445 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1446 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1447 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1448 | // No known subblocks, always skip them. |
| 1449 | Cursor.ReadSubBlockID(); |
| 1450 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1451 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1452 | return; |
| 1453 | } |
| 1454 | continue; |
| 1455 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1456 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1457 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1458 | Cursor.ReadAbbrevRecord(); |
| 1459 | continue; |
| 1460 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1461 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1462 | // Read a record. |
| 1463 | const char *BlobStart; |
| 1464 | unsigned BlobLen; |
| 1465 | Record.clear(); |
| 1466 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1467 | default: // Default behavior: ignore. |
| 1468 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1469 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1470 | case PP_MACRO_OBJECT_LIKE: |
| 1471 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1472 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1473 | break; |
| 1474 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1475 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1476 | // Ignore tokens. |
| 1477 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1478 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1479 | } |
| 1480 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1481 | |
| 1482 | // Drain the unread macro-record offsets map. |
| 1483 | while (!UnreadMacroRecordOffsets.empty()) |
| 1484 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1485 | } |
| 1486 | |
| 1487 | void ASTReader::LoadMacroDefinition( |
| 1488 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1489 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1490 | uint64_t Offset = Pos->second; |
| 1491 | UnreadMacroRecordOffsets.erase(Pos); |
| 1492 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1493 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1494 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1498 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1499 | = UnreadMacroRecordOffsets.find(II); |
| 1500 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1503 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1504 | std::string Filename = filenameStrRef; |
| 1505 | MaybeAddSystemRootToFilename(Filename); |
| 1506 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1507 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1508 | OriginalDir != CurrentDir) { |
| 1509 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1510 | OriginalDir, |
| 1511 | CurrentDir); |
| 1512 | if (!resolved.empty()) |
| 1513 | File = FileMgr.getFile(resolved); |
| 1514 | } |
| 1515 | |
| 1516 | return File; |
| 1517 | } |
| 1518 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1519 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1520 | /// not an absolute path, add the system root to the beginning of the file |
| 1521 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1522 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1523 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1524 | if (!RelocatablePCH) |
| 1525 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1526 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1527 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1528 | return; |
| 1529 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1530 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1531 | // If no system root was given, default to '/' |
| 1532 | Filename.insert(Filename.begin(), '/'); |
| 1533 | return; |
| 1534 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1535 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1536 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1537 | if (isysroot[Length - 1] != '/') |
| 1538 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1539 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1540 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1543 | ASTReader::ASTReadResult |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1544 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1545 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1546 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1547 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1548 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1549 | return Failure; |
| 1550 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1551 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1552 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1553 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1554 | while (!Stream.AtEndOfStream()) { |
| 1555 | unsigned Code = Stream.ReadCode(); |
| 1556 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1557 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1558 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1559 | return Failure; |
| 1560 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1561 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1562 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1566 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1567 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1568 | // We lazily load the decls block, but we want to set up the |
| 1569 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1570 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1571 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1572 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1573 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1574 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1575 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1576 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1577 | return Failure; |
| 1578 | } |
| 1579 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1580 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1581 | case DECL_UPDATES_BLOCK_ID: |
| 1582 | if (Stream.SkipBlock()) { |
| 1583 | Error("malformed block record in AST file"); |
| 1584 | return Failure; |
| 1585 | } |
| 1586 | break; |
| 1587 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1588 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1589 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1590 | if (!PP.getExternalSource()) |
| 1591 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1592 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1593 | if (Stream.SkipBlock() || |
| 1594 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1595 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1596 | return Failure; |
| 1597 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1598 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1599 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1600 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1601 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1602 | F.PreprocessorDetailCursor = Stream; |
| 1603 | if (Stream.SkipBlock() || |
| 1604 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1605 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1606 | Error("malformed preprocessor detail record in AST file"); |
| 1607 | return Failure; |
| 1608 | } |
| 1609 | F.PreprocessorDetailStartOffset |
| 1610 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1611 | |
| 1612 | if (!PP.getPreprocessingRecord()) |
| 1613 | PP.createPreprocessingRecord(true); |
| 1614 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1615 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1616 | break; |
| 1617 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1618 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1619 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1620 | case Success: |
| 1621 | break; |
| 1622 | |
| 1623 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1624 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1625 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1626 | |
| 1627 | case IgnorePCH: |
| 1628 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1629 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1630 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1631 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1632 | continue; |
| 1633 | } |
| 1634 | |
| 1635 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1636 | Stream.ReadAbbrevRecord(); |
| 1637 | continue; |
| 1638 | } |
| 1639 | |
| 1640 | // Read and process a record. |
| 1641 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1642 | const char *BlobStart = 0; |
| 1643 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1644 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1645 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1646 | default: // Default behavior: ignore. |
| 1647 | break; |
| 1648 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1649 | case METADATA: { |
| 1650 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1651 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1652 | : diag::warn_pch_version_too_new); |
| 1653 | return IgnorePCH; |
| 1654 | } |
| 1655 | |
| 1656 | RelocatablePCH = Record[4]; |
| 1657 | if (Listener) { |
| 1658 | std::string TargetTriple(BlobStart, BlobLen); |
| 1659 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1660 | return IgnorePCH; |
| 1661 | } |
| 1662 | break; |
| 1663 | } |
| 1664 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1665 | case IMPORTS: { |
| 1666 | // Load each of the imported PCH files. |
| 1667 | unsigned Idx = 0, N = Record.size(); |
| 1668 | while (Idx < N) { |
| 1669 | // Read information about the AST file. |
| 1670 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1671 | unsigned Length = Record[Idx++]; |
| 1672 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1673 | Record.begin() + Idx + Length); |
| 1674 | Idx += Length; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1676 | // Load the AST file. |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1677 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1678 | case Failure: return Failure; |
| 1679 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1680 | case IgnorePCH: return IgnorePCH; |
| 1681 | case Success: break; |
| 1682 | } |
| 1683 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1684 | break; |
| 1685 | } |
| 1686 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1687 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1688 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1689 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1690 | return Failure; |
| 1691 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1692 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1693 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1694 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1695 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1696 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1697 | if (F.LocalNumTypes > 0) { |
| 1698 | // Introduce the global -> local mapping for types within this module. |
| 1699 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1700 | |
| 1701 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1702 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 1703 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1704 | |
| 1705 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1706 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1707 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1710 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1711 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1712 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1713 | return Failure; |
| 1714 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1715 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1716 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1717 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1718 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1719 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1720 | if (F.LocalNumDecls > 0) { |
| 1721 | // Introduce the global -> local mapping for declarations within this |
| 1722 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1723 | GlobalDeclMap.insert( |
| 1724 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1725 | |
| 1726 | // Introduce the local -> global mapping for declarations within this |
| 1727 | // module. |
| 1728 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 1729 | F.BaseDeclID - LocalBaseDeclID)); |
| 1730 | |
| 1731 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1732 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1733 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1736 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1737 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1738 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1739 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1740 | Info.NumLexicalDecls |
| 1741 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1742 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1743 | break; |
| 1744 | } |
| 1745 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1746 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1747 | unsigned Idx = 0; |
| 1748 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1749 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1750 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1751 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1752 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1753 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1754 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1755 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1756 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1757 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1758 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1759 | break; |
| 1760 | } |
| 1761 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1762 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1763 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1764 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 1765 | DeclID First = ReadDeclID(F, Record, i); |
| 1766 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1767 | FirstLatestDeclIDs[First] = Latest; |
| 1768 | } |
| 1769 | break; |
| 1770 | } |
| 1771 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1772 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1773 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1774 | return IgnorePCH; |
| 1775 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1776 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1777 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1778 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1779 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1780 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1781 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1782 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1783 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1784 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1785 | |
| 1786 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1787 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1788 | break; |
| 1789 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1790 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1791 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1792 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1793 | return Failure; |
| 1794 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1795 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1796 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1797 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1798 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 1799 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1800 | if (F.LocalNumIdentifiers > 0) { |
| 1801 | // Introduce the global -> local mapping for identifiers within this |
| 1802 | // module. |
| 1803 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 1804 | &F)); |
| 1805 | |
| 1806 | // Introduce the local -> global mapping for identifiers within this |
| 1807 | // module. |
| 1808 | F.IdentifierRemap.insert( |
| 1809 | std::make_pair(LocalBaseIdentifierID, |
| 1810 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 1811 | |
| 1812 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 1813 | + F.LocalNumIdentifiers); |
| 1814 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1815 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1818 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1819 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1820 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1821 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1822 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1823 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1824 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1825 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1826 | break; |
| 1827 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1828 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1829 | TotalNumStatements += Record[0]; |
| 1830 | TotalNumMacros += Record[1]; |
| 1831 | TotalLexicalDeclContexts += Record[2]; |
| 1832 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1833 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1834 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1835 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1836 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1837 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1838 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1839 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1840 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1841 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1842 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1843 | break; |
| 1844 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1845 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 1846 | if (Record.size() % 4 != 0) { |
| 1847 | Error("invalid weak identifiers record"); |
| 1848 | return Failure; |
| 1849 | } |
| 1850 | |
| 1851 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 1852 | // files. This isn't the way to do it :) |
| 1853 | WeakUndeclaredIdentifiers.clear(); |
| 1854 | |
| 1855 | // Translate the weak, undeclared identifiers into global IDs. |
| 1856 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 1857 | WeakUndeclaredIdentifiers.push_back( |
| 1858 | getGlobalIdentifierID(F, Record[I++])); |
| 1859 | WeakUndeclaredIdentifiers.push_back( |
| 1860 | getGlobalIdentifierID(F, Record[I++])); |
| 1861 | WeakUndeclaredIdentifiers.push_back( |
| 1862 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 1863 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 1864 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1865 | break; |
| 1866 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1867 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1868 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1869 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1870 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1871 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1872 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1873 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1874 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1875 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1876 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1878 | if (F.LocalNumSelectors > 0) { |
| 1879 | // Introduce the global -> local mapping for selectors within this |
| 1880 | // module. |
| 1881 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 1882 | |
| 1883 | // Introduce the local -> global mapping for selectors within this |
| 1884 | // module. |
| 1885 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 1886 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1887 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1888 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 1889 | } |
| 1890 | break; |
| 1891 | } |
| 1892 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1893 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1894 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1895 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1896 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1897 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1898 | F.SelectorLookupTableData + Record[0], |
| 1899 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1900 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 1901 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1902 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1903 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 1904 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 1905 | if (!Record.empty()) { |
| 1906 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 1907 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 1908 | Record[Idx++])); |
| 1909 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 1910 | getRawEncoding()); |
| 1911 | } |
| 1912 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1913 | break; |
| 1914 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1915 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1916 | if (!Record.empty() && Listener) |
| 1917 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1918 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1920 | case SOURCE_LOCATION_OFFSETS: { |
| 1921 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1922 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1923 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1924 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1925 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 1926 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1927 | // Make our entry in the range map. BaseID is negative and growing, so |
| 1928 | // we invert it. Because we invert it, though, we need the other end of |
| 1929 | // the range. |
| 1930 | unsigned RangeStart = |
| 1931 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 1932 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 1933 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 1934 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 1935 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 1936 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 1937 | GlobalSLocOffsetMap.insert( |
| 1938 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 1939 | - SLocSpaceSize,&F)); |
| 1940 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1941 | // Initialize the remapping table. |
| 1942 | // Invalid stays invalid. |
| 1943 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 1944 | // This module. Base was 2 when being compiled. |
| 1945 | F.SLocRemap.insert(std::make_pair(2U, |
| 1946 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1947 | |
| 1948 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1949 | break; |
| 1950 | } |
| 1951 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 1952 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1953 | // Additional remapping information. |
| 1954 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 1955 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 1956 | |
| 1957 | // Continuous range maps we may be updating in our module. |
| 1958 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1959 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 1960 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1961 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1962 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 1963 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1964 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1965 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1966 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 1967 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1968 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1969 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1970 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 1971 | Data += Len; |
Jonathan D. Turner | 48d2c3f | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 1972 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1973 | if (!OM) { |
| 1974 | Error("SourceLocation remap refers to unknown module"); |
| 1975 | return Failure; |
| 1976 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 1977 | |
| 1978 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 1979 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 1980 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 1981 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 1982 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1983 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 1984 | |
| 1985 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 1986 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 1987 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1988 | IdentifierRemap.insert( |
| 1989 | std::make_pair(IdentifierIDOffset, |
| 1990 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1991 | PreprocessedEntityRemap.insert( |
| 1992 | std::make_pair(PreprocessedEntityIDOffset, |
| 1993 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 1994 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 1995 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1996 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 1997 | OM->BaseDeclID - DeclIDOffset)); |
| 1998 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1999 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2000 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2001 | } |
| 2002 | break; |
| 2003 | } |
| 2004 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2005 | case SOURCE_MANAGER_LINE_TABLE: |
| 2006 | if (ParseLineTable(F, Record)) |
| 2007 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2008 | break; |
| 2009 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2010 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2011 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2012 | F.LocalNumSLocFileEntries = Record[0]; |
| 2013 | break; |
| 2014 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2015 | case SOURCE_LOCATION_PRELOADS: { |
| 2016 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2017 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2018 | if (!F.PreloadSLocEntries.empty()) { |
| 2019 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2020 | return Failure; |
| 2021 | } |
| 2022 | |
| 2023 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2024 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2025 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2026 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2027 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2028 | if (!DisableStatCache) { |
| 2029 | ASTStatCache *MyStatCache = |
| 2030 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2031 | (const unsigned char *)BlobStart, |
| 2032 | NumStatHits, NumStatMisses); |
| 2033 | FileMgr.addStatCache(MyStatCache); |
| 2034 | F.StatCache = MyStatCache; |
| 2035 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2036 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2037 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2038 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2039 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2040 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2041 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2042 | break; |
| 2043 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2044 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2045 | if (Record.size() % 3 != 0) { |
| 2046 | Error("Invalid VTABLE_USES record"); |
| 2047 | return Failure; |
| 2048 | } |
| 2049 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2050 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2051 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2052 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2053 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2054 | |
| 2055 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2056 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2057 | VTableUses.push_back( |
| 2058 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2059 | VTableUses.push_back(Record[Idx++]); |
| 2060 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2061 | break; |
| 2062 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2063 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2064 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2065 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2066 | break; |
| 2067 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2068 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2069 | if (PendingInstantiations.size() % 2 != 0) { |
| 2070 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2071 | return Failure; |
| 2072 | } |
| 2073 | |
| 2074 | // Later lists of pending instantiations overwrite earlier ones. |
| 2075 | // FIXME: This is most certainly wrong for modules. |
| 2076 | PendingInstantiations.clear(); |
| 2077 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2078 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2079 | PendingInstantiations.push_back( |
| 2080 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2081 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2082 | break; |
| 2083 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2084 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2085 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2086 | // FIXME: Modules will have some trouble with this. |
| 2087 | SemaDeclRefs.clear(); |
| 2088 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2089 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2090 | break; |
| 2091 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2092 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2093 | // 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] | 2094 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2095 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2096 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2097 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2098 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2099 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2100 | case ORIGINAL_FILE_ID: |
| 2101 | OriginalFileID = FileID::get(Record[0]); |
| 2102 | break; |
| 2103 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2104 | case ORIGINAL_PCH_DIR: |
| 2105 | // The primary AST will be the last to get here, so it will be the one |
| 2106 | // that's used. |
| 2107 | OriginalDir.assign(BlobStart, BlobLen); |
| 2108 | break; |
| 2109 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2110 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2111 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2112 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2113 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2114 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2115 | return IgnorePCH; |
| 2116 | } |
| 2117 | break; |
| 2118 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2119 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2120 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2121 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2122 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2123 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2124 | |
| 2125 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2126 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2127 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2128 | if (!PP.getPreprocessingRecord()) |
| 2129 | PP.createPreprocessingRecord(true); |
| 2130 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2131 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2132 | StartingID |
| 2133 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2134 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2135 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2136 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2137 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2138 | // Introduce the global -> local mapping for preprocessed entities in |
| 2139 | // this module. |
| 2140 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2141 | |
| 2142 | // Introduce the local -> global mapping for preprocessed entities in |
| 2143 | // this module. |
| 2144 | F.PreprocessedEntityRemap.insert( |
| 2145 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2146 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2147 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2148 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2149 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2152 | case DECL_UPDATE_OFFSETS: { |
| 2153 | if (Record.size() % 2 != 0) { |
| 2154 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2155 | return Failure; |
| 2156 | } |
| 2157 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2158 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2159 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2160 | break; |
| 2161 | } |
| 2162 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2163 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2164 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2165 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2166 | return Failure; |
| 2167 | } |
| 2168 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2169 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2170 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2171 | break; |
| 2172 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2173 | |
| 2174 | case OBJC_CHAINED_CATEGORIES: { |
| 2175 | if (Record.size() % 3 != 0) { |
| 2176 | Error("invalid OBJC_CHAINED_CATEGORIES block in AST file"); |
| 2177 | return Failure; |
| 2178 | } |
| 2179 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) { |
| 2180 | serialization::GlobalDeclID GlobID = getGlobalDeclID(F, Record[I]); |
| 2181 | F.ChainedObjCCategories[GlobID] = std::make_pair(Record[I+1], |
| 2182 | Record[I+2]); |
| 2183 | ObjCChainedCategoriesInterfaces.insert(GlobID); |
| 2184 | } |
| 2185 | break; |
| 2186 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2187 | |
| 2188 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2189 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2190 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2191 | return Failure; |
| 2192 | } |
| 2193 | |
| 2194 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2195 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2196 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2197 | break; |
| 2198 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2199 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2200 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2201 | if (Record.size() % 2 != 0) { |
| 2202 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2203 | return Failure; |
| 2204 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2205 | |
| 2206 | if (F.PragmaDiagMappings.empty()) |
| 2207 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2208 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2209 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2210 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2211 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2212 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2213 | case CUDA_SPECIAL_DECL_REFS: |
| 2214 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2215 | // FIXME: Modules will have trouble with this. |
| 2216 | CUDASpecialDeclRefs.clear(); |
| 2217 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2218 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2219 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2220 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2221 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2222 | F.HeaderFileInfoTableData = BlobStart; |
| 2223 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2224 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2225 | if (Record[0]) { |
| 2226 | F.HeaderFileInfoTable |
| 2227 | = HeaderFileInfoLookupTable::Create( |
| 2228 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2229 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2230 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2231 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2232 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2233 | |
| 2234 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2235 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2236 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2237 | } |
| 2238 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2239 | } |
| 2240 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2241 | case FP_PRAGMA_OPTIONS: |
| 2242 | // Later tables overwrite earlier ones. |
| 2243 | FPPragmaOptions.swap(Record); |
| 2244 | break; |
| 2245 | |
| 2246 | case OPENCL_EXTENSIONS: |
| 2247 | // Later tables overwrite earlier ones. |
| 2248 | OpenCLExtensions.swap(Record); |
| 2249 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2250 | |
| 2251 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2252 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2253 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2254 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2255 | |
| 2256 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2257 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2258 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2259 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2260 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2261 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2262 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2263 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2264 | } |
| 2265 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2266 | ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) { |
| 2267 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2268 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2269 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2270 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2271 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2272 | if (Code == llvm::bitc::END_BLOCK || |
| 2273 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2274 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2275 | Error("incorrectly-formatted source location entry in AST file"); |
| 2276 | return Failure; |
| 2277 | } |
| 2278 | |
| 2279 | RecordData Record; |
| 2280 | const char *BlobStart; |
| 2281 | unsigned BlobLen; |
| 2282 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2283 | default: |
| 2284 | Error("incorrectly-formatted source location entry in AST file"); |
| 2285 | return Failure; |
| 2286 | |
| 2287 | case SM_SLOC_FILE_ENTRY: { |
| 2288 | StringRef Filename(BlobStart, BlobLen); |
| 2289 | const FileEntry *File = getFileEntry(Filename); |
| 2290 | |
| 2291 | if (File == 0) { |
| 2292 | std::string ErrorStr = "could not find file '"; |
| 2293 | ErrorStr += Filename; |
| 2294 | ErrorStr += "' referenced by AST file"; |
| 2295 | Error(ErrorStr.c_str()); |
| 2296 | return IgnorePCH; |
| 2297 | } |
| 2298 | |
| 2299 | if (Record.size() < 6) { |
| 2300 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2301 | return Failure; |
| 2302 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2303 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2304 | // The stat info from the FileEntry came from the cached stat |
| 2305 | // info of the PCH, so we cannot trust it. |
| 2306 | struct stat StatBuf; |
| 2307 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2308 | StatBuf.st_size = File->getSize(); |
| 2309 | StatBuf.st_mtime = File->getModificationTime(); |
| 2310 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2311 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2312 | if (((off_t)Record[4] != StatBuf.st_size |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2313 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2314 | // In our regression testing, the Windows file system seems to |
| 2315 | // have inconsistent modification times that sometimes |
| 2316 | // erroneously trigger this error-handling path. |
| 2317 | || (time_t)Record[5] != StatBuf.st_mtime |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2318 | #endif |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2319 | )) { |
| 2320 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2321 | return IgnorePCH; |
| 2322 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2323 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2324 | break; |
| 2325 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | return Success; |
| 2330 | } |
| 2331 | |
Douglas Gregor | 46c03c3 | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2332 | namespace { |
| 2333 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 2334 | class IdentifierLookupVisitor { |
| 2335 | StringRef Name; |
| 2336 | IdentifierInfo *Found; |
| 2337 | public: |
| 2338 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
| 2339 | |
| 2340 | static bool visit(Module &M, void *UserData) { |
| 2341 | IdentifierLookupVisitor *This |
| 2342 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 2343 | |
| 2344 | ASTIdentifierLookupTable *IdTable |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 2345 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
Douglas Gregor | 46c03c3 | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2346 | if (!IdTable) |
| 2347 | return false; |
| 2348 | |
| 2349 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 2350 | This->Name.size()); |
| 2351 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2352 | if (Pos == IdTable->end()) |
| 2353 | return false; |
| 2354 | |
| 2355 | // Dereferencing the iterator has the effect of building the |
| 2356 | // IdentifierInfo node and populating it with the various |
| 2357 | // declarations it needs. |
| 2358 | This->Found = *Pos; |
| 2359 | return true; |
| 2360 | } |
| 2361 | |
| 2362 | // \brief Retrieve the identifier info found within the module |
| 2363 | // files. |
| 2364 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 2365 | }; |
| 2366 | } |
| 2367 | |
| 2368 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2369 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2370 | ModuleKind Type) { |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2371 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2372 | case Failure: return Failure; |
| 2373 | case IgnorePCH: return IgnorePCH; |
| 2374 | case Success: break; |
| 2375 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2376 | |
| 2377 | // 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] | 2378 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2379 | // Check the predefines buffers. |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 2380 | if (!DisableValidation && Type != MK_Module && Type != MK_Preamble && |
| 2381 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2382 | // if DisableValidation is true, defines that were set on command-line |
| 2383 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2384 | CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2385 | return IgnorePCH; |
| 2386 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2387 | // Initialization of keywords and pragmas occurs before the |
| 2388 | // AST file is read, so there may be some identifiers that were |
| 2389 | // loaded into the IdentifierTable before we intercepted the |
| 2390 | // creation of identifiers. Iterate through the list of known |
| 2391 | // identifiers and determine whether we have to establish |
| 2392 | // preprocessor definitions or top-level identifier declaration |
| 2393 | // chains for those identifiers. |
| 2394 | // |
| 2395 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2396 | // since de-serializing declarations or macro definitions can add |
| 2397 | // new entries into the identifier table, invalidating the |
| 2398 | // iterators. |
| 2399 | // |
| 2400 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2401 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2402 | // AST file(s) if it is uttered in the source. This could save us some |
| 2403 | // module load time. |
| 2404 | SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2405 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2406 | IdEnd = PP.getIdentifierTable().end(); |
| 2407 | Id != IdEnd; ++Id) |
| 2408 | Identifiers.push_back(Id->second); |
| 2409 | |
| 2410 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2411 | IdentifierLookupVisitor Visitor(Identifiers[I]->getName()); |
| 2412 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2415 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2416 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2417 | if (DeserializationListener) |
| 2418 | DeserializationListener->ReaderInitialized(this); |
| 2419 | |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2420 | // If this AST file is a precompiled preamble, then set the preamble file ID |
| 2421 | // of the source manager to the file source file from which the preamble was |
| 2422 | // built. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2423 | if (Type == MK_Preamble) { |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2424 | if (!OriginalFileID.isInvalid()) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2425 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2426 | + OriginalFileID.getOpaqueValue() - 1); |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2427 | SourceMgr.setPreambleFileID(OriginalFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2428 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2431 | return Success; |
| 2432 | } |
| 2433 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2434 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2435 | ModuleKind Type, |
| 2436 | Module *ImportedBy) { |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2437 | Module *M; |
| 2438 | bool NewModule; |
| 2439 | std::string ErrorStr; |
| 2440 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2441 | ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2442 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2443 | if (!M) { |
| 2444 | // We couldn't load the module. |
| 2445 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2446 | + ErrorStr; |
| 2447 | Error(Msg); |
| 2448 | return Failure; |
| 2449 | } |
| 2450 | |
| 2451 | if (!NewModule) { |
| 2452 | // We've already loaded this module. |
| 2453 | return Success; |
| 2454 | } |
| 2455 | |
| 2456 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2457 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2458 | if (FileName != "-") { |
| 2459 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2460 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2461 | } |
| 2462 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2463 | Module &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2464 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2465 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2466 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2467 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2468 | // Sniff for the signature. |
| 2469 | if (Stream.Read(8) != 'C' || |
| 2470 | Stream.Read(8) != 'P' || |
| 2471 | Stream.Read(8) != 'C' || |
| 2472 | Stream.Read(8) != 'H') { |
| 2473 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2474 | return Failure; |
| 2475 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2476 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2477 | while (!Stream.AtEndOfStream()) { |
| 2478 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2479 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2480 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2481 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2482 | return Failure; |
| 2483 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2484 | |
| 2485 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2486 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2487 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2488 | switch (BlockID) { |
| 2489 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2490 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2491 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2492 | return Failure; |
| 2493 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2494 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2495 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2496 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2497 | case Success: |
| 2498 | break; |
| 2499 | |
| 2500 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2501 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2502 | |
| 2503 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2504 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2505 | // AST block, skipping subblocks, to see if there are other |
| 2506 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2507 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2508 | // FIXME: We can't clear loaded slocentries anymore. |
| 2509 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2510 | |
| 2511 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2512 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2513 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2514 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2515 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2516 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2517 | break; |
| 2518 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2519 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2520 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2521 | return Failure; |
| 2522 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2523 | break; |
| 2524 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2525 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2526 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2527 | // 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] | 2528 | // bits of all files we've seen. |
| 2529 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2530 | TotalModulesSizeInBits += F.SizeInBits; |
| 2531 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2532 | |
| 2533 | // Make sure that the files this module was built against are still available. |
| 2534 | if (!DisableValidation) { |
| 2535 | switch(validateFileEntries(*M)) { |
| 2536 | case Failure: return Failure; |
| 2537 | case IgnorePCH: return IgnorePCH; |
| 2538 | case Success: break; |
| 2539 | } |
| 2540 | } |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2541 | |
| 2542 | // Preload SLocEntries. |
| 2543 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2544 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Argyrios Kyrtzidis | ac1ffcc | 2011-09-19 20:39:54 +0000 | [diff] [blame] | 2545 | // Load it through the SourceManager and don't call ReadSLocEntryRecord() |
| 2546 | // directly because the entry may have already been loaded in which case |
| 2547 | // calling ReadSLocEntryRecord() directly would trigger an assertion in |
| 2548 | // SourceManager. |
| 2549 | SourceMgr.getLoadedSLocEntryByID(Index); |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2550 | } |
| 2551 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2552 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2553 | return Success; |
| 2554 | } |
| 2555 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2556 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2557 | // If there's a listener, notify them that we "read" the translation unit. |
| 2558 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2559 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2560 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2561 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2562 | // Make sure we load the declaration update records for the translation unit, |
| 2563 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2564 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2565 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2566 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2567 | // FIXME: Find a better way to deal with collisions between these |
| 2568 | // built-in types. Right now, we just ignore the problem. |
| 2569 | |
| 2570 | // Load the special types. |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2571 | if (SpecialTypes.size() > NumSpecialTypeIDs) { |
| 2572 | if (Context.getBuiltinVaListType().isNull()) { |
| 2573 | Context.setBuiltinVaListType( |
| 2574 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2577 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2578 | if (Context.ObjCProtoType.isNull()) |
| 2579 | Context.ObjCProtoType = GetType(Proto); |
| 2580 | } |
| 2581 | |
| 2582 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2583 | if (!Context.CFConstantStringTypeDecl) |
| 2584 | Context.setCFConstantStringType(GetType(String)); |
| 2585 | } |
| 2586 | |
| 2587 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2588 | QualType FileType = GetType(File); |
| 2589 | if (FileType.isNull()) { |
| 2590 | Error("FILE type is NULL"); |
| 2591 | return; |
| 2592 | } |
| 2593 | |
| 2594 | if (!Context.FILEDecl) { |
| 2595 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2596 | Context.setFILEDecl(Typedef->getDecl()); |
| 2597 | else { |
| 2598 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2599 | if (!Tag) { |
| 2600 | Error("Invalid FILE type in AST file"); |
| 2601 | return; |
| 2602 | } |
| 2603 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2604 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2605 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2606 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2607 | |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2608 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 2609 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2610 | if (Jmp_bufType.isNull()) { |
| 2611 | Error("jmp_buf type is NULL"); |
| 2612 | return; |
| 2613 | } |
| 2614 | |
| 2615 | if (!Context.jmp_bufDecl) { |
| 2616 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2617 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2618 | else { |
| 2619 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2620 | if (!Tag) { |
| 2621 | Error("Invalid jmp_buf type in AST file"); |
| 2622 | return; |
| 2623 | } |
| 2624 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2625 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2626 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2627 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2628 | |
| 2629 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 2630 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2631 | if (Sigjmp_bufType.isNull()) { |
| 2632 | Error("sigjmp_buf type is NULL"); |
| 2633 | return; |
| 2634 | } |
| 2635 | |
| 2636 | if (!Context.sigjmp_bufDecl) { |
| 2637 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2638 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2639 | else { |
| 2640 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2641 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2642 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2643 | } |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | if (unsigned ObjCIdRedef |
| 2648 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2649 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2650 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2651 | } |
| 2652 | |
| 2653 | if (unsigned ObjCClassRedef |
| 2654 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2655 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2656 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2657 | } |
| 2658 | |
| 2659 | if (unsigned ObjCSelRedef |
| 2660 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2661 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2662 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2663 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2666 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2667 | |
| 2668 | // If there were any CUDA special declarations, deserialize them. |
| 2669 | if (!CUDASpecialDeclRefs.empty()) { |
| 2670 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2671 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2672 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2673 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2676 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2677 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2678 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2679 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2680 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 2681 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2682 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2683 | std::string ErrStr; |
| 2684 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2685 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2686 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2687 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2688 | return std::string(); |
| 2689 | } |
| 2690 | |
| 2691 | // Initialize the stream |
| 2692 | llvm::BitstreamReader StreamFile; |
| 2693 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2694 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2695 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2696 | Stream.init(StreamFile); |
| 2697 | |
| 2698 | // Sniff for the signature. |
| 2699 | if (Stream.Read(8) != 'C' || |
| 2700 | Stream.Read(8) != 'P' || |
| 2701 | Stream.Read(8) != 'C' || |
| 2702 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2703 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2704 | return std::string(); |
| 2705 | } |
| 2706 | |
| 2707 | RecordData Record; |
| 2708 | while (!Stream.AtEndOfStream()) { |
| 2709 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2710 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2711 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2712 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2713 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2714 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2715 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2716 | case AST_BLOCK_ID: |
| 2717 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2718 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2719 | return std::string(); |
| 2720 | } |
| 2721 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2722 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2723 | default: |
| 2724 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2725 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2726 | return std::string(); |
| 2727 | } |
| 2728 | break; |
| 2729 | } |
| 2730 | continue; |
| 2731 | } |
| 2732 | |
| 2733 | if (Code == llvm::bitc::END_BLOCK) { |
| 2734 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2735 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2736 | return std::string(); |
| 2737 | } |
| 2738 | continue; |
| 2739 | } |
| 2740 | |
| 2741 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2742 | Stream.ReadAbbrevRecord(); |
| 2743 | continue; |
| 2744 | } |
| 2745 | |
| 2746 | Record.clear(); |
| 2747 | const char *BlobStart = 0; |
| 2748 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2749 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2750 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2751 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2752 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2753 | |
| 2754 | return std::string(); |
| 2755 | } |
| 2756 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2757 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2758 | /// structure. |
| 2759 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2760 | /// This routine parses the language options from the AST file and then gives |
| 2761 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2762 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2763 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2764 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2765 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2766 | if (Listener) { |
| 2767 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2768 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 2769 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 2770 | LangOpts.Name = Record[Idx++]; |
| 2771 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 2772 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 2773 | #include "clang/Basic/LangOptions.def" |
| 2774 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2775 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2776 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2777 | |
| 2778 | return false; |
| 2779 | } |
| 2780 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame^] | 2781 | std::pair<Module *, unsigned> |
| 2782 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2783 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame^] | 2784 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2785 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 2786 | "Corrupted global preprocessed entity map"); |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame^] | 2787 | Module *M = I->second; |
| 2788 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 2789 | return std::make_pair(M, LocalIndex); |
| 2790 | } |
| 2791 | |
| 2792 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 2793 | PreprocessedEntityID PPID = Index+1; |
| 2794 | std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 2795 | Module &M = *PPInfo.first; |
| 2796 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2797 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2798 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2799 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2800 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2801 | |
| 2802 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 2803 | switch (Code) { |
| 2804 | case llvm::bitc::END_BLOCK: |
| 2805 | return 0; |
| 2806 | |
| 2807 | case llvm::bitc::ENTER_SUBBLOCK: |
| 2808 | Error("unexpected subblock record in preprocessor detail block"); |
| 2809 | return 0; |
| 2810 | |
| 2811 | case llvm::bitc::DEFINE_ABBREV: |
| 2812 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 2813 | return 0; |
| 2814 | |
| 2815 | default: |
| 2816 | break; |
| 2817 | } |
| 2818 | |
| 2819 | if (!PP.getPreprocessingRecord()) { |
| 2820 | Error("no preprocessing record"); |
| 2821 | return 0; |
| 2822 | } |
| 2823 | |
| 2824 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2825 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 2826 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2827 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 2828 | const char *BlobStart = 0; |
| 2829 | unsigned BlobLen = 0; |
| 2830 | RecordData Record; |
| 2831 | PreprocessorDetailRecordTypes RecType = |
| 2832 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 2833 | Code, Record, BlobStart, BlobLen); |
| 2834 | switch (RecType) { |
| 2835 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2836 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2837 | IdentifierInfo *Name = 0; |
| 2838 | MacroDefinition *Def = 0; |
| 2839 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2840 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2841 | else { |
| 2842 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2843 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2844 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 2845 | } |
| 2846 | |
| 2847 | MacroExpansion *ME; |
| 2848 | if (isBuiltin) |
| 2849 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 2850 | else |
| 2851 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 2852 | |
| 2853 | return ME; |
| 2854 | } |
| 2855 | |
| 2856 | case PPD_MACRO_DEFINITION: { |
| 2857 | // Decode the identifier info and then check again; if the macro is |
| 2858 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2859 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2860 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2861 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2862 | |
| 2863 | if (DeserializationListener) |
| 2864 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 2865 | |
| 2866 | return MD; |
| 2867 | } |
| 2868 | |
| 2869 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2870 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2871 | const FileEntry *File |
| 2872 | = PP.getFileManager().getFile(StringRef(FullFileNameStart, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2873 | BlobLen - Record[0])); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2874 | |
| 2875 | // FIXME: Stable encoding |
| 2876 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2877 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2878 | InclusionDirective *ID |
| 2879 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2880 | StringRef(BlobStart, Record[0]), |
| 2881 | Record[1], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2882 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 2883 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 2884 | return ID; |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | Error("invalid offset in preprocessor detail block"); |
| 2889 | return 0; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2890 | } |
| 2891 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2892 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 2893 | /// preprocessed entities or the entities it contains are not the ones we are |
| 2894 | /// looking for. Find the next module that contains entities and return the ID |
| 2895 | /// of the first entry. |
| 2896 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 2897 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 2898 | ++SLocMapI; |
| 2899 | for (GlobalSLocOffsetMapType::const_iterator |
| 2900 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 2901 | Module &M = *SLocMapI->second; |
| 2902 | if (M.NumPreprocessedEntities) |
| 2903 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 2904 | } |
| 2905 | |
| 2906 | return getTotalNumPreprocessedEntities(); |
| 2907 | } |
| 2908 | |
| 2909 | namespace { |
| 2910 | |
| 2911 | template <unsigned PPEntityOffset::*PPLoc> |
| 2912 | struct PPEntityComp { |
| 2913 | const ASTReader &Reader; |
| 2914 | Module &M; |
| 2915 | |
| 2916 | PPEntityComp(const ASTReader &Reader, Module &M) : Reader(Reader), M(M) { } |
| 2917 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 2918 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 2919 | SourceLocation LHS = getLoc(L); |
| 2920 | SourceLocation RHS = getLoc(R); |
| 2921 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 2922 | } |
| 2923 | |
| 2924 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2925 | SourceLocation LHS = getLoc(L); |
| 2926 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 2927 | } |
| 2928 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 2929 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2930 | SourceLocation RHS = getLoc(R); |
| 2931 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 2932 | } |
| 2933 | |
| 2934 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 2935 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 2936 | } |
| 2937 | }; |
| 2938 | |
| 2939 | } |
| 2940 | |
| 2941 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 2942 | PreprocessedEntityID |
| 2943 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 2944 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 2945 | return getTotalNumPreprocessedEntities(); |
| 2946 | |
| 2947 | GlobalSLocOffsetMapType::const_iterator |
| 2948 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 2949 | BLoc.getOffset()); |
| 2950 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 2951 | "Corrupted global sloc offset map"); |
| 2952 | |
| 2953 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 2954 | return findNextPreprocessedEntity(SLocMapI); |
| 2955 | |
| 2956 | Module &M = *SLocMapI->second; |
| 2957 | typedef const PPEntityOffset *pp_iterator; |
| 2958 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 2959 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 2960 | |
| 2961 | size_t Count = M.NumPreprocessedEntities; |
| 2962 | size_t Half; |
| 2963 | pp_iterator First = pp_begin; |
| 2964 | pp_iterator PPI; |
| 2965 | |
| 2966 | // Do a binary search manually instead of using std::lower_bound because |
| 2967 | // The end locations of entities may be unordered (when a macro expansion |
| 2968 | // is inside another macro argument), but for this case it is not important |
| 2969 | // whether we get the first macro expansion or its containing macro. |
| 2970 | while (Count > 0) { |
| 2971 | Half = Count/2; |
| 2972 | PPI = First; |
| 2973 | std::advance(PPI, Half); |
| 2974 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 2975 | BLoc)){ |
| 2976 | First = PPI; |
| 2977 | ++First; |
| 2978 | Count = Count - Half - 1; |
| 2979 | } else |
| 2980 | Count = Half; |
| 2981 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2982 | |
| 2983 | if (PPI == pp_end) |
| 2984 | return findNextPreprocessedEntity(SLocMapI); |
| 2985 | |
| 2986 | return getGlobalPreprocessedEntityID(M, |
| 2987 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 2988 | } |
| 2989 | |
| 2990 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 2991 | PreprocessedEntityID |
| 2992 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 2993 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 2994 | return getTotalNumPreprocessedEntities(); |
| 2995 | |
| 2996 | GlobalSLocOffsetMapType::const_iterator |
| 2997 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 2998 | ELoc.getOffset()); |
| 2999 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3000 | "Corrupted global sloc offset map"); |
| 3001 | |
| 3002 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3003 | return findNextPreprocessedEntity(SLocMapI); |
| 3004 | |
| 3005 | Module &M = *SLocMapI->second; |
| 3006 | typedef const PPEntityOffset *pp_iterator; |
| 3007 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3008 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 3009 | pp_iterator PPI = |
| 3010 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 3011 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 3012 | |
| 3013 | if (PPI == pp_end) |
| 3014 | return findNextPreprocessedEntity(SLocMapI); |
| 3015 | |
| 3016 | return getGlobalPreprocessedEntityID(M, |
| 3017 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3018 | } |
| 3019 | |
| 3020 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 3021 | /// preprocessed entities that \arg Range encompasses. |
| 3022 | std::pair<unsigned, unsigned> |
| 3023 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 3024 | if (Range.isInvalid()) |
| 3025 | return std::make_pair(0,0); |
| 3026 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 3027 | |
| 3028 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 3029 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 3030 | return std::make_pair(BeginID, EndID); |
| 3031 | } |
| 3032 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame^] | 3033 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 3034 | /// entity with index \arg Index came from file \arg FID. |
| 3035 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 3036 | FileID FID) { |
| 3037 | if (FID.isInvalid()) |
| 3038 | return false; |
| 3039 | |
| 3040 | std::pair<Module *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3041 | Module &M = *PPInfo.first; |
| 3042 | unsigned LocalIndex = PPInfo.second; |
| 3043 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 3044 | |
| 3045 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 3046 | if (Loc.isInvalid()) |
| 3047 | return false; |
| 3048 | |
| 3049 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 3050 | return true; |
| 3051 | else |
| 3052 | return false; |
| 3053 | } |
| 3054 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3055 | namespace { |
| 3056 | /// \brief Visitor used to search for information about a header file. |
| 3057 | class HeaderFileInfoVisitor { |
| 3058 | ASTReader &Reader; |
| 3059 | const FileEntry *FE; |
| 3060 | |
| 3061 | llvm::Optional<HeaderFileInfo> HFI; |
| 3062 | |
| 3063 | public: |
| 3064 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3065 | : Reader(Reader), FE(FE) { } |
| 3066 | |
| 3067 | static bool visit(Module &M, void *UserData) { |
| 3068 | HeaderFileInfoVisitor *This |
| 3069 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3070 | |
| 3071 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3072 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3073 | M.HeaderFileFrameworkStrings, |
| 3074 | This->FE->getName()); |
| 3075 | |
| 3076 | HeaderFileInfoLookupTable *Table |
| 3077 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3078 | if (!Table) |
| 3079 | return false; |
| 3080 | |
| 3081 | // Look in the on-disk hash table for an entry for this file name. |
| 3082 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3083 | &Trait); |
| 3084 | if (Pos == Table->end()) |
| 3085 | return false; |
| 3086 | |
| 3087 | This->HFI = *Pos; |
| 3088 | return true; |
| 3089 | } |
| 3090 | |
| 3091 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3092 | }; |
| 3093 | } |
| 3094 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3095 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3096 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3097 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3098 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3099 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3100 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3101 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | return HeaderFileInfo(); |
| 3105 | } |
| 3106 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3107 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3108 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3109 | Module &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3110 | unsigned Idx = 0; |
| 3111 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3112 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3113 | while (1) { |
| 3114 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3115 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3116 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3117 | break; // Something is messed up but at least avoid infinite loop in |
| 3118 | // release build. |
| 3119 | } |
| 3120 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3121 | if (DiagID == (unsigned)-1) { |
| 3122 | break; // no more diag/map pairs for this location. |
| 3123 | } |
| 3124 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | eabdd67 | 2011-09-26 23:06:41 +0000 | [diff] [blame] | 3125 | // The user bit gets set by WritePragmaDiagnosticMappings. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3126 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3127 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3128 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3129 | } |
| 3130 | } |
| 3131 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3132 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3133 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3134 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3135 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3136 | Module *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3137 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3141 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3142 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3143 | /// routine actually reads the record corresponding to the type at the given |
| 3144 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3145 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3146 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3147 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3148 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3149 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3150 | // Keep track of where we are in the stream, then jump back there |
| 3151 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3152 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3153 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3154 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3155 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3156 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3157 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3158 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3159 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3160 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3161 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3162 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3163 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3164 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3165 | if (Record.size() != 2) { |
| 3166 | Error("Incorrect encoding of extended qualifier type"); |
| 3167 | return QualType(); |
| 3168 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3169 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3170 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3171 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3172 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3173 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3174 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3175 | if (Record.size() != 1) { |
| 3176 | Error("Incorrect encoding of complex type"); |
| 3177 | return QualType(); |
| 3178 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3179 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3180 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3183 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3184 | if (Record.size() != 1) { |
| 3185 | Error("Incorrect encoding of pointer type"); |
| 3186 | return QualType(); |
| 3187 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3188 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3189 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3192 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3193 | if (Record.size() != 1) { |
| 3194 | Error("Incorrect encoding of block pointer type"); |
| 3195 | return QualType(); |
| 3196 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3197 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3198 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3201 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3202 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3203 | Error("Incorrect encoding of lvalue reference type"); |
| 3204 | return QualType(); |
| 3205 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3206 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3207 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3210 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3211 | if (Record.size() != 1) { |
| 3212 | Error("Incorrect encoding of rvalue reference type"); |
| 3213 | return QualType(); |
| 3214 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3215 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3216 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3219 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3220 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3221 | Error("Incorrect encoding of member pointer type"); |
| 3222 | return QualType(); |
| 3223 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3224 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3225 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3226 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3227 | return QualType(); |
| 3228 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3229 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3230 | } |
| 3231 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3232 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3233 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3234 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3235 | unsigned IndexTypeQuals = Record[2]; |
| 3236 | unsigned Idx = 3; |
| 3237 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3238 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3239 | ASM, IndexTypeQuals); |
| 3240 | } |
| 3241 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3242 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3243 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3244 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3245 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3246 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3249 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3250 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3251 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3252 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3253 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3254 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3255 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3256 | ASM, IndexTypeQuals, |
| 3257 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3260 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3261 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3262 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3263 | return QualType(); |
| 3264 | } |
| 3265 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3266 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3267 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3268 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3269 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3270 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3271 | } |
| 3272 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3273 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3274 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3275 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3276 | return QualType(); |
| 3277 | } |
| 3278 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3279 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3280 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3281 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3284 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3285 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3286 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3287 | return QualType(); |
| 3288 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3289 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3290 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3291 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3292 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3295 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3296 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3297 | |
| 3298 | FunctionProtoType::ExtProtoInfo EPI; |
| 3299 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3300 | /*hasregparm*/ Record[2], |
| 3301 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3302 | static_cast<CallingConv>(Record[4]), |
| 3303 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3304 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3305 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3306 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3307 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3308 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3309 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3310 | |
| 3311 | EPI.Variadic = Record[Idx++]; |
| 3312 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3313 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3314 | ExceptionSpecificationType EST = |
| 3315 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3316 | EPI.ExceptionSpecType = EST; |
| 3317 | if (EST == EST_Dynamic) { |
| 3318 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3319 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3320 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3321 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3322 | EPI.Exceptions = Exceptions.data(); |
| 3323 | } else if (EST == EST_ComputedNoexcept) { |
| 3324 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3325 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3326 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3327 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3328 | } |
| 3329 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3330 | case TYPE_UNRESOLVED_USING: { |
| 3331 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3332 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3333 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3334 | } |
| 3335 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3336 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3337 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3338 | Error("incorrect encoding of typedef type"); |
| 3339 | return QualType(); |
| 3340 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3341 | unsigned Idx = 0; |
| 3342 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3343 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3344 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3345 | Canonical = Context.getCanonicalType(Canonical); |
| 3346 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3347 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3348 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3349 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3350 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3351 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3352 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3353 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3354 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3355 | return QualType(); |
| 3356 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3357 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3358 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3359 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3360 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3361 | case TYPE_DECLTYPE: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3362 | return Context.getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3363 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3364 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3365 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3366 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3367 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3368 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3369 | } |
| 3370 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3371 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3372 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3373 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3374 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3375 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3376 | Error("incorrect encoding of record type"); |
| 3377 | return QualType(); |
| 3378 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3379 | unsigned Idx = 0; |
| 3380 | bool IsDependent = Record[Idx++]; |
| 3381 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3382 | = Context.getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3383 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3384 | return T; |
| 3385 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3386 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3387 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3388 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3389 | Error("incorrect encoding of enum type"); |
| 3390 | return QualType(); |
| 3391 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3392 | unsigned Idx = 0; |
| 3393 | bool IsDependent = Record[Idx++]; |
| 3394 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3395 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3396 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3397 | return T; |
| 3398 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3399 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3400 | case TYPE_ATTRIBUTED: { |
| 3401 | if (Record.size() != 3) { |
| 3402 | Error("incorrect encoding of attributed type"); |
| 3403 | return QualType(); |
| 3404 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3405 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3406 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3407 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3408 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3411 | case TYPE_PAREN: { |
| 3412 | if (Record.size() != 1) { |
| 3413 | Error("incorrect encoding of paren type"); |
| 3414 | return QualType(); |
| 3415 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3416 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3417 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3418 | } |
| 3419 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3420 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3421 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3422 | Error("incorrect encoding of pack expansion type"); |
| 3423 | return QualType(); |
| 3424 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3425 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3426 | if (Pattern.isNull()) |
| 3427 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3428 | llvm::Optional<unsigned> NumExpansions; |
| 3429 | if (Record[1]) |
| 3430 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3431 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3432 | } |
| 3433 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3434 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3435 | unsigned Idx = 0; |
| 3436 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3437 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3438 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3439 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3442 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3443 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3444 | ObjCInterfaceDecl *ItfD |
| 3445 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3446 | return Context.getObjCInterfaceType(ItfD); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3449 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3450 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3451 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3452 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3453 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3454 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3455 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3456 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3457 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3458 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3459 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3460 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3461 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3462 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3463 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3464 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3465 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3466 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3467 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3468 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3469 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3470 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3471 | Replacement); |
| 3472 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3473 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3474 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3475 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3476 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3477 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3478 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3479 | cast<TemplateTypeParmType>(Parm), |
| 3480 | ArgPack); |
| 3481 | } |
| 3482 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3483 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3484 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3485 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3486 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3487 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3488 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3489 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3490 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3491 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3492 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3493 | unsigned Idx = 0; |
| 3494 | unsigned Depth = Record[Idx++]; |
| 3495 | unsigned Index = Record[Idx++]; |
| 3496 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3497 | TemplateTypeParmDecl *D |
| 3498 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3499 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3500 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3501 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3502 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3503 | unsigned Idx = 0; |
| 3504 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3505 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3506 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3507 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3508 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3509 | Canon = Context.getCanonicalType(Canon); |
| 3510 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3511 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3512 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3513 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3514 | unsigned Idx = 0; |
| 3515 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3516 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3517 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3518 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3519 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3520 | Args.reserve(NumArgs); |
| 3521 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3522 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3523 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3524 | Args.size(), Args.data()); |
| 3525 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3526 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3527 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3528 | unsigned Idx = 0; |
| 3529 | |
| 3530 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3531 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3532 | ArrayType::ArraySizeModifier ASM |
| 3533 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3534 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3535 | |
| 3536 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3537 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3538 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3539 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3540 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3541 | IndexTypeQuals, Brackets); |
| 3542 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3543 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3544 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3545 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3546 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3547 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3548 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3549 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3550 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3551 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3552 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3553 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3554 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3555 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3556 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3557 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3558 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3559 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3560 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 3561 | |
| 3562 | case TYPE_ATOMIC: { |
| 3563 | if (Record.size() != 1) { |
| 3564 | Error("Incorrect encoding of atomic type"); |
| 3565 | return QualType(); |
| 3566 | } |
| 3567 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 3568 | return Context.getAtomicType(ValueType); |
| 3569 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3570 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3571 | // Suppress a GCC warning |
| 3572 | return QualType(); |
| 3573 | } |
| 3574 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3575 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3576 | ASTReader &Reader; |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3577 | Module &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3578 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3579 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3580 | unsigned &Idx; |
| 3581 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3582 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3583 | unsigned &I) { |
| 3584 | return Reader.ReadSourceLocation(F, R, I); |
| 3585 | } |
| 3586 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3587 | template<typename T> |
| 3588 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3589 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3590 | } |
| 3591 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3592 | public: |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3593 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3594 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3595 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3596 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3597 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3598 | // We want compile-time assurance that we've enumerated all of |
| 3599 | // these, so unfortunately we have to declare them first, then |
| 3600 | // define them out-of-line. |
| 3601 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3602 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3603 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3604 | #include "clang/AST/TypeLocNodes.def" |
| 3605 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3606 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3607 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3608 | }; |
| 3609 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3610 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3611 | // nothing to do |
| 3612 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3613 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3614 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3615 | if (TL.needsExtraLocalData()) { |
| 3616 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3617 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3618 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3619 | TL.setModeAttr(Record[Idx++]); |
| 3620 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3621 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3622 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3623 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3624 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3625 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3626 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3627 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3628 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3629 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3630 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3631 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3632 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3633 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3634 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3635 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3636 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3637 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3638 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3639 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3640 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3641 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3642 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3643 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3644 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3645 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3646 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3647 | TL.setSizeExpr(0); |
| 3648 | } |
| 3649 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3650 | VisitArrayTypeLoc(TL); |
| 3651 | } |
| 3652 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3653 | VisitArrayTypeLoc(TL); |
| 3654 | } |
| 3655 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3656 | VisitArrayTypeLoc(TL); |
| 3657 | } |
| 3658 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3659 | DependentSizedArrayTypeLoc TL) { |
| 3660 | VisitArrayTypeLoc(TL); |
| 3661 | } |
| 3662 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3663 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3664 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3665 | } |
| 3666 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3667 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3668 | } |
| 3669 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3670 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3671 | } |
| 3672 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3673 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3674 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3675 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3676 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3677 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3678 | } |
| 3679 | } |
| 3680 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3681 | VisitFunctionTypeLoc(TL); |
| 3682 | } |
| 3683 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3684 | VisitFunctionTypeLoc(TL); |
| 3685 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3686 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3687 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3688 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3689 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3690 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3691 | } |
| 3692 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3693 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3694 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3695 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3696 | } |
| 3697 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3698 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3699 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3700 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3701 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3702 | } |
| 3703 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3704 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3705 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3706 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3707 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3708 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3709 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3710 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3711 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3712 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3713 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3714 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3715 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc 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::VisitEnumTypeLoc(EnumTypeLoc 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 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3721 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3722 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3723 | if (TL.hasAttrOperand()) { |
| 3724 | SourceRange range; |
| 3725 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3726 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3727 | TL.setAttrOperandParensRange(range); |
| 3728 | } |
| 3729 | if (TL.hasAttrExprOperand()) { |
| 3730 | if (Record[Idx++]) |
| 3731 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3732 | else |
| 3733 | TL.setAttrExprOperand(0); |
| 3734 | } else if (TL.hasAttrEnumOperand()) |
| 3735 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3736 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3737 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3738 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3739 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3740 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3741 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3742 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3743 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3744 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3745 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3746 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3747 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3748 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3749 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3750 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3751 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3752 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3753 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3754 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3755 | Reader.GetTemplateArgumentLocInfo(F, |
| 3756 | TL.getTypePtr()->getArg(i).getKind(), |
| 3757 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3758 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3759 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3760 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3761 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3762 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3763 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3764 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3765 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3766 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3767 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3768 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3769 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3770 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3771 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3772 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3773 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3774 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3775 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3776 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3777 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3778 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3779 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3780 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3781 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3782 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3783 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3784 | Reader.GetTemplateArgumentLocInfo(F, |
| 3785 | TL.getTypePtr()->getArg(I).getKind(), |
| 3786 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3787 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3788 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3789 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3790 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3791 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3792 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3793 | } |
| 3794 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3795 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3796 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3797 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3798 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3799 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3800 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3801 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3802 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3803 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 3804 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 3805 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3806 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3807 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3808 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3809 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3810 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3811 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3812 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3813 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3814 | if (InfoTy.isNull()) |
| 3815 | return 0; |
| 3816 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3817 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3818 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3819 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3820 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3821 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3822 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3823 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3824 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3825 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3826 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3827 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3828 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3829 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3830 | switch ((PredefinedTypeIDs)Index) { |
| 3831 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3832 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 3833 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3834 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3835 | case PREDEF_TYPE_CHAR_U_ID: |
| 3836 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3837 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3838 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3839 | break; |
| 3840 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3841 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 3842 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 3843 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 3844 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 3845 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 3846 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 3847 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 3848 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 3849 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 3850 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 3851 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 3852 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 3853 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 3854 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3855 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 3856 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 3857 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 3858 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 3859 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
| 3860 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 3861 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 3862 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 3863 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 3864 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 3865 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 3866 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 3867 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 3868 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3869 | |
| 3870 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3871 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3872 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 3873 | |
| 3874 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 3875 | T = Context.ARCUnbridgedCastTy; |
| 3876 | break; |
| 3877 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3881 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3884 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3885 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3886 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3887 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3888 | if (TypesLoaded[Index].isNull()) |
| 3889 | return QualType(); |
| 3890 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3891 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3892 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3893 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3894 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3895 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3896 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3897 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3898 | } |
| 3899 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3900 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3901 | return GetType(getGlobalTypeID(F, LocalID)); |
| 3902 | } |
| 3903 | |
| 3904 | serialization::TypeID |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3905 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3906 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 3907 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 3908 | |
| 3909 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 3910 | return LocalID; |
| 3911 | |
| 3912 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 3913 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 3914 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 3915 | |
| 3916 | unsigned GlobalIndex = LocalIndex + I->second; |
| 3917 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 3918 | } |
| 3919 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3920 | TemplateArgumentLocInfo |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3921 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3922 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3923 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3924 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3925 | switch (Kind) { |
| 3926 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3927 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3928 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3929 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3930 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3931 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3932 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3933 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3934 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3935 | SourceLocation()); |
| 3936 | } |
| 3937 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3938 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3939 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3940 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3941 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3942 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3943 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3944 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3945 | case TemplateArgument::Null: |
| 3946 | case TemplateArgument::Integral: |
| 3947 | case TemplateArgument::Declaration: |
| 3948 | case TemplateArgument::Pack: |
| 3949 | return TemplateArgumentLocInfo(); |
| 3950 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3951 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3952 | return TemplateArgumentLocInfo(); |
| 3953 | } |
| 3954 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3955 | TemplateArgumentLoc |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3956 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3957 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3958 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3959 | |
| 3960 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3961 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3962 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3963 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3964 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3965 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3966 | } |
| 3967 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3968 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3969 | return GetDecl(ID); |
| 3970 | } |
| 3971 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3972 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 3973 | unsigned &Idx){ |
| 3974 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3975 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3976 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3977 | unsigned LocalID = Record[Idx++]; |
| 3978 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3982 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 3983 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3984 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3985 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3986 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3987 | RecordData Record; |
| 3988 | unsigned Code = Cursor.ReadCode(); |
| 3989 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3990 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3991 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3992 | return 0; |
| 3993 | } |
| 3994 | |
| 3995 | unsigned Idx = 0; |
| 3996 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3997 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3998 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3999 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4000 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4001 | return Bases; |
| 4002 | } |
| 4003 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4004 | serialization::DeclID |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4005 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4006 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4007 | return LocalID; |
| 4008 | |
| 4009 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4010 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4011 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4012 | |
| 4013 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4014 | } |
| 4015 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4016 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 4017 | Module &M) const { |
| 4018 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4019 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4020 | return &M == I->second; |
| 4021 | } |
| 4022 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4023 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4024 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4025 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4026 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4027 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4028 | |
| 4029 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4030 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4031 | |
| 4032 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4033 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4034 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4035 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4036 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4037 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4038 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4039 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4040 | |
| 4041 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4042 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4043 | |
| 4044 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4045 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4046 | |
| 4047 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4048 | return Context.getObjCInstanceTypeDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4051 | return 0; |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4052 | } |
| 4053 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4054 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4055 | |
| 4056 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4057 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4058 | return 0; |
| 4059 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4060 | |
| 4061 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4062 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4063 | if (DeserializationListener) |
| 4064 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4065 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4066 | |
| 4067 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4068 | } |
| 4069 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4070 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4071 | const RecordData &Record, |
| 4072 | unsigned &Idx) { |
| 4073 | if (Idx >= Record.size()) { |
| 4074 | Error("Corrupted AST file"); |
| 4075 | return 0; |
| 4076 | } |
| 4077 | |
| 4078 | return getGlobalDeclID(F, Record[Idx++]); |
| 4079 | } |
| 4080 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4081 | /// \brief Resolve the offset of a statement into a statement. |
| 4082 | /// |
| 4083 | /// This operation will read a new statement from the external |
| 4084 | /// source each time it is called, and is meant to be used via a |
| 4085 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4086 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4087 | // Switch case IDs are per Decl. |
| 4088 | ClearSwitchCaseIDs(); |
| 4089 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4090 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4091 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4092 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4093 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4096 | namespace { |
| 4097 | class FindExternalLexicalDeclsVisitor { |
| 4098 | ASTReader &Reader; |
| 4099 | const DeclContext *DC; |
| 4100 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4101 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4102 | SmallVectorImpl<Decl*> &Decls; |
| 4103 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4104 | |
| 4105 | public: |
| 4106 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4107 | bool (*isKindWeWant)(Decl::Kind), |
| 4108 | SmallVectorImpl<Decl*> &Decls) |
| 4109 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4110 | { |
| 4111 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4112 | PredefsVisited[I] = false; |
| 4113 | } |
| 4114 | |
| 4115 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4116 | if (Preorder) |
| 4117 | return false; |
| 4118 | |
| 4119 | FindExternalLexicalDeclsVisitor *This |
| 4120 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4121 | |
| 4122 | Module::DeclContextInfosMap::iterator Info |
| 4123 | = M.DeclContextInfos.find(This->DC); |
| 4124 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4125 | return false; |
| 4126 | |
| 4127 | // Load all of the declaration IDs |
| 4128 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4129 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4130 | ID != IDE; ++ID) { |
| 4131 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4132 | continue; |
| 4133 | |
| 4134 | // Don't add predefined declarations to the lexical context more |
| 4135 | // than once. |
| 4136 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4137 | if (This->PredefsVisited[ID->second]) |
| 4138 | continue; |
| 4139 | |
| 4140 | This->PredefsVisited[ID->second] = true; |
| 4141 | } |
| 4142 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4143 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4144 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4145 | This->Decls.push_back(D); |
| 4146 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | return false; |
| 4150 | } |
| 4151 | }; |
| 4152 | } |
| 4153 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4154 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4155 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4156 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4157 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4158 | // least. Walk all of the modules in the order they were loaded. |
| 4159 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4160 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4161 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4162 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4165 | namespace { |
| 4166 | /// \brief Module visitor used to perform name lookup into a |
| 4167 | /// declaration context. |
| 4168 | class DeclContextNameLookupVisitor { |
| 4169 | ASTReader &Reader; |
| 4170 | const DeclContext *DC; |
| 4171 | DeclarationName Name; |
| 4172 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4173 | |
| 4174 | public: |
| 4175 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4176 | const DeclContext *DC, DeclarationName Name, |
| 4177 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4178 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4179 | |
| 4180 | static bool visit(Module &M, void *UserData) { |
| 4181 | DeclContextNameLookupVisitor *This |
| 4182 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4183 | |
| 4184 | // Check whether we have any visible declaration information for |
| 4185 | // this context in this module. |
| 4186 | Module::DeclContextInfosMap::iterator Info |
| 4187 | = M.DeclContextInfos.find(This->DC); |
| 4188 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4189 | return false; |
| 4190 | |
| 4191 | // Look for this name within this module. |
| 4192 | ASTDeclContextNameLookupTable *LookupTable = |
| 4193 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4194 | ASTDeclContextNameLookupTable::iterator Pos |
| 4195 | = LookupTable->find(This->Name); |
| 4196 | if (Pos == LookupTable->end()) |
| 4197 | return false; |
| 4198 | |
| 4199 | bool FoundAnything = false; |
| 4200 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4201 | for (; Data.first != Data.second; ++Data.first) { |
| 4202 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4203 | if (!ND) |
| 4204 | continue; |
| 4205 | |
| 4206 | if (ND->getDeclName() != This->Name) { |
| 4207 | assert(!This->Name.getCXXNameType().isNull() && |
| 4208 | "Name mismatch without a type"); |
| 4209 | continue; |
| 4210 | } |
| 4211 | |
| 4212 | // Record this declaration. |
| 4213 | FoundAnything = true; |
| 4214 | This->Decls.push_back(ND); |
| 4215 | } |
| 4216 | |
| 4217 | return FoundAnything; |
| 4218 | } |
| 4219 | }; |
| 4220 | } |
| 4221 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4222 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4223 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4224 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4225 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4226 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4227 | if (!Name) |
| 4228 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4229 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4230 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4231 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4232 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4233 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4234 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4235 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4236 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4237 | } |
| 4238 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4239 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 4240 | /// before receiving the implementation, and codegen depends on this. |
| 4241 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 4242 | /// implementation before passing the deserialized implementation decl. |
| 4243 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 4244 | ASTConsumer *Consumer) { |
| 4245 | assert(ImplD && Consumer); |
| 4246 | |
| 4247 | for (ObjCImplDecl::method_iterator |
| 4248 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
| 4249 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
| 4250 | |
| 4251 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 4252 | } |
| 4253 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4254 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4255 | assert(Consumer); |
| 4256 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4257 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4258 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4259 | |
| 4260 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 4261 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 4262 | else |
| 4263 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4267 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4268 | this->Consumer = Consumer; |
| 4269 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4270 | if (!Consumer) |
| 4271 | return; |
| 4272 | |
| 4273 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4274 | // Force deserialization of this decl, which will cause it to be queued for |
| 4275 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4276 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4277 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 4278 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4279 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4280 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4281 | } |
| 4282 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4283 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4284 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4285 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4286 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4287 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4288 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4289 | unsigned NumDeclsLoaded |
| 4290 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4291 | (Decl *)0); |
| 4292 | unsigned NumIdentifiersLoaded |
| 4293 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4294 | IdentifiersLoaded.end(), |
| 4295 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4296 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4297 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4298 | SelectorsLoaded.end(), |
| 4299 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4300 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4301 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4302 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4303 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4304 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4305 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4306 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4307 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4308 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4309 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4310 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4311 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4312 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4313 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4314 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4315 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4316 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4317 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4318 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4319 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4320 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4321 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4322 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4323 | if (TotalNumStatements) |
| 4324 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4325 | NumStatementsRead, TotalNumStatements, |
| 4326 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4327 | if (TotalNumMacros) |
| 4328 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4329 | NumMacrosRead, TotalNumMacros, |
| 4330 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4331 | if (TotalLexicalDeclContexts) |
| 4332 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4333 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4334 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4335 | * 100)); |
| 4336 | if (TotalVisibleDeclContexts) |
| 4337 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4338 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4339 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4340 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4341 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4342 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4343 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4344 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4345 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4346 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4347 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4348 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4349 | dump(); |
| 4350 | std::fprintf(stderr, "\n"); |
| 4351 | } |
| 4352 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4353 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4354 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4355 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4356 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4357 | InitialCapacity> &Map) { |
| 4358 | if (Map.begin() == Map.end()) |
| 4359 | return; |
| 4360 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4361 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4362 | llvm::errs() << Name << ":\n"; |
| 4363 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4364 | I != IEnd; ++I) { |
| 4365 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4366 | << "\n"; |
| 4367 | } |
| 4368 | } |
| 4369 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4370 | void ASTReader::dump() { |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4371 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4372 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4373 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4374 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4375 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4376 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4377 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4378 | dumpModuleIDMap("Global preprocessed entity map", |
| 4379 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4380 | |
| 4381 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4382 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4383 | MEnd = ModuleMgr.end(); |
| 4384 | M != MEnd; ++M) |
| 4385 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4386 | } |
| 4387 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4388 | /// Return the amount of memory used by memory buffers, breaking down |
| 4389 | /// by heap-backed versus mmap'ed memory. |
| 4390 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4391 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4392 | E = ModuleMgr.end(); I != E; ++I) { |
| 4393 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4394 | size_t bytes = buf->getBufferSize(); |
| 4395 | switch (buf->getBufferKind()) { |
| 4396 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4397 | sizes.malloc_bytes += bytes; |
| 4398 | break; |
| 4399 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4400 | sizes.mmap_bytes += bytes; |
| 4401 | break; |
| 4402 | } |
| 4403 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4404 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4407 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4408 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4409 | S.ExternalSource = this; |
| 4410 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4411 | // Makes sure any declarations that were deserialized "too early" |
| 4412 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4413 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4414 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4415 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4416 | |
| 4417 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4418 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4419 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4420 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4421 | // Load the offsets of the declarations that Sema references. |
| 4422 | // They will be lazily deserialized when needed. |
| 4423 | if (!SemaDeclRefs.empty()) { |
| 4424 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4425 | if (!SemaObj->StdNamespace) |
| 4426 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4427 | if (!SemaObj->StdBadAlloc) |
| 4428 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4431 | if (!FPPragmaOptions.empty()) { |
| 4432 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4433 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4434 | } |
| 4435 | |
| 4436 | if (!OpenCLExtensions.empty()) { |
| 4437 | unsigned I = 0; |
| 4438 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4439 | #include "clang/Basic/OpenCLExtensions.def" |
| 4440 | |
| 4441 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4442 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4443 | } |
| 4444 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4445 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4446 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4447 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4448 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4451 | namespace clang { |
| 4452 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4453 | /// identifiers stored within a set of AST files. |
| 4454 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4455 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4456 | const ASTReader &Reader; |
| 4457 | |
| 4458 | /// \brief The current index into the chain of AST files stored in |
| 4459 | /// the AST reader. |
| 4460 | unsigned Index; |
| 4461 | |
| 4462 | /// \brief The current position within the identifier lookup table |
| 4463 | /// of the current AST file. |
| 4464 | ASTIdentifierLookupTable::key_iterator Current; |
| 4465 | |
| 4466 | /// \brief The end position within the identifier lookup table of |
| 4467 | /// the current AST file. |
| 4468 | ASTIdentifierLookupTable::key_iterator End; |
| 4469 | |
| 4470 | public: |
| 4471 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4472 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4473 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4474 | }; |
| 4475 | } |
| 4476 | |
| 4477 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4478 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4479 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4480 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4481 | Current = IdTable->key_begin(); |
| 4482 | End = IdTable->key_end(); |
| 4483 | } |
| 4484 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4485 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4486 | while (Current == End) { |
| 4487 | // If we have exhausted all of our AST files, we're done. |
| 4488 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4489 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4490 | |
| 4491 | --Index; |
| 4492 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4493 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4494 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4495 | Current = IdTable->key_begin(); |
| 4496 | End = IdTable->key_end(); |
| 4497 | } |
| 4498 | |
| 4499 | // We have any identifiers remaining in the current AST file; return |
| 4500 | // the next one. |
| 4501 | std::pair<const char*, unsigned> Key = *Current; |
| 4502 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4503 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4504 | } |
| 4505 | |
| 4506 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4507 | return new ASTIdentifierIterator(*this); |
| 4508 | } |
| 4509 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4510 | namespace clang { namespace serialization { |
| 4511 | class ReadMethodPoolVisitor { |
| 4512 | ASTReader &Reader; |
| 4513 | Selector Sel; |
| 4514 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4515 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4516 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4517 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4518 | /// declarations. |
| 4519 | ObjCMethodList |
| 4520 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4521 | { |
| 4522 | ObjCMethodList List; |
| 4523 | ObjCMethodList *Prev = 0; |
| 4524 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4525 | if (!List.Method) { |
| 4526 | // This is the first method, which is the easy case. |
| 4527 | List.Method = Vec[I]; |
| 4528 | Prev = &List; |
| 4529 | continue; |
| 4530 | } |
| 4531 | |
| 4532 | ObjCMethodList *Mem = |
| 4533 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4534 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4535 | Prev = Prev->Next; |
| 4536 | } |
| 4537 | |
| 4538 | return List; |
| 4539 | } |
| 4540 | |
| 4541 | public: |
| 4542 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4543 | : Reader(Reader), Sel(Sel) { } |
| 4544 | |
| 4545 | static bool visit(Module &M, void *UserData) { |
| 4546 | ReadMethodPoolVisitor *This |
| 4547 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4548 | |
| 4549 | if (!M.SelectorLookupTable) |
| 4550 | return false; |
| 4551 | |
| 4552 | ASTSelectorLookupTable *PoolTable |
| 4553 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4554 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4555 | if (Pos == PoolTable->end()) |
| 4556 | return false; |
| 4557 | |
| 4558 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4559 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4560 | // disable this tracking when called via LoadSelector. |
| 4561 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4562 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4563 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4564 | if (This->Reader.DeserializationListener) |
| 4565 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4566 | This->Sel); |
| 4567 | |
| 4568 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4569 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4570 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4571 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4572 | |
| 4573 | /// \brief Retrieve the instance methods found by this visitor. |
| 4574 | ObjCMethodList getInstanceMethods() const { |
| 4575 | return buildObjCMethodList(InstanceMethods); |
| 4576 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4577 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4578 | /// \brief Retrieve the instance methods found by this visitor. |
| 4579 | ObjCMethodList getFactoryMethods() const { |
| 4580 | return buildObjCMethodList(FactoryMethods); |
| 4581 | } |
| 4582 | }; |
| 4583 | } } // end namespace clang::serialization |
| 4584 | |
| 4585 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4586 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4587 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4588 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4589 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4590 | Result.first = Visitor.getInstanceMethods(); |
| 4591 | Result.second = Visitor.getFactoryMethods(); |
| 4592 | |
| 4593 | if (!Result.first.Method && !Result.second.Method) |
| 4594 | ++NumMethodPoolMisses; |
| 4595 | return Result; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4596 | } |
| 4597 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4598 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4599 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4600 | Namespaces.clear(); |
| 4601 | |
| 4602 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4603 | if (NamespaceDecl *Namespace |
| 4604 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4605 | Namespaces.push_back(Namespace); |
| 4606 | } |
| 4607 | } |
| 4608 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4609 | void ASTReader::ReadTentativeDefinitions( |
| 4610 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4611 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4612 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4613 | if (Var) |
| 4614 | TentativeDefs.push_back(Var); |
| 4615 | } |
| 4616 | TentativeDefinitions.clear(); |
| 4617 | } |
| 4618 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4619 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4620 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4621 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4622 | DeclaratorDecl *D |
| 4623 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4624 | if (D) |
| 4625 | Decls.push_back(D); |
| 4626 | } |
| 4627 | UnusedFileScopedDecls.clear(); |
| 4628 | } |
| 4629 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4630 | void ASTReader::ReadDelegatingConstructors( |
| 4631 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4632 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4633 | CXXConstructorDecl *D |
| 4634 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4635 | if (D) |
| 4636 | Decls.push_back(D); |
| 4637 | } |
| 4638 | DelegatingCtorDecls.clear(); |
| 4639 | } |
| 4640 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4641 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4642 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4643 | TypedefNameDecl *D |
| 4644 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4645 | if (D) |
| 4646 | Decls.push_back(D); |
| 4647 | } |
| 4648 | ExtVectorDecls.clear(); |
| 4649 | } |
| 4650 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4651 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4652 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4653 | CXXRecordDecl *D |
| 4654 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4655 | if (D) |
| 4656 | Decls.push_back(D); |
| 4657 | } |
| 4658 | DynamicClasses.clear(); |
| 4659 | } |
| 4660 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4661 | void |
| 4662 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4663 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4664 | NamedDecl *D |
| 4665 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4666 | if (D) |
| 4667 | Decls.push_back(D); |
| 4668 | } |
| 4669 | LocallyScopedExternalDecls.clear(); |
| 4670 | } |
| 4671 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4672 | void ASTReader::ReadReferencedSelectors( |
| 4673 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4674 | if (ReferencedSelectorsData.empty()) |
| 4675 | return; |
| 4676 | |
| 4677 | // If there are @selector references added them to its pool. This is for |
| 4678 | // implementation of -Wselector. |
| 4679 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4680 | unsigned I = 0; |
| 4681 | while (I < DataSize) { |
| 4682 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4683 | SourceLocation SelLoc |
| 4684 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4685 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4686 | } |
| 4687 | ReferencedSelectorsData.clear(); |
| 4688 | } |
| 4689 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4690 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4691 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4692 | if (WeakUndeclaredIdentifiers.empty()) |
| 4693 | return; |
| 4694 | |
| 4695 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4696 | IdentifierInfo *WeakId |
| 4697 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4698 | IdentifierInfo *AliasId |
| 4699 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4700 | SourceLocation Loc |
| 4701 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4702 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4703 | WeakInfo WI(AliasId, Loc); |
| 4704 | WI.setUsed(Used); |
| 4705 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4706 | } |
| 4707 | WeakUndeclaredIdentifiers.clear(); |
| 4708 | } |
| 4709 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4710 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4711 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4712 | ExternalVTableUse VT; |
| 4713 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4714 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4715 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4716 | VTables.push_back(VT); |
| 4717 | } |
| 4718 | |
| 4719 | VTableUses.clear(); |
| 4720 | } |
| 4721 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4722 | void ASTReader::ReadPendingInstantiations( |
| 4723 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4724 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4725 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4726 | SourceLocation Loc |
| 4727 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4728 | Pending.push_back(std::make_pair(D, Loc)); |
| 4729 | } |
| 4730 | PendingInstantiations.clear(); |
| 4731 | } |
| 4732 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4733 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4734 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4735 | ReadMethodPool(Sel); |
| 4736 | } |
| 4737 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4738 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4739 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4740 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4741 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4742 | if (DeserializationListener) |
| 4743 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4746 | /// \brief Set the globally-visible declarations associated with the given |
| 4747 | /// identifier. |
| 4748 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4749 | /// 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] | 4750 | /// 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] | 4751 | /// them. |
| 4752 | /// |
| 4753 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4754 | /// declarations. |
| 4755 | /// |
| 4756 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4757 | /// visible at global scope. |
| 4758 | /// |
| 4759 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4760 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4761 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4762 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4763 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4764 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4765 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4766 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4767 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4768 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4769 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4770 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4771 | return; |
| 4772 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4773 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4774 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4775 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4776 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4777 | if (SemaObj->TUScope) { |
| 4778 | // Introduce this declaration into the translation-unit scope |
| 4779 | // and add it to the declaration chain for this identifier, so |
| 4780 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4781 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4782 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4783 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4784 | } else { |
| 4785 | // Queue this declaration so that it will be added to the |
| 4786 | // translation unit scope and identifier's declaration chain |
| 4787 | // once a Sema object is known. |
| 4788 | PreloadedDecls.push_back(D); |
| 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4793 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4794 | if (ID == 0) |
| 4795 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4796 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4797 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4798 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4799 | return 0; |
| 4800 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4801 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4802 | ID -= 1; |
| 4803 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4804 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4805 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4806 | Module *M = I->second; |
| 4807 | unsigned Index = ID - M->BaseIdentifierID; |
| 4808 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4809 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4810 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4811 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4812 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4813 | // unsigned integers. This is important to avoid integer overflow when |
| 4814 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4815 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4816 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4817 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4818 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 4819 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4820 | if (DeserializationListener) |
| 4821 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4822 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4823 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4824 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4825 | } |
| 4826 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4827 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4828 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4829 | } |
| 4830 | |
| 4831 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4832 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4833 | return LocalID; |
| 4834 | |
| 4835 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4836 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4837 | assert(I != M.IdentifierRemap.end() |
| 4838 | && "Invalid index into identifier index remap"); |
| 4839 | |
| 4840 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4843 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4844 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4847 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4848 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4849 | } |
| 4850 | |
| 4851 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4852 | if (ID == 0) |
| 4853 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4854 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4855 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4856 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4857 | return Selector(); |
| 4858 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4859 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4860 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4861 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4862 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 4863 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4864 | Module &M = *I->second; |
| 4865 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4866 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4867 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4868 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4869 | if (DeserializationListener) |
| 4870 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4873 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4876 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4877 | return DecodeSelector(ID); |
| 4878 | } |
| 4879 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4880 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4881 | // ID 0 (the null selector) is considered an external selector. |
| 4882 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4885 | serialization::SelectorID |
| 4886 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 4887 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 4888 | return LocalID; |
| 4889 | |
| 4890 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4891 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 4892 | assert(I != M.SelectorRemap.end() |
| 4893 | && "Invalid index into identifier index remap"); |
| 4894 | |
| 4895 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4898 | DeclarationName |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4899 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4900 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4901 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4902 | switch (Kind) { |
| 4903 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4904 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4905 | |
| 4906 | case DeclarationName::ObjCZeroArgSelector: |
| 4907 | case DeclarationName::ObjCOneArgSelector: |
| 4908 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4909 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4910 | |
| 4911 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4912 | return Context.DeclarationNames.getCXXConstructorName( |
| 4913 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4914 | |
| 4915 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4916 | return Context.DeclarationNames.getCXXDestructorName( |
| 4917 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4918 | |
| 4919 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4920 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 4921 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4922 | |
| 4923 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4924 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4925 | (OverloadedOperatorKind)Record[Idx++]); |
| 4926 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4927 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4928 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4929 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4930 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4931 | case DeclarationName::CXXUsingDirective: |
| 4932 | return DeclarationName::getUsingDirectiveName(); |
| 4933 | } |
| 4934 | |
| 4935 | // Required to silence GCC warning |
| 4936 | return DeclarationName(); |
| 4937 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4938 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4939 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4940 | DeclarationNameLoc &DNLoc, |
| 4941 | DeclarationName Name, |
| 4942 | const RecordData &Record, unsigned &Idx) { |
| 4943 | switch (Name.getNameKind()) { |
| 4944 | case DeclarationName::CXXConstructorName: |
| 4945 | case DeclarationName::CXXDestructorName: |
| 4946 | case DeclarationName::CXXConversionFunctionName: |
| 4947 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4948 | break; |
| 4949 | |
| 4950 | case DeclarationName::CXXOperatorName: |
| 4951 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4952 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4953 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4954 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4955 | break; |
| 4956 | |
| 4957 | case DeclarationName::CXXLiteralOperatorName: |
| 4958 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4959 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4960 | break; |
| 4961 | |
| 4962 | case DeclarationName::Identifier: |
| 4963 | case DeclarationName::ObjCZeroArgSelector: |
| 4964 | case DeclarationName::ObjCOneArgSelector: |
| 4965 | case DeclarationName::ObjCMultiArgSelector: |
| 4966 | case DeclarationName::CXXUsingDirective: |
| 4967 | break; |
| 4968 | } |
| 4969 | } |
| 4970 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4971 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4972 | DeclarationNameInfo &NameInfo, |
| 4973 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4974 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4975 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4976 | DeclarationNameLoc DNLoc; |
| 4977 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4978 | NameInfo.setInfo(DNLoc); |
| 4979 | } |
| 4980 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4981 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4982 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4983 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4984 | unsigned NumTPLists = Record[Idx++]; |
| 4985 | Info.NumTemplParamLists = NumTPLists; |
| 4986 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4987 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4988 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4989 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4990 | } |
| 4991 | } |
| 4992 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4993 | TemplateName |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4994 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4995 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4996 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4997 | switch (Kind) { |
| 4998 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4999 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5000 | |
| 5001 | case TemplateName::OverloadedTemplate: { |
| 5002 | unsigned size = Record[Idx++]; |
| 5003 | UnresolvedSet<8> Decls; |
| 5004 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5005 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5006 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5007 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5008 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5009 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5010 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5011 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5012 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5013 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5014 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5015 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5016 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5017 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5018 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5019 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5020 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5021 | GetIdentifierInfo(F, Record, |
| 5022 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5023 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5024 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5025 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5026 | |
| 5027 | case TemplateName::SubstTemplateTemplateParm: { |
| 5028 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5029 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5030 | if (!param) return TemplateName(); |
| 5031 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5032 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5033 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5034 | |
| 5035 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5036 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5037 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5038 | if (!Param) |
| 5039 | return TemplateName(); |
| 5040 | |
| 5041 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5042 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5043 | return TemplateName(); |
| 5044 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5045 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5046 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5047 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5048 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5049 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | TemplateArgument |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5053 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5054 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5055 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5056 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5057 | case TemplateArgument::Null: |
| 5058 | return TemplateArgument(); |
| 5059 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5060 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5061 | case TemplateArgument::Declaration: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5062 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5063 | case TemplateArgument::Integral: { |
| 5064 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5065 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5066 | return TemplateArgument(Value, T); |
| 5067 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5068 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5069 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5070 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5071 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5072 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5073 | if (unsigned NumExpansions = Record[Idx++]) |
| 5074 | NumTemplateExpansions = NumExpansions - 1; |
| 5075 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5076 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5077 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5078 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5079 | case TemplateArgument::Pack: { |
| 5080 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5081 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5082 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5083 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5084 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5085 | } |
| 5086 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5087 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5088 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5089 | } |
| 5090 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5091 | TemplateParameterList * |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5092 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5093 | const RecordData &Record, unsigned &Idx) { |
| 5094 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5095 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5096 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5097 | |
| 5098 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5099 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5100 | Params.reserve(NumParams); |
| 5101 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5102 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5103 | |
| 5104 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5105 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5106 | Params.data(), Params.size(), RAngleLoc); |
| 5107 | return TemplateParams; |
| 5108 | } |
| 5109 | |
| 5110 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5111 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5112 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5113 | Module &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5114 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5115 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5116 | TemplArgs.reserve(NumTemplateArgs); |
| 5117 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5118 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5121 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5122 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5123 | const RecordData &Record, unsigned &Idx) { |
| 5124 | unsigned NumDecls = Record[Idx++]; |
| 5125 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5126 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5127 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5128 | Set.addDecl(D, AS); |
| 5129 | } |
| 5130 | } |
| 5131 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5132 | CXXBaseSpecifier |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5133 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5134 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5135 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5136 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5137 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5138 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5139 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5140 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5141 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5142 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5143 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5144 | Result.setInheritConstructors(inheritConstructors); |
| 5145 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5146 | } |
| 5147 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5148 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5149 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5150 | unsigned &Idx) { |
| 5151 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5152 | unsigned NumInitializers = Record[Idx++]; |
| 5153 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5154 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5155 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5156 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5157 | TypeSourceInfo *BaseClassInfo = 0; |
| 5158 | bool IsBaseVirtual = false; |
| 5159 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5160 | IndirectFieldDecl *IndirectMember = 0; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5161 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5162 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5163 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5164 | switch (Type) { |
| 5165 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5166 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5167 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5168 | break; |
| 5169 | |
| 5170 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5171 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5172 | break; |
| 5173 | |
| 5174 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5175 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5176 | break; |
| 5177 | |
| 5178 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5179 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5180 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5181 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5182 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5183 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5184 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5185 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5186 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5187 | bool IsWritten = Record[Idx++]; |
| 5188 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5189 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5190 | if (IsWritten) { |
| 5191 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5192 | } else { |
| 5193 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5194 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5195 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5196 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5197 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5198 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5199 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5200 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5201 | BOMInit = new (Context) CXXCtorInitializer(Context, BaseClassInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5202 | LParenLoc, Init, RParenLoc, |
| 5203 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5204 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5205 | BOMInit = new (Context) CXXCtorInitializer(Context, MemberOrEllipsisLoc, LParenLoc, |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5206 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5207 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5208 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5209 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5210 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5211 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5212 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5213 | MemberOrEllipsisLoc, LParenLoc, |
| 5214 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5215 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5216 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5217 | LParenLoc, Init, RParenLoc, |
| 5218 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5219 | } |
| 5220 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5221 | if (IsWritten) |
| 5222 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5223 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5224 | } |
| 5225 | } |
| 5226 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5227 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5230 | NestedNameSpecifier * |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5231 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5232 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5233 | unsigned N = Record[Idx++]; |
| 5234 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5235 | for (unsigned I = 0; I != N; ++I) { |
| 5236 | NestedNameSpecifier::SpecifierKind Kind |
| 5237 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5238 | switch (Kind) { |
| 5239 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5240 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5241 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5242 | break; |
| 5243 | } |
| 5244 | |
| 5245 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5246 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5247 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5248 | break; |
| 5249 | } |
| 5250 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5251 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5252 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5253 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5254 | break; |
| 5255 | } |
| 5256 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5257 | case NestedNameSpecifier::TypeSpec: |
| 5258 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5259 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5260 | if (!T) |
| 5261 | return 0; |
| 5262 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5263 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5264 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5265 | break; |
| 5266 | } |
| 5267 | |
| 5268 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5269 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5270 | // No associated value, and there can't be a prefix. |
| 5271 | break; |
| 5272 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5273 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5274 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5275 | } |
| 5276 | return NNS; |
| 5277 | } |
| 5278 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5279 | NestedNameSpecifierLoc |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5280 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5281 | unsigned &Idx) { |
| 5282 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5283 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5284 | for (unsigned I = 0; I != N; ++I) { |
| 5285 | NestedNameSpecifier::SpecifierKind Kind |
| 5286 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5287 | switch (Kind) { |
| 5288 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5289 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5290 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5291 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5292 | break; |
| 5293 | } |
| 5294 | |
| 5295 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5296 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5297 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5298 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5299 | break; |
| 5300 | } |
| 5301 | |
| 5302 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5303 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5304 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5305 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5306 | break; |
| 5307 | } |
| 5308 | |
| 5309 | case NestedNameSpecifier::TypeSpec: |
| 5310 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5311 | bool Template = Record[Idx++]; |
| 5312 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5313 | if (!T) |
| 5314 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5315 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5316 | |
| 5317 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5318 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5319 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5320 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5321 | break; |
| 5322 | } |
| 5323 | |
| 5324 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5325 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5326 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5327 | break; |
| 5328 | } |
| 5329 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5332 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5333 | } |
| 5334 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5335 | SourceRange |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5336 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5337 | unsigned &Idx) { |
| 5338 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5339 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5340 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5341 | } |
| 5342 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5343 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5344 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5345 | unsigned BitWidth = Record[Idx++]; |
| 5346 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5347 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5348 | Idx += NumWords; |
| 5349 | return Result; |
| 5350 | } |
| 5351 | |
| 5352 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5353 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5354 | bool isUnsigned = Record[Idx++]; |
| 5355 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5356 | } |
| 5357 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5358 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5359 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5360 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5361 | } |
| 5362 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5363 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5364 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5365 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5366 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5367 | Idx += Len; |
| 5368 | return Result; |
| 5369 | } |
| 5370 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5371 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5372 | unsigned &Idx) { |
| 5373 | unsigned Major = Record[Idx++]; |
| 5374 | unsigned Minor = Record[Idx++]; |
| 5375 | unsigned Subminor = Record[Idx++]; |
| 5376 | if (Minor == 0) |
| 5377 | return VersionTuple(Major); |
| 5378 | if (Subminor == 0) |
| 5379 | return VersionTuple(Major, Minor - 1); |
| 5380 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5381 | } |
| 5382 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5383 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5384 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5385 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5386 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5387 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5390 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5391 | return Diag(SourceLocation(), DiagID); |
| 5392 | } |
| 5393 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5394 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5395 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5396 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5397 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5398 | /// \brief Retrieve the identifier table associated with the |
| 5399 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5400 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5401 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5402 | } |
| 5403 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5404 | /// \brief Record that the given ID maps to the given switch-case |
| 5405 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5406 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5407 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5408 | SwitchCaseStmts[ID] = SC; |
| 5409 | } |
| 5410 | |
| 5411 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5412 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5413 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5414 | return SwitchCaseStmts[ID]; |
| 5415 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5416 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5417 | void ASTReader::ClearSwitchCaseIDs() { |
| 5418 | SwitchCaseStmts.clear(); |
| 5419 | } |
| 5420 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5421 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5422 | assert(NumCurrentElementsDeserializing && |
| 5423 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5424 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5425 | // If any identifiers with corresponding top-level declarations have |
| 5426 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5427 | while (!PendingIdentifierInfos.empty()) { |
| 5428 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5429 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5430 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5431 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5432 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5433 | // Ready to load previous declarations of Decls that were delayed. |
| 5434 | while (!PendingPreviousDecls.empty()) { |
| 5435 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5436 | PendingPreviousDecls.front().second); |
| 5437 | PendingPreviousDecls.pop_front(); |
| 5438 | } |
| 5439 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5440 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5441 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5442 | if (Consumer) |
| 5443 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5444 | |
| 5445 | assert(PendingForwardRefs.size() == 0 && |
| 5446 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5447 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5448 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5449 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5450 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 5451 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5452 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5453 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5454 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5455 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5456 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Jonathan D. Turner | 1afb661 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5457 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5458 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5459 | DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5460 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5461 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5462 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5463 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5464 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5465 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5466 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5467 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5468 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5469 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5470 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5471 | } |
| 5472 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5473 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5474 | for (DeclContextVisibleUpdatesPending::iterator |
| 5475 | I = PendingVisibleUpdates.begin(), |
| 5476 | E = PendingVisibleUpdates.end(); |
| 5477 | I != E; ++I) { |
| 5478 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5479 | F = I->second.end(); |
| 5480 | J != F; ++J) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5481 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5482 | } |
| 5483 | } |