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