Sebastian Redl | 904c9c8 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | 6ab7cd8 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 16 | #include "clang/Serialization/ModuleManager.h" |
Chandler Carruth | a2398d7 | 2011-12-09 00:02:23 +0000 | [diff] [blame] | 17 | #include "clang/Serialization/SerializationDiagnostic.h" |
Argyrios Kyrtzidis | 0eca89e | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 18 | #include "ASTCommon.h" |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 19 | #include "ASTReaderInternals.h" |
Douglas Gregor | e737f50 | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Sema.h" |
John McCall | 5f1e094 | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Scope.h" |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTContext.h" |
John McCall | 2a7fb27 | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 25 | #include "clang/AST/Expr.h" |
John McCall | 7a1fad3 | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 26 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 27 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 28 | #include "clang/AST/Type.h" |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 29 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 42d42b5 | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 31 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 32 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 83d63c7 | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 33 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 39 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 40 | #include "clang/Basic/Version.h" |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 41 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 42 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 45 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 46 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 03013fa | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 47 | #include "llvm/Support/Path.h" |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 48 | #include "llvm/Support/SaveAndRestore.h" |
Michael J. Spencer | 3a321e2 | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 49 | #include "llvm/Support/system_error.h" |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <algorithm> |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 51 | #include <iterator> |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | #include <cstdio> |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 53 | #include <sys/stat.h> |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 54 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | using namespace clang; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 56 | using namespace clang::serialization; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 57 | using namespace clang::serialization::reader; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 58 | |
| 59 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 60 | // PCH validator implementation |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | //===----------------------------------------------------------------------===// |
| 62 | |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 63 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 64 | |
| 65 | bool |
| 66 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 67 | const LangOptions &PPLangOpts = PP.getLangOpts(); |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 68 | |
| 69 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 70 | if (PPLangOpts.Name != LangOpts.Name) { \ |
| 71 | Reader.Diag(diag::err_pch_langopt_mismatch) \ |
| 72 | << Description << LangOpts.Name << PPLangOpts.Name; \ |
| 73 | return true; \ |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 76 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 77 | if (PPLangOpts.Name != LangOpts.Name) { \ |
| 78 | Reader.Diag(diag::err_pch_langopt_value_mismatch) \ |
| 79 | << Description; \ |
| 80 | return true; \ |
| 81 | } |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 82 | |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 83 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 84 | if (PPLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 85 | Reader.Diag(diag::err_pch_langopt_value_mismatch) \ |
| 86 | << Description; \ |
| 87 | return true; \ |
| 88 | } |
| 89 | |
| 90 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 91 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 92 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 93 | |
| 94 | if (PPLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 95 | Reader.Diag(diag::err_pch_langopt_value_mismatch) |
| 96 | << "target Objective-C runtime"; |
| 97 | return true; |
| 98 | } |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 99 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 103 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | dc3c0d2 | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 104 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 105 | return false; |
| 106 | |
| 107 | Reader.Diag(diag::warn_pch_target_triple) |
| 108 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 109 | return true; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 112 | namespace { |
| 113 | struct EmptyStringRef { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 114 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 115 | }; |
| 116 | struct EmptyBlock { |
| 117 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 118 | }; |
| 119 | } |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 120 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 121 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 122 | PCHPredefinesBlocks R) { |
| 123 | // First, sum up the lengths. |
| 124 | unsigned LL = 0, RL = 0; |
| 125 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 126 | LL += L[I].size(); |
| 127 | } |
| 128 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 129 | RL += R[I].Data.size(); |
| 130 | } |
| 131 | if (LL != RL) |
| 132 | return false; |
| 133 | if (LL == 0 && RL == 0) |
| 134 | return true; |
| 135 | |
| 136 | // Kick out empty parts, they confuse the algorithm below. |
| 137 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 138 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 139 | |
| 140 | // Do it the hard way. At this point, both vectors must be non-empty. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 141 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 142 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | c76c9e0 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 143 | (void) RN; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 144 | for (;;) { |
| 145 | // Compare the current pieces. |
| 146 | if (LR.size() == RR.size()) { |
| 147 | // If they're the same length, it's pretty easy. |
| 148 | if (LR != RR) |
| 149 | return false; |
| 150 | // Both pieces are done, advance. |
| 151 | ++LI; |
| 152 | ++RI; |
| 153 | // If either string is done, they're both done, since they're the same |
| 154 | // length. |
| 155 | if (LI == LN) { |
| 156 | assert(RI == RN && "Strings not the same length after all?"); |
| 157 | return true; |
| 158 | } |
| 159 | LR = L[LI]; |
| 160 | RR = R[RI].Data; |
| 161 | } else if (LR.size() < RR.size()) { |
| 162 | // Right piece is longer. |
| 163 | if (!RR.startswith(LR)) |
| 164 | return false; |
| 165 | ++LI; |
| 166 | assert(LI != LN && "Strings not the same length after all?"); |
| 167 | RR = RR.substr(LR.size()); |
| 168 | LR = L[LI]; |
| 169 | } else { |
| 170 | // Left piece is longer. |
| 171 | if (!LR.startswith(RR)) |
| 172 | return false; |
| 173 | ++RI; |
| 174 | assert(RI != RN && "Strings not the same length after all?"); |
| 175 | LR = LR.substr(RR.size()); |
| 176 | RR = R[RI].Data; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 181 | static std::pair<FileID, StringRef::size_type> |
| 182 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 183 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 184 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 185 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 186 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 187 | Res.first = Buffers[I].BufferID; |
| 188 | break; |
| 189 | } |
| 190 | } |
| 191 | return Res; |
| 192 | } |
| 193 | |
| 194 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 195 | StringRef OriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 196 | std::string &SuggestedPredefines, |
| 197 | FileManager &FileMgr) { |
Daniel Dunbar | c716293 | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 198 | // We are in the context of an implicit include, so the predefines buffer will |
| 199 | // have a #include entry for the PCH file itself (as normalized by the |
| 200 | // preprocessor initialization). Find it and skip over it in the checking |
| 201 | // below. |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 202 | SmallString<256> PCHInclude; |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 203 | PCHInclude += "#include \""; |
Chandler Carruth | cb381ea | 2011-12-09 01:33:57 +0000 | [diff] [blame] | 204 | PCHInclude += HeaderSearch::NormalizeDashIncludePath(OriginalFileName, |
| 205 | FileMgr); |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 206 | PCHInclude += "\"\n"; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 207 | std::pair<StringRef,StringRef> Split = |
| 208 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 209 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 210 | if (Left == PP.getPredefines()) { |
| 211 | Error("Missing PCH include entry!"); |
| 212 | return true; |
| 213 | } |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 214 | |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 215 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 216 | // command line, we're done. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 217 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 218 | CommandLine.push_back(Left); |
| 219 | CommandLine.push_back(Right); |
| 220 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 221 | return false; |
| 222 | |
| 223 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 225 | // The predefines buffers are different. Determine what the differences are, |
| 226 | // and whether they require us to reject the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 227 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 228 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 229 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 230 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 231 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | e675049 | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 232 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 233 | |
| 234 | // Pick out implicit #includes after the PCH and don't consider them for |
| 235 | // validation; we will insert them into SuggestedPredefines so that the |
| 236 | // preprocessor includes them. |
| 237 | std::string IncludesAfterPCH; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 238 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 239 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 240 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 241 | if (AfterPCHLines[i].startswith("#include ")) { |
| 242 | IncludesAfterPCH += AfterPCHLines[i]; |
| 243 | IncludesAfterPCH += '\n'; |
| 244 | } else { |
| 245 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // Make sure we add the includes last into SuggestedPredefines before we |
| 250 | // exit this function. |
| 251 | struct AddIncludesRAII { |
| 252 | std::string &SuggestedPredefines; |
| 253 | std::string &IncludesAfterPCH; |
| 254 | |
| 255 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 256 | std::string &IncludesAfterPCH) |
| 257 | : SuggestedPredefines(SuggestedPredefines), |
| 258 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 259 | ~AddIncludesRAII() { |
| 260 | SuggestedPredefines += IncludesAfterPCH; |
| 261 | } |
| 262 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 263 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 264 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 265 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 266 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 267 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 268 | |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 269 | // Determine which predefines that were used to build the PCH file are missing |
| 270 | // from the command line. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 271 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 272 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 273 | CmdLineLines.begin(), CmdLineLines.end(), |
| 274 | std::back_inserter(MissingPredefines)); |
| 275 | |
| 276 | bool MissingDefines = false; |
| 277 | bool ConflictingDefines = false; |
| 278 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 279 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 297c706 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 280 | if (Missing.startswith("#include ")) { |
| 281 | // An -include was specified when generating the PCH; it is included in |
| 282 | // the PCH, just ignore it. |
| 283 | continue; |
| 284 | } |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 285 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 286 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 287 | return true; |
| 288 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 289 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 290 | // This is a macro definition. Determine the name of the macro we're |
| 291 | // defining. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 292 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 294 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 295 | assert(EndOfMacroName != std::string::npos && |
| 296 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 297 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 298 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 299 | // Determine whether this macro was given a different definition on the |
| 300 | // command line. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 301 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 302 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 303 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 304 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 305 | MacroDefStart); |
| 306 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 307 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 308 | // Different macro; we're done. |
| 309 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | break; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 311 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
| 313 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 314 | "Invalid #define in predefines buffer?"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 316 | (*ConflictPos)[MacroDefLen] != '(') |
| 317 | continue; // Longer macro name; keep trying. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 318 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 319 | // We found a conflicting macro definition. |
| 320 | break; |
| 321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | if (ConflictPos != CmdLineLines.end()) { |
| 324 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 325 | << MacroName; |
| 326 | |
| 327 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 328 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 329 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 330 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 331 | SourceLocation PCHMissingLoc = |
| 332 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 333 | .getLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 334 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 335 | |
| 336 | ConflictingDefines = true; |
| 337 | continue; |
| 338 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | |
Daniel Dunbar | 10014aa | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 340 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 341 | // definition from the PCH file. Warn the user that they made a mistake. |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | if (ConflictingDefines) |
| 343 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | if (!MissingDefines) { |
| 346 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 347 | MissingDefines = true; |
| 348 | } |
| 349 | |
| 350 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 351 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 352 | FindMacro(Buffers, Missing); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 353 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 354 | SourceLocation PCHMissingLoc = |
| 355 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
Argyrios Kyrtzidis | a64ccef | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 356 | .getLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 358 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 359 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 360 | if (ConflictingDefines) |
| 361 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | // Determine what predefines were introduced based on command-line |
| 364 | // parameters that were not present when building the PCH |
| 365 | // file. Extra #defines are okay, so long as the identifiers being |
| 366 | // defined were not used within the precompiled header. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 367 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 369 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 372 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 373 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 374 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | // This is an extra macro definition. Determine the name of the |
| 379 | // macro we're defining. |
| 380 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 382 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 383 | assert(EndOfMacroName != std::string::npos && |
| 384 | "Couldn't find the end of the macro name"); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 385 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 386 | |
| 387 | // Check whether this name was used somewhere in the PCH file. If |
| 388 | // so, defining it as a macro could change behavior, so we reject |
| 389 | // the PCH file. |
Daniel Dunbar | 4d5936a | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 390 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 4fda42e | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 391 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 392 | return true; |
| 393 | } |
| 394 | |
| 395 | // Add this definition to the suggested predefines buffer. |
| 396 | SuggestedPredefines += Extra; |
| 397 | SuggestedPredefines += '\n'; |
| 398 | } |
| 399 | |
| 400 | // If we get here, it's because the predefines buffer had compatible |
| 401 | // contents. Accept the PCH file. |
| 402 | return false; |
| 403 | } |
| 404 | |
Douglas Gregor | 12fab31 | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 405 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 406 | unsigned ID) { |
| 407 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 408 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void PCHValidator::ReadCounter(unsigned Value) { |
| 412 | PP.setCounterValue(Value); |
| 413 | } |
| 414 | |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 415 | //===----------------------------------------------------------------------===// |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 416 | // AST reader implementation |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 417 | //===----------------------------------------------------------------------===// |
| 418 | |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 419 | void |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 420 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 421 | DeserializationListener = Listener; |
Sebastian Redl | ffaab3e | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Chris Lattner | 4c6f952 | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 424 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 425 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 426 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 427 | return serialization::ComputeHash(Sel); |
| 428 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 429 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 431 | std::pair<unsigned, unsigned> |
| 432 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 433 | using namespace clang::io; |
| 434 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 435 | unsigned DataLen = ReadUnalignedLE16(d); |
| 436 | return std::make_pair(KeyLen, DataLen); |
| 437 | } |
| 438 | |
| 439 | ASTSelectorLookupTrait::internal_key_type |
| 440 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 441 | using namespace clang::io; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 442 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 443 | unsigned N = ReadUnalignedLE16(d); |
| 444 | IdentifierInfo *FirstII |
| 445 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 446 | if (N == 0) |
| 447 | return SelTable.getNullarySelector(FirstII); |
| 448 | else if (N == 1) |
| 449 | return SelTable.getUnarySelector(FirstII); |
| 450 | |
| 451 | SmallVector<IdentifierInfo *, 16> Args; |
| 452 | Args.push_back(FirstII); |
| 453 | for (unsigned I = 1; I != N; ++I) |
| 454 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 455 | |
| 456 | return SelTable.getSelector(N, Args.data()); |
| 457 | } |
| 458 | |
| 459 | ASTSelectorLookupTrait::data_type |
| 460 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 461 | unsigned DataLen) { |
| 462 | using namespace clang::io; |
| 463 | |
| 464 | data_type Result; |
| 465 | |
| 466 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 467 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 468 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 469 | |
| 470 | // Load instance methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 471 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 472 | if (ObjCMethodDecl *Method |
| 473 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 474 | Result.Instance.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 475 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 476 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 477 | // Load factory methods |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 478 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 479 | if (ObjCMethodDecl *Method |
| 480 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 481 | Result.Factory.push_back(Method); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 482 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 483 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 484 | return Result; |
| 485 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 486 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 487 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 488 | return llvm::HashString(StringRef(a.first, a.second)); |
| 489 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 491 | std::pair<unsigned, unsigned> |
| 492 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 493 | using namespace clang::io; |
| 494 | unsigned DataLen = ReadUnalignedLE16(d); |
| 495 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 496 | return std::make_pair(KeyLen, DataLen); |
| 497 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 499 | std::pair<const char*, unsigned> |
| 500 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 501 | assert(n >= 2 && d[n-1] == '\0'); |
| 502 | return std::make_pair((const char*) d, n-1); |
| 503 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 505 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 506 | const unsigned char* d, |
| 507 | unsigned DataLen) { |
| 508 | using namespace clang::io; |
| 509 | unsigned RawID = ReadUnalignedLE32(d); |
| 510 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 512 | // Wipe out the "is interesting" bit. |
| 513 | RawID = RawID >> 1; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 514 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 515 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 516 | if (!IsInteresting) { |
| 517 | // For uninteresting identifiers, just build the IdentifierInfo |
| 518 | // and associate it with the persistent ID. |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 519 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 520 | if (!II) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 521 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 522 | KnownII = II; |
| 523 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 524 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 525 | II->setIsFromAST(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 526 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 527 | return II; |
| 528 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 530 | unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 531 | unsigned Bits = ReadUnalignedLE16(d); |
| 532 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 533 | Bits >>= 1; |
| 534 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 535 | Bits >>= 1; |
| 536 | bool Poisoned = Bits & 0x01; |
| 537 | Bits >>= 1; |
| 538 | bool ExtensionToken = Bits & 0x01; |
| 539 | Bits >>= 1; |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 540 | bool hadMacroDefinition = Bits & 0x01; |
| 541 | Bits >>= 1; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 542 | bool hasMacroDefinition = Bits & 0x01; |
| 543 | Bits >>= 1; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 544 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 545 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 546 | DataLen -= 8; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 547 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 548 | // Build the IdentifierInfo itself and link the identifier ID with |
| 549 | // the new IdentifierInfo. |
| 550 | IdentifierInfo *II = KnownII; |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 551 | if (!II) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 552 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 553 | KnownII = II; |
| 554 | } |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 555 | Reader.markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 556 | II->setIsFromAST(); |
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 | // Set or check the various bits in the IdentifierInfo structure. |
| 559 | // Token IDs are read-only. |
| 560 | if (HasRevertedTokenIDToIdentifier) |
| 561 | II->RevertTokenIDToIdentifier(); |
| 562 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 563 | assert(II->isExtensionToken() == ExtensionToken && |
| 564 | "Incorrect extension token flag"); |
| 565 | (void)ExtensionToken; |
| 566 | if (Poisoned) |
| 567 | II->setIsPoisoned(true); |
| 568 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 569 | "Incorrect C++ operator keyword flag"); |
| 570 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 571 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 572 | // If this identifier is a macro, deserialize the macro |
| 573 | // definition. |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 574 | if (hadMacroDefinition) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 575 | // FIXME: Check for conflicts? |
| 576 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 577 | unsigned LocalSubmoduleID = ReadUnalignedLE32(d); |
| 578 | |
| 579 | // Determine whether this macro definition should be visible now, or |
| 580 | // whether it is in a hidden submodule. |
| 581 | bool Visible = true; |
| 582 | if (SubmoduleID GlobalSubmoduleID |
| 583 | = Reader.getGlobalSubmoduleID(F, LocalSubmoduleID)) { |
| 584 | if (Module *Owner = Reader.getSubmodule(GlobalSubmoduleID)) { |
| 585 | if (Owner->NameVisibility == Module::Hidden) { |
| 586 | // The owning module is not visible, and this macro definition should |
| 587 | // not be, either. |
| 588 | Visible = false; |
| 589 | |
| 590 | // Note that this macro definition was hidden because its owning |
| 591 | // module is not yet visible. |
| 592 | Reader.HiddenNamesMap[Owner].push_back(II); |
| 593 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 594 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 595 | } |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 596 | |
| 597 | Reader.setIdentifierIsMacro(II, F, Offset, Visible && hasMacroDefinition); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 598 | DataLen -= 8; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 601 | Reader.SetIdentifierInfo(ID, II); |
| 602 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 603 | // Read all of the declarations visible at global scope with this |
| 604 | // name. |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 605 | if (DataLen > 0) { |
| 606 | SmallVector<uint32_t, 4> DeclIDs; |
| 607 | for (; DataLen > 0; DataLen -= 4) |
| 608 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 609 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 612 | return II; |
| 613 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 614 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 615 | unsigned |
| 616 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 617 | llvm::FoldingSetNodeID ID; |
| 618 | ID.AddInteger(Key.Kind); |
| 619 | |
| 620 | switch (Key.Kind) { |
| 621 | case DeclarationName::Identifier: |
| 622 | case DeclarationName::CXXLiteralOperatorName: |
| 623 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 624 | break; |
| 625 | case DeclarationName::ObjCZeroArgSelector: |
| 626 | case DeclarationName::ObjCOneArgSelector: |
| 627 | case DeclarationName::ObjCMultiArgSelector: |
| 628 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 629 | break; |
| 630 | case DeclarationName::CXXOperatorName: |
| 631 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 632 | break; |
| 633 | case DeclarationName::CXXConstructorName: |
| 634 | case DeclarationName::CXXDestructorName: |
| 635 | case DeclarationName::CXXConversionFunctionName: |
| 636 | case DeclarationName::CXXUsingDirective: |
| 637 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 640 | return ID.ComputeHash(); |
| 641 | } |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 642 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 643 | ASTDeclContextNameLookupTrait::internal_key_type |
| 644 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 645 | const external_key_type& Name) const { |
| 646 | DeclNameKey Key; |
| 647 | Key.Kind = Name.getNameKind(); |
| 648 | switch (Name.getNameKind()) { |
| 649 | case DeclarationName::Identifier: |
| 650 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 651 | break; |
| 652 | case DeclarationName::ObjCZeroArgSelector: |
| 653 | case DeclarationName::ObjCOneArgSelector: |
| 654 | case DeclarationName::ObjCMultiArgSelector: |
| 655 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 656 | break; |
| 657 | case DeclarationName::CXXOperatorName: |
| 658 | Key.Data = Name.getCXXOverloadedOperator(); |
| 659 | break; |
| 660 | case DeclarationName::CXXLiteralOperatorName: |
| 661 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 662 | break; |
| 663 | case DeclarationName::CXXConstructorName: |
| 664 | case DeclarationName::CXXDestructorName: |
| 665 | case DeclarationName::CXXConversionFunctionName: |
| 666 | case DeclarationName::CXXUsingDirective: |
| 667 | Key.Data = 0; |
| 668 | break; |
Argyrios Kyrtzidis | a60786b | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 671 | return Key; |
| 672 | } |
| 673 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 674 | std::pair<unsigned, unsigned> |
| 675 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 676 | using namespace clang::io; |
| 677 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 678 | unsigned DataLen = ReadUnalignedLE16(d); |
| 679 | return std::make_pair(KeyLen, DataLen); |
| 680 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 681 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 682 | ASTDeclContextNameLookupTrait::internal_key_type |
| 683 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 684 | using namespace clang::io; |
| 685 | |
| 686 | DeclNameKey Key; |
| 687 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 688 | switch (Key.Kind) { |
| 689 | case DeclarationName::Identifier: |
| 690 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 691 | break; |
| 692 | case DeclarationName::ObjCZeroArgSelector: |
| 693 | case DeclarationName::ObjCOneArgSelector: |
| 694 | case DeclarationName::ObjCMultiArgSelector: |
| 695 | Key.Data = |
| 696 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 697 | .getAsOpaquePtr(); |
| 698 | break; |
| 699 | case DeclarationName::CXXOperatorName: |
| 700 | Key.Data = *d++; // OverloadedOperatorKind |
| 701 | break; |
| 702 | case DeclarationName::CXXLiteralOperatorName: |
| 703 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 704 | break; |
| 705 | case DeclarationName::CXXConstructorName: |
| 706 | case DeclarationName::CXXDestructorName: |
| 707 | case DeclarationName::CXXConversionFunctionName: |
| 708 | case DeclarationName::CXXUsingDirective: |
| 709 | Key.Data = 0; |
| 710 | break; |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 713 | return Key; |
| 714 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 715 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 716 | ASTDeclContextNameLookupTrait::data_type |
| 717 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 718 | const unsigned char* d, |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 719 | unsigned DataLen) { |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 720 | using namespace clang::io; |
| 721 | unsigned NumDecls = ReadUnalignedLE16(d); |
Douglas Gregor | 9b8b20f | 2012-01-06 16:09:53 +0000 | [diff] [blame] | 722 | LE32DeclID *Start = (LE32DeclID *)d; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 723 | return std::make_pair(Start, Start + NumDecls); |
| 724 | } |
Argyrios Kyrtzidis | 5d26768 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 725 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 726 | bool ASTReader::ReadDeclContextStorage(ModuleFile &M, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 727 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 728 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 729 | DeclContextInfo &Info) { |
| 730 | SavedStreamPosition SavedPosition(Cursor); |
| 731 | // First the lexical decls. |
| 732 | if (Offsets.first != 0) { |
| 733 | Cursor.JumpToBit(Offsets.first); |
| 734 | |
| 735 | RecordData Record; |
| 736 | const char *Blob; |
| 737 | unsigned BlobLen; |
| 738 | unsigned Code = Cursor.ReadCode(); |
| 739 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 740 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 741 | Error("Expected lexical block"); |
| 742 | return true; |
| 743 | } |
| 744 | |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 745 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 746 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | // Now the lookup table. |
| 750 | if (Offsets.second != 0) { |
| 751 | Cursor.JumpToBit(Offsets.second); |
| 752 | |
| 753 | RecordData Record; |
| 754 | const char *Blob; |
| 755 | unsigned BlobLen; |
| 756 | unsigned Code = Cursor.ReadCode(); |
| 757 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 758 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 759 | Error("Expected visible lookup table block"); |
| 760 | return true; |
| 761 | } |
| 762 | Info.NameLookupTableData |
| 763 | = ASTDeclContextNameLookupTable::Create( |
| 764 | (const unsigned char *)Blob + Record[0], |
| 765 | (const unsigned char *)Blob, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 766 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | return false; |
| 770 | } |
| 771 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 772 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 773 | Error(diag::err_fe_pch_malformed, Msg); |
| 774 | } |
| 775 | |
| 776 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 777 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 778 | if (Diags.isDiagnosticInFlight()) |
| 779 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 780 | else |
| 781 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 784 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 785 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 786 | if (Listener) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 787 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 788 | ActualOriginalFileName, |
Nick Lewycky | 277a6e7 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 789 | SuggestedPredefines, |
| 790 | FileMgr); |
Douglas Gregor | e721f95 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 791 | return false; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 792 | } |
| 793 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 794 | //===----------------------------------------------------------------------===// |
| 795 | // Source Manager Deserialization |
| 796 | //===----------------------------------------------------------------------===// |
| 797 | |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 798 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 799 | /// \returns true if there was an error. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 800 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 801 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 802 | unsigned Idx = 0; |
| 803 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 804 | |
| 805 | // Parse the file names |
Douglas Gregor | ff0a987 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 806 | std::map<int, int> FileIDs; |
| 807 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 808 | // Extract the file name |
| 809 | unsigned FilenameLen = Record[Idx++]; |
| 810 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 811 | Idx += FilenameLen; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 812 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 813 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | // Parse the line entries |
| 817 | std::vector<LineEntry> Entries; |
| 818 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 819 | int FID = Record[Idx++]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 820 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 821 | // Remap FileID from 1-based old view. |
| 822 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 823 | |
| 824 | // Extract the line entries |
| 825 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 826 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 827 | Entries.clear(); |
| 828 | Entries.reserve(NumEntries); |
| 829 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 830 | unsigned FileOffset = Record[Idx++]; |
| 831 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | f52a5d2 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 832 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 834 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 835 | unsigned IncludeOffset = Record[Idx++]; |
| 836 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 837 | FileKind, IncludeOffset)); |
| 838 | } |
Douglas Gregor | 47d9de6 | 2012-06-08 16:40:28 +0000 | [diff] [blame] | 839 | LineTable.AddEntry(FileID::get(FID), Entries); |
Douglas Gregor | bd94500 | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | return false; |
| 843 | } |
| 844 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 845 | namespace { |
| 846 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 847 | class ASTStatData { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 848 | public: |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 849 | const ino_t ino; |
| 850 | const dev_t dev; |
| 851 | const mode_t mode; |
| 852 | const time_t mtime; |
| 853 | const off_t size; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 855 | 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] | 856 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 857 | }; |
| 858 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 859 | class ASTStatLookupTrait { |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 860 | public: |
| 861 | typedef const char *external_key_type; |
| 862 | typedef const char *internal_key_type; |
| 863 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 864 | typedef ASTStatData data_type; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 865 | |
| 866 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | 2596e42 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 867 | return llvm::HashString(path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 871 | |
| 872 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 873 | return strcmp(a, b) == 0; |
| 874 | } |
| 875 | |
| 876 | static std::pair<unsigned, unsigned> |
| 877 | ReadKeyDataLength(const unsigned char*& d) { |
| 878 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 879 | unsigned DataLen = (unsigned) *d++; |
| 880 | return std::make_pair(KeyLen + 1, DataLen); |
| 881 | } |
| 882 | |
| 883 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 884 | return (const char *)d; |
| 885 | } |
| 886 | |
| 887 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 888 | unsigned /*DataLen*/) { |
| 889 | using namespace clang::io; |
| 890 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 891 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 892 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 893 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 895 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 896 | return data_type(ino, dev, mode, mtime, size); |
| 897 | } |
| 898 | }; |
| 899 | |
| 900 | /// \brief stat() cache for precompiled headers. |
| 901 | /// |
| 902 | /// This cache is very similar to the stat cache used by pretokenized |
| 903 | /// headers. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 904 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 905 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 906 | CacheTy *Cache; |
| 907 | |
| 908 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | public: |
Chris Lattner | 74e976b | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 910 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 911 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 912 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 913 | Cache = CacheTy::Create(Buckets, Base); |
| 914 | } |
| 915 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 916 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 918 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 919 | int *FileDescriptor) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 920 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 921 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 922 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 923 | // 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] | 924 | if (I == Cache->end()) { |
| 925 | ++NumStatMisses; |
Chris Lattner | 898a061 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 926 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 927 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 929 | ++NumStatHits; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 930 | ASTStatData Data = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | |
Chris Lattner | 10e286a | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 932 | StatBuf.st_ino = Data.ino; |
| 933 | StatBuf.st_dev = Data.dev; |
| 934 | StatBuf.st_mtime = Data.mtime; |
| 935 | StatBuf.st_mode = Data.mode; |
| 936 | StatBuf.st_size = Data.size; |
Chris Lattner | d6f6111 | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 937 | return CacheExists; |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 938 | } |
| 939 | }; |
| 940 | } // end anonymous namespace |
| 941 | |
| 942 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 943 | /// \brief Read a source manager block |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 944 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 945 | using namespace SrcMgr; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 946 | |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 947 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 948 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 949 | // Set the source-location entry cursor to the current position in |
| 950 | // the stream. This cursor will be used to read the contents of the |
| 951 | // source manager block initially, and then lazily read |
| 952 | // source-location entries as needed. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 953 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 954 | |
| 955 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 956 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 957 | Error("malformed block record in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 958 | return Failure; |
| 959 | } |
| 960 | |
| 961 | // Enter the source manager block. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 962 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 963 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 964 | return Failure; |
| 965 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 966 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 967 | RecordData Record; |
| 968 | while (true) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 969 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 970 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 971 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 972 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 973 | return Failure; |
| 974 | } |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 975 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 976 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 978 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 979 | // No known subblocks, always skip them. |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 980 | SLocEntryCursor.ReadSubBlockID(); |
| 981 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 982 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 983 | return Failure; |
| 984 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 985 | continue; |
| 986 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 987 | |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 988 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 989 | SLocEntryCursor.ReadAbbrevRecord(); |
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 | // Read a record. |
| 994 | const char *BlobStart; |
| 995 | unsigned BlobLen; |
| 996 | Record.clear(); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 997 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 998 | default: // Default behavior: ignore. |
| 999 | break; |
| 1000 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1001 | case SM_SLOC_FILE_ENTRY: |
| 1002 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1003 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1004 | // Once we hit one of the source location entries, we're done. |
| 1005 | return Success; |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1010 | /// \brief If a header file is not found at the path that we expect it to be |
| 1011 | /// and the PCH file was moved from its original location, try to resolve the |
| 1012 | /// file by assuming that header+PCH were moved together and the header is in |
| 1013 | /// the same place relative to the PCH. |
| 1014 | static std::string |
| 1015 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1016 | const std::string &OriginalDir, |
| 1017 | const std::string &CurrDir) { |
| 1018 | assert(OriginalDir != CurrDir && |
| 1019 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1020 | using namespace llvm::sys; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1021 | SmallString<128> filePath(Filename); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1022 | fs::make_absolute(filePath); |
| 1023 | assert(path::is_absolute(OriginalDir)); |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1024 | SmallString<128> currPCHPath(CurrDir); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1025 | |
| 1026 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1027 | fileDirE = path::end(path::parent_path(filePath)); |
| 1028 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1029 | origDirE = path::end(OriginalDir); |
| 1030 | // Skip the common path components from filePath and OriginalDir. |
| 1031 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1032 | *fileDirI == *origDirI) { |
| 1033 | ++fileDirI; |
| 1034 | ++origDirI; |
| 1035 | } |
| 1036 | for (; origDirI != origDirE; ++origDirI) |
| 1037 | path::append(currPCHPath, ".."); |
| 1038 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1039 | path::append(currPCHPath, path::filename(Filename)); |
| 1040 | return currPCHPath.str(); |
| 1041 | } |
| 1042 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1043 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1044 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1045 | if (ID == 0) |
| 1046 | return Success; |
| 1047 | |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1048 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1049 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1050 | return Failure; |
| 1051 | } |
| 1052 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1053 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1054 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1055 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1056 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1057 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1058 | ++NumSLocEntriesRead; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1059 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1060 | if (Code == llvm::bitc::END_BLOCK || |
| 1061 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1062 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1063 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1064 | return Failure; |
| 1065 | } |
| 1066 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1067 | RecordData Record; |
| 1068 | const char *BlobStart; |
| 1069 | unsigned BlobLen; |
| 1070 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1071 | default: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1072 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1073 | return Failure; |
| 1074 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1075 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1076 | if (Record.size() < 7) { |
| 1077 | Error("source location entry is incorrect"); |
| 1078 | return Failure; |
| 1079 | } |
| 1080 | |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1081 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1082 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1083 | ASTReader::ASTReadResult Result = Success; |
| 1084 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1085 | bool OverriddenBuffer = Record[6]; |
| 1086 | |
| 1087 | std::string OrigFilename(BlobStart, BlobStart + BlobLen); |
| 1088 | std::string Filename = OrigFilename; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1089 | MaybeAddSystemRootToFilename(Filename); |
Douglas Gregor | a4581a1 | 2011-11-17 19:08:51 +0000 | [diff] [blame] | 1090 | const FileEntry *File = |
| 1091 | OverriddenBuffer? FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1092 | (time_t)Record[5]) |
| 1093 | : FileMgr.getFile(Filename, /*OpenFile=*/false); |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1094 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1095 | OriginalDir != CurrentDir) { |
| 1096 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1097 | OriginalDir, |
| 1098 | CurrentDir); |
| 1099 | if (!resolved.empty()) |
| 1100 | File = FileMgr.getFile(resolved); |
| 1101 | } |
Axel Naumann | 0433116 | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1102 | if (File == 0) |
| 1103 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1104 | (time_t)Record[5]); |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1105 | if (File == 0) { |
| 1106 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1107 | ErrorStr += Filename; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1108 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d3555ae | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1109 | Error(ErrorStr.c_str()); |
| 1110 | return Failure; |
| 1111 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1112 | |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1113 | if (!DisableValidation && |
| 1114 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1115 | #if !defined(LLVM_ON_WIN32) |
| 1116 | // In our regression testing, the Windows file system seems to |
| 1117 | // have inconsistent modification times that sometimes |
| 1118 | // erroneously trigger this error-handling path. |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1119 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 9f692a0 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1120 | #endif |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1121 | )) { |
Argyrios Kyrtzidis | 8d8f2c2 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1122 | Error(diag::err_fe_pch_file_modified, Filename); |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1123 | Result = Failure; |
Douglas Gregor | 2d52be5 | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1126 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1127 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1128 | // This is the module's main file. |
| 1129 | IncludeLoc = getImportLocation(F); |
| 1130 | } |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1131 | SrcMgr::CharacteristicKind |
| 1132 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1133 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1134 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1135 | SrcMgr::FileInfo &FileInfo = |
| 1136 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1137 | FileInfo.NumCreatedFIDs = Record[7]; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1138 | if (Record[3]) |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1139 | FileInfo.setHasLineDirectives(); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1141 | const DeclID *FirstDecl = F->FileSortedDecls + Record[8]; |
| 1142 | unsigned NumFileDecls = Record[9]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1143 | if (NumFileDecls) { |
| 1144 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
Argyrios Kyrtzidis | 9d128d0 | 2011-10-31 07:20:08 +0000 | [diff] [blame] | 1145 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1146 | NumFileDecls)); |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1147 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1148 | |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1149 | const SrcMgr::ContentCache *ContentCache |
Argyrios Kyrtzidis | ff39896 | 2012-07-11 20:59:04 +0000 | [diff] [blame] | 1150 | = SourceMgr.getOrCreateContentCache(File, |
| 1151 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
Douglas Gregor | 35f9ae6 | 2011-11-17 01:44:33 +0000 | [diff] [blame] | 1152 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| 1153 | ContentCache->ContentsEntry == ContentCache->OrigEntry) { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1154 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1155 | Record.clear(); |
| 1156 | unsigned RecCode |
| 1157 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
| 1158 | |
| 1159 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
| 1160 | Error("AST record has invalid code"); |
| 1161 | return Failure; |
| 1162 | } |
| 1163 | |
| 1164 | llvm::MemoryBuffer *Buffer |
| 1165 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1166 | Filename); |
| 1167 | SourceMgr.overrideFileContents(File, Buffer); |
| 1168 | } |
Argyrios Kyrtzidis | a4c29b6 | 2012-02-20 23:58:07 +0000 | [diff] [blame] | 1169 | |
| 1170 | if (Result == Failure) |
| 1171 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1172 | break; |
| 1173 | } |
| 1174 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1175 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1176 | const char *Name = BlobStart; |
| 1177 | unsigned Offset = Record[0]; |
| 1178 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1179 | Record.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | unsigned RecCode |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1181 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1182 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1183 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1184 | Error("AST record has invalid code"); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1185 | return Failure; |
| 1186 | } |
| 1187 | |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1188 | llvm::MemoryBuffer *Buffer |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1189 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
| 1190 | Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1191 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1192 | BaseOffset + Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1193 | |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 1194 | if (strcmp(Name, "<built-in>") == 0 && F->Kind == MK_PCH) { |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1195 | PCHPredefinesBlock Block = { |
| 1196 | BufferID, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1197 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 7e9ad8b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1198 | }; |
| 1199 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | 92b059e | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1200 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1201 | |
| 1202 | break; |
| 1203 | } |
| 1204 | |
Chandler Carruth | f70d12d | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1205 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1206 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | bf340e4 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1207 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1208 | ReadSourceLocation(*F, Record[2]), |
| 1209 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1210 | Record[4], |
| 1211 | ID, |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1212 | BaseOffset + Record[0]); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1213 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1214 | } |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | return Success; |
| 1218 | } |
| 1219 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1220 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1221 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1222 | if (F->ImportLoc.isValid()) |
| 1223 | return F->ImportLoc; |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1224 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1225 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1226 | // location of its includer. |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1227 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1228 | // Main file is the importer. We assume that it is the first entry in the |
| 1229 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1230 | // the main file entry doesn't exist yet. |
| 1231 | // The very first entry is the invalid instantiation loc, which takes up |
| 1232 | // offsets 0 and 1. |
| 1233 | return SourceLocation::getFromRawEncoding(2U); |
| 1234 | } |
Jonathan D. Turner | 2e09163 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1235 | //return F->Loaders[0]->FirstLoc; |
| 1236 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1239 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1240 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1241 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1242 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1243 | unsigned BlockID) { |
| 1244 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1245 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1246 | return Failure; |
| 1247 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1248 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1249 | while (true) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1250 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1251 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1252 | |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1253 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1254 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1255 | Cursor.JumpToBit(Offset); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1256 | return false; |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1257 | } |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1258 | Cursor.ReadAbbrevRecord(); |
| 1259 | } |
| 1260 | } |
| 1261 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1262 | void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1263 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1264 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1265 | // Keep track of where we are in the stream, then jump back there |
| 1266 | // after reading this macro. |
| 1267 | SavedStreamPosition SavedPosition(Stream); |
| 1268 | |
| 1269 | Stream.JumpToBit(Offset); |
| 1270 | RecordData Record; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1271 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1272 | MacroInfo *Macro = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1274 | while (true) { |
| 1275 | unsigned Code = Stream.ReadCode(); |
| 1276 | switch (Code) { |
| 1277 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1278 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1279 | |
| 1280 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1281 | // No known subblocks, always skip them. |
| 1282 | Stream.ReadSubBlockID(); |
| 1283 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1284 | Error("malformed block record in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1285 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1286 | } |
| 1287 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1288 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1289 | case llvm::bitc::DEFINE_ABBREV: |
| 1290 | Stream.ReadAbbrevRecord(); |
| 1291 | continue; |
| 1292 | default: break; |
| 1293 | } |
| 1294 | |
| 1295 | // Read a record. |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1296 | const char *BlobStart = 0; |
| 1297 | unsigned BlobLen = 0; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1298 | Record.clear(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1299 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1300 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1301 | BlobLen); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1302 | switch (RecType) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1303 | case PP_MACRO_OBJECT_LIKE: |
| 1304 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1305 | // If we already have a macro, that means that we've hit the end |
| 1306 | // of the definition of the macro we were looking for. We're |
| 1307 | // done. |
| 1308 | if (Macro) |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1309 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1310 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1311 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1312 | if (II == 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1313 | Error("macro must have a name in AST file"); |
Douglas Gregor | 3b2257c | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1314 | return; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1315 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1316 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1317 | unsigned NextIndex = 1; |
| 1318 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1319 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1320 | |
| 1321 | SourceLocation UndefLoc = ReadSourceLocation(F, Record, NextIndex); |
| 1322 | if (UndefLoc.isValid()) |
| 1323 | MI->setUndefLoc(UndefLoc); |
| 1324 | |
| 1325 | MI->setIsUsed(Record[NextIndex++]); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1326 | MI->setIsFromAST(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1328 | bool IsPublic = Record[NextIndex++]; |
Douglas Gregor | aa93a87 | 2011-10-17 15:32:29 +0000 | [diff] [blame] | 1329 | MI->setVisibility(IsPublic, ReadSourceLocation(F, Record, NextIndex)); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 1330 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1331 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1332 | // Decode function-like macro info. |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1333 | bool isC99VarArgs = Record[NextIndex++]; |
| 1334 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1335 | MacroArgs.clear(); |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1336 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1337 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 7143aab | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1338 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1339 | |
| 1340 | // Install function-like macro info. |
| 1341 | MI->setIsFunctionLike(); |
| 1342 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1343 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 75fdb23 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1344 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1345 | PP.getPreprocessorAllocator()); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | // Finally, install the macro. |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1349 | PP.setMacroInfo(II, MI, /*LoadedFromAST=*/true); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1350 | |
| 1351 | // Remember that we saw this macro last so that we add the tokens that |
| 1352 | // form its body to it. |
| 1353 | Macro = MI; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1354 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 1355 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1356 | Record[NextIndex]) { |
| 1357 | // We have a macro definition. Register the association |
| 1358 | PreprocessedEntityID |
| 1359 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1360 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1361 | PPRec.RegisterMacroDefinition(Macro, |
| 1362 | PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1363 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1364 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1365 | ++NumMacrosRead; |
| 1366 | break; |
| 1367 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1368 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1369 | case PP_TOKEN: { |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1370 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1371 | // erroneous, just pretend we didn't see this. |
| 1372 | if (Macro == 0) break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1374 | Token Tok; |
| 1375 | Tok.startToken(); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1376 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1377 | Tok.setLength(Record[1]); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1378 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1379 | Tok.setIdentifierInfo(II); |
| 1380 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1381 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1382 | Macro->AddTokenToBody(Tok); |
| 1383 | break; |
| 1384 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 1385 | } |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1386 | } |
Douglas Gregor | 37e2684 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1387 | } |
| 1388 | |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1389 | PreprocessedEntityID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1390 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const { |
Argyrios Kyrtzidis | 1f6d225 | 2011-09-19 20:40:02 +0000 | [diff] [blame] | 1391 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1392 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1393 | assert(I != M.PreprocessedEntityRemap.end() |
| 1394 | && "Invalid index into preprocessed entity index remap"); |
| 1395 | |
| 1396 | return LocalID + I->second; |
Douglas Gregor | 86c67d8 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1399 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1400 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1401 | } |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1402 | |
| 1403 | HeaderFileInfoTrait::internal_key_type |
| 1404 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1405 | |
| 1406 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1407 | if (strcmp(a, b) == 0) |
| 1408 | return true; |
| 1409 | |
| 1410 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1411 | return false; |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1412 | |
| 1413 | // Determine whether the actual files are equivalent. |
| 1414 | bool Result = false; |
| 1415 | if (llvm::sys::fs::equivalent(a, b, Result)) |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1416 | return false; |
| 1417 | |
Douglas Gregor | 99a922b | 2011-12-09 16:22:07 +0000 | [diff] [blame] | 1418 | return Result; |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | std::pair<unsigned, unsigned> |
| 1422 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1423 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1424 | unsigned DataLen = (unsigned) *d++; |
| 1425 | return std::make_pair(KeyLen + 1, DataLen); |
| 1426 | } |
| 1427 | |
| 1428 | HeaderFileInfoTrait::data_type |
| 1429 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1430 | unsigned DataLen) { |
| 1431 | const unsigned char *End = d + DataLen; |
| 1432 | using namespace clang::io; |
| 1433 | HeaderFileInfo HFI; |
| 1434 | unsigned Flags = *d++; |
| 1435 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1436 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1437 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1438 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1439 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1440 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | 541ba16 | 2011-10-17 18:53:12 +0000 | [diff] [blame] | 1441 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, |
| 1442 | ReadUnalignedLE32(d)); |
Douglas Gregor | 98339b9 | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1443 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1444 | // The framework offset is 1 greater than the actual offset, |
| 1445 | // since 0 is used as an indicator for "no framework name". |
| 1446 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1447 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1448 | } |
| 1449 | |
| 1450 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1451 | (void)End; |
| 1452 | |
| 1453 | // This HeaderFileInfo was externally loaded. |
| 1454 | HFI.External = true; |
| 1455 | return HFI; |
| 1456 | } |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1457 | |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 1458 | void ASTReader::setIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F, |
| 1459 | uint64_t LocalOffset, bool Visible) { |
| 1460 | if (Visible) { |
| 1461 | // Note that this identifier has a macro definition. |
| 1462 | II->setHasMacroDefinition(true); |
Douglas Gregor | 3644d97 | 2012-10-09 16:01:50 +0000 | [diff] [blame] | 1463 | } else { |
| 1464 | II->setHadMacroDefinition(true); |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 1465 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1466 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1467 | // Adjust the offset to a global offset. |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1468 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1469 | } |
| 1470 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1471 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1472 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1473 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1474 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1475 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1476 | // If there was no preprocessor block, skip this file. |
| 1477 | if (!MacroCursor.getBitStreamReader()) |
| 1478 | continue; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1479 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1480 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1481 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1482 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1483 | RecordData Record; |
| 1484 | while (true) { |
| 1485 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1486 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1487 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1488 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1489 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1490 | // No known subblocks, always skip them. |
| 1491 | Cursor.ReadSubBlockID(); |
| 1492 | if (Cursor.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1493 | Error("malformed block record in AST file"); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1494 | return; |
| 1495 | } |
| 1496 | continue; |
| 1497 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1498 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1499 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1500 | Cursor.ReadAbbrevRecord(); |
| 1501 | continue; |
| 1502 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1503 | |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1504 | // Read a record. |
| 1505 | const char *BlobStart; |
| 1506 | unsigned BlobLen; |
| 1507 | Record.clear(); |
| 1508 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1509 | default: // Default behavior: ignore. |
| 1510 | break; |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1511 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1512 | case PP_MACRO_OBJECT_LIKE: |
| 1513 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1514 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1515 | break; |
| 1516 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1517 | case PP_TOKEN: |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1518 | // Ignore tokens. |
| 1519 | break; |
Sebastian Redl | d27d3fc | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1520 | } |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1521 | } |
| 1522 | } |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1523 | |
| 1524 | // Drain the unread macro-record offsets map. |
| 1525 | while (!UnreadMacroRecordOffsets.empty()) |
| 1526 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1527 | } |
| 1528 | |
| 1529 | void ASTReader::LoadMacroDefinition( |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1530 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1531 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1532 | uint64_t Offset = Pos->second; |
| 1533 | UnreadMacroRecordOffsets.erase(Pos); |
| 1534 | |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1535 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1536 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 295a2a6 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1540 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1541 | = UnreadMacroRecordOffsets.find(II); |
| 1542 | LoadMacroDefinition(Pos); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1545 | namespace { |
| 1546 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1547 | class IdentifierLookupVisitor { |
| 1548 | StringRef Name; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1549 | unsigned PriorGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1550 | IdentifierInfo *Found; |
| 1551 | public: |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1552 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration) |
| 1553 | : Name(Name), PriorGeneration(PriorGeneration), Found() { } |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1554 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1555 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1556 | IdentifierLookupVisitor *This |
| 1557 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 1558 | |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1559 | // If we've already searched this module file, skip it now. |
| 1560 | if (M.Generation <= This->PriorGeneration) |
| 1561 | return true; |
| 1562 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1563 | ASTIdentifierLookupTable *IdTable |
| 1564 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1565 | if (!IdTable) |
| 1566 | return false; |
| 1567 | |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1568 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), |
| 1569 | M, This->Found); |
| 1570 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1571 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 1572 | This->Name.size()); |
Douglas Gregor | 5d5051f | 2012-01-24 15:24:38 +0000 | [diff] [blame] | 1573 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1574 | if (Pos == IdTable->end()) |
| 1575 | return false; |
| 1576 | |
| 1577 | // Dereferencing the iterator has the effect of building the |
| 1578 | // IdentifierInfo node and populating it with the various |
| 1579 | // declarations it needs. |
| 1580 | This->Found = *Pos; |
| 1581 | return true; |
| 1582 | } |
| 1583 | |
| 1584 | // \brief Retrieve the identifier info found within the module |
| 1585 | // files. |
| 1586 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1587 | }; |
| 1588 | } |
| 1589 | |
| 1590 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1591 | unsigned PriorGeneration = 0; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1592 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1593 | PriorGeneration = IdentifierGeneration[&II]; |
| 1594 | |
| 1595 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration); |
| 1596 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 1597 | markIdentifierUpToDate(&II); |
| 1598 | } |
| 1599 | |
| 1600 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1601 | if (!II) |
| 1602 | return; |
| 1603 | |
| 1604 | II->setOutOfDate(false); |
| 1605 | |
| 1606 | // Update the generation for this identifier. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 1607 | if (getContext().getLangOpts().Modules) |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 1608 | IdentifierGeneration[II] = CurrentGeneration; |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1611 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1612 | std::string Filename = filenameStrRef; |
| 1613 | MaybeAddSystemRootToFilename(Filename); |
| 1614 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1615 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1616 | OriginalDir != CurrentDir) { |
| 1617 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1618 | OriginalDir, |
| 1619 | CurrentDir); |
| 1620 | if (!resolved.empty()) |
| 1621 | File = FileMgr.getFile(resolved); |
| 1622 | } |
| 1623 | |
| 1624 | return File; |
| 1625 | } |
| 1626 | |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1627 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1628 | /// not an absolute path, add the system root to the beginning of the file |
| 1629 | /// name. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1630 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1631 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1632 | if (!RelocatablePCH) |
| 1633 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | |
Michael J. Spencer | 256053b | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1635 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1636 | return; |
| 1637 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1638 | if (isysroot.empty()) { |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1639 | // If no system root was given, default to '/' |
| 1640 | Filename.insert(Filename.begin(), '/'); |
| 1641 | return; |
| 1642 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1644 | unsigned Length = isysroot.size(); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1645 | if (isysroot[Length - 1] != '/') |
| 1646 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1647 | |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1648 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1651 | ASTReader::ASTReadResult |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 1652 | ASTReader::ReadASTBlock(ModuleFile &F) { |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1653 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1654 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1655 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1656 | Error("malformed block record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1657 | return Failure; |
| 1658 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1659 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1660 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1661 | RecordData Record; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1662 | while (!Stream.AtEndOfStream()) { |
| 1663 | unsigned Code = Stream.ReadCode(); |
| 1664 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1665 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1666 | Error("error at end of module block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1667 | return Failure; |
| 1668 | } |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1669 | |
Argyrios Kyrtzidis | 1f94124 | 2012-09-21 01:30:00 +0000 | [diff] [blame] | 1670 | DeclContext *DC = Context.getTranslationUnitDecl(); |
| 1671 | if (!DC->hasExternalVisibleStorage() && DC->hasExternalLexicalStorage()) |
| 1672 | DC->setMustBuildLookupTable(); |
| 1673 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1674 | return Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1678 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1679 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1680 | // We lazily load the decls block, but we want to set up the |
| 1681 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1682 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1683 | // With the main cursor, we just skip over it. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1684 | F.DeclsCursor = Stream; |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1685 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1686 | // Read the abbrevs. |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1687 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1688 | Error("malformed block record in AST file"); |
Chris Lattner | 6367f6d | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1689 | return Failure; |
| 1690 | } |
| 1691 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1692 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1693 | case DECL_UPDATES_BLOCK_ID: |
| 1694 | if (Stream.SkipBlock()) { |
| 1695 | Error("malformed block record in AST file"); |
| 1696 | return Failure; |
| 1697 | } |
| 1698 | break; |
| 1699 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1700 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1701 | F.MacroCursor = Stream; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1702 | if (!PP.getExternalSource()) |
| 1703 | PP.setExternalSource(this); |
Douglas Gregor | 88a3586 | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1704 | |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1705 | if (Stream.SkipBlock() || |
| 1706 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1707 | Error("malformed block record in AST file"); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1708 | return Failure; |
| 1709 | } |
Douglas Gregor | ecdcb88 | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1710 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | 7356a31 | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1711 | break; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1712 | |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1713 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1714 | F.PreprocessorDetailCursor = Stream; |
| 1715 | if (Stream.SkipBlock() || |
| 1716 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1717 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1718 | Error("malformed preprocessor detail record in AST file"); |
| 1719 | return Failure; |
| 1720 | } |
| 1721 | F.PreprocessorDetailStartOffset |
| 1722 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1723 | |
| 1724 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 1725 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1726 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1727 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1728 | break; |
| 1729 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1730 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1731 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1732 | case Success: |
| 1733 | break; |
| 1734 | |
| 1735 | case Failure: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1736 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1737 | return Failure; |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1738 | |
| 1739 | case IgnorePCH: |
| 1740 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1741 | } |
Douglas Gregor | 14f7900 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1742 | break; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1743 | |
| 1744 | case SUBMODULE_BLOCK_ID: |
| 1745 | switch (ReadSubmoduleBlock(F)) { |
| 1746 | case Success: |
| 1747 | break; |
| 1748 | |
| 1749 | case Failure: |
| 1750 | Error("malformed submodule block in AST file"); |
| 1751 | return Failure; |
| 1752 | |
| 1753 | case IgnorePCH: |
| 1754 | return IgnorePCH; |
| 1755 | } |
| 1756 | break; |
| 1757 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 1758 | case COMMENTS_BLOCK_ID: { |
| 1759 | llvm::BitstreamCursor C = Stream; |
| 1760 | if (Stream.SkipBlock() || |
| 1761 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 1762 | Error("malformed comments block in AST file"); |
| 1763 | return Failure; |
| 1764 | } |
| 1765 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 1766 | break; |
| 1767 | } |
| 1768 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 1769 | default: |
| 1770 | if (!Stream.SkipBlock()) |
| 1771 | break; |
| 1772 | Error("malformed block record in AST file"); |
| 1773 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1774 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1775 | continue; |
| 1776 | } |
| 1777 | |
| 1778 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1779 | Stream.ReadAbbrevRecord(); |
| 1780 | continue; |
| 1781 | } |
| 1782 | |
| 1783 | // Read and process a record. |
| 1784 | Record.clear(); |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1785 | const char *BlobStart = 0; |
| 1786 | unsigned BlobLen = 0; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1787 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1788 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1789 | default: // Default behavior: ignore. |
| 1790 | break; |
| 1791 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1792 | case METADATA: { |
| 1793 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1794 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1795 | : diag::warn_pch_version_too_new); |
| 1796 | return IgnorePCH; |
| 1797 | } |
| 1798 | |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 1799 | bool hasErrors = Record[5]; |
| 1800 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 1801 | Diag(diag::err_pch_with_compiler_errors); |
| 1802 | return IgnorePCH; |
| 1803 | } |
| 1804 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1805 | RelocatablePCH = Record[4]; |
| 1806 | if (Listener) { |
| 1807 | std::string TargetTriple(BlobStart, BlobLen); |
| 1808 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1809 | return IgnorePCH; |
| 1810 | } |
| 1811 | break; |
| 1812 | } |
| 1813 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1814 | case IMPORTS: { |
| 1815 | // Load each of the imported PCH files. |
| 1816 | unsigned Idx = 0, N = Record.size(); |
| 1817 | while (Idx < N) { |
| 1818 | // Read information about the AST file. |
| 1819 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1820 | unsigned Length = Record[Idx++]; |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1821 | SmallString<128> ImportedFile(Record.begin() + Idx, |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1822 | Record.begin() + Idx + Length); |
| 1823 | Idx += Length; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1824 | |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1825 | // Load the AST file. |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1826 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | e95b919 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1827 | case Failure: return Failure; |
| 1828 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1829 | case IgnorePCH: return IgnorePCH; |
| 1830 | case Success: break; |
| 1831 | } |
| 1832 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1833 | break; |
| 1834 | } |
| 1835 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1836 | case TYPE_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1837 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1838 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1839 | return Failure; |
| 1840 | } |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1841 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1842 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1843 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1844 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1845 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1846 | if (F.LocalNumTypes > 0) { |
| 1847 | // Introduce the global -> local mapping for types within this module. |
| 1848 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1849 | |
| 1850 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1851 | F.TypeRemap.insertOrReplace( |
| 1852 | std::make_pair(LocalBaseTypeIndex, |
| 1853 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1854 | |
| 1855 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1856 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1857 | break; |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1858 | } |
| 1859 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1860 | case DECL_OFFSET: { |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1861 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1862 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1863 | return Failure; |
| 1864 | } |
Argyrios Kyrtzidis | 9d31fa7 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 1865 | F.DeclOffsets = (const DeclOffset *)BlobStart; |
Sebastian Redl | 12d6da0 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1866 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1867 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1868 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 96e973f | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1869 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1870 | if (F.LocalNumDecls > 0) { |
| 1871 | // Introduce the global -> local mapping for declarations within this |
| 1872 | // module. |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1873 | GlobalDeclMap.insert( |
| 1874 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1875 | |
| 1876 | // Introduce the local -> global mapping for declarations within this |
| 1877 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1878 | F.DeclRemap.insertOrReplace( |
| 1879 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1880 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 1881 | // Introduce the global -> local mapping for declarations within this |
| 1882 | // module. |
| 1883 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 1884 | |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1885 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1886 | } |
Douglas Gregor | 8038d51 | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1887 | break; |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1890 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1891 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1892 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1893 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1894 | Info.NumLexicalDecls |
| 1895 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1896 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | d692af7 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1897 | break; |
| 1898 | } |
| 1899 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1900 | case UPDATE_VISIBLE: { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1901 | unsigned Idx = 0; |
| 1902 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 1903 | ASTDeclContextNameLookupTable *Table = |
| 1904 | ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1905 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1906 | (const unsigned char *)BlobStart, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1907 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1908 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1909 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1910 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1911 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1912 | } else |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1913 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1914 | break; |
| 1915 | } |
| 1916 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1917 | case LANGUAGE_OPTIONS: |
Douglas Gregor | fae3b2f | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1918 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1919 | return IgnorePCH; |
| 1920 | break; |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1921 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1922 | case IDENTIFIER_TABLE: |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1923 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1924 | if (Record[0]) { |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1925 | F.IdentifierLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1926 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 93fb9ed | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1927 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1928 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1929 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1930 | |
| 1931 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1932 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1933 | break; |
| 1934 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1935 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1936 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1937 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1938 | return Failure; |
| 1939 | } |
Sebastian Redl | 2da08f9 | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1940 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1941 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1942 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1943 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 1944 | |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1945 | if (F.LocalNumIdentifiers > 0) { |
| 1946 | // Introduce the global -> local mapping for identifiers within this |
| 1947 | // module. |
| 1948 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 1949 | &F)); |
| 1950 | |
| 1951 | // Introduce the local -> global mapping for identifiers within this |
| 1952 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 1953 | F.IdentifierRemap.insertOrReplace( |
| 1954 | std::make_pair(LocalBaseIdentifierID, |
| 1955 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1956 | |
| 1957 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 1958 | + F.LocalNumIdentifiers); |
| 1959 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1960 | break; |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1963 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1964 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1965 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1966 | break; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1967 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1968 | case SPECIAL_TYPES: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1969 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1970 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | ad1de00 | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1971 | break; |
| 1972 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1973 | case STATISTICS: |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1974 | TotalNumStatements += Record[0]; |
| 1975 | TotalNumMacros += Record[1]; |
| 1976 | TotalLexicalDeclContexts += Record[2]; |
| 1977 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 3e1af84 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1978 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1979 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1980 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1981 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1982 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | e6bbc01 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1983 | break; |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1984 | |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1985 | case DELEGATING_CTORS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 1986 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 1987 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 1988 | break; |
| 1989 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1990 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 1991 | if (Record.size() % 4 != 0) { |
| 1992 | Error("invalid weak identifiers record"); |
| 1993 | return Failure; |
| 1994 | } |
| 1995 | |
| 1996 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 1997 | // files. This isn't the way to do it :) |
| 1998 | WeakUndeclaredIdentifiers.clear(); |
| 1999 | |
| 2000 | // Translate the weak, undeclared identifiers into global IDs. |
| 2001 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2002 | WeakUndeclaredIdentifiers.push_back( |
| 2003 | getGlobalIdentifierID(F, Record[I++])); |
| 2004 | WeakUndeclaredIdentifiers.push_back( |
| 2005 | getGlobalIdentifierID(F, Record[I++])); |
| 2006 | WeakUndeclaredIdentifiers.push_back( |
| 2007 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2008 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2009 | } |
Argyrios Kyrtzidis | 72b9057 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2010 | break; |
| 2011 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2012 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2013 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2014 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 14c22f2 | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2015 | break; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2016 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2017 | case SELECTOR_OFFSETS: { |
Sebastian Redl | 059612d | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2018 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2019 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2020 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2021 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2022 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2023 | if (F.LocalNumSelectors > 0) { |
| 2024 | // Introduce the global -> local mapping for selectors within this |
| 2025 | // module. |
| 2026 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2027 | |
| 2028 | // Introduce the local -> global mapping for selectors within this |
| 2029 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2030 | F.SelectorRemap.insertOrReplace( |
| 2031 | std::make_pair(LocalBaseSelectorID, |
| 2032 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2033 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2034 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2035 | } |
| 2036 | break; |
| 2037 | } |
| 2038 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2039 | case METHOD_POOL: |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2040 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2041 | if (Record[0]) |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2042 | F.SelectorLookupTable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2043 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2044 | F.SelectorLookupTableData + Record[0], |
| 2045 | F.SelectorLookupTableData, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2046 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2047 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2048 | break; |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2049 | |
Sebastian Redl | 4ee5a6f | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2050 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2051 | if (!Record.empty()) { |
| 2052 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2053 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2054 | Record[Idx++])); |
| 2055 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2056 | getRawEncoding()); |
| 2057 | } |
| 2058 | } |
Fariborz Jahanian | 3201983 | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2059 | break; |
| 2060 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2061 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2062 | if (!Record.empty() && Listener) |
| 2063 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | 2eafc1b | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2064 | break; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2065 | |
| 2066 | case FILE_SORTED_DECLS: |
| 2067 | F.FileSortedDecls = (const DeclID *)BlobStart; |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2068 | F.NumFileSortedDecls = Record[0]; |
Argyrios Kyrtzidis | 10f3df5 | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2069 | break; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2071 | case SOURCE_LOCATION_OFFSETS: { |
| 2072 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | 518d8cb | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2073 | F.LocalNumSLocEntries = Record[0]; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2074 | unsigned SLocSpaceSize = Record[1]; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2075 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2076 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 2077 | SLocSpaceSize); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2078 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2079 | // we invert it. Because we invert it, though, we need the other end of |
| 2080 | // the range. |
| 2081 | unsigned RangeStart = |
| 2082 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2083 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2084 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2085 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2086 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2087 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2088 | GlobalSLocOffsetMap.insert( |
| 2089 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2090 | - SLocSpaceSize,&F)); |
| 2091 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2092 | // Initialize the remapping table. |
| 2093 | // Invalid stays invalid. |
| 2094 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2095 | // This module. Base was 2 when being compiled. |
| 2096 | F.SLocRemap.insert(std::make_pair(2U, |
| 2097 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2098 | |
| 2099 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2100 | break; |
| 2101 | } |
| 2102 | |
Douglas Gregor | 5d51a1d | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2103 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2104 | // Additional remapping information. |
| 2105 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2106 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2107 | |
| 2108 | // Continuous range maps we may be updating in our module. |
| 2109 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2110 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2111 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2112 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2113 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2114 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2115 | SubmoduleRemap(F.SubmoduleRemap); |
| 2116 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2117 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2118 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2119 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2120 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2121 | while(Data < DataEnd) { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2122 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2123 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2124 | Data += Len; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2125 | ModuleFile *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2126 | if (!OM) { |
| 2127 | Error("SourceLocation remap refers to unknown module"); |
| 2128 | return Failure; |
| 2129 | } |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2130 | |
| 2131 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2132 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2133 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2134 | uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2135 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2136 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2137 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | f33740e | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2138 | |
| 2139 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2140 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2141 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2142 | IdentifierRemap.insert( |
| 2143 | std::make_pair(IdentifierIDOffset, |
| 2144 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2145 | PreprocessedEntityRemap.insert( |
| 2146 | std::make_pair(PreprocessedEntityIDOffset, |
| 2147 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2148 | SubmoduleRemap.insert(std::make_pair(SubmoduleIDOffset, |
| 2149 | OM->BaseSubmoduleID - SubmoduleIDOffset)); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2150 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2151 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2152 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2153 | OM->BaseDeclID - DeclIDOffset)); |
| 2154 | |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2155 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2156 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2157 | |
| 2158 | // Global -> local mappings. |
| 2159 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2160 | } |
| 2161 | break; |
| 2162 | } |
| 2163 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2164 | case SOURCE_MANAGER_LINE_TABLE: |
| 2165 | if (ParseLineTable(F, Record)) |
| 2166 | return Failure; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2167 | break; |
| 2168 | |
Argyrios Kyrtzidis | 4cdb0e2 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2169 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2170 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2171 | F.LocalNumSLocFileEntries = Record[0]; |
| 2172 | break; |
| 2173 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2174 | case SOURCE_LOCATION_PRELOADS: { |
| 2175 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2176 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2177 | if (!F.PreloadSLocEntries.empty()) { |
| 2178 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2179 | return Failure; |
| 2180 | } |
| 2181 | |
| 2182 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2183 | break; |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2184 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2185 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2186 | case STAT_CACHE: { |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2187 | if (!DisableStatCache) { |
| 2188 | ASTStatCache *MyStatCache = |
| 2189 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2190 | (const unsigned char *)BlobStart, |
| 2191 | NumStatHits, NumStatMisses); |
| 2192 | FileMgr.addStatCache(MyStatCache); |
| 2193 | F.StatCache = MyStatCache; |
| 2194 | } |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2195 | break; |
Douglas Gregor | 52e7108 | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2196 | } |
Kovarththanan Rajaratnam | 6b82f64 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2197 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2198 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2199 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2200 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | b81c170 | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2203 | case VTABLE_USES: |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2204 | if (Record.size() % 3 != 0) { |
| 2205 | Error("Invalid VTABLE_USES record"); |
| 2206 | return Failure; |
| 2207 | } |
| 2208 | |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2209 | // Later tables overwrite earlier ones. |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2210 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2211 | // the right way to do this. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2212 | VTableUses.clear(); |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2213 | |
| 2214 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2215 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2216 | VTableUses.push_back( |
| 2217 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2218 | VTableUses.push_back(Record[Idx++]); |
| 2219 | } |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2220 | break; |
| 2221 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2222 | case DYNAMIC_CLASSES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2223 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2224 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | d455add | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2225 | break; |
| 2226 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2227 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2228 | if (PendingInstantiations.size() % 2 != 0) { |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2229 | Error("Invalid existing PendingInstantiations"); |
| 2230 | return Failure; |
| 2231 | } |
| 2232 | |
| 2233 | if (Record.size() % 2 != 0) { |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2234 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2235 | return Failure; |
| 2236 | } |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 2237 | |
Douglas Gregor | f2abb52 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2238 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2239 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2240 | PendingInstantiations.push_back( |
| 2241 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2242 | } |
Argyrios Kyrtzidis | 0e03638 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2243 | break; |
| 2244 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2245 | case SEMA_DECL_REFS: |
Sebastian Redl | 4056680 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2246 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2247 | // FIXME: Modules will have some trouble with this. |
| 2248 | SemaDeclRefs.clear(); |
| 2249 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2250 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2251 | break; |
| 2252 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2253 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2254 | // 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] | 2255 | // that's used. |
Daniel Dunbar | 7b5a121 | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2256 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2257 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | e650c8c | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2258 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2259 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2260 | |
Douglas Gregor | 31d375f | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2261 | case ORIGINAL_FILE_ID: |
| 2262 | OriginalFileID = FileID::get(Record[0]); |
| 2263 | break; |
| 2264 | |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2265 | case ORIGINAL_PCH_DIR: |
| 2266 | // The primary AST will be the last to get here, so it will be the one |
| 2267 | // that's used. |
| 2268 | OriginalDir.assign(BlobStart, BlobLen); |
| 2269 | break; |
| 2270 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2271 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 974be4d | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2272 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2273 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2274 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2275 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | 445e23e | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2276 | return IgnorePCH; |
| 2277 | } |
| 2278 | break; |
| 2279 | } |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2280 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2281 | case PPD_ENTITIES_OFFSETS: { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2282 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)BlobStart; |
| 2283 | assert(BlobLen % sizeof(PPEntityOffset) == 0); |
| 2284 | F.NumPreprocessedEntities = BlobLen / sizeof(PPEntityOffset); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2285 | |
| 2286 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
Douglas Gregor | fb2d9e0 | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2287 | |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2288 | unsigned StartingID; |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2289 | if (!PP.getPreprocessingRecord()) |
Argyrios Kyrtzidis | c6c5452 | 2012-03-05 05:48:17 +0000 | [diff] [blame] | 2290 | PP.createPreprocessingRecord(/*RecordConditionalDirectives=*/false); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2291 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2292 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2293 | StartingID |
| 2294 | = PP.getPreprocessingRecord() |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2295 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2296 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2297 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2298 | if (F.NumPreprocessedEntities > 0) { |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2299 | // Introduce the global -> local mapping for preprocessed entities in |
| 2300 | // this module. |
| 2301 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2302 | |
| 2303 | // Introduce the local -> global mapping for preprocessed entities in |
| 2304 | // this module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 2305 | F.PreprocessedEntityRemap.insertOrReplace( |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2306 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2307 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2308 | } |
Douglas Gregor | 272b6bc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2309 | |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2310 | break; |
Douglas Gregor | 4c30bb1 | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2313 | case DECL_UPDATE_OFFSETS: { |
| 2314 | if (Record.size() % 2 != 0) { |
| 2315 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2316 | return Failure; |
| 2317 | } |
| 2318 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2319 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2320 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2321 | break; |
| 2322 | } |
| 2323 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2324 | case DECL_REPLACEMENTS: { |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2325 | if (Record.size() % 3 != 0) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2326 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2327 | return Failure; |
| 2328 | } |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2329 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2330 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
Argyrios Kyrtzidis | ef23b60 | 2011-10-31 07:20:15 +0000 | [diff] [blame] | 2331 | = ReplacedDeclInfo(&F, Record[I+1], Record[I+2]); |
Sebastian Redl | 0b17c61 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2332 | break; |
| 2333 | } |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2334 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2335 | case OBJC_CATEGORIES_MAP: { |
| 2336 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 2337 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2338 | return Failure; |
| 2339 | } |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2340 | |
| 2341 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 2342 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)BlobStart; |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2343 | break; |
| 2344 | } |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2345 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2346 | case OBJC_CATEGORIES: |
| 2347 | F.ObjCCategories.swap(Record); |
| 2348 | break; |
| 2349 | |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2350 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2351 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2352 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2353 | return Failure; |
| 2354 | } |
| 2355 | |
| 2356 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2357 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2358 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2359 | break; |
| 2360 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2361 | |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2362 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2363 | if (Record.size() % 2 != 0) { |
| 2364 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2365 | return Failure; |
| 2366 | } |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2367 | |
| 2368 | if (F.PragmaDiagMappings.empty()) |
| 2369 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2370 | else |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2371 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2372 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2373 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2374 | |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2375 | case CUDA_SPECIAL_DECL_REFS: |
| 2376 | // Later tables overwrite earlier ones. |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2377 | // FIXME: Modules will have trouble with this. |
| 2378 | CUDASpecialDeclRefs.clear(); |
| 2379 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2380 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2381 | break; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2382 | |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2383 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2384 | F.HeaderFileInfoTableData = BlobStart; |
| 2385 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2386 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2387 | if (Record[0]) { |
| 2388 | F.HeaderFileInfoTable |
| 2389 | = HeaderFileInfoLookupTable::Create( |
| 2390 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2391 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2392 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2393 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2394 | BlobStart + Record[2])); |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2395 | |
| 2396 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2397 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2398 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2399 | } |
| 2400 | break; |
Douglas Gregor | b4dc485 | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2403 | case FP_PRAGMA_OPTIONS: |
| 2404 | // Later tables overwrite earlier ones. |
| 2405 | FPPragmaOptions.swap(Record); |
| 2406 | break; |
| 2407 | |
| 2408 | case OPENCL_EXTENSIONS: |
| 2409 | // Later tables overwrite earlier ones. |
| 2410 | OpenCLExtensions.swap(Record); |
| 2411 | break; |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2412 | |
| 2413 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2414 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2415 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Sean Hunt | ebcbe1d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2416 | break; |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2417 | |
| 2418 | case KNOWN_NAMESPACES: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2419 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2420 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2421 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2422 | |
| 2423 | case IMPORTED_MODULES: { |
| 2424 | if (F.Kind != MK_Module) { |
| 2425 | // If we aren't loading a module (which has its own exports), make |
| 2426 | // all of the imported modules visible. |
| 2427 | // FIXME: Deal with macros-only imports. |
| 2428 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2429 | if (unsigned GlobalID = getGlobalSubmoduleID(F, Record[I])) |
| 2430 | ImportedModules.push_back(GlobalID); |
| 2431 | } |
| 2432 | } |
| 2433 | break; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2434 | } |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2435 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2436 | case LOCAL_REDECLARATIONS: { |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2437 | F.RedeclarationChains.swap(Record); |
| 2438 | break; |
| 2439 | } |
| 2440 | |
| 2441 | case LOCAL_REDECLARATIONS_MAP: { |
| 2442 | if (F.LocalNumRedeclarationsInMap != 0) { |
| 2443 | Error("duplicate LOCAL_REDECLARATIONS_MAP record in AST file"); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2444 | return Failure; |
| 2445 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2446 | |
Douglas Gregor | 2171bf1 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2447 | F.LocalNumRedeclarationsInMap = Record[0]; |
| 2448 | F.RedeclarationsMap = (const LocalRedeclarationsInfo *)BlobStart; |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 2449 | break; |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 2450 | } |
Douglas Gregor | c3cfd2a | 2011-12-22 21:40:42 +0000 | [diff] [blame] | 2451 | |
| 2452 | case MERGED_DECLARATIONS: { |
| 2453 | for (unsigned Idx = 0; Idx < Record.size(); /* increment in loop */) { |
| 2454 | GlobalDeclID CanonID = getGlobalDeclID(F, Record[Idx++]); |
| 2455 | SmallVectorImpl<GlobalDeclID> &Decls = StoredMergedDecls[CanonID]; |
| 2456 | for (unsigned N = Record[Idx++]; N > 0; --N) |
| 2457 | Decls.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2458 | } |
| 2459 | break; |
| 2460 | } |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2461 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2462 | } |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2463 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2464 | return Failure; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2467 | ASTReader::ASTReadResult ASTReader::validateFileEntries(ModuleFile &M) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2468 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2469 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2470 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2471 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2472 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2473 | if (Code == llvm::bitc::END_BLOCK || |
| 2474 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2475 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2476 | Error("incorrectly-formatted source location entry in AST file"); |
| 2477 | return Failure; |
| 2478 | } |
| 2479 | |
| 2480 | RecordData Record; |
| 2481 | const char *BlobStart; |
| 2482 | unsigned BlobLen; |
| 2483 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2484 | default: |
| 2485 | Error("incorrectly-formatted source location entry in AST file"); |
| 2486 | return Failure; |
| 2487 | |
| 2488 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2489 | // If the buffer was overridden, the file need not exist. |
| 2490 | if (Record[6]) |
| 2491 | break; |
| 2492 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2493 | StringRef Filename(BlobStart, BlobLen); |
| 2494 | const FileEntry *File = getFileEntry(Filename); |
| 2495 | |
| 2496 | if (File == 0) { |
| 2497 | std::string ErrorStr = "could not find file '"; |
| 2498 | ErrorStr += Filename; |
| 2499 | ErrorStr += "' referenced by AST file"; |
| 2500 | Error(ErrorStr.c_str()); |
| 2501 | return IgnorePCH; |
| 2502 | } |
| 2503 | |
Douglas Gregor | a081da5 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 2504 | if (Record.size() < 7) { |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2505 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2506 | return Failure; |
| 2507 | } |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2508 | |
| 2509 | off_t StoredSize = (off_t)Record[4]; |
| 2510 | time_t StoredTime = (time_t)Record[5]; |
| 2511 | |
| 2512 | // Check if there was a request to override the contents of the file |
| 2513 | // that was part of the precompiled header. Overridding such a file |
| 2514 | // can lead to problems when lexing using the source locations from the |
| 2515 | // PCH. |
| 2516 | SourceManager &SM = getSourceManager(); |
| 2517 | if (SM.isFileOverridden(File)) { |
| 2518 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2519 | // After emitting the diagnostic, recover by disabling the override so |
| 2520 | // that the original file will be used. |
| 2521 | SM.disableFileContentsOverride(File); |
| 2522 | // The FileEntry is a virtual file entry with the size of the contents |
| 2523 | // that would override the original contents. Set it to the original's |
| 2524 | // size/time. |
| 2525 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2526 | StoredSize, StoredTime); |
| 2527 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2528 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2529 | // The stat info from the FileEntry came from the cached stat |
| 2530 | // info of the PCH, so we cannot trust it. |
| 2531 | struct stat StatBuf; |
| 2532 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2533 | StatBuf.st_size = File->getSize(); |
| 2534 | StatBuf.st_mtime = File->getModificationTime(); |
| 2535 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2536 | |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2537 | if ((StoredSize != StatBuf.st_size |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2538 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2539 | // In our regression testing, the Windows file system seems to |
| 2540 | // have inconsistent modification times that sometimes |
| 2541 | // erroneously trigger this error-handling path. |
Argyrios Kyrtzidis | d54dff0 | 2012-05-03 21:50:39 +0000 | [diff] [blame] | 2542 | || StoredTime != StatBuf.st_mtime |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2543 | #endif |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2544 | )) { |
| 2545 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2546 | return IgnorePCH; |
| 2547 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2548 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
Argyrios Kyrtzidis | b68ffb1 | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | return Success; |
| 2555 | } |
| 2556 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2557 | void ASTReader::makeNamesVisible(const HiddenNames &Names) { |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2558 | for (unsigned I = 0, N = Names.size(); I != N; ++I) { |
| 2559 | if (Decl *D = Names[I].dyn_cast<Decl *>()) |
Douglas Gregor | f143ffc | 2012-01-06 16:22:39 +0000 | [diff] [blame] | 2560 | D->Hidden = false; |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2561 | else { |
| 2562 | IdentifierInfo *II = Names[I].get<IdentifierInfo *>(); |
Alexander Kornienko | 4d7e0ce | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2563 | // FIXME: Check if this works correctly with macro history. |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2564 | if (!II->hasMacroDefinition()) { |
Douglas Gregor | c12906e | 2012-09-24 19:56:18 +0000 | [diff] [blame] | 2565 | // Make sure that this macro hasn't been #undef'd in the mean-time. |
| 2566 | llvm::DenseMap<IdentifierInfo*, MacroInfo*>::iterator Known |
| 2567 | = PP.Macros.find(II); |
| 2568 | if (Known == PP.Macros.end() || |
| 2569 | Known->second->getUndefLoc().isInvalid()) { |
| 2570 | II->setHasMacroDefinition(true); |
| 2571 | if (DeserializationListener) |
| 2572 | DeserializationListener->MacroVisible(II); |
| 2573 | } |
Douglas Gregor | 1d4c113 | 2011-12-20 22:06:13 +0000 | [diff] [blame] | 2574 | } |
| 2575 | } |
Douglas Gregor | 1329264 | 2011-12-02 15:45:10 +0000 | [diff] [blame] | 2576 | } |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2579 | void ASTReader::makeModuleVisible(Module *Mod, |
| 2580 | Module::NameVisibilityKind NameVisibility) { |
| 2581 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 2582 | llvm::SmallVector<Module *, 4> Stack; |
| 2583 | Stack.push_back(Mod); |
| 2584 | while (!Stack.empty()) { |
| 2585 | Mod = Stack.back(); |
| 2586 | Stack.pop_back(); |
| 2587 | |
| 2588 | if (NameVisibility <= Mod->NameVisibility) { |
| 2589 | // This module already has this level of visibility (or greater), so |
| 2590 | // there is nothing more to do. |
| 2591 | continue; |
| 2592 | } |
| 2593 | |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2594 | if (!Mod->isAvailable()) { |
| 2595 | // Modules that aren't available cannot be made visible. |
| 2596 | continue; |
| 2597 | } |
| 2598 | |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2599 | // Update the module's name visibility. |
| 2600 | Mod->NameVisibility = NameVisibility; |
| 2601 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2602 | // If we've already deserialized any names from this module, |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2603 | // mark them as visible. |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 2604 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 2605 | if (Hidden != HiddenNamesMap.end()) { |
| 2606 | makeNamesVisible(Hidden->second); |
| 2607 | HiddenNamesMap.erase(Hidden); |
| 2608 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2609 | |
| 2610 | // Push any non-explicit submodules onto the stack to be marked as |
| 2611 | // visible. |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2612 | for (Module::submodule_iterator Sub = Mod->submodule_begin(), |
| 2613 | SubEnd = Mod->submodule_end(); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2614 | Sub != SubEnd; ++Sub) { |
Douglas Gregor | b7a7819 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2615 | if (!(*Sub)->IsExplicit && Visited.insert(*Sub)) |
| 2616 | Stack.push_back(*Sub); |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2617 | } |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2618 | |
| 2619 | // Push any exported modules onto the stack to be marked as visible. |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2620 | bool AnyWildcard = false; |
| 2621 | bool UnrestrictedWildcard = false; |
| 2622 | llvm::SmallVector<Module *, 4> WildcardRestrictions; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2623 | for (unsigned I = 0, N = Mod->Exports.size(); I != N; ++I) { |
| 2624 | Module *Exported = Mod->Exports[I].getPointer(); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2625 | if (!Mod->Exports[I].getInt()) { |
| 2626 | // Export a named module directly; no wildcards involved. |
| 2627 | if (Visited.insert(Exported)) |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2628 | Stack.push_back(Exported); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2629 | |
| 2630 | continue; |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2631 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2632 | |
| 2633 | // Wildcard export: export all of the imported modules that match |
| 2634 | // the given pattern. |
| 2635 | AnyWildcard = true; |
| 2636 | if (UnrestrictedWildcard) |
| 2637 | continue; |
| 2638 | |
| 2639 | if (Module *Restriction = Mod->Exports[I].getPointer()) |
| 2640 | WildcardRestrictions.push_back(Restriction); |
| 2641 | else { |
| 2642 | WildcardRestrictions.clear(); |
| 2643 | UnrestrictedWildcard = true; |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | // If there were any wildcards, push any imported modules that were |
| 2648 | // re-exported by the wildcard restriction. |
| 2649 | if (!AnyWildcard) |
| 2650 | continue; |
| 2651 | |
| 2652 | for (unsigned I = 0, N = Mod->Imports.size(); I != N; ++I) { |
| 2653 | Module *Imported = Mod->Imports[I]; |
Benjamin Kramer | d48bcb2 | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 2654 | if (!Visited.insert(Imported)) |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2655 | continue; |
| 2656 | |
| 2657 | bool Acceptable = UnrestrictedWildcard; |
| 2658 | if (!Acceptable) { |
| 2659 | // Check whether this module meets one of the restrictions. |
| 2660 | for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { |
| 2661 | Module *Restriction = WildcardRestrictions[R]; |
| 2662 | if (Imported == Restriction || Imported->isSubModuleOf(Restriction)) { |
| 2663 | Acceptable = true; |
| 2664 | break; |
| 2665 | } |
| 2666 | } |
| 2667 | } |
| 2668 | |
| 2669 | if (!Acceptable) |
| 2670 | continue; |
| 2671 | |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2672 | Stack.push_back(Imported); |
Douglas Gregor | 07165b9 | 2011-12-02 19:11:09 +0000 | [diff] [blame] | 2673 | } |
Douglas Gregor | 5e35693 | 2011-12-01 17:11:21 +0000 | [diff] [blame] | 2674 | } |
| 2675 | } |
| 2676 | |
Sebastian Redl | 1d9f1fe | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2677 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | 72a9ae1 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2678 | ModuleKind Type) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2679 | // Bump the generation number. |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2680 | unsigned PreviousGeneration = CurrentGeneration++; |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2681 | |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2682 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2683 | case Failure: return Failure; |
| 2684 | case IgnorePCH: return IgnorePCH; |
| 2685 | case Success: break; |
| 2686 | } |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2687 | |
| 2688 | // Here comes stuff that we only do once the entire chain is loaded. |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2689 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2690 | // Check the predefines buffers. |
Douglas Gregor | 6236a29 | 2011-12-02 21:56:05 +0000 | [diff] [blame] | 2691 | if (!DisableValidation && Type == MK_PCH && |
Argyrios Kyrtzidis | 26d43cd | 2011-09-12 18:09:38 +0000 | [diff] [blame] | 2692 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2693 | // if DisableValidation is true, defines that were set on command-line |
| 2694 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2695 | CheckPredefinesBuffers()) |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2696 | return IgnorePCH; |
| 2697 | |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2698 | // Mark all of the identifiers in the identifier table as being out of date, |
| 2699 | // so that various accessors know to check the loaded modules when the |
| 2700 | // identifier is used. |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2701 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2702 | IdEnd = PP.getIdentifierTable().end(); |
| 2703 | Id != IdEnd; ++Id) |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 2704 | Id->second->setOutOfDate(true); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2705 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2706 | // Resolve any unresolved module exports. |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2707 | for (unsigned I = 0, N = UnresolvedModuleImportExports.size(); I != N; ++I) { |
| 2708 | UnresolvedModuleImportExport &Unresolved = UnresolvedModuleImportExports[I]; |
| 2709 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2710 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 2711 | |
| 2712 | if (Unresolved.IsImport) { |
| 2713 | if (ResolvedMod) |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2714 | Unresolved.Mod->Imports.push_back(ResolvedMod); |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2715 | continue; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2716 | } |
Douglas Gregor | 0adaa88 | 2011-12-05 17:28:06 +0000 | [diff] [blame] | 2717 | |
| 2718 | if (ResolvedMod || Unresolved.IsWildcard) |
| 2719 | Unresolved.Mod->Exports.push_back( |
| 2720 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2721 | } |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2722 | UnresolvedModuleImportExports.clear(); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2723 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2724 | InitializeContext(); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2725 | |
Argyrios Kyrtzidis | 7b90340 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2726 | if (DeserializationListener) |
| 2727 | DeserializationListener->ReaderInitialized(this); |
| 2728 | |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2729 | if (!OriginalFileID.isInvalid()) { |
| 2730 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
| 2731 | + OriginalFileID.getOpaqueValue() - 1); |
| 2732 | |
| 2733 | // If this AST file is a precompiled preamble, then set the preamble file ID |
| 2734 | // of the source manager to the file source file from which the preamble was |
| 2735 | // built. |
| 2736 | if (Type == MK_Preamble) { |
Argyrios Kyrtzidis | 507097e | 2011-09-19 20:40:35 +0000 | [diff] [blame] | 2737 | SourceMgr.setPreambleFileID(OriginalFileID); |
Argyrios Kyrtzidis | b8c879a | 2012-01-05 21:36:25 +0000 | [diff] [blame] | 2738 | } else if (Type == MK_MainFile) { |
| 2739 | SourceMgr.setMainFileID(OriginalFileID); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2740 | } |
Douglas Gregor | 414cb64 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 2743 | // For any Objective-C class definitions we have already loaded, make sure |
| 2744 | // that we load any additional categories. |
| 2745 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 2746 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 2747 | ObjCClassesLoaded[I], |
| 2748 | PreviousGeneration); |
| 2749 | } |
| 2750 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2751 | return Success; |
| 2752 | } |
| 2753 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2754 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | 10bc00f | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2755 | ModuleKind Type, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2756 | ModuleFile *ImportedBy) { |
| 2757 | ModuleFile *M; |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2758 | bool NewModule; |
| 2759 | std::string ErrorStr; |
| 2760 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 2761 | CurrentGeneration, ErrorStr); |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2762 | |
Douglas Gregor | fac4ece | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2763 | if (!M) { |
| 2764 | // We couldn't load the module. |
| 2765 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2766 | + ErrorStr; |
| 2767 | Error(Msg); |
| 2768 | return Failure; |
| 2769 | } |
| 2770 | |
| 2771 | if (!NewModule) { |
| 2772 | // We've already loaded this module. |
| 2773 | return Success; |
| 2774 | } |
| 2775 | |
| 2776 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2777 | // module? |
Argyrios Kyrtzidis | 8e3df4d | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2778 | if (FileName != "-") { |
| 2779 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2780 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2781 | } |
| 2782 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2783 | ModuleFile &F = *M; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2784 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2785 | Stream.init(F.StreamFile); |
Sebastian Redl | 04e6fd4 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2786 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2787 | |
Sebastian Redl | fbd4bf1 | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2788 | // Sniff for the signature. |
| 2789 | if (Stream.Read(8) != 'C' || |
| 2790 | Stream.Read(8) != 'P' || |
| 2791 | Stream.Read(8) != 'C' || |
| 2792 | Stream.Read(8) != 'H') { |
| 2793 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2794 | return Failure; |
| 2795 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2796 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2797 | while (!Stream.AtEndOfStream()) { |
| 2798 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2799 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2800 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2801 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2802 | return Failure; |
| 2803 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2804 | |
| 2805 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2806 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2807 | // We only know the AST subblock ID. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2808 | switch (BlockID) { |
| 2809 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2810 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2811 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2812 | return Failure; |
| 2813 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2814 | break; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2815 | case AST_BLOCK_ID: |
Sebastian Redl | 571db7f | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2816 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2817 | case Success: |
| 2818 | break; |
| 2819 | |
| 2820 | case Failure: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2821 | return Failure; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2822 | |
| 2823 | case IgnorePCH: |
Douglas Gregor | 2bec041 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2824 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2825 | // AST block, skipping subblocks, to see if there are other |
| 2826 | // AST blocks elsewhere. |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2827 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2828 | // FIXME: We can't clear loaded slocentries anymore. |
| 2829 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2830 | |
| 2831 | // Remove the stat cache. |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2832 | if (F.StatCache) |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2833 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 2bf1eb0 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2834 | |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2835 | return IgnorePCH; |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2836 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2837 | break; |
| 2838 | default: |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2839 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2840 | Error("malformed block record in AST file"); |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2841 | return Failure; |
| 2842 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2845 | } |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2846 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2847 | // Once read, set the ModuleFile bit base offset and update the size in |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2848 | // bits of all files we've seen. |
| 2849 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2850 | TotalModulesSizeInBits += F.SizeInBits; |
| 2851 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2852 | |
| 2853 | // Make sure that the files this module was built against are still available. |
| 2854 | if (!DisableValidation) { |
| 2855 | switch(validateFileEntries(*M)) { |
| 2856 | case Failure: return Failure; |
| 2857 | case IgnorePCH: return IgnorePCH; |
| 2858 | case Success: break; |
| 2859 | } |
| 2860 | } |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2861 | |
| 2862 | // Preload SLocEntries. |
| 2863 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2864 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
Argyrios Kyrtzidis | ac1ffcc | 2011-09-19 20:39:54 +0000 | [diff] [blame] | 2865 | // Load it through the SourceManager and don't call ReadSLocEntryRecord() |
| 2866 | // directly because the entry may have already been loaded in which case |
| 2867 | // calling ReadSLocEntryRecord() directly would trigger an assertion in |
| 2868 | // SourceManager. |
| 2869 | SourceMgr.getLoadedSLocEntryByID(Index); |
Douglas Gregor | f249bf3 | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
Douglas Gregor | c69a292 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2872 | |
Sebastian Redl | cdf3b83 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2873 | return Success; |
| 2874 | } |
| 2875 | |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2876 | void ASTReader::InitializeContext() { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2877 | // If there's a listener, notify them that we "read" the translation unit. |
| 2878 | if (DeserializationListener) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2879 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2880 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 3747ee7 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2881 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2882 | // Make sure we load the declaration update records for the translation unit, |
| 2883 | // if there are any. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2884 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2885 | Context.getTranslationUnitDecl()); |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2886 | |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2887 | // FIXME: Find a better way to deal with collisions between these |
| 2888 | // built-in types. Right now, we just ignore the problem. |
| 2889 | |
| 2890 | // Load the special types. |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 2891 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2892 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2893 | if (!Context.CFConstantStringTypeDecl) |
| 2894 | Context.setCFConstantStringType(GetType(String)); |
| 2895 | } |
| 2896 | |
| 2897 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2898 | QualType FileType = GetType(File); |
| 2899 | if (FileType.isNull()) { |
| 2900 | Error("FILE type is NULL"); |
| 2901 | return; |
| 2902 | } |
| 2903 | |
| 2904 | if (!Context.FILEDecl) { |
| 2905 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2906 | Context.setFILEDecl(Typedef->getDecl()); |
| 2907 | else { |
| 2908 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2909 | if (!Tag) { |
| 2910 | Error("Invalid FILE type in AST file"); |
| 2911 | return; |
| 2912 | } |
| 2913 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2914 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2915 | } |
Douglas Gregor | c29f77b | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2916 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2917 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2918 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2919 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2920 | if (Jmp_bufType.isNull()) { |
| 2921 | Error("jmp_buf type is NULL"); |
| 2922 | return; |
| 2923 | } |
| 2924 | |
| 2925 | if (!Context.jmp_bufDecl) { |
| 2926 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2927 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2928 | else { |
| 2929 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2930 | if (!Tag) { |
| 2931 | Error("Invalid jmp_buf type in AST file"); |
| 2932 | return; |
| 2933 | } |
| 2934 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2935 | } |
Jonathan D. Turner | de91db5 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2936 | } |
Mike Stump | 782fa30 | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2937 | } |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2938 | |
Douglas Gregor | 72cd7a0 | 2011-11-11 19:13:12 +0000 | [diff] [blame] | 2939 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
Douglas Gregor | 02a5e87 | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2940 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2941 | if (Sigjmp_bufType.isNull()) { |
| 2942 | Error("sigjmp_buf type is NULL"); |
| 2943 | return; |
| 2944 | } |
| 2945 | |
| 2946 | if (!Context.sigjmp_bufDecl) { |
| 2947 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2948 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2949 | else { |
| 2950 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2951 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2952 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2953 | } |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | if (unsigned ObjCIdRedef |
| 2958 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2959 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2960 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2961 | } |
| 2962 | |
| 2963 | if (unsigned ObjCClassRedef |
| 2964 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2965 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2966 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2967 | } |
| 2968 | |
| 2969 | if (unsigned ObjCSelRedef |
| 2970 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2971 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2972 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2973 | } |
Rafael Espindola | e2d4f4e | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 2974 | |
| 2975 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 2976 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 2977 | if (Ucontext_tType.isNull()) { |
| 2978 | Error("ucontext_t type is NULL"); |
| 2979 | return; |
| 2980 | } |
| 2981 | |
| 2982 | if (!Context.ucontext_tDecl) { |
| 2983 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 2984 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 2985 | else { |
| 2986 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 2987 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 2988 | Context.setucontext_tDecl(Tag->getDecl()); |
| 2989 | } |
| 2990 | } |
| 2991 | } |
Douglas Gregor | 5f95728 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2994 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2995 | |
| 2996 | // If there were any CUDA special declarations, deserialize them. |
| 2997 | if (!CUDASpecialDeclRefs.empty()) { |
| 2998 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2999 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 14b6ba7 | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3000 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 3001 | } |
Douglas Gregor | f6137e4 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 3002 | |
| 3003 | // Re-export any modules that were imported by a non-module AST file. |
| 3004 | for (unsigned I = 0, N = ImportedModules.size(); I != N; ++I) { |
| 3005 | if (Module *Imported = getSubmodule(ImportedModules[I])) |
| 3006 | makeModuleVisible(Imported, Module::AllVisible); |
| 3007 | } |
| 3008 | ImportedModules.clear(); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
Douglas Gregor | ecc2c09 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 3011 | void ASTReader::finalizeForWriting() { |
| 3012 | for (HiddenNamesMapType::iterator Hidden = HiddenNamesMap.begin(), |
| 3013 | HiddenEnd = HiddenNamesMap.end(); |
| 3014 | Hidden != HiddenEnd; ++Hidden) { |
| 3015 | makeNamesVisible(Hidden->second); |
| 3016 | } |
| 3017 | HiddenNamesMap.clear(); |
| 3018 | } |
| 3019 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3020 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3021 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3022 | /// file. |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3023 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 389db16 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3024 | FileManager &FileMgr, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3025 | DiagnosticsEngine &Diags) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3026 | // Open the AST file. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3027 | std::string ErrStr; |
Dylan Noblesmith | 6f42b62 | 2012-02-05 02:12:40 +0000 | [diff] [blame] | 3028 | OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 39b49bc | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3029 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3030 | if (!Buffer) { |
Kaelyn Uhrain | da01f62 | 2012-06-20 00:36:03 +0000 | [diff] [blame] | 3031 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ASTFileName << ErrStr; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3032 | return std::string(); |
| 3033 | } |
| 3034 | |
| 3035 | // Initialize the stream |
| 3036 | llvm::BitstreamReader StreamFile; |
| 3037 | llvm::BitstreamCursor Stream; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3038 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3039 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3040 | Stream.init(StreamFile); |
| 3041 | |
| 3042 | // Sniff for the signature. |
| 3043 | if (Stream.Read(8) != 'C' || |
| 3044 | Stream.Read(8) != 'P' || |
| 3045 | Stream.Read(8) != 'C' || |
| 3046 | Stream.Read(8) != 'H') { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3047 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3048 | return std::string(); |
| 3049 | } |
| 3050 | |
| 3051 | RecordData Record; |
| 3052 | while (!Stream.AtEndOfStream()) { |
| 3053 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3054 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3055 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3056 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3057 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3058 | // We only know the AST subblock ID. |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3059 | switch (BlockID) { |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3060 | case AST_BLOCK_ID: |
| 3061 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3062 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3063 | return std::string(); |
| 3064 | } |
| 3065 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3066 | |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3067 | default: |
| 3068 | if (Stream.SkipBlock()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3069 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3070 | return std::string(); |
| 3071 | } |
| 3072 | break; |
| 3073 | } |
| 3074 | continue; |
| 3075 | } |
| 3076 | |
| 3077 | if (Code == llvm::bitc::END_BLOCK) { |
| 3078 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3079 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3080 | return std::string(); |
| 3081 | } |
| 3082 | continue; |
| 3083 | } |
| 3084 | |
| 3085 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3086 | Stream.ReadAbbrevRecord(); |
| 3087 | continue; |
| 3088 | } |
| 3089 | |
| 3090 | Record.clear(); |
| 3091 | const char *BlobStart = 0; |
| 3092 | unsigned BlobLen = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3094 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3095 | return std::string(BlobStart, BlobLen); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3096 | } |
Douglas Gregor | b64c193 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3097 | |
| 3098 | return std::string(); |
| 3099 | } |
| 3100 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3101 | ASTReader::ASTReadResult ASTReader::ReadSubmoduleBlock(ModuleFile &F) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3102 | // Enter the submodule block. |
| 3103 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 3104 | Error("malformed submodule block record in AST file"); |
| 3105 | return Failure; |
| 3106 | } |
| 3107 | |
| 3108 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3109 | bool First = true; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3110 | Module *CurrentModule = 0; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3111 | RecordData Record; |
| 3112 | while (true) { |
| 3113 | unsigned Code = F.Stream.ReadCode(); |
| 3114 | if (Code == llvm::bitc::END_BLOCK) { |
| 3115 | if (F.Stream.ReadBlockEnd()) { |
| 3116 | Error("error at end of submodule block in AST file"); |
| 3117 | return Failure; |
| 3118 | } |
| 3119 | return Success; |
| 3120 | } |
| 3121 | |
| 3122 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3123 | // No known subblocks, always skip them. |
| 3124 | F.Stream.ReadSubBlockID(); |
| 3125 | if (F.Stream.SkipBlock()) { |
| 3126 | Error("malformed block record in AST file"); |
| 3127 | return Failure; |
| 3128 | } |
| 3129 | continue; |
| 3130 | } |
| 3131 | |
| 3132 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3133 | F.Stream.ReadAbbrevRecord(); |
| 3134 | continue; |
| 3135 | } |
| 3136 | |
| 3137 | // Read a record. |
| 3138 | const char *BlobStart; |
| 3139 | unsigned BlobLen; |
| 3140 | Record.clear(); |
| 3141 | switch (F.Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 3142 | default: // Default behavior: ignore. |
| 3143 | break; |
| 3144 | |
| 3145 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3146 | if (First) { |
| 3147 | Error("missing submodule metadata record at beginning of block"); |
| 3148 | return Failure; |
| 3149 | } |
| 3150 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3151 | if (Record.size() < 7) { |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3152 | Error("malformed module definition"); |
| 3153 | return Failure; |
| 3154 | } |
| 3155 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3156 | StringRef Name(BlobStart, BlobLen); |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3157 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[0]); |
| 3158 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[1]); |
| 3159 | bool IsFramework = Record[2]; |
| 3160 | bool IsExplicit = Record[3]; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3161 | bool IsSystem = Record[4]; |
| 3162 | bool InferSubmodules = Record[5]; |
| 3163 | bool InferExplicitSubmodules = Record[6]; |
| 3164 | bool InferExportWildcard = Record[7]; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3165 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3166 | Module *ParentModule = 0; |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3167 | if (Parent) |
| 3168 | ParentModule = getSubmodule(Parent); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3169 | |
| 3170 | // Retrieve this (sub)module from the module map, creating it if |
| 3171 | // necessary. |
| 3172 | CurrentModule = ModMap.findOrCreateModule(Name, ParentModule, |
| 3173 | IsFramework, |
| 3174 | IsExplicit).first; |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3175 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 3176 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 3177 | SubmodulesLoaded[GlobalIndex]) { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3178 | Error("too many submodules"); |
| 3179 | return Failure; |
| 3180 | } |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3181 | |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 3182 | CurrentModule->setASTFile(F.File); |
Douglas Gregor | 305dc3e | 2011-12-20 00:28:52 +0000 | [diff] [blame] | 3183 | CurrentModule->IsFromModuleFile = true; |
Douglas Gregor | a1f1fad | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 3184 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Douglas Gregor | 1e12368 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 3185 | CurrentModule->InferSubmodules = InferSubmodules; |
| 3186 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 3187 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3188 | if (DeserializationListener) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3189 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
Douglas Gregor | a015cab | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 3190 | |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3191 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3192 | break; |
| 3193 | } |
| 3194 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3195 | case SUBMODULE_UMBRELLA_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3196 | if (First) { |
| 3197 | Error("missing submodule metadata record at beginning of block"); |
| 3198 | return Failure; |
| 3199 | } |
| 3200 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3201 | if (!CurrentModule) |
| 3202 | break; |
| 3203 | |
| 3204 | StringRef FileName(BlobStart, BlobLen); |
| 3205 | if (const FileEntry *Umbrella = PP.getFileManager().getFile(FileName)) { |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3206 | if (!CurrentModule->getUmbrellaHeader()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3207 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella); |
Douglas Gregor | 10694ce | 2011-12-08 17:39:04 +0000 | [diff] [blame] | 3208 | else if (CurrentModule->getUmbrellaHeader() != Umbrella) { |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3209 | Error("mismatched umbrella headers in submodule"); |
| 3210 | return Failure; |
| 3211 | } |
| 3212 | } |
| 3213 | break; |
| 3214 | } |
| 3215 | |
| 3216 | case SUBMODULE_HEADER: { |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3217 | if (First) { |
| 3218 | Error("missing submodule metadata record at beginning of block"); |
| 3219 | return Failure; |
| 3220 | } |
| 3221 | |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3222 | if (!CurrentModule) |
| 3223 | break; |
| 3224 | |
| 3225 | // FIXME: Be more lazy about this! |
| 3226 | StringRef FileName(BlobStart, BlobLen); |
| 3227 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) { |
| 3228 | if (std::find(CurrentModule->Headers.begin(), |
| 3229 | CurrentModule->Headers.end(), |
| 3230 | File) == CurrentModule->Headers.end()) |
Douglas Gregor | e209e50 | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 3231 | ModMap.addHeader(CurrentModule, File); |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3232 | } |
| 3233 | break; |
| 3234 | } |
Argyrios Kyrtzidis | c7782d9 | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 3235 | |
| 3236 | case SUBMODULE_TOPHEADER: { |
| 3237 | if (First) { |
| 3238 | Error("missing submodule metadata record at beginning of block"); |
| 3239 | return Failure; |
| 3240 | } |
| 3241 | |
| 3242 | if (!CurrentModule) |
| 3243 | break; |
| 3244 | |
| 3245 | // FIXME: Be more lazy about this! |
| 3246 | StringRef FileName(BlobStart, BlobLen); |
| 3247 | if (const FileEntry *File = PP.getFileManager().getFile(FileName)) |
| 3248 | CurrentModule->TopHeaders.insert(File); |
| 3249 | break; |
| 3250 | } |
| 3251 | |
Douglas Gregor | 77d029f | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 3252 | case SUBMODULE_UMBRELLA_DIR: { |
| 3253 | if (First) { |
| 3254 | Error("missing submodule metadata record at beginning of block"); |
| 3255 | return Failure; |
| 3256 | } |
| 3257 | |
| 3258 | if (!CurrentModule) |
| 3259 | break; |
| 3260 | |
| 3261 | StringRef DirName(BlobStart, BlobLen); |
| 3262 | if (const DirectoryEntry *Umbrella |
| 3263 | = PP.getFileManager().getDirectory(DirName)) { |
| 3264 | if (!CurrentModule->getUmbrellaDir()) |
| 3265 | ModMap.setUmbrellaDir(CurrentModule, Umbrella); |
| 3266 | else if (CurrentModule->getUmbrellaDir() != Umbrella) { |
| 3267 | Error("mismatched umbrella directories in submodule"); |
| 3268 | return Failure; |
| 3269 | } |
| 3270 | } |
| 3271 | break; |
| 3272 | } |
| 3273 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3274 | case SUBMODULE_METADATA: { |
| 3275 | if (!First) { |
| 3276 | Error("submodule metadata record not at beginning of block"); |
| 3277 | return Failure; |
| 3278 | } |
| 3279 | First = false; |
| 3280 | |
| 3281 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3282 | F.LocalNumSubmodules = Record[0]; |
| 3283 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 3284 | if (F.LocalNumSubmodules > 0) { |
| 3285 | // Introduce the global -> local mapping for submodules within this |
| 3286 | // module. |
| 3287 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 3288 | |
| 3289 | // Introduce the local -> global mapping for submodules within this |
| 3290 | // module. |
Douglas Gregor | adafc2e | 2011-12-19 16:14:14 +0000 | [diff] [blame] | 3291 | F.SubmoduleRemap.insertOrReplace( |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 3292 | std::make_pair(LocalBaseSubmoduleID, |
| 3293 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 3294 | |
| 3295 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 3296 | } |
| 3297 | break; |
| 3298 | } |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3299 | |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3300 | case SUBMODULE_IMPORTS: { |
| 3301 | if (First) { |
| 3302 | Error("missing submodule metadata record at beginning of block"); |
| 3303 | return Failure; |
| 3304 | } |
| 3305 | |
| 3306 | if (!CurrentModule) |
| 3307 | break; |
| 3308 | |
| 3309 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 3310 | UnresolvedModuleImportExport Unresolved; |
| 3311 | Unresolved.File = &F; |
| 3312 | Unresolved.Mod = CurrentModule; |
| 3313 | Unresolved.ID = Record[Idx]; |
| 3314 | Unresolved.IsImport = true; |
| 3315 | Unresolved.IsWildcard = false; |
| 3316 | UnresolvedModuleImportExports.push_back(Unresolved); |
| 3317 | } |
| 3318 | break; |
| 3319 | } |
| 3320 | |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3321 | case SUBMODULE_EXPORTS: { |
| 3322 | if (First) { |
| 3323 | Error("missing submodule metadata record at beginning of block"); |
| 3324 | return Failure; |
| 3325 | } |
| 3326 | |
| 3327 | if (!CurrentModule) |
| 3328 | break; |
| 3329 | |
| 3330 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3331 | UnresolvedModuleImportExport Unresolved; |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3332 | Unresolved.File = &F; |
Douglas Gregor | 5598868 | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 3333 | Unresolved.Mod = CurrentModule; |
| 3334 | Unresolved.ID = Record[Idx]; |
| 3335 | Unresolved.IsImport = false; |
| 3336 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 3337 | UnresolvedModuleImportExports.push_back(Unresolved); |
Douglas Gregor | af13bfc | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | // Once we've loaded the set of exports, there's no reason to keep |
| 3341 | // the parsed, unresolved exports around. |
| 3342 | CurrentModule->UnresolvedExports.clear(); |
| 3343 | break; |
| 3344 | } |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3345 | case SUBMODULE_REQUIRES: { |
| 3346 | if (First) { |
| 3347 | Error("missing submodule metadata record at beginning of block"); |
| 3348 | return Failure; |
| 3349 | } |
| 3350 | |
| 3351 | if (!CurrentModule) |
| 3352 | break; |
| 3353 | |
| 3354 | CurrentModule->addRequirement(StringRef(BlobStart, BlobLen), |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3355 | Context.getLangOpts(), |
Douglas Gregor | dc58aa7 | 2012-01-30 06:01:29 +0000 | [diff] [blame] | 3356 | Context.getTargetInfo()); |
Douglas Gregor | 51f564f | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 3357 | break; |
| 3358 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3359 | } |
| 3360 | } |
Douglas Gregor | 392ed2b | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 3361 | } |
| 3362 | |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3363 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3364 | /// structure. |
| 3365 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3366 | /// This routine parses the language options from the AST file and then gives |
| 3367 | /// them to the AST listener if one is set. |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3368 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3369 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3370 | bool ASTReader::ParseLanguageOptions(const RecordData &Record) { |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3371 | if (Listener) { |
| 3372 | LangOptions LangOpts; |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3373 | unsigned Idx = 0; |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3374 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 3375 | LangOpts.Name = Record[Idx++]; |
| 3376 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 3377 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 3378 | #include "clang/Basic/LangOptions.def" |
John McCall | 260611a | 2012-06-20 06:18:46 +0000 | [diff] [blame] | 3379 | |
| 3380 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 3381 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 3382 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Douglas Gregor | 7d5e81b | 2011-09-13 18:26:39 +0000 | [diff] [blame] | 3383 | |
Douglas Gregor | b86b8dc | 2011-11-15 19:35:01 +0000 | [diff] [blame] | 3384 | unsigned Length = Record[Idx++]; |
| 3385 | LangOpts.CurrentModule.assign(Record.begin() + Idx, |
| 3386 | Record.begin() + Idx + Length); |
Argyrios Kyrtzidis | 11e5110 | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3387 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3388 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3389 | |
| 3390 | return false; |
| 3391 | } |
| 3392 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3393 | std::pair<ModuleFile *, unsigned> |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3394 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3395 | GlobalPreprocessedEntityMapType::iterator |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3396 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3397 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 3398 | "Corrupted global preprocessed entity map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3399 | ModuleFile *M = I->second; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3400 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 3401 | return std::make_pair(M, LocalIndex); |
| 3402 | } |
| 3403 | |
Argyrios Kyrtzidis | 632dcc9 | 2012-10-02 16:10:51 +0000 | [diff] [blame] | 3404 | std::pair<PreprocessingRecord::iterator, PreprocessingRecord::iterator> |
| 3405 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 3406 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 3407 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 3408 | Mod.NumPreprocessedEntities); |
| 3409 | |
| 3410 | return std::make_pair(PreprocessingRecord::iterator(), |
| 3411 | PreprocessingRecord::iterator()); |
| 3412 | } |
| 3413 | |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 3414 | std::pair<ASTReader::ModuleDeclIterator, ASTReader::ModuleDeclIterator> |
| 3415 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
| 3416 | return std::make_pair(ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 3417 | ModuleDeclIterator(this, &Mod, |
| 3418 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
| 3419 | } |
| 3420 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3421 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 3422 | PreprocessedEntityID PPID = Index+1; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3423 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3424 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3425 | unsigned LocalIndex = PPInfo.second; |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3426 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
Douglas Gregor | 4800a5c | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3427 | |
Argyrios Kyrtzidis | e24692b | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 3428 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3429 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3430 | |
| 3431 | unsigned Code = M.PreprocessorDetailCursor.ReadCode(); |
| 3432 | switch (Code) { |
| 3433 | case llvm::bitc::END_BLOCK: |
| 3434 | return 0; |
| 3435 | |
| 3436 | case llvm::bitc::ENTER_SUBBLOCK: |
| 3437 | Error("unexpected subblock record in preprocessor detail block"); |
| 3438 | return 0; |
| 3439 | |
| 3440 | case llvm::bitc::DEFINE_ABBREV: |
| 3441 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 3442 | return 0; |
| 3443 | |
| 3444 | default: |
| 3445 | break; |
| 3446 | } |
| 3447 | |
| 3448 | if (!PP.getPreprocessingRecord()) { |
| 3449 | Error("no preprocessing record"); |
| 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | // Read the record. |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3454 | SourceRange Range(ReadSourceLocation(M, PPOffs.Begin), |
| 3455 | ReadSourceLocation(M, PPOffs.End)); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3456 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 3457 | const char *BlobStart = 0; |
| 3458 | unsigned BlobLen = 0; |
| 3459 | RecordData Record; |
| 3460 | PreprocessorDetailRecordTypes RecType = |
| 3461 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.ReadRecord( |
| 3462 | Code, Record, BlobStart, BlobLen); |
| 3463 | switch (RecType) { |
| 3464 | case PPD_MACRO_EXPANSION: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3465 | bool isBuiltin = Record[0]; |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3466 | IdentifierInfo *Name = 0; |
| 3467 | MacroDefinition *Def = 0; |
| 3468 | if (isBuiltin) |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3469 | Name = getLocalIdentifier(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3470 | else { |
| 3471 | PreprocessedEntityID |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3472 | GlobalID = getGlobalPreprocessedEntityID(M, Record[1]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3473 | Def =cast<MacroDefinition>(PPRec.getLoadedPreprocessedEntity(GlobalID-1)); |
| 3474 | } |
| 3475 | |
| 3476 | MacroExpansion *ME; |
| 3477 | if (isBuiltin) |
| 3478 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 3479 | else |
| 3480 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 3481 | |
| 3482 | return ME; |
| 3483 | } |
| 3484 | |
| 3485 | case PPD_MACRO_DEFINITION: { |
| 3486 | // Decode the identifier info and then check again; if the macro is |
| 3487 | // still defined and associated with the identifier, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3488 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3489 | MacroDefinition *MD |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3490 | = new (PPRec) MacroDefinition(II, Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3491 | |
| 3492 | if (DeserializationListener) |
| 3493 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 3494 | |
| 3495 | return MD; |
| 3496 | } |
| 3497 | |
| 3498 | case PPD_INCLUSION_DIRECTIVE: { |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3499 | const char *FullFileNameStart = BlobStart + Record[0]; |
Argyrios Kyrtzidis | 29f98b4 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 3500 | StringRef FullFileName(FullFileNameStart, BlobLen - Record[0]); |
| 3501 | const FileEntry *File = 0; |
| 3502 | if (!FullFileName.empty()) |
| 3503 | File = PP.getFileManager().getFile(FullFileName); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3504 | |
| 3505 | // FIXME: Stable encoding |
| 3506 | InclusionDirective::InclusionKind Kind |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3507 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3508 | InclusionDirective *ID |
| 3509 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3510 | StringRef(BlobStart, Record[0]), |
Argyrios Kyrtzidis | 8dd927c | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 3511 | Record[1], Record[3], |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3512 | File, |
Argyrios Kyrtzidis | 8f958f1 | 2011-09-20 23:27:41 +0000 | [diff] [blame] | 3513 | Range); |
Argyrios Kyrtzidis | 290ad8c | 2011-09-20 23:27:38 +0000 | [diff] [blame] | 3514 | return ID; |
| 3515 | } |
| 3516 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 3517 | |
| 3518 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
Douglas Gregor | 6a5a23f | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3521 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 3522 | /// preprocessed entities or the entities it contains are not the ones we are |
| 3523 | /// looking for. Find the next module that contains entities and return the ID |
| 3524 | /// of the first entry. |
| 3525 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 3526 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 3527 | ++SLocMapI; |
| 3528 | for (GlobalSLocOffsetMapType::const_iterator |
| 3529 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3530 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3531 | if (M.NumPreprocessedEntities) |
| 3532 | return getGlobalPreprocessedEntityID(M, M.BasePreprocessedEntityID); |
| 3533 | } |
| 3534 | |
| 3535 | return getTotalNumPreprocessedEntities(); |
| 3536 | } |
| 3537 | |
| 3538 | namespace { |
| 3539 | |
| 3540 | template <unsigned PPEntityOffset::*PPLoc> |
| 3541 | struct PPEntityComp { |
| 3542 | const ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3543 | ModuleFile &M; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3544 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3545 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3546 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3547 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 3548 | SourceLocation LHS = getLoc(L); |
| 3549 | SourceLocation RHS = getLoc(R); |
| 3550 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3551 | } |
| 3552 | |
| 3553 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3554 | SourceLocation LHS = getLoc(L); |
| 3555 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3556 | } |
| 3557 | |
Benjamin Kramer | 88df125 | 2011-09-21 06:42:26 +0000 | [diff] [blame] | 3558 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3559 | SourceLocation RHS = getLoc(R); |
| 3560 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 3561 | } |
| 3562 | |
| 3563 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 3564 | return Reader.ReadSourceLocation(M, PPE.*PPLoc); |
| 3565 | } |
| 3566 | }; |
| 3567 | |
| 3568 | } |
| 3569 | |
| 3570 | /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc. |
| 3571 | PreprocessedEntityID |
| 3572 | ASTReader::findBeginPreprocessedEntity(SourceLocation BLoc) const { |
| 3573 | if (SourceMgr.isLocalSourceLocation(BLoc)) |
| 3574 | return getTotalNumPreprocessedEntities(); |
| 3575 | |
| 3576 | GlobalSLocOffsetMapType::const_iterator |
| 3577 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3578 | BLoc.getOffset()); |
| 3579 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3580 | "Corrupted global sloc offset map"); |
| 3581 | |
| 3582 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3583 | return findNextPreprocessedEntity(SLocMapI); |
| 3584 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3585 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3586 | typedef const PPEntityOffset *pp_iterator; |
| 3587 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3588 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
Argyrios Kyrtzidis | 4cd0634 | 2011-09-22 21:17:02 +0000 | [diff] [blame] | 3589 | |
| 3590 | size_t Count = M.NumPreprocessedEntities; |
| 3591 | size_t Half; |
| 3592 | pp_iterator First = pp_begin; |
| 3593 | pp_iterator PPI; |
| 3594 | |
| 3595 | // Do a binary search manually instead of using std::lower_bound because |
| 3596 | // The end locations of entities may be unordered (when a macro expansion |
| 3597 | // is inside another macro argument), but for this case it is not important |
| 3598 | // whether we get the first macro expansion or its containing macro. |
| 3599 | while (Count > 0) { |
| 3600 | Half = Count/2; |
| 3601 | PPI = First; |
| 3602 | std::advance(PPI, Half); |
| 3603 | if (SourceMgr.isBeforeInTranslationUnit(ReadSourceLocation(M, PPI->End), |
| 3604 | BLoc)){ |
| 3605 | First = PPI; |
| 3606 | ++First; |
| 3607 | Count = Count - Half - 1; |
| 3608 | } else |
| 3609 | Count = Half; |
| 3610 | } |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3611 | |
| 3612 | if (PPI == pp_end) |
| 3613 | return findNextPreprocessedEntity(SLocMapI); |
| 3614 | |
| 3615 | return getGlobalPreprocessedEntityID(M, |
| 3616 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3617 | } |
| 3618 | |
| 3619 | /// \brief Returns the first preprocessed entity ID that begins after \arg ELoc. |
| 3620 | PreprocessedEntityID |
| 3621 | ASTReader::findEndPreprocessedEntity(SourceLocation ELoc) const { |
| 3622 | if (SourceMgr.isLocalSourceLocation(ELoc)) |
| 3623 | return getTotalNumPreprocessedEntities(); |
| 3624 | |
| 3625 | GlobalSLocOffsetMapType::const_iterator |
| 3626 | SLocMapI = GlobalSLocOffsetMap.find(SourceManager::MaxLoadedOffset - |
| 3627 | ELoc.getOffset()); |
| 3628 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 3629 | "Corrupted global sloc offset map"); |
| 3630 | |
| 3631 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 3632 | return findNextPreprocessedEntity(SLocMapI); |
| 3633 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3634 | ModuleFile &M = *SLocMapI->second; |
Argyrios Kyrtzidis | 2dbaca7 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 3635 | typedef const PPEntityOffset *pp_iterator; |
| 3636 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 3637 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 3638 | pp_iterator PPI = |
| 3639 | std::upper_bound(pp_begin, pp_end, ELoc, |
| 3640 | PPEntityComp<&PPEntityOffset::Begin>(*this, M)); |
| 3641 | |
| 3642 | if (PPI == pp_end) |
| 3643 | return findNextPreprocessedEntity(SLocMapI); |
| 3644 | |
| 3645 | return getGlobalPreprocessedEntityID(M, |
| 3646 | M.BasePreprocessedEntityID + (PPI - pp_begin)); |
| 3647 | } |
| 3648 | |
| 3649 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 3650 | /// preprocessed entities that \arg Range encompasses. |
| 3651 | std::pair<unsigned, unsigned> |
| 3652 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 3653 | if (Range.isInvalid()) |
| 3654 | return std::make_pair(0,0); |
| 3655 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 3656 | |
| 3657 | PreprocessedEntityID BeginID = findBeginPreprocessedEntity(Range.getBegin()); |
| 3658 | PreprocessedEntityID EndID = findEndPreprocessedEntity(Range.getEnd()); |
| 3659 | return std::make_pair(BeginID, EndID); |
| 3660 | } |
| 3661 | |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3662 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 3663 | /// entity with index \arg Index came from file \arg FID. |
| 3664 | llvm::Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 3665 | FileID FID) { |
| 3666 | if (FID.isInvalid()) |
| 3667 | return false; |
| 3668 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3669 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 3670 | ModuleFile &M = *PPInfo.first; |
Argyrios Kyrtzidis | f226ff9 | 2011-10-25 00:29:50 +0000 | [diff] [blame] | 3671 | unsigned LocalIndex = PPInfo.second; |
| 3672 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 3673 | |
| 3674 | SourceLocation Loc = ReadSourceLocation(M, PPOffs.Begin); |
| 3675 | if (Loc.isInvalid()) |
| 3676 | return false; |
| 3677 | |
| 3678 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 3679 | return true; |
| 3680 | else |
| 3681 | return false; |
| 3682 | } |
| 3683 | |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3684 | namespace { |
| 3685 | /// \brief Visitor used to search for information about a header file. |
| 3686 | class HeaderFileInfoVisitor { |
| 3687 | ASTReader &Reader; |
| 3688 | const FileEntry *FE; |
| 3689 | |
| 3690 | llvm::Optional<HeaderFileInfo> HFI; |
| 3691 | |
| 3692 | public: |
| 3693 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3694 | : Reader(Reader), FE(FE) { } |
| 3695 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3696 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3697 | HeaderFileInfoVisitor *This |
| 3698 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3699 | |
| 3700 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3701 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3702 | M.HeaderFileFrameworkStrings, |
| 3703 | This->FE->getName()); |
| 3704 | |
| 3705 | HeaderFileInfoLookupTable *Table |
| 3706 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3707 | if (!Table) |
| 3708 | return false; |
| 3709 | |
| 3710 | // Look in the on-disk hash table for an entry for this file name. |
| 3711 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3712 | &Trait); |
| 3713 | if (Pos == Table->end()) |
| 3714 | return false; |
| 3715 | |
| 3716 | This->HFI = *Pos; |
| 3717 | return true; |
| 3718 | } |
| 3719 | |
| 3720 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3721 | }; |
| 3722 | } |
| 3723 | |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3724 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3725 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3726 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3727 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3728 | if (Listener) |
Douglas Gregor | d10a381 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3729 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3730 | return *HFI; |
Douglas Gregor | cfbf1c7 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | return HeaderFileInfo(); |
| 3734 | } |
| 3735 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 3736 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3737 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3738 | ModuleFile &F = *(*I); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3739 | unsigned Idx = 0; |
| 3740 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3741 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3742 | Diag.DiagStates.push_back(*Diag.GetCurDiagState()); |
| 3743 | Diag.DiagStatePoints.push_back( |
| 3744 | DiagnosticsEngine::DiagStatePoint(&Diag.DiagStates.back(), |
| 3745 | FullSourceLoc(Loc, SourceMgr))); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3746 | while (1) { |
| 3747 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3748 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3749 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3750 | break; // Something is messed up but at least avoid infinite loop in |
| 3751 | // release build. |
| 3752 | } |
| 3753 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3754 | if (DiagID == (unsigned)-1) { |
| 3755 | break; // no more diag/map pairs for this location. |
| 3756 | } |
| 3757 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
Argyrios Kyrtzidis | 87429a0 | 2011-11-09 01:24:17 +0000 | [diff] [blame] | 3758 | DiagnosticMappingInfo MappingInfo = Diag.makeMappingInfo(Map, Loc); |
| 3759 | Diag.GetCurDiagState()->setMappingInfo(DiagID, MappingInfo); |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3760 | } |
Argyrios Kyrtzidis | 3efd52c | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3761 | } |
Argyrios Kyrtzidis | f41d3be | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3762 | } |
| 3763 | } |
| 3764 | |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3765 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3766 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3767 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | e9b76c1 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3768 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 3769 | ModuleFile *M = I->second; |
Douglas Gregor | e360501 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3770 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3774 | /// |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3775 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3776 | /// routine actually reads the record corresponding to the type at the given |
| 3777 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3778 | /// IDs. |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3779 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3780 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3781 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 9137a52 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3782 | |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3783 | // Keep track of where we are in the stream, then jump back there |
| 3784 | // after reading this type. |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3785 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3786 | |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3787 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | 27372b4 | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3788 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3789 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3790 | Deserializing AType(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3791 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3792 | unsigned Idx = 0; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3793 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3794 | RecordData Record; |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3795 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3796 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3797 | case TYPE_EXT_QUAL: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3798 | if (Record.size() != 2) { |
| 3799 | Error("Incorrect encoding of extended qualifier type"); |
| 3800 | return QualType(); |
| 3801 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3802 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3803 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3804 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 6d47396 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3805 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3806 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3807 | case TYPE_COMPLEX: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3808 | if (Record.size() != 1) { |
| 3809 | Error("Incorrect encoding of complex type"); |
| 3810 | return QualType(); |
| 3811 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3812 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3813 | return Context.getComplexType(ElemType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3816 | case TYPE_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3817 | if (Record.size() != 1) { |
| 3818 | Error("Incorrect encoding of pointer type"); |
| 3819 | return QualType(); |
| 3820 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3821 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3822 | return Context.getPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3825 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3826 | if (Record.size() != 1) { |
| 3827 | Error("Incorrect encoding of block pointer type"); |
| 3828 | return QualType(); |
| 3829 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3830 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3831 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3834 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | df1550f | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3835 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3836 | Error("Incorrect encoding of lvalue reference type"); |
| 3837 | return QualType(); |
| 3838 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3839 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3840 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3841 | } |
| 3842 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3843 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3844 | if (Record.size() != 1) { |
| 3845 | Error("Incorrect encoding of rvalue reference type"); |
| 3846 | return QualType(); |
| 3847 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3848 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3849 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3852 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | 240437b | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3853 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3854 | Error("Incorrect encoding of member pointer type"); |
| 3855 | return QualType(); |
| 3856 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3857 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3858 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3859 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3860 | return QualType(); |
| 3861 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3862 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3865 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3866 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3867 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3868 | unsigned IndexTypeQuals = Record[2]; |
| 3869 | unsigned Idx = 3; |
| 3870 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3871 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3872 | ASM, IndexTypeQuals); |
| 3873 | } |
| 3874 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3875 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3876 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3877 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3878 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3879 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3882 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3883 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0b74891 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3884 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3885 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3886 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3887 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3888 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3889 | ASM, IndexTypeQuals, |
| 3890 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3893 | case TYPE_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3894 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3895 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3896 | return QualType(); |
| 3897 | } |
| 3898 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3899 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3900 | unsigned NumElements = Record[1]; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3901 | unsigned VecKind = Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3902 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3903 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3904 | } |
| 3905 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3906 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3907 | if (Record.size() != 3) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3908 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3909 | return QualType(); |
| 3910 | } |
| 3911 | |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3912 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3913 | unsigned NumElements = Record[1]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3914 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3917 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3918 | if (Record.size() != 6) { |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3919 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3920 | return QualType(); |
| 3921 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3922 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3923 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3924 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3925 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3928 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3929 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3930 | |
| 3931 | FunctionProtoType::ExtProtoInfo EPI; |
| 3932 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | a49218e | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3933 | /*hasregparm*/ Record[2], |
| 3934 | /*regparm*/ Record[3], |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3935 | static_cast<CallingConv>(Record[4]), |
| 3936 | /*produces*/ Record[5]); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3937 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3938 | unsigned Idx = 6; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3939 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3940 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3941 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3942 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3943 | |
| 3944 | EPI.Variadic = Record[Idx++]; |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 3945 | EPI.HasTrailingReturn = Record[Idx++]; |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3946 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | c938c16 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3947 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3948 | ExceptionSpecificationType EST = |
| 3949 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3950 | EPI.ExceptionSpecType = EST; |
Douglas Gregor | b0d06e2 | 2012-04-04 00:34:49 +0000 | [diff] [blame] | 3951 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3952 | if (EST == EST_Dynamic) { |
| 3953 | EPI.NumExceptions = Record[Idx++]; |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3954 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3955 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3956 | EPI.Exceptions = Exceptions.data(); |
| 3957 | } else if (EST == EST_ComputedNoexcept) { |
| 3958 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
Richard Smith | 7bb698a | 2012-04-21 17:47:47 +0000 | [diff] [blame] | 3959 | } else if (EST == EST_Uninstantiated) { |
| 3960 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
| 3961 | EPI.ExceptionSpecTemplate = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Richard Smith | b9d0b76 | 2012-07-27 04:22:15 +0000 | [diff] [blame] | 3962 | } else if (EST == EST_Unevaluated) { |
| 3963 | EPI.ExceptionSpecDecl = ReadDeclAs<FunctionDecl>(*Loc.F, Record, Idx); |
Sebastian Redl | 60618fa | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3964 | } |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3965 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | e23cf43 | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3966 | EPI); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3969 | case TYPE_UNRESOLVED_USING: { |
| 3970 | unsigned Idx = 0; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3971 | return Context.getTypeDeclType( |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3972 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3973 | } |
| 3974 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3975 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3976 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3977 | Error("incorrect encoding of typedef type"); |
| 3978 | return QualType(); |
| 3979 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3980 | unsigned Idx = 0; |
| 3981 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3982 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3983 | if (!Canonical.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3984 | Canonical = Context.getCanonicalType(Canonical); |
| 3985 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3986 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3987 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3988 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3989 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3990 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3991 | case TYPE_TYPEOF: { |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3992 | if (Record.size() != 1) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3993 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3994 | return QualType(); |
| 3995 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3996 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3997 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3998 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3999 | |
Douglas Gregor | f8af982 | 2012-02-12 18:42:33 +0000 | [diff] [blame] | 4000 | case TYPE_DECLTYPE: { |
| 4001 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 4002 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 4003 | } |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 4004 | |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4005 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4006 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 4007 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4008 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4009 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4010 | } |
| 4011 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4012 | case TYPE_AUTO: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4013 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4014 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4015 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4016 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4017 | Error("incorrect encoding of record type"); |
| 4018 | return QualType(); |
| 4019 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4020 | unsigned Idx = 0; |
| 4021 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4022 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 4023 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 4024 | QualType T = Context.getRecordType(RD); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4025 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4026 | return T; |
| 4027 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4028 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4029 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4030 | if (Record.size() != 2) { |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4031 | Error("incorrect encoding of enum type"); |
| 4032 | return QualType(); |
| 4033 | } |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4034 | unsigned Idx = 0; |
| 4035 | bool IsDependent = Record[Idx++]; |
| 4036 | QualType T |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4037 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4038 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4039 | return T; |
| 4040 | } |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4041 | |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4042 | case TYPE_ATTRIBUTED: { |
| 4043 | if (Record.size() != 3) { |
| 4044 | Error("incorrect encoding of attributed type"); |
| 4045 | return QualType(); |
| 4046 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4047 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 4048 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4049 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4050 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4053 | case TYPE_PAREN: { |
| 4054 | if (Record.size() != 1) { |
| 4055 | Error("incorrect encoding of paren type"); |
| 4056 | return QualType(); |
| 4057 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4058 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4059 | return Context.getParenType(InnerType); |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4060 | } |
| 4061 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4062 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | f9997a0 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 4063 | if (Record.size() != 2) { |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4064 | Error("incorrect encoding of pack expansion type"); |
| 4065 | return QualType(); |
| 4066 | } |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4067 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4068 | if (Pattern.isNull()) |
| 4069 | return QualType(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 4070 | llvm::Optional<unsigned> NumExpansions; |
| 4071 | if (Record[1]) |
| 4072 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4073 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4076 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4077 | unsigned Idx = 0; |
| 4078 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4079 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4080 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4081 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 4082 | } |
| 4083 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4084 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4085 | unsigned Idx = 0; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4086 | ObjCInterfaceDecl *ItfD |
| 4087 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 4088 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4091 | case TYPE_OBJC_OBJECT: { |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4092 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4093 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4094 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4095 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4096 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4097 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4098 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | c6fa445 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 4099 | } |
Douglas Gregor | b4e715b | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 4100 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4101 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4102 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4103 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4104 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | d7a3fcd | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 4105 | } |
Argyrios Kyrtzidis | 24fab41 | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 4106 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4107 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4108 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4109 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 4110 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4111 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4112 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4113 | Replacement); |
| 4114 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4115 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4116 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 4117 | unsigned Idx = 0; |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4118 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4119 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4120 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4121 | cast<TemplateTypeParmType>(Parm), |
| 4122 | ArgPack); |
| 4123 | } |
| 4124 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4125 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4126 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4127 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4128 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4129 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | 43921b5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 4130 | return |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4131 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4132 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4133 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4134 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4135 | unsigned Idx = 0; |
| 4136 | unsigned Depth = Record[Idx++]; |
| 4137 | unsigned Index = Record[Idx++]; |
| 4138 | bool Pack = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4139 | TemplateTypeParmDecl *D |
| 4140 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4141 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4142 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4143 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4144 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4145 | unsigned Idx = 0; |
| 4146 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4147 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4148 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4149 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 32adc8b | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 4150 | if (!Canon.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4151 | Canon = Context.getCanonicalType(Canon); |
| 4152 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | 8dfbd8b | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 4153 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4154 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4155 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4156 | unsigned Idx = 0; |
| 4157 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4158 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4159 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4160 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4161 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4162 | Args.reserve(NumArgs); |
| 4163 | while (NumArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4164 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4165 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | 3acad62 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 4166 | Args.size(), Args.data()); |
| 4167 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 4168 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4169 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4170 | unsigned Idx = 0; |
| 4171 | |
| 4172 | // ArrayType |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4173 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4174 | ArrayType::ArraySizeModifier ASM |
| 4175 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 4176 | unsigned IndexTypeQuals = Record[Idx++]; |
| 4177 | |
| 4178 | // DependentSizedArrayType |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4179 | Expr *NumElts = ReadExpr(*Loc.F); |
| 4180 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4181 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4182 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | ae8b17f | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 4183 | IndexTypeQuals, Brackets); |
| 4184 | } |
Argyrios Kyrtzidis | 90b715e | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 4185 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4186 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4187 | unsigned Idx = 0; |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4188 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 4189 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4190 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4191 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4192 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4193 | QualType T; |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4194 | if (Underlying.isNull()) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4195 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4196 | Args.size()); |
Argyrios Kyrtzidis | 9763e22 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 4197 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4198 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 4199 | Args.size(), Underlying); |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 4200 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | be19110 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 4201 | return T; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4202 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4203 | |
| 4204 | case TYPE_ATOMIC: { |
| 4205 | if (Record.size() != 1) { |
| 4206 | Error("Incorrect encoding of atomic type"); |
| 4207 | return QualType(); |
| 4208 | } |
| 4209 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 4210 | return Context.getAtomicType(ValueType); |
| 4211 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4212 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 4213 | llvm_unreachable("Invalid TypeCode!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4214 | } |
| 4215 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4216 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4217 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4218 | ModuleFile &F; |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4219 | const ASTReader::RecordData &Record; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4220 | unsigned &Idx; |
| 4221 | |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4222 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 4223 | unsigned &I) { |
| 4224 | return Reader.ReadSourceLocation(F, R, I); |
| 4225 | } |
| 4226 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4227 | template<typename T> |
| 4228 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 4229 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 4230 | } |
| 4231 | |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4232 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4233 | TypeLocReader(ASTReader &Reader, ModuleFile &F, |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4234 | const ASTReader::RecordData &Record, unsigned &Idx) |
Benjamin Kramer | facde17 | 2012-06-06 17:32:50 +0000 | [diff] [blame] | 4235 | : Reader(Reader), F(F), Record(Record), Idx(Idx) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4236 | { } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4237 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4238 | // We want compile-time assurance that we've enumerated all of |
| 4239 | // these, so unfortunately we have to declare them first, then |
| 4240 | // define them out-of-line. |
| 4241 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4242 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4243 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4244 | #include "clang/AST/TypeLocNodes.def" |
| 4245 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4246 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 4247 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4248 | }; |
| 4249 | |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4250 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4251 | // nothing to do |
| 4252 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4253 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4254 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 4255 | if (TL.needsExtraLocalData()) { |
| 4256 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 4257 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 4258 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 4259 | TL.setModeAttr(Record[Idx++]); |
| 4260 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4261 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4262 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4263 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4264 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4265 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4266 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4267 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4268 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4269 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4270 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4271 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4272 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4273 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4274 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4275 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4276 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4277 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4278 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | b6ab6c1 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 4279 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4280 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4281 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4282 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 4283 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4284 | if (Record[Idx++]) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4285 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 61d60ee | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 4286 | else |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4287 | TL.setSizeExpr(0); |
| 4288 | } |
| 4289 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 4290 | VisitArrayTypeLoc(TL); |
| 4291 | } |
| 4292 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 4293 | VisitArrayTypeLoc(TL); |
| 4294 | } |
| 4295 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 4296 | VisitArrayTypeLoc(TL); |
| 4297 | } |
| 4298 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 4299 | DependentSizedArrayTypeLoc TL) { |
| 4300 | VisitArrayTypeLoc(TL); |
| 4301 | } |
| 4302 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 4303 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4304 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4305 | } |
| 4306 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4307 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4308 | } |
| 4309 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4310 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4311 | } |
| 4312 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4313 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 4314 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4315 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 4316 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4317 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4318 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4319 | } |
| 4320 | } |
| 4321 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 4322 | VisitFunctionTypeLoc(TL); |
| 4323 | } |
| 4324 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 4325 | VisitFunctionTypeLoc(TL); |
| 4326 | } |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4327 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4328 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 4329 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4330 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4331 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4332 | } |
| 4333 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4334 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4335 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4336 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4337 | } |
| 4338 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4339 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 4340 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4341 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4342 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4343 | } |
| 4344 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4345 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4346 | } |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 4347 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 4348 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4349 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4350 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4351 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 4352 | } |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 4353 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 4354 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4355 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4356 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4357 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4358 | } |
| 4359 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4360 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4361 | } |
John McCall | 9d156a7 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 4362 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 4363 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 4364 | if (TL.hasAttrOperand()) { |
| 4365 | SourceRange range; |
| 4366 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 4367 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 4368 | TL.setAttrOperandParensRange(range); |
| 4369 | } |
| 4370 | if (TL.hasAttrExprOperand()) { |
| 4371 | if (Record[Idx++]) |
| 4372 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 4373 | else |
| 4374 | TL.setAttrExprOperand(0); |
| 4375 | } else if (TL.hasAttrEnumOperand()) |
| 4376 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 4377 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4378 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4379 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4380 | } |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4381 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 4382 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4383 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 49a832b | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 4384 | } |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 4385 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 4386 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 4387 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 4388 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4389 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 4390 | TemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4391 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4392 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 4393 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4394 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4395 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 4396 | TL.setArgLocInfo(i, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4397 | Reader.GetTemplateArgumentLocInfo(F, |
| 4398 | TL.getTypePtr()->getArg(i).getKind(), |
| 4399 | Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4400 | } |
Abramo Bagnara | 075f8f1 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 4401 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 4402 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4403 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4404 | } |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 4405 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4406 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 9e87687 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 4407 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4408 | } |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4409 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4410 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3cb0ebd | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 4411 | } |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 4412 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Abramo Bagnara | 38a4291 | 2012-02-06 19:09:27 +0000 | [diff] [blame] | 4413 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 2494dd0 | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 4414 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4415 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4416 | } |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4417 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 4418 | DependentTemplateSpecializationTypeLoc TL) { |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4419 | TL.setElaboratedKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 94fdffa | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 4420 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Abramo Bagnara | 66581d4 | 2012-02-06 22:45:07 +0000 | [diff] [blame] | 4421 | TL.setTemplateKeywordLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 55d23c9 | 2012-02-06 14:41:24 +0000 | [diff] [blame] | 4422 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4423 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4424 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4425 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 4426 | TL.setArgLocInfo(I, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4427 | Reader.GetTemplateArgumentLocInfo(F, |
| 4428 | TL.getTypePtr()->getArg(I).getKind(), |
| 4429 | Record, Idx)); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 4430 | } |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 4431 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 4432 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 4433 | } |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4434 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4435 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 4436 | } |
| 4437 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 4438 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4439 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 4440 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 51bd803 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 4441 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4442 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4443 | } |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4444 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4445 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 4446 | } |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 4447 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 4448 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 4449 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 4450 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 4451 | } |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4452 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4453 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4454 | const RecordData &Record, |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4455 | unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4456 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4457 | if (InfoTy.isNull()) |
| 4458 | return 0; |
| 4459 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4460 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4461 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4462 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4463 | TLR.Visit(TL); |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4464 | return TInfo; |
John McCall | a1ee0c5 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4465 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4466 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4467 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4468 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4469 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4470 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4471 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4472 | QualType T; |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4473 | switch ((PredefinedTypeIDs)Index) { |
| 4474 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4475 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 4476 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4477 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4478 | case PREDEF_TYPE_CHAR_U_ID: |
| 4479 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4480 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4481 | T = Context.CharTy; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4482 | break; |
| 4483 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4484 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 4485 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 4486 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 4487 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 4488 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 4489 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 4490 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 4491 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 4492 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 4493 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 4494 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 4495 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 4496 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 4497 | case PREDEF_TYPE_HALF_ID: T = Context.HalfTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4498 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 4499 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 4500 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 4501 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 4502 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
John McCall | 3c3b7f9 | 2011-10-25 17:37:35 +0000 | [diff] [blame] | 4503 | case PREDEF_TYPE_PSEUDO_OBJECT: T = Context.PseudoObjectTy; break; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4504 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 4505 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 4506 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 4507 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 4508 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 4509 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 4510 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 4511 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 4512 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4513 | |
| 4514 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4515 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | 3b8043b | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4516 | break; |
John McCall | 0ddaeb9 | 2011-10-17 18:09:15 +0000 | [diff] [blame] | 4517 | |
| 4518 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 4519 | T = Context.ARCUnbridgedCastTy; |
| 4520 | break; |
| 4521 | |
Meador Inge | fb40e3f | 2012-07-01 15:57:25 +0000 | [diff] [blame] | 4522 | case PREDEF_TYPE_VA_LIST_TAG: |
| 4523 | T = Context.getVaListTagType(); |
| 4524 | break; |
Eli Friedman | a6c66ce | 2012-08-31 00:14:07 +0000 | [diff] [blame] | 4525 | |
| 4526 | case PREDEF_TYPE_BUILTIN_FN: |
| 4527 | T = Context.BuiltinFnTy; |
| 4528 | break; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4529 | } |
| 4530 | |
| 4531 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4532 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4535 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | aaec0aa | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4536 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4537 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4538 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9747583 | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4539 | if (TypesLoaded[Index].isNull()) |
| 4540 | return QualType(); |
| 4541 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4542 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4543 | if (DeserializationListener) |
Argyrios Kyrtzidis | c8e5d51 | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4544 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1476ed4 | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4545 | TypesLoaded[Index]); |
Sebastian Redl | 07a353c | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4546 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4547 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4548 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4549 | } |
| 4550 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4551 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4552 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4553 | } |
| 4554 | |
| 4555 | serialization::TypeID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4556 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
Douglas Gregor | a119da0 | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4557 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4558 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4559 | |
| 4560 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4561 | return LocalID; |
| 4562 | |
| 4563 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4564 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4565 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4566 | |
| 4567 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4568 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4569 | } |
| 4570 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4571 | TemplateArgumentLocInfo |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4572 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4573 | TemplateArgument::ArgKind Kind, |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4574 | const RecordData &Record, |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4575 | unsigned &Index) { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4576 | switch (Kind) { |
| 4577 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4578 | return ReadExpr(F); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4579 | case TemplateArgument::Type: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4580 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4581 | case TemplateArgument::Template: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4582 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4583 | Index); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4584 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4585 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4586 | SourceLocation()); |
| 4587 | } |
| 4588 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4589 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4590 | Index); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4591 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4592 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4593 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4594 | EllipsisLoc); |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4595 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4596 | case TemplateArgument::Null: |
| 4597 | case TemplateArgument::Integral: |
| 4598 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4599 | case TemplateArgument::NullPtr: |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4600 | case TemplateArgument::Pack: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 4601 | // FIXME: Is this right? |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4602 | return TemplateArgumentLocInfo(); |
| 4603 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4604 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4607 | TemplateArgumentLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4608 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4609 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4610 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4611 | |
| 4612 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4613 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4614 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4615 | } |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4616 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | 919e693 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4617 | Record, Index)); |
Argyrios Kyrtzidis | 44f8c37 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4618 | } |
| 4619 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4620 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4621 | return GetDecl(ID); |
| 4622 | } |
| 4623 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4624 | uint64_t ASTReader::readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record, |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4625 | unsigned &Idx){ |
| 4626 | if (Idx >= Record.size()) |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4627 | return 0; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4628 | |
Douglas Gregor | e92b8a1 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4629 | unsigned LocalID = Record[Idx++]; |
| 4630 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4631 | } |
| 4632 | |
| 4633 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4634 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4635 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4636 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4637 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4638 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4639 | RecordData Record; |
| 4640 | unsigned Code = Cursor.ReadCode(); |
| 4641 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4642 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4643 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4644 | return 0; |
| 4645 | } |
| 4646 | |
| 4647 | unsigned Idx = 0; |
| 4648 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4649 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4650 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4651 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4652 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 7c789c1 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4653 | return Bases; |
| 4654 | } |
| 4655 | |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4656 | serialization::DeclID |
Argyrios Kyrtzidis | 2093e0b | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 4657 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4658 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4659 | return LocalID; |
| 4660 | |
| 4661 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4662 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4663 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4664 | |
| 4665 | return LocalID + I->second; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4668 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4669 | ModuleFile &M) const { |
Argyrios Kyrtzidis | e6b8d68 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4670 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4671 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4672 | return &M == I->second; |
| 4673 | } |
| 4674 | |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4675 | ModuleFile *ASTReader::getOwningModuleFile(Decl *D) { |
| 4676 | if (!D->isFromASTFile()) |
| 4677 | return 0; |
| 4678 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 4679 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4680 | return I->second; |
| 4681 | } |
| 4682 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4683 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 4684 | if (ID < NUM_PREDEF_DECL_IDS) |
| 4685 | return SourceLocation(); |
| 4686 | |
| 4687 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4688 | |
| 4689 | if (Index > DeclsLoaded.size()) { |
| 4690 | Error("declaration ID out-of-range for AST file"); |
| 4691 | return SourceLocation(); |
| 4692 | } |
| 4693 | |
| 4694 | if (Decl *D = DeclsLoaded[Index]) |
| 4695 | return D->getLocation(); |
| 4696 | |
| 4697 | unsigned RawLocation = 0; |
| 4698 | RecordLocation Rec = DeclCursorForID(ID, RawLocation); |
| 4699 | return ReadSourceLocation(*Rec.F, RawLocation); |
| 4700 | } |
| 4701 | |
Sebastian Redl | 8538e8d | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4702 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4703 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4704 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4705 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4706 | return 0; |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4707 | |
| 4708 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4709 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 4dfd02a | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4710 | |
| 4711 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4712 | return Context.getObjCIdDecl(); |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4713 | |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4714 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4715 | return Context.getObjCSelDecl(); |
Douglas Gregor | 7a27ea5 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4716 | |
Douglas Gregor | 79d6726 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4717 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4718 | return Context.getObjCClassDecl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4719 | |
Douglas Gregor | a6ea10e | 2012-01-17 18:09:05 +0000 | [diff] [blame] | 4720 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 4721 | return Context.getObjCProtocolDecl(); |
| 4722 | |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4723 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4724 | return Context.getInt128Decl(); |
Douglas Gregor | 772eeae | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4725 | |
| 4726 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4727 | return Context.getUInt128Decl(); |
Douglas Gregor | e97179c | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4728 | |
| 4729 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4730 | return Context.getObjCInstanceTypeDecl(); |
Meador Inge | c5613b2 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4731 | |
| 4732 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 4733 | return Context.getBuiltinVaListDecl(); |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4734 | } |
Douglas Gregor | 0a14e4b | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4737 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4738 | |
Richard Smith | 2fbf373 | 2011-12-20 04:39:57 +0000 | [diff] [blame] | 4739 | if (Index >= DeclsLoaded.size()) { |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4740 | assert(0 && "declaration ID out-of-range for AST file"); |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4741 | Error("declaration ID out-of-range for AST file"); |
Argyrios Kyrtzidis | 7518b37 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4742 | return 0; |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4743 | } |
Douglas Gregor | 6bf2b9f | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4744 | |
Douglas Gregor | fd002a7 | 2011-12-16 22:37:11 +0000 | [diff] [blame] | 4745 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | 496c709 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4746 | ReadDeclRecord(ID); |
Sebastian Redl | 30c514c | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4747 | if (DeserializationListener) |
| 4748 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4749 | } |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4750 | |
| 4751 | return DeclsLoaded[Index]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4752 | } |
| 4753 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4754 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 4755 | DeclID GlobalID) { |
| 4756 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 4757 | return GlobalID; |
| 4758 | |
| 4759 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 4760 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4761 | ModuleFile *Owner = I->second; |
| 4762 | |
| 4763 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 4764 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 4765 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 4766 | return 0; |
| 4767 | |
| 4768 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 4769 | } |
| 4770 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4771 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4772 | const RecordData &Record, |
| 4773 | unsigned &Idx) { |
| 4774 | if (Idx >= Record.size()) { |
| 4775 | Error("Corrupted AST file"); |
| 4776 | return 0; |
| 4777 | } |
| 4778 | |
| 4779 | return getGlobalDeclID(F, Record[Idx++]); |
| 4780 | } |
| 4781 | |
Chris Lattner | 887e2b3 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4782 | /// \brief Resolve the offset of a statement into a statement. |
| 4783 | /// |
| 4784 | /// This operation will read a new statement from the external |
| 4785 | /// source each time it is called, and is meant to be used via a |
| 4786 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4787 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4788 | // Switch case IDs are per Decl. |
| 4789 | ClearSwitchCaseIDs(); |
| 4790 | |
Sebastian Redl | 0fa7d0b | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4791 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4792 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4793 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4794 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 250fc9c | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4795 | } |
| 4796 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4797 | namespace { |
| 4798 | class FindExternalLexicalDeclsVisitor { |
| 4799 | ASTReader &Reader; |
| 4800 | const DeclContext *DC; |
| 4801 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4802 | |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4803 | SmallVectorImpl<Decl*> &Decls; |
| 4804 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4805 | |
| 4806 | public: |
| 4807 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4808 | bool (*isKindWeWant)(Decl::Kind), |
| 4809 | SmallVectorImpl<Decl*> &Decls) |
| 4810 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4811 | { |
| 4812 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4813 | PredefsVisited[I] = false; |
| 4814 | } |
| 4815 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4816 | static bool visit(ModuleFile &M, bool Preorder, void *UserData) { |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4817 | if (Preorder) |
| 4818 | return false; |
| 4819 | |
| 4820 | FindExternalLexicalDeclsVisitor *This |
| 4821 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4822 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4823 | ModuleFile::DeclContextInfosMap::iterator Info |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4824 | = M.DeclContextInfos.find(This->DC); |
| 4825 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4826 | return false; |
| 4827 | |
| 4828 | // Load all of the declaration IDs |
| 4829 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4830 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4831 | ID != IDE; ++ID) { |
| 4832 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4833 | continue; |
| 4834 | |
| 4835 | // Don't add predefined declarations to the lexical context more |
| 4836 | // than once. |
| 4837 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4838 | if (This->PredefsVisited[ID->second]) |
| 4839 | continue; |
| 4840 | |
| 4841 | This->PredefsVisited[ID->second] = true; |
| 4842 | } |
| 4843 | |
Douglas Gregor | 2ea054f | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4844 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4845 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4846 | This->Decls.push_back(D); |
| 4847 | } |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | return false; |
| 4851 | } |
| 4852 | }; |
| 4853 | } |
| 4854 | |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4855 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | eb5e998 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4856 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4857 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4858 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 851c75a | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4859 | // least. Walk all of the modules in the order they were loaded. |
| 4860 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4861 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4862 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ba6ffaf | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4863 | return ELR_Success; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4864 | } |
| 4865 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4866 | namespace { |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4867 | |
| 4868 | class DeclIDComp { |
| 4869 | ASTReader &Reader; |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4870 | ModuleFile &Mod; |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4871 | |
| 4872 | public: |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4873 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4874 | |
| 4875 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 4876 | SourceLocation LHS = getLocation(L); |
| 4877 | SourceLocation RHS = getLocation(R); |
| 4878 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4879 | } |
| 4880 | |
| 4881 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 4882 | SourceLocation RHS = getLocation(R); |
| 4883 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4884 | } |
| 4885 | |
| 4886 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 4887 | SourceLocation LHS = getLocation(L); |
| 4888 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 4889 | } |
| 4890 | |
| 4891 | SourceLocation getLocation(LocalDeclID ID) const { |
| 4892 | return Reader.getSourceManager().getFileLoc( |
| 4893 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 4894 | } |
| 4895 | }; |
| 4896 | |
| 4897 | } |
| 4898 | |
| 4899 | void ASTReader::FindFileRegionDecls(FileID File, |
| 4900 | unsigned Offset, unsigned Length, |
| 4901 | SmallVectorImpl<Decl *> &Decls) { |
| 4902 | SourceManager &SM = getSourceManager(); |
| 4903 | |
| 4904 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 4905 | if (I == FileDeclIDs.end()) |
| 4906 | return; |
| 4907 | |
| 4908 | FileDeclsInfo &DInfo = I->second; |
| 4909 | if (DInfo.Decls.empty()) |
| 4910 | return; |
| 4911 | |
| 4912 | SourceLocation |
| 4913 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 4914 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 4915 | |
| 4916 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 4917 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4918 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4919 | BeginLoc, DIDComp); |
| 4920 | if (BeginIt != DInfo.Decls.begin()) |
| 4921 | --BeginIt; |
| 4922 | |
Argyrios Kyrtzidis | c14a03d | 2011-11-23 20:27:36 +0000 | [diff] [blame] | 4923 | // If we are pointing at a top-level decl inside an objc container, we need |
| 4924 | // to backtrack until we find it otherwise we will fail to report that the |
| 4925 | // region overlaps with an objc container. |
| 4926 | while (BeginIt != DInfo.Decls.begin() && |
| 4927 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 4928 | ->isTopLevelDeclInObjCContainer()) |
| 4929 | --BeginIt; |
| 4930 | |
Argyrios Kyrtzidis | dfb332d | 2011-11-03 02:20:32 +0000 | [diff] [blame] | 4931 | ArrayRef<serialization::LocalDeclID>::iterator |
| 4932 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 4933 | EndLoc, DIDComp); |
| 4934 | if (EndIt != DInfo.Decls.end()) |
| 4935 | ++EndIt; |
| 4936 | |
| 4937 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 4938 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 4939 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 4940 | } |
| 4941 | |
| 4942 | namespace { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4943 | /// \brief ModuleFile visitor used to perform name lookup into a |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4944 | /// declaration context. |
| 4945 | class DeclContextNameLookupVisitor { |
| 4946 | ASTReader &Reader; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4947 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4948 | DeclarationName Name; |
| 4949 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4950 | |
| 4951 | public: |
| 4952 | DeclContextNameLookupVisitor(ASTReader &Reader, |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4953 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 4954 | DeclarationName Name, |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4955 | SmallVectorImpl<NamedDecl *> &Decls) |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4956 | : Reader(Reader), Contexts(Contexts), Name(Name), Decls(Decls) { } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4957 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 4958 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4959 | DeclContextNameLookupVisitor *This |
| 4960 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4961 | |
| 4962 | // Check whether we have any visible declaration information for |
| 4963 | // this context in this module. |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4964 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 4965 | bool FoundInfo = false; |
| 4966 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 4967 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 4968 | if (Info != M.DeclContextInfos.end() && |
| 4969 | Info->second.NameLookupTableData) { |
| 4970 | FoundInfo = true; |
| 4971 | break; |
| 4972 | } |
| 4973 | } |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4974 | |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 4975 | if (!FoundInfo) |
| 4976 | return false; |
| 4977 | |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4978 | // Look for this name within this module. |
| 4979 | ASTDeclContextNameLookupTable *LookupTable = |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 4980 | Info->second.NameLookupTableData; |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4981 | ASTDeclContextNameLookupTable::iterator Pos |
| 4982 | = LookupTable->find(This->Name); |
| 4983 | if (Pos == LookupTable->end()) |
| 4984 | return false; |
| 4985 | |
| 4986 | bool FoundAnything = false; |
| 4987 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4988 | for (; Data.first != Data.second; ++Data.first) { |
| 4989 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4990 | if (!ND) |
| 4991 | continue; |
| 4992 | |
| 4993 | if (ND->getDeclName() != This->Name) { |
Axel Naumann | 3dd82f7 | 2012-10-01 09:51:27 +0000 | [diff] [blame] | 4994 | // A name might be null because the decl's redeclarable part is |
| 4995 | // currently read before reading its name. The lookup is triggered by |
| 4996 | // building that decl (likely indirectly), and so it is later in the |
| 4997 | // sense of "already existing" and can be ignored here. |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4998 | continue; |
| 4999 | } |
| 5000 | |
| 5001 | // Record this declaration. |
| 5002 | FoundAnything = true; |
| 5003 | This->Decls.push_back(ND); |
| 5004 | } |
| 5005 | |
| 5006 | return FoundAnything; |
| 5007 | } |
| 5008 | }; |
| 5009 | } |
| 5010 | |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5011 | DeclContext::lookup_result |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5012 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5013 | DeclarationName Name) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5014 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5015 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5016 | if (!Name) |
| 5017 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 5018 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | d5d7b3f | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 5019 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5020 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | c6c8e0e | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 5021 | |
| 5022 | // Compute the declaration contexts we need to look into. Multiple such |
| 5023 | // declaration contexts occur when two declaration contexts from disjoint |
| 5024 | // modules get merged, e.g., when two namespaces with the same name are |
| 5025 | // independently defined in separate modules. |
| 5026 | SmallVector<const DeclContext *, 2> Contexts; |
| 5027 | Contexts.push_back(DC); |
| 5028 | |
| 5029 | if (DC->isNamespace()) { |
| 5030 | MergedDeclsMap::iterator Merged |
| 5031 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5032 | if (Merged != MergedDecls.end()) { |
| 5033 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5034 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | DeclContextNameLookupVisitor Visitor(*this, Contexts, Name, Decls); |
Douglas Gregor | 0d95f77 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5039 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | 2512308 | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 5040 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | 074dcc8 | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 5041 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 76bd1f3 | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 5042 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5043 | } |
| 5044 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5045 | namespace { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5046 | /// \brief ModuleFile visitor used to retrieve all visible names in a |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5047 | /// declaration context. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5048 | class DeclContextAllNamesVisitor { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5049 | ASTReader &Reader; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5050 | llvm::SmallVectorImpl<const DeclContext *> &Contexts; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5051 | llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > &Decls; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5052 | |
| 5053 | public: |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5054 | DeclContextAllNamesVisitor(ASTReader &Reader, |
| 5055 | SmallVectorImpl<const DeclContext *> &Contexts, |
| 5056 | llvm::DenseMap<DeclarationName, |
| 5057 | SmallVector<NamedDecl *, 8> > &Decls) |
| 5058 | : Reader(Reader), Contexts(Contexts), Decls(Decls) { } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5059 | |
| 5060 | static bool visit(ModuleFile &M, void *UserData) { |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5061 | DeclContextAllNamesVisitor *This |
| 5062 | = static_cast<DeclContextAllNamesVisitor *>(UserData); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5063 | |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5064 | // Check whether we have any visible declaration information for |
| 5065 | // this context in this module. |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5066 | ModuleFile::DeclContextInfosMap::iterator Info; |
| 5067 | bool FoundInfo = false; |
| 5068 | for (unsigned I = 0, N = This->Contexts.size(); I != N; ++I) { |
| 5069 | Info = M.DeclContextInfos.find(This->Contexts[I]); |
| 5070 | if (Info != M.DeclContextInfos.end() && |
| 5071 | Info->second.NameLookupTableData) { |
| 5072 | FoundInfo = true; |
| 5073 | break; |
| 5074 | } |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5075 | } |
| 5076 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5077 | if (!FoundInfo) |
| 5078 | return false; |
| 5079 | |
| 5080 | ASTDeclContextNameLookupTable *LookupTable = |
| 5081 | Info->second.NameLookupTableData; |
| 5082 | bool FoundAnything = false; |
| 5083 | for (ASTDeclContextNameLookupTable::data_iterator |
| 5084 | I = LookupTable->data_begin(), E = LookupTable->data_end(); |
| 5085 | I != E; ++I) { |
| 5086 | ASTDeclContextNameLookupTrait::data_type Data = *I; |
| 5087 | for (; Data.first != Data.second; ++Data.first) { |
| 5088 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, |
| 5089 | *Data.first); |
| 5090 | if (!ND) |
| 5091 | continue; |
| 5092 | |
| 5093 | // Record this declaration. |
| 5094 | FoundAnything = true; |
| 5095 | This->Decls[ND->getDeclName()].push_back(ND); |
| 5096 | } |
| 5097 | } |
| 5098 | |
| 5099 | return FoundAnything; |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5100 | } |
| 5101 | }; |
| 5102 | } |
| 5103 | |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5104 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5105 | if (!DC->hasExternalVisibleStorage()) |
| 5106 | return; |
Nick Lewycky | b346d2f | 2012-04-16 02:51:46 +0000 | [diff] [blame] | 5107 | llvm::DenseMap<DeclarationName, llvm::SmallVector<NamedDecl*, 8> > Decls; |
| 5108 | |
| 5109 | // Compute the declaration contexts we need to look into. Multiple such |
| 5110 | // declaration contexts occur when two declaration contexts from disjoint |
| 5111 | // modules get merged, e.g., when two namespaces with the same name are |
| 5112 | // independently defined in separate modules. |
| 5113 | SmallVector<const DeclContext *, 2> Contexts; |
| 5114 | Contexts.push_back(DC); |
| 5115 | |
| 5116 | if (DC->isNamespace()) { |
| 5117 | MergedDeclsMap::iterator Merged |
| 5118 | = MergedDecls.find(const_cast<Decl *>(cast<Decl>(DC))); |
| 5119 | if (Merged != MergedDecls.end()) { |
| 5120 | for (unsigned I = 0, N = Merged->second.size(); I != N; ++I) |
| 5121 | Contexts.push_back(cast<DeclContext>(GetDecl(Merged->second[I]))); |
| 5122 | } |
| 5123 | } |
| 5124 | |
| 5125 | DeclContextAllNamesVisitor Visitor(*this, Contexts, Decls); |
| 5126 | ModuleMgr.visit(&DeclContextAllNamesVisitor::visit, &Visitor); |
| 5127 | ++NumVisibleDeclContextsRead; |
| 5128 | |
| 5129 | for (llvm::DenseMap<DeclarationName, |
| 5130 | llvm::SmallVector<NamedDecl*, 8> >::iterator |
| 5131 | I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 5132 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 5133 | } |
Argyrios Kyrtzidis | 394e539 | 2012-04-26 18:34:14 +0000 | [diff] [blame] | 5134 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
Argyrios Kyrtzidis | 643586f | 2012-03-22 16:08:04 +0000 | [diff] [blame] | 5135 | } |
| 5136 | |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5137 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 5138 | /// before receiving the implementation, and codegen depends on this. |
| 5139 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 5140 | /// implementation before passing the deserialized implementation decl. |
| 5141 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 5142 | ASTConsumer *Consumer) { |
| 5143 | assert(ImplD && Consumer); |
| 5144 | |
| 5145 | for (ObjCImplDecl::method_iterator |
| 5146 | I = ImplD->meth_begin(), E = ImplD->meth_end(); I != E; ++I) |
David Blaikie | 581deb3 | 2012-06-06 20:45:41 +0000 | [diff] [blame] | 5147 | Consumer->HandleInterestingDecl(DeclGroupRef(*I)); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5148 | |
| 5149 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 5150 | } |
| 5151 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5152 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5153 | assert(Consumer); |
| 5154 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5155 | Decl *D = InterestingDecls.front(); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5156 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 144b38a | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 5157 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5158 | PassInterestingDeclToConsumer(D); |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5159 | } |
| 5160 | } |
| 5161 | |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 5162 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 5163 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 5164 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 5165 | else |
| 5166 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 5167 | } |
| 5168 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5169 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | 0af2ca4 | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 5170 | this->Consumer = Consumer; |
| 5171 | |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5172 | if (!Consumer) |
| 5173 | return; |
| 5174 | |
| 5175 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5176 | // Force deserialization of this decl, which will cause it to be queued for |
| 5177 | // passing to the consumer. |
Daniel Dunbar | 04a0b50 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 5178 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5179 | } |
Douglas Gregor | 1a995dd | 2011-09-15 18:47:32 +0000 | [diff] [blame] | 5180 | ExternalDefinitions.clear(); |
Douglas Gregor | c62a2fe | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 5181 | |
Argyrios Kyrtzidis | bb80a8e | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5182 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | fdd0172 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 5183 | } |
| 5184 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5185 | void ASTReader::PrintStats() { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5186 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5187 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5188 | unsigned NumTypesLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5189 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 5190 | QualType()); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5191 | unsigned NumDeclsLoaded |
| 5192 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 5193 | (Decl *)0); |
| 5194 | unsigned NumIdentifiersLoaded |
| 5195 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 5196 | IdentifiersLoaded.end(), |
| 5197 | (IdentifierInfo *)0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5198 | unsigned NumSelectorsLoaded |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5199 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 5200 | SelectorsLoaded.end(), |
| 5201 | Selector()); |
Douglas Gregor | 2d41cc1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 5202 | |
Douglas Gregor | 4fed3f4 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 5203 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 5204 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 0cdd798 | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 5205 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5206 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 5207 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 5208 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5209 | if (!TypesLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5210 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5211 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 5212 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 5213 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5214 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 8f5dc7f | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 5215 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 5216 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5217 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5218 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5219 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 5220 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5221 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5222 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5223 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 5224 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5225 | if (TotalNumStatements) |
| 5226 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 5227 | NumStatementsRead, TotalNumStatements, |
| 5228 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 5229 | if (TotalNumMacros) |
| 5230 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 5231 | NumMacrosRead, TotalNumMacros, |
| 5232 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 5233 | if (TotalLexicalDeclContexts) |
| 5234 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 5235 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 5236 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 5237 | * 100)); |
| 5238 | if (TotalVisibleDeclContexts) |
| 5239 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 5240 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 5241 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 5242 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5243 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5244 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5245 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 5246 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5247 | * 100)); |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5248 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5249 | } |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5250 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5251 | dump(); |
| 5252 | std::fprintf(stderr, "\n"); |
| 5253 | } |
| 5254 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5255 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5256 | static void |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5257 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5258 | const ContinuousRangeMap<Key, ModuleFile *, |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5259 | InitialCapacity> &Map) { |
| 5260 | if (Map.begin() == Map.end()) |
| 5261 | return; |
| 5262 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5263 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5264 | llvm::errs() << Name << ":\n"; |
| 5265 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5266 | I != IEnd; ++I) { |
| 5267 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 5268 | << "\n"; |
| 5269 | } |
| 5270 | } |
| 5271 | |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5272 | void ASTReader::dump() { |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5273 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
Douglas Gregor | 8f1231b | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 5274 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 23d7df5 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 5275 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 1e849b6 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 5276 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5277 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5278 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5279 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5280 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5281 | dumpModuleIDMap("Global preprocessed entity map", |
| 5282 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 8df5c9b | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5283 | |
| 5284 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 5285 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 5286 | MEnd = ModuleMgr.end(); |
| 5287 | M != MEnd; ++M) |
| 5288 | (*M)->dump(); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5289 | } |
| 5290 | |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5291 | /// Return the amount of memory used by memory buffers, breaking down |
| 5292 | /// by heap-backed versus mmap'ed memory. |
| 5293 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5294 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 5295 | E = ModuleMgr.end(); I != E; ++I) { |
| 5296 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5297 | size_t bytes = buf->getBufferSize(); |
| 5298 | switch (buf->getBufferKind()) { |
| 5299 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 5300 | sizes.malloc_bytes += bytes; |
| 5301 | break; |
| 5302 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 5303 | sizes.mmap_bytes += bytes; |
| 5304 | break; |
| 5305 | } |
| 5306 | } |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5307 | } |
Ted Kremenek | e9b5f3d | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 5308 | } |
| 5309 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5310 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5311 | SemaObj = &S; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5312 | S.ExternalSource = this; |
| 5313 | |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5314 | // Makes sure any declarations that were deserialized "too early" |
| 5315 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 76dc889 | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 5316 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5317 | SemaObj->pushExternalDeclIntoScope(PreloadedDecls[I], |
| 5318 | PreloadedDecls[I]->getDeclName()); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5319 | } |
Douglas Gregor | 6cfc1a8 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 5320 | PreloadedDecls.clear(); |
Douglas Gregor | 4c0e86b | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 5321 | |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5322 | // Load the offsets of the declarations that Sema references. |
| 5323 | // They will be lazily deserialized when needed. |
| 5324 | if (!SemaDeclRefs.empty()) { |
| 5325 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | 1e5b6f6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 5326 | if (!SemaObj->StdNamespace) |
| 5327 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 5328 | if (!SemaObj->StdBadAlloc) |
| 5329 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 76c38d3 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
Peter Collingbourne | 84bccea | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 5332 | if (!FPPragmaOptions.empty()) { |
| 5333 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 5334 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 5335 | } |
| 5336 | |
| 5337 | if (!OpenCLExtensions.empty()) { |
| 5338 | unsigned I = 0; |
| 5339 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 5340 | #include "clang/Basic/OpenCLExtensions.def" |
| 5341 | |
| 5342 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 5343 | } |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5344 | } |
| 5345 | |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5346 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5347 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart), |
| 5348 | /*PriorGeneration=*/0); |
Douglas Gregor | 211f6e8 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5349 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5350 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
Douglas Gregor | 057df20 | 2012-01-18 20:56:22 +0000 | [diff] [blame] | 5351 | markIdentifierUpToDate(II); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5352 | return II; |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5355 | namespace clang { |
| 5356 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 5357 | /// identifiers stored within a set of AST files. |
| 5358 | class ASTIdentifierIterator : public IdentifierIterator { |
| 5359 | /// \brief The AST reader whose identifiers are being enumerated. |
| 5360 | const ASTReader &Reader; |
| 5361 | |
| 5362 | /// \brief The current index into the chain of AST files stored in |
| 5363 | /// the AST reader. |
| 5364 | unsigned Index; |
| 5365 | |
| 5366 | /// \brief The current position within the identifier lookup table |
| 5367 | /// of the current AST file. |
| 5368 | ASTIdentifierLookupTable::key_iterator Current; |
| 5369 | |
| 5370 | /// \brief The end position within the identifier lookup table of |
| 5371 | /// the current AST file. |
| 5372 | ASTIdentifierLookupTable::key_iterator End; |
| 5373 | |
| 5374 | public: |
| 5375 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 5376 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5377 | virtual StringRef Next(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5378 | }; |
| 5379 | } |
| 5380 | |
| 5381 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5382 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5383 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5384 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5385 | Current = IdTable->key_begin(); |
| 5386 | End = IdTable->key_end(); |
| 5387 | } |
| 5388 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5389 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5390 | while (Current == End) { |
| 5391 | // If we have exhausted all of our AST files, we're done. |
| 5392 | if (Index == 0) |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5393 | return StringRef(); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5394 | |
| 5395 | --Index; |
| 5396 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 5d6d89f | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 5397 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 5398 | IdentifierLookupTable; |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5399 | Current = IdTable->key_begin(); |
| 5400 | End = IdTable->key_end(); |
| 5401 | } |
| 5402 | |
| 5403 | // We have any identifiers remaining in the current AST file; return |
| 5404 | // the next one. |
| 5405 | std::pair<const char*, unsigned> Key = *Current; |
| 5406 | ++Current; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5407 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 95f4292 | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 5411 | return new ASTIdentifierIterator(*this); |
| 5412 | } |
| 5413 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5414 | namespace clang { namespace serialization { |
| 5415 | class ReadMethodPoolVisitor { |
| 5416 | ASTReader &Reader; |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5417 | Selector Sel; |
| 5418 | unsigned PriorGeneration; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5419 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 5420 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5421 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5422 | public: |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5423 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 5424 | unsigned PriorGeneration) |
| 5425 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) { } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5426 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5427 | static bool visit(ModuleFile &M, void *UserData) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5428 | ReadMethodPoolVisitor *This |
| 5429 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 5430 | |
| 5431 | if (!M.SelectorLookupTable) |
| 5432 | return false; |
| 5433 | |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5434 | // If we've already searched this module file, skip it now. |
| 5435 | if (M.Generation <= This->PriorGeneration) |
| 5436 | return true; |
| 5437 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5438 | ASTSelectorLookupTable *PoolTable |
| 5439 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 5440 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 5441 | if (Pos == PoolTable->end()) |
| 5442 | return false; |
| 5443 | |
| 5444 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | fa78dec | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 5445 | // FIXME: Not quite happy with the statistics here. We probably should |
| 5446 | // disable this tracking when called via LoadSelector. |
| 5447 | // Also, should entries without methods count as misses? |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5448 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5449 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5450 | if (This->Reader.DeserializationListener) |
| 5451 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 5452 | This->Sel); |
| 5453 | |
| 5454 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 5455 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 5456 | return true; |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5457 | } |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5458 | |
| 5459 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5460 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 5461 | return InstanceMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5462 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5463 | |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5464 | /// \brief Retrieve the instance methods found by this visitor. |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5465 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 5466 | return FactoryMethods; |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5467 | } |
| 5468 | }; |
| 5469 | } } // end namespace clang::serialization |
| 5470 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5471 | /// \brief Add the given set of methods to the method list. |
| 5472 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 5473 | ObjCMethodList &List) { |
| 5474 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 5475 | S.addMethodToGlobalList(&List, Methods[I]); |
| 5476 | } |
| 5477 | } |
| 5478 | |
| 5479 | void ASTReader::ReadMethodPool(Selector Sel) { |
Douglas Gregor | 8efca6b | 2012-01-25 01:14:32 +0000 | [diff] [blame] | 5480 | // Get the selector generation and update it to the current generation. |
| 5481 | unsigned &Generation = SelectorGeneration[Sel]; |
| 5482 | unsigned PriorGeneration = Generation; |
| 5483 | Generation = CurrentGeneration; |
| 5484 | |
| 5485 | // Search for methods defined with this selector. |
| 5486 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5487 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5488 | |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5489 | if (Visitor.getInstanceMethods().empty() && |
| 5490 | Visitor.getFactoryMethods().empty()) { |
Douglas Gregor | 3d15ab8 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 5491 | ++NumMethodPoolMisses; |
Douglas Gregor | 5ac4b69 | 2012-01-25 00:49:42 +0000 | [diff] [blame] | 5492 | return; |
| 5493 | } |
| 5494 | |
| 5495 | if (!getSema()) |
| 5496 | return; |
| 5497 | |
| 5498 | Sema &S = *getSema(); |
| 5499 | Sema::GlobalMethodPool::iterator Pos |
| 5500 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 5501 | |
| 5502 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 5503 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 5504 | } |
| 5505 | |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5506 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5507 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 5508 | Namespaces.clear(); |
| 5509 | |
| 5510 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 5511 | if (NamespaceDecl *Namespace |
| 5512 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 5513 | Namespaces.push_back(Namespace); |
| 5514 | } |
| 5515 | } |
| 5516 | |
Douglas Gregor | a862320 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 5517 | void ASTReader::ReadTentativeDefinitions( |
| 5518 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 5519 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 5520 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 5521 | if (Var) |
| 5522 | TentativeDefs.push_back(Var); |
| 5523 | } |
| 5524 | TentativeDefinitions.clear(); |
| 5525 | } |
| 5526 | |
Douglas Gregor | a2ee20a | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 5527 | void ASTReader::ReadUnusedFileScopedDecls( |
| 5528 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 5529 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 5530 | DeclaratorDecl *D |
| 5531 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 5532 | if (D) |
| 5533 | Decls.push_back(D); |
| 5534 | } |
| 5535 | UnusedFileScopedDecls.clear(); |
| 5536 | } |
| 5537 | |
Douglas Gregor | 0129b56 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 5538 | void ASTReader::ReadDelegatingConstructors( |
| 5539 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 5540 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 5541 | CXXConstructorDecl *D |
| 5542 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 5543 | if (D) |
| 5544 | Decls.push_back(D); |
| 5545 | } |
| 5546 | DelegatingCtorDecls.clear(); |
| 5547 | } |
| 5548 | |
Douglas Gregor | d58a0a5 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 5549 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 5550 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 5551 | TypedefNameDecl *D |
| 5552 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 5553 | if (D) |
| 5554 | Decls.push_back(D); |
| 5555 | } |
| 5556 | ExtVectorDecls.clear(); |
| 5557 | } |
| 5558 | |
Douglas Gregor | a126f17 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 5559 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 5560 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 5561 | CXXRecordDecl *D |
| 5562 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 5563 | if (D) |
| 5564 | Decls.push_back(D); |
| 5565 | } |
| 5566 | DynamicClasses.clear(); |
| 5567 | } |
| 5568 | |
Douglas Gregor | ec12ce2 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 5569 | void |
| 5570 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 5571 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 5572 | NamedDecl *D |
| 5573 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 5574 | if (D) |
| 5575 | Decls.push_back(D); |
| 5576 | } |
| 5577 | LocallyScopedExternalDecls.clear(); |
| 5578 | } |
| 5579 | |
Douglas Gregor | 5b9dc7c | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 5580 | void ASTReader::ReadReferencedSelectors( |
| 5581 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 5582 | if (ReferencedSelectorsData.empty()) |
| 5583 | return; |
| 5584 | |
| 5585 | // If there are @selector references added them to its pool. This is for |
| 5586 | // implementation of -Wselector. |
| 5587 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 5588 | unsigned I = 0; |
| 5589 | while (I < DataSize) { |
| 5590 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 5591 | SourceLocation SelLoc |
| 5592 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 5593 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 5594 | } |
| 5595 | ReferencedSelectorsData.clear(); |
| 5596 | } |
| 5597 | |
Douglas Gregor | 31e37b2 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 5598 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 5599 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 5600 | if (WeakUndeclaredIdentifiers.empty()) |
| 5601 | return; |
| 5602 | |
| 5603 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 5604 | IdentifierInfo *WeakId |
| 5605 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5606 | IdentifierInfo *AliasId |
| 5607 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 5608 | SourceLocation Loc |
| 5609 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 5610 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 5611 | WeakInfo WI(AliasId, Loc); |
| 5612 | WI.setUsed(Used); |
| 5613 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 5614 | } |
| 5615 | WeakUndeclaredIdentifiers.clear(); |
| 5616 | } |
| 5617 | |
Douglas Gregor | dfe6543 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 5618 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 5619 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 5620 | ExternalVTableUse VT; |
| 5621 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 5622 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 5623 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 5624 | VTables.push_back(VT); |
| 5625 | } |
| 5626 | |
| 5627 | VTableUses.clear(); |
| 5628 | } |
| 5629 | |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 5630 | void ASTReader::ReadPendingInstantiations( |
| 5631 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 5632 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 5633 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 5634 | SourceLocation Loc |
| 5635 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 5636 | |
Douglas Gregor | e5fa3c2 | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 5637 | Pending.push_back(std::make_pair(D, Loc)); |
Douglas Gregor | 6e4a3f5 | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 5638 | } |
| 5639 | PendingInstantiations.clear(); |
| 5640 | } |
| 5641 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5642 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | e58aa89 | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5643 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 5644 | ReadMethodPool(Sel); |
| 5645 | } |
| 5646 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5647 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5648 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | a02b147 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 5649 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 2b3a5a8 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 5650 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5651 | if (DeserializationListener) |
| 5652 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5653 | } |
| 5654 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5655 | /// \brief Set the globally-visible declarations associated with the given |
| 5656 | /// identifier. |
| 5657 | /// |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5658 | /// 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] | 5659 | /// 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] | 5660 | /// them. |
| 5661 | /// |
| 5662 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 5663 | /// declarations. |
| 5664 | /// |
| 5665 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 5666 | /// visible at global scope. |
| 5667 | /// |
| 5668 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 5669 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 5670 | /// will not be placed onto the pending queue. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5671 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5672 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5673 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5674 | bool Nonrecursive) { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5675 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5676 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 5677 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 5678 | PII.II = II; |
Benjamin Kramer | 4ea884b | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 5679 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5680 | return; |
| 5681 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5682 | |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5683 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 5684 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 5685 | if (SemaObj) { |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 5686 | // Introduce this declaration into the translation-unit scope |
| 5687 | // and add it to the declaration chain for this identifier, so |
| 5688 | // that (unqualified) name lookup will find it. |
| 5689 | SemaObj->pushExternalDeclIntoScope(D, II); |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5690 | } else { |
| 5691 | // Queue this declaration so that it will be added to the |
| 5692 | // translation unit scope and identifier's declaration chain |
| 5693 | // once a Sema object is known. |
| 5694 | PreloadedDecls.push_back(D); |
| 5695 | } |
| 5696 | } |
| 5697 | } |
| 5698 | |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5699 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5700 | if (ID == 0) |
| 5701 | return 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5702 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5703 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5704 | Error("no identifier table in AST file"); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5705 | return 0; |
| 5706 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5707 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5708 | ID -= 1; |
| 5709 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 67268d0 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 5710 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 5711 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5712 | ModuleFile *M = I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5713 | unsigned Index = ID - M->BaseIdentifierID; |
| 5714 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | d6595a4 | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 5715 | |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5716 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 5717 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | 231bc0b | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 5718 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 5719 | // unsigned integers. This is important to avoid integer overflow when |
| 5720 | // we cast them to 'unsigned'. |
Ted Kremenek | ff1ea46 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 5721 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | 02fc751 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 5722 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 5723 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5724 | IdentifiersLoaded[ID] |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5725 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | f2f0f03 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5726 | if (DeserializationListener) |
| 5727 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | afaf308 | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5728 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5729 | |
Sebastian Redl | 11f5ccf | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5730 | return IdentifiersLoaded[ID]; |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5731 | } |
| 5732 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5733 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5734 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 5735 | } |
| 5736 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5737 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 6ec60e0 | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 5738 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 5739 | return LocalID; |
| 5740 | |
| 5741 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5742 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 5743 | assert(I != M.IdentifierRemap.end() |
| 5744 | && "Invalid index into identifier index remap"); |
| 5745 | |
| 5746 | return LocalID + I->second; |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5747 | } |
| 5748 | |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5749 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | e23ac65 | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 5750 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 7f94b0b | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5751 | } |
| 5752 | |
Douglas Gregor | 26ced12 | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5753 | serialization::SubmoduleID |
| 5754 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 5755 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 5756 | return LocalID; |
| 5757 | |
| 5758 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5759 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 5760 | assert(I != M.SubmoduleRemap.end() |
| 5761 | && "Invalid index into identifier index remap"); |
| 5762 | |
| 5763 | return LocalID + I->second; |
| 5764 | } |
| 5765 | |
| 5766 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 5767 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 5768 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 5769 | return 0; |
| 5770 | } |
| 5771 | |
| 5772 | if (GlobalID > SubmodulesLoaded.size()) { |
| 5773 | Error("submodule ID out of range in AST file"); |
| 5774 | return 0; |
| 5775 | } |
| 5776 | |
| 5777 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 5778 | } |
| 5779 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5780 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5781 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 5782 | } |
| 5783 | |
| 5784 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5785 | if (ID == 0) |
| 5786 | return Selector(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5787 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5788 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | 3c7f413 | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5789 | Error("selector ID out of range in AST file"); |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5790 | return Selector(); |
| 5791 | } |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5792 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5793 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5794 | // Load this selector from the selector table. |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5795 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 5796 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5797 | ModuleFile &M = *I->second; |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5798 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5799 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5800 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | 9827a80 | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5801 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 96958cb | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5802 | if (DeserializationListener) |
| 5803 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 83941df | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5806 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 90cd1bb | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5807 | } |
| 5808 | |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5809 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5810 | return DecodeSelector(ID); |
| 5811 | } |
| 5812 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5813 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | 725cd96 | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5814 | // ID 0 (the null selector) is considered an external selector. |
| 5815 | return getTotalNumSelectors() + 1; |
Douglas Gregor | 719770d | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5816 | } |
| 5817 | |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5818 | serialization::SelectorID |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5819 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
Douglas Gregor | b18b1fd | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5820 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 5821 | return LocalID; |
| 5822 | |
| 5823 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5824 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 5825 | assert(I != M.SelectorRemap.end() |
| 5826 | && "Invalid index into identifier index remap"); |
| 5827 | |
| 5828 | return LocalID + I->second; |
Douglas Gregor | 8451ec7 | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5831 | DeclarationName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5832 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5833 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5834 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 5835 | switch (Kind) { |
| 5836 | case DeclarationName::Identifier: |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5837 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5838 | |
| 5839 | case DeclarationName::ObjCZeroArgSelector: |
| 5840 | case DeclarationName::ObjCOneArgSelector: |
| 5841 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 2d2689a | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5842 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5843 | |
| 5844 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5845 | return Context.DeclarationNames.getCXXConstructorName( |
| 5846 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5847 | |
| 5848 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5849 | return Context.DeclarationNames.getCXXDestructorName( |
| 5850 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5851 | |
| 5852 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5853 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 5854 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5855 | |
| 5856 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5857 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5858 | (OverloadedOperatorKind)Record[Idx++]); |
| 5859 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5860 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5861 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5862 | GetIdentifierInfo(F, Record, Idx)); |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5863 | |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5864 | case DeclarationName::CXXUsingDirective: |
| 5865 | return DeclarationName::getUsingDirectiveName(); |
| 5866 | } |
| 5867 | |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 5868 | llvm_unreachable("Invalid NameKind!"); |
Douglas Gregor | 2cf2634 | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5869 | } |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5870 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5871 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5872 | DeclarationNameLoc &DNLoc, |
| 5873 | DeclarationName Name, |
| 5874 | const RecordData &Record, unsigned &Idx) { |
| 5875 | switch (Name.getNameKind()) { |
| 5876 | case DeclarationName::CXXConstructorName: |
| 5877 | case DeclarationName::CXXDestructorName: |
| 5878 | case DeclarationName::CXXConversionFunctionName: |
| 5879 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5880 | break; |
| 5881 | |
| 5882 | case DeclarationName::CXXOperatorName: |
| 5883 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5884 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5885 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5886 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5887 | break; |
| 5888 | |
| 5889 | case DeclarationName::CXXLiteralOperatorName: |
| 5890 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5891 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5892 | break; |
| 5893 | |
| 5894 | case DeclarationName::Identifier: |
| 5895 | case DeclarationName::ObjCZeroArgSelector: |
| 5896 | case DeclarationName::ObjCOneArgSelector: |
| 5897 | case DeclarationName::ObjCMultiArgSelector: |
| 5898 | case DeclarationName::CXXUsingDirective: |
| 5899 | break; |
| 5900 | } |
| 5901 | } |
| 5902 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5903 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5904 | DeclarationNameInfo &NameInfo, |
| 5905 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5906 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5907 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5908 | DeclarationNameLoc DNLoc; |
| 5909 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5910 | NameInfo.setInfo(DNLoc); |
| 5911 | } |
| 5912 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5913 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5914 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5915 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5916 | unsigned NumTPLists = Record[Idx++]; |
| 5917 | Info.NumTemplParamLists = NumTPLists; |
| 5918 | if (NumTPLists) { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5919 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 4045107 | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5920 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5921 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5922 | } |
| 5923 | } |
| 5924 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5925 | TemplateName |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5926 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5927 | unsigned &Idx) { |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5928 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5929 | switch (Kind) { |
| 5930 | case TemplateName::Template: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5931 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5932 | |
| 5933 | case TemplateName::OverloadedTemplate: { |
| 5934 | unsigned size = Record[Idx++]; |
| 5935 | UnresolvedSet<8> Decls; |
| 5936 | while (size--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5937 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5938 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5939 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5940 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5941 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5942 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5943 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5944 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5945 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5946 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5947 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5948 | |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5949 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5950 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5951 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5952 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5953 | GetIdentifierInfo(F, Record, |
| 5954 | Idx)); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5955 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | 17cfded | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5956 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5957 | } |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5958 | |
| 5959 | case TemplateName::SubstTemplateTemplateParm: { |
| 5960 | TemplateTemplateParmDecl *param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5961 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5962 | if (!param) return TemplateName(); |
| 5963 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5964 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | 1460604 | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5965 | } |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5966 | |
| 5967 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5968 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5969 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5970 | if (!Param) |
| 5971 | return TemplateName(); |
| 5972 | |
| 5973 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5974 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5975 | return TemplateName(); |
| 5976 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5977 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5978 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5979 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5980 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 5981 | llvm_unreachable("Unhandled template name kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | TemplateArgument |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 5985 | ASTReader::ReadTemplateArgument(ModuleFile &F, |
Sebastian Redl | 577d479 | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5986 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5987 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5988 | switch (Kind) { |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5989 | case TemplateArgument::Null: |
| 5990 | return TemplateArgument(); |
| 5991 | case TemplateArgument::Type: |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5992 | return TemplateArgument(readType(F, Record, Idx)); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5993 | case TemplateArgument::Declaration: { |
| 5994 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
| 5995 | bool ForReferenceParam = Record[Idx++]; |
| 5996 | return TemplateArgument(D, ForReferenceParam); |
| 5997 | } |
| 5998 | case TemplateArgument::NullPtr: |
| 5999 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6000 | case TemplateArgument::Integral: { |
| 6001 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6002 | QualType T = readType(F, Record, Idx); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 6003 | return TemplateArgument(Context, Value, T); |
Argyrios Kyrtzidis | dc767e3 | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 6004 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6005 | case TemplateArgument::Template: |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6006 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 6007 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 6008 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 6009 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 6010 | if (unsigned NumExpansions = Record[Idx++]) |
| 6011 | NumTemplateExpansions = NumExpansions - 1; |
| 6012 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 6013 | } |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6014 | case TemplateArgument::Expression: |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6015 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6016 | case TemplateArgument::Pack: { |
| 6017 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6018 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 910f800 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 6019 | for (unsigned I = 0; I != NumArgs; ++I) |
| 6020 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 6021 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6022 | } |
| 6023 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6024 | |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 6025 | llvm_unreachable("Unhandled template argument kind!"); |
Argyrios Kyrtzidis | 8731ca7 | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 6026 | } |
| 6027 | |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6028 | TemplateParameterList * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6029 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6030 | const RecordData &Record, unsigned &Idx) { |
| 6031 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 6032 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 6033 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6034 | |
| 6035 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6036 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6037 | Params.reserve(NumParams); |
| 6038 | while (NumParams--) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6039 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6040 | |
| 6041 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6042 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6043 | Params.data(), Params.size(), RAngleLoc); |
| 6044 | return TemplateParams; |
| 6045 | } |
| 6046 | |
| 6047 | void |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6048 | ASTReader:: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6049 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6050 | ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6051 | unsigned &Idx) { |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6052 | unsigned NumTemplateArgs = Record[Idx++]; |
| 6053 | TemplArgs.reserve(NumTemplateArgs); |
| 6054 | while (NumTemplateArgs--) |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6055 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | dd41c14 | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 6056 | } |
| 6057 | |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6058 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6059 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6060 | const RecordData &Record, unsigned &Idx) { |
| 6061 | unsigned NumDecls = Record[Idx++]; |
| 6062 | while (NumDecls--) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6063 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 37ffed3 | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 6064 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 6065 | Set.addDecl(D, AS); |
| 6066 | } |
| 6067 | } |
| 6068 | |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6069 | CXXBaseSpecifier |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6070 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
Nick Lewycky | 5606220 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 6071 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6072 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 6073 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 6074 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6075 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6076 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 6077 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6078 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6079 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 6080 | EllipsisLoc); |
Sebastian Redl | f677ea3 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 6081 | Result.setInheritConstructors(inheritConstructors); |
| 6082 | return Result; |
Argyrios Kyrtzidis | 0745d0a | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6085 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6086 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6087 | unsigned &Idx) { |
| 6088 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6089 | unsigned NumInitializers = Record[Idx++]; |
| 6090 | if (NumInitializers) { |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6091 | CtorInitializers |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6092 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6093 | for (unsigned i=0; i != NumInitializers; ++i) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6094 | TypeSourceInfo *TInfo = 0; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6095 | bool IsBaseVirtual = false; |
| 6096 | FieldDecl *Member = 0; |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6097 | IndirectFieldDecl *IndirectMember = 0; |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6098 | |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6099 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 6100 | switch (Type) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6101 | case CTOR_INITIALIZER_BASE: |
| 6102 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6103 | IsBaseVirtual = Record[Idx++]; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6104 | break; |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6105 | |
| 6106 | case CTOR_INITIALIZER_DELEGATING: |
| 6107 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6108 | break; |
| 6109 | |
| 6110 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6111 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6112 | break; |
| 6113 | |
| 6114 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6115 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6116 | break; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6117 | } |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6118 | |
Douglas Gregor | 3fb9e4b | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 6119 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6120 | Expr *Init = ReadExpr(F); |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6121 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 6122 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6123 | bool IsWritten = Record[Idx++]; |
| 6124 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 6125 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6126 | if (IsWritten) { |
| 6127 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6128 | } else { |
| 6129 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 6130 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 6131 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6132 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6133 | } |
Michael J. Spencer | 20249a1 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 6134 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6135 | CXXCtorInitializer *BOMInit; |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6136 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6137 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, IsBaseVirtual, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6138 | LParenLoc, Init, RParenLoc, |
| 6139 | MemberOrEllipsisLoc); |
Sean Hunt | 156b640 | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 6140 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 76852c2 | 2011-11-01 01:16:03 +0000 | [diff] [blame] | 6141 | BOMInit = new (Context) CXXCtorInitializer(Context, TInfo, LParenLoc, |
| 6142 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6143 | } else if (IsWritten) { |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6144 | if (Member) |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6145 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6146 | LParenLoc, Init, RParenLoc); |
Francois Pichet | 00eb3f9 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 6147 | else |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6148 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6149 | MemberOrEllipsisLoc, LParenLoc, |
| 6150 | Init, RParenLoc); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6151 | } else { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6152 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6153 | LParenLoc, Init, RParenLoc, |
| 6154 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
Argyrios Kyrtzidis | f84cde1 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 6157 | if (IsWritten) |
| 6158 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6159 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6160 | } |
| 6161 | } |
| 6162 | |
Sean Hunt | cbb6748 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 6163 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 8e706f4 | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6166 | NestedNameSpecifier * |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6167 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6168 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6169 | unsigned N = Record[Idx++]; |
| 6170 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 6171 | for (unsigned I = 0; I != N; ++I) { |
| 6172 | NestedNameSpecifier::SpecifierKind Kind |
| 6173 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6174 | switch (Kind) { |
| 6175 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6176 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6177 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6178 | break; |
| 6179 | } |
| 6180 | |
| 6181 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6182 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6183 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6184 | break; |
| 6185 | } |
| 6186 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6187 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6188 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6189 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 6190 | break; |
| 6191 | } |
| 6192 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6193 | case NestedNameSpecifier::TypeSpec: |
| 6194 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 393f249 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 6195 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 1ab55e9 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 6196 | if (!T) |
| 6197 | return 0; |
| 6198 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6199 | bool Template = Record[Idx++]; |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6200 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6201 | break; |
| 6202 | } |
| 6203 | |
| 6204 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6205 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6206 | // No associated value, and there can't be a prefix. |
| 6207 | break; |
| 6208 | } |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6209 | } |
Argyrios Kyrtzidis | d2bb2c0 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 6210 | Prev = NNS; |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6211 | } |
| 6212 | return NNS; |
| 6213 | } |
| 6214 | |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6215 | NestedNameSpecifierLoc |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6216 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6217 | unsigned &Idx) { |
| 6218 | unsigned N = Record[Idx++]; |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6219 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6220 | for (unsigned I = 0; I != N; ++I) { |
| 6221 | NestedNameSpecifier::SpecifierKind Kind |
| 6222 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 6223 | switch (Kind) { |
| 6224 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | 95eab17 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 6225 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6226 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6227 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6228 | break; |
| 6229 | } |
| 6230 | |
| 6231 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6232 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6233 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6234 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6235 | break; |
| 6236 | } |
| 6237 | |
| 6238 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6239 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6240 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6241 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6242 | break; |
| 6243 | } |
| 6244 | |
| 6245 | case NestedNameSpecifier::TypeSpec: |
| 6246 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6247 | bool Template = Record[Idx++]; |
| 6248 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 6249 | if (!T) |
| 6250 | return NestedNameSpecifierLoc(); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6251 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6252 | |
| 6253 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6254 | Builder.Extend(Context, |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 6255 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 6256 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6257 | break; |
| 6258 | } |
| 6259 | |
| 6260 | case NestedNameSpecifier::Global: { |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6261 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6262 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6263 | break; |
| 6264 | } |
| 6265 | } |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6266 | } |
| 6267 | |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6268 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | dc35571 | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 6269 | } |
| 6270 | |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6271 | SourceRange |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6272 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
Sebastian Redl | c363273 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 6273 | unsigned &Idx) { |
| 6274 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 6275 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 8ee5939 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 6276 | return SourceRange(beg, end); |
Chris Lattner | 6ad9ac0 | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6279 | /// \brief Read an integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6280 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6281 | unsigned BitWidth = Record[Idx++]; |
| 6282 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 6283 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 6284 | Idx += NumWords; |
| 6285 | return Result; |
| 6286 | } |
| 6287 | |
| 6288 | /// \brief Read a signed integral value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6289 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 0a2b45e | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 6290 | bool isUnsigned = Record[Idx++]; |
| 6291 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 6292 | } |
| 6293 | |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6294 | /// \brief Read a floating-point value |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6295 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 17fc223 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 6296 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 6297 | } |
| 6298 | |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6299 | // \brief Read a string |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6300 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6301 | unsigned Len = Record[Idx++]; |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 6302 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | 68a2eb0 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 6303 | Idx += Len; |
| 6304 | return Result; |
| 6305 | } |
| 6306 | |
Douglas Gregor | 0a0d2b1 | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 6307 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 6308 | unsigned &Idx) { |
| 6309 | unsigned Major = Record[Idx++]; |
| 6310 | unsigned Minor = Record[Idx++]; |
| 6311 | unsigned Subminor = Record[Idx++]; |
| 6312 | if (Minor == 0) |
| 6313 | return VersionTuple(Major); |
| 6314 | if (Subminor == 0) |
| 6315 | return VersionTuple(Major, Minor - 1); |
| 6316 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 6317 | } |
| 6318 | |
Douglas Gregor | 1a4761e | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 6319 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6320 | const RecordData &Record, |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6321 | unsigned &Idx) { |
Douglas Gregor | 409448c | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 6322 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 3594277 | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 6323 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | d259836 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6326 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | e1d918e | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 6327 | return Diag(SourceLocation(), DiagID); |
| 6328 | } |
| 6329 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6330 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 6331 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 0a0428e | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 6332 | } |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6333 | |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6334 | /// \brief Retrieve the identifier table associated with the |
| 6335 | /// preprocessor. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6336 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6337 | return PP.getIdentifierTable(); |
Douglas Gregor | 668c1a4 | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 6338 | } |
| 6339 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6340 | /// \brief Record that the given ID maps to the given switch-case |
| 6341 | /// statement. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6342 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6343 | assert((*CurrSwitchCaseStmts)[ID] == 0 && |
| 6344 | "Already have a SwitchCase with this ID"); |
| 6345 | (*CurrSwitchCaseStmts)[ID] = SC; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6349 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6350 | assert((*CurrSwitchCaseStmts)[ID] != 0 && "No SwitchCase with this ID"); |
| 6351 | return (*CurrSwitchCaseStmts)[ID]; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 6352 | } |
Douglas Gregor | 1de05fe | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 6353 | |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6354 | void ASTReader::ClearSwitchCaseIDs() { |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6355 | CurrSwitchCaseStmts->clear(); |
Argyrios Kyrtzidis | e09a275 | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 6356 | } |
| 6357 | |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6358 | void ASTReader::ReadComments() { |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6359 | std::vector<RawComment *> Comments; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6360 | for (SmallVectorImpl<std::pair<llvm::BitstreamCursor, |
| 6361 | serialization::ModuleFile *> >::iterator |
| 6362 | I = CommentsCursors.begin(), |
| 6363 | E = CommentsCursors.end(); |
| 6364 | I != E; ++I) { |
| 6365 | llvm::BitstreamCursor &Cursor = I->first; |
| 6366 | serialization::ModuleFile &F = *I->second; |
| 6367 | SavedStreamPosition SavedPosition(Cursor); |
| 6368 | |
| 6369 | RecordData Record; |
| 6370 | while (true) { |
| 6371 | unsigned Code = Cursor.ReadCode(); |
| 6372 | if (Code == llvm::bitc::END_BLOCK) |
| 6373 | break; |
| 6374 | |
| 6375 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 6376 | // No known subblocks, always skip them. |
| 6377 | Cursor.ReadSubBlockID(); |
| 6378 | if (Cursor.SkipBlock()) { |
| 6379 | Error("malformed block record in AST file"); |
| 6380 | return; |
| 6381 | } |
| 6382 | continue; |
| 6383 | } |
| 6384 | |
| 6385 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 6386 | Cursor.ReadAbbrevRecord(); |
| 6387 | continue; |
| 6388 | } |
| 6389 | |
| 6390 | // Read a record. |
| 6391 | Record.clear(); |
| 6392 | switch ((CommentRecordTypes) Cursor.ReadRecord(Code, Record)) { |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6393 | case COMMENTS_RAW_COMMENT: { |
| 6394 | unsigned Idx = 0; |
| 6395 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 6396 | RawComment::CommentKind Kind = |
| 6397 | (RawComment::CommentKind) Record[Idx++]; |
| 6398 | bool IsTrailingComment = Record[Idx++]; |
| 6399 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | 811c820 | 2012-07-06 18:19:34 +0000 | [diff] [blame] | 6400 | Comments.push_back(new (Context) RawComment(SR, Kind, |
| 6401 | IsTrailingComment, |
| 6402 | IsAlmostTrailingComment)); |
Chandler Carruth | 13691bb | 2012-06-20 06:47:54 +0000 | [diff] [blame] | 6403 | break; |
Dmitri Gribenko | aa0cd85 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 6404 | } |
| 6405 | } |
| 6406 | } |
| 6407 | } |
| 6408 | Context.Comments.addCommentsToFront(Comments); |
| 6409 | } |
| 6410 | |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6411 | void ASTReader::finishPendingActions() { |
Douglas Gregor | cff9f26 | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 6412 | while (!PendingIdentifierInfos.empty() || !PendingDeclChains.empty()) { |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6413 | // If any identifiers with corresponding top-level declarations have |
| 6414 | // been loaded, load those declarations now. |
| 6415 | while (!PendingIdentifierInfos.empty()) { |
| 6416 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 6417 | PendingIdentifierInfos.front().DeclIDs, true); |
| 6418 | PendingIdentifierInfos.pop_front(); |
| 6419 | } |
| 6420 | |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6421 | // Load pending declaration chains. |
| 6422 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) { |
| 6423 | loadPendingDeclChain(PendingDeclChains[I]); |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6424 | PendingDeclChainsKnown.erase(PendingDeclChains[I]); |
Douglas Gregor | a1be278 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 6425 | } |
| 6426 | PendingDeclChains.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6427 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6428 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6429 | // If we deserialized any C++ or Objective-C class definitions, any |
| 6430 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| 6431 | // that all redeclarations point to the definitions. Note that this can only |
| 6432 | // happen now, after the redeclaration chains have been fully wired. |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6433 | for (llvm::SmallPtrSet<Decl *, 4>::iterator D = PendingDefinitions.begin(), |
| 6434 | DEnd = PendingDefinitions.end(); |
| 6435 | D != DEnd; ++D) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6436 | if (TagDecl *TD = dyn_cast<TagDecl>(*D)) { |
| 6437 | if (const TagType *TagT = dyn_cast<TagType>(TD->TypeForDecl)) { |
| 6438 | // Make sure that the TagType points at the definition. |
| 6439 | const_cast<TagType*>(TagT)->decl = TD; |
| 6440 | } |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6441 | |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6442 | if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(*D)) { |
| 6443 | for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), |
| 6444 | REnd = RD->redecls_end(); |
| 6445 | R != REnd; ++R) |
| 6446 | cast<CXXRecordDecl>(*R)->DefinitionData = RD->DefinitionData; |
| 6447 | |
| 6448 | } |
| 6449 | |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6450 | continue; |
| 6451 | } |
| 6452 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6453 | if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(*D)) { |
Douglas Gregor | 56ca8a9 | 2012-01-17 19:21:53 +0000 | [diff] [blame] | 6454 | // Make sure that the ObjCInterfaceType points at the definition. |
| 6455 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 6456 | ->Decl = ID; |
| 6457 | |
Douglas Gregor | 1d784b2 | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 6458 | for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), |
| 6459 | REnd = ID->redecls_end(); |
| 6460 | R != REnd; ++R) |
| 6461 | R->Data = ID->Data; |
| 6462 | |
| 6463 | continue; |
| 6464 | } |
| 6465 | |
Douglas Gregor | 7c99bb5c | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 6466 | if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(*D)) { |
| 6467 | for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), |
| 6468 | REnd = PD->redecls_end(); |
| 6469 | R != REnd; ++R) |
| 6470 | R->Data = PD->Data; |
| 6471 | |
| 6472 | continue; |
| 6473 | } |
| 6474 | |
| 6475 | RedeclarableTemplateDecl *RTD |
| 6476 | = cast<RedeclarableTemplateDecl>(*D)->getCanonicalDecl(); |
| 6477 | for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), |
| 6478 | REnd = RTD->redecls_end(); |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6479 | R != REnd; ++R) |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6480 | R->Common = RTD->Common; |
Douglas Gregor | fc529f7 | 2011-12-19 19:00:47 +0000 | [diff] [blame] | 6481 | } |
| 6482 | PendingDefinitions.clear(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6483 | |
| 6484 | // Load the bodies of any functions or methods we've encountered. We do |
| 6485 | // this now (delayed) so that we can be sure that the declaration chains |
| 6486 | // have been fully wired up. |
Douglas Gregor | ce12d2f | 2012-10-09 17:50:23 +0000 | [diff] [blame^] | 6487 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 6488 | PBEnd = PendingBodies.end(); |
Douglas Gregor | 5456b0fe | 2012-10-09 17:21:28 +0000 | [diff] [blame] | 6489 | PB != PBEnd; ++PB) { |
| 6490 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 6491 | // FIXME: Check for =delete/=default? |
| 6492 | // FIXME: Complain about ODR violations here? |
| 6493 | if (!getContext().getLangOpts().Modules || !FD->hasBody()) |
| 6494 | FD->setLazyBody(PB->second); |
| 6495 | continue; |
| 6496 | } |
| 6497 | |
| 6498 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 6499 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 6500 | MD->setLazyBody(PB->second); |
| 6501 | } |
| 6502 | PendingBodies.clear(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6503 | } |
| 6504 | |
Sebastian Redl | c43b54c | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 6505 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | 29ee3a2 | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 6506 | assert(NumCurrentElementsDeserializing && |
| 6507 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 6508 | if (NumCurrentElementsDeserializing == 1) { |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6509 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 6510 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 6511 | finishPendingActions(); |
| 6512 | } |
| 6513 | --NumCurrentElementsDeserializing; |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6514 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6515 | if (NumCurrentElementsDeserializing == 0 && |
| 6516 | Consumer && !PassingDeclsToConsumer) { |
| 6517 | // Guard variable to avoid recursively redoing the process of passing |
| 6518 | // decls to consumer. |
| 6519 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 6520 | true); |
Argyrios Kyrtzidis | 7116833 | 2011-12-17 04:13:28 +0000 | [diff] [blame] | 6521 | |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6522 | while (!InterestingDecls.empty()) { |
Argyrios Kyrtzidis | 8d39c3d | 2011-11-30 23:18:26 +0000 | [diff] [blame] | 6523 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 6524 | // decls to the consumer. |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6525 | Decl *D = InterestingDecls.front(); |
| 6526 | InterestingDecls.pop_front(); |
Argyrios Kyrtzidis | 9170783 | 2011-12-17 08:11:25 +0000 | [diff] [blame] | 6527 | PassInterestingDeclToConsumer(D); |
| 6528 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6529 | } |
Douglas Gregor | d89275b | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 6530 | } |
Douglas Gregor | 501c103 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 6531 | |
Douglas Gregor | f8a1e51 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 6532 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | 832d620 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 6533 | StringRef isysroot, bool DisableValidation, |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6534 | bool DisableStatCache, bool AllowASTWithCompilerErrors) |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6535 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 6536 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 712f2fc | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 6537 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Argyrios Kyrtzidis | d64c26f | 2012-10-03 01:58:42 +0000 | [diff] [blame] | 6538 | Consumer(0), ModuleMgr(PP.getFileManager()), |
Jonathan D. Turner | 1afb661 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 6539 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6540 | DisableValidation(DisableValidation), |
Argyrios Kyrtzidis | bef35c9 | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 6541 | DisableStatCache(DisableStatCache), |
| 6542 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
Argyrios Kyrtzidis | b88acb0 | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 6543 | CurrentGeneration(0), CurrSwitchCaseStmts(&SwitchCaseStmts), |
| 6544 | NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6545 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6546 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 6547 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 6548 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 6549 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6550 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 6551 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
Argyrios Kyrtzidis | 44d2dbd | 2012-02-09 07:31:52 +0000 | [diff] [blame] | 6552 | PassingDeclsToConsumer(false), |
Jonathan D. Turner | 1da9014 | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 6553 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 8ef6c8c | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 6554 | { |
Douglas Gregor | f62d43d | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 6555 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6556 | } |
| 6557 | |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6558 | ASTReader::~ASTReader() { |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6559 | for (DeclContextVisibleUpdatesPending::iterator |
| 6560 | I = PendingVisibleUpdates.begin(), |
| 6561 | E = PendingVisibleUpdates.end(); |
| 6562 | I != E; ++I) { |
| 6563 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 6564 | F = I->second.end(); |
| 6565 | J != F; ++J) |
Benjamin Kramer | b1758c6 | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 6566 | delete J->first; |
Sebastian Redl | e1dde81 | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 6567 | } |
| 6568 | } |