Sebastian Redl | 3b3c874 | 2010-08-18 23:57:11 +0000 | [diff] [blame] | 1 | //===--- ASTReader.cpp - AST File Reader ------------------------*- C++ -*-===// |
Douglas Gregor | ef84c4b | 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 | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file defines the ASTReader class, which reads AST files. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 13 | |
Sebastian Redl | f5b1346 | 2010-08-18 23:57:17 +0000 | [diff] [blame] | 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "clang/Serialization/ASTDeserializationListener.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 16 | #include "ASTCommon.h" |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Sema.h" |
John McCall | cc14d1f | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 20 | #include "clang/Sema/Scope.h" |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/ASTContext.h" |
John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 24 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 25 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 26 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 27 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 34321bc | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 28 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 29 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 30 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 3fa455a | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 31 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 32 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/FileManager.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 36 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 37 | #include "clang/Basic/Version.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 39 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 40 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | f2ce9a2 | 2009-11-18 19:50:41 +0000 | [diff] [blame] | 42 | #include "llvm/System/Path.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include <algorithm> |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 44 | #include <iterator> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 45 | #include <cstdio> |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 46 | #include <sys/stat.h> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 47 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 48 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 49 | |
| 50 | //===----------------------------------------------------------------------===// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 51 | // PCH validator implementation |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 52 | //===----------------------------------------------------------------------===// |
| 53 | |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 54 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 55 | |
| 56 | bool |
| 57 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 58 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 59 | #define PARSE_LANGOPT_BENIGN(Option) |
| 60 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 61 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 62 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 63 | return true; \ |
| 64 | } |
| 65 | |
| 66 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 67 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 68 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 69 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 70 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 71 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 72 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 73 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 74 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 75 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
| 76 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
| 77 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 78 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 79 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 80 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 81 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 82 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 84 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 85 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 86 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 87 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 89 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 90 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Daniel Dunbar | 925152c | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 94 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 95 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 97 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | a77eaeb | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 100 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 101 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | diag::warn_pch_heinous_extensions); |
| 105 | // FIXME: Most of the options below are benign if the macro wasn't |
| 106 | // used. Unfortunately, this means that a PCH compiled without |
| 107 | // optimization can't be used with optimization turned on, even |
| 108 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 109 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 110 | // doesn't matter. We could consider making this some special kind |
| 111 | // of check. |
| 112 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 113 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 114 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 115 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 116 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 117 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
| 118 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 119 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 120 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 74825bc | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 121 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 122 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 124 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 125 | return true; |
| 126 | } |
| 127 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 128 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 129 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 130 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 131 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 132 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | 8ed0c0b | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_BENIGN(SpellChecking); |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 135 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 136 | #undef PARSE_LANGOPT_BENIGN |
| 137 | |
| 138 | return false; |
| 139 | } |
| 140 | |
Daniel Dunbar | 20a682d | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 141 | bool PCHValidator::ReadTargetTriple(llvm::StringRef Triple) { |
| 142 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 143 | return false; |
| 144 | |
| 145 | Reader.Diag(diag::warn_pch_target_triple) |
| 146 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 147 | return true; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 150 | struct EmptyStringRef { |
Benjamin Kramer | 8d5609b | 2010-07-14 23:19:41 +0000 | [diff] [blame] | 151 | bool operator ()(llvm::StringRef r) const { return r.empty(); } |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 152 | }; |
| 153 | struct EmptyBlock { |
| 154 | bool operator ()(const PCHPredefinesBlock &r) const { return r.Data.empty(); } |
| 155 | }; |
| 156 | |
| 157 | static bool EqualConcatenations(llvm::SmallVector<llvm::StringRef, 2> L, |
| 158 | PCHPredefinesBlocks R) { |
| 159 | // First, sum up the lengths. |
| 160 | unsigned LL = 0, RL = 0; |
| 161 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 162 | LL += L[I].size(); |
| 163 | } |
| 164 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 165 | RL += R[I].Data.size(); |
| 166 | } |
| 167 | if (LL != RL) |
| 168 | return false; |
| 169 | if (LL == 0 && RL == 0) |
| 170 | return true; |
| 171 | |
| 172 | // Kick out empty parts, they confuse the algorithm below. |
| 173 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 174 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 175 | |
| 176 | // Do it the hard way. At this point, both vectors must be non-empty. |
| 177 | llvm::StringRef LR = L[0], RR = R[0].Data; |
| 178 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | 01ad0a7 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 179 | (void) RN; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 180 | for (;;) { |
| 181 | // Compare the current pieces. |
| 182 | if (LR.size() == RR.size()) { |
| 183 | // If they're the same length, it's pretty easy. |
| 184 | if (LR != RR) |
| 185 | return false; |
| 186 | // Both pieces are done, advance. |
| 187 | ++LI; |
| 188 | ++RI; |
| 189 | // If either string is done, they're both done, since they're the same |
| 190 | // length. |
| 191 | if (LI == LN) { |
| 192 | assert(RI == RN && "Strings not the same length after all?"); |
| 193 | return true; |
| 194 | } |
| 195 | LR = L[LI]; |
| 196 | RR = R[RI].Data; |
| 197 | } else if (LR.size() < RR.size()) { |
| 198 | // Right piece is longer. |
| 199 | if (!RR.startswith(LR)) |
| 200 | return false; |
| 201 | ++LI; |
| 202 | assert(LI != LN && "Strings not the same length after all?"); |
| 203 | RR = RR.substr(LR.size()); |
| 204 | LR = L[LI]; |
| 205 | } else { |
| 206 | // Left piece is longer. |
| 207 | if (!LR.startswith(RR)) |
| 208 | return false; |
| 209 | ++RI; |
| 210 | assert(RI != RN && "Strings not the same length after all?"); |
| 211 | LR = LR.substr(RR.size()); |
| 212 | RR = R[RI].Data; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | static std::pair<FileID, llvm::StringRef::size_type> |
| 218 | FindMacro(const PCHPredefinesBlocks &Buffers, llvm::StringRef MacroDef) { |
| 219 | std::pair<FileID, llvm::StringRef::size_type> Res; |
| 220 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 221 | Res.second = Buffers[I].Data.find(MacroDef); |
| 222 | if (Res.second != llvm::StringRef::npos) { |
| 223 | Res.first = Buffers[I].BufferID; |
| 224 | break; |
| 225 | } |
| 226 | } |
| 227 | return Res; |
| 228 | } |
| 229 | |
| 230 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 231 | llvm::StringRef OriginalFileName, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 232 | std::string &SuggestedPredefines) { |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 233 | // We are in the context of an implicit include, so the predefines buffer will |
| 234 | // have a #include entry for the PCH file itself (as normalized by the |
| 235 | // preprocessor initialization). Find it and skip over it in the checking |
| 236 | // below. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 237 | llvm::SmallString<256> PCHInclude; |
| 238 | PCHInclude += "#include \""; |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 239 | PCHInclude += NormalizeDashIncludePath(OriginalFileName); |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 240 | PCHInclude += "\"\n"; |
| 241 | std::pair<llvm::StringRef,llvm::StringRef> Split = |
| 242 | llvm::StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 243 | llvm::StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 244 | if (Left == PP.getPredefines()) { |
| 245 | Error("Missing PCH include entry!"); |
| 246 | return true; |
| 247 | } |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 248 | |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 249 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 250 | // command line, we're done. |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 251 | llvm::SmallVector<llvm::StringRef, 2> CommandLine; |
| 252 | CommandLine.push_back(Left); |
| 253 | CommandLine.push_back(Right); |
| 254 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 255 | return false; |
| 256 | |
| 257 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 258 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 259 | // The predefines buffers are different. Determine what the differences are, |
| 260 | // and whether they require us to reject the PCH file. |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 261 | llvm::SmallVector<llvm::StringRef, 8> PCHLines; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 262 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 263 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 264 | |
| 265 | llvm::SmallVector<llvm::StringRef, 8> CmdLineLines; |
| 266 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 267 | |
| 268 | // Pick out implicit #includes after the PCH and don't consider them for |
| 269 | // validation; we will insert them into SuggestedPredefines so that the |
| 270 | // preprocessor includes them. |
| 271 | std::string IncludesAfterPCH; |
| 272 | llvm::SmallVector<llvm::StringRef, 8> AfterPCHLines; |
| 273 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 274 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 275 | if (AfterPCHLines[i].startswith("#include ")) { |
| 276 | IncludesAfterPCH += AfterPCHLines[i]; |
| 277 | IncludesAfterPCH += '\n'; |
| 278 | } else { |
| 279 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | // Make sure we add the includes last into SuggestedPredefines before we |
| 284 | // exit this function. |
| 285 | struct AddIncludesRAII { |
| 286 | std::string &SuggestedPredefines; |
| 287 | std::string &IncludesAfterPCH; |
| 288 | |
| 289 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 290 | std::string &IncludesAfterPCH) |
| 291 | : SuggestedPredefines(SuggestedPredefines), |
| 292 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 293 | ~AddIncludesRAII() { |
| 294 | SuggestedPredefines += IncludesAfterPCH; |
| 295 | } |
| 296 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 297 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 298 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 299 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 300 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 301 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 302 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 303 | // Determine which predefines that were used to build the PCH file are missing |
| 304 | // from the command line. |
| 305 | std::vector<llvm::StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 306 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 307 | CmdLineLines.begin(), CmdLineLines.end(), |
| 308 | std::back_inserter(MissingPredefines)); |
| 309 | |
| 310 | bool MissingDefines = false; |
| 311 | bool ConflictingDefines = false; |
| 312 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 313 | llvm::StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 314 | if (Missing.startswith("#include ")) { |
| 315 | // An -include was specified when generating the PCH; it is included in |
| 316 | // the PCH, just ignore it. |
| 317 | continue; |
| 318 | } |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 319 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 320 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 321 | return true; |
| 322 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 324 | // This is a macro definition. Determine the name of the macro we're |
| 325 | // defining. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 326 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 327 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 328 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 329 | assert(EndOfMacroName != std::string::npos && |
| 330 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 331 | llvm::StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 332 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 333 | // Determine whether this macro was given a different definition on the |
| 334 | // command line. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 335 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 336 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 337 | llvm::SmallVector<llvm::StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 338 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 339 | MacroDefStart); |
| 340 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 341 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 342 | // Different macro; we're done. |
| 343 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | break; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | |
| 347 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 348 | "Invalid #define in predefines buffer?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 350 | (*ConflictPos)[MacroDefLen] != '(') |
| 351 | continue; // Longer macro name; keep trying. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 353 | // We found a conflicting macro definition. |
| 354 | break; |
| 355 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 356 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | if (ConflictPos != CmdLineLines.end()) { |
| 358 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 359 | << MacroName; |
| 360 | |
| 361 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 362 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 363 | FindMacro(Buffers, Missing); |
| 364 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 365 | SourceLocation PCHMissingLoc = |
| 366 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 367 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 368 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 369 | |
| 370 | ConflictingDefines = true; |
| 371 | continue; |
| 372 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 374 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 375 | // definition from the PCH file. Warn the user that they made a mistake. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 376 | if (ConflictingDefines) |
| 377 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 379 | if (!MissingDefines) { |
| 380 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 381 | MissingDefines = true; |
| 382 | } |
| 383 | |
| 384 | // Show the definition of this macro within the PCH file. |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 385 | std::pair<FileID, llvm::StringRef::size_type> MacroLoc = |
| 386 | FindMacro(Buffers, Missing); |
| 387 | assert(MacroLoc.second!=llvm::StringRef::npos && "Unable to find macro!"); |
| 388 | SourceLocation PCHMissingLoc = |
| 389 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 390 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 391 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 392 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 393 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 394 | if (ConflictingDefines) |
| 395 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 397 | // Determine what predefines were introduced based on command-line |
| 398 | // parameters that were not present when building the PCH |
| 399 | // file. Extra #defines are okay, so long as the identifiers being |
| 400 | // defined were not used within the precompiled header. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 401 | std::vector<llvm::StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 402 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 403 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 405 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 406 | llvm::StringRef &Extra = ExtraPredefines[I]; |
| 407 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 408 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 409 | return true; |
| 410 | } |
| 411 | |
| 412 | // This is an extra macro definition. Determine the name of the |
| 413 | // macro we're defining. |
| 414 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 415 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 416 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 417 | assert(EndOfMacroName != std::string::npos && |
| 418 | "Couldn't find the end of the macro name"); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 419 | llvm::StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | |
| 421 | // Check whether this name was used somewhere in the PCH file. If |
| 422 | // so, defining it as a macro could change behavior, so we reject |
| 423 | // the PCH file. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 424 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 045c92f | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 425 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 426 | return true; |
| 427 | } |
| 428 | |
| 429 | // Add this definition to the suggested predefines buffer. |
| 430 | SuggestedPredefines += Extra; |
| 431 | SuggestedPredefines += '\n'; |
| 432 | } |
| 433 | |
| 434 | // If we get here, it's because the predefines buffer had compatible |
| 435 | // contents. Accept the PCH file. |
| 436 | return false; |
| 437 | } |
| 438 | |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 439 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 440 | unsigned ID) { |
| 441 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 442 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | void PCHValidator::ReadCounter(unsigned Value) { |
| 446 | PP.setCounterValue(Value); |
| 447 | } |
| 448 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 449 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 450 | // AST reader implementation |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 451 | //===----------------------------------------------------------------------===// |
| 452 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 453 | void |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 454 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 455 | DeserializationListener = Listener; |
| 456 | if (DeserializationListener) |
| 457 | DeserializationListener->SetReader(this); |
| 458 | } |
| 459 | |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 460 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 461 | namespace { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 462 | class ASTSelectorLookupTrait { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 463 | ASTReader &Reader; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 464 | |
| 465 | public: |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 466 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 467 | SelectorID ID; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 468 | ObjCMethodList Instance, Factory; |
| 469 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 470 | |
| 471 | typedef Selector external_key_type; |
| 472 | typedef external_key_type internal_key_type; |
| 473 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 474 | explicit ASTSelectorLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 475 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 476 | static bool EqualKey(const internal_key_type& a, |
| 477 | const internal_key_type& b) { |
| 478 | return a == b; |
| 479 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 481 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 482 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 483 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 484 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | // This hopefully will just get inlined and removed by the optimizer. |
| 486 | static const internal_key_type& |
| 487 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 488 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 489 | static std::pair<unsigned, unsigned> |
| 490 | ReadKeyDataLength(const unsigned char*& d) { |
| 491 | using namespace clang::io; |
| 492 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 493 | unsigned DataLen = ReadUnalignedLE16(d); |
| 494 | return std::make_pair(KeyLen, DataLen); |
| 495 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 496 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 497 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 498 | using namespace clang::io; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 499 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 500 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | IdentifierInfo *FirstII |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 502 | = Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 503 | if (N == 0) |
| 504 | return SelTable.getNullarySelector(FirstII); |
| 505 | else if (N == 1) |
| 506 | return SelTable.getUnarySelector(FirstII); |
| 507 | |
| 508 | llvm::SmallVector<IdentifierInfo *, 16> Args; |
| 509 | Args.push_back(FirstII); |
| 510 | for (unsigned I = 1; I != N; ++I) |
| 511 | Args.push_back(Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d))); |
| 512 | |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 513 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 514 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 515 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 516 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 517 | using namespace clang::io; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 518 | |
| 519 | data_type Result; |
| 520 | |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 521 | Result.ID = ReadUnalignedLE32(d); |
| 522 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 523 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 524 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 525 | // Load instance methods |
| 526 | ObjCMethodList *Prev = 0; |
| 527 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | ObjCMethodDecl *Method |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 529 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 530 | if (!Result.Instance.Method) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 531 | // This is the first method, which is the easy case. |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 532 | Result.Instance.Method = Method; |
| 533 | Prev = &Result.Instance; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 534 | continue; |
| 535 | } |
| 536 | |
Ted Kremenek | da4abf1 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 537 | ObjCMethodList *Mem = |
| 538 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 539 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 540 | Prev = Prev->Next; |
| 541 | } |
| 542 | |
| 543 | // Load factory methods |
| 544 | Prev = 0; |
| 545 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 546 | ObjCMethodDecl *Method |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 547 | = cast<ObjCMethodDecl>(Reader.GetDecl(ReadUnalignedLE32(d))); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 548 | if (!Result.Factory.Method) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 549 | // This is the first method, which is the easy case. |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 550 | Result.Factory.Method = Method; |
| 551 | Prev = &Result.Factory; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 552 | continue; |
| 553 | } |
| 554 | |
Ted Kremenek | da4abf1 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 555 | ObjCMethodList *Mem = |
| 556 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 557 | Prev->Next = new (Mem) ObjCMethodList(Method, 0); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 558 | Prev = Prev->Next; |
| 559 | } |
| 560 | |
| 561 | return Result; |
| 562 | } |
| 563 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | |
| 565 | } // end anonymous namespace |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 566 | |
| 567 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 568 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 569 | ASTSelectorLookupTable; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 570 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 571 | namespace clang { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 572 | class ASTIdentifierLookupTrait { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 573 | ASTReader &Reader; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 574 | ASTReader::PerFileData &F; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 575 | |
| 576 | // If we know the IdentifierInfo in advance, it is here and we will |
| 577 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 578 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 579 | IdentifierInfo *KnownII; |
| 580 | |
| 581 | public: |
| 582 | typedef IdentifierInfo * data_type; |
| 583 | |
| 584 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 585 | |
| 586 | typedef external_key_type internal_key_type; |
| 587 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 588 | ASTIdentifierLookupTrait(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 589 | IdentifierInfo *II = 0) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 590 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 592 | static bool EqualKey(const internal_key_type& a, |
| 593 | const internal_key_type& b) { |
| 594 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 595 | : false; |
| 596 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 597 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 598 | static unsigned ComputeHash(const internal_key_type& a) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 599 | return llvm::HashString(llvm::StringRef(a.first, a.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | // This hopefully will just get inlined and removed by the optimizer. |
| 603 | static const internal_key_type& |
| 604 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 606 | // This hopefully will just get inlined and removed by the optimizer. |
| 607 | static const external_key_type& |
| 608 | GetExternalKey(const internal_key_type& x) { return x; } |
| 609 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 610 | static std::pair<unsigned, unsigned> |
| 611 | ReadKeyDataLength(const unsigned char*& d) { |
| 612 | using namespace clang::io; |
Douglas Gregor | 6b7bf5a | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 613 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 614 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 615 | return std::make_pair(KeyLen, DataLen); |
| 616 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 617 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 618 | static std::pair<const char*, unsigned> |
| 619 | ReadKey(const unsigned char* d, unsigned n) { |
| 620 | assert(n >= 2 && d[n-1] == '\0'); |
| 621 | return std::make_pair((const char*) d, n-1); |
| 622 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 623 | |
| 624 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 625 | const unsigned char* d, |
| 626 | unsigned DataLen) { |
| 627 | using namespace clang::io; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 628 | IdentID ID = ReadUnalignedLE32(d); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 629 | bool IsInteresting = ID & 0x01; |
| 630 | |
| 631 | // Wipe out the "is interesting" bit. |
| 632 | ID = ID >> 1; |
| 633 | |
| 634 | if (!IsInteresting) { |
Sebastian Redl | 9891212 | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 635 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 636 | // and associate it with the persistent ID. |
| 637 | IdentifierInfo *II = KnownII; |
| 638 | if (!II) |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 639 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 640 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 641 | II->setIsFromAST(); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 642 | return II; |
| 643 | } |
| 644 | |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 645 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 646 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 647 | Bits >>= 1; |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 648 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 649 | Bits >>= 1; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 650 | bool Poisoned = Bits & 0x01; |
| 651 | Bits >>= 1; |
| 652 | bool ExtensionToken = Bits & 0x01; |
| 653 | Bits >>= 1; |
| 654 | bool hasMacroDefinition = Bits & 0x01; |
| 655 | Bits >>= 1; |
| 656 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 657 | Bits >>= 10; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 659 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 660 | DataLen -= 6; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 661 | |
| 662 | // Build the IdentifierInfo itself and link the identifier ID with |
| 663 | // the new IdentifierInfo. |
| 664 | IdentifierInfo *II = KnownII; |
| 665 | if (!II) |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 666 | II = &Reader.getIdentifierTable().getOwn(k.first, k.first + k.second); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 667 | Reader.SetIdentifierInfo(ID, II); |
| 668 | |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 669 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 670 | // Token IDs are read-only. |
| 671 | if (HasRevertedTokenIDToIdentifier) |
| 672 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 673 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 674 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 675 | "Incorrect extension token flag"); |
| 676 | (void)ExtensionToken; |
| 677 | II->setIsPoisoned(Poisoned); |
| 678 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 679 | "Incorrect C++ operator keyword flag"); |
| 680 | (void)CPlusPlusOperatorKeyword; |
| 681 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 682 | // If this identifier is a macro, deserialize the macro |
| 683 | // definition. |
| 684 | if (hasMacroDefinition) { |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 685 | uint32_t Offset = ReadUnalignedLE32(d); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 686 | Reader.ReadMacroRecord(F, Offset); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 687 | DataLen -= 4; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 688 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 689 | |
| 690 | // Read all of the declarations visible at global scope with this |
| 691 | // name. |
Chris Lattner | 1d72888 | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 692 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 693 | if (DataLen > 0) { |
| 694 | llvm::SmallVector<uint32_t, 4> DeclIDs; |
| 695 | for (; DataLen > 0; DataLen -= 4) |
| 696 | DeclIDs.push_back(ReadUnalignedLE32(d)); |
| 697 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 698 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 699 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 700 | II->setIsFromAST(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 701 | return II; |
| 702 | } |
| 703 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | |
| 705 | } // end anonymous namespace |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 706 | |
| 707 | /// \brief The on-disk hash table used to contain information about |
| 708 | /// all of the identifiers in the program. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 709 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 710 | ASTIdentifierLookupTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 711 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 712 | namespace { |
| 713 | class ASTDeclContextNameLookupTrait { |
| 714 | ASTReader &Reader; |
| 715 | |
| 716 | public: |
| 717 | /// \brief Pair of begin/end iterators for DeclIDs. |
| 718 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 719 | |
| 720 | /// \brief Special internal key for declaration names. |
| 721 | /// The hash table creates keys for comparison; we do not create |
| 722 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 723 | struct DeclNameKey { |
| 724 | DeclarationName::NameKind Kind; |
| 725 | uint64_t Data; |
| 726 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 727 | }; |
| 728 | |
| 729 | typedef DeclarationName external_key_type; |
| 730 | typedef DeclNameKey internal_key_type; |
| 731 | |
| 732 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader) : Reader(Reader) { } |
| 733 | |
| 734 | static bool EqualKey(const internal_key_type& a, |
| 735 | const internal_key_type& b) { |
| 736 | return a.Kind == b.Kind && a.Data == b.Data; |
| 737 | } |
| 738 | |
| 739 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 740 | llvm::FoldingSetNodeID ID; |
| 741 | ID.AddInteger(Key.Kind); |
| 742 | |
| 743 | switch (Key.Kind) { |
| 744 | case DeclarationName::Identifier: |
| 745 | case DeclarationName::CXXLiteralOperatorName: |
| 746 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 747 | break; |
| 748 | case DeclarationName::ObjCZeroArgSelector: |
| 749 | case DeclarationName::ObjCOneArgSelector: |
| 750 | case DeclarationName::ObjCMultiArgSelector: |
| 751 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 752 | break; |
| 753 | case DeclarationName::CXXConstructorName: |
| 754 | case DeclarationName::CXXDestructorName: |
| 755 | case DeclarationName::CXXConversionFunctionName: |
| 756 | ID.AddInteger((TypeID)Key.Data); |
| 757 | break; |
| 758 | case DeclarationName::CXXOperatorName: |
| 759 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 760 | break; |
| 761 | case DeclarationName::CXXUsingDirective: |
| 762 | break; |
| 763 | } |
| 764 | |
| 765 | return ID.ComputeHash(); |
| 766 | } |
| 767 | |
| 768 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 769 | DeclNameKey Key; |
| 770 | Key.Kind = Name.getNameKind(); |
| 771 | switch (Name.getNameKind()) { |
| 772 | case DeclarationName::Identifier: |
| 773 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 774 | break; |
| 775 | case DeclarationName::ObjCZeroArgSelector: |
| 776 | case DeclarationName::ObjCOneArgSelector: |
| 777 | case DeclarationName::ObjCMultiArgSelector: |
| 778 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 779 | break; |
| 780 | case DeclarationName::CXXConstructorName: |
| 781 | case DeclarationName::CXXDestructorName: |
| 782 | case DeclarationName::CXXConversionFunctionName: |
| 783 | Key.Data = Reader.GetTypeID(Name.getCXXNameType()); |
| 784 | break; |
| 785 | case DeclarationName::CXXOperatorName: |
| 786 | Key.Data = Name.getCXXOverloadedOperator(); |
| 787 | break; |
| 788 | case DeclarationName::CXXLiteralOperatorName: |
| 789 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 790 | break; |
| 791 | case DeclarationName::CXXUsingDirective: |
| 792 | break; |
| 793 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 794 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 795 | return Key; |
| 796 | } |
| 797 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 798 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 799 | ASTContext *Context = Reader.getContext(); |
| 800 | switch (Key.Kind) { |
| 801 | case DeclarationName::Identifier: |
| 802 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 803 | |
| 804 | case DeclarationName::ObjCZeroArgSelector: |
| 805 | case DeclarationName::ObjCOneArgSelector: |
| 806 | case DeclarationName::ObjCMultiArgSelector: |
| 807 | return DeclarationName(Selector(Key.Data)); |
| 808 | |
| 809 | case DeclarationName::CXXConstructorName: |
| 810 | return Context->DeclarationNames.getCXXConstructorName( |
| 811 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 812 | |
| 813 | case DeclarationName::CXXDestructorName: |
| 814 | return Context->DeclarationNames.getCXXDestructorName( |
| 815 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 816 | |
| 817 | case DeclarationName::CXXConversionFunctionName: |
| 818 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 819 | Context->getCanonicalType(Reader.GetType(Key.Data))); |
| 820 | |
| 821 | case DeclarationName::CXXOperatorName: |
| 822 | return Context->DeclarationNames.getCXXOperatorName( |
| 823 | (OverloadedOperatorKind)Key.Data); |
| 824 | |
| 825 | case DeclarationName::CXXLiteralOperatorName: |
| 826 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 827 | (IdentifierInfo*)Key.Data); |
| 828 | |
| 829 | case DeclarationName::CXXUsingDirective: |
| 830 | return DeclarationName::getUsingDirectiveName(); |
| 831 | } |
| 832 | |
| 833 | llvm_unreachable("Invalid Name Kind ?"); |
| 834 | } |
| 835 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 836 | static std::pair<unsigned, unsigned> |
| 837 | ReadKeyDataLength(const unsigned char*& d) { |
| 838 | using namespace clang::io; |
| 839 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 840 | unsigned DataLen = ReadUnalignedLE16(d); |
| 841 | return std::make_pair(KeyLen, DataLen); |
| 842 | } |
| 843 | |
| 844 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 845 | using namespace clang::io; |
| 846 | |
| 847 | DeclNameKey Key; |
| 848 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 849 | switch (Key.Kind) { |
| 850 | case DeclarationName::Identifier: |
| 851 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 852 | break; |
| 853 | case DeclarationName::ObjCZeroArgSelector: |
| 854 | case DeclarationName::ObjCOneArgSelector: |
| 855 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 856 | Key.Data = |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 857 | (uint64_t)Reader.DecodeSelector(ReadUnalignedLE32(d)).getAsOpaquePtr(); |
| 858 | break; |
| 859 | case DeclarationName::CXXConstructorName: |
| 860 | case DeclarationName::CXXDestructorName: |
| 861 | case DeclarationName::CXXConversionFunctionName: |
| 862 | Key.Data = ReadUnalignedLE32(d); // TypeID |
| 863 | break; |
| 864 | case DeclarationName::CXXOperatorName: |
| 865 | Key.Data = *d++; // OverloadedOperatorKind |
| 866 | break; |
| 867 | case DeclarationName::CXXLiteralOperatorName: |
| 868 | Key.Data = (uint64_t)Reader.DecodeIdentifierInfo(ReadUnalignedLE32(d)); |
| 869 | break; |
| 870 | case DeclarationName::CXXUsingDirective: |
| 871 | break; |
| 872 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 873 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 874 | return Key; |
| 875 | } |
| 876 | |
| 877 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 878 | unsigned DataLen) { |
| 879 | using namespace clang::io; |
| 880 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 881 | DeclID *Start = (DeclID *)d; |
| 882 | return std::make_pair(Start, Start + NumDecls); |
| 883 | } |
| 884 | }; |
| 885 | |
| 886 | } // end anonymous namespace |
| 887 | |
| 888 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 889 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 890 | ASTDeclContextNameLookupTable; |
| 891 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 892 | bool ASTReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor, |
| 893 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 894 | DeclContextInfo &Info) { |
| 895 | SavedStreamPosition SavedPosition(Cursor); |
| 896 | // First the lexical decls. |
| 897 | if (Offsets.first != 0) { |
| 898 | Cursor.JumpToBit(Offsets.first); |
| 899 | |
| 900 | RecordData Record; |
| 901 | const char *Blob; |
| 902 | unsigned BlobLen; |
| 903 | unsigned Code = Cursor.ReadCode(); |
| 904 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 905 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 906 | Error("Expected lexical block"); |
| 907 | return true; |
| 908 | } |
| 909 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 910 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 911 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 912 | } else { |
| 913 | Info.LexicalDecls = 0; |
| 914 | Info.NumLexicalDecls = 0; |
| 915 | } |
| 916 | |
| 917 | // Now the lookup table. |
| 918 | if (Offsets.second != 0) { |
| 919 | Cursor.JumpToBit(Offsets.second); |
| 920 | |
| 921 | RecordData Record; |
| 922 | const char *Blob; |
| 923 | unsigned BlobLen; |
| 924 | unsigned Code = Cursor.ReadCode(); |
| 925 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 926 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 927 | Error("Expected visible lookup table block"); |
| 928 | return true; |
| 929 | } |
| 930 | Info.NameLookupTableData |
| 931 | = ASTDeclContextNameLookupTable::Create( |
| 932 | (const unsigned char *)Blob + Record[0], |
| 933 | (const unsigned char *)Blob, |
| 934 | ASTDeclContextNameLookupTrait(*this)); |
Sebastian Redl | 9d8f58b | 2010-08-24 00:50:00 +0000 | [diff] [blame] | 935 | } else { |
| 936 | Info.NameLookupTableData = 0; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | return false; |
| 940 | } |
| 941 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 942 | void ASTReader::Error(const char *Msg) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 943 | Diag(diag::err_fe_pch_malformed) << Msg; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 946 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 947 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 948 | if (Listener) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 949 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 950 | ActualOriginalFileName, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 951 | SuggestedPredefines); |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 952 | return false; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 955 | //===----------------------------------------------------------------------===// |
| 956 | // Source Manager Deserialization |
| 957 | //===----------------------------------------------------------------------===// |
| 958 | |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 959 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 960 | /// \returns true if there was an error. |
| 961 | bool ASTReader::ParseLineTable(PerFileData &F, |
| 962 | llvm::SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 963 | unsigned Idx = 0; |
| 964 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 965 | |
| 966 | // Parse the file names |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 967 | std::map<int, int> FileIDs; |
| 968 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 969 | // Extract the file name |
| 970 | unsigned FilenameLen = Record[Idx++]; |
| 971 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 972 | Idx += FilenameLen; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 973 | MaybeAddSystemRootToFilename(Filename); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename.c_str(), |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 975 | Filename.size()); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | // Parse the line entries |
| 979 | std::vector<LineEntry> Entries; |
| 980 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 981 | int FID = Record[Idx++]; |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 982 | |
| 983 | // Extract the line entries |
| 984 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 985 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 986 | Entries.clear(); |
| 987 | Entries.reserve(NumEntries); |
| 988 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 989 | unsigned FileOffset = Record[Idx++]; |
| 990 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 991 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 993 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 994 | unsigned IncludeOffset = Record[Idx++]; |
| 995 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 996 | FileKind, IncludeOffset)); |
| 997 | } |
| 998 | LineTable.AddEntry(FID, Entries); |
| 999 | } |
| 1000 | |
| 1001 | return false; |
| 1002 | } |
| 1003 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1004 | namespace { |
| 1005 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1006 | class ASTStatData { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1007 | public: |
| 1008 | const bool hasStat; |
| 1009 | const ino_t ino; |
| 1010 | const dev_t dev; |
| 1011 | const mode_t mode; |
| 1012 | const time_t mtime; |
| 1013 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1015 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1016 | : hasStat(true), ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
| 1017 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1018 | ASTStatData() |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1019 | : hasStat(false), ino(0), dev(0), mode(0), mtime(0), size(0) {} |
| 1020 | }; |
| 1021 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1022 | class ASTStatLookupTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1023 | public: |
| 1024 | typedef const char *external_key_type; |
| 1025 | typedef const char *internal_key_type; |
| 1026 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1027 | typedef ASTStatData data_type; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1028 | |
| 1029 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1030 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1034 | |
| 1035 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1036 | return strcmp(a, b) == 0; |
| 1037 | } |
| 1038 | |
| 1039 | static std::pair<unsigned, unsigned> |
| 1040 | ReadKeyDataLength(const unsigned char*& d) { |
| 1041 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1042 | unsigned DataLen = (unsigned) *d++; |
| 1043 | return std::make_pair(KeyLen + 1, DataLen); |
| 1044 | } |
| 1045 | |
| 1046 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1047 | return (const char *)d; |
| 1048 | } |
| 1049 | |
| 1050 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1051 | unsigned /*DataLen*/) { |
| 1052 | using namespace clang::io; |
| 1053 | |
| 1054 | if (*d++ == 1) |
| 1055 | return data_type(); |
| 1056 | |
| 1057 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1058 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1059 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1060 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1061 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1062 | return data_type(ino, dev, mode, mtime, size); |
| 1063 | } |
| 1064 | }; |
| 1065 | |
| 1066 | /// \brief stat() cache for precompiled headers. |
| 1067 | /// |
| 1068 | /// This cache is very similar to the stat cache used by pretokenized |
| 1069 | /// headers. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1070 | class ASTStatCache : public StatSysCallCache { |
| 1071 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1072 | CacheTy *Cache; |
| 1073 | |
| 1074 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1075 | public: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1076 | ASTStatCache(const unsigned char *Buckets, |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1077 | const unsigned char *Base, |
| 1078 | unsigned &NumStatHits, |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | unsigned &NumStatMisses) |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1080 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1081 | Cache = CacheTy::Create(Buckets, Base); |
| 1082 | } |
| 1083 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1084 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1086 | int stat(const char *path, struct stat *buf) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1087 | // Do the lookup for the file's data in the AST file. |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1088 | CacheTy::iterator I = Cache->find(path); |
| 1089 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1090 | // If we don't get a hit in the AST file just forward to 'stat'. |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1091 | if (I == Cache->end()) { |
| 1092 | ++NumStatMisses; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 1093 | return StatSysCallCache::stat(path, buf); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1094 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1096 | ++NumStatHits; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1097 | ASTStatData Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1098 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1099 | if (!Data.hasStat) |
| 1100 | return 1; |
| 1101 | |
| 1102 | buf->st_ino = Data.ino; |
| 1103 | buf->st_dev = Data.dev; |
| 1104 | buf->st_mtime = Data.mtime; |
| 1105 | buf->st_mode = Data.mode; |
| 1106 | buf->st_size = Data.size; |
| 1107 | return 0; |
| 1108 | } |
| 1109 | }; |
| 1110 | } // end anonymous namespace |
| 1111 | |
| 1112 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1113 | /// \brief Read a source manager block |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1114 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(PerFileData &F) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1115 | using namespace SrcMgr; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1116 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1117 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1119 | // Set the source-location entry cursor to the current position in |
| 1120 | // the stream. This cursor will be used to read the contents of the |
| 1121 | // source manager block initially, and then lazily read |
| 1122 | // source-location entries as needed. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1123 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1124 | |
| 1125 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1126 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1127 | Error("malformed block record in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1128 | return Failure; |
| 1129 | } |
| 1130 | |
| 1131 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1132 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1133 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1134 | return Failure; |
| 1135 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1136 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1137 | RecordData Record; |
| 1138 | while (true) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1140 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1141 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1142 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1143 | return Failure; |
| 1144 | } |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1145 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1146 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1148 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1149 | // No known subblocks, always skip them. |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1150 | SLocEntryCursor.ReadSubBlockID(); |
| 1151 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1152 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1153 | return Failure; |
| 1154 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1155 | continue; |
| 1156 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1158 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1159 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1160 | continue; |
| 1161 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1162 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1163 | // Read a record. |
| 1164 | const char *BlobStart; |
| 1165 | unsigned BlobLen; |
| 1166 | Record.clear(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1167 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1168 | default: // Default behavior: ignore. |
| 1169 | break; |
| 1170 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1171 | case SM_LINE_TABLE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1172 | if (ParseLineTable(F, Record)) |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1173 | return Failure; |
Chris Lattner | 184e65d | 2009-04-14 23:22:57 +0000 | [diff] [blame] | 1174 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1175 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1176 | case SM_SLOC_FILE_ENTRY: |
| 1177 | case SM_SLOC_BUFFER_ENTRY: |
| 1178 | case SM_SLOC_INSTANTIATION_ENTRY: |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1179 | // Once we hit one of the source location entries, we're done. |
| 1180 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | |
Sebastian Redl | 0675030 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1185 | /// \brief Get a cursor that's correctly positioned for reading the source |
| 1186 | /// location entry with the given ID. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1187 | ASTReader::PerFileData *ASTReader::SLocCursorForID(unsigned ID) { |
Sebastian Redl | 0675030 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1188 | assert(ID != 0 && ID <= TotalNumSLocEntries && |
| 1189 | "SLocCursorForID should only be called for real IDs."); |
| 1190 | |
| 1191 | ID -= 1; |
| 1192 | PerFileData *F = 0; |
| 1193 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1194 | F = Chain[N - I - 1]; |
| 1195 | if (ID < F->LocalNumSLocEntries) |
| 1196 | break; |
| 1197 | ID -= F->LocalNumSLocEntries; |
| 1198 | } |
| 1199 | assert(F && F->LocalNumSLocEntries > ID && "Chain corrupted"); |
| 1200 | |
| 1201 | F->SLocEntryCursor.JumpToBit(F->SLocOffsets[ID]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1202 | return F; |
Sebastian Redl | 0675030 | 2010-07-20 21:50:20 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1205 | /// \brief Read in the source location entry with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1206 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(unsigned ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1207 | if (ID == 0) |
| 1208 | return Success; |
| 1209 | |
| 1210 | if (ID > TotalNumSLocEntries) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1211 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1212 | return Failure; |
| 1213 | } |
| 1214 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1215 | PerFileData *F = SLocCursorForID(ID); |
| 1216 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1217 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1218 | ++NumSLocEntriesRead; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1219 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1220 | if (Code == llvm::bitc::END_BLOCK || |
| 1221 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1222 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1223 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1224 | return Failure; |
| 1225 | } |
| 1226 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1227 | RecordData Record; |
| 1228 | const char *BlobStart; |
| 1229 | unsigned BlobLen; |
| 1230 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1231 | default: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1232 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1233 | return Failure; |
| 1234 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1235 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1236 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1237 | MaybeAddSystemRootToFilename(Filename); |
| 1238 | const FileEntry *File = FileMgr.getFile(Filename); |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1239 | if (File == 0) { |
| 1240 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1241 | ErrorStr += Filename; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1242 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1243 | Error(ErrorStr.c_str()); |
| 1244 | return Failure; |
| 1245 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1246 | |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1247 | if (Record.size() < 10) { |
Ted Kremenek | abb1ddd | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1248 | Error("source location entry is incorrect"); |
| 1249 | return Failure; |
| 1250 | } |
| 1251 | |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1252 | if (!DisableValidation && |
| 1253 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1254 | #if !defined(LLVM_ON_WIN32) |
| 1255 | // In our regression testing, the Windows file system seems to |
| 1256 | // have inconsistent modification times that sometimes |
| 1257 | // erroneously trigger this error-handling path. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1258 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1259 | #endif |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1260 | )) { |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1261 | Diag(diag::err_fe_pch_file_modified) |
| 1262 | << Filename; |
| 1263 | return Failure; |
| 1264 | } |
| 1265 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1266 | FileID FID = SourceMgr.createFileID(File, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1267 | ReadSourceLocation(*F, Record[1]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1268 | (SrcMgr::CharacteristicKind)Record[2], |
| 1269 | ID, Record[0]); |
| 1270 | if (Record[3]) |
| 1271 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()) |
| 1272 | .setHasLineDirectives(); |
| 1273 | |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1274 | // Reconstruct header-search information for this file. |
| 1275 | HeaderFileInfo HFI; |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1276 | HFI.isImport = Record[6]; |
| 1277 | HFI.DirInfo = Record[7]; |
| 1278 | HFI.NumIncludes = Record[8]; |
| 1279 | HFI.ControllingMacroID = Record[9]; |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 1280 | if (Listener) |
| 1281 | Listener->ReadHeaderFileInfo(HFI, File->getUID()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1282 | break; |
| 1283 | } |
| 1284 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1285 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1286 | const char *Name = BlobStart; |
| 1287 | unsigned Offset = Record[0]; |
| 1288 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1289 | Record.clear(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1290 | unsigned RecCode |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1291 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1292 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1293 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1294 | Error("AST record has invalid code"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1295 | return Failure; |
| 1296 | } |
| 1297 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1298 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1299 | = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(BlobStart, BlobLen - 1), |
| 1300 | Name); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1301 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, Offset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1303 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1304 | PCHPredefinesBlock Block = { |
| 1305 | BufferID, |
| 1306 | llvm::StringRef(BlobStart, BlobLen - 1) |
| 1307 | }; |
| 1308 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1309 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1310 | |
| 1311 | break; |
| 1312 | } |
| 1313 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1314 | case SM_SLOC_INSTANTIATION_ENTRY: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1315 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1316 | SourceMgr.createInstantiationLoc(SpellingLoc, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1317 | ReadSourceLocation(*F, Record[2]), |
| 1318 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1319 | Record[4], |
| 1320 | ID, |
| 1321 | Record[0]); |
| 1322 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1323 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | return Success; |
| 1327 | } |
| 1328 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1329 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1330 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1331 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1332 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1333 | unsigned BlockID) { |
| 1334 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1335 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1336 | return Failure; |
| 1337 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1338 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1339 | while (true) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1340 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1341 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1342 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1343 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1344 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1345 | Cursor.JumpToBit(Offset); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1346 | return false; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1347 | } |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1348 | Cursor.ReadAbbrevRecord(); |
| 1349 | } |
| 1350 | } |
| 1351 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1352 | void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1353 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1354 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1355 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1356 | // Keep track of where we are in the stream, then jump back there |
| 1357 | // after reading this macro. |
| 1358 | SavedStreamPosition SavedPosition(Stream); |
| 1359 | |
| 1360 | Stream.JumpToBit(Offset); |
| 1361 | RecordData Record; |
| 1362 | llvm::SmallVector<IdentifierInfo*, 16> MacroArgs; |
| 1363 | MacroInfo *Macro = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1364 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1365 | while (true) { |
| 1366 | unsigned Code = Stream.ReadCode(); |
| 1367 | switch (Code) { |
| 1368 | case llvm::bitc::END_BLOCK: |
| 1369 | return; |
| 1370 | |
| 1371 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1372 | // No known subblocks, always skip them. |
| 1373 | Stream.ReadSubBlockID(); |
| 1374 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1375 | Error("malformed block record in AST file"); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1376 | return; |
| 1377 | } |
| 1378 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1380 | case llvm::bitc::DEFINE_ABBREV: |
| 1381 | Stream.ReadAbbrevRecord(); |
| 1382 | continue; |
| 1383 | default: break; |
| 1384 | } |
| 1385 | |
| 1386 | // Read a record. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1387 | const char *BlobStart = 0; |
| 1388 | unsigned BlobLen = 0; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1389 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1390 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1391 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1392 | BlobLen); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1393 | switch (RecType) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1394 | case PP_MACRO_OBJECT_LIKE: |
| 1395 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1396 | // If we already have a macro, that means that we've hit the end |
| 1397 | // of the definition of the macro we were looking for. We're |
| 1398 | // done. |
| 1399 | if (Macro) |
| 1400 | return; |
| 1401 | |
| 1402 | IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); |
| 1403 | if (II == 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1404 | Error("macro must have a name in AST file"); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1405 | return; |
| 1406 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1407 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1408 | bool isUsed = Record[2]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1410 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1411 | MI->setIsUsed(isUsed); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1412 | MI->setIsFromAST(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1414 | unsigned NextIndex = 3; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1415 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1416 | // Decode function-like macro info. |
| 1417 | bool isC99VarArgs = Record[3]; |
| 1418 | bool isGNUVarArgs = Record[4]; |
| 1419 | MacroArgs.clear(); |
| 1420 | unsigned NumArgs = Record[5]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1421 | NextIndex = 6 + NumArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1422 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1423 | MacroArgs.push_back(DecodeIdentifierInfo(Record[6+i])); |
| 1424 | |
| 1425 | // Install function-like macro info. |
| 1426 | MI->setIsFunctionLike(); |
| 1427 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1428 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1429 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1430 | PP->getPreprocessorAllocator()); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | // Finally, install the macro. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1434 | PP->setMacroInfo(II, MI); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1435 | |
| 1436 | // Remember that we saw this macro last so that we add the tokens that |
| 1437 | // form its body to it. |
| 1438 | Macro = MI; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1439 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1440 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1441 | // We have a macro definition. Load it now. |
| 1442 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
| 1443 | getMacroDefinition(Record[NextIndex])); |
| 1444 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1445 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1446 | ++NumMacrosRead; |
| 1447 | break; |
| 1448 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1450 | case PP_TOKEN: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1451 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1452 | // erroneous, just pretend we didn't see this. |
| 1453 | if (Macro == 0) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1454 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1455 | Token Tok; |
| 1456 | Tok.startToken(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1457 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1458 | Tok.setLength(Record[1]); |
| 1459 | if (IdentifierInfo *II = DecodeIdentifierInfo(Record[2])) |
| 1460 | Tok.setIdentifierInfo(II); |
| 1461 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1462 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1463 | Macro->AddTokenToBody(Tok); |
| 1464 | break; |
| 1465 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1466 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1467 | case PP_MACRO_INSTANTIATION: { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1468 | // If we already have a macro, that means that we've hit the end |
| 1469 | // of the definition of the macro we were looking for. We're |
| 1470 | // done. |
| 1471 | if (Macro) |
| 1472 | return; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1473 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1474 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1475 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1476 | return; |
| 1477 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1478 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1479 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1480 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1481 | return; |
| 1482 | |
| 1483 | MacroInstantiation *MI |
| 1484 | = new (PPRec) MacroInstantiation(DecodeIdentifierInfo(Record[3]), |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1485 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1486 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1487 | getMacroDefinition(Record[4])); |
| 1488 | PPRec.SetPreallocatedEntity(Record[0], MI); |
| 1489 | return; |
| 1490 | } |
| 1491 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1492 | case PP_MACRO_DEFINITION: { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1493 | // If we already have a macro, that means that we've hit the end |
| 1494 | // of the definition of the macro we were looking for. We're |
| 1495 | // done. |
| 1496 | if (Macro) |
| 1497 | return; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1498 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1499 | if (!PP->getPreprocessingRecord()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1500 | Error("missing preprocessing record in AST file"); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1501 | return; |
| 1502 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1503 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1504 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1505 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1506 | return; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1507 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1508 | if (Record[1] > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1509 | Error("out-of-bounds macro definition record"); |
| 1510 | return; |
| 1511 | } |
| 1512 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1513 | // Decode the identifier info and then check again; if the macro is |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1514 | // still defined and associated with the identifier, |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1515 | IdentifierInfo *II = DecodeIdentifierInfo(Record[4]); |
| 1516 | if (!MacroDefinitionsLoaded[Record[1] - 1]) { |
| 1517 | MacroDefinition *MD |
| 1518 | = new (PPRec) MacroDefinition(II, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1519 | ReadSourceLocation(F, Record[5]), |
Douglas Gregor | 36ea4d4 | 2010-10-01 20:33:34 +0000 | [diff] [blame] | 1520 | SourceRange( |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1521 | ReadSourceLocation(F, Record[2]), |
| 1522 | ReadSourceLocation(F, Record[3]))); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1523 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1524 | PPRec.SetPreallocatedEntity(Record[0], MD); |
| 1525 | MacroDefinitionsLoaded[Record[1] - 1] = MD; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1526 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1527 | if (DeserializationListener) |
| 1528 | DeserializationListener->MacroDefinitionRead(Record[1], MD); |
| 1529 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1530 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1531 | return; |
| 1532 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1533 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1534 | case PP_INCLUSION_DIRECTIVE: { |
| 1535 | // If we already have a macro, that means that we've hit the end |
| 1536 | // of the definition of the macro we were looking for. We're |
| 1537 | // done. |
| 1538 | if (Macro) |
| 1539 | return; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1540 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1541 | if (!PP->getPreprocessingRecord()) { |
| 1542 | Error("missing preprocessing record in AST file"); |
| 1543 | return; |
| 1544 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1545 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1546 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1547 | if (PPRec.getPreprocessedEntity(Record[0])) |
| 1548 | return; |
| 1549 | |
| 1550 | const char *FullFileNameStart = BlobStart + Record[3]; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1551 | const FileEntry *File |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1552 | = PP->getFileManager().getFile(FullFileNameStart, |
| 1553 | FullFileNameStart + (BlobLen - Record[3])); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1554 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1555 | // FIXME: Stable encoding |
| 1556 | InclusionDirective::InclusionKind Kind |
| 1557 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1558 | InclusionDirective *ID |
| 1559 | = new (PPRec) InclusionDirective(Kind, |
| 1560 | llvm::StringRef(BlobStart, Record[3]), |
| 1561 | Record[4], |
| 1562 | File, |
| 1563 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1564 | ReadSourceLocation(F, Record[2]))); |
| 1565 | PPRec.SetPreallocatedEntity(Record[0], ID); |
| 1566 | return; |
| 1567 | } |
Sebastian Redl | 9609b4f | 2010-09-27 22:18:47 +0000 | [diff] [blame] | 1568 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1569 | } |
| 1570 | } |
| 1571 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1572 | void ASTReader::ReadDefinedMacros() { |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1573 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1574 | PerFileData &F = *Chain[N - I - 1]; |
| 1575 | llvm::BitstreamCursor &MacroCursor = F.MacroCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1576 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1577 | // If there was no preprocessor block, skip this file. |
| 1578 | if (!MacroCursor.getBitStreamReader()) |
| 1579 | continue; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1580 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1581 | llvm::BitstreamCursor Cursor = MacroCursor; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1582 | Cursor.JumpToBit(F.MacroStartOffset); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1583 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1584 | RecordData Record; |
| 1585 | while (true) { |
Sebastian Redl | 4102dd5 | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1586 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1587 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1588 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1589 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1590 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1591 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1592 | // No known subblocks, always skip them. |
| 1593 | Cursor.ReadSubBlockID(); |
| 1594 | if (Cursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1595 | Error("malformed block record in AST file"); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1596 | return; |
| 1597 | } |
| 1598 | continue; |
| 1599 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1600 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1601 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1602 | Cursor.ReadAbbrevRecord(); |
| 1603 | continue; |
| 1604 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1605 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1606 | // Read a record. |
| 1607 | const char *BlobStart; |
| 1608 | unsigned BlobLen; |
| 1609 | Record.clear(); |
| 1610 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1611 | default: // Default behavior: ignore. |
| 1612 | break; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1613 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1614 | case PP_MACRO_OBJECT_LIKE: |
| 1615 | case PP_MACRO_FUNCTION_LIKE: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1616 | DecodeIdentifierInfo(Record[0]); |
| 1617 | break; |
| 1618 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1619 | case PP_TOKEN: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1620 | // Ignore tokens. |
| 1621 | break; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 1622 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1623 | case PP_MACRO_INSTANTIATION: |
| 1624 | case PP_MACRO_DEFINITION: |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1625 | case PP_INCLUSION_DIRECTIVE: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1626 | // Read the macro record. |
Sebastian Redl | 4102dd5 | 2010-09-28 02:55:49 +0000 | [diff] [blame] | 1627 | // FIXME: That's a stupid way to do this. We should reuse this cursor. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1628 | ReadMacroRecord(F, Offset); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | } |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | } |
| 1634 | |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1635 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1636 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1637 | return 0; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1638 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1639 | if (!MacroDefinitionsLoaded[ID - 1]) { |
| 1640 | unsigned Index = ID - 1; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1641 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 1642 | PerFileData &F = *Chain[N - I - 1]; |
| 1643 | if (Index < F.LocalNumMacroDefinitions) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1644 | ReadMacroRecord(F, F.MacroDefinitionOffsets[Index]); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1645 | break; |
| 1646 | } |
| 1647 | Index -= F.LocalNumMacroDefinitions; |
| 1648 | } |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1649 | assert(MacroDefinitionsLoaded[ID - 1] && "Broken chain"); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1652 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1655 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1656 | /// not an absolute path, add the system root to the beginning of the file |
| 1657 | /// name. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1658 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1659 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1660 | if (!RelocatablePCH) |
| 1661 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1662 | |
Daniel Dunbar | f2ce9a2 | 2009-11-18 19:50:41 +0000 | [diff] [blame] | 1663 | if (Filename.empty() || llvm::sys::Path(Filename).isAbsolute()) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1664 | return; |
| 1665 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1666 | if (isysroot == 0) { |
| 1667 | // If no system root was given, default to '/' |
| 1668 | Filename.insert(Filename.begin(), '/'); |
| 1669 | return; |
| 1670 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1671 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1672 | unsigned Length = strlen(isysroot); |
| 1673 | if (isysroot[Length - 1] != '/') |
| 1674 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1675 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1676 | Filename.insert(Filename.begin(), isysroot, isysroot + Length); |
| 1677 | } |
| 1678 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1679 | ASTReader::ASTReadResult |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 1680 | ASTReader::ReadASTBlock(PerFileData &F) { |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1681 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1682 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1683 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1684 | Error("malformed block record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1685 | return Failure; |
| 1686 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1687 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1688 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1689 | RecordData Record; |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1690 | bool First = true; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1691 | while (!Stream.AtEndOfStream()) { |
| 1692 | unsigned Code = Stream.ReadCode(); |
| 1693 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1694 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1695 | Error("error at end of module block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1696 | return Failure; |
| 1697 | } |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1698 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1699 | return Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1703 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1704 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1705 | // We lazily load the decls block, but we want to set up the |
| 1706 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1707 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1708 | // With the main cursor, we just skip over it. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1709 | F.DeclsCursor = Stream; |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1710 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1711 | // Read the abbrevs. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1712 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1713 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1714 | return Failure; |
| 1715 | } |
| 1716 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1717 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1718 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1719 | F.MacroCursor = Stream; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1720 | if (PP) |
| 1721 | PP->setExternalSource(this); |
| 1722 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1723 | if (Stream.SkipBlock() || |
| 1724 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1725 | Error("malformed block record in AST file"); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1726 | return Failure; |
| 1727 | } |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1728 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1729 | break; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1730 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1731 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1732 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1733 | case Success: |
| 1734 | break; |
| 1735 | |
| 1736 | case Failure: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1737 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1738 | return Failure; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1739 | |
| 1740 | case IgnorePCH: |
| 1741 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1742 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1743 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1744 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1745 | First = false; |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1746 | continue; |
| 1747 | } |
| 1748 | |
| 1749 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1750 | Stream.ReadAbbrevRecord(); |
| 1751 | continue; |
| 1752 | } |
| 1753 | |
| 1754 | // Read and process a record. |
| 1755 | Record.clear(); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1756 | const char *BlobStart = 0; |
| 1757 | unsigned BlobLen = 0; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1758 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1759 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1760 | default: // Default behavior: ignore. |
| 1761 | break; |
| 1762 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1763 | case METADATA: { |
| 1764 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1765 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1766 | : diag::warn_pch_version_too_new); |
| 1767 | return IgnorePCH; |
| 1768 | } |
| 1769 | |
| 1770 | RelocatablePCH = Record[4]; |
| 1771 | if (Listener) { |
| 1772 | std::string TargetTriple(BlobStart, BlobLen); |
| 1773 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1774 | return IgnorePCH; |
| 1775 | } |
| 1776 | break; |
| 1777 | } |
| 1778 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1779 | case CHAINED_METADATA: { |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1780 | if (!First) { |
| 1781 | Error("CHAINED_METADATA is not first record in block"); |
| 1782 | return Failure; |
| 1783 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1784 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1785 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1786 | : diag::warn_pch_version_too_new); |
| 1787 | return IgnorePCH; |
| 1788 | } |
| 1789 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 1790 | // Load the chained file, which is always a PCH file. |
| 1791 | switch(ReadASTCore(llvm::StringRef(BlobStart, BlobLen), PCH)) { |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1792 | case Failure: return Failure; |
| 1793 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1794 | case IgnorePCH: return IgnorePCH; |
| 1795 | case Success: break; |
| 1796 | } |
| 1797 | break; |
| 1798 | } |
| 1799 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1800 | case TYPE_OFFSET: |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1801 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1802 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1803 | return Failure; |
| 1804 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1805 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1806 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1809 | case DECL_OFFSET: |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1810 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1811 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1812 | return Failure; |
| 1813 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1814 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1815 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1816 | break; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1817 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1818 | case TU_UPDATE_LEXICAL: { |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1819 | DeclContextInfo Info = { |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 1820 | /* No visible information */ 0, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 1821 | reinterpret_cast<const KindDeclIDPair *>(BlobStart), |
| 1822 | BlobLen / sizeof(KindDeclIDPair) |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1823 | }; |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1824 | DeclContextOffsets[Context ? Context->getTranslationUnitDecl() : 0] |
| 1825 | .push_back(Info); |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1826 | break; |
| 1827 | } |
| 1828 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1829 | case UPDATE_VISIBLE: { |
| 1830 | serialization::DeclID ID = Record[0]; |
| 1831 | void *Table = ASTDeclContextNameLookupTable::Create( |
| 1832 | (const unsigned char *)BlobStart + Record[1], |
| 1833 | (const unsigned char *)BlobStart, |
| 1834 | ASTDeclContextNameLookupTrait(*this)); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 1835 | if (ID == 1 && Context) { // Is it the TU? |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1836 | DeclContextInfo Info = { |
| 1837 | Table, /* No lexical inforamtion */ 0, 0 |
| 1838 | }; |
| 1839 | DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info); |
| 1840 | } else |
| 1841 | PendingVisibleUpdates[ID].push_back(Table); |
| 1842 | break; |
| 1843 | } |
| 1844 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1845 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1846 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
| 1847 | for (unsigned i = 0, e = Record.size(); i < e; i += 2) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1848 | DeclID First = Record[i], Latest = Record[i+1]; |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1849 | assert((FirstLatestDeclIDs.find(First) == FirstLatestDeclIDs.end() || |
| 1850 | Latest > FirstLatestDeclIDs[First]) && |
| 1851 | "The new latest is supposed to come after the previous latest"); |
| 1852 | FirstLatestDeclIDs[First] = Latest; |
| 1853 | } |
| 1854 | break; |
| 1855 | } |
| 1856 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1857 | case LANGUAGE_OPTIONS: |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1858 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1859 | return IgnorePCH; |
| 1860 | break; |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1861 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1862 | case IDENTIFIER_TABLE: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1863 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1864 | if (Record[0]) { |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1865 | F.IdentifierLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1866 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1867 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1868 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1869 | ASTIdentifierLookupTrait(*this, F)); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1870 | if (PP) |
| 1871 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1872 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1873 | break; |
| 1874 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1875 | case IDENTIFIER_OFFSET: |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1876 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1877 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1878 | return Failure; |
| 1879 | } |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1880 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1881 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1882 | break; |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1883 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1884 | case EXTERNAL_DEFINITIONS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1885 | // Optimization for the first block. |
| 1886 | if (ExternalDefinitions.empty()) |
| 1887 | ExternalDefinitions.swap(Record); |
| 1888 | else |
| 1889 | ExternalDefinitions.insert(ExternalDefinitions.end(), |
| 1890 | Record.begin(), Record.end()); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 1891 | break; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1892 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1893 | case SPECIAL_TYPES: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1894 | // Optimization for the first block |
| 1895 | if (SpecialTypes.empty()) |
| 1896 | SpecialTypes.swap(Record); |
| 1897 | else |
| 1898 | SpecialTypes.insert(SpecialTypes.end(), Record.begin(), Record.end()); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 1899 | break; |
| 1900 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1901 | case STATISTICS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1902 | TotalNumStatements += Record[0]; |
| 1903 | TotalNumMacros += Record[1]; |
| 1904 | TotalLexicalDeclContexts += Record[2]; |
| 1905 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 1906 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1907 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1908 | case TENTATIVE_DEFINITIONS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1909 | // Optimization for the first block. |
| 1910 | if (TentativeDefinitions.empty()) |
| 1911 | TentativeDefinitions.swap(Record); |
| 1912 | else |
| 1913 | TentativeDefinitions.insert(TentativeDefinitions.end(), |
| 1914 | Record.begin(), Record.end()); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 1915 | break; |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1916 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1917 | case UNUSED_FILESCOPED_DECLS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1918 | // Optimization for the first block. |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1919 | if (UnusedFileScopedDecls.empty()) |
| 1920 | UnusedFileScopedDecls.swap(Record); |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1921 | else |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 1922 | UnusedFileScopedDecls.insert(UnusedFileScopedDecls.end(), |
| 1923 | Record.begin(), Record.end()); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 1924 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1925 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1926 | case WEAK_UNDECLARED_IDENTIFIERS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1927 | // Later blocks overwrite earlier ones. |
| 1928 | WeakUndeclaredIdentifiers.swap(Record); |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1931 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1932 | // Optimization for the first block. |
| 1933 | if (LocallyScopedExternalDecls.empty()) |
| 1934 | LocallyScopedExternalDecls.swap(Record); |
| 1935 | else |
| 1936 | LocallyScopedExternalDecls.insert(LocallyScopedExternalDecls.end(), |
| 1937 | Record.begin(), Record.end()); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 1938 | break; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1939 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1940 | case SELECTOR_OFFSETS: |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 1941 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1942 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1945 | case METHOD_POOL: |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1946 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 1947 | if (Record[0]) |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1948 | F.SelectorLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1949 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 1950 | F.SelectorLookupTableData + Record[0], |
| 1951 | F.SelectorLookupTableData, |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1952 | ASTSelectorLookupTrait(*this)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 1953 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1954 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1955 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 1956 | case REFERENCED_SELECTOR_POOL: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1957 | F.ReferencedSelectorsData.swap(Record); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 1958 | break; |
| 1959 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1960 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1961 | if (!Record.empty() && Listener) |
| 1962 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 1963 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1964 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1965 | case SOURCE_LOCATION_OFFSETS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 1966 | F.SLocOffsets = (const uint32_t *)BlobStart; |
| 1967 | F.LocalNumSLocEntries = Record[0]; |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 1968 | F.LocalSLocSize = Record[1]; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1969 | break; |
| 1970 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1971 | case SOURCE_LOCATION_PRELOADS: |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 1972 | if (PreloadSLocEntries.empty()) |
| 1973 | PreloadSLocEntries.swap(Record); |
| 1974 | else |
| 1975 | PreloadSLocEntries.insert(PreloadSLocEntries.end(), |
| 1976 | Record.begin(), Record.end()); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1977 | break; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1978 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1979 | case STAT_CACHE: { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1980 | ASTStatCache *MyStatCache = |
| 1981 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 1982 | (const unsigned char *)BlobStart, |
| 1983 | NumStatHits, NumStatMisses); |
| 1984 | FileMgr.addStatCache(MyStatCache); |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1985 | F.StatCache = MyStatCache; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1986 | break; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 1987 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1988 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1989 | case EXT_VECTOR_DECLS: |
Sebastian Redl | 04f5c31 | 2010-07-28 21:38:49 +0000 | [diff] [blame] | 1990 | // Optimization for the first block. |
| 1991 | if (ExtVectorDecls.empty()) |
| 1992 | ExtVectorDecls.swap(Record); |
| 1993 | else |
| 1994 | ExtVectorDecls.insert(ExtVectorDecls.end(), |
| 1995 | Record.begin(), Record.end()); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 1996 | break; |
| 1997 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1998 | case VTABLE_USES: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 1999 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2000 | VTableUses.swap(Record); |
| 2001 | break; |
| 2002 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2003 | case DYNAMIC_CLASSES: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2004 | // Optimization for the first block. |
| 2005 | if (DynamicClasses.empty()) |
| 2006 | DynamicClasses.swap(Record); |
| 2007 | else |
| 2008 | DynamicClasses.insert(DynamicClasses.end(), |
| 2009 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2010 | break; |
| 2011 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2012 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2013 | F.PendingInstantiations.swap(Record); |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2014 | break; |
| 2015 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2016 | case SEMA_DECL_REFS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2017 | // Later tables overwrite earlier ones. |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2018 | SemaDeclRefs.swap(Record); |
| 2019 | break; |
| 2020 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2021 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2022 | // The primary AST will be the last to get here, so it will be the one |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2023 | // that's used. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2024 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2025 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2026 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2027 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2028 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2029 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 8bd0929 | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2030 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2031 | llvm::StringRef ASTBranch(BlobStart, BlobLen); |
| 2032 | if (llvm::StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2033 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2034 | return IgnorePCH; |
| 2035 | } |
| 2036 | break; |
| 2037 | } |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2038 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2039 | case MACRO_DEFINITION_OFFSETS: |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2040 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2041 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
| 2042 | F.LocalNumMacroDefinitions = Record[1]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2043 | break; |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2044 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2045 | case DECL_REPLACEMENTS: { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2046 | if (Record.size() % 2 != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2047 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2048 | return Failure; |
| 2049 | } |
| 2050 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2051 | ReplacedDecls[static_cast<DeclID>(Record[I])] = |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2052 | std::make_pair(&F, Record[I+1]); |
| 2053 | break; |
| 2054 | } |
Sebastian Redl | aba202b | 2010-08-24 22:50:19 +0000 | [diff] [blame] | 2055 | |
| 2056 | case ADDITIONAL_TEMPLATE_SPECIALIZATIONS: { |
| 2057 | AdditionalTemplateSpecializations &ATS = |
| 2058 | AdditionalTemplateSpecializationsPending[Record[0]]; |
| 2059 | ATS.insert(ATS.end(), Record.begin()+1, Record.end()); |
| 2060 | break; |
| 2061 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2062 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2063 | First = false; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2064 | } |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2065 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2066 | return Failure; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2067 | } |
| 2068 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2069 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
| 2070 | ASTFileType Type) { |
| 2071 | switch(ReadASTCore(FileName, Type)) { |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2072 | case Failure: return Failure; |
| 2073 | case IgnorePCH: return IgnorePCH; |
| 2074 | case Success: break; |
| 2075 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2076 | |
| 2077 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2078 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2079 | // Allocate space for loaded slocentries, identifiers, decls and types. |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2080 | unsigned TotalNumIdentifiers = 0, TotalNumTypes = 0, TotalNumDecls = 0, |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2081 | TotalNumPreallocatedPreprocessingEntities = 0, TotalNumMacroDefs = 0, |
| 2082 | TotalNumSelectors = 0; |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2083 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2084 | TotalNumSLocEntries += Chain[I]->LocalNumSLocEntries; |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2085 | NextSLocOffset += Chain[I]->LocalSLocSize; |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2086 | TotalNumIdentifiers += Chain[I]->LocalNumIdentifiers; |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2087 | TotalNumTypes += Chain[I]->LocalNumTypes; |
| 2088 | TotalNumDecls += Chain[I]->LocalNumDecls; |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2089 | TotalNumPreallocatedPreprocessingEntities += |
| 2090 | Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2091 | TotalNumMacroDefs += Chain[I]->LocalNumMacroDefinitions; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2092 | TotalNumSelectors += Chain[I]->LocalNumSelectors; |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2093 | } |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 2094 | SourceMgr.PreallocateSLocEntries(this, TotalNumSLocEntries, NextSLocOffset); |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2095 | IdentifiersLoaded.resize(TotalNumIdentifiers); |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2096 | TypesLoaded.resize(TotalNumTypes); |
| 2097 | DeclsLoaded.resize(TotalNumDecls); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2098 | MacroDefinitionsLoaded.resize(TotalNumMacroDefs); |
| 2099 | if (PP) { |
| 2100 | if (TotalNumIdentifiers > 0) |
| 2101 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2102 | if (TotalNumPreallocatedPreprocessingEntities > 0) { |
| 2103 | if (!PP->getPreprocessingRecord()) |
| 2104 | PP->createPreprocessingRecord(); |
| 2105 | PP->getPreprocessingRecord()->SetExternalSource(*this, |
| 2106 | TotalNumPreallocatedPreprocessingEntities); |
| 2107 | } |
| 2108 | } |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2109 | SelectorsLoaded.resize(TotalNumSelectors); |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2110 | // Preload SLocEntries. |
| 2111 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2112 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2113 | if (Result != Success) |
| 2114 | return Result; |
| 2115 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2116 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2117 | // Check the predefines buffers. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2118 | if (!DisableValidation && CheckPredefinesBuffers()) |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2119 | return IgnorePCH; |
| 2120 | |
| 2121 | if (PP) { |
| 2122 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2123 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2124 | // loaded into the IdentifierTable before we intercepted the |
| 2125 | // creation of identifiers. Iterate through the list of known |
| 2126 | // identifiers and determine whether we have to establish |
| 2127 | // preprocessor definitions or top-level identifier declaration |
| 2128 | // chains for those identifiers. |
| 2129 | // |
| 2130 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2131 | // since de-serializing declarations or macro definitions can add |
| 2132 | // new entries into the identifier table, invalidating the |
| 2133 | // iterators. |
| 2134 | llvm::SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2135 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2136 | IdEnd = PP->getIdentifierTable().end(); |
| 2137 | Id != IdEnd; ++Id) |
| 2138 | Identifiers.push_back(Id->second); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2139 | // We need to search the tables in all files. |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2140 | for (unsigned J = 0, M = Chain.size(); J != M; ++J) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2141 | ASTIdentifierLookupTable *IdTable |
| 2142 | = (ASTIdentifierLookupTable *)Chain[J]->IdentifierLookupTable; |
| 2143 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2144 | // ones. |
| 2145 | if (!IdTable) |
| 2146 | continue; |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2147 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2148 | IdentifierInfo *II = Identifiers[I]; |
| 2149 | // Look in the on-disk hash tables for an entry for this identifier |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2150 | ASTIdentifierLookupTrait Info(*this, *Chain[J], II); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2151 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2152 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2153 | if (Pos == IdTable->end()) |
| 2154 | continue; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2155 | |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2156 | // Dereferencing the iterator has the effect of populating the |
| 2157 | // IdentifierInfo node with the various declarations it needs. |
| 2158 | (void)*Pos; |
| 2159 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | if (Context) |
| 2164 | InitializeContext(*Context); |
| 2165 | |
| 2166 | return Success; |
| 2167 | } |
| 2168 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2169 | ASTReader::ASTReadResult ASTReader::ReadASTCore(llvm::StringRef FileName, |
| 2170 | ASTFileType Type) { |
Sebastian Redl | 3f6b753 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2171 | PerFileData *Prev = Chain.empty() ? 0 : Chain.back(); |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2172 | Chain.push_back(new PerFileData(Type)); |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2173 | PerFileData &F = *Chain.back(); |
Sebastian Redl | 3f6b753 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 2174 | if (Prev) |
| 2175 | Prev->NextInSource = &F; |
| 2176 | else |
| 2177 | FirstInSource = &F; |
| 2178 | F.Loaders.push_back(Prev); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2179 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2180 | // Set the AST file name. |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2181 | F.FileName = FileName; |
| 2182 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2183 | // Open the AST file. |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2184 | // |
| 2185 | // FIXME: This shouldn't be here, we should just take a raw_ostream. |
| 2186 | std::string ErrStr; |
| 2187 | F.Buffer.reset(llvm::MemoryBuffer::getFileOrSTDIN(FileName, &ErrStr)); |
| 2188 | if (!F.Buffer) { |
| 2189 | Error(ErrStr.c_str()); |
| 2190 | return IgnorePCH; |
| 2191 | } |
| 2192 | |
| 2193 | // Initialize the stream |
| 2194 | F.StreamFile.init((const unsigned char *)F.Buffer->getBufferStart(), |
| 2195 | (const unsigned char *)F.Buffer->getBufferEnd()); |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2196 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2197 | Stream.init(F.StreamFile); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2198 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2199 | |
| 2200 | // Sniff for the signature. |
| 2201 | if (Stream.Read(8) != 'C' || |
| 2202 | Stream.Read(8) != 'P' || |
| 2203 | Stream.Read(8) != 'C' || |
| 2204 | Stream.Read(8) != 'H') { |
| 2205 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2206 | return Failure; |
| 2207 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2208 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2209 | while (!Stream.AtEndOfStream()) { |
| 2210 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2211 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2212 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2213 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2214 | return Failure; |
| 2215 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2216 | |
| 2217 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2218 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2219 | // We only know the AST subblock ID. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2220 | switch (BlockID) { |
| 2221 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2222 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2223 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2224 | return Failure; |
| 2225 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2226 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2227 | case AST_BLOCK_ID: |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2228 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2229 | case Success: |
| 2230 | break; |
| 2231 | |
| 2232 | case Failure: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2233 | return Failure; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2234 | |
| 2235 | case IgnorePCH: |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2236 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2237 | // AST block, skipping subblocks, to see if there are other |
| 2238 | // AST blocks elsewhere. |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2239 | |
| 2240 | // Clear out any preallocated source location entries, so that |
| 2241 | // the source manager does not try to resolve them later. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2242 | SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2243 | |
| 2244 | // Remove the stat cache. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2245 | if (F.StatCache) |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2246 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2247 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2248 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2249 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2250 | break; |
| 2251 | default: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2252 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2253 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2254 | return Failure; |
| 2255 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2256 | break; |
| 2257 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2260 | return Success; |
| 2261 | } |
| 2262 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2263 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2264 | PP = &pp; |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2265 | |
| 2266 | unsigned TotalNum = 0; |
| 2267 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) |
| 2268 | TotalNum += Chain[I]->NumPreallocatedPreprocessingEntities; |
| 2269 | if (TotalNum) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2270 | if (!PP->getPreprocessingRecord()) |
| 2271 | PP->createPreprocessingRecord(); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2272 | PP->getPreprocessingRecord()->SetExternalSource(*this, TotalNum); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2276 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2277 | Context = &Ctx; |
| 2278 | assert(Context && "Passed null context!"); |
| 2279 | |
| 2280 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2281 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
| 2282 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2283 | PP->setExternalSource(this); |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2284 | |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2285 | // If we have an update block for the TU waiting, we have to add it before |
| 2286 | // deserializing the decl. |
| 2287 | DeclContextOffsetsMap::iterator DCU = DeclContextOffsets.find(0); |
| 2288 | if (DCU != DeclContextOffsets.end()) { |
| 2289 | // Insertion could invalidate map, so grab vector. |
| 2290 | DeclContextInfos T; |
| 2291 | T.swap(DCU->second); |
| 2292 | DeclContextOffsets.erase(DCU); |
| 2293 | DeclContextOffsets[Ctx.getTranslationUnitDecl()].swap(T); |
| 2294 | } |
| 2295 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2296 | // Load the translation unit declaration |
Argyrios Kyrtzidis | 7e8996c | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 2297 | GetTranslationUnitDecl(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2298 | |
| 2299 | // Load the special types. |
| 2300 | Context->setBuiltinVaListType( |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2301 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
| 2302 | if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2303 | Context->setObjCIdType(GetType(Id)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2304 | if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2305 | Context->setObjCSelType(GetType(Sel)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2306 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2307 | Context->setObjCProtoType(GetType(Proto)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2308 | if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2309 | Context->setObjCClassType(GetType(Class)); |
Steve Naroff | 7cae42b | 2009-07-10 23:34:53 +0000 | [diff] [blame] | 2310 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2311 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2312 | Context->setCFConstantStringType(GetType(String)); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2313 | if (unsigned FastEnum |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2314 | = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2315 | Context->setObjCFastEnumerationStateType(GetType(FastEnum)); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2316 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2317 | QualType FileType = GetType(File); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2318 | if (FileType.isNull()) { |
| 2319 | Error("FILE type is NULL"); |
| 2320 | return; |
| 2321 | } |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2322 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2323 | Context->setFILEDecl(Typedef->getDecl()); |
| 2324 | else { |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2325 | const TagType *Tag = FileType->getAs<TagType>(); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2326 | if (!Tag) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2327 | Error("Invalid FILE type in AST file"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2328 | return; |
| 2329 | } |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2330 | Context->setFILEDecl(Tag->getDecl()); |
| 2331 | } |
| 2332 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2333 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2334 | QualType Jmp_bufType = GetType(Jmp_buf); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2335 | if (Jmp_bufType.isNull()) { |
| 2336 | Error("jmp_bug type is NULL"); |
| 2337 | return; |
| 2338 | } |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2339 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2340 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2341 | else { |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2342 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2343 | if (!Tag) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2344 | Error("Invalid jmp_buf type in AST file"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2345 | return; |
| 2346 | } |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2347 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2348 | } |
| 2349 | } |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2350 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2351 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2352 | if (Sigjmp_bufType.isNull()) { |
| 2353 | Error("sigjmp_buf type is NULL"); |
| 2354 | return; |
| 2355 | } |
John McCall | 9dd450b | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2356 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2357 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2358 | else { |
Ted Kremenek | c23c7e6 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 2359 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2360 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2361 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2362 | } |
| 2363 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2364 | if (unsigned ObjCIdRedef |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2365 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) |
Douglas Gregor | a8eed7d | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2366 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2367 | if (unsigned ObjCClassRedef |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2368 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) |
Douglas Gregor | a8eed7d | 2009-08-21 00:27:50 +0000 | [diff] [blame] | 2369 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2370 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_BLOCK_DESCRIPTOR]) |
Mike Stump | d015328 | 2009-10-20 02:12:22 +0000 | [diff] [blame] | 2371 | Context->setBlockDescriptorType(GetType(String)); |
Mike Stump | e1b19ba | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2372 | if (unsigned String |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2373 | = SpecialTypes[SPECIAL_TYPE_BLOCK_EXTENDED_DESCRIPTOR]) |
Mike Stump | e1b19ba | 2009-10-22 00:49:09 +0000 | [diff] [blame] | 2374 | Context->setBlockDescriptorExtendedType(GetType(String)); |
Fariborz Jahanian | e804c28 | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2375 | if (unsigned ObjCSelRedef |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2376 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) |
Fariborz Jahanian | e804c28 | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2377 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2378 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_NS_CONSTANT_STRING]) |
Fariborz Jahanian | e804c28 | 2010-04-23 17:41:07 +0000 | [diff] [blame] | 2379 | Context->setNSConstantStringType(GetType(String)); |
Argyrios Kyrtzidis | e862cbc | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2380 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2381 | if (SpecialTypes[SPECIAL_TYPE_INT128_INSTALLED]) |
Argyrios Kyrtzidis | e862cbc | 2010-07-04 21:44:19 +0000 | [diff] [blame] | 2382 | Context->setInt128Installed(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2385 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2386 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2387 | /// file. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2388 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2389 | Diagnostic &Diags) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2390 | // Open the AST file. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2391 | std::string ErrStr; |
| 2392 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2393 | Buffer.reset(llvm::MemoryBuffer::getFile(ASTFileName.c_str(), &ErrStr)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2394 | if (!Buffer) { |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2395 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2396 | return std::string(); |
| 2397 | } |
| 2398 | |
| 2399 | // Initialize the stream |
| 2400 | llvm::BitstreamReader StreamFile; |
| 2401 | llvm::BitstreamCursor Stream; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2402 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2403 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2404 | Stream.init(StreamFile); |
| 2405 | |
| 2406 | // Sniff for the signature. |
| 2407 | if (Stream.Read(8) != 'C' || |
| 2408 | Stream.Read(8) != 'P' || |
| 2409 | Stream.Read(8) != 'C' || |
| 2410 | Stream.Read(8) != 'H') { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2411 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2412 | return std::string(); |
| 2413 | } |
| 2414 | |
| 2415 | RecordData Record; |
| 2416 | while (!Stream.AtEndOfStream()) { |
| 2417 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2418 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2419 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2420 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2421 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2422 | // We only know the AST subblock ID. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2423 | switch (BlockID) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2424 | case AST_BLOCK_ID: |
| 2425 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2426 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2427 | return std::string(); |
| 2428 | } |
| 2429 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2430 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2431 | default: |
| 2432 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2433 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2434 | return std::string(); |
| 2435 | } |
| 2436 | break; |
| 2437 | } |
| 2438 | continue; |
| 2439 | } |
| 2440 | |
| 2441 | if (Code == llvm::bitc::END_BLOCK) { |
| 2442 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2443 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2444 | return std::string(); |
| 2445 | } |
| 2446 | continue; |
| 2447 | } |
| 2448 | |
| 2449 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2450 | Stream.ReadAbbrevRecord(); |
| 2451 | continue; |
| 2452 | } |
| 2453 | |
| 2454 | Record.clear(); |
| 2455 | const char *BlobStart = 0; |
| 2456 | unsigned BlobLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2457 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2458 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2459 | return std::string(BlobStart, BlobLen); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2460 | } |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2461 | |
| 2462 | return std::string(); |
| 2463 | } |
| 2464 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2465 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2466 | /// structure. |
| 2467 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2468 | /// This routine parses the language options from the AST file and then gives |
| 2469 | /// them to the AST listener if one is set. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2470 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2471 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2472 | bool ASTReader::ParseLanguageOptions( |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2473 | const llvm::SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2474 | if (Listener) { |
| 2475 | LangOptions LangOpts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2476 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2477 | #define PARSE_LANGOPT(Option) \ |
| 2478 | LangOpts.Option = Record[Idx]; \ |
| 2479 | ++Idx |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2480 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2481 | unsigned Idx = 0; |
| 2482 | PARSE_LANGOPT(Trigraphs); |
| 2483 | PARSE_LANGOPT(BCPLComment); |
| 2484 | PARSE_LANGOPT(DollarIdents); |
| 2485 | PARSE_LANGOPT(AsmPreprocessor); |
| 2486 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 2487 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2488 | PARSE_LANGOPT(ImplicitInt); |
| 2489 | PARSE_LANGOPT(Digraphs); |
| 2490 | PARSE_LANGOPT(HexFloats); |
| 2491 | PARSE_LANGOPT(C99); |
| 2492 | PARSE_LANGOPT(Microsoft); |
| 2493 | PARSE_LANGOPT(CPlusPlus); |
| 2494 | PARSE_LANGOPT(CPlusPlus0x); |
| 2495 | PARSE_LANGOPT(CXXOperatorNames); |
| 2496 | PARSE_LANGOPT(ObjC1); |
| 2497 | PARSE_LANGOPT(ObjC2); |
| 2498 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 2499 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 2500 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2501 | PARSE_LANGOPT(PascalStrings); |
| 2502 | PARSE_LANGOPT(WritableStrings); |
| 2503 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2504 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2505 | PARSE_LANGOPT(Exceptions); |
Daniel Dunbar | 925152c | 2010-02-10 18:48:44 +0000 | [diff] [blame] | 2506 | PARSE_LANGOPT(SjLjExceptions); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2507 | PARSE_LANGOPT(NeXTRuntime); |
| 2508 | PARSE_LANGOPT(Freestanding); |
| 2509 | PARSE_LANGOPT(NoBuiltin); |
| 2510 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 2511 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2512 | PARSE_LANGOPT(Blocks); |
| 2513 | PARSE_LANGOPT(EmitAllDecls); |
| 2514 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2515 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 2516 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2517 | PARSE_LANGOPT(HeinousExtensions); |
| 2518 | PARSE_LANGOPT(Optimize); |
| 2519 | PARSE_LANGOPT(OptimizeSize); |
| 2520 | PARSE_LANGOPT(Static); |
| 2521 | PARSE_LANGOPT(PICLevel); |
| 2522 | PARSE_LANGOPT(GNUInline); |
| 2523 | PARSE_LANGOPT(NoInline); |
| 2524 | PARSE_LANGOPT(AccessControl); |
| 2525 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 2526 | PARSE_LANGOPT(ShortWChar); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2527 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
| 2528 | LangOpts.setVisibilityMode((LangOptions::VisibilityMode)Record[Idx++]); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 2529 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 2530 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2531 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 2532 | PARSE_LANGOPT(OpenCL); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 2533 | PARSE_LANGOPT(CatchUndefined); |
| 2534 | // FIXME: Missing ElideConstructors?! |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2535 | #undef PARSE_LANGOPT |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2536 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2537 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2538 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2539 | |
| 2540 | return false; |
| 2541 | } |
| 2542 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2543 | void ASTReader::ReadPreprocessedEntities() { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2544 | ReadDefinedMacros(); |
| 2545 | } |
| 2546 | |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2547 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2548 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2549 | PerFileData *F = 0; |
| 2550 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 2551 | F = Chain[N - I - 1]; |
| 2552 | if (Index < F->LocalNumTypes) |
| 2553 | break; |
| 2554 | Index -= F->LocalNumTypes; |
| 2555 | } |
| 2556 | assert(F && F->LocalNumTypes > Index && "Broken chain"); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2557 | return RecordLocation(F, F->TypeOffsets[Index]); |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2561 | /// |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2562 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 2563 | /// routine actually reads the record corresponding to the type at the given |
| 2564 | /// location. It is a helper routine for GetType, which deals with reading type |
| 2565 | /// IDs. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2566 | QualType ASTReader::ReadTypeRecord(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 2567 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2568 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2569 | |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2570 | // Keep track of where we are in the stream, then jump back there |
| 2571 | // after reading this type. |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2572 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2573 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 2574 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 2575 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 2576 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 2577 | Deserializing AType(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2578 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2579 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2580 | RecordData Record; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2581 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2582 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 2583 | case TYPE_EXT_QUAL: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2584 | if (Record.size() != 2) { |
| 2585 | Error("Incorrect encoding of extended qualifier type"); |
| 2586 | return QualType(); |
| 2587 | } |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2588 | QualType Base = GetType(Record[0]); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2589 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[1]); |
| 2590 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 2591 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2592 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2593 | case TYPE_COMPLEX: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2594 | if (Record.size() != 1) { |
| 2595 | Error("Incorrect encoding of complex type"); |
| 2596 | return QualType(); |
| 2597 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2598 | QualType ElemType = GetType(Record[0]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2599 | return Context->getComplexType(ElemType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2602 | case TYPE_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2603 | if (Record.size() != 1) { |
| 2604 | Error("Incorrect encoding of pointer type"); |
| 2605 | return QualType(); |
| 2606 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2607 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2608 | return Context->getPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2611 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2612 | if (Record.size() != 1) { |
| 2613 | Error("Incorrect encoding of block pointer type"); |
| 2614 | return QualType(); |
| 2615 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2616 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2617 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2620 | case TYPE_LVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2621 | if (Record.size() != 1) { |
| 2622 | Error("Incorrect encoding of lvalue reference type"); |
| 2623 | return QualType(); |
| 2624 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2625 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2626 | return Context->getLValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2629 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2630 | if (Record.size() != 1) { |
| 2631 | Error("Incorrect encoding of rvalue reference type"); |
| 2632 | return QualType(); |
| 2633 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2634 | QualType PointeeType = GetType(Record[0]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2635 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2638 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | ee776bc | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 2639 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2640 | Error("Incorrect encoding of member pointer type"); |
| 2641 | return QualType(); |
| 2642 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2643 | QualType PointeeType = GetType(Record[0]); |
| 2644 | QualType ClassType = GetType(Record[1]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2645 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2648 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2649 | QualType ElementType = GetType(Record[0]); |
| 2650 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2651 | unsigned IndexTypeQuals = Record[2]; |
| 2652 | unsigned Idx = 3; |
| 2653 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2654 | return Context->getConstantArrayType(ElementType, Size, |
| 2655 | ASM, IndexTypeQuals); |
| 2656 | } |
| 2657 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2658 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2659 | QualType ElementType = GetType(Record[0]); |
| 2660 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2661 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2662 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2665 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 2666 | QualType ElementType = GetType(Record[0]); |
| 2667 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 2668 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2669 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 2670 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 2671 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 2672 | ASM, IndexTypeQuals, |
| 2673 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2676 | case TYPE_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2677 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2678 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2679 | return QualType(); |
| 2680 | } |
| 2681 | |
| 2682 | QualType ElementType = GetType(Record[0]); |
| 2683 | unsigned NumElements = Record[1]; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2684 | unsigned AltiVecSpec = Record[2]; |
| 2685 | return Context->getVectorType(ElementType, NumElements, |
| 2686 | (VectorType::AltiVecSpecific)AltiVecSpec); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2689 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 2690 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2691 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2692 | return QualType(); |
| 2693 | } |
| 2694 | |
| 2695 | QualType ElementType = GetType(Record[0]); |
| 2696 | unsigned NumElements = Record[1]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2697 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2698 | } |
| 2699 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2700 | case TYPE_FUNCTION_NO_PROTO: { |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2701 | if (Record.size() != 4) { |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 2702 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2703 | return QualType(); |
| 2704 | } |
| 2705 | QualType ResultType = GetType(Record[0]); |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2706 | FunctionType::ExtInfo Info(Record[1], Record[2], (CallingConv)Record[3]); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2707 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2710 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2711 | QualType ResultType = GetType(Record[0]); |
Douglas Gregor | dc72875 | 2009-12-22 18:11:50 +0000 | [diff] [blame] | 2712 | bool NoReturn = Record[1]; |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2713 | unsigned RegParm = Record[2]; |
| 2714 | CallingConv CallConv = (CallingConv)Record[3]; |
| 2715 | unsigned Idx = 4; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2716 | unsigned NumParams = Record[Idx++]; |
| 2717 | llvm::SmallVector<QualType, 16> ParamTypes; |
| 2718 | for (unsigned I = 0; I != NumParams; ++I) |
| 2719 | ParamTypes.push_back(GetType(Record[Idx++])); |
| 2720 | bool isVariadic = Record[Idx++]; |
| 2721 | unsigned Quals = Record[Idx++]; |
Sebastian Redl | 5068f77ac | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2722 | bool hasExceptionSpec = Record[Idx++]; |
| 2723 | bool hasAnyExceptionSpec = Record[Idx++]; |
| 2724 | unsigned NumExceptions = Record[Idx++]; |
| 2725 | llvm::SmallVector<QualType, 2> Exceptions; |
| 2726 | for (unsigned I = 0; I != NumExceptions; ++I) |
| 2727 | Exceptions.push_back(GetType(Record[Idx++])); |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2728 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
Sebastian Redl | 5068f77ac | 2009-05-27 22:11:52 +0000 | [diff] [blame] | 2729 | isVariadic, Quals, hasExceptionSpec, |
| 2730 | hasAnyExceptionSpec, NumExceptions, |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 2731 | Exceptions.data(), |
Rafael Espindola | 49b85ab | 2010-03-30 22:15:11 +0000 | [diff] [blame] | 2732 | FunctionType::ExtInfo(NoReturn, RegParm, |
| 2733 | CallConv)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2734 | } |
| 2735 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2736 | case TYPE_UNRESOLVED_USING: |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 2737 | return Context->getTypeDeclType( |
| 2738 | cast<UnresolvedUsingTypenameDecl>(GetDecl(Record[0]))); |
| 2739 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2740 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2741 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2742 | Error("incorrect encoding of typedef type"); |
| 2743 | return QualType(); |
| 2744 | } |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2745 | TypedefDecl *Decl = cast<TypedefDecl>(GetDecl(Record[0])); |
| 2746 | QualType Canonical = GetType(Record[1]); |
| 2747 | return Context->getTypedefType(Decl, Canonical); |
| 2748 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2749 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2750 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2751 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2752 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2753 | case TYPE_TYPEOF: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2754 | if (Record.size() != 1) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2755 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2756 | return QualType(); |
| 2757 | } |
| 2758 | QualType UnderlyingType = GetType(Record[0]); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 2759 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2760 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2761 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2762 | case TYPE_DECLTYPE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2763 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 2764 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2765 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2766 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2767 | Error("incorrect encoding of record type"); |
| 2768 | return QualType(); |
| 2769 | } |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2770 | bool IsDependent = Record[0]; |
| 2771 | QualType T = Context->getRecordType(cast<RecordDecl>(GetDecl(Record[1]))); |
John McCall | 25c9d11 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2772 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2773 | return T; |
| 2774 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2775 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2776 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2777 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2778 | Error("incorrect encoding of enum type"); |
| 2779 | return QualType(); |
| 2780 | } |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2781 | bool IsDependent = Record[0]; |
| 2782 | QualType T = Context->getEnumType(cast<EnumDecl>(GetDecl(Record[1]))); |
John McCall | 25c9d11 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2783 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2784 | return T; |
| 2785 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 2786 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2787 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2788 | unsigned Idx = 0; |
| 2789 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2790 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2791 | QualType NamedType = GetType(Record[Idx++]); |
| 2792 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 2793 | } |
| 2794 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2795 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2796 | unsigned Idx = 0; |
| 2797 | ObjCInterfaceDecl *ItfD = cast<ObjCInterfaceDecl>(GetDecl(Record[Idx++])); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2798 | return Context->getObjCInterfaceType(ItfD); |
| 2799 | } |
| 2800 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2801 | case TYPE_OBJC_OBJECT: { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2802 | unsigned Idx = 0; |
| 2803 | QualType Base = GetType(Record[Idx++]); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2804 | unsigned NumProtos = Record[Idx++]; |
| 2805 | llvm::SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 2806 | for (unsigned I = 0; I != NumProtos; ++I) |
| 2807 | Protos.push_back(cast<ObjCProtocolDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 2808 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 2809 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 2810 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2811 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2812 | unsigned Idx = 0; |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 2813 | QualType Pointee = GetType(Record[Idx++]); |
| 2814 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 2815 | } |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 2816 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2817 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 2818 | unsigned Idx = 0; |
| 2819 | QualType Parm = GetType(Record[Idx++]); |
| 2820 | QualType Replacement = GetType(Record[Idx++]); |
| 2821 | return |
| 2822 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 2823 | Replacement); |
| 2824 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2825 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2826 | case TYPE_INJECTED_CLASS_NAME: { |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2827 | CXXRecordDecl *D = cast<CXXRecordDecl>(GetDecl(Record[0])); |
| 2828 | QualType TST = GetType(Record[1]); // probably derivable |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2829 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2830 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 2831 | return |
| 2832 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 2833 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 2834 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2835 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2836 | unsigned Idx = 0; |
| 2837 | unsigned Depth = Record[Idx++]; |
| 2838 | unsigned Index = Record[Idx++]; |
| 2839 | bool Pack = Record[Idx++]; |
| 2840 | IdentifierInfo *Name = GetIdentifierInfo(Record, Idx); |
| 2841 | return Context->getTemplateTypeParmType(Depth, Index, Pack, Name); |
| 2842 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 2843 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2844 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2845 | unsigned Idx = 0; |
| 2846 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2847 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2848 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 2849 | QualType Canon = GetType(Record[Idx++]); |
| 2850 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 2851 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 2852 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2853 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2854 | unsigned Idx = 0; |
| 2855 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 2856 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 2857 | const IdentifierInfo *Name = this->GetIdentifierInfo(Record, Idx); |
| 2858 | unsigned NumArgs = Record[Idx++]; |
| 2859 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 2860 | Args.reserve(NumArgs); |
| 2861 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2862 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 2863 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 2864 | Args.size(), Args.data()); |
| 2865 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 2866 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2867 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2868 | unsigned Idx = 0; |
| 2869 | |
| 2870 | // ArrayType |
| 2871 | QualType ElementType = GetType(Record[Idx++]); |
| 2872 | ArrayType::ArraySizeModifier ASM |
| 2873 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 2874 | unsigned IndexTypeQuals = Record[Idx++]; |
| 2875 | |
| 2876 | // DependentSizedArrayType |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2877 | Expr *NumElts = ReadExpr(*Loc.F); |
| 2878 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 2879 | |
| 2880 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 2881 | IndexTypeQuals, Brackets); |
| 2882 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 2883 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2884 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2885 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2886 | bool IsDependent = Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2887 | TemplateName Name = ReadTemplateName(Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2888 | llvm::SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2889 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2890 | QualType Canon = GetType(Record[Idx++]); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2891 | QualType T; |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2892 | if (Canon.isNull()) |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2893 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 2894 | Args.size()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 2895 | else |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2896 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
| 2897 | Args.size(), Canon); |
John McCall | 25c9d11 | 2010-10-14 21:48:26 +0000 | [diff] [blame] | 2898 | T->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 2899 | return T; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2900 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2901 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2902 | // Suppress a GCC warning |
| 2903 | return QualType(); |
| 2904 | } |
| 2905 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2906 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2907 | ASTReader &Reader; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2908 | ASTReader::PerFileData &F; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 2909 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2910 | const ASTReader::RecordData &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2911 | unsigned &Idx; |
| 2912 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2913 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 2914 | unsigned &I) { |
| 2915 | return Reader.ReadSourceLocation(F, R, I); |
| 2916 | } |
| 2917 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2918 | public: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2919 | TypeLocReader(ASTReader &Reader, ASTReader::PerFileData &F, |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2920 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2921 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 2922 | { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2923 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2924 | // We want compile-time assurance that we've enumerated all of |
| 2925 | // these, so unfortunately we have to declare them first, then |
| 2926 | // define them out-of-line. |
| 2927 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2928 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2929 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2930 | #include "clang/AST/TypeLocNodes.def" |
| 2931 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2932 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 2933 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2934 | }; |
| 2935 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2936 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2937 | // nothing to do |
| 2938 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2939 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2940 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 2941 | if (TL.needsExtraLocalData()) { |
| 2942 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 2943 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 2944 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 2945 | TL.setModeAttr(Record[Idx++]); |
| 2946 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2947 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2948 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2949 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2950 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2951 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2952 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2953 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2954 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2955 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2956 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2957 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2958 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2959 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2960 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2961 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2962 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2963 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2964 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2965 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2966 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2967 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 2968 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 2969 | if (Record[Idx++]) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2970 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 2971 | else |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2972 | TL.setSizeExpr(0); |
| 2973 | } |
| 2974 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 2975 | VisitArrayTypeLoc(TL); |
| 2976 | } |
| 2977 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 2978 | VisitArrayTypeLoc(TL); |
| 2979 | } |
| 2980 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 2981 | VisitArrayTypeLoc(TL); |
| 2982 | } |
| 2983 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 2984 | DependentSizedArrayTypeLoc TL) { |
| 2985 | VisitArrayTypeLoc(TL); |
| 2986 | } |
| 2987 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 2988 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2989 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2990 | } |
| 2991 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2992 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2993 | } |
| 2994 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2995 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 2996 | } |
| 2997 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2998 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 2999 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3000 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3001 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
John McCall | e634700 | 2009-10-23 01:28:53 +0000 | [diff] [blame] | 3002 | TL.setArg(i, cast_or_null<ParmVarDecl>(Reader.GetDecl(Record[Idx++]))); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3006 | VisitFunctionTypeLoc(TL); |
| 3007 | } |
| 3008 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3009 | VisitFunctionTypeLoc(TL); |
| 3010 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3011 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3012 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3013 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3014 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3015 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3016 | } |
| 3017 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3018 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3019 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3020 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3021 | } |
| 3022 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3023 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3024 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3025 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3026 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3027 | } |
| 3028 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3029 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3030 | } |
| 3031 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3032 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3033 | } |
| 3034 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3035 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3036 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3037 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3038 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3039 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3040 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3041 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3042 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3043 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3044 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3045 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3046 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3047 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3048 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3049 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3050 | TL.setArgLocInfo(i, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3051 | Reader.GetTemplateArgumentLocInfo(F, |
| 3052 | TL.getTypePtr()->getArg(i).getKind(), |
| 3053 | Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3054 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3055 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3056 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3057 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3058 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3059 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3060 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3061 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3062 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3063 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3064 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3065 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3066 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3067 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3068 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3069 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
| 3070 | TL.setQualifierRange(Reader.ReadSourceRange(F, Record, Idx)); |
| 3071 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3072 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3073 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3074 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3075 | TL.setArgLocInfo(I, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3076 | Reader.GetTemplateArgumentLocInfo(F, |
| 3077 | TL.getTypePtr()->getArg(I).getKind(), |
| 3078 | Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3079 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3080 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3081 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3082 | } |
| 3083 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3084 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3085 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3086 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3087 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3088 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3089 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3090 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3091 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3092 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3093 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3094 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(PerFileData &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3095 | const RecordData &Record, |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3096 | unsigned &Idx) { |
| 3097 | QualType InfoTy = GetType(Record[Idx++]); |
| 3098 | if (InfoTy.isNull()) |
| 3099 | return 0; |
| 3100 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3101 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3102 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3103 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3104 | TLR.Visit(TL); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3105 | return TInfo; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3106 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3107 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3108 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3109 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3110 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3111 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3112 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3113 | QualType T; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3114 | switch ((PredefinedTypeIDs)Index) { |
| 3115 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3116 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3117 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3118 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3119 | case PREDEF_TYPE_CHAR_U_ID: |
| 3120 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3121 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3122 | T = Context->CharTy; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3123 | break; |
| 3124 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3125 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3126 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3127 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3128 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3129 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3130 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3131 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3132 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3133 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3134 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3135 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3136 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3137 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3138 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3139 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3140 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3141 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
| 3142 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
| 3143 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3144 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3145 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3146 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3147 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3148 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3149 | } |
| 3150 | |
| 3151 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3152 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3155 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3156 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3157 | if (TypesLoaded[Index].isNull()) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3158 | TypesLoaded[Index] = ReadTypeRecord(Index); |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3159 | if (TypesLoaded[Index].isNull()) |
| 3160 | return QualType(); |
| 3161 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3162 | TypesLoaded[Index]->setFromAST(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3163 | TypeIdxs[TypesLoaded[Index]] = TypeIdx::fromTypeID(ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3164 | if (DeserializationListener) |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3165 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3166 | TypesLoaded[Index]); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3168 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3169 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3172 | TypeID ASTReader::GetTypeID(QualType T) const { |
| 3173 | return MakeTypeID(T, |
| 3174 | std::bind1st(std::mem_fun(&ASTReader::GetTypeIdx), this)); |
| 3175 | } |
| 3176 | |
| 3177 | TypeIdx ASTReader::GetTypeIdx(QualType T) const { |
| 3178 | if (T.isNull()) |
| 3179 | return TypeIdx(); |
| 3180 | assert(!T.getLocalFastQualifiers()); |
| 3181 | |
| 3182 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); |
| 3183 | // GetTypeIdx is mostly used for computing the hash of DeclarationNames and |
| 3184 | // comparing keys of ASTDeclContextNameLookupTable. |
| 3185 | // If the type didn't come from the AST file use a specially marked index |
| 3186 | // so that any hash/key comparison fail since no such index is stored |
| 3187 | // in a AST file. |
| 3188 | if (I == TypeIdxs.end()) |
| 3189 | return TypeIdx(-1); |
| 3190 | return I->second; |
| 3191 | } |
| 3192 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3193 | TemplateArgumentLocInfo |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3194 | ASTReader::GetTemplateArgumentLocInfo(PerFileData &F, |
| 3195 | TemplateArgument::ArgKind Kind, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3196 | const RecordData &Record, |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3197 | unsigned &Index) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3198 | switch (Kind) { |
| 3199 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3200 | return ReadExpr(F); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3201 | case TemplateArgument::Type: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3202 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3203 | case TemplateArgument::Template: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3204 | SourceRange QualifierRange = ReadSourceRange(F, Record, Index); |
| 3205 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3206 | return TemplateArgumentLocInfo(QualifierRange, TemplateNameLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3207 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3208 | case TemplateArgument::Null: |
| 3209 | case TemplateArgument::Integral: |
| 3210 | case TemplateArgument::Declaration: |
| 3211 | case TemplateArgument::Pack: |
| 3212 | return TemplateArgumentLocInfo(); |
| 3213 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3214 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3215 | return TemplateArgumentLocInfo(); |
| 3216 | } |
| 3217 | |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3218 | TemplateArgumentLoc |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3219 | ASTReader::ReadTemplateArgumentLoc(PerFileData &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3220 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3221 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3222 | |
| 3223 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 3224 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 3225 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 3226 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3227 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3228 | Record, Index)); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3231 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3232 | return GetDecl(ID); |
| 3233 | } |
| 3234 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3235 | TranslationUnitDecl *ASTReader::GetTranslationUnitDecl() { |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3236 | if (!DeclsLoaded[0]) { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 3237 | ReadDeclRecord(0, 1); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3238 | if (DeserializationListener) |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3239 | DeserializationListener->DeclRead(1, DeclsLoaded[0]); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3240 | } |
Argyrios Kyrtzidis | 7e8996c | 2010-07-08 17:13:02 +0000 | [diff] [blame] | 3241 | |
| 3242 | return cast<TranslationUnitDecl>(DeclsLoaded[0]); |
| 3243 | } |
| 3244 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3245 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3246 | if (ID == 0) |
| 3247 | return 0; |
| 3248 | |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3249 | if (ID > DeclsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3250 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3251 | return 0; |
| 3252 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3253 | |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3254 | unsigned Index = ID - 1; |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3255 | if (!DeclsLoaded[Index]) { |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 3256 | ReadDeclRecord(Index, ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3257 | if (DeserializationListener) |
| 3258 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 3259 | } |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3260 | |
| 3261 | return DeclsLoaded[Index]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 3264 | /// \brief Resolve the offset of a statement into a statement. |
| 3265 | /// |
| 3266 | /// This operation will read a new statement from the external |
| 3267 | /// source each time it is called, and is meant to be used via a |
| 3268 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3269 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3270 | // Offset here is a global offset across the entire chain. |
| 3271 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3272 | PerFileData &F = *Chain[N - I - 1]; |
| 3273 | if (Offset < F.SizeInBits) { |
| 3274 | // Since we know that this statement is part of a decl, make sure to use |
| 3275 | // the decl cursor to read it. |
| 3276 | F.DeclsCursor.JumpToBit(Offset); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3277 | return ReadStmtFromStream(F); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3278 | } |
| 3279 | Offset -= F.SizeInBits; |
| 3280 | } |
| 3281 | llvm_unreachable("Broken chain"); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 3282 | } |
| 3283 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3284 | bool ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3285 | bool (*isKindWeWant)(Decl::Kind), |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3286 | llvm::SmallVectorImpl<Decl*> &Decls) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3287 | assert(DC->hasExternalLexicalStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3288 | "DeclContext has no lexical decls in storage"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3289 | |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3290 | // There might be lexical decls in multiple parts of the chain, for the TU |
| 3291 | // at least. |
Sebastian Redl | da6a21c | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3292 | // DeclContextOffsets might reallocate as we load additional decls below, |
| 3293 | // so make a copy of the vector. |
| 3294 | DeclContextInfos Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3295 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3296 | I != E; ++I) { |
Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 3297 | // IDs can be 0 if this context doesn't contain declarations. |
| 3298 | if (!I->LexicalDecls) |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3299 | continue; |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3300 | |
| 3301 | // Load all of the declaration IDs |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 3302 | for (const KindDeclIDPair *ID = I->LexicalDecls, |
| 3303 | *IDE = ID + I->NumLexicalDecls; ID != IDE; ++ID) { |
| 3304 | if (isKindWeWant && !isKindWeWant((Decl::Kind)ID->first)) |
| 3305 | continue; |
| 3306 | |
| 3307 | Decl *D = GetDecl(ID->second); |
Sebastian Redl | da6a21c | 2010-09-28 02:24:44 +0000 | [diff] [blame] | 3308 | assert(D && "Null decl in lexical decls"); |
| 3309 | Decls.push_back(D); |
| 3310 | } |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3311 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3312 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3313 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3314 | return false; |
| 3315 | } |
| 3316 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3317 | DeclContext::lookup_result |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3318 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3319 | DeclarationName Name) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3320 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3321 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3322 | if (!Name) |
| 3323 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 3324 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3325 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3326 | llvm::SmallVector<NamedDecl *, 64> Decls; |
Sebastian Redl | 471ac2f | 2010-08-24 00:49:55 +0000 | [diff] [blame] | 3327 | // There might be visible decls in multiple parts of the chain, for the TU |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3328 | // and namespaces. For any given name, the last available results replace |
| 3329 | // all earlier ones. For this reason, we walk in reverse. |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3330 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3331 | for (DeclContextInfos::reverse_iterator I = Infos.rbegin(), E = Infos.rend(); |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3332 | I != E; ++I) { |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3333 | if (!I->NameLookupTableData) |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3334 | continue; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3335 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3336 | ASTDeclContextNameLookupTable *LookupTable = |
| 3337 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3338 | ASTDeclContextNameLookupTable::iterator Pos = LookupTable->find(Name); |
| 3339 | if (Pos == LookupTable->end()) |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3340 | continue; |
| 3341 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3342 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 3343 | for (; Data.first != Data.second; ++Data.first) |
| 3344 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
Sebastian Redl | 9617e7e | 2010-08-24 00:50:16 +0000 | [diff] [blame] | 3345 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 3348 | ++NumVisibleDeclContextsRead; |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3349 | |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3350 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 3351 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3352 | } |
| 3353 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 3354 | void ASTReader::MaterializeVisibleDecls(const DeclContext *DC) { |
| 3355 | assert(DC->hasExternalVisibleStorage() && |
| 3356 | "DeclContext has no visible decls in storage"); |
| 3357 | |
| 3358 | llvm::SmallVector<NamedDecl *, 64> Decls; |
| 3359 | // There might be visible decls in multiple parts of the chain, for the TU |
| 3360 | // and namespaces. |
| 3361 | DeclContextInfos &Infos = DeclContextOffsets[DC]; |
| 3362 | for (DeclContextInfos::iterator I = Infos.begin(), E = Infos.end(); |
| 3363 | I != E; ++I) { |
| 3364 | if (!I->NameLookupTableData) |
| 3365 | continue; |
| 3366 | |
| 3367 | ASTDeclContextNameLookupTable *LookupTable = |
| 3368 | (ASTDeclContextNameLookupTable*)I->NameLookupTableData; |
| 3369 | for (ASTDeclContextNameLookupTable::item_iterator |
| 3370 | ItemI = LookupTable->item_begin(), |
| 3371 | ItemEnd = LookupTable->item_end() ; ItemI != ItemEnd; ++ItemI) { |
| 3372 | ASTDeclContextNameLookupTable::item_iterator::value_type Val |
| 3373 | = *ItemI; |
| 3374 | ASTDeclContextNameLookupTrait::data_type Data = Val.second; |
| 3375 | Decls.clear(); |
| 3376 | for (; Data.first != Data.second; ++Data.first) |
| 3377 | Decls.push_back(cast<NamedDecl>(GetDecl(*Data.first))); |
| 3378 | MaterializeVisibleDeclsForName(DC, Val.first, Decls); |
| 3379 | } |
| 3380 | } |
| 3381 | } |
| 3382 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3383 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3384 | assert(Consumer); |
| 3385 | while (!InterestingDecls.empty()) { |
| 3386 | DeclGroupRef DG(InterestingDecls.front()); |
| 3387 | InterestingDecls.pop_front(); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3388 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3389 | } |
| 3390 | } |
| 3391 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3392 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | b985eeb | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 3393 | this->Consumer = Consumer; |
| 3394 | |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3395 | if (!Consumer) |
| 3396 | return; |
| 3397 | |
| 3398 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3399 | // Force deserialization of this decl, which will cause it to be queued for |
| 3400 | // passing to the consumer. |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 3401 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3402 | } |
Douglas Gregor | f005eac | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 3403 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 3404 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3407 | void ASTReader::PrintStats() { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3408 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3409 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3410 | unsigned NumTypesLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3411 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3412 | QualType()); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3413 | unsigned NumDeclsLoaded |
| 3414 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 3415 | (Decl *)0); |
| 3416 | unsigned NumIdentifiersLoaded |
| 3417 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 3418 | IdentifiersLoaded.end(), |
| 3419 | (IdentifierInfo *)0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3420 | unsigned NumSelectorsLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3421 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 3422 | SelectorsLoaded.end(), |
| 3423 | Selector()); |
Douglas Gregor | c3b1dd1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 3424 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3425 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 3426 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3427 | if (TotalNumSLocEntries) |
| 3428 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 3429 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 3430 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3431 | if (!TypesLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3432 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3433 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 3434 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 3435 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3436 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 3437 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 3438 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3439 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3440 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3441 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 3442 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3443 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3444 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3445 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 3446 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3447 | if (TotalNumStatements) |
| 3448 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 3449 | NumStatementsRead, TotalNumStatements, |
| 3450 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 3451 | if (TotalNumMacros) |
| 3452 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 3453 | NumMacrosRead, TotalNumMacros, |
| 3454 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 3455 | if (TotalLexicalDeclContexts) |
| 3456 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 3457 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 3458 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 3459 | * 100)); |
| 3460 | if (TotalVisibleDeclContexts) |
| 3461 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 3462 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 3463 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 3464 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3465 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3466 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3467 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 3468 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3469 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3470 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3471 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3472 | std::fprintf(stderr, "\n"); |
| 3473 | } |
| 3474 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3475 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3476 | SemaObj = &S; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3477 | S.ExternalSource = this; |
| 3478 | |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3479 | // Makes sure any declarations that were deserialized "too early" |
| 3480 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3481 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 3482 | if (SemaObj->TUScope) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3483 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3484 | |
| 3485 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3486 | } |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 3487 | PreloadedDecls.clear(); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3488 | |
| 3489 | // If there were any tentative definitions, deserialize them and add |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3490 | // them to Sema's list of tentative definitions. |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3491 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 3492 | VarDecl *Var = cast<VarDecl>(GetDecl(TentativeDefinitions[I])); |
Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 3493 | SemaObj->TentativeDefinitions.push_back(Var); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 3494 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 3495 | |
Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 3496 | // If there were any unused file scoped decls, deserialize them and add to |
| 3497 | // Sema's list of unused file scoped decls. |
| 3498 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 3499 | DeclaratorDecl *D = cast<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 3500 | SemaObj->UnusedFileScopedDecls.push_back(D); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 3501 | } |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 3502 | |
| 3503 | // If there were any locally-scoped external declarations, |
| 3504 | // deserialize them and add them to Sema's table of locally-scoped |
| 3505 | // external declarations. |
| 3506 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 3507 | NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 3508 | SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D; |
| 3509 | } |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 3510 | |
| 3511 | // If there were any ext_vector type declarations, deserialize them |
| 3512 | // and add them to Sema's vector of such declarations. |
| 3513 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) |
| 3514 | SemaObj->ExtVectorDecls.push_back( |
| 3515 | cast<TypedefDecl>(GetDecl(ExtVectorDecls[I]))); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3516 | |
| 3517 | // FIXME: Do VTable uses and dynamic classes deserialize too much ? |
| 3518 | // Can we cut them down before writing them ? |
| 3519 | |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 3520 | // If there were any dynamic classes declarations, deserialize them |
| 3521 | // and add them to Sema's vector of such declarations. |
| 3522 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) |
| 3523 | SemaObj->DynamicClasses.push_back( |
| 3524 | cast<CXXRecordDecl>(GetDecl(DynamicClasses[I]))); |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3525 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 3526 | // Load the offsets of the declarations that Sema references. |
| 3527 | // They will be lazily deserialized when needed. |
| 3528 | if (!SemaDeclRefs.empty()) { |
| 3529 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
| 3530 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 3531 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
| 3532 | } |
| 3533 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3534 | for (PerFileData *F = FirstInSource; F; F = F->NextInSource) { |
| 3535 | |
| 3536 | // If there are @selector references added them to its pool. This is for |
| 3537 | // implementation of -Wselector. |
| 3538 | if (!F->ReferencedSelectorsData.empty()) { |
| 3539 | unsigned int DataSize = F->ReferencedSelectorsData.size()-1; |
| 3540 | unsigned I = 0; |
| 3541 | while (I < DataSize) { |
| 3542 | Selector Sel = DecodeSelector(F->ReferencedSelectorsData[I++]); |
| 3543 | SourceLocation SelLoc = ReadSourceLocation( |
| 3544 | *F, F->ReferencedSelectorsData, I); |
| 3545 | SemaObj->ReferencedSelectors.insert(std::make_pair(Sel, SelLoc)); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | // If there were any pending implicit instantiations, deserialize them |
| 3550 | // and add them to Sema's queue of such instantiations. |
| 3551 | assert(F->PendingInstantiations.size() % 2 == 0 && |
| 3552 | "Expected pairs of entries"); |
| 3553 | for (unsigned Idx = 0, N = F->PendingInstantiations.size(); Idx < N;) { |
| 3554 | ValueDecl *D=cast<ValueDecl>(GetDecl(F->PendingInstantiations[Idx++])); |
| 3555 | SourceLocation Loc = ReadSourceLocation(*F, F->PendingInstantiations,Idx); |
| 3556 | SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc)); |
| 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | // The two special data sets below always come from the most recent PCH, |
| 3561 | // which is at the front of the chain. |
| 3562 | PerFileData &F = *Chain.front(); |
| 3563 | |
| 3564 | // If there were any weak undeclared identifiers, deserialize them and add to |
| 3565 | // Sema's list of weak undeclared identifiers. |
| 3566 | if (!WeakUndeclaredIdentifiers.empty()) { |
| 3567 | unsigned Idx = 0; |
| 3568 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers[Idx++]; I != N; ++I) { |
| 3569 | IdentifierInfo *WeakId = GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3570 | IdentifierInfo *AliasId= GetIdentifierInfo(WeakUndeclaredIdentifiers,Idx); |
| 3571 | SourceLocation Loc = ReadSourceLocation(F, WeakUndeclaredIdentifiers,Idx); |
| 3572 | bool Used = WeakUndeclaredIdentifiers[Idx++]; |
| 3573 | Sema::WeakInfo WI(AliasId, Loc); |
| 3574 | WI.setUsed(Used); |
| 3575 | SemaObj->WeakUndeclaredIdentifiers.insert(std::make_pair(WeakId, WI)); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | // If there were any VTable uses, deserialize the information and add it |
| 3580 | // to Sema's vector and map of VTable uses. |
| 3581 | if (!VTableUses.empty()) { |
| 3582 | unsigned Idx = 0; |
| 3583 | for (unsigned I = 0, N = VTableUses[Idx++]; I != N; ++I) { |
| 3584 | CXXRecordDecl *Class = cast<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 3585 | SourceLocation Loc = ReadSourceLocation(F, VTableUses, Idx); |
| 3586 | bool DefinitionRequired = VTableUses[Idx++]; |
| 3587 | SemaObj->VTableUses.push_back(std::make_pair(Class, Loc)); |
| 3588 | SemaObj->VTablesUsed[Class] = DefinitionRequired; |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3589 | } |
| 3590 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3591 | } |
| 3592 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3593 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Sebastian Redl | 78f5177 | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3594 | // Try to find this name within our on-disk hash tables. We start with the |
| 3595 | // most recent one, since that one contains the most up-to-date info. |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3596 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3597 | ASTIdentifierLookupTable *IdTable |
| 3598 | = (ASTIdentifierLookupTable *)Chain[I]->IdentifierLookupTable; |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 3599 | if (!IdTable) |
| 3600 | continue; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3601 | std::pair<const char*, unsigned> Key(NameStart, NameEnd - NameStart); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3602 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3603 | if (Pos == IdTable->end()) |
| 3604 | continue; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3605 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3606 | // Dereferencing the iterator has the effect of building the |
| 3607 | // IdentifierInfo node and populating it with the various |
| 3608 | // declarations it needs. |
Sebastian Redl | 78f5177 | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3609 | return *Pos; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 3610 | } |
Sebastian Redl | 78f5177 | 2010-08-02 18:30:12 +0000 | [diff] [blame] | 3611 | return 0; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 3614 | namespace clang { |
| 3615 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 3616 | /// identifiers stored within a set of AST files. |
| 3617 | class ASTIdentifierIterator : public IdentifierIterator { |
| 3618 | /// \brief The AST reader whose identifiers are being enumerated. |
| 3619 | const ASTReader &Reader; |
| 3620 | |
| 3621 | /// \brief The current index into the chain of AST files stored in |
| 3622 | /// the AST reader. |
| 3623 | unsigned Index; |
| 3624 | |
| 3625 | /// \brief The current position within the identifier lookup table |
| 3626 | /// of the current AST file. |
| 3627 | ASTIdentifierLookupTable::key_iterator Current; |
| 3628 | |
| 3629 | /// \brief The end position within the identifier lookup table of |
| 3630 | /// the current AST file. |
| 3631 | ASTIdentifierLookupTable::key_iterator End; |
| 3632 | |
| 3633 | public: |
| 3634 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 3635 | |
| 3636 | virtual llvm::StringRef Next(); |
| 3637 | }; |
| 3638 | } |
| 3639 | |
| 3640 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
| 3641 | : Reader(Reader), Index(Reader.Chain.size() - 1) { |
| 3642 | ASTIdentifierLookupTable *IdTable |
| 3643 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3644 | Current = IdTable->key_begin(); |
| 3645 | End = IdTable->key_end(); |
| 3646 | } |
| 3647 | |
| 3648 | llvm::StringRef ASTIdentifierIterator::Next() { |
| 3649 | while (Current == End) { |
| 3650 | // If we have exhausted all of our AST files, we're done. |
| 3651 | if (Index == 0) |
| 3652 | return llvm::StringRef(); |
| 3653 | |
| 3654 | --Index; |
| 3655 | ASTIdentifierLookupTable *IdTable |
| 3656 | = (ASTIdentifierLookupTable *)Reader.Chain[Index]->IdentifierLookupTable; |
| 3657 | Current = IdTable->key_begin(); |
| 3658 | End = IdTable->key_end(); |
| 3659 | } |
| 3660 | |
| 3661 | // We have any identifiers remaining in the current AST file; return |
| 3662 | // the next one. |
| 3663 | std::pair<const char*, unsigned> Key = *Current; |
| 3664 | ++Current; |
| 3665 | return llvm::StringRef(Key.first, Key.second); |
| 3666 | } |
| 3667 | |
| 3668 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 3669 | return new ASTIdentifierIterator(*this); |
| 3670 | } |
| 3671 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3672 | std::pair<ObjCMethodList, ObjCMethodList> |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3673 | ASTReader::ReadMethodPool(Selector Sel) { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3674 | // Find this selector in a hash table. We want to find the most recent entry. |
| 3675 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3676 | PerFileData &F = *Chain[I]; |
| 3677 | if (!F.SelectorLookupTable) |
| 3678 | continue; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3679 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3680 | ASTSelectorLookupTable *PoolTable |
| 3681 | = (ASTSelectorLookupTable*)F.SelectorLookupTable; |
| 3682 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3683 | if (Pos != PoolTable->end()) { |
| 3684 | ++NumSelectorsRead; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3685 | // FIXME: Not quite happy with the statistics here. We probably should |
| 3686 | // disable this tracking when called via LoadSelector. |
| 3687 | // Also, should entries without methods count as misses? |
| 3688 | ++NumMethodPoolEntriesRead; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3689 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3690 | if (DeserializationListener) |
| 3691 | DeserializationListener->SelectorRead(Data.ID, Sel); |
| 3692 | return std::make_pair(Data.Instance, Data.Factory); |
| 3693 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3694 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3695 | |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3696 | ++NumMethodPoolMisses; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3697 | return std::pair<ObjCMethodList, ObjCMethodList>(); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3698 | } |
| 3699 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3700 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3701 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 3702 | ReadMethodPool(Sel); |
| 3703 | } |
| 3704 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3705 | void ASTReader::SetIdentifierInfo(unsigned ID, IdentifierInfo *II) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3706 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3707 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3708 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3709 | if (DeserializationListener) |
| 3710 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3713 | /// \brief Set the globally-visible declarations associated with the given |
| 3714 | /// identifier. |
| 3715 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3716 | /// If the AST reader is currently in a state where the given declaration IDs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3717 | /// cannot safely be resolved, they are queued until it is safe to resolve |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3718 | /// them. |
| 3719 | /// |
| 3720 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 3721 | /// declarations. |
| 3722 | /// |
| 3723 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 3724 | /// visible at global scope. |
| 3725 | /// |
| 3726 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 3727 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 3728 | /// will not be placed onto the pending queue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3729 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3730 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3731 | const llvm::SmallVectorImpl<uint32_t> &DeclIDs, |
| 3732 | bool Nonrecursive) { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3733 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3734 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 3735 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 3736 | PII.II = II; |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 3737 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3738 | return; |
| 3739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3740 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3741 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 3742 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 3743 | if (SemaObj) { |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3744 | if (SemaObj->TUScope) { |
| 3745 | // Introduce this declaration into the translation-unit scope |
| 3746 | // and add it to the declaration chain for this identifier, so |
| 3747 | // that (unqualified) name lookup will find it. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 3748 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 3749 | } |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 3750 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3751 | } else { |
| 3752 | // Queue this declaration so that it will be added to the |
| 3753 | // translation unit scope and identifier's declaration chain |
| 3754 | // once a Sema object is known. |
| 3755 | PreloadedDecls.push_back(D); |
| 3756 | } |
| 3757 | } |
| 3758 | } |
| 3759 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3760 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(unsigned ID) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3761 | if (ID == 0) |
| 3762 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3763 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3764 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3765 | Error("no identifier table in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3766 | return 0; |
| 3767 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3768 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3769 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3770 | ID -= 1; |
| 3771 | if (!IdentifiersLoaded[ID]) { |
| 3772 | unsigned Index = ID; |
| 3773 | const char *Str = 0; |
| 3774 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3775 | PerFileData *F = Chain[N - I - 1]; |
| 3776 | if (Index < F->LocalNumIdentifiers) { |
| 3777 | uint32_t Offset = F->IdentifierOffsets[Index]; |
| 3778 | Str = F->IdentifierTableData + Offset; |
| 3779 | break; |
| 3780 | } |
| 3781 | Index -= F->LocalNumIdentifiers; |
| 3782 | } |
| 3783 | assert(Str && "Broken Chain"); |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 3784 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3785 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 3786 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | ca42a51 | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 3787 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 3788 | // unsigned integers. This is important to avoid integer overflow when |
| 3789 | // we cast them to 'unsigned'. |
Ted Kremenek | 49c5232 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 3790 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3791 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 3792 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3793 | IdentifiersLoaded[ID] |
Kovarththanan Rajaratnam | a3b0959 | 2010-03-12 10:32:27 +0000 | [diff] [blame] | 3794 | = &PP->getIdentifierTable().get(Str, StrLen); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3795 | if (DeserializationListener) |
| 3796 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3797 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3798 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 3799 | return IdentifiersLoaded[ID]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3802 | void ASTReader::ReadSLocEntry(unsigned ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 3803 | ReadSLocEntryRecord(ID); |
| 3804 | } |
| 3805 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3806 | Selector ASTReader::DecodeSelector(unsigned ID) { |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3807 | if (ID == 0) |
| 3808 | return Selector(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3809 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3810 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3811 | Error("selector ID out of range in AST file"); |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3812 | return Selector(); |
| 3813 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3814 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3815 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3816 | // Load this selector from the selector table. |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3817 | unsigned Idx = ID - 1; |
| 3818 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 3819 | PerFileData &F = *Chain[N - I - 1]; |
| 3820 | if (Idx < F.LocalNumSelectors) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3821 | ASTSelectorLookupTrait Trait(*this); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3822 | SelectorsLoaded[ID - 1] = |
| 3823 | Trait.ReadKey(F.SelectorLookupTableData + F.SelectorOffsets[Idx], 0); |
| 3824 | if (DeserializationListener) |
| 3825 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 3826 | break; |
| 3827 | } |
| 3828 | Idx -= F.LocalNumSelectors; |
| 3829 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3830 | } |
| 3831 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3832 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 3835 | Selector ASTReader::GetExternalSelector(uint32_t ID) { |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 3836 | return DecodeSelector(ID); |
| 3837 | } |
| 3838 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3839 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3840 | // ID 0 (the null selector) is considered an external selector. |
| 3841 | return getTotalNumSelectors() + 1; |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3844 | DeclarationName |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3845 | ASTReader::ReadDeclarationName(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3846 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 3847 | switch (Kind) { |
| 3848 | case DeclarationName::Identifier: |
| 3849 | return DeclarationName(GetIdentifierInfo(Record, Idx)); |
| 3850 | |
| 3851 | case DeclarationName::ObjCZeroArgSelector: |
| 3852 | case DeclarationName::ObjCOneArgSelector: |
| 3853 | case DeclarationName::ObjCMultiArgSelector: |
Steve Naroff | 3c301dc | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 3854 | return DeclarationName(GetSelector(Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3855 | |
| 3856 | case DeclarationName::CXXConstructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3857 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 2211d34 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 3858 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3859 | |
| 3860 | case DeclarationName::CXXDestructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3861 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 2211d34 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 3862 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3863 | |
| 3864 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3865 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 2211d34 | 2009-08-05 05:36:45 +0000 | [diff] [blame] | 3866 | Context->getCanonicalType(GetType(Record[Idx++]))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3867 | |
| 3868 | case DeclarationName::CXXOperatorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3869 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3870 | (OverloadedOperatorKind)Record[Idx++]); |
| 3871 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 3872 | case DeclarationName::CXXLiteralOperatorName: |
| 3873 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 3874 | GetIdentifierInfo(Record, Idx)); |
| 3875 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3876 | case DeclarationName::CXXUsingDirective: |
| 3877 | return DeclarationName::getUsingDirectiveName(); |
| 3878 | } |
| 3879 | |
| 3880 | // Required to silence GCC warning |
| 3881 | return DeclarationName(); |
| 3882 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3883 | |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 3884 | void ASTReader::ReadDeclarationNameLoc(PerFileData &F, |
| 3885 | DeclarationNameLoc &DNLoc, |
| 3886 | DeclarationName Name, |
| 3887 | const RecordData &Record, unsigned &Idx) { |
| 3888 | switch (Name.getNameKind()) { |
| 3889 | case DeclarationName::CXXConstructorName: |
| 3890 | case DeclarationName::CXXDestructorName: |
| 3891 | case DeclarationName::CXXConversionFunctionName: |
| 3892 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 3893 | break; |
| 3894 | |
| 3895 | case DeclarationName::CXXOperatorName: |
| 3896 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 3897 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 3898 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 3899 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 3900 | break; |
| 3901 | |
| 3902 | case DeclarationName::CXXLiteralOperatorName: |
| 3903 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 3904 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 3905 | break; |
| 3906 | |
| 3907 | case DeclarationName::Identifier: |
| 3908 | case DeclarationName::ObjCZeroArgSelector: |
| 3909 | case DeclarationName::ObjCOneArgSelector: |
| 3910 | case DeclarationName::ObjCMultiArgSelector: |
| 3911 | case DeclarationName::CXXUsingDirective: |
| 3912 | break; |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | void ASTReader::ReadDeclarationNameInfo(PerFileData &F, |
| 3917 | DeclarationNameInfo &NameInfo, |
| 3918 | const RecordData &Record, unsigned &Idx) { |
| 3919 | NameInfo.setName(ReadDeclarationName(Record, Idx)); |
| 3920 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 3921 | DeclarationNameLoc DNLoc; |
| 3922 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 3923 | NameInfo.setInfo(DNLoc); |
| 3924 | } |
| 3925 | |
| 3926 | void ASTReader::ReadQualifierInfo(PerFileData &F, QualifierInfo &Info, |
| 3927 | const RecordData &Record, unsigned &Idx) { |
| 3928 | Info.NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3929 | Info.NNSRange = ReadSourceRange(F, Record, Idx); |
| 3930 | unsigned NumTPLists = Record[Idx++]; |
| 3931 | Info.NumTemplParamLists = NumTPLists; |
| 3932 | if (NumTPLists) { |
| 3933 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 3934 | for (unsigned i=0; i != NumTPLists; ++i) |
| 3935 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 3936 | } |
| 3937 | } |
| 3938 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3939 | TemplateName |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3940 | ASTReader::ReadTemplateName(const RecordData &Record, unsigned &Idx) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 3941 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3942 | switch (Kind) { |
| 3943 | case TemplateName::Template: |
| 3944 | return TemplateName(cast_or_null<TemplateDecl>(GetDecl(Record[Idx++]))); |
| 3945 | |
| 3946 | case TemplateName::OverloadedTemplate: { |
| 3947 | unsigned size = Record[Idx++]; |
| 3948 | UnresolvedSet<8> Decls; |
| 3949 | while (size--) |
| 3950 | Decls.addDecl(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
| 3951 | |
| 3952 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 3953 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 3954 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3955 | case TemplateName::QualifiedTemplate: { |
| 3956 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3957 | bool hasTemplKeyword = Record[Idx++]; |
| 3958 | TemplateDecl *Template = cast<TemplateDecl>(GetDecl(Record[Idx++])); |
| 3959 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 3960 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 3961 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3962 | case TemplateName::DependentTemplate: { |
| 3963 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(Record, Idx); |
| 3964 | if (Record[Idx++]) // isIdentifier |
| 3965 | return Context->getDependentTemplateName(NNS, |
| 3966 | GetIdentifierInfo(Record, Idx)); |
| 3967 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3968 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3969 | } |
| 3970 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 3971 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3972 | assert(0 && "Unhandled template name kind!"); |
| 3973 | return TemplateName(); |
| 3974 | } |
| 3975 | |
| 3976 | TemplateArgument |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3977 | ASTReader::ReadTemplateArgument(PerFileData &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3978 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3979 | switch ((TemplateArgument::ArgKind)Record[Idx++]) { |
| 3980 | case TemplateArgument::Null: |
| 3981 | return TemplateArgument(); |
| 3982 | case TemplateArgument::Type: |
| 3983 | return TemplateArgument(GetType(Record[Idx++])); |
| 3984 | case TemplateArgument::Declaration: |
| 3985 | return TemplateArgument(GetDecl(Record[Idx++])); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 3986 | case TemplateArgument::Integral: { |
| 3987 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 3988 | QualType T = GetType(Record[Idx++]); |
| 3989 | return TemplateArgument(Value, T); |
| 3990 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3991 | case TemplateArgument::Template: |
| 3992 | return TemplateArgument(ReadTemplateName(Record, Idx)); |
| 3993 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3994 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3995 | case TemplateArgument::Pack: { |
| 3996 | unsigned NumArgs = Record[Idx++]; |
| 3997 | llvm::SmallVector<TemplateArgument, 8> Args; |
| 3998 | Args.reserve(NumArgs); |
| 3999 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4000 | Args.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4001 | TemplateArgument TemplArg; |
| 4002 | TemplArg.setArgumentPack(Args.data(), Args.size(), /*CopyArgs=*/true); |
| 4003 | return TemplArg; |
| 4004 | } |
| 4005 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 4006 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 4007 | assert(0 && "Unhandled template argument kind!"); |
| 4008 | return TemplateArgument(); |
| 4009 | } |
| 4010 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4011 | TemplateParameterList * |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4012 | ASTReader::ReadTemplateParameterList(PerFileData &F, |
| 4013 | const RecordData &Record, unsigned &Idx) { |
| 4014 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 4015 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 4016 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4017 | |
| 4018 | unsigned NumParams = Record[Idx++]; |
| 4019 | llvm::SmallVector<NamedDecl *, 16> Params; |
| 4020 | Params.reserve(NumParams); |
| 4021 | while (NumParams--) |
| 4022 | Params.push_back(cast<NamedDecl>(GetDecl(Record[Idx++]))); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 4023 | |
| 4024 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4025 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 4026 | Params.data(), Params.size(), RAngleLoc); |
| 4027 | return TemplateParams; |
| 4028 | } |
| 4029 | |
| 4030 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4031 | ASTReader:: |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4032 | ReadTemplateArgumentList(llvm::SmallVector<TemplateArgument, 8> &TemplArgs, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4033 | PerFileData &F, const RecordData &Record, |
| 4034 | unsigned &Idx) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4035 | unsigned NumTemplateArgs = Record[Idx++]; |
| 4036 | TemplArgs.reserve(NumTemplateArgs); |
| 4037 | while (NumTemplateArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4038 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 4039 | } |
| 4040 | |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4041 | /// \brief Read a UnresolvedSet structure. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4042 | void ASTReader::ReadUnresolvedSet(UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 4043 | const RecordData &Record, unsigned &Idx) { |
| 4044 | unsigned NumDecls = Record[Idx++]; |
| 4045 | while (NumDecls--) { |
| 4046 | NamedDecl *D = cast<NamedDecl>(GetDecl(Record[Idx++])); |
| 4047 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 4048 | Set.addDecl(D, AS); |
| 4049 | } |
| 4050 | } |
| 4051 | |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4052 | CXXBaseSpecifier |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4053 | ASTReader::ReadCXXBaseSpecifier(PerFileData &F, |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4054 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4055 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 4056 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 4057 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4058 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4059 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 4060 | return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, TInfo); |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4063 | std::pair<CXXBaseOrMemberInitializer **, unsigned> |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4064 | ASTReader::ReadCXXBaseOrMemberInitializers(PerFileData &F, |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4065 | const RecordData &Record, |
| 4066 | unsigned &Idx) { |
| 4067 | CXXBaseOrMemberInitializer **BaseOrMemberInitializers = 0; |
| 4068 | unsigned NumInitializers = Record[Idx++]; |
| 4069 | if (NumInitializers) { |
| 4070 | ASTContext &C = *getContext(); |
| 4071 | |
| 4072 | BaseOrMemberInitializers |
| 4073 | = new (C) CXXBaseOrMemberInitializer*[NumInitializers]; |
| 4074 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 4075 | TypeSourceInfo *BaseClassInfo = 0; |
| 4076 | bool IsBaseVirtual = false; |
| 4077 | FieldDecl *Member = 0; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 4078 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4079 | bool IsBaseInitializer = Record[Idx++]; |
| 4080 | if (IsBaseInitializer) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4081 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4082 | IsBaseVirtual = Record[Idx++]; |
| 4083 | } else { |
| 4084 | Member = cast<FieldDecl>(GetDecl(Record[Idx++])); |
| 4085 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4086 | SourceLocation MemberLoc = ReadSourceLocation(F, Record, Idx); |
| 4087 | Expr *Init = ReadExpr(F); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4088 | FieldDecl *AnonUnionMember |
| 4089 | = cast_or_null<FieldDecl>(GetDecl(Record[Idx++])); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4090 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 4091 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4092 | bool IsWritten = Record[Idx++]; |
| 4093 | unsigned SourceOrderOrNumArrayIndices; |
| 4094 | llvm::SmallVector<VarDecl *, 8> Indices; |
| 4095 | if (IsWritten) { |
| 4096 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4097 | } else { |
| 4098 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 4099 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 4100 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
| 4101 | Indices.push_back(cast<VarDecl>(GetDecl(Record[Idx++]))); |
| 4102 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame^] | 4103 | |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4104 | CXXBaseOrMemberInitializer *BOMInit; |
| 4105 | if (IsBaseInitializer) { |
| 4106 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo, |
| 4107 | IsBaseVirtual, LParenLoc, |
| 4108 | Init, RParenLoc); |
| 4109 | } else if (IsWritten) { |
| 4110 | BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc, |
| 4111 | LParenLoc, Init, RParenLoc); |
| 4112 | } else { |
| 4113 | BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc, |
| 4114 | LParenLoc, Init, RParenLoc, |
| 4115 | Indices.data(), |
| 4116 | Indices.size()); |
| 4117 | } |
| 4118 | |
Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 4119 | if (IsWritten) |
| 4120 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 4121 | BOMInit->setAnonUnionMember(AnonUnionMember); |
| 4122 | BaseOrMemberInitializers[i] = BOMInit; |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | return std::make_pair(BaseOrMemberInitializers, NumInitializers); |
| 4127 | } |
| 4128 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4129 | NestedNameSpecifier * |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4130 | ASTReader::ReadNestedNameSpecifier(const RecordData &Record, unsigned &Idx) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4131 | unsigned N = Record[Idx++]; |
| 4132 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 4133 | for (unsigned I = 0; I != N; ++I) { |
| 4134 | NestedNameSpecifier::SpecifierKind Kind |
| 4135 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 4136 | switch (Kind) { |
| 4137 | case NestedNameSpecifier::Identifier: { |
| 4138 | IdentifierInfo *II = GetIdentifierInfo(Record, Idx); |
| 4139 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 4140 | break; |
| 4141 | } |
| 4142 | |
| 4143 | case NestedNameSpecifier::Namespace: { |
| 4144 | NamespaceDecl *NS = cast<NamespaceDecl>(GetDecl(Record[Idx++])); |
| 4145 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 4146 | break; |
| 4147 | } |
| 4148 | |
| 4149 | case NestedNameSpecifier::TypeSpec: |
| 4150 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 4151 | Type *T = GetType(Record[Idx++]).getTypePtr(); |
| 4152 | bool Template = Record[Idx++]; |
| 4153 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 4154 | break; |
| 4155 | } |
| 4156 | |
| 4157 | case NestedNameSpecifier::Global: { |
| 4158 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 4159 | // No associated value, and there can't be a prefix. |
| 4160 | break; |
| 4161 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4162 | } |
Argyrios Kyrtzidis | ad65c69 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 4163 | Prev = NNS; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4164 | } |
| 4165 | return NNS; |
| 4166 | } |
| 4167 | |
| 4168 | SourceRange |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4169 | ASTReader::ReadSourceRange(PerFileData &F, const RecordData &Record, |
| 4170 | unsigned &Idx) { |
| 4171 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 4172 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 6d3bc08 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 4173 | return SourceRange(beg, end); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 4174 | } |
| 4175 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4176 | /// \brief Read an integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4177 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4178 | unsigned BitWidth = Record[Idx++]; |
| 4179 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 4180 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 4181 | Idx += NumWords; |
| 4182 | return Result; |
| 4183 | } |
| 4184 | |
| 4185 | /// \brief Read a signed integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4186 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 4187 | bool isUnsigned = Record[Idx++]; |
| 4188 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 4189 | } |
| 4190 | |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4191 | /// \brief Read a floating-point value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4192 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 4193 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 4194 | } |
| 4195 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4196 | // \brief Read a string |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4197 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4198 | unsigned Len = Record[Idx++]; |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 4199 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4200 | Idx += Len; |
| 4201 | return Result; |
| 4202 | } |
| 4203 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4204 | CXXTemporary *ASTReader::ReadCXXTemporary(const RecordData &Record, |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 4205 | unsigned &Idx) { |
| 4206 | CXXDestructorDecl *Decl = cast<CXXDestructorDecl>(GetDecl(Record[Idx++])); |
| 4207 | return CXXTemporary::Create(*Context, Decl); |
| 4208 | } |
| 4209 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4210 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 4211 | return Diag(SourceLocation(), DiagID); |
| 4212 | } |
| 4213 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4214 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4215 | return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4216 | } |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4217 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4218 | /// \brief Retrieve the identifier table associated with the |
| 4219 | /// preprocessor. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4220 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4221 | assert(PP && "Forgot to set Preprocessor ?"); |
| 4222 | return PP->getIdentifierTable(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4225 | /// \brief Record that the given ID maps to the given switch-case |
| 4226 | /// statement. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4227 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4228 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 4229 | SwitchCaseStmts[ID] = SC; |
| 4230 | } |
| 4231 | |
| 4232 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4233 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 4234 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 4235 | return SwitchCaseStmts[ID]; |
| 4236 | } |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4237 | |
| 4238 | /// \brief Record that the given label statement has been |
| 4239 | /// deserialized and has the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4240 | void ASTReader::RecordLabelStmt(LabelStmt *S, unsigned ID) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4241 | assert(LabelStmts.find(ID) == LabelStmts.end() && |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4242 | "Deserialized label twice"); |
| 4243 | LabelStmts[ID] = S; |
| 4244 | |
| 4245 | // If we've already seen any goto statements that point to this |
| 4246 | // label, resolve them now. |
| 4247 | typedef std::multimap<unsigned, GotoStmt *>::iterator GotoIter; |
| 4248 | std::pair<GotoIter, GotoIter> Gotos = UnresolvedGotoStmts.equal_range(ID); |
| 4249 | for (GotoIter Goto = Gotos.first; Goto != Gotos.second; ++Goto) |
| 4250 | Goto->second->setLabel(S); |
| 4251 | UnresolvedGotoStmts.erase(Gotos.first, Gotos.second); |
Douglas Gregor | 779d865 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4252 | |
| 4253 | // If we've already seen any address-label statements that point to |
| 4254 | // this label, resolve them now. |
| 4255 | typedef std::multimap<unsigned, AddrLabelExpr *>::iterator AddrLabelIter; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4256 | std::pair<AddrLabelIter, AddrLabelIter> AddrLabels |
Douglas Gregor | 779d865 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4257 | = UnresolvedAddrLabelExprs.equal_range(ID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4258 | for (AddrLabelIter AddrLabel = AddrLabels.first; |
Douglas Gregor | 779d865 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4259 | AddrLabel != AddrLabels.second; ++AddrLabel) |
| 4260 | AddrLabel->second->setLabel(S); |
| 4261 | UnresolvedAddrLabelExprs.erase(AddrLabels.first, AddrLabels.second); |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | /// \brief Set the label of the given statement to the label |
| 4265 | /// identified by ID. |
| 4266 | /// |
| 4267 | /// Depending on the order in which the label and other statements |
| 4268 | /// referencing that label occur, this operation may complete |
| 4269 | /// immediately (updating the statement) or it may queue the |
| 4270 | /// statement to be back-patched later. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4271 | void ASTReader::SetLabelOf(GotoStmt *S, unsigned ID) { |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 4272 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4273 | if (Label != LabelStmts.end()) { |
| 4274 | // We've already seen this label, so set the label of the goto and |
| 4275 | // we're done. |
| 4276 | S->setLabel(Label->second); |
| 4277 | } else { |
| 4278 | // We haven't seen this label yet, so add this goto to the set of |
| 4279 | // unresolved goto statements. |
| 4280 | UnresolvedGotoStmts.insert(std::make_pair(ID, S)); |
| 4281 | } |
| 4282 | } |
Douglas Gregor | 779d865 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4283 | |
| 4284 | /// \brief Set the label of the given expression to the label |
| 4285 | /// identified by ID. |
| 4286 | /// |
| 4287 | /// Depending on the order in which the label and other statements |
| 4288 | /// referencing that label occur, this operation may complete |
| 4289 | /// immediately (updating the statement) or it may queue the |
| 4290 | /// statement to be back-patched later. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4291 | void ASTReader::SetLabelOf(AddrLabelExpr *S, unsigned ID) { |
Douglas Gregor | 779d865 | 2009-04-17 18:58:21 +0000 | [diff] [blame] | 4292 | std::map<unsigned, LabelStmt *>::iterator Label = LabelStmts.find(ID); |
| 4293 | if (Label != LabelStmts.end()) { |
| 4294 | // We've already seen this label, so set the label of the |
| 4295 | // label-address expression and we're done. |
| 4296 | S->setLabel(Label->second); |
| 4297 | } else { |
| 4298 | // We haven't seen this label yet, so add this label-address |
| 4299 | // expression to the set of unresolved label-address expressions. |
| 4300 | UnresolvedAddrLabelExprs.insert(std::make_pair(ID, S)); |
| 4301 | } |
| 4302 | } |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4303 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4304 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4305 | assert(NumCurrentElementsDeserializing && |
| 4306 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 4307 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4308 | // If any identifiers with corresponding top-level declarations have |
| 4309 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4310 | while (!PendingIdentifierInfos.empty()) { |
| 4311 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 4312 | PendingIdentifierInfos.front().DeclIDs, true); |
| 4313 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4314 | } |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4315 | |
| 4316 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 4317 | // decls to the consumer. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4318 | if (Consumer) |
| 4319 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4320 | } |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4321 | --NumCurrentElementsDeserializing; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4322 | } |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4323 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4324 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
| 4325 | const char *isysroot, bool DisableValidation) |
| 4326 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 4327 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 4328 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
| 4329 | Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation), |
| 4330 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4331 | TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0), |
| 4332 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 4333 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4334 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4335 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4336 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
| 4337 | RelocatablePCH = false; |
| 4338 | } |
| 4339 | |
| 4340 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
| 4341 | Diagnostic &Diags, const char *isysroot, |
| 4342 | bool DisableValidation) |
| 4343 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
| 4344 | Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0), |
| 4345 | isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0), |
| 4346 | NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 4347 | NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0), |
| 4348 | NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0), |
| 4349 | NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
| 4350 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 4351 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
| 4352 | TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 4353 | RelocatablePCH = false; |
| 4354 | } |
| 4355 | |
| 4356 | ASTReader::~ASTReader() { |
| 4357 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 4358 | delete Chain[e - i - 1]; |
| 4359 | // Delete all visible decl lookup tables |
| 4360 | for (DeclContextOffsetsMap::iterator I = DeclContextOffsets.begin(), |
| 4361 | E = DeclContextOffsets.end(); |
| 4362 | I != E; ++I) { |
| 4363 | for (DeclContextInfos::iterator J = I->second.begin(), F = I->second.end(); |
| 4364 | J != F; ++J) { |
| 4365 | if (J->NameLookupTableData) |
| 4366 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 4367 | J->NameLookupTableData); |
| 4368 | } |
| 4369 | } |
| 4370 | for (DeclContextVisibleUpdatesPending::iterator |
| 4371 | I = PendingVisibleUpdates.begin(), |
| 4372 | E = PendingVisibleUpdates.end(); |
| 4373 | I != E; ++I) { |
| 4374 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 4375 | F = I->second.end(); |
| 4376 | J != F; ++J) |
| 4377 | delete static_cast<ASTDeclContextNameLookupTable*>(*J); |
| 4378 | } |
| 4379 | } |
| 4380 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 4381 | ASTReader::PerFileData::PerFileData(ASTFileType Ty) |
| 4382 | : Type(Ty), SizeInBits(0), LocalNumSLocEntries(0), SLocOffsets(0), LocalSLocSize(0), |
Sebastian Redl | 949fe9e | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 4383 | LocalNumIdentifiers(0), IdentifierOffsets(0), IdentifierTableData(0), |
| 4384 | IdentifierLookupTable(0), LocalNumMacroDefinitions(0), |
| 4385 | MacroDefinitionOffsets(0), LocalNumSelectors(0), SelectorOffsets(0), |
| 4386 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
| 4387 | DeclOffsets(0), LocalNumTypes(0), TypeOffsets(0), StatCache(0), |
Sebastian Redl | 3f6b753 | 2010-10-01 19:59:12 +0000 | [diff] [blame] | 4388 | NumPreallocatedPreprocessingEntities(0), NextInSource(0) |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 4389 | {} |
| 4390 | |
| 4391 | ASTReader::PerFileData::~PerFileData() { |
| 4392 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
| 4393 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 4394 | } |
| 4395 | |