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) |
| 326 | .getFileLocWithOffset(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) |
| 349 | .getFileLocWithOffset(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 | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1286 | unsigned NextIndex = 3; |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1287 | MI->setExportLocation(ReadSourceLocation(F, Record, NextIndex)); |
| 1288 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1289 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1290 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1291 | bool isC99VarArgs = Record[NextIndex++]; |
| 1292 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1293 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1294 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1295 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1296 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1297 | |
| 1298 | // Install function-like macro info. |
| 1299 | MI->setIsFunctionLike(); |
| 1300 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1301 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1302 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1303 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | // Finally, install the macro. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1307 | PP.setMacroInfo(II, MI); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1308 | |
| 1309 | // Remember that we saw this macro last so that we add the tokens that |
| 1310 | // form its body to it. |
| 1311 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1312 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1313 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord()) { |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1314 | // We have a macro definition. Load it now. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1315 | PP.getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
Douglas Gregor | e144c70 | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1316 | getLocalMacroDefinition(F, Record[NextIndex])); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1317 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1318 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1319 | ++NumMacrosRead; |
| 1320 | break; |
| 1321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1323 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1324 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1325 | // erroneous, just pretend we didn't see this. |
| 1326 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1328 | Token Tok; |
| 1329 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1330 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1331 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1332 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1333 | Tok.setIdentifierInfo(II); |
| 1334 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1335 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1336 | Macro->AddTokenToBody(Tok); |
| 1337 | break; |
| 1338 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1339 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1340 | } |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1342 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1345 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1346 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1347 | switch (Code) { |
| 1348 | case llvm::bitc::END_BLOCK: |
| 1349 | return 0; |
| 1350 | |
| 1351 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1352 | Error("unexpected subblock record in preprocessor detail block"); |
| 1353 | return 0; |
| 1354 | |
| 1355 | case llvm::bitc::DEFINE_ABBREV: |
| 1356 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1357 | return 0; |
| 1358 | |
| 1359 | default: |
| 1360 | break; |
| 1361 | } |
| 1362 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1363 | if (!PP.getPreprocessingRecord()) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1364 | Error("no preprocessing record"); |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | // Read the record. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1369 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1370 | const char *BlobStart = 0; |
| 1371 | unsigned BlobLen = 0; |
| 1372 | RecordData Record; |
| 1373 | PreprocessorDetailRecordTypes RecType = |
| 1374 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1375 | Code, Record, BlobStart, BlobLen); |
| 1376 | switch (RecType) { |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1377 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1378 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1379 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1380 | return PE; |
| 1381 | |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1382 | bool isBuiltin = Record[3]; |
| 1383 | MacroExpansion *ME; |
| 1384 | if (isBuiltin) |
| 1385 | ME = new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[4]), |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1386 | SourceRange(ReadSourceLocation(F, Record[1]), |
Argyrios Kyrtzidis | 8f7c540 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1387 | ReadSourceLocation(F, Record[2]))); |
| 1388 | else |
| 1389 | ME = new (PPRec) MacroExpansion(getLocalMacroDefinition(F, Record[4]), |
| 1390 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1391 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1392 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ME); |
Chandler Carruth | 9e5bb85 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1393 | return ME; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | case PPD_MACRO_DEFINITION: { |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1397 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1398 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1399 | return PE; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1400 | |
| 1401 | unsigned MacroDefID = getGlobalMacroDefinitionID(F, Record[1]); |
| 1402 | if (MacroDefID > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1403 | Error("out-of-bounds macro definition record"); |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | // Decode the identifier info and then check again; if the macro is |
| 1408 | // still defined and associated with the identifier, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1409 | IdentifierInfo *II = getLocalIdentifier(F, Record[4]); |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1410 | if (!MacroDefinitionsLoaded[MacroDefID - 1]) { |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1411 | MacroDefinition *MD |
| 1412 | = new (PPRec) MacroDefinition(II, |
| 1413 | ReadSourceLocation(F, Record[5]), |
| 1414 | SourceRange( |
| 1415 | ReadSourceLocation(F, Record[2]), |
| 1416 | ReadSourceLocation(F, Record[3]))); |
| 1417 | |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1418 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, MD); |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1419 | MacroDefinitionsLoaded[MacroDefID - 1] = MD; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1420 | |
| 1421 | if (DeserializationListener) |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1422 | DeserializationListener->MacroDefinitionRead(MacroDefID, MD); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1425 | return MacroDefinitionsLoaded[MacroDefID - 1]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | case PPD_INCLUSION_DIRECTIVE: { |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1429 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1430 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1431 | return PE; |
| 1432 | |
| 1433 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1434 | const FileEntry *File |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1435 | = PP.getFileManager().getFile(StringRef(FullFileNameStart, |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1436 | BlobLen - Record[3])); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1437 | |
| 1438 | // FIXME: Stable encoding |
| 1439 | InclusionDirective::InclusionKind Kind |
| 1440 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1441 | InclusionDirective *ID |
| 1442 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1443 | StringRef(BlobStart, Record[3]), |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1444 | Record[4], |
| 1445 | File, |
| 1446 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1447 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 7338a92 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1448 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ID); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1449 | return ID; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | Error("invalid offset in preprocessor detail block"); |
| 1454 | return 0; |
| 1455 | } |
| 1456 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1457 | PreprocessedEntityID |
| 1458 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1459 | ContinuousRangeMap<uint32_t, int, 2>::iterator |
| 1460 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1461 | assert(I != M.PreprocessedEntityRemap.end() |
| 1462 | && "Invalid index into preprocessed entity index remap"); |
| 1463 | |
| 1464 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1467 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1468 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1469 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1470 | |
| 1471 | HeaderFileInfoTrait::internal_key_type |
| 1472 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1473 | |
| 1474 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1475 | if (strcmp(a, b) == 0) |
| 1476 | return true; |
| 1477 | |
| 1478 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1479 | return false; |
| 1480 | |
| 1481 | // The file names match, but the path names don't. stat() the files to |
| 1482 | // see if they are the same. |
| 1483 | struct stat StatBufA, StatBufB; |
| 1484 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1485 | return false; |
| 1486 | |
| 1487 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1488 | } |
| 1489 | |
| 1490 | std::pair<unsigned, unsigned> |
| 1491 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1492 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1493 | unsigned DataLen = (unsigned) *d++; |
| 1494 | return std::make_pair(KeyLen + 1, DataLen); |
| 1495 | } |
| 1496 | |
| 1497 | HeaderFileInfoTrait::data_type |
| 1498 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1499 | unsigned DataLen) { |
| 1500 | const unsigned char *End = d + DataLen; |
| 1501 | using namespace clang::io; |
| 1502 | HeaderFileInfo HFI; |
| 1503 | unsigned Flags = *d++; |
| 1504 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1505 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1506 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1507 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1508 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1509 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1510 | HFI.ControllingMacroID = Reader.getGlobalDeclID(M, ReadUnalignedLE32(d)); |
| 1511 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1512 | // The framework offset is 1 greater than the actual offset, |
| 1513 | // since 0 is used as an indicator for "no framework name". |
| 1514 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1515 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1516 | } |
| 1517 | |
| 1518 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1519 | (void)End; |
| 1520 | |
| 1521 | // This HeaderFileInfo was externally loaded. |
| 1522 | HFI.External = true; |
| 1523 | return HFI; |
| 1524 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1525 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1526 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1527 | uint64_t LocalOffset) { |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1528 | // Note that this identifier has a macro definition. |
| 1529 | II->setHasMacroDefinition(true); |
| 1530 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1531 | // Adjust the offset to a global offset. |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1532 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1535 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1536 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1537 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1538 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1539 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1540 | // If there was no preprocessor block, skip this file. |
| 1541 | if (!MacroCursor.getBitStreamReader()) |
| 1542 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1543 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1544 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1545 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1546 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1547 | RecordData Record; |
| 1548 | while (true) { |
| 1549 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1550 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1551 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1552 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1553 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1554 | // No known subblocks, always skip them. |
| 1555 | Cursor.ReadSubBlockID(); |
| 1556 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1557 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1558 | return; |
| 1559 | } |
| 1560 | continue; |
| 1561 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1562 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1563 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1564 | Cursor.ReadAbbrevRecord(); |
| 1565 | continue; |
| 1566 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1567 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1568 | // Read a record. |
| 1569 | const char *BlobStart; |
| 1570 | unsigned BlobLen; |
| 1571 | Record.clear(); |
| 1572 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1573 | default: // Default behavior: ignore. |
| 1574 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1575 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1576 | case PP_MACRO_OBJECT_LIKE: |
| 1577 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1578 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1579 | break; |
| 1580 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1581 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1582 | // Ignore tokens. |
| 1583 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1584 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1585 | } |
| 1586 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1587 | |
| 1588 | // Drain the unread macro-record offsets map. |
| 1589 | while (!UnreadMacroRecordOffsets.empty()) |
| 1590 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1591 | } |
| 1592 | |
| 1593 | void ASTReader::LoadMacroDefinition( |
| 1594 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1595 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1596 | uint64_t Offset = Pos->second; |
| 1597 | UnreadMacroRecordOffsets.erase(Pos); |
| 1598 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1599 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1600 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1604 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1605 | = UnreadMacroRecordOffsets.find(II); |
| 1606 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Sebastian Redl | f73c93f | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1609 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1610 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1611 | return 0; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1612 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1613 | if (!MacroDefinitionsLoaded[ID - 1]) { |
Douglas Gregor | 14ad03b | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 1614 | GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID); |
| 1615 | assert(I != GlobalMacroDefinitionMap.end() && |
| 1616 | "Corrupted global macro definition map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1617 | Module &M = *I->second; |
| 1618 | unsigned Index = ID - 1 - M.BaseMacroDefinitionID; |
| 1619 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 1620 | M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]); |
| 1621 | LoadPreprocessedEntity(M); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1622 | } |
| 1623 | |
Douglas Gregor | 77424bc | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1624 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1627 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1628 | std::string Filename = filenameStrRef; |
| 1629 | MaybeAddSystemRootToFilename(Filename); |
| 1630 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1631 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1632 | OriginalDir != CurrentDir) { |
| 1633 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1634 | OriginalDir, |
| 1635 | CurrentDir); |
| 1636 | if (!resolved.empty()) |
| 1637 | File = FileMgr.getFile(resolved); |
| 1638 | } |
| 1639 | |
| 1640 | return File; |
| 1641 | } |
| 1642 | |
Douglas Gregor | e144c70 | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1643 | MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) { |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1644 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 1645 | return LocalID; |
| 1646 | |
| 1647 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 1648 | = M.MacroDefinitionRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 1649 | assert(I != M.MacroDefinitionRemap.end() && |
| 1650 | "Invalid index into macro definition ID remap"); |
| 1651 | |
| 1652 | return LocalID + I->second; |
Douglas Gregor | e144c70 | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1655 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1656 | /// not an absolute path, add the system root to the beginning of the file |
| 1657 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1658 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1659 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1660 | if (!RelocatablePCH) |
| 1661 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1663 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1664 | return; |
| 1665 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1666 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1667 | // If no system root was given, default to '/' |
| 1668 | Filename.insert(Filename.begin(), '/'); |
| 1669 | return; |
| 1670 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1672 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1673 | if (isysroot[Length - 1] != '/') |
| 1674 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1676 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1677 | } |
| 1678 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1679 | ASTReader::ASTReadResult |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1680 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1681 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1682 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1683 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1684 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1685 | return Failure; |
| 1686 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1687 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1688 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1689 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1690 | while (!Stream.AtEndOfStream()) { |
| 1691 | unsigned Code = Stream.ReadCode(); |
| 1692 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1693 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1694 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1695 | return Failure; |
| 1696 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1697 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1698 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1702 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1703 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1704 | // We lazily load the decls block, but we want to set up the |
| 1705 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1706 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1707 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1708 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1709 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1710 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1711 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1712 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1713 | return Failure; |
| 1714 | } |
| 1715 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1717 | case DECL_UPDATES_BLOCK_ID: |
| 1718 | if (Stream.SkipBlock()) { |
| 1719 | Error("malformed block record in AST file"); |
| 1720 | return Failure; |
| 1721 | } |
| 1722 | break; |
| 1723 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1724 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1725 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1726 | if (!PP.getExternalSource()) |
| 1727 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1728 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1729 | if (Stream.SkipBlock() || |
| 1730 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1731 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1732 | return Failure; |
| 1733 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1734 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1735 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1736 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1737 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1738 | F.PreprocessorDetailCursor = Stream; |
| 1739 | if (Stream.SkipBlock() || |
| 1740 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1741 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1742 | Error("malformed preprocessor detail record in AST file"); |
| 1743 | return Failure; |
| 1744 | } |
| 1745 | F.PreprocessorDetailStartOffset |
| 1746 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1747 | |
| 1748 | if (!PP.getPreprocessingRecord()) |
| 1749 | PP.createPreprocessingRecord(true); |
| 1750 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1751 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1752 | break; |
| 1753 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1754 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1755 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1756 | case Success: |
| 1757 | break; |
| 1758 | |
| 1759 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1760 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1761 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1762 | |
| 1763 | case IgnorePCH: |
| 1764 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1765 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1766 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1767 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1768 | continue; |
| 1769 | } |
| 1770 | |
| 1771 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1772 | Stream.ReadAbbrevRecord(); |
| 1773 | continue; |
| 1774 | } |
| 1775 | |
| 1776 | // Read and process a record. |
| 1777 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1778 | const char *BlobStart = 0; |
| 1779 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1780 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1781 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1782 | default: // Default behavior: ignore. |
| 1783 | break; |
| 1784 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1785 | case METADATA: { |
| 1786 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1787 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1788 | : diag::warn_pch_version_too_new); |
| 1789 | return IgnorePCH; |
| 1790 | } |
| 1791 | |
| 1792 | RelocatablePCH = Record[4]; |
| 1793 | if (Listener) { |
| 1794 | std::string TargetTriple(BlobStart, BlobLen); |
| 1795 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1796 | return IgnorePCH; |
| 1797 | } |
| 1798 | break; |
| 1799 | } |
| 1800 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1801 | case IMPORTS: { |
| 1802 | // Load each of the imported PCH files. |
| 1803 | unsigned Idx = 0, N = Record.size(); |
| 1804 | while (Idx < N) { |
| 1805 | // Read information about the AST file. |
| 1806 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1807 | unsigned Length = Record[Idx++]; |
| 1808 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1809 | Record.begin() + Idx + Length); |
| 1810 | Idx += Length; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1811 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1812 | // Load the AST file. |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1813 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1814 | case Failure: return Failure; |
| 1815 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1816 | case IgnorePCH: return IgnorePCH; |
| 1817 | case Success: break; |
| 1818 | } |
| 1819 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | } |
| 1822 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1823 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1824 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1825 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1826 | return Failure; |
| 1827 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1828 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1829 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1830 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1831 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1832 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1833 | if (F.LocalNumTypes > 0) { |
| 1834 | // Introduce the global -> local mapping for types within this module. |
| 1835 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1836 | |
| 1837 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1838 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 1839 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1840 | |
| 1841 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1842 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1843 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1844 | } |
| 1845 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1846 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1847 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1848 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1849 | return Failure; |
| 1850 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1851 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1852 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1853 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1854 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1855 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1856 | if (F.LocalNumDecls > 0) { |
| 1857 | // Introduce the global -> local mapping for declarations within this |
| 1858 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1859 | GlobalDeclMap.insert( |
| 1860 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1861 | |
| 1862 | // Introduce the local -> global mapping for declarations within this |
| 1863 | // module. |
| 1864 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 1865 | F.BaseDeclID - LocalBaseDeclID)); |
| 1866 | |
| 1867 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1868 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1869 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1870 | } |
| 1871 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1872 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1873 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1874 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1875 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1876 | Info.NumLexicalDecls |
| 1877 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1878 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1879 | break; |
| 1880 | } |
| 1881 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1882 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1883 | unsigned Idx = 0; |
| 1884 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1885 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1886 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1887 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1888 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1889 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1890 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1891 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1892 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1893 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1894 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1895 | break; |
| 1896 | } |
| 1897 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1898 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1899 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1900 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 1901 | DeclID First = ReadDeclID(F, Record, i); |
| 1902 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | a865005 | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1903 | FirstLatestDeclIDs[First] = Latest; |
| 1904 | } |
| 1905 | break; |
| 1906 | } |
| 1907 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1908 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1909 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1910 | return IgnorePCH; |
| 1911 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1912 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1913 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1914 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1915 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1916 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1917 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1918 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1919 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1920 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1921 | |
| 1922 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1923 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1926 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1927 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1928 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1929 | return Failure; |
| 1930 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1931 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1932 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1933 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1934 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 1935 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1936 | if (F.LocalNumIdentifiers > 0) { |
| 1937 | // Introduce the global -> local mapping for identifiers within this |
| 1938 | // module. |
| 1939 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 1940 | &F)); |
| 1941 | |
| 1942 | // Introduce the local -> global mapping for identifiers within this |
| 1943 | // module. |
| 1944 | F.IdentifierRemap.insert( |
| 1945 | std::make_pair(LocalBaseIdentifierID, |
| 1946 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 1947 | |
| 1948 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 1949 | + F.LocalNumIdentifiers); |
| 1950 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1951 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1954 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1955 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1956 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1957 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1958 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1959 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1960 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1961 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1962 | break; |
| 1963 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1964 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1965 | TotalNumStatements += Record[0]; |
| 1966 | TotalNumMacros += Record[1]; |
| 1967 | TotalLexicalDeclContexts += Record[2]; |
| 1968 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1969 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1970 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1971 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1972 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1973 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1974 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1975 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1976 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1977 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1978 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1979 | break; |
| 1980 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1981 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 1982 | if (Record.size() % 4 != 0) { |
| 1983 | Error("invalid weak identifiers record"); |
| 1984 | return Failure; |
| 1985 | } |
| 1986 | |
| 1987 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 1988 | // files. This isn't the way to do it :) |
| 1989 | WeakUndeclaredIdentifiers.clear(); |
| 1990 | |
| 1991 | // Translate the weak, undeclared identifiers into global IDs. |
| 1992 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 1993 | WeakUndeclaredIdentifiers.push_back( |
| 1994 | getGlobalIdentifierID(F, Record[I++])); |
| 1995 | WeakUndeclaredIdentifiers.push_back( |
| 1996 | getGlobalIdentifierID(F, Record[I++])); |
| 1997 | WeakUndeclaredIdentifiers.push_back( |
| 1998 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 1999 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2000 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2001 | break; |
| 2002 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2003 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2004 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2005 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2006 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2007 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2008 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2009 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2010 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2011 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2012 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2013 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2014 | if (F.LocalNumSelectors > 0) { |
| 2015 | // Introduce the global -> local mapping for selectors within this |
| 2016 | // module. |
| 2017 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2018 | |
| 2019 | // Introduce the local -> global mapping for selectors within this |
| 2020 | // module. |
| 2021 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 2022 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2023 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2024 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2025 | } |
| 2026 | break; |
| 2027 | } |
| 2028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2029 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2030 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2031 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2032 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2033 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2034 | F.SelectorLookupTableData + Record[0], |
| 2035 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2036 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2037 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2038 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2039 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2040 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2041 | if (!Record.empty()) { |
| 2042 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2043 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2044 | Record[Idx++])); |
| 2045 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2046 | getRawEncoding()); |
| 2047 | } |
| 2048 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2051 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2052 | if (!Record.empty() && Listener) |
| 2053 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2054 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2055 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2056 | case SOURCE_LOCATION_OFFSETS: { |
| 2057 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2058 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2059 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2060 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2061 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2062 | // we invert it. Because we invert it, though, we need the other end of |
| 2063 | // the range. |
| 2064 | unsigned RangeStart = |
| 2065 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2066 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2067 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2068 | |
| 2069 | // Initialize the remapping table. |
| 2070 | // Invalid stays invalid. |
| 2071 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2072 | // This module. Base was 2 when being compiled. |
| 2073 | F.SLocRemap.insert(std::make_pair(2U, |
| 2074 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2075 | |
| 2076 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2077 | break; |
| 2078 | } |
| 2079 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2080 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2081 | // Additional remapping information. |
| 2082 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2083 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2084 | |
| 2085 | // Continuous range maps we may be updating in our module. |
| 2086 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2087 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2088 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2089 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2090 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2091 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2092 | MacroDefinitionRemap(F.MacroDefinitionRemap); |
| 2093 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2094 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2095 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2096 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2097 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2098 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2099 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2100 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2101 | Data += Len; |
Jonathan D. Turner | 48d2c3f | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2102 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2103 | if (!OM) { |
| 2104 | Error("SourceLocation remap refers to unknown module"); |
| 2105 | return Failure; |
| 2106 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2107 | |
| 2108 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2109 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2110 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
| 2111 | uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data); |
| 2112 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2113 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2114 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2115 | |
| 2116 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2117 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2118 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2119 | IdentifierRemap.insert( |
| 2120 | std::make_pair(IdentifierIDOffset, |
| 2121 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2122 | PreprocessedEntityRemap.insert( |
| 2123 | std::make_pair(PreprocessedEntityIDOffset, |
| 2124 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2125 | MacroDefinitionRemap.insert( |
| 2126 | std::make_pair(MacroDefinitionIDOffset, |
| 2127 | OM->BaseMacroDefinitionID - MacroDefinitionIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2128 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2129 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2130 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2131 | OM->BaseDeclID - DeclIDOffset)); |
| 2132 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2133 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2134 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2135 | } |
| 2136 | break; |
| 2137 | } |
| 2138 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2139 | case SOURCE_MANAGER_LINE_TABLE: |
| 2140 | if (ParseLineTable(F, Record)) |
| 2141 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2142 | break; |
| 2143 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2144 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2145 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2146 | F.LocalNumSLocFileEntries = Record[0]; |
| 2147 | break; |
| 2148 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2149 | case SOURCE_LOCATION_PRELOADS: { |
| 2150 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2151 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2152 | if (!F.PreloadSLocEntries.empty()) { |
| 2153 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2154 | return Failure; |
| 2155 | } |
| 2156 | |
| 2157 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2158 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2159 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2160 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2161 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2162 | if (!DisableStatCache) { |
| 2163 | ASTStatCache *MyStatCache = |
| 2164 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2165 | (const unsigned char *)BlobStart, |
| 2166 | NumStatHits, NumStatMisses); |
| 2167 | FileMgr.addStatCache(MyStatCache); |
| 2168 | F.StatCache = MyStatCache; |
| 2169 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2170 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2171 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2172 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2173 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2174 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2175 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2176 | break; |
| 2177 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2178 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2179 | if (Record.size() % 3 != 0) { |
| 2180 | Error("Invalid VTABLE_USES record"); |
| 2181 | return Failure; |
| 2182 | } |
| 2183 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2184 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2185 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2186 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2187 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2188 | |
| 2189 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2190 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2191 | VTableUses.push_back( |
| 2192 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2193 | VTableUses.push_back(Record[Idx++]); |
| 2194 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2195 | break; |
| 2196 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2197 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2198 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2199 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2200 | break; |
| 2201 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2202 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2203 | if (PendingInstantiations.size() % 2 != 0) { |
| 2204 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2205 | return Failure; |
| 2206 | } |
| 2207 | |
| 2208 | // Later lists of pending instantiations overwrite earlier ones. |
| 2209 | // FIXME: This is most certainly wrong for modules. |
| 2210 | PendingInstantiations.clear(); |
| 2211 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2212 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2213 | PendingInstantiations.push_back( |
| 2214 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2215 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2216 | break; |
| 2217 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2218 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2219 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2220 | // FIXME: Modules will have some trouble with this. |
| 2221 | SemaDeclRefs.clear(); |
| 2222 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2223 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2224 | break; |
| 2225 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2226 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2227 | // 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] | 2228 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2229 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2230 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2231 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2232 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2234 | case ORIGINAL_FILE_ID: |
| 2235 | OriginalFileID = FileID::get(Record[0]); |
| 2236 | break; |
| 2237 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2238 | case ORIGINAL_PCH_DIR: |
| 2239 | // The primary AST will be the last to get here, so it will be the one |
| 2240 | // that's used. |
| 2241 | OriginalDir.assign(BlobStart, BlobLen); |
| 2242 | break; |
| 2243 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2244 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2245 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2246 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2247 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2248 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2249 | return IgnorePCH; |
| 2250 | } |
| 2251 | break; |
| 2252 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2253 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2254 | case MACRO_DEFINITION_OFFSETS: { |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2255 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2256 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2257 | unsigned LocalBasePreprocessedEntityID = Record[1]; |
| 2258 | F.LocalNumMacroDefinitions = Record[2]; |
| 2259 | unsigned LocalBaseMacroID = Record[3]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2261 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2262 | if (!PP.getPreprocessingRecord()) |
| 2263 | PP.createPreprocessingRecord(true); |
| 2264 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2265 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2266 | StartingID |
| 2267 | = PP.getPreprocessingRecord() |
| 2268 | ->allocateLoadedEntities(F.NumPreallocatedPreprocessingEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2269 | F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); |
| 2270 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2271 | |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2272 | if (F.NumPreallocatedPreprocessingEntities > 0) { |
| 2273 | // Introduce the global -> local mapping for preprocessed entities in |
| 2274 | // this module. |
| 2275 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2276 | |
| 2277 | // Introduce the local -> global mapping for preprocessed entities in |
| 2278 | // this module. |
| 2279 | F.PreprocessedEntityRemap.insert( |
| 2280 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2281 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2282 | } |
| 2283 | |
| 2284 | |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2285 | if (F.LocalNumMacroDefinitions > 0) { |
| 2286 | // Introduce the global -> local mapping for macro definitions within |
| 2287 | // this module. |
| 2288 | GlobalMacroDefinitionMap.insert( |
| 2289 | std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); |
| 2290 | |
| 2291 | // Introduce the local -> global mapping for macro definitions within |
| 2292 | // this module. |
| 2293 | F.MacroDefinitionRemap.insert( |
| 2294 | std::make_pair(LocalBaseMacroID, |
| 2295 | F.BaseMacroDefinitionID - LocalBaseMacroID)); |
| 2296 | |
| 2297 | MacroDefinitionsLoaded.resize( |
Douglas Gregor | 14ad03b | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 2298 | MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2301 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2304 | case DECL_UPDATE_OFFSETS: { |
| 2305 | if (Record.size() % 2 != 0) { |
| 2306 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2307 | return Failure; |
| 2308 | } |
| 2309 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2310 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2311 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2312 | break; |
| 2313 | } |
| 2314 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2315 | case DECL_REPLACEMENTS: { |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2316 | if (Record.size() % 2 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2317 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2318 | return Failure; |
| 2319 | } |
| 2320 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2321 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2322 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2323 | break; |
| 2324 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2325 | |
| 2326 | case OBJC_CHAINED_CATEGORIES: { |
| 2327 | if (Record.size() % 3 != 0) { |
| 2328 | Error("invalid OBJC_CHAINED_CATEGORIES block in AST file"); |
| 2329 | return Failure; |
| 2330 | } |
| 2331 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) { |
| 2332 | serialization::GlobalDeclID GlobID = getGlobalDeclID(F, Record[I]); |
| 2333 | F.ChainedObjCCategories[GlobID] = std::make_pair(Record[I+1], |
| 2334 | Record[I+2]); |
| 2335 | ObjCChainedCategoriesInterfaces.insert(GlobID); |
| 2336 | } |
| 2337 | break; |
| 2338 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2339 | |
| 2340 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2341 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2342 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2343 | return Failure; |
| 2344 | } |
| 2345 | |
| 2346 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2347 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2348 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2349 | break; |
| 2350 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2351 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2352 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2353 | if (Record.size() % 2 != 0) { |
| 2354 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2355 | return Failure; |
| 2356 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2357 | |
| 2358 | if (F.PragmaDiagMappings.empty()) |
| 2359 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2360 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2361 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2362 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2363 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2364 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2365 | case CUDA_SPECIAL_DECL_REFS: |
| 2366 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2367 | // FIXME: Modules will have trouble with this. |
| 2368 | CUDASpecialDeclRefs.clear(); |
| 2369 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2370 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2371 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2372 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2373 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2374 | F.HeaderFileInfoTableData = BlobStart; |
| 2375 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2376 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2377 | if (Record[0]) { |
| 2378 | F.HeaderFileInfoTable |
| 2379 | = HeaderFileInfoLookupTable::Create( |
| 2380 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2381 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2382 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2383 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2384 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2385 | |
| 2386 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2387 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2388 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2389 | } |
| 2390 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2393 | case FP_PRAGMA_OPTIONS: |
| 2394 | // Later tables overwrite earlier ones. |
| 2395 | FPPragmaOptions.swap(Record); |
| 2396 | break; |
| 2397 | |
| 2398 | case OPENCL_EXTENSIONS: |
| 2399 | // Later tables overwrite earlier ones. |
| 2400 | OpenCLExtensions.swap(Record); |
| 2401 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2402 | |
| 2403 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2404 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2405 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2406 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2407 | |
| 2408 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2409 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2410 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2411 | break; |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2412 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2413 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2414 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2415 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2416 | } |
| 2417 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2418 | ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) { |
| 2419 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2420 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2421 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2422 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2423 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2424 | if (Code == llvm::bitc::END_BLOCK || |
| 2425 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2426 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2427 | Error("incorrectly-formatted source location entry in AST file"); |
| 2428 | return Failure; |
| 2429 | } |
| 2430 | |
| 2431 | RecordData Record; |
| 2432 | const char *BlobStart; |
| 2433 | unsigned BlobLen; |
| 2434 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2435 | default: |
| 2436 | Error("incorrectly-formatted source location entry in AST file"); |
| 2437 | return Failure; |
| 2438 | |
| 2439 | case SM_SLOC_FILE_ENTRY: { |
| 2440 | StringRef Filename(BlobStart, BlobLen); |
| 2441 | const FileEntry *File = getFileEntry(Filename); |
| 2442 | |
| 2443 | if (File == 0) { |
| 2444 | std::string ErrorStr = "could not find file '"; |
| 2445 | ErrorStr += Filename; |
| 2446 | ErrorStr += "' referenced by AST file"; |
| 2447 | Error(ErrorStr.c_str()); |
| 2448 | return IgnorePCH; |
| 2449 | } |
| 2450 | |
| 2451 | if (Record.size() < 6) { |
| 2452 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2453 | return Failure; |
| 2454 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2455 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2456 | // The stat info from the FileEntry came from the cached stat |
| 2457 | // info of the PCH, so we cannot trust it. |
| 2458 | struct stat StatBuf; |
| 2459 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2460 | StatBuf.st_size = File->getSize(); |
| 2461 | StatBuf.st_mtime = File->getModificationTime(); |
| 2462 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2463 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2464 | if (((off_t)Record[4] != StatBuf.st_size |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2465 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2466 | // In our regression testing, the Windows file system seems to |
| 2467 | // have inconsistent modification times that sometimes |
| 2468 | // erroneously trigger this error-handling path. |
| 2469 | || (time_t)Record[5] != StatBuf.st_mtime |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2470 | #endif |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2471 | )) { |
| 2472 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2473 | return IgnorePCH; |
| 2474 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2475 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2476 | break; |
| 2477 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | return Success; |
| 2482 | } |
| 2483 | |
Douglas Gregor | 46c03c3 | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2484 | namespace { |
| 2485 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 2486 | class IdentifierLookupVisitor { |
| 2487 | StringRef Name; |
| 2488 | IdentifierInfo *Found; |
| 2489 | public: |
| 2490 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
| 2491 | |
| 2492 | static bool visit(Module &M, void *UserData) { |
| 2493 | IdentifierLookupVisitor *This |
| 2494 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 2495 | |
| 2496 | ASTIdentifierLookupTable *IdTable |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 2497 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
Douglas Gregor | 46c03c3 | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2498 | if (!IdTable) |
| 2499 | return false; |
| 2500 | |
| 2501 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 2502 | This->Name.size()); |
| 2503 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2504 | if (Pos == IdTable->end()) |
| 2505 | return false; |
| 2506 | |
| 2507 | // Dereferencing the iterator has the effect of building the |
| 2508 | // IdentifierInfo node and populating it with the various |
| 2509 | // declarations it needs. |
| 2510 | This->Found = *Pos; |
| 2511 | return true; |
| 2512 | } |
| 2513 | |
| 2514 | // \brief Retrieve the identifier info found within the module |
| 2515 | // files. |
| 2516 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 2517 | }; |
| 2518 | } |
| 2519 | |
| 2520 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2521 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2522 | ModuleKind Type) { |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2523 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2524 | case Failure: return Failure; |
| 2525 | case IgnorePCH: return IgnorePCH; |
| 2526 | case Success: break; |
| 2527 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2528 | |
| 2529 | // 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] | 2530 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2531 | // Check the predefines buffers. |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 2532 | if (!DisableValidation && Type != MK_Module && Type != MK_Preamble && |
| 2533 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2534 | // if DisableValidation is true, defines that were set on command-line |
| 2535 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2536 | CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2537 | return IgnorePCH; |
| 2538 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2539 | // Initialization of keywords and pragmas occurs before the |
| 2540 | // AST file is read, so there may be some identifiers that were |
| 2541 | // loaded into the IdentifierTable before we intercepted the |
| 2542 | // creation of identifiers. Iterate through the list of known |
| 2543 | // identifiers and determine whether we have to establish |
| 2544 | // preprocessor definitions or top-level identifier declaration |
| 2545 | // chains for those identifiers. |
| 2546 | // |
| 2547 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2548 | // since de-serializing declarations or macro definitions can add |
| 2549 | // new entries into the identifier table, invalidating the |
| 2550 | // iterators. |
| 2551 | // |
| 2552 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2553 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2554 | // AST file(s) if it is uttered in the source. This could save us some |
| 2555 | // module load time. |
| 2556 | SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2557 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2558 | IdEnd = PP.getIdentifierTable().end(); |
| 2559 | Id != IdEnd; ++Id) |
| 2560 | Identifiers.push_back(Id->second); |
| 2561 | |
| 2562 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2563 | IdentifierLookupVisitor Visitor(Identifiers[I]->getName()); |
| 2564 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2567 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2568 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2569 | if (DeserializationListener) |
| 2570 | DeserializationListener->ReaderInitialized(this); |
| 2571 | |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2572 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2573 | // the source manager to the file source file from which the preamble was |
| 2574 | // built. This is the only valid way to use a precompiled preamble. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2575 | if (Type == MK_Preamble) { |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2576 | if (OriginalFileID.isInvalid()) { |
| 2577 | SourceLocation Loc |
| 2578 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2579 | if (Loc.isValid()) |
| 2580 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2581 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2582 | else { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2583 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2584 | + OriginalFileID.getOpaqueValue() - 1); |
| 2585 | } |
| 2586 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2587 | if (!OriginalFileID.isInvalid()) |
| 2588 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2591 | return Success; |
| 2592 | } |
| 2593 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2594 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2595 | ModuleKind Type, |
| 2596 | Module *ImportedBy) { |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2597 | Module *M; |
| 2598 | bool NewModule; |
| 2599 | std::string ErrorStr; |
| 2600 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2601 | ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2602 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2603 | if (!M) { |
| 2604 | // We couldn't load the module. |
| 2605 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2606 | + ErrorStr; |
| 2607 | Error(Msg); |
| 2608 | return Failure; |
| 2609 | } |
| 2610 | |
| 2611 | if (!NewModule) { |
| 2612 | // We've already loaded this module. |
| 2613 | return Success; |
| 2614 | } |
| 2615 | |
| 2616 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2617 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2618 | if (FileName != "-") { |
| 2619 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2620 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2621 | } |
| 2622 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2623 | Module &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2624 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2625 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2626 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2627 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2628 | // Sniff for the signature. |
| 2629 | if (Stream.Read(8) != 'C' || |
| 2630 | Stream.Read(8) != 'P' || |
| 2631 | Stream.Read(8) != 'C' || |
| 2632 | Stream.Read(8) != 'H') { |
| 2633 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2634 | return Failure; |
| 2635 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2636 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2637 | while (!Stream.AtEndOfStream()) { |
| 2638 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2639 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2640 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2641 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2642 | return Failure; |
| 2643 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2644 | |
| 2645 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2646 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2647 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2648 | switch (BlockID) { |
| 2649 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2650 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2651 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2652 | return Failure; |
| 2653 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2654 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2655 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2656 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2657 | case Success: |
| 2658 | break; |
| 2659 | |
| 2660 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2661 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2662 | |
| 2663 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2664 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2665 | // AST block, skipping subblocks, to see if there are other |
| 2666 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2667 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2668 | // FIXME: We can't clear loaded slocentries anymore. |
| 2669 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2670 | |
| 2671 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2672 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2673 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2674 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2675 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2676 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2679 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2680 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2681 | return Failure; |
| 2682 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2683 | break; |
| 2684 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2685 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2686 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2687 | // 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] | 2688 | // bits of all files we've seen. |
| 2689 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2690 | TotalModulesSizeInBits += F.SizeInBits; |
| 2691 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2692 | |
| 2693 | // Make sure that the files this module was built against are still available. |
| 2694 | if (!DisableValidation) { |
| 2695 | switch(validateFileEntries(*M)) { |
| 2696 | case Failure: return Failure; |
| 2697 | case IgnorePCH: return IgnorePCH; |
| 2698 | case Success: break; |
| 2699 | } |
| 2700 | } |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2701 | |
| 2702 | // Preload SLocEntries. |
| 2703 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2704 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 2705 | ASTReadResult Result = ReadSLocEntryRecord(Index); |
| 2706 | if (Result != Success) |
| 2707 | return Failure; |
| 2708 | } |
| 2709 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2710 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2711 | return Success; |
| 2712 | } |
| 2713 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2714 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2715 | // If there's a listener, notify them that we "read" the translation unit. |
| 2716 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2717 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2718 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2719 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2720 | // Make sure we load the declaration update records for the translation unit, |
| 2721 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2722 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2723 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2724 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2725 | // FIXME: Find a better way to deal with collisions between these |
| 2726 | // built-in types. Right now, we just ignore the problem. |
| 2727 | |
| 2728 | // Load the special types. |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2729 | if (SpecialTypes.size() > NumSpecialTypeIDs) { |
| 2730 | if (Context.getBuiltinVaListType().isNull()) { |
| 2731 | Context.setBuiltinVaListType( |
| 2732 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2735 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2736 | if (Context.ObjCProtoType.isNull()) |
| 2737 | Context.ObjCProtoType = GetType(Proto); |
| 2738 | } |
| 2739 | |
| 2740 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2741 | if (!Context.CFConstantStringTypeDecl) |
| 2742 | Context.setCFConstantStringType(GetType(String)); |
| 2743 | } |
| 2744 | |
| 2745 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2746 | QualType FileType = GetType(File); |
| 2747 | if (FileType.isNull()) { |
| 2748 | Error("FILE type is NULL"); |
| 2749 | return; |
| 2750 | } |
| 2751 | |
| 2752 | if (!Context.FILEDecl) { |
| 2753 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2754 | Context.setFILEDecl(Typedef->getDecl()); |
| 2755 | else { |
| 2756 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2757 | if (!Tag) { |
| 2758 | Error("Invalid FILE type in AST file"); |
| 2759 | return; |
| 2760 | } |
| 2761 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2762 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2763 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2764 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2765 | |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2766 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 2767 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2768 | if (Jmp_bufType.isNull()) { |
| 2769 | Error("jmp_buf type is NULL"); |
| 2770 | return; |
| 2771 | } |
| 2772 | |
| 2773 | if (!Context.jmp_bufDecl) { |
| 2774 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2775 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2776 | else { |
| 2777 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2778 | if (!Tag) { |
| 2779 | Error("Invalid jmp_buf type in AST file"); |
| 2780 | return; |
| 2781 | } |
| 2782 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2783 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2784 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2785 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2786 | |
| 2787 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 2788 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2789 | if (Sigjmp_bufType.isNull()) { |
| 2790 | Error("sigjmp_buf type is NULL"); |
| 2791 | return; |
| 2792 | } |
| 2793 | |
| 2794 | if (!Context.sigjmp_bufDecl) { |
| 2795 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2796 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2797 | else { |
| 2798 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2799 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2800 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2801 | } |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | if (unsigned ObjCIdRedef |
| 2806 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2807 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2808 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2809 | } |
| 2810 | |
| 2811 | if (unsigned ObjCClassRedef |
| 2812 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2813 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2814 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2815 | } |
| 2816 | |
| 2817 | if (unsigned ObjCSelRedef |
| 2818 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2819 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2820 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2821 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2822 | } |
| 2823 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2824 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2825 | |
| 2826 | // If there were any CUDA special declarations, deserialize them. |
| 2827 | if (!CUDASpecialDeclRefs.empty()) { |
| 2828 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2829 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2830 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2831 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2834 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2835 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2836 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2837 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2838 | FileManager &FileMgr, |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2839 | Diagnostic &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2840 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2841 | std::string ErrStr; |
| 2842 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2843 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2844 | if (!Buffer) { |
Daniel Dunbar | 93ebb1b | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2845 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2846 | return std::string(); |
| 2847 | } |
| 2848 | |
| 2849 | // Initialize the stream |
| 2850 | llvm::BitstreamReader StreamFile; |
| 2851 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2852 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2853 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2854 | Stream.init(StreamFile); |
| 2855 | |
| 2856 | // Sniff for the signature. |
| 2857 | if (Stream.Read(8) != 'C' || |
| 2858 | Stream.Read(8) != 'P' || |
| 2859 | Stream.Read(8) != 'C' || |
| 2860 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2861 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2862 | return std::string(); |
| 2863 | } |
| 2864 | |
| 2865 | RecordData Record; |
| 2866 | while (!Stream.AtEndOfStream()) { |
| 2867 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2868 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2869 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2870 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2871 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2872 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2873 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2874 | case AST_BLOCK_ID: |
| 2875 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2876 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2877 | return std::string(); |
| 2878 | } |
| 2879 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2880 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2881 | default: |
| 2882 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2883 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2884 | return std::string(); |
| 2885 | } |
| 2886 | break; |
| 2887 | } |
| 2888 | continue; |
| 2889 | } |
| 2890 | |
| 2891 | if (Code == llvm::bitc::END_BLOCK) { |
| 2892 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2893 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2894 | return std::string(); |
| 2895 | } |
| 2896 | continue; |
| 2897 | } |
| 2898 | |
| 2899 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2900 | Stream.ReadAbbrevRecord(); |
| 2901 | continue; |
| 2902 | } |
| 2903 | |
| 2904 | Record.clear(); |
| 2905 | const char *BlobStart = 0; |
| 2906 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2907 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2908 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2909 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2910 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2911 | |
| 2912 | return std::string(); |
| 2913 | } |
| 2914 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2915 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2916 | /// structure. |
| 2917 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2918 | /// This routine parses the language options from the AST file and then gives |
| 2919 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2920 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2921 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2922 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2923 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2924 | if (Listener) { |
| 2925 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2926 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 2927 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 2928 | LangOpts.Name = Record[Idx++]; |
| 2929 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 2930 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 2931 | #include "clang/Basic/LangOptions.def" |
| 2932 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2933 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2934 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2935 | |
| 2936 | return false; |
| 2937 | } |
| 2938 | |
Douglas Gregor | b95cd09 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 2939 | namespace { |
| 2940 | /// \brief Visitor used by ASTReader::ReadPreprocessedEntities() to load |
| 2941 | /// all of the preprocessed entities within a module. |
| 2942 | class ReadPreprocessedEntitiesVisitor { |
| 2943 | ASTReader &Reader; |
| 2944 | |
| 2945 | public: |
| 2946 | explicit ReadPreprocessedEntitiesVisitor(ASTReader &Reader) |
| 2947 | : Reader(Reader) { } |
| 2948 | |
| 2949 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 2950 | if (Preorder) |
| 2951 | return false; |
| 2952 | |
| 2953 | ReadPreprocessedEntitiesVisitor *This |
| 2954 | = static_cast<ReadPreprocessedEntitiesVisitor *>(UserData); |
| 2955 | |
| 2956 | if (!M.PreprocessorDetailCursor.getBitStreamReader()) |
| 2957 | return false; |
| 2958 | |
| 2959 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 2960 | M.PreprocessorDetailCursor.JumpToBit(M.PreprocessorDetailStartOffset); |
| 2961 | while (This->Reader.LoadPreprocessedEntity(M)) { } |
| 2962 | return false; |
| 2963 | } |
| 2964 | }; |
| 2965 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2966 | |
Douglas Gregor | b95cd09 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 2967 | void ASTReader::ReadPreprocessedEntities() { |
| 2968 | ReadPreprocessedEntitiesVisitor Visitor(*this); |
| 2969 | ModuleMgr.visitDepthFirst(&ReadPreprocessedEntitiesVisitor::visit, &Visitor); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
Douglas Gregor | 0a48029 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 2972 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2973 | RecordLocation Loc = getLocalBitOffset(Offset); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2975 | // Keep track of where we are in the stream, then jump back there |
| 2976 | // after reading this entity. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2977 | SavedStreamPosition SavedPosition(Loc.F->PreprocessorDetailCursor); |
| 2978 | Loc.F->PreprocessorDetailCursor.JumpToBit(Loc.Offset); |
| 2979 | return LoadPreprocessedEntity(*Loc.F); |
Douglas Gregor | 89d9980 | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 2982 | namespace { |
| 2983 | /// \brief Visitor used to search for information about a header file. |
| 2984 | class HeaderFileInfoVisitor { |
| 2985 | ASTReader &Reader; |
| 2986 | const FileEntry *FE; |
| 2987 | |
| 2988 | llvm::Optional<HeaderFileInfo> HFI; |
| 2989 | |
| 2990 | public: |
| 2991 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 2992 | : Reader(Reader), FE(FE) { } |
| 2993 | |
| 2994 | static bool visit(Module &M, void *UserData) { |
| 2995 | HeaderFileInfoVisitor *This |
| 2996 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 2997 | |
| 2998 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 2999 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3000 | M.HeaderFileFrameworkStrings, |
| 3001 | This->FE->getName()); |
| 3002 | |
| 3003 | HeaderFileInfoLookupTable *Table |
| 3004 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3005 | if (!Table) |
| 3006 | return false; |
| 3007 | |
| 3008 | // Look in the on-disk hash table for an entry for this file name. |
| 3009 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3010 | &Trait); |
| 3011 | if (Pos == Table->end()) |
| 3012 | return false; |
| 3013 | |
| 3014 | This->HFI = *Pos; |
| 3015 | return true; |
| 3016 | } |
| 3017 | |
| 3018 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3019 | }; |
| 3020 | } |
| 3021 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3022 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3023 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3024 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3025 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3026 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3027 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3028 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3029 | } |
| 3030 | |
| 3031 | return HeaderFileInfo(); |
| 3032 | } |
| 3033 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3034 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3035 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3036 | Module &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3037 | unsigned Idx = 0; |
| 3038 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3039 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3040 | while (1) { |
| 3041 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3042 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3043 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3044 | break; // Something is messed up but at least avoid infinite loop in |
| 3045 | // release build. |
| 3046 | } |
| 3047 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3048 | if (DiagID == (unsigned)-1) { |
| 3049 | break; // no more diag/map pairs for this location. |
| 3050 | } |
| 3051 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3052 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3053 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3054 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3055 | } |
| 3056 | } |
| 3057 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3058 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3059 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3060 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3061 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3062 | Module *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3063 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3064 | } |
| 3065 | |
| 3066 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3067 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3068 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3069 | /// routine actually reads the record corresponding to the type at the given |
| 3070 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3071 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3072 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3073 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3074 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3075 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3076 | // Keep track of where we are in the stream, then jump back there |
| 3077 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3078 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3079 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3080 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3081 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3082 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3083 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3084 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3085 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3086 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3087 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3088 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3089 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3090 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3091 | if (Record.size() != 2) { |
| 3092 | Error("Incorrect encoding of extended qualifier type"); |
| 3093 | return QualType(); |
| 3094 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3095 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3096 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3097 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3098 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3099 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3100 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3101 | if (Record.size() != 1) { |
| 3102 | Error("Incorrect encoding of complex type"); |
| 3103 | return QualType(); |
| 3104 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3105 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3106 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3107 | } |
| 3108 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3109 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3110 | if (Record.size() != 1) { |
| 3111 | Error("Incorrect encoding of pointer type"); |
| 3112 | return QualType(); |
| 3113 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3114 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3115 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3116 | } |
| 3117 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3118 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3119 | if (Record.size() != 1) { |
| 3120 | Error("Incorrect encoding of block pointer type"); |
| 3121 | return QualType(); |
| 3122 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3123 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3124 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3127 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3128 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3129 | Error("Incorrect encoding of lvalue reference type"); |
| 3130 | return QualType(); |
| 3131 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3132 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3133 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3134 | } |
| 3135 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3136 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3137 | if (Record.size() != 1) { |
| 3138 | Error("Incorrect encoding of rvalue reference type"); |
| 3139 | return QualType(); |
| 3140 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3141 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3142 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3145 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3146 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3147 | Error("Incorrect encoding of member pointer type"); |
| 3148 | return QualType(); |
| 3149 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3150 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3151 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3152 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3153 | return QualType(); |
| 3154 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3155 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3158 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3159 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3160 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3161 | unsigned IndexTypeQuals = Record[2]; |
| 3162 | unsigned Idx = 3; |
| 3163 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3164 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3165 | ASM, IndexTypeQuals); |
| 3166 | } |
| 3167 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3168 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3169 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3170 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3171 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3172 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3173 | } |
| 3174 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3175 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3176 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3177 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3178 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3179 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3180 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3181 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3182 | ASM, IndexTypeQuals, |
| 3183 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3184 | } |
| 3185 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3186 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3187 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3188 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3189 | return QualType(); |
| 3190 | } |
| 3191 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3192 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3193 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3194 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3195 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3196 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3199 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3200 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3201 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3202 | return QualType(); |
| 3203 | } |
| 3204 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3205 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3206 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3207 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3210 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3211 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3212 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3213 | return QualType(); |
| 3214 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3215 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3216 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3217 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3218 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3219 | } |
| 3220 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3221 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3222 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3223 | |
| 3224 | FunctionProtoType::ExtProtoInfo EPI; |
| 3225 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3226 | /*hasregparm*/ Record[2], |
| 3227 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3228 | static_cast<CallingConv>(Record[4]), |
| 3229 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3230 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3231 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3232 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3233 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3234 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3235 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3236 | |
| 3237 | EPI.Variadic = Record[Idx++]; |
| 3238 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3239 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3240 | ExceptionSpecificationType EST = |
| 3241 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3242 | EPI.ExceptionSpecType = EST; |
| 3243 | if (EST == EST_Dynamic) { |
| 3244 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3245 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3246 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3247 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3248 | EPI.Exceptions = Exceptions.data(); |
| 3249 | } else if (EST == EST_ComputedNoexcept) { |
| 3250 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3251 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3252 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3253 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3254 | } |
| 3255 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3256 | case TYPE_UNRESOLVED_USING: { |
| 3257 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3258 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3259 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3260 | } |
| 3261 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3262 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3263 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3264 | Error("incorrect encoding of typedef type"); |
| 3265 | return QualType(); |
| 3266 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3267 | unsigned Idx = 0; |
| 3268 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3269 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3270 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3271 | Canonical = Context.getCanonicalType(Canonical); |
| 3272 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3273 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3274 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3275 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3276 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3277 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3278 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3279 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3280 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3281 | return QualType(); |
| 3282 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3283 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3284 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3285 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3286 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3287 | case TYPE_DECLTYPE: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3288 | return Context.getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3289 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3290 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3291 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3292 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3293 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3294 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3295 | } |
| 3296 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3297 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3298 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3299 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3300 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3301 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3302 | Error("incorrect encoding of record type"); |
| 3303 | return QualType(); |
| 3304 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3305 | unsigned Idx = 0; |
| 3306 | bool IsDependent = Record[Idx++]; |
| 3307 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3308 | = Context.getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3309 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3310 | return T; |
| 3311 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3312 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3313 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3314 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3315 | Error("incorrect encoding of enum type"); |
| 3316 | return QualType(); |
| 3317 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3318 | unsigned Idx = 0; |
| 3319 | bool IsDependent = Record[Idx++]; |
| 3320 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3321 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3322 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3323 | return T; |
| 3324 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3325 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3326 | case TYPE_ATTRIBUTED: { |
| 3327 | if (Record.size() != 3) { |
| 3328 | Error("incorrect encoding of attributed type"); |
| 3329 | return QualType(); |
| 3330 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3331 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3332 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3333 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3334 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3335 | } |
| 3336 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3337 | case TYPE_PAREN: { |
| 3338 | if (Record.size() != 1) { |
| 3339 | Error("incorrect encoding of paren type"); |
| 3340 | return QualType(); |
| 3341 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3342 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3343 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3346 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3347 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3348 | Error("incorrect encoding of pack expansion type"); |
| 3349 | return QualType(); |
| 3350 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3351 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3352 | if (Pattern.isNull()) |
| 3353 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3354 | llvm::Optional<unsigned> NumExpansions; |
| 3355 | if (Record[1]) |
| 3356 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3357 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3360 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3361 | unsigned Idx = 0; |
| 3362 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3363 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3364 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3365 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3368 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3369 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3370 | ObjCInterfaceDecl *ItfD |
| 3371 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3372 | return Context.getObjCInterfaceType(ItfD); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3375 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3376 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3377 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3378 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3379 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3380 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3381 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3382 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3383 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3384 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3385 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3386 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3387 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3388 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3389 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3390 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3391 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3392 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3393 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3394 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3395 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3396 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3397 | Replacement); |
| 3398 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3399 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3400 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3401 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3402 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3403 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3404 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3405 | cast<TemplateTypeParmType>(Parm), |
| 3406 | ArgPack); |
| 3407 | } |
| 3408 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3409 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3410 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3411 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3412 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3413 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3414 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3415 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3416 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3417 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3418 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3419 | unsigned Idx = 0; |
| 3420 | unsigned Depth = Record[Idx++]; |
| 3421 | unsigned Index = Record[Idx++]; |
| 3422 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3423 | TemplateTypeParmDecl *D |
| 3424 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3425 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3426 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3427 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3428 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3429 | unsigned Idx = 0; |
| 3430 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3431 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3432 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3433 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3434 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3435 | Canon = Context.getCanonicalType(Canon); |
| 3436 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3437 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3438 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3439 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3440 | unsigned Idx = 0; |
| 3441 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3442 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3443 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3444 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3445 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3446 | Args.reserve(NumArgs); |
| 3447 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3448 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3449 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3450 | Args.size(), Args.data()); |
| 3451 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3452 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3453 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3454 | unsigned Idx = 0; |
| 3455 | |
| 3456 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3457 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3458 | ArrayType::ArraySizeModifier ASM |
| 3459 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3460 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3461 | |
| 3462 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3463 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3464 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3465 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3466 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3467 | IndexTypeQuals, Brackets); |
| 3468 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3469 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3470 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3471 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3472 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3473 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3474 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3475 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3476 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3477 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3478 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3479 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3480 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3481 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3482 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3483 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3484 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3485 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3486 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3487 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3488 | // Suppress a GCC warning |
| 3489 | return QualType(); |
| 3490 | } |
| 3491 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3492 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3493 | ASTReader &Reader; |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3494 | Module &F; |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3495 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3496 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3497 | unsigned &Idx; |
| 3498 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3499 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3500 | unsigned &I) { |
| 3501 | return Reader.ReadSourceLocation(F, R, I); |
| 3502 | } |
| 3503 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3504 | template<typename T> |
| 3505 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3506 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3507 | } |
| 3508 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3509 | public: |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3510 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3511 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3512 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3513 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3514 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3515 | // We want compile-time assurance that we've enumerated all of |
| 3516 | // these, so unfortunately we have to declare them first, then |
| 3517 | // define them out-of-line. |
| 3518 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3519 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3520 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3521 | #include "clang/AST/TypeLocNodes.def" |
| 3522 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3523 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3524 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3525 | }; |
| 3526 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3527 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3528 | // nothing to do |
| 3529 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3530 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3531 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3532 | if (TL.needsExtraLocalData()) { |
| 3533 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3534 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3535 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3536 | TL.setModeAttr(Record[Idx++]); |
| 3537 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3538 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3539 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3540 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3541 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3542 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3543 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3544 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3545 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3546 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3547 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3548 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3549 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3550 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3551 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3552 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3553 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3554 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3555 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3556 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3557 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3558 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3559 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3560 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3561 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3562 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3563 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3564 | TL.setSizeExpr(0); |
| 3565 | } |
| 3566 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3567 | VisitArrayTypeLoc(TL); |
| 3568 | } |
| 3569 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3570 | VisitArrayTypeLoc(TL); |
| 3571 | } |
| 3572 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3573 | VisitArrayTypeLoc(TL); |
| 3574 | } |
| 3575 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3576 | DependentSizedArrayTypeLoc TL) { |
| 3577 | VisitArrayTypeLoc(TL); |
| 3578 | } |
| 3579 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3580 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3581 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3582 | } |
| 3583 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3584 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3585 | } |
| 3586 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3587 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3588 | } |
| 3589 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3590 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3591 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3592 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3593 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3594 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3598 | VisitFunctionTypeLoc(TL); |
| 3599 | } |
| 3600 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3601 | VisitFunctionTypeLoc(TL); |
| 3602 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3603 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3604 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3605 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3606 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3607 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3608 | } |
| 3609 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3610 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3611 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3612 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3613 | } |
| 3614 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3615 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3616 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3617 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3618 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3619 | } |
| 3620 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3621 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3622 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3623 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3624 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3625 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3626 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3627 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3628 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3629 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3630 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3631 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3632 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3633 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3634 | } |
| 3635 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3636 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3637 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3638 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3639 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3640 | if (TL.hasAttrOperand()) { |
| 3641 | SourceRange range; |
| 3642 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3643 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3644 | TL.setAttrOperandParensRange(range); |
| 3645 | } |
| 3646 | if (TL.hasAttrExprOperand()) { |
| 3647 | if (Record[Idx++]) |
| 3648 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3649 | else |
| 3650 | TL.setAttrExprOperand(0); |
| 3651 | } else if (TL.hasAttrEnumOperand()) |
| 3652 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3653 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3654 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3655 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3656 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3657 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3658 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3659 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3660 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3661 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3662 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3663 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3664 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3665 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3666 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3667 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3668 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3669 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3670 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3671 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3672 | Reader.GetTemplateArgumentLocInfo(F, |
| 3673 | TL.getTypePtr()->getArg(i).getKind(), |
| 3674 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3675 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3676 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3677 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3678 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3679 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3680 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3681 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3682 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3683 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3684 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3685 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3686 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3687 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3688 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3689 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
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 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3692 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3693 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3694 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3695 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3696 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3697 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3698 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3699 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3700 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3701 | Reader.GetTemplateArgumentLocInfo(F, |
| 3702 | TL.getTypePtr()->getArg(I).getKind(), |
| 3703 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3704 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3705 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3706 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3707 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3708 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3709 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3710 | } |
| 3711 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3712 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3713 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3714 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3715 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3716 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3717 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3718 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3719 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3720 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3721 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3722 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3723 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3724 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3725 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3726 | if (InfoTy.isNull()) |
| 3727 | return 0; |
| 3728 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3729 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3730 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3731 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3732 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3733 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3734 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3735 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3736 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3737 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3738 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3739 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3740 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3741 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3742 | switch ((PredefinedTypeIDs)Index) { |
| 3743 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3744 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 3745 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3746 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3747 | case PREDEF_TYPE_CHAR_U_ID: |
| 3748 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3749 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3750 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3753 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 3754 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 3755 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 3756 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 3757 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 3758 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 3759 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 3760 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 3761 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 3762 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 3763 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 3764 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 3765 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
| 3766 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 3767 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 3768 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 3769 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 3770 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
| 3771 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 3772 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 3773 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 3774 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 3775 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 3776 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 3777 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 3778 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 3779 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3780 | |
| 3781 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3782 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3783 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3787 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3790 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3791 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3792 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3793 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3794 | if (TypesLoaded[Index].isNull()) |
| 3795 | return QualType(); |
| 3796 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3797 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3798 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3799 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3800 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3801 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3802 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3803 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3804 | } |
| 3805 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3806 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3807 | return GetType(getGlobalTypeID(F, LocalID)); |
| 3808 | } |
| 3809 | |
| 3810 | serialization::TypeID |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3811 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3812 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 3813 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 3814 | |
| 3815 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 3816 | return LocalID; |
| 3817 | |
| 3818 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 3819 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 3820 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 3821 | |
| 3822 | unsigned GlobalIndex = LocalIndex + I->second; |
| 3823 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 3824 | } |
| 3825 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3826 | TemplateArgumentLocInfo |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3827 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3828 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3829 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3830 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3831 | switch (Kind) { |
| 3832 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3833 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3834 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3835 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3836 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3837 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3838 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3839 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3840 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3841 | SourceLocation()); |
| 3842 | } |
| 3843 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3844 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3845 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3846 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3847 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3848 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3849 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3850 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3851 | case TemplateArgument::Null: |
| 3852 | case TemplateArgument::Integral: |
| 3853 | case TemplateArgument::Declaration: |
| 3854 | case TemplateArgument::Pack: |
| 3855 | return TemplateArgumentLocInfo(); |
| 3856 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3857 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3858 | return TemplateArgumentLocInfo(); |
| 3859 | } |
| 3860 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3861 | TemplateArgumentLoc |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3862 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3863 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3864 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3865 | |
| 3866 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3867 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3868 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3869 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3870 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3871 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3874 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3875 | return GetDecl(ID); |
| 3876 | } |
| 3877 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3878 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 3879 | unsigned &Idx){ |
| 3880 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3881 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3882 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 3883 | unsigned LocalID = Record[Idx++]; |
| 3884 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3888 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 3889 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3890 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3891 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3892 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3893 | RecordData Record; |
| 3894 | unsigned Code = Cursor.ReadCode(); |
| 3895 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 3896 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 3897 | Error("Malformed AST file: missing C++ base specifiers"); |
| 3898 | return 0; |
| 3899 | } |
| 3900 | |
| 3901 | unsigned Idx = 0; |
| 3902 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3903 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3904 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 3905 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3906 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3907 | return Bases; |
| 3908 | } |
| 3909 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3910 | serialization::DeclID |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3911 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3912 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3913 | return LocalID; |
| 3914 | |
| 3915 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3916 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3917 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 3918 | |
| 3919 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 3922 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 3923 | Module &M) const { |
| 3924 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 3925 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 3926 | return &M == I->second; |
| 3927 | } |
| 3928 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3929 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3930 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 3931 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3932 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3933 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3934 | |
| 3935 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3936 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 3937 | |
| 3938 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3939 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3940 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3941 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3942 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 3943 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 3944 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3945 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3946 | |
| 3947 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3948 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 3949 | |
| 3950 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3951 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 3952 | |
| 3953 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3954 | return Context.getObjCInstanceTypeDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3955 | } |
| 3956 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3957 | return 0; |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 3958 | } |
| 3959 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3960 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 3961 | |
| 3962 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3963 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3964 | return 0; |
| 3965 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3966 | |
| 3967 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3968 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3969 | if (DeserializationListener) |
| 3970 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3971 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3972 | |
| 3973 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3976 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3977 | const RecordData &Record, |
| 3978 | unsigned &Idx) { |
| 3979 | if (Idx >= Record.size()) { |
| 3980 | Error("Corrupted AST file"); |
| 3981 | return 0; |
| 3982 | } |
| 3983 | |
| 3984 | return getGlobalDeclID(F, Record[Idx++]); |
| 3985 | } |
| 3986 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3987 | /// \brief Resolve the offset of a statement into a statement. |
| 3988 | /// |
| 3989 | /// This operation will read a new statement from the external |
| 3990 | /// source each time it is called, and is meant to be used via a |
| 3991 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3992 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 3993 | // Switch case IDs are per Decl. |
| 3994 | ClearSwitchCaseIDs(); |
| 3995 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3996 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3997 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 3998 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 3999 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4000 | } |
| 4001 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4002 | namespace { |
| 4003 | class FindExternalLexicalDeclsVisitor { |
| 4004 | ASTReader &Reader; |
| 4005 | const DeclContext *DC; |
| 4006 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4007 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4008 | SmallVectorImpl<Decl*> &Decls; |
| 4009 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4010 | |
| 4011 | public: |
| 4012 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4013 | bool (*isKindWeWant)(Decl::Kind), |
| 4014 | SmallVectorImpl<Decl*> &Decls) |
| 4015 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4016 | { |
| 4017 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4018 | PredefsVisited[I] = false; |
| 4019 | } |
| 4020 | |
| 4021 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4022 | if (Preorder) |
| 4023 | return false; |
| 4024 | |
| 4025 | FindExternalLexicalDeclsVisitor *This |
| 4026 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4027 | |
| 4028 | Module::DeclContextInfosMap::iterator Info |
| 4029 | = M.DeclContextInfos.find(This->DC); |
| 4030 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4031 | return false; |
| 4032 | |
| 4033 | // Load all of the declaration IDs |
| 4034 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4035 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4036 | ID != IDE; ++ID) { |
| 4037 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4038 | continue; |
| 4039 | |
| 4040 | // Don't add predefined declarations to the lexical context more |
| 4041 | // than once. |
| 4042 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4043 | if (This->PredefsVisited[ID->second]) |
| 4044 | continue; |
| 4045 | |
| 4046 | This->PredefsVisited[ID->second] = true; |
| 4047 | } |
| 4048 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4049 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4050 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4051 | This->Decls.push_back(D); |
| 4052 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | return false; |
| 4056 | } |
| 4057 | }; |
| 4058 | } |
| 4059 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4060 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4061 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4062 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4063 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4064 | // least. Walk all of the modules in the order they were loaded. |
| 4065 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4066 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4067 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4068 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4071 | namespace { |
| 4072 | /// \brief Module visitor used to perform name lookup into a |
| 4073 | /// declaration context. |
| 4074 | class DeclContextNameLookupVisitor { |
| 4075 | ASTReader &Reader; |
| 4076 | const DeclContext *DC; |
| 4077 | DeclarationName Name; |
| 4078 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4079 | |
| 4080 | public: |
| 4081 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4082 | const DeclContext *DC, DeclarationName Name, |
| 4083 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4084 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4085 | |
| 4086 | static bool visit(Module &M, void *UserData) { |
| 4087 | DeclContextNameLookupVisitor *This |
| 4088 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4089 | |
| 4090 | // Check whether we have any visible declaration information for |
| 4091 | // this context in this module. |
| 4092 | Module::DeclContextInfosMap::iterator Info |
| 4093 | = M.DeclContextInfos.find(This->DC); |
| 4094 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4095 | return false; |
| 4096 | |
| 4097 | // Look for this name within this module. |
| 4098 | ASTDeclContextNameLookupTable *LookupTable = |
| 4099 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4100 | ASTDeclContextNameLookupTable::iterator Pos |
| 4101 | = LookupTable->find(This->Name); |
| 4102 | if (Pos == LookupTable->end()) |
| 4103 | return false; |
| 4104 | |
| 4105 | bool FoundAnything = false; |
| 4106 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4107 | for (; Data.first != Data.second; ++Data.first) { |
| 4108 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4109 | if (!ND) |
| 4110 | continue; |
| 4111 | |
| 4112 | if (ND->getDeclName() != This->Name) { |
| 4113 | assert(!This->Name.getCXXNameType().isNull() && |
| 4114 | "Name mismatch without a type"); |
| 4115 | continue; |
| 4116 | } |
| 4117 | |
| 4118 | // Record this declaration. |
| 4119 | FoundAnything = true; |
| 4120 | This->Decls.push_back(ND); |
| 4121 | } |
| 4122 | |
| 4123 | return FoundAnything; |
| 4124 | } |
| 4125 | }; |
| 4126 | } |
| 4127 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4128 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4129 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4130 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4131 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4132 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4133 | if (!Name) |
| 4134 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4135 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4136 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4137 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4138 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4139 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4140 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4141 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4142 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4143 | } |
| 4144 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4145 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 4146 | /// before receiving the implementation, and codegen depends on this. |
| 4147 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 4148 | /// implementation before passing the deserialized implementation decl. |
| 4149 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 4150 | ASTConsumer *Consumer) { |
| 4151 | assert(ImplD && Consumer); |
| 4152 | |
| 4153 | for (ObjCImplDecl::method_iterator |
| 4154 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
| 4155 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
| 4156 | |
| 4157 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 4158 | } |
| 4159 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4160 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4161 | assert(Consumer); |
| 4162 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4163 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4164 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 4165 | |
| 4166 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 4167 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 4168 | else |
| 4169 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4170 | } |
| 4171 | } |
| 4172 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4173 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4174 | this->Consumer = Consumer; |
| 4175 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4176 | if (!Consumer) |
| 4177 | return; |
| 4178 | |
| 4179 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4180 | // Force deserialization of this decl, which will cause it to be queued for |
| 4181 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4182 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4183 | } |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4184 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4185 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4188 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4189 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4190 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4191 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4192 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4193 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4194 | unsigned NumDeclsLoaded |
| 4195 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4196 | (Decl *)0); |
| 4197 | unsigned NumIdentifiersLoaded |
| 4198 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4199 | IdentifiersLoaded.end(), |
| 4200 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4201 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4202 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4203 | SelectorsLoaded.end(), |
| 4204 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4205 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4206 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4207 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4208 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4209 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4210 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4211 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4212 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4213 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4214 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4215 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4216 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4217 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4218 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4219 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4220 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4221 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4222 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4223 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4224 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4225 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4226 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4227 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4228 | if (TotalNumStatements) |
| 4229 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4230 | NumStatementsRead, TotalNumStatements, |
| 4231 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4232 | if (TotalNumMacros) |
| 4233 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4234 | NumMacrosRead, TotalNumMacros, |
| 4235 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4236 | if (TotalLexicalDeclContexts) |
| 4237 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4238 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4239 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4240 | * 100)); |
| 4241 | if (TotalVisibleDeclContexts) |
| 4242 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4243 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4244 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4245 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4246 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4247 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4248 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4249 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4250 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4251 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4252 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4253 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4254 | dump(); |
| 4255 | std::fprintf(stderr, "\n"); |
| 4256 | } |
| 4257 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4258 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4259 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4260 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4261 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4262 | InitialCapacity> &Map) { |
| 4263 | if (Map.begin() == Map.end()) |
| 4264 | return; |
| 4265 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4266 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4267 | llvm::errs() << Name << ":\n"; |
| 4268 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4269 | I != IEnd; ++I) { |
| 4270 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4271 | << "\n"; |
| 4272 | } |
| 4273 | } |
| 4274 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4275 | void ASTReader::dump() { |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4276 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4277 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4278 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4279 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4280 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4281 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4282 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 4283 | dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); |
| 4284 | dumpModuleIDMap("Global preprocessed entity map", |
| 4285 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4286 | |
| 4287 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4288 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4289 | MEnd = ModuleMgr.end(); |
| 4290 | M != MEnd; ++M) |
| 4291 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4292 | } |
| 4293 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4294 | /// Return the amount of memory used by memory buffers, breaking down |
| 4295 | /// by heap-backed versus mmap'ed memory. |
| 4296 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4297 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4298 | E = ModuleMgr.end(); I != E; ++I) { |
| 4299 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4300 | size_t bytes = buf->getBufferSize(); |
| 4301 | switch (buf->getBufferKind()) { |
| 4302 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4303 | sizes.malloc_bytes += bytes; |
| 4304 | break; |
| 4305 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4306 | sizes.mmap_bytes += bytes; |
| 4307 | break; |
| 4308 | } |
| 4309 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4310 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4311 | } |
| 4312 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4313 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4314 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4315 | S.ExternalSource = this; |
| 4316 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4317 | // Makes sure any declarations that were deserialized "too early" |
| 4318 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4319 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4320 | if (SemaObj->TUScope) |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4321 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4322 | |
| 4323 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4324 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4325 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4326 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4327 | // Load the offsets of the declarations that Sema references. |
| 4328 | // They will be lazily deserialized when needed. |
| 4329 | if (!SemaDeclRefs.empty()) { |
| 4330 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4331 | if (!SemaObj->StdNamespace) |
| 4332 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4333 | if (!SemaObj->StdBadAlloc) |
| 4334 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4335 | } |
| 4336 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4337 | if (!FPPragmaOptions.empty()) { |
| 4338 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4339 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4340 | } |
| 4341 | |
| 4342 | if (!OpenCLExtensions.empty()) { |
| 4343 | unsigned I = 0; |
| 4344 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4345 | #include "clang/Basic/OpenCLExtensions.def" |
| 4346 | |
| 4347 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4348 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4349 | } |
| 4350 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4351 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4352 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4353 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4354 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4357 | namespace clang { |
| 4358 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4359 | /// identifiers stored within a set of AST files. |
| 4360 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4361 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4362 | const ASTReader &Reader; |
| 4363 | |
| 4364 | /// \brief The current index into the chain of AST files stored in |
| 4365 | /// the AST reader. |
| 4366 | unsigned Index; |
| 4367 | |
| 4368 | /// \brief The current position within the identifier lookup table |
| 4369 | /// of the current AST file. |
| 4370 | ASTIdentifierLookupTable::key_iterator Current; |
| 4371 | |
| 4372 | /// \brief The end position within the identifier lookup table of |
| 4373 | /// the current AST file. |
| 4374 | ASTIdentifierLookupTable::key_iterator End; |
| 4375 | |
| 4376 | public: |
| 4377 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4378 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4379 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4380 | }; |
| 4381 | } |
| 4382 | |
| 4383 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4384 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4385 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4386 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4387 | Current = IdTable->key_begin(); |
| 4388 | End = IdTable->key_end(); |
| 4389 | } |
| 4390 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4391 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4392 | while (Current == End) { |
| 4393 | // If we have exhausted all of our AST files, we're done. |
| 4394 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4395 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4396 | |
| 4397 | --Index; |
| 4398 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4399 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4400 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4401 | Current = IdTable->key_begin(); |
| 4402 | End = IdTable->key_end(); |
| 4403 | } |
| 4404 | |
| 4405 | // We have any identifiers remaining in the current AST file; return |
| 4406 | // the next one. |
| 4407 | std::pair<const char*, unsigned> Key = *Current; |
| 4408 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4409 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4410 | } |
| 4411 | |
| 4412 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4413 | return new ASTIdentifierIterator(*this); |
| 4414 | } |
| 4415 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4416 | namespace clang { namespace serialization { |
| 4417 | class ReadMethodPoolVisitor { |
| 4418 | ASTReader &Reader; |
| 4419 | Selector Sel; |
| 4420 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4421 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4422 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4423 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4424 | /// declarations. |
| 4425 | ObjCMethodList |
| 4426 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4427 | { |
| 4428 | ObjCMethodList List; |
| 4429 | ObjCMethodList *Prev = 0; |
| 4430 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4431 | if (!List.Method) { |
| 4432 | // This is the first method, which is the easy case. |
| 4433 | List.Method = Vec[I]; |
| 4434 | Prev = &List; |
| 4435 | continue; |
| 4436 | } |
| 4437 | |
| 4438 | ObjCMethodList *Mem = |
| 4439 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4440 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4441 | Prev = Prev->Next; |
| 4442 | } |
| 4443 | |
| 4444 | return List; |
| 4445 | } |
| 4446 | |
| 4447 | public: |
| 4448 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4449 | : Reader(Reader), Sel(Sel) { } |
| 4450 | |
| 4451 | static bool visit(Module &M, void *UserData) { |
| 4452 | ReadMethodPoolVisitor *This |
| 4453 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4454 | |
| 4455 | if (!M.SelectorLookupTable) |
| 4456 | return false; |
| 4457 | |
| 4458 | ASTSelectorLookupTable *PoolTable |
| 4459 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4460 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4461 | if (Pos == PoolTable->end()) |
| 4462 | return false; |
| 4463 | |
| 4464 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4465 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4466 | // disable this tracking when called via LoadSelector. |
| 4467 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4468 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4469 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4470 | if (This->Reader.DeserializationListener) |
| 4471 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4472 | This->Sel); |
| 4473 | |
| 4474 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4475 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4476 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4477 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4478 | |
| 4479 | /// \brief Retrieve the instance methods found by this visitor. |
| 4480 | ObjCMethodList getInstanceMethods() const { |
| 4481 | return buildObjCMethodList(InstanceMethods); |
| 4482 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4483 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4484 | /// \brief Retrieve the instance methods found by this visitor. |
| 4485 | ObjCMethodList getFactoryMethods() const { |
| 4486 | return buildObjCMethodList(FactoryMethods); |
| 4487 | } |
| 4488 | }; |
| 4489 | } } // end namespace clang::serialization |
| 4490 | |
| 4491 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4492 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4493 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4494 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4495 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4496 | Result.first = Visitor.getInstanceMethods(); |
| 4497 | Result.second = Visitor.getFactoryMethods(); |
| 4498 | |
| 4499 | if (!Result.first.Method && !Result.second.Method) |
| 4500 | ++NumMethodPoolMisses; |
| 4501 | return Result; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4504 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4505 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4506 | Namespaces.clear(); |
| 4507 | |
| 4508 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4509 | if (NamespaceDecl *Namespace |
| 4510 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4511 | Namespaces.push_back(Namespace); |
| 4512 | } |
| 4513 | } |
| 4514 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4515 | void ASTReader::ReadTentativeDefinitions( |
| 4516 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4517 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4518 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4519 | if (Var) |
| 4520 | TentativeDefs.push_back(Var); |
| 4521 | } |
| 4522 | TentativeDefinitions.clear(); |
| 4523 | } |
| 4524 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4525 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4526 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4527 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4528 | DeclaratorDecl *D |
| 4529 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4530 | if (D) |
| 4531 | Decls.push_back(D); |
| 4532 | } |
| 4533 | UnusedFileScopedDecls.clear(); |
| 4534 | } |
| 4535 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4536 | void ASTReader::ReadDelegatingConstructors( |
| 4537 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4538 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4539 | CXXConstructorDecl *D |
| 4540 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4541 | if (D) |
| 4542 | Decls.push_back(D); |
| 4543 | } |
| 4544 | DelegatingCtorDecls.clear(); |
| 4545 | } |
| 4546 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4547 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4548 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4549 | TypedefNameDecl *D |
| 4550 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4551 | if (D) |
| 4552 | Decls.push_back(D); |
| 4553 | } |
| 4554 | ExtVectorDecls.clear(); |
| 4555 | } |
| 4556 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4557 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4558 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4559 | CXXRecordDecl *D |
| 4560 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4561 | if (D) |
| 4562 | Decls.push_back(D); |
| 4563 | } |
| 4564 | DynamicClasses.clear(); |
| 4565 | } |
| 4566 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4567 | void |
| 4568 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4569 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4570 | NamedDecl *D |
| 4571 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4572 | if (D) |
| 4573 | Decls.push_back(D); |
| 4574 | } |
| 4575 | LocallyScopedExternalDecls.clear(); |
| 4576 | } |
| 4577 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4578 | void ASTReader::ReadReferencedSelectors( |
| 4579 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4580 | if (ReferencedSelectorsData.empty()) |
| 4581 | return; |
| 4582 | |
| 4583 | // If there are @selector references added them to its pool. This is for |
| 4584 | // implementation of -Wselector. |
| 4585 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4586 | unsigned I = 0; |
| 4587 | while (I < DataSize) { |
| 4588 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4589 | SourceLocation SelLoc |
| 4590 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4591 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4592 | } |
| 4593 | ReferencedSelectorsData.clear(); |
| 4594 | } |
| 4595 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4596 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4597 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4598 | if (WeakUndeclaredIdentifiers.empty()) |
| 4599 | return; |
| 4600 | |
| 4601 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4602 | IdentifierInfo *WeakId |
| 4603 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4604 | IdentifierInfo *AliasId |
| 4605 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4606 | SourceLocation Loc |
| 4607 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4608 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4609 | WeakInfo WI(AliasId, Loc); |
| 4610 | WI.setUsed(Used); |
| 4611 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4612 | } |
| 4613 | WeakUndeclaredIdentifiers.clear(); |
| 4614 | } |
| 4615 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4616 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4617 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4618 | ExternalVTableUse VT; |
| 4619 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4620 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4621 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4622 | VTables.push_back(VT); |
| 4623 | } |
| 4624 | |
| 4625 | VTableUses.clear(); |
| 4626 | } |
| 4627 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4628 | void ASTReader::ReadPendingInstantiations( |
| 4629 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4630 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4631 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4632 | SourceLocation Loc |
| 4633 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4634 | Pending.push_back(std::make_pair(D, Loc)); |
| 4635 | } |
| 4636 | PendingInstantiations.clear(); |
| 4637 | } |
| 4638 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4639 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4640 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4641 | ReadMethodPool(Sel); |
| 4642 | } |
| 4643 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4644 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4645 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4646 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4647 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4648 | if (DeserializationListener) |
| 4649 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4650 | } |
| 4651 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4652 | /// \brief Set the globally-visible declarations associated with the given |
| 4653 | /// identifier. |
| 4654 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4655 | /// 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] | 4656 | /// 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] | 4657 | /// them. |
| 4658 | /// |
| 4659 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4660 | /// declarations. |
| 4661 | /// |
| 4662 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4663 | /// visible at global scope. |
| 4664 | /// |
| 4665 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4666 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4667 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4668 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4669 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4670 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4671 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4672 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4673 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4674 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4675 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4676 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4677 | return; |
| 4678 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4679 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4680 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4681 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4682 | if (SemaObj) { |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4683 | if (SemaObj->TUScope) { |
| 4684 | // Introduce this declaration into the translation-unit scope |
| 4685 | // and add it to the declaration chain for this identifier, so |
| 4686 | // that (unqualified) name lookup will find it. |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4687 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 914ed9d | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4688 | } |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4689 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4690 | } else { |
| 4691 | // Queue this declaration so that it will be added to the |
| 4692 | // translation unit scope and identifier's declaration chain |
| 4693 | // once a Sema object is known. |
| 4694 | PreloadedDecls.push_back(D); |
| 4695 | } |
| 4696 | } |
| 4697 | } |
| 4698 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4699 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4700 | if (ID == 0) |
| 4701 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4702 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4703 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4704 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4705 | return 0; |
| 4706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4707 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4708 | ID -= 1; |
| 4709 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4710 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4711 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4712 | Module *M = I->second; |
| 4713 | unsigned Index = ID - M->BaseIdentifierID; |
| 4714 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4715 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4716 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4717 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4718 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4719 | // unsigned integers. This is important to avoid integer overflow when |
| 4720 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4721 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4722 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4723 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4724 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 4725 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4726 | if (DeserializationListener) |
| 4727 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4729 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4730 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4733 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4734 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4735 | } |
| 4736 | |
| 4737 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4738 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4739 | return LocalID; |
| 4740 | |
| 4741 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4742 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4743 | assert(I != M.IdentifierRemap.end() |
| 4744 | && "Invalid index into identifier index remap"); |
| 4745 | |
| 4746 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4749 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4750 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4751 | } |
| 4752 | |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4753 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4754 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4755 | } |
| 4756 | |
| 4757 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4758 | if (ID == 0) |
| 4759 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4760 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4761 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4762 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4763 | return Selector(); |
| 4764 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4765 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4766 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4767 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4768 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 4769 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4770 | Module &M = *I->second; |
| 4771 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4772 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4773 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4774 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4775 | if (DeserializationListener) |
| 4776 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4779 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4782 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4783 | return DecodeSelector(ID); |
| 4784 | } |
| 4785 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4786 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4787 | // ID 0 (the null selector) is considered an external selector. |
| 4788 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4789 | } |
| 4790 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4791 | serialization::SelectorID |
| 4792 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 4793 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 4794 | return LocalID; |
| 4795 | |
| 4796 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4797 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 4798 | assert(I != M.SelectorRemap.end() |
| 4799 | && "Invalid index into identifier index remap"); |
| 4800 | |
| 4801 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4802 | } |
| 4803 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4804 | DeclarationName |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4805 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4806 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4807 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4808 | switch (Kind) { |
| 4809 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4810 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4811 | |
| 4812 | case DeclarationName::ObjCZeroArgSelector: |
| 4813 | case DeclarationName::ObjCOneArgSelector: |
| 4814 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4815 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4816 | |
| 4817 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4818 | return Context.DeclarationNames.getCXXConstructorName( |
| 4819 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4820 | |
| 4821 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4822 | return Context.DeclarationNames.getCXXDestructorName( |
| 4823 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4824 | |
| 4825 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4826 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 4827 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4828 | |
| 4829 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4830 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4831 | (OverloadedOperatorKind)Record[Idx++]); |
| 4832 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4833 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4834 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4835 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4836 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4837 | case DeclarationName::CXXUsingDirective: |
| 4838 | return DeclarationName::getUsingDirectiveName(); |
| 4839 | } |
| 4840 | |
| 4841 | // Required to silence GCC warning |
| 4842 | return DeclarationName(); |
| 4843 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4844 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4845 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4846 | DeclarationNameLoc &DNLoc, |
| 4847 | DeclarationName Name, |
| 4848 | const RecordData &Record, unsigned &Idx) { |
| 4849 | switch (Name.getNameKind()) { |
| 4850 | case DeclarationName::CXXConstructorName: |
| 4851 | case DeclarationName::CXXDestructorName: |
| 4852 | case DeclarationName::CXXConversionFunctionName: |
| 4853 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4854 | break; |
| 4855 | |
| 4856 | case DeclarationName::CXXOperatorName: |
| 4857 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4858 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4859 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4860 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4861 | break; |
| 4862 | |
| 4863 | case DeclarationName::CXXLiteralOperatorName: |
| 4864 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4865 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4866 | break; |
| 4867 | |
| 4868 | case DeclarationName::Identifier: |
| 4869 | case DeclarationName::ObjCZeroArgSelector: |
| 4870 | case DeclarationName::ObjCOneArgSelector: |
| 4871 | case DeclarationName::ObjCMultiArgSelector: |
| 4872 | case DeclarationName::CXXUsingDirective: |
| 4873 | break; |
| 4874 | } |
| 4875 | } |
| 4876 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4877 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4878 | DeclarationNameInfo &NameInfo, |
| 4879 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4880 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4881 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4882 | DeclarationNameLoc DNLoc; |
| 4883 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4884 | NameInfo.setInfo(DNLoc); |
| 4885 | } |
| 4886 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4887 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4888 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 4889 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4890 | unsigned NumTPLists = Record[Idx++]; |
| 4891 | Info.NumTemplParamLists = NumTPLists; |
| 4892 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4893 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4894 | for (unsigned i=0; i != NumTPLists; ++i) |
| 4895 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 4896 | } |
| 4897 | } |
| 4898 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4899 | TemplateName |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4900 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4901 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4902 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4903 | switch (Kind) { |
| 4904 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4905 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4906 | |
| 4907 | case TemplateName::OverloadedTemplate: { |
| 4908 | unsigned size = Record[Idx++]; |
| 4909 | UnresolvedSet<8> Decls; |
| 4910 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4911 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4912 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4913 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4914 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4915 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4916 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4917 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4918 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4919 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4920 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4921 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4922 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4923 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4924 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4925 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4926 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4927 | GetIdentifierInfo(F, Record, |
| 4928 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4929 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4930 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4931 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4932 | |
| 4933 | case TemplateName::SubstTemplateTemplateParm: { |
| 4934 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4935 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4936 | if (!param) return TemplateName(); |
| 4937 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4938 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 4939 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4940 | |
| 4941 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 4942 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4943 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4944 | if (!Param) |
| 4945 | return TemplateName(); |
| 4946 | |
| 4947 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 4948 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 4949 | return TemplateName(); |
| 4950 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4951 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4952 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4953 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4954 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4955 | assert(0 && "Unhandled template name kind!"); |
| 4956 | return TemplateName(); |
| 4957 | } |
| 4958 | |
| 4959 | TemplateArgument |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4960 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4961 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4962 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 4963 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4964 | case TemplateArgument::Null: |
| 4965 | return TemplateArgument(); |
| 4966 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4967 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4968 | case TemplateArgument::Declaration: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4969 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4970 | case TemplateArgument::Integral: { |
| 4971 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4972 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 4973 | return TemplateArgument(Value, T); |
| 4974 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4975 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4976 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4977 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4978 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 4979 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 4980 | if (unsigned NumExpansions = Record[Idx++]) |
| 4981 | NumTemplateExpansions = NumExpansions - 1; |
| 4982 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4983 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4984 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4985 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4986 | case TemplateArgument::Pack: { |
| 4987 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4988 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 4989 | for (unsigned I = 0; I != NumArgs; ++I) |
| 4990 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 4991 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4992 | } |
| 4993 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4994 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4995 | assert(0 && "Unhandled template argument kind!"); |
| 4996 | return TemplateArgument(); |
| 4997 | } |
| 4998 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4999 | TemplateParameterList * |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5000 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5001 | const RecordData &Record, unsigned &Idx) { |
| 5002 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5003 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5004 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5005 | |
| 5006 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5007 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5008 | Params.reserve(NumParams); |
| 5009 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5010 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5011 | |
| 5012 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5013 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5014 | Params.data(), Params.size(), RAngleLoc); |
| 5015 | return TemplateParams; |
| 5016 | } |
| 5017 | |
| 5018 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5019 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5020 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5021 | Module &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5022 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5023 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5024 | TemplArgs.reserve(NumTemplateArgs); |
| 5025 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5026 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5027 | } |
| 5028 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5029 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5030 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5031 | const RecordData &Record, unsigned &Idx) { |
| 5032 | unsigned NumDecls = Record[Idx++]; |
| 5033 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5034 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5035 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5036 | Set.addDecl(D, AS); |
| 5037 | } |
| 5038 | } |
| 5039 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5040 | CXXBaseSpecifier |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5041 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5042 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5043 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5044 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5045 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5046 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5047 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5048 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5049 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5050 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5051 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5052 | Result.setInheritConstructors(inheritConstructors); |
| 5053 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5056 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5057 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5058 | unsigned &Idx) { |
| 5059 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5060 | unsigned NumInitializers = Record[Idx++]; |
| 5061 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5062 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5063 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5064 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5065 | TypeSourceInfo *BaseClassInfo = 0; |
| 5066 | bool IsBaseVirtual = false; |
| 5067 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5068 | IndirectFieldDecl *IndirectMember = 0; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5069 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5070 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5071 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5072 | switch (Type) { |
| 5073 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5074 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5075 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5076 | break; |
| 5077 | |
| 5078 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5079 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5080 | break; |
| 5081 | |
| 5082 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5083 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5084 | break; |
| 5085 | |
| 5086 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5087 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5088 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5089 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5090 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5091 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5092 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5093 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5094 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5095 | bool IsWritten = Record[Idx++]; |
| 5096 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5097 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5098 | if (IsWritten) { |
| 5099 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5100 | } else { |
| 5101 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5102 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5103 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5104 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5105 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5106 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5107 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5108 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5109 | BOMInit = new (Context) CXXCtorInitializer(Context, BaseClassInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5110 | LParenLoc, Init, RParenLoc, |
| 5111 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5112 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5113 | BOMInit = new (Context) CXXCtorInitializer(Context, MemberOrEllipsisLoc, LParenLoc, |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5114 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5115 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5116 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5117 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5118 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5119 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5120 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5121 | MemberOrEllipsisLoc, LParenLoc, |
| 5122 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5123 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5124 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5125 | LParenLoc, Init, RParenLoc, |
| 5126 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5127 | } |
| 5128 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5129 | if (IsWritten) |
| 5130 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5131 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5132 | } |
| 5133 | } |
| 5134 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5135 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5136 | } |
| 5137 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5138 | NestedNameSpecifier * |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5139 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5140 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5141 | unsigned N = Record[Idx++]; |
| 5142 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5143 | for (unsigned I = 0; I != N; ++I) { |
| 5144 | NestedNameSpecifier::SpecifierKind Kind |
| 5145 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5146 | switch (Kind) { |
| 5147 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5148 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5149 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5150 | break; |
| 5151 | } |
| 5152 | |
| 5153 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5154 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5155 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5156 | break; |
| 5157 | } |
| 5158 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5159 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5160 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5161 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5162 | break; |
| 5163 | } |
| 5164 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5165 | case NestedNameSpecifier::TypeSpec: |
| 5166 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5167 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5168 | if (!T) |
| 5169 | return 0; |
| 5170 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5171 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5172 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5173 | break; |
| 5174 | } |
| 5175 | |
| 5176 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5177 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5178 | // No associated value, and there can't be a prefix. |
| 5179 | break; |
| 5180 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5181 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5182 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5183 | } |
| 5184 | return NNS; |
| 5185 | } |
| 5186 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5187 | NestedNameSpecifierLoc |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5188 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5189 | unsigned &Idx) { |
| 5190 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5191 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5192 | for (unsigned I = 0; I != N; ++I) { |
| 5193 | NestedNameSpecifier::SpecifierKind Kind |
| 5194 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5195 | switch (Kind) { |
| 5196 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5197 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5198 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5199 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5200 | break; |
| 5201 | } |
| 5202 | |
| 5203 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5204 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5205 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5206 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5207 | break; |
| 5208 | } |
| 5209 | |
| 5210 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5211 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5212 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5213 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5214 | break; |
| 5215 | } |
| 5216 | |
| 5217 | case NestedNameSpecifier::TypeSpec: |
| 5218 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5219 | bool Template = Record[Idx++]; |
| 5220 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5221 | if (!T) |
| 5222 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5223 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5224 | |
| 5225 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5226 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5227 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5228 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5229 | break; |
| 5230 | } |
| 5231 | |
| 5232 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5233 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5234 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5235 | break; |
| 5236 | } |
| 5237 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5238 | } |
| 5239 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5240 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5243 | SourceRange |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5244 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5245 | unsigned &Idx) { |
| 5246 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5247 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5248 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5251 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5252 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5253 | unsigned BitWidth = Record[Idx++]; |
| 5254 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5255 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5256 | Idx += NumWords; |
| 5257 | return Result; |
| 5258 | } |
| 5259 | |
| 5260 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5261 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5262 | bool isUnsigned = Record[Idx++]; |
| 5263 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5264 | } |
| 5265 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5266 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5267 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5268 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5269 | } |
| 5270 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5271 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5272 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5273 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5274 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5275 | Idx += Len; |
| 5276 | return Result; |
| 5277 | } |
| 5278 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5279 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5280 | unsigned &Idx) { |
| 5281 | unsigned Major = Record[Idx++]; |
| 5282 | unsigned Minor = Record[Idx++]; |
| 5283 | unsigned Subminor = Record[Idx++]; |
| 5284 | if (Minor == 0) |
| 5285 | return VersionTuple(Major); |
| 5286 | if (Subminor == 0) |
| 5287 | return VersionTuple(Major, Minor - 1); |
| 5288 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5289 | } |
| 5290 | |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5291 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5292 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5293 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5294 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5295 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5296 | } |
| 5297 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5298 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5299 | return Diag(SourceLocation(), DiagID); |
| 5300 | } |
| 5301 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5302 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5303 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5304 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5305 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5306 | /// \brief Retrieve the identifier table associated with the |
| 5307 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5308 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5309 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5312 | /// \brief Record that the given ID maps to the given switch-case |
| 5313 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5314 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5315 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5316 | SwitchCaseStmts[ID] = SC; |
| 5317 | } |
| 5318 | |
| 5319 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5320 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5321 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5322 | return SwitchCaseStmts[ID]; |
| 5323 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5324 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5325 | void ASTReader::ClearSwitchCaseIDs() { |
| 5326 | SwitchCaseStmts.clear(); |
| 5327 | } |
| 5328 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5329 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5330 | assert(NumCurrentElementsDeserializing && |
| 5331 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5332 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5333 | // If any identifiers with corresponding top-level declarations have |
| 5334 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5335 | while (!PendingIdentifierInfos.empty()) { |
| 5336 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5337 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5338 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5339 | } |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5340 | |
Argyrios Kyrtzidis | 0895d15 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5341 | // Ready to load previous declarations of Decls that were delayed. |
| 5342 | while (!PendingPreviousDecls.empty()) { |
| 5343 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5344 | PendingPreviousDecls.front().second); |
| 5345 | PendingPreviousDecls.pop_front(); |
| 5346 | } |
| 5347 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5348 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5349 | // decls to the consumer. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5350 | if (Consumer) |
| 5351 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | 134db1f | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5352 | |
| 5353 | assert(PendingForwardRefs.size() == 0 && |
| 5354 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5355 | } |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5356 | --NumCurrentElementsDeserializing; |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5357 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5358 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 5359 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5360 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5361 | bool DisableStatCache) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5362 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5363 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5364 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Jonathan D. Turner | 1afb661 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5365 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5366 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5367 | DisableValidation(DisableValidation), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5368 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5369 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5370 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5371 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5372 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5373 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5374 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5375 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5376 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5377 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5378 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5381 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5382 | for (DeclContextVisibleUpdatesPending::iterator |
| 5383 | I = PendingVisibleUpdates.begin(), |
| 5384 | E = PendingVisibleUpdates.end(); |
| 5385 | I != E; ++I) { |
| 5386 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5387 | F = I->second.end(); |
| 5388 | J != F; ++J) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5389 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5390 | } |
| 5391 | } |