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 | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 26 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 27 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 28 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 34321bc | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 29 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 30 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 31 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 3fa455a | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 32 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 33 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 34 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 35 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 38 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 39 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 40 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 42 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 43 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 44 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 45 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 46 | #include "llvm/Support/Path.h" |
Michael J. Spencer | f25faaa | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 47 | #include "llvm/Support/system_error.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 48 | #include <algorithm> |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 49 | #include <iterator> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <cstdio> |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 51 | #include <sys/stat.h> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 52 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 53 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 54 | using namespace clang::serialization; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | |
| 56 | //===----------------------------------------------------------------------===// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 57 | // PCH validator implementation |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 60 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | |
| 62 | bool |
| 63 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 64 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 65 | #define PARSE_LANGOPT_BENIGN(Option) |
| 66 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 67 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 68 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 69 | return true; \ |
| 70 | } |
| 71 | |
| 72 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 73 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 74 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 75 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 76 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 77 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 78 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 79 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 80 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 81 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 82 | PARSE_LANGOPT_IMPORTANT(C1X, diag::warn_pch_c1x); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 83 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | 4992ca4b | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 84 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 85 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 86 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 87 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 88 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 89 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 90 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 91 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 92 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 93 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 94 | diag::warn_pch_objc_auto_properties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedResultType) |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 97 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 99 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 101 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 102 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 104 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 106 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 109 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 110 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 112 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | a77eaeb | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 113 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 115 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 116 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 117 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 119 | diag::warn_pch_heinous_extensions); |
| 120 | // FIXME: Most of the options below are benign if the macro wasn't |
| 121 | // used. Unfortunately, this means that a PCH compiled without |
| 122 | // optimization can't be used with optimization turned on, even |
| 123 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 124 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 125 | // doesn't matter. We could consider making this some special kind |
| 126 | // of check. |
| 127 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 128 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 129 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 130 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 131 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 132 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 133 | PARSE_LANGOPT_IMPORTANT(Deprecated, diag::warn_pch_deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 134 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 135 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 74825bc | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 138 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 140 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 141 | return true; |
| 142 | } |
| 143 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 144 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 145 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 146 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 148 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 150 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 151 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | 8ed0c0b | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 152 | PARSE_LANGOPT_BENIGN(SpellChecking); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 153 | PARSE_LANGOPT_IMPORTANT(ObjCAutoRefCount, diag::warn_pch_auto_ref_count); |
| 154 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedReturnType); |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 155 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 156 | #undef PARSE_LANGOPT_BENIGN |
| 157 | |
| 158 | return false; |
| 159 | } |
| 160 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 161 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | 20a682d | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 162 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 163 | return false; |
| 164 | |
| 165 | Reader.Diag(diag::warn_pch_target_triple) |
| 166 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 167 | return true; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 170 | namespace { |
| 171 | struct EmptyStringRef { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 172 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 173 | }; |
| 174 | struct EmptyBlock { |
| 175 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 176 | }; |
| 177 | } |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 178 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 179 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 180 | PCHPredefinesBlocks R) { |
| 181 | // First, sum up the lengths. |
| 182 | unsigned LL = 0, RL = 0; |
| 183 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 184 | LL += L[I].size(); |
| 185 | } |
| 186 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 187 | RL += R[I].Data.size(); |
| 188 | } |
| 189 | if (LL != RL) |
| 190 | return false; |
| 191 | if (LL == 0 && RL == 0) |
| 192 | return true; |
| 193 | |
| 194 | // Kick out empty parts, they confuse the algorithm below. |
| 195 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 196 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 197 | |
| 198 | // Do it the hard way. At this point, both vectors must be non-empty. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 199 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 200 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | 01ad0a7 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 201 | (void) RN; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 202 | for (;;) { |
| 203 | // Compare the current pieces. |
| 204 | if (LR.size() == RR.size()) { |
| 205 | // If they're the same length, it's pretty easy. |
| 206 | if (LR != RR) |
| 207 | return false; |
| 208 | // Both pieces are done, advance. |
| 209 | ++LI; |
| 210 | ++RI; |
| 211 | // If either string is done, they're both done, since they're the same |
| 212 | // length. |
| 213 | if (LI == LN) { |
| 214 | assert(RI == RN && "Strings not the same length after all?"); |
| 215 | return true; |
| 216 | } |
| 217 | LR = L[LI]; |
| 218 | RR = R[RI].Data; |
| 219 | } else if (LR.size() < RR.size()) { |
| 220 | // Right piece is longer. |
| 221 | if (!RR.startswith(LR)) |
| 222 | return false; |
| 223 | ++LI; |
| 224 | assert(LI != LN && "Strings not the same length after all?"); |
| 225 | RR = RR.substr(LR.size()); |
| 226 | LR = L[LI]; |
| 227 | } else { |
| 228 | // Left piece is longer. |
| 229 | if (!LR.startswith(RR)) |
| 230 | return false; |
| 231 | ++RI; |
| 232 | assert(RI != RN && "Strings not the same length after all?"); |
| 233 | LR = LR.substr(RR.size()); |
| 234 | RR = R[RI].Data; |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 239 | static std::pair<FileID, StringRef::size_type> |
| 240 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 241 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 242 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 243 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 244 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 245 | Res.first = Buffers[I].BufferID; |
| 246 | break; |
| 247 | } |
| 248 | } |
| 249 | return Res; |
| 250 | } |
| 251 | |
| 252 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 253 | StringRef OriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 254 | std::string &SuggestedPredefines, |
| 255 | FileManager &FileMgr) { |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 256 | // We are in the context of an implicit include, so the predefines buffer will |
| 257 | // have a #include entry for the PCH file itself (as normalized by the |
| 258 | // preprocessor initialization). Find it and skip over it in the checking |
| 259 | // below. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 260 | llvm::SmallString<256> PCHInclude; |
| 261 | PCHInclude += "#include \""; |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 262 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 263 | PCHInclude += "\"\n"; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 264 | std::pair<StringRef,StringRef> Split = |
| 265 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 266 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 267 | if (Left == PP.getPredefines()) { |
| 268 | Error("Missing PCH include entry!"); |
| 269 | return true; |
| 270 | } |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 271 | |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 272 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 273 | // command line, we're done. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 274 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 275 | CommandLine.push_back(Left); |
| 276 | CommandLine.push_back(Right); |
| 277 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 278 | return false; |
| 279 | |
| 280 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 282 | // The predefines buffers are different. Determine what the differences are, |
| 283 | // and whether they require us to reject the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 284 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 285 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 286 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 287 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 288 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 289 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 290 | |
| 291 | // Pick out implicit #includes after the PCH and don't consider them for |
| 292 | // validation; we will insert them into SuggestedPredefines so that the |
| 293 | // preprocessor includes them. |
| 294 | std::string IncludesAfterPCH; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 295 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 296 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 297 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 298 | if (AfterPCHLines[i].startswith("#include ")) { |
| 299 | IncludesAfterPCH += AfterPCHLines[i]; |
| 300 | IncludesAfterPCH += '\n'; |
| 301 | } else { |
| 302 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // Make sure we add the includes last into SuggestedPredefines before we |
| 307 | // exit this function. |
| 308 | struct AddIncludesRAII { |
| 309 | std::string &SuggestedPredefines; |
| 310 | std::string &IncludesAfterPCH; |
| 311 | |
| 312 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 313 | std::string &IncludesAfterPCH) |
| 314 | : SuggestedPredefines(SuggestedPredefines), |
| 315 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 316 | ~AddIncludesRAII() { |
| 317 | SuggestedPredefines += IncludesAfterPCH; |
| 318 | } |
| 319 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 320 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 321 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 322 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 324 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 325 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 326 | // Determine which predefines that were used to build the PCH file are missing |
| 327 | // from the command line. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 328 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 329 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 330 | CmdLineLines.begin(), CmdLineLines.end(), |
| 331 | std::back_inserter(MissingPredefines)); |
| 332 | |
| 333 | bool MissingDefines = false; |
| 334 | bool ConflictingDefines = false; |
| 335 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 336 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 337 | if (Missing.startswith("#include ")) { |
| 338 | // An -include was specified when generating the PCH; it is included in |
| 339 | // the PCH, just ignore it. |
| 340 | continue; |
| 341 | } |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 342 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 343 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 344 | return true; |
| 345 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 346 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 347 | // This is a macro definition. Determine the name of the macro we're |
| 348 | // defining. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 349 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 352 | assert(EndOfMacroName != std::string::npos && |
| 353 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 354 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 355 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 356 | // Determine whether this macro was given a different definition on the |
| 357 | // command line. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 358 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 359 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 360 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 362 | MacroDefStart); |
| 363 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 364 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 365 | // Different macro; we're done. |
| 366 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | break; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | |
| 370 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | "Invalid #define in predefines buffer?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 373 | (*ConflictPos)[MacroDefLen] != '(') |
| 374 | continue; // Longer macro name; keep trying. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 376 | // We found a conflicting macro definition. |
| 377 | break; |
| 378 | } |
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 (ConflictPos != CmdLineLines.end()) { |
| 381 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 382 | << MacroName; |
| 383 | |
| 384 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 385 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 386 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 387 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 388 | SourceLocation PCHMissingLoc = |
| 389 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 390 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 391 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 392 | |
| 393 | ConflictingDefines = true; |
| 394 | continue; |
| 395 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 397 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 398 | // 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] | 399 | if (ConflictingDefines) |
| 400 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 402 | if (!MissingDefines) { |
| 403 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 404 | MissingDefines = true; |
| 405 | } |
| 406 | |
| 407 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 408 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 409 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 410 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 411 | SourceLocation PCHMissingLoc = |
| 412 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 413 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 414 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 415 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 416 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 417 | if (ConflictingDefines) |
| 418 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 419 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 420 | // Determine what predefines were introduced based on command-line |
| 421 | // parameters that were not present when building the PCH |
| 422 | // file. Extra #defines are okay, so long as the identifiers being |
| 423 | // defined were not used within the precompiled header. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 424 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 425 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 426 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 428 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 429 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 430 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 431 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 432 | return true; |
| 433 | } |
| 434 | |
| 435 | // This is an extra macro definition. Determine the name of the |
| 436 | // macro we're defining. |
| 437 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 438 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 439 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 440 | assert(EndOfMacroName != std::string::npos && |
| 441 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 442 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 443 | |
| 444 | // Check whether this name was used somewhere in the PCH file. If |
| 445 | // so, defining it as a macro could change behavior, so we reject |
| 446 | // the PCH file. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 447 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 045c92f | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 448 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 449 | return true; |
| 450 | } |
| 451 | |
| 452 | // Add this definition to the suggested predefines buffer. |
| 453 | SuggestedPredefines += Extra; |
| 454 | SuggestedPredefines += '\n'; |
| 455 | } |
| 456 | |
| 457 | // If we get here, it's because the predefines buffer had compatible |
| 458 | // contents. Accept the PCH file. |
| 459 | return false; |
| 460 | } |
| 461 | |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 462 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 463 | unsigned ID) { |
| 464 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 465 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void PCHValidator::ReadCounter(unsigned Value) { |
| 469 | PP.setCounterValue(Value); |
| 470 | } |
| 471 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 472 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 473 | // AST reader implementation |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 474 | //===----------------------------------------------------------------------===// |
| 475 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 476 | void |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 477 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 478 | DeserializationListener = Listener; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 481 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 482 | namespace { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 483 | class ASTSelectorLookupTrait { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 484 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 485 | Module &F; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 486 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 487 | public: |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 488 | struct data_type { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 489 | SelectorID ID; |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 490 | llvm::SmallVector<ObjCMethodDecl *, 2> Instance; |
| 491 | llvm::SmallVector<ObjCMethodDecl *, 2> Factory; |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 492 | }; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 493 | |
| 494 | typedef Selector external_key_type; |
| 495 | typedef external_key_type internal_key_type; |
| 496 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 497 | ASTSelectorLookupTrait(ASTReader &Reader, Module &F) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 498 | : Reader(Reader), F(F) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 500 | static bool EqualKey(const internal_key_type& a, |
| 501 | const internal_key_type& b) { |
| 502 | return a == b; |
| 503 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 505 | static unsigned ComputeHash(Selector Sel) { |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 506 | return serialization::ComputeHash(Sel); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 507 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 508 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 509 | // This hopefully will just get inlined and removed by the optimizer. |
| 510 | static const internal_key_type& |
| 511 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 513 | static std::pair<unsigned, unsigned> |
| 514 | ReadKeyDataLength(const unsigned char*& d) { |
| 515 | using namespace clang::io; |
| 516 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 517 | unsigned DataLen = ReadUnalignedLE16(d); |
| 518 | return std::make_pair(KeyLen, DataLen); |
| 519 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 520 | |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 521 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 522 | using namespace clang::io; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 523 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 524 | unsigned N = ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 525 | IdentifierInfo *FirstII |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 526 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 527 | if (N == 0) |
| 528 | return SelTable.getNullarySelector(FirstII); |
| 529 | else if (N == 1) |
| 530 | return SelTable.getUnarySelector(FirstII); |
| 531 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 532 | SmallVector<IdentifierInfo *, 16> Args; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 533 | Args.push_back(FirstII); |
| 534 | for (unsigned I = 1; I != N; ++I) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 535 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 537 | return SelTable.getSelector(N, Args.data()); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 538 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 540 | data_type ReadData(Selector, const unsigned char* d, unsigned DataLen) { |
| 541 | using namespace clang::io; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 542 | |
| 543 | data_type Result; |
| 544 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 545 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 546 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 547 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 548 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 549 | // Load instance methods |
| 550 | ObjCMethodList *Prev = 0; |
| 551 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 552 | if (ObjCMethodDecl *Method |
| 553 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 554 | Result.Instance.push_back(Method); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | // Load factory methods |
| 558 | Prev = 0; |
| 559 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 560 | if (ObjCMethodDecl *Method |
| 561 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 562 | Result.Factory.push_back(Method); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | return Result; |
| 566 | } |
| 567 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 568 | |
| 569 | } // end anonymous namespace |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 570 | |
| 571 | /// \brief The on-disk hash table used for the global method pool. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 572 | typedef OnDiskChainedHashTable<ASTSelectorLookupTrait> |
| 573 | ASTSelectorLookupTable; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 574 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 575 | namespace clang { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 576 | class ASTIdentifierLookupTrait { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 577 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 578 | Module &F; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 579 | |
| 580 | // If we know the IdentifierInfo in advance, it is here and we will |
| 581 | // not build a new one. Used when deserializing information about an |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 582 | // identifier that was constructed before the AST file was read. |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 583 | IdentifierInfo *KnownII; |
| 584 | |
| 585 | public: |
| 586 | typedef IdentifierInfo * data_type; |
| 587 | |
| 588 | typedef const std::pair<const char*, unsigned> external_key_type; |
| 589 | |
| 590 | typedef external_key_type internal_key_type; |
| 591 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 592 | ASTIdentifierLookupTrait(ASTReader &Reader, Module &F, |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 593 | IdentifierInfo *II = 0) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 594 | : Reader(Reader), F(F), KnownII(II) { } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 596 | static bool EqualKey(const internal_key_type& a, |
| 597 | const internal_key_type& b) { |
| 598 | return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0 |
| 599 | : false; |
| 600 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | static unsigned ComputeHash(const internal_key_type& a) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 603 | return llvm::HashString(StringRef(a.first, a.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 604 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 606 | // This hopefully will just get inlined and removed by the optimizer. |
| 607 | static const internal_key_type& |
| 608 | GetInternalKey(const external_key_type& x) { return x; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 610 | // This hopefully will just get inlined and removed by the optimizer. |
| 611 | static const external_key_type& |
| 612 | GetExternalKey(const internal_key_type& x) { return x; } |
| 613 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 614 | static std::pair<unsigned, unsigned> |
| 615 | ReadKeyDataLength(const unsigned char*& d) { |
| 616 | using namespace clang::io; |
Douglas Gregor | 6b7bf5a | 2009-04-25 20:26:24 +0000 | [diff] [blame] | 617 | unsigned DataLen = ReadUnalignedLE16(d); |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 618 | unsigned KeyLen = ReadUnalignedLE16(d); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 619 | return std::make_pair(KeyLen, DataLen); |
| 620 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 622 | static std::pair<const char*, unsigned> |
| 623 | ReadKey(const unsigned char* d, unsigned n) { |
| 624 | assert(n >= 2 && d[n-1] == '\0'); |
| 625 | return std::make_pair((const char*) d, n-1); |
| 626 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 627 | |
| 628 | IdentifierInfo *ReadData(const internal_key_type& k, |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 629 | const unsigned char* d, |
| 630 | unsigned DataLen) { |
| 631 | using namespace clang::io; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 632 | unsigned RawID = ReadUnalignedLE32(d); |
| 633 | bool IsInteresting = RawID & 0x01; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 634 | |
| 635 | // Wipe out the "is interesting" bit. |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 636 | RawID = RawID >> 1; |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 637 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 638 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 639 | if (!IsInteresting) { |
Sebastian Redl | 9891212 | 2010-07-27 23:01:28 +0000 | [diff] [blame] | 640 | // For uninteresting identifiers, just build the IdentifierInfo |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 641 | // and associate it with the persistent ID. |
| 642 | IdentifierInfo *II = KnownII; |
| 643 | if (!II) |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 644 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 645 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 646 | II->setIsFromAST(); |
Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 647 | return II; |
| 648 | } |
| 649 | |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 650 | unsigned Bits = ReadUnalignedLE16(d); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 651 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 652 | Bits >>= 1; |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 653 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 654 | Bits >>= 1; |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 655 | bool Poisoned = Bits & 0x01; |
| 656 | Bits >>= 1; |
| 657 | bool ExtensionToken = Bits & 0x01; |
| 658 | Bits >>= 1; |
| 659 | bool hasMacroDefinition = Bits & 0x01; |
| 660 | Bits >>= 1; |
| 661 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 662 | Bits >>= 10; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 664 | assert(Bits == 0 && "Extra bits in the identifier?"); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 665 | DataLen -= 6; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 666 | |
| 667 | // Build the IdentifierInfo itself and link the identifier ID with |
| 668 | // the new IdentifierInfo. |
| 669 | IdentifierInfo *II = KnownII; |
| 670 | if (!II) |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 671 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 672 | Reader.SetIdentifierInfo(ID, II); |
| 673 | |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 674 | // Set or check the various bits in the IdentifierInfo structure. |
Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 675 | // Token IDs are read-only. |
| 676 | if (HasRevertedTokenIDToIdentifier) |
| 677 | II->RevertTokenIDToIdentifier(); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 678 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 679 | assert(II->isExtensionToken() == ExtensionToken && |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 680 | "Incorrect extension token flag"); |
| 681 | (void)ExtensionToken; |
Douglas Gregor | b36fc53 | 2011-08-20 05:09:43 +0000 | [diff] [blame] | 682 | if (Poisoned) |
| 683 | II->setIsPoisoned(true); |
Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 684 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 685 | "Incorrect C++ operator keyword flag"); |
| 686 | (void)CPlusPlusOperatorKeyword; |
| 687 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 688 | // If this identifier is a macro, deserialize the macro |
| 689 | // definition. |
| 690 | if (hasMacroDefinition) { |
Douglas Gregor | b36fc53 | 2011-08-20 05:09:43 +0000 | [diff] [blame] | 691 | // FIXME: Check for conflicts? |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 692 | uint32_t Offset = ReadUnalignedLE32(d); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 693 | Reader.SetIdentifierIsMacro(II, F, Offset); |
Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 694 | DataLen -= 4; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 695 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 696 | |
| 697 | // Read all of the declarations visible at global scope with this |
| 698 | // name. |
Chris Lattner | 1d72888 | 2009-04-27 22:17:41 +0000 | [diff] [blame] | 699 | if (Reader.getContext() == 0) return II; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 700 | if (DataLen > 0) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 701 | SmallVector<uint32_t, 4> DeclIDs; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 702 | for (; DataLen > 0; DataLen -= 4) |
Douglas Gregor | f224ae0 | 2011-07-21 23:29:11 +0000 | [diff] [blame] | 703 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 704 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 705 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 707 | II->setIsFromAST(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 708 | return II; |
| 709 | } |
| 710 | }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | |
| 712 | } // end anonymous namespace |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 713 | |
| 714 | /// \brief The on-disk hash table used to contain information about |
| 715 | /// all of the identifiers in the program. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 716 | typedef OnDiskChainedHashTable<ASTIdentifierLookupTrait> |
| 717 | ASTIdentifierLookupTable; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 718 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 719 | namespace { |
| 720 | class ASTDeclContextNameLookupTrait { |
| 721 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 722 | Module &F; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 723 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 724 | public: |
| 725 | /// \brief Pair of begin/end iterators for DeclIDs. |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 726 | /// |
| 727 | /// Note that these declaration IDs are local to the module that contains this |
| 728 | /// particular lookup t |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 729 | typedef std::pair<DeclID *, DeclID *> data_type; |
| 730 | |
| 731 | /// \brief Special internal key for declaration names. |
| 732 | /// The hash table creates keys for comparison; we do not create |
| 733 | /// a DeclarationName for the internal key to avoid deserializing types. |
| 734 | struct DeclNameKey { |
| 735 | DeclarationName::NameKind Kind; |
| 736 | uint64_t Data; |
| 737 | DeclNameKey() : Kind((DeclarationName::NameKind)0), Data(0) { } |
| 738 | }; |
| 739 | |
| 740 | typedef DeclarationName external_key_type; |
| 741 | typedef DeclNameKey internal_key_type; |
| 742 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 743 | explicit ASTDeclContextNameLookupTrait(ASTReader &Reader, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 744 | Module &F) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 745 | : Reader(Reader), F(F) { } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 746 | |
| 747 | static bool EqualKey(const internal_key_type& a, |
| 748 | const internal_key_type& b) { |
| 749 | return a.Kind == b.Kind && a.Data == b.Data; |
| 750 | } |
| 751 | |
| 752 | unsigned ComputeHash(const DeclNameKey &Key) const { |
| 753 | llvm::FoldingSetNodeID ID; |
| 754 | ID.AddInteger(Key.Kind); |
| 755 | |
| 756 | switch (Key.Kind) { |
| 757 | case DeclarationName::Identifier: |
| 758 | case DeclarationName::CXXLiteralOperatorName: |
| 759 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 760 | break; |
| 761 | case DeclarationName::ObjCZeroArgSelector: |
| 762 | case DeclarationName::ObjCOneArgSelector: |
| 763 | case DeclarationName::ObjCMultiArgSelector: |
| 764 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 765 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 766 | case DeclarationName::CXXOperatorName: |
| 767 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 768 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 769 | case DeclarationName::CXXConstructorName: |
| 770 | case DeclarationName::CXXDestructorName: |
| 771 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 772 | case DeclarationName::CXXUsingDirective: |
| 773 | break; |
| 774 | } |
| 775 | |
| 776 | return ID.ComputeHash(); |
| 777 | } |
| 778 | |
| 779 | internal_key_type GetInternalKey(const external_key_type& Name) const { |
| 780 | DeclNameKey Key; |
| 781 | Key.Kind = Name.getNameKind(); |
| 782 | switch (Name.getNameKind()) { |
| 783 | case DeclarationName::Identifier: |
| 784 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 785 | break; |
| 786 | case DeclarationName::ObjCZeroArgSelector: |
| 787 | case DeclarationName::ObjCOneArgSelector: |
| 788 | case DeclarationName::ObjCMultiArgSelector: |
| 789 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 790 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 791 | case DeclarationName::CXXOperatorName: |
| 792 | Key.Data = Name.getCXXOverloadedOperator(); |
| 793 | break; |
| 794 | case DeclarationName::CXXLiteralOperatorName: |
| 795 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 796 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 797 | case DeclarationName::CXXConstructorName: |
| 798 | case DeclarationName::CXXDestructorName: |
| 799 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 800 | case DeclarationName::CXXUsingDirective: |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 801 | Key.Data = 0; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 802 | break; |
| 803 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 804 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 805 | return Key; |
| 806 | } |
| 807 | |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 808 | external_key_type GetExternalKey(const internal_key_type& Key) const { |
| 809 | ASTContext *Context = Reader.getContext(); |
| 810 | switch (Key.Kind) { |
| 811 | case DeclarationName::Identifier: |
| 812 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 813 | |
| 814 | case DeclarationName::ObjCZeroArgSelector: |
| 815 | case DeclarationName::ObjCOneArgSelector: |
| 816 | case DeclarationName::ObjCMultiArgSelector: |
| 817 | return DeclarationName(Selector(Key.Data)); |
| 818 | |
| 819 | case DeclarationName::CXXConstructorName: |
| 820 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 821 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 822 | |
| 823 | case DeclarationName::CXXDestructorName: |
| 824 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 825 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 826 | |
| 827 | case DeclarationName::CXXConversionFunctionName: |
| 828 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 829 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 830 | |
| 831 | case DeclarationName::CXXOperatorName: |
| 832 | return Context->DeclarationNames.getCXXOperatorName( |
| 833 | (OverloadedOperatorKind)Key.Data); |
| 834 | |
| 835 | case DeclarationName::CXXLiteralOperatorName: |
| 836 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 837 | (IdentifierInfo*)Key.Data); |
| 838 | |
| 839 | case DeclarationName::CXXUsingDirective: |
| 840 | return DeclarationName::getUsingDirectiveName(); |
| 841 | } |
| 842 | |
| 843 | llvm_unreachable("Invalid Name Kind ?"); |
| 844 | } |
| 845 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 846 | static std::pair<unsigned, unsigned> |
| 847 | ReadKeyDataLength(const unsigned char*& d) { |
| 848 | using namespace clang::io; |
| 849 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 850 | unsigned DataLen = ReadUnalignedLE16(d); |
| 851 | return std::make_pair(KeyLen, DataLen); |
| 852 | } |
| 853 | |
| 854 | internal_key_type ReadKey(const unsigned char* d, unsigned) { |
| 855 | using namespace clang::io; |
| 856 | |
| 857 | DeclNameKey Key; |
| 858 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 859 | switch (Key.Kind) { |
| 860 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 861 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 862 | break; |
| 863 | case DeclarationName::ObjCZeroArgSelector: |
| 864 | case DeclarationName::ObjCOneArgSelector: |
| 865 | case DeclarationName::ObjCMultiArgSelector: |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 866 | Key.Data = |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 867 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 868 | .getAsOpaquePtr(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 869 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 870 | case DeclarationName::CXXOperatorName: |
| 871 | Key.Data = *d++; // OverloadedOperatorKind |
| 872 | break; |
| 873 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 874 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 875 | break; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 876 | case DeclarationName::CXXConstructorName: |
| 877 | case DeclarationName::CXXDestructorName: |
| 878 | case DeclarationName::CXXConversionFunctionName: |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 879 | case DeclarationName::CXXUsingDirective: |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 880 | Key.Data = 0; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 881 | break; |
| 882 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 883 | |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 884 | return Key; |
| 885 | } |
| 886 | |
| 887 | data_type ReadData(internal_key_type, const unsigned char* d, |
| 888 | unsigned DataLen) { |
| 889 | using namespace clang::io; |
| 890 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 891 | DeclID *Start = (DeclID *)d; |
| 892 | return std::make_pair(Start, Start + NumDecls); |
| 893 | } |
| 894 | }; |
| 895 | |
| 896 | } // end anonymous namespace |
| 897 | |
| 898 | /// \brief The on-disk hash table used for the DeclContext's Name lookup table. |
| 899 | typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait> |
| 900 | ASTDeclContextNameLookupTable; |
| 901 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 902 | bool ASTReader::ReadDeclContextStorage(Module &M, |
| 903 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 904 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 905 | DeclContextInfo &Info) { |
| 906 | SavedStreamPosition SavedPosition(Cursor); |
| 907 | // First the lexical decls. |
| 908 | if (Offsets.first != 0) { |
| 909 | Cursor.JumpToBit(Offsets.first); |
| 910 | |
| 911 | RecordData Record; |
| 912 | const char *Blob; |
| 913 | unsigned BlobLen; |
| 914 | unsigned Code = Cursor.ReadCode(); |
| 915 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 916 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 917 | Error("Expected lexical block"); |
| 918 | return true; |
| 919 | } |
| 920 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 921 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 922 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // Now the lookup table. |
| 926 | if (Offsets.second != 0) { |
| 927 | Cursor.JumpToBit(Offsets.second); |
| 928 | |
| 929 | RecordData Record; |
| 930 | const char *Blob; |
| 931 | unsigned BlobLen; |
| 932 | unsigned Code = Cursor.ReadCode(); |
| 933 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 934 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 935 | Error("Expected visible lookup table block"); |
| 936 | return true; |
| 937 | } |
| 938 | Info.NameLookupTableData |
| 939 | = ASTDeclContextNameLookupTable::Create( |
| 940 | (const unsigned char *)Blob + Record[0], |
| 941 | (const unsigned char *)Blob, |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 942 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | return false; |
| 946 | } |
| 947 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 948 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 949 | Error(diag::err_fe_pch_malformed, Msg); |
| 950 | } |
| 951 | |
| 952 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 953 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 954 | if (Diags.isDiagnosticInFlight()) |
| 955 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 956 | else |
| 957 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 960 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 961 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 962 | if (Listener) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 963 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 964 | ActualOriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 965 | SuggestedPredefines, |
| 966 | FileMgr); |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 967 | return false; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 970 | //===----------------------------------------------------------------------===// |
| 971 | // Source Manager Deserialization |
| 972 | //===----------------------------------------------------------------------===// |
| 973 | |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 974 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 975 | /// \returns true if there was an error. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 976 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 977 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 978 | unsigned Idx = 0; |
| 979 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 980 | |
| 981 | // Parse the file names |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 982 | std::map<int, int> FileIDs; |
| 983 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 984 | // Extract the file name |
| 985 | unsigned FilenameLen = Record[Idx++]; |
| 986 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 987 | Idx += FilenameLen; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 988 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 9a6b098 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 989 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | // Parse the line entries |
| 993 | std::vector<LineEntry> Entries; |
| 994 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 995 | int FID = Record[Idx++]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 996 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 997 | // Remap FileID from 1-based old view. |
| 998 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 999 | |
| 1000 | // Extract the line entries |
| 1001 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1002 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1003 | Entries.clear(); |
| 1004 | Entries.reserve(NumEntries); |
| 1005 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1006 | unsigned FileOffset = Record[Idx++]; |
| 1007 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 1008 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 1010 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1011 | unsigned IncludeOffset = Record[Idx++]; |
| 1012 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1013 | FileKind, IncludeOffset)); |
| 1014 | } |
| 1015 | LineTable.AddEntry(FID, Entries); |
| 1016 | } |
| 1017 | |
| 1018 | return false; |
| 1019 | } |
| 1020 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1021 | namespace { |
| 1022 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1023 | class ASTStatData { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1024 | public: |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1025 | const ino_t ino; |
| 1026 | const dev_t dev; |
| 1027 | const mode_t mode; |
| 1028 | const time_t mtime; |
| 1029 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1030 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1031 | ASTStatData(ino_t i, dev_t d, mode_t mo, time_t m, off_t s) |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1032 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1033 | }; |
| 1034 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1035 | class ASTStatLookupTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1036 | public: |
| 1037 | typedef const char *external_key_type; |
| 1038 | typedef const char *internal_key_type; |
| 1039 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1040 | typedef ASTStatData data_type; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1041 | |
| 1042 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 1043 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1047 | |
| 1048 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1049 | return strcmp(a, b) == 0; |
| 1050 | } |
| 1051 | |
| 1052 | static std::pair<unsigned, unsigned> |
| 1053 | ReadKeyDataLength(const unsigned char*& d) { |
| 1054 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1055 | unsigned DataLen = (unsigned) *d++; |
| 1056 | return std::make_pair(KeyLen + 1, DataLen); |
| 1057 | } |
| 1058 | |
| 1059 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1060 | return (const char *)d; |
| 1061 | } |
| 1062 | |
| 1063 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1064 | unsigned /*DataLen*/) { |
| 1065 | using namespace clang::io; |
| 1066 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1067 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 1068 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 1069 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1070 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1071 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 1072 | return data_type(ino, dev, mode, mtime, size); |
| 1073 | } |
| 1074 | }; |
| 1075 | |
| 1076 | /// \brief stat() cache for precompiled headers. |
| 1077 | /// |
| 1078 | /// This cache is very similar to the stat cache used by pretokenized |
| 1079 | /// headers. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1080 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1081 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1082 | CacheTy *Cache; |
| 1083 | |
| 1084 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1085 | public: |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 1086 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 1087 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1088 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 1089 | Cache = CacheTy::Create(Buckets, Base); |
| 1090 | } |
| 1091 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1092 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1093 | |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1094 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 1095 | int *FileDescriptor) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1096 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1097 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1098 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1099 | // 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] | 1100 | if (I == Cache->end()) { |
| 1101 | ++NumStatMisses; |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1102 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1103 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1105 | ++NumStatHits; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1106 | ASTStatData Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1107 | |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1108 | StatBuf.st_ino = Data.ino; |
| 1109 | StatBuf.st_dev = Data.dev; |
| 1110 | StatBuf.st_mtime = Data.mtime; |
| 1111 | StatBuf.st_mode = Data.mode; |
| 1112 | StatBuf.st_size = Data.size; |
Chris Lattner | 8f0583d | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1113 | return CacheExists; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1114 | } |
| 1115 | }; |
| 1116 | } // end anonymous namespace |
| 1117 | |
| 1118 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1119 | /// \brief Read a source manager block |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1120 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1121 | using namespace SrcMgr; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1122 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1123 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1124 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1125 | // Set the source-location entry cursor to the current position in |
| 1126 | // the stream. This cursor will be used to read the contents of the |
| 1127 | // source manager block initially, and then lazily read |
| 1128 | // source-location entries as needed. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1129 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | |
| 1131 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1132 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1133 | Error("malformed block record in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1134 | return Failure; |
| 1135 | } |
| 1136 | |
| 1137 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1138 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1139 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1140 | return Failure; |
| 1141 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1142 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1143 | RecordData Record; |
| 1144 | while (true) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1145 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1146 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1147 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1148 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1149 | return Failure; |
| 1150 | } |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1151 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1152 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1154 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1155 | // No known subblocks, always skip them. |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1156 | SLocEntryCursor.ReadSubBlockID(); |
| 1157 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1158 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1159 | return Failure; |
| 1160 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1161 | continue; |
| 1162 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1163 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1164 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1165 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1166 | continue; |
| 1167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1169 | // Read a record. |
| 1170 | const char *BlobStart; |
| 1171 | unsigned BlobLen; |
| 1172 | Record.clear(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1173 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1174 | default: // Default behavior: ignore. |
| 1175 | break; |
| 1176 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1177 | case SM_SLOC_FILE_ENTRY: |
| 1178 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1179 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1180 | // Once we hit one of the source location entries, we're done. |
| 1181 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1186 | /// \brief If a header file is not found at the path that we expect it to be |
| 1187 | /// and the PCH file was moved from its original location, try to resolve the |
| 1188 | /// file by assuming that header+PCH were moved together and the header is in |
| 1189 | /// the same place relative to the PCH. |
| 1190 | static std::string |
| 1191 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1192 | const std::string &OriginalDir, |
| 1193 | const std::string &CurrDir) { |
| 1194 | assert(OriginalDir != CurrDir && |
| 1195 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1196 | using namespace llvm::sys; |
| 1197 | llvm::SmallString<128> filePath(Filename); |
| 1198 | fs::make_absolute(filePath); |
| 1199 | assert(path::is_absolute(OriginalDir)); |
| 1200 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1201 | |
| 1202 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1203 | fileDirE = path::end(path::parent_path(filePath)); |
| 1204 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1205 | origDirE = path::end(OriginalDir); |
| 1206 | // Skip the common path components from filePath and OriginalDir. |
| 1207 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1208 | *fileDirI == *origDirI) { |
| 1209 | ++fileDirI; |
| 1210 | ++origDirI; |
| 1211 | } |
| 1212 | for (; origDirI != origDirE; ++origDirI) |
| 1213 | path::append(currPCHPath, ".."); |
| 1214 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1215 | path::append(currPCHPath, path::filename(Filename)); |
| 1216 | return currPCHPath.str(); |
| 1217 | } |
| 1218 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1219 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1220 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1221 | if (ID == 0) |
| 1222 | return Success; |
| 1223 | |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1224 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1225 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1226 | return Failure; |
| 1227 | } |
| 1228 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1229 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1230 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1231 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1232 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1233 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1234 | ++NumSLocEntriesRead; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1235 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1236 | if (Code == llvm::bitc::END_BLOCK || |
| 1237 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1238 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1239 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1240 | return Failure; |
| 1241 | } |
| 1242 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1243 | RecordData Record; |
| 1244 | const char *BlobStart; |
| 1245 | unsigned BlobLen; |
| 1246 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1247 | default: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1248 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1249 | return Failure; |
| 1250 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1251 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1252 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1253 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1254 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1255 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1256 | OriginalDir != CurrentDir) { |
| 1257 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1258 | OriginalDir, |
| 1259 | CurrentDir); |
| 1260 | if (!resolved.empty()) |
| 1261 | File = FileMgr.getFile(resolved); |
| 1262 | } |
Axel Naumann | 63fbaed | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1263 | if (File == 0) |
| 1264 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1265 | (time_t)Record[5]); |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1266 | if (File == 0) { |
| 1267 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1268 | ErrorStr += Filename; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1269 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1270 | Error(ErrorStr.c_str()); |
| 1271 | return Failure; |
| 1272 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1273 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1274 | if (Record.size() < 6) { |
Ted Kremenek | abb1ddd | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1275 | Error("source location entry is incorrect"); |
| 1276 | return Failure; |
| 1277 | } |
| 1278 | |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1279 | if (!DisableValidation && |
| 1280 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1281 | #if !defined(LLVM_ON_WIN32) |
| 1282 | // In our regression testing, the Windows file system seems to |
| 1283 | // have inconsistent modification times that sometimes |
| 1284 | // erroneously trigger this error-handling path. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1285 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1286 | #endif |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1287 | )) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1288 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1289 | return Failure; |
| 1290 | } |
| 1291 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1292 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1293 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1294 | // This is the module's main file. |
| 1295 | IncludeLoc = getImportLocation(F); |
| 1296 | } |
| 1297 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 26b5c19 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1298 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1299 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1300 | SrcMgr::FileInfo &FileInfo = |
| 1301 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1302 | FileInfo.NumCreatedFIDs = Record[6]; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1303 | if (Record[3]) |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1304 | FileInfo.setHasLineDirectives(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1305 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1306 | break; |
| 1307 | } |
| 1308 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1309 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1310 | const char *Name = BlobStart; |
| 1311 | unsigned Offset = Record[0]; |
| 1312 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1313 | Record.clear(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1314 | unsigned RecCode |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1315 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1316 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1317 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1318 | Error("AST record has invalid code"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1319 | return Failure; |
| 1320 | } |
| 1321 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1322 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1323 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1324 | Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1325 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1326 | BaseOffset + Offset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1328 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1329 | PCHPredefinesBlock Block = { |
| 1330 | BufferID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1331 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1332 | }; |
| 1333 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1334 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1335 | |
| 1336 | break; |
| 1337 | } |
| 1338 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1339 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1340 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | 115b077 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1341 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1342 | ReadSourceLocation(*F, Record[2]), |
| 1343 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1344 | Record[4], |
| 1345 | ID, |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1346 | BaseOffset + Record[0]); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1347 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1348 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | return Success; |
| 1352 | } |
| 1353 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1354 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1355 | SourceLocation ASTReader::getImportLocation(Module *F) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1356 | if (F->ImportLoc.isValid()) |
| 1357 | return F->ImportLoc; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1358 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1359 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1360 | // location of its includer. |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1361 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1362 | // Main file is the importer. We assume that it is the first entry in the |
| 1363 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1364 | // the main file entry doesn't exist yet. |
| 1365 | // The very first entry is the invalid instantiation loc, which takes up |
| 1366 | // offsets 0 and 1. |
| 1367 | return SourceLocation::getFromRawEncoding(2U); |
| 1368 | } |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1369 | //return F->Loaders[0]->FirstLoc; |
| 1370 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1373 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1374 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1375 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1376 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1377 | unsigned BlockID) { |
| 1378 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1379 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1380 | return Failure; |
| 1381 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1383 | while (true) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1384 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1385 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1386 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1387 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1388 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1389 | Cursor.JumpToBit(Offset); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1390 | return false; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1391 | } |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1392 | Cursor.ReadAbbrevRecord(); |
| 1393 | } |
| 1394 | } |
| 1395 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1396 | void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1397 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1398 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1400 | // Keep track of where we are in the stream, then jump back there |
| 1401 | // after reading this macro. |
| 1402 | SavedStreamPosition SavedPosition(Stream); |
| 1403 | |
| 1404 | Stream.JumpToBit(Offset); |
| 1405 | RecordData Record; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1406 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1407 | MacroInfo *Macro = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1408 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1409 | while (true) { |
| 1410 | unsigned Code = Stream.ReadCode(); |
| 1411 | switch (Code) { |
| 1412 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1413 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1414 | |
| 1415 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1416 | // No known subblocks, always skip them. |
| 1417 | Stream.ReadSubBlockID(); |
| 1418 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1419 | Error("malformed block record in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1420 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1421 | } |
| 1422 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1424 | case llvm::bitc::DEFINE_ABBREV: |
| 1425 | Stream.ReadAbbrevRecord(); |
| 1426 | continue; |
| 1427 | default: break; |
| 1428 | } |
| 1429 | |
| 1430 | // Read a record. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1431 | const char *BlobStart = 0; |
| 1432 | unsigned BlobLen = 0; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1433 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1434 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1435 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1436 | BlobLen); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1437 | switch (RecType) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1438 | case PP_MACRO_OBJECT_LIKE: |
| 1439 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1440 | // If we already have a macro, that means that we've hit the end |
| 1441 | // of the definition of the macro we were looking for. We're |
| 1442 | // done. |
| 1443 | if (Macro) |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1444 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1445 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1446 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1447 | if (II == 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1448 | Error("macro must have a name in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1449 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1450 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1451 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1452 | bool isUsed = Record[2]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1453 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1454 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1455 | MI->setIsUsed(isUsed); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1456 | MI->setIsFromAST(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1457 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1458 | unsigned NextIndex = 3; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1459 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1460 | // Decode function-like macro info. |
| 1461 | bool isC99VarArgs = Record[3]; |
| 1462 | bool isGNUVarArgs = Record[4]; |
| 1463 | MacroArgs.clear(); |
| 1464 | unsigned NumArgs = Record[5]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1465 | NextIndex = 6 + NumArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1466 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1467 | MacroArgs.push_back(getLocalIdentifier(F, Record[6+i])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1468 | |
| 1469 | // Install function-like macro info. |
| 1470 | MI->setIsFunctionLike(); |
| 1471 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1472 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1473 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1474 | PP->getPreprocessorAllocator()); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | // Finally, install the macro. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1478 | PP->setMacroInfo(II, MI); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1479 | |
| 1480 | // Remember that we saw this macro last so that we add the tokens that |
| 1481 | // form its body to it. |
| 1482 | Macro = MI; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1483 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1484 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1485 | // We have a macro definition. Load it now. |
| 1486 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1487 | getLocalMacroDefinition(F, Record[NextIndex])); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1488 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1489 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1490 | ++NumMacrosRead; |
| 1491 | break; |
| 1492 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1493 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1494 | case PP_TOKEN: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1495 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1496 | // erroneous, just pretend we didn't see this. |
| 1497 | if (Macro == 0) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1499 | Token Tok; |
| 1500 | Tok.startToken(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1501 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1502 | Tok.setLength(Record[1]); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1503 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1504 | Tok.setIdentifierInfo(II); |
| 1505 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1506 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1507 | Macro->AddTokenToBody(Tok); |
| 1508 | break; |
| 1509 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1510 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1511 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1512 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1513 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1516 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1517 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1518 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1519 | switch (Code) { |
| 1520 | case llvm::bitc::END_BLOCK: |
| 1521 | return 0; |
| 1522 | |
| 1523 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1524 | Error("unexpected subblock record in preprocessor detail block"); |
| 1525 | return 0; |
| 1526 | |
| 1527 | case llvm::bitc::DEFINE_ABBREV: |
| 1528 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1529 | return 0; |
| 1530 | |
| 1531 | default: |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | if (!PP->getPreprocessingRecord()) { |
| 1536 | Error("no preprocessing record"); |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | // Read the record. |
| 1541 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1542 | const char *BlobStart = 0; |
| 1543 | unsigned BlobLen = 0; |
| 1544 | RecordData Record; |
| 1545 | PreprocessorDetailRecordTypes RecType = |
| 1546 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1547 | Code, Record, BlobStart, BlobLen); |
| 1548 | switch (RecType) { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1549 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1550 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1551 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1552 | return PE; |
| 1553 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1554 | MacroExpansion *ME = |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1555 | new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1556 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1557 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1558 | getLocalMacroDefinition(F, Record[4])); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1559 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ME); |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1560 | return ME; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | case PPD_MACRO_DEFINITION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1564 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1565 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1566 | return PE; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1567 | |
| 1568 | unsigned MacroDefID = getGlobalMacroDefinitionID(F, Record[1]); |
| 1569 | if (MacroDefID > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1570 | Error("out-of-bounds macro definition record"); |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
| 1574 | // Decode the identifier info and then check again; if the macro is |
| 1575 | // still defined and associated with the identifier, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1576 | IdentifierInfo *II = getLocalIdentifier(F, Record[4]); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1577 | if (!MacroDefinitionsLoaded[MacroDefID - 1]) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1578 | MacroDefinition *MD |
| 1579 | = new (PPRec) MacroDefinition(II, |
| 1580 | ReadSourceLocation(F, Record[5]), |
| 1581 | SourceRange( |
| 1582 | ReadSourceLocation(F, Record[2]), |
| 1583 | ReadSourceLocation(F, Record[3]))); |
| 1584 | |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1585 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, MD); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1586 | MacroDefinitionsLoaded[MacroDefID - 1] = MD; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1587 | |
| 1588 | if (DeserializationListener) |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1589 | DeserializationListener->MacroDefinitionRead(MacroDefID, MD); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1592 | return MacroDefinitionsLoaded[MacroDefID - 1]; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | case PPD_INCLUSION_DIRECTIVE: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1596 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1597 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1598 | return PE; |
| 1599 | |
| 1600 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1601 | const FileEntry *File |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1602 | = PP->getFileManager().getFile(StringRef(FullFileNameStart, |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1603 | BlobLen - Record[3])); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1604 | |
| 1605 | // FIXME: Stable encoding |
| 1606 | InclusionDirective::InclusionKind Kind |
| 1607 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1608 | InclusionDirective *ID |
| 1609 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1610 | StringRef(BlobStart, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1611 | Record[4], |
| 1612 | File, |
| 1613 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1614 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1615 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ID); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1616 | return ID; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | Error("invalid offset in preprocessor detail block"); |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1624 | PreprocessedEntityID |
| 1625 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) { |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1626 | ContinuousRangeMap<uint32_t, int, 2>::iterator |
| 1627 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1628 | assert(I != M.PreprocessedEntityRemap.end() |
| 1629 | && "Invalid index into preprocessed entity index remap"); |
| 1630 | |
| 1631 | return LocalID + I->second; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1634 | namespace { |
| 1635 | /// \brief Trait class used to search the on-disk hash table containing all of |
| 1636 | /// the header search information. |
| 1637 | /// |
| 1638 | /// The on-disk hash table contains a mapping from each header path to |
| 1639 | /// information about that header (how many times it has been included, its |
| 1640 | /// controlling macro, etc.). Note that we actually hash based on the |
| 1641 | /// filename, and support "deep" comparisons of file names based on current |
| 1642 | /// inode numbers, so that the search can cope with non-normalized path names |
| 1643 | /// and symlinks. |
| 1644 | class HeaderFileInfoTrait { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1645 | ASTReader &Reader; |
| 1646 | Module &M; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1647 | HeaderSearch *HS; |
| 1648 | const char *FrameworkStrings; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1649 | const char *SearchPath; |
| 1650 | struct stat SearchPathStatBuf; |
| 1651 | llvm::Optional<int> SearchPathStatResult; |
| 1652 | |
| 1653 | int StatSimpleCache(const char *Path, struct stat *StatBuf) { |
| 1654 | if (Path == SearchPath) { |
| 1655 | if (!SearchPathStatResult) |
| 1656 | SearchPathStatResult = stat(Path, &SearchPathStatBuf); |
| 1657 | |
| 1658 | *StatBuf = SearchPathStatBuf; |
| 1659 | return *SearchPathStatResult; |
| 1660 | } |
| 1661 | |
| 1662 | return stat(Path, StatBuf); |
| 1663 | } |
| 1664 | |
| 1665 | public: |
| 1666 | typedef const char *external_key_type; |
| 1667 | typedef const char *internal_key_type; |
| 1668 | |
| 1669 | typedef HeaderFileInfo data_type; |
| 1670 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1671 | HeaderFileInfoTrait(ASTReader &Reader, Module &M, HeaderSearch *HS, |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1672 | const char *FrameworkStrings, |
| 1673 | const char *SearchPath = 0) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1674 | : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings), |
| 1675 | SearchPath(SearchPath) { } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1676 | |
| 1677 | static unsigned ComputeHash(const char *path) { |
| 1678 | return llvm::HashString(llvm::sys::path::filename(path)); |
| 1679 | } |
| 1680 | |
| 1681 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 1682 | |
| 1683 | bool EqualKey(internal_key_type a, internal_key_type b) { |
| 1684 | if (strcmp(a, b) == 0) |
| 1685 | return true; |
| 1686 | |
| 1687 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1688 | return false; |
| 1689 | |
| 1690 | // The file names match, but the path names don't. stat() the files to |
| 1691 | // see if they are the same. |
| 1692 | struct stat StatBufA, StatBufB; |
| 1693 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1694 | return false; |
| 1695 | |
| 1696 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1697 | } |
| 1698 | |
| 1699 | static std::pair<unsigned, unsigned> |
| 1700 | ReadKeyDataLength(const unsigned char*& d) { |
| 1701 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1702 | unsigned DataLen = (unsigned) *d++; |
| 1703 | return std::make_pair(KeyLen + 1, DataLen); |
| 1704 | } |
| 1705 | |
| 1706 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 1707 | return (const char *)d; |
| 1708 | } |
| 1709 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1710 | data_type ReadData(const internal_key_type, const unsigned char *d, |
| 1711 | unsigned DataLen) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1712 | const unsigned char *End = d + DataLen; |
| 1713 | using namespace clang::io; |
| 1714 | HeaderFileInfo HFI; |
| 1715 | unsigned Flags = *d++; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1716 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1717 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1718 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1719 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1720 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1721 | HFI.NumIncludes = ReadUnalignedLE16(d); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1722 | HFI.ControllingMacroID = Reader.getGlobalDeclID(M, ReadUnalignedLE32(d)); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1723 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1724 | // The framework offset is 1 greater than the actual offset, |
| 1725 | // since 0 is used as an indicator for "no framework name". |
| 1726 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1727 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1728 | } |
| 1729 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1730 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1731 | (void)End; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1732 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1733 | // This HeaderFileInfo was externally loaded. |
| 1734 | HFI.External = true; |
| 1735 | return HFI; |
| 1736 | } |
| 1737 | }; |
| 1738 | } |
| 1739 | |
| 1740 | /// \brief The on-disk hash table used for the global method pool. |
| 1741 | typedef OnDiskChainedHashTable<HeaderFileInfoTrait> |
| 1742 | HeaderFileInfoLookupTable; |
| 1743 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1744 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1745 | uint64_t LocalOffset) { |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1746 | // Note that this identifier has a macro definition. |
| 1747 | II->setHasMacroDefinition(true); |
| 1748 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1749 | // Adjust the offset to a global offset. |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1750 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1753 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1754 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1755 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1756 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1757 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1758 | // If there was no preprocessor block, skip this file. |
| 1759 | if (!MacroCursor.getBitStreamReader()) |
| 1760 | continue; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1761 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1762 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1763 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1764 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1765 | RecordData Record; |
| 1766 | while (true) { |
| 1767 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1768 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1769 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1770 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1771 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1772 | // No known subblocks, always skip them. |
| 1773 | Cursor.ReadSubBlockID(); |
| 1774 | if (Cursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1775 | Error("malformed block record in AST file"); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1776 | return; |
| 1777 | } |
| 1778 | continue; |
| 1779 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1780 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1781 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1782 | Cursor.ReadAbbrevRecord(); |
| 1783 | continue; |
| 1784 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1785 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1786 | // Read a record. |
| 1787 | const char *BlobStart; |
| 1788 | unsigned BlobLen; |
| 1789 | Record.clear(); |
| 1790 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1791 | default: // Default behavior: ignore. |
| 1792 | break; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1793 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1794 | case PP_MACRO_OBJECT_LIKE: |
| 1795 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1796 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1797 | break; |
| 1798 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1799 | case PP_TOKEN: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1800 | // Ignore tokens. |
| 1801 | break; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1802 | } |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1803 | } |
| 1804 | } |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1805 | |
| 1806 | // Drain the unread macro-record offsets map. |
| 1807 | while (!UnreadMacroRecordOffsets.empty()) |
| 1808 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1809 | } |
| 1810 | |
| 1811 | void ASTReader::LoadMacroDefinition( |
| 1812 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1813 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1814 | uint64_t Offset = Pos->second; |
| 1815 | UnreadMacroRecordOffsets.erase(Pos); |
| 1816 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1817 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1818 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1822 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1823 | = UnreadMacroRecordOffsets.find(II); |
| 1824 | LoadMacroDefinition(Pos); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1827 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1828 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1829 | return 0; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1830 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1831 | if (!MacroDefinitionsLoaded[ID - 1]) { |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 1832 | GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID); |
| 1833 | assert(I != GlobalMacroDefinitionMap.end() && |
| 1834 | "Corrupted global macro definition map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1835 | Module &M = *I->second; |
| 1836 | unsigned Index = ID - 1 - M.BaseMacroDefinitionID; |
| 1837 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 1838 | M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]); |
| 1839 | LoadPreprocessedEntity(M); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1842 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1845 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1846 | std::string Filename = filenameStrRef; |
| 1847 | MaybeAddSystemRootToFilename(Filename); |
| 1848 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1849 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1850 | OriginalDir != CurrentDir) { |
| 1851 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1852 | OriginalDir, |
| 1853 | CurrentDir); |
| 1854 | if (!resolved.empty()) |
| 1855 | File = FileMgr.getFile(resolved); |
| 1856 | } |
| 1857 | |
| 1858 | return File; |
| 1859 | } |
| 1860 | |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1861 | MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) { |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1862 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 1863 | return LocalID; |
| 1864 | |
| 1865 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 1866 | = M.MacroDefinitionRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 1867 | assert(I != M.MacroDefinitionRemap.end() && |
| 1868 | "Invalid index into macro definition ID remap"); |
| 1869 | |
| 1870 | return LocalID + I->second; |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1873 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1874 | /// not an absolute path, add the system root to the beginning of the file |
| 1875 | /// name. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1876 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1877 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1878 | if (!RelocatablePCH) |
| 1879 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1880 | |
Michael J. Spencer | f28df4c | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1881 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1882 | return; |
| 1883 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1884 | if (isysroot.empty()) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1885 | // If no system root was given, default to '/' |
| 1886 | Filename.insert(Filename.begin(), '/'); |
| 1887 | return; |
| 1888 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1890 | unsigned Length = isysroot.size(); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1891 | if (isysroot[Length - 1] != '/') |
| 1892 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1893 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1894 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1897 | ASTReader::ASTReadResult |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1898 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1899 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1900 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1901 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1902 | Error("malformed block record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1903 | return Failure; |
| 1904 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1905 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1906 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1907 | RecordData Record; |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1908 | bool First = true; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1909 | while (!Stream.AtEndOfStream()) { |
| 1910 | unsigned Code = Stream.ReadCode(); |
| 1911 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1912 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1913 | Error("error at end of module block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1914 | return Failure; |
| 1915 | } |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1916 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1917 | return Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1921 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1922 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1923 | // We lazily load the decls block, but we want to set up the |
| 1924 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1925 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1926 | // With the main cursor, we just skip over it. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1927 | F.DeclsCursor = Stream; |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1928 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1929 | // Read the abbrevs. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1930 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1931 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1932 | return Failure; |
| 1933 | } |
| 1934 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1935 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1936 | case DECL_UPDATES_BLOCK_ID: |
| 1937 | if (Stream.SkipBlock()) { |
| 1938 | Error("malformed block record in AST file"); |
| 1939 | return Failure; |
| 1940 | } |
| 1941 | break; |
| 1942 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1943 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1944 | F.MacroCursor = Stream; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1945 | if (PP) |
| 1946 | PP->setExternalSource(this); |
| 1947 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1948 | if (Stream.SkipBlock() || |
| 1949 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1950 | Error("malformed block record in AST file"); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1951 | return Failure; |
| 1952 | } |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1953 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1954 | break; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1955 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1956 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1957 | F.PreprocessorDetailCursor = Stream; |
| 1958 | if (Stream.SkipBlock() || |
| 1959 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1960 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1961 | Error("malformed preprocessor detail record in AST file"); |
| 1962 | return Failure; |
| 1963 | } |
| 1964 | F.PreprocessorDetailStartOffset |
| 1965 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1966 | break; |
| 1967 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1968 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1969 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1970 | case Success: |
| 1971 | break; |
| 1972 | |
| 1973 | case Failure: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1974 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1975 | return Failure; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1976 | |
| 1977 | case IgnorePCH: |
| 1978 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1979 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1980 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1981 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1982 | First = false; |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1983 | continue; |
| 1984 | } |
| 1985 | |
| 1986 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1987 | Stream.ReadAbbrevRecord(); |
| 1988 | continue; |
| 1989 | } |
| 1990 | |
| 1991 | // Read and process a record. |
| 1992 | Record.clear(); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1993 | const char *BlobStart = 0; |
| 1994 | unsigned BlobLen = 0; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1995 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1996 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1997 | default: // Default behavior: ignore. |
| 1998 | break; |
| 1999 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2000 | case METADATA: { |
| 2001 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2002 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2003 | : diag::warn_pch_version_too_new); |
| 2004 | return IgnorePCH; |
| 2005 | } |
| 2006 | |
| 2007 | RelocatablePCH = Record[4]; |
| 2008 | if (Listener) { |
| 2009 | std::string TargetTriple(BlobStart, BlobLen); |
| 2010 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 2011 | return IgnorePCH; |
| 2012 | } |
| 2013 | break; |
| 2014 | } |
| 2015 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 2016 | case IMPORTS: { |
| 2017 | // Load each of the imported PCH files. |
| 2018 | unsigned Idx = 0, N = Record.size(); |
| 2019 | while (Idx < N) { |
| 2020 | // Read information about the AST file. |
| 2021 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2022 | unsigned Length = Record[Idx++]; |
| 2023 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 2024 | Record.begin() + Idx + Length); |
| 2025 | Idx += Length; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 2027 | // Load the AST file. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2028 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 2029 | case Failure: return Failure; |
| 2030 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 2031 | case IgnorePCH: return IgnorePCH; |
| 2032 | case Success: break; |
| 2033 | } |
| 2034 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2035 | break; |
| 2036 | } |
| 2037 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2038 | case TYPE_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2039 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2040 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2041 | return Failure; |
| 2042 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2043 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 2044 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2045 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2046 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 2047 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2048 | if (F.LocalNumTypes > 0) { |
| 2049 | // Introduce the global -> local mapping for types within this module. |
| 2050 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 2051 | |
| 2052 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2053 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 2054 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2055 | |
| 2056 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 2057 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2058 | break; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2061 | case DECL_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2062 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2063 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2064 | return Failure; |
| 2065 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 2066 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 2067 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2068 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2069 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2070 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2071 | if (F.LocalNumDecls > 0) { |
| 2072 | // Introduce the global -> local mapping for declarations within this |
| 2073 | // module. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2074 | GlobalDeclMap.insert( |
| 2075 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2076 | |
| 2077 | // Introduce the local -> global mapping for declarations within this |
| 2078 | // module. |
| 2079 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 2080 | F.BaseDeclID - LocalBaseDeclID)); |
| 2081 | |
| 2082 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2083 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 2084 | break; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2087 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2088 | DeclContext *TU = Context ? Context->getTranslationUnitDecl() : 0; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2089 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 2090 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 2091 | Info.NumLexicalDecls |
| 2092 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2093 | if (TU) |
| 2094 | TU->setHasExternalLexicalStorage(true); |
| 2095 | |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 2096 | break; |
| 2097 | } |
| 2098 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2099 | case UPDATE_VISIBLE: { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2100 | unsigned Idx = 0; |
| 2101 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2102 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2103 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2104 | (const unsigned char *)BlobStart, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2105 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2106 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID && Context) { // Is it the TU? |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2107 | DeclContext *TU = Context->getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2108 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2109 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2110 | } else |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2111 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 2112 | break; |
| 2113 | } |
| 2114 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2115 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2116 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2117 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 2118 | DeclID First = ReadDeclID(F, Record, i); |
| 2119 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2120 | FirstLatestDeclIDs[First] = Latest; |
| 2121 | } |
| 2122 | break; |
| 2123 | } |
| 2124 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2125 | case LANGUAGE_OPTIONS: |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 2126 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2127 | return IgnorePCH; |
| 2128 | break; |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2129 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2130 | case IDENTIFIER_TABLE: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2131 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2132 | if (Record[0]) { |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2133 | F.IdentifierLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2134 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2135 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2136 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 2137 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2138 | if (PP) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2139 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2140 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 2141 | } |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 2142 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2143 | break; |
| 2144 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2145 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2146 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2147 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2148 | return Failure; |
| 2149 | } |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 2150 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2151 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2152 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2153 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2154 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2155 | if (F.LocalNumIdentifiers > 0) { |
| 2156 | // Introduce the global -> local mapping for identifiers within this |
| 2157 | // module. |
| 2158 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2159 | &F)); |
| 2160 | |
| 2161 | // Introduce the local -> global mapping for identifiers within this |
| 2162 | // module. |
| 2163 | F.IdentifierRemap.insert( |
| 2164 | std::make_pair(LocalBaseIdentifierID, |
| 2165 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 2166 | |
| 2167 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2168 | + F.LocalNumIdentifiers); |
| 2169 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2170 | break; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2173 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2174 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2175 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2176 | break; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2177 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2178 | case SPECIAL_TYPES: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2179 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2180 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2181 | break; |
| 2182 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2183 | case STATISTICS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2184 | TotalNumStatements += Record[0]; |
| 2185 | TotalNumMacros += Record[1]; |
| 2186 | TotalLexicalDeclContexts += Record[2]; |
| 2187 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2188 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2189 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2190 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2191 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2192 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2193 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2194 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2195 | case DELEGATING_CTORS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2196 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2197 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2198 | break; |
| 2199 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2200 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2201 | if (Record.size() % 4 != 0) { |
| 2202 | Error("invalid weak identifiers record"); |
| 2203 | return Failure; |
| 2204 | } |
| 2205 | |
| 2206 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2207 | // files. This isn't the way to do it :) |
| 2208 | WeakUndeclaredIdentifiers.clear(); |
| 2209 | |
| 2210 | // Translate the weak, undeclared identifiers into global IDs. |
| 2211 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2212 | WeakUndeclaredIdentifiers.push_back( |
| 2213 | getGlobalIdentifierID(F, Record[I++])); |
| 2214 | WeakUndeclaredIdentifiers.push_back( |
| 2215 | getGlobalIdentifierID(F, Record[I++])); |
| 2216 | WeakUndeclaredIdentifiers.push_back( |
| 2217 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2218 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2219 | } |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2220 | break; |
| 2221 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2222 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2223 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2224 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2225 | break; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2226 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2227 | case SELECTOR_OFFSETS: { |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2228 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2229 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2230 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2231 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2232 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2233 | if (F.LocalNumSelectors > 0) { |
| 2234 | // Introduce the global -> local mapping for selectors within this |
| 2235 | // module. |
| 2236 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2237 | |
| 2238 | // Introduce the local -> global mapping for selectors within this |
| 2239 | // module. |
| 2240 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 2241 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2242 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2243 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2244 | } |
| 2245 | break; |
| 2246 | } |
| 2247 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2248 | case METHOD_POOL: |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2249 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2250 | if (Record[0]) |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2251 | F.SelectorLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2252 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2253 | F.SelectorLookupTableData + Record[0], |
| 2254 | F.SelectorLookupTableData, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2255 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2256 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2257 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2258 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2259 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2260 | if (!Record.empty()) { |
| 2261 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2262 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2263 | Record[Idx++])); |
| 2264 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2265 | getRawEncoding()); |
| 2266 | } |
| 2267 | } |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2268 | break; |
| 2269 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2270 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2271 | if (!Record.empty() && Listener) |
| 2272 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2273 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2274 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2275 | case SOURCE_LOCATION_OFFSETS: { |
| 2276 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2277 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2278 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2279 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2280 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2281 | // we invert it. Because we invert it, though, we need the other end of |
| 2282 | // the range. |
| 2283 | unsigned RangeStart = |
| 2284 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2285 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2286 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2287 | |
| 2288 | // Initialize the remapping table. |
| 2289 | // Invalid stays invalid. |
| 2290 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2291 | // This module. Base was 2 when being compiled. |
| 2292 | F.SLocRemap.insert(std::make_pair(2U, |
| 2293 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2294 | |
| 2295 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2296 | break; |
| 2297 | } |
| 2298 | |
Douglas Gregor | 5a1797c | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2299 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2300 | // Additional remapping information. |
| 2301 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2302 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2303 | |
| 2304 | // Continuous range maps we may be updating in our module. |
| 2305 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2306 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2307 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2308 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2309 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2310 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2311 | MacroDefinitionRemap(F.MacroDefinitionRemap); |
| 2312 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2313 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2314 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2315 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2316 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2317 | while(Data < DataEnd) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2318 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2319 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2320 | Data += Len; |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2321 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2322 | if (!OM) { |
| 2323 | Error("SourceLocation remap refers to unknown module"); |
| 2324 | return Failure; |
| 2325 | } |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2326 | |
| 2327 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2328 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2329 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
| 2330 | uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data); |
| 2331 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2332 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2333 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2334 | |
| 2335 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2336 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2337 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2338 | IdentifierRemap.insert( |
| 2339 | std::make_pair(IdentifierIDOffset, |
| 2340 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2341 | PreprocessedEntityRemap.insert( |
| 2342 | std::make_pair(PreprocessedEntityIDOffset, |
| 2343 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2344 | MacroDefinitionRemap.insert( |
| 2345 | std::make_pair(MacroDefinitionIDOffset, |
| 2346 | OM->BaseMacroDefinitionID - MacroDefinitionIDOffset)); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2347 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2348 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2349 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2350 | OM->BaseDeclID - DeclIDOffset)); |
| 2351 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2352 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2353 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2354 | } |
| 2355 | break; |
| 2356 | } |
| 2357 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2358 | case SOURCE_MANAGER_LINE_TABLE: |
| 2359 | if (ParseLineTable(F, Record)) |
| 2360 | return Failure; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2361 | break; |
| 2362 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2363 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2364 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2365 | F.LocalNumSLocFileEntries = Record[0]; |
| 2366 | break; |
| 2367 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2368 | case SOURCE_LOCATION_PRELOADS: { |
| 2369 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2370 | // which is based off F.SLocEntryBaseID. |
| 2371 | PreloadSLocEntries.reserve(PreloadSLocEntries.size() + Record.size()); |
| 2372 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2373 | PreloadSLocEntries.push_back(int(Record[I] - 1) + F.SLocEntryBaseID); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2374 | break; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2375 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2376 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2377 | case STAT_CACHE: { |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2378 | if (!DisableStatCache) { |
| 2379 | ASTStatCache *MyStatCache = |
| 2380 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2381 | (const unsigned char *)BlobStart, |
| 2382 | NumStatHits, NumStatMisses); |
| 2383 | FileMgr.addStatCache(MyStatCache); |
| 2384 | F.StatCache = MyStatCache; |
| 2385 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2386 | break; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2387 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2388 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2389 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2390 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2391 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2392 | break; |
| 2393 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2394 | case VTABLE_USES: |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2395 | if (Record.size() % 3 != 0) { |
| 2396 | Error("Invalid VTABLE_USES record"); |
| 2397 | return Failure; |
| 2398 | } |
| 2399 | |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2400 | // Later tables overwrite earlier ones. |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2401 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2402 | // the right way to do this. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2403 | VTableUses.clear(); |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2404 | |
| 2405 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2406 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2407 | VTableUses.push_back( |
| 2408 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2409 | VTableUses.push_back(Record[Idx++]); |
| 2410 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2411 | break; |
| 2412 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2413 | case DYNAMIC_CLASSES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2414 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2415 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2416 | break; |
| 2417 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2418 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | bbbc367 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2419 | if (PendingInstantiations.size() % 2 != 0) { |
| 2420 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2421 | return Failure; |
| 2422 | } |
| 2423 | |
| 2424 | // Later lists of pending instantiations overwrite earlier ones. |
| 2425 | // FIXME: This is most certainly wrong for modules. |
| 2426 | PendingInstantiations.clear(); |
| 2427 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2428 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2429 | PendingInstantiations.push_back( |
| 2430 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2431 | } |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2432 | break; |
| 2433 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2434 | case SEMA_DECL_REFS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2435 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2436 | // FIXME: Modules will have some trouble with this. |
| 2437 | SemaDeclRefs.clear(); |
| 2438 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2439 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2440 | break; |
| 2441 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2442 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2443 | // 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] | 2444 | // that's used. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2445 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2446 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2447 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2448 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2449 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2450 | case ORIGINAL_FILE_ID: |
| 2451 | OriginalFileID = FileID::get(Record[0]); |
| 2452 | break; |
| 2453 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2454 | case ORIGINAL_PCH_DIR: |
| 2455 | // The primary AST will be the last to get here, so it will be the one |
| 2456 | // that's used. |
| 2457 | OriginalDir.assign(BlobStart, BlobLen); |
| 2458 | break; |
| 2459 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2460 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 8bd0929 | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2461 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2462 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2463 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2464 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2465 | return IgnorePCH; |
| 2466 | } |
| 2467 | break; |
| 2468 | } |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2469 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2470 | case MACRO_DEFINITION_OFFSETS: { |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2471 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2472 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2473 | unsigned LocalBasePreprocessedEntityID = Record[1]; |
| 2474 | F.LocalNumMacroDefinitions = Record[2]; |
| 2475 | unsigned LocalBaseMacroID = Record[3]; |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2476 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2477 | unsigned StartingID; |
| 2478 | if (PP) { |
| 2479 | if (!PP->getPreprocessingRecord()) |
| 2480 | PP->createPreprocessingRecord(true); |
| 2481 | if (!PP->getPreprocessingRecord()->getExternalSource()) |
| 2482 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2483 | StartingID |
| 2484 | = PP->getPreprocessingRecord() |
| 2485 | ->allocateLoadedEntities(F.NumPreallocatedPreprocessingEntities); |
| 2486 | } else { |
| 2487 | // FIXME: We'll eventually want to kill this path, since it assumes |
| 2488 | // a particular allocation strategy in the preprocessing record. |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2489 | StartingID = getTotalNumPreprocessedEntities() |
| 2490 | - F.NumPreallocatedPreprocessingEntities; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2491 | } |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2492 | F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); |
| 2493 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2494 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2495 | if (F.NumPreallocatedPreprocessingEntities > 0) { |
| 2496 | // Introduce the global -> local mapping for preprocessed entities in |
| 2497 | // this module. |
| 2498 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2499 | |
| 2500 | // Introduce the local -> global mapping for preprocessed entities in |
| 2501 | // this module. |
| 2502 | F.PreprocessedEntityRemap.insert( |
| 2503 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2504 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2505 | } |
| 2506 | |
| 2507 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2508 | if (F.LocalNumMacroDefinitions > 0) { |
| 2509 | // Introduce the global -> local mapping for macro definitions within |
| 2510 | // this module. |
| 2511 | GlobalMacroDefinitionMap.insert( |
| 2512 | std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); |
| 2513 | |
| 2514 | // Introduce the local -> global mapping for macro definitions within |
| 2515 | // this module. |
| 2516 | F.MacroDefinitionRemap.insert( |
| 2517 | std::make_pair(LocalBaseMacroID, |
| 2518 | F.BaseMacroDefinitionID - LocalBaseMacroID)); |
| 2519 | |
| 2520 | MacroDefinitionsLoaded.resize( |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 2521 | MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2524 | break; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2527 | case DECL_UPDATE_OFFSETS: { |
| 2528 | if (Record.size() % 2 != 0) { |
| 2529 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2530 | return Failure; |
| 2531 | } |
| 2532 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2533 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2534 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | } |
| 2537 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2538 | case DECL_REPLACEMENTS: { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2539 | if (Record.size() % 2 != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2540 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2541 | return Failure; |
| 2542 | } |
| 2543 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2544 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2545 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2546 | break; |
| 2547 | } |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2548 | |
| 2549 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2550 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2551 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2552 | return Failure; |
| 2553 | } |
| 2554 | |
| 2555 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2556 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2557 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2558 | break; |
| 2559 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2560 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2561 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2562 | if (Record.size() % 2 != 0) { |
| 2563 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2564 | return Failure; |
| 2565 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2566 | |
| 2567 | if (F.PragmaDiagMappings.empty()) |
| 2568 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2569 | else |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2570 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2571 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2572 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2573 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2574 | case CUDA_SPECIAL_DECL_REFS: |
| 2575 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2576 | // FIXME: Modules will have trouble with this. |
| 2577 | CUDASpecialDeclRefs.clear(); |
| 2578 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2579 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2580 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2581 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2582 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2583 | F.HeaderFileInfoTableData = BlobStart; |
| 2584 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2585 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2586 | if (Record[0]) { |
| 2587 | F.HeaderFileInfoTable |
| 2588 | = HeaderFileInfoLookupTable::Create( |
| 2589 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2590 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2591 | HeaderFileInfoTrait(*this, F, |
| 2592 | PP? &PP->getHeaderSearchInfo() : 0, |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2593 | BlobStart + Record[2])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2594 | if (PP) |
| 2595 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2596 | } |
| 2597 | break; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2600 | case FP_PRAGMA_OPTIONS: |
| 2601 | // Later tables overwrite earlier ones. |
| 2602 | FPPragmaOptions.swap(Record); |
| 2603 | break; |
| 2604 | |
| 2605 | case OPENCL_EXTENSIONS: |
| 2606 | // Later tables overwrite earlier ones. |
| 2607 | OpenCLExtensions.swap(Record); |
| 2608 | break; |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2609 | |
| 2610 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2611 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2612 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2613 | break; |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2614 | |
| 2615 | case KNOWN_NAMESPACES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2616 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2617 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2618 | break; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2619 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2620 | First = false; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2621 | } |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2622 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2623 | return Failure; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2626 | ASTReader::ASTReadResult ASTReader::validateFileEntries() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2627 | for (ModuleIterator I = ModuleMgr.begin(), |
| 2628 | E = ModuleMgr.end(); I != E; ++I) { |
| 2629 | Module *F = *I; |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2630 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
| 2631 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2632 | for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) { |
| 2633 | SLocEntryCursor.JumpToBit(F->SLocFileOffsets[i]); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2634 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2635 | if (Code == llvm::bitc::END_BLOCK || |
| 2636 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2637 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2638 | Error("incorrectly-formatted source location entry in AST file"); |
| 2639 | return Failure; |
| 2640 | } |
| 2641 | |
| 2642 | RecordData Record; |
| 2643 | const char *BlobStart; |
| 2644 | unsigned BlobLen; |
| 2645 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2646 | default: |
| 2647 | Error("incorrectly-formatted source location entry in AST file"); |
| 2648 | return Failure; |
| 2649 | |
| 2650 | case SM_SLOC_FILE_ENTRY: { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2651 | StringRef Filename(BlobStart, BlobLen); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2652 | const FileEntry *File = getFileEntry(Filename); |
| 2653 | |
| 2654 | if (File == 0) { |
| 2655 | std::string ErrorStr = "could not find file '"; |
| 2656 | ErrorStr += Filename; |
| 2657 | ErrorStr += "' referenced by AST file"; |
| 2658 | Error(ErrorStr.c_str()); |
| 2659 | return IgnorePCH; |
| 2660 | } |
| 2661 | |
| 2662 | if (Record.size() < 6) { |
| 2663 | Error("source location entry is incorrect"); |
| 2664 | return Failure; |
| 2665 | } |
| 2666 | |
| 2667 | // The stat info from the FileEntry came from the cached stat |
| 2668 | // info of the PCH, so we cannot trust it. |
| 2669 | struct stat StatBuf; |
| 2670 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2671 | StatBuf.st_size = File->getSize(); |
| 2672 | StatBuf.st_mtime = File->getModificationTime(); |
| 2673 | } |
| 2674 | |
| 2675 | if (((off_t)Record[4] != StatBuf.st_size |
| 2676 | #if !defined(LLVM_ON_WIN32) |
| 2677 | // In our regression testing, the Windows file system seems to |
| 2678 | // have inconsistent modification times that sometimes |
| 2679 | // erroneously trigger this error-handling path. |
| 2680 | || (time_t)Record[5] != StatBuf.st_mtime |
| 2681 | #endif |
| 2682 | )) { |
| 2683 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2684 | return IgnorePCH; |
| 2685 | } |
| 2686 | |
| 2687 | break; |
| 2688 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2689 | } |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | return Success; |
| 2694 | } |
| 2695 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2696 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2697 | ModuleKind Type) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2698 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2699 | case Failure: return Failure; |
| 2700 | case IgnorePCH: return IgnorePCH; |
| 2701 | case Success: break; |
| 2702 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2703 | |
| 2704 | // Here comes stuff that we only do once the entire chain is loaded. |
| 2705 | |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2706 | if (!DisableValidation) { |
| 2707 | switch(validateFileEntries()) { |
| 2708 | case Failure: return Failure; |
| 2709 | case IgnorePCH: return IgnorePCH; |
| 2710 | case Success: break; |
| 2711 | } |
| 2712 | } |
| 2713 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2714 | // Preload SLocEntries. |
| 2715 | for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) { |
| 2716 | ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]); |
| 2717 | if (Result != Success) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2718 | return Failure; |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2719 | } |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2720 | PreloadSLocEntries.clear(); |
| 2721 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2722 | // Check the predefines buffers. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2723 | if (!DisableValidation && Type != MK_Module && CheckPredefinesBuffers()) |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2724 | return IgnorePCH; |
| 2725 | |
| 2726 | if (PP) { |
| 2727 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2728 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2729 | // loaded into the IdentifierTable before we intercepted the |
| 2730 | // creation of identifiers. Iterate through the list of known |
| 2731 | // identifiers and determine whether we have to establish |
| 2732 | // preprocessor definitions or top-level identifier declaration |
| 2733 | // chains for those identifiers. |
| 2734 | // |
| 2735 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2736 | // since de-serializing declarations or macro definitions can add |
| 2737 | // new entries into the identifier table, invalidating the |
| 2738 | // iterators. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2739 | // |
| 2740 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2741 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2742 | // AST file(s) if it is uttered in the source. This could save us some |
| 2743 | // module load time. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2744 | SmallVector<IdentifierInfo *, 128> Identifiers; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2745 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2746 | IdEnd = PP->getIdentifierTable().end(); |
| 2747 | Id != IdEnd; ++Id) |
| 2748 | Identifiers.push_back(Id->second); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2749 | // We need to search the tables in all files. |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2750 | for (ModuleIterator J = ModuleMgr.begin(), |
| 2751 | M = ModuleMgr.end(); J != M; ++J) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2752 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2753 | = (ASTIdentifierLookupTable *)(*J)->IdentifierLookupTable; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2754 | // Not all AST files necessarily have identifier tables, only the useful |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 2755 | // ones. |
| 2756 | if (!IdTable) |
| 2757 | continue; |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2758 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2759 | IdentifierInfo *II = Identifiers[I]; |
| 2760 | // Look in the on-disk hash tables for an entry for this identifier |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2761 | ASTIdentifierLookupTrait Info(*this, *(*J), II); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2762 | std::pair<const char*,unsigned> Key(II->getNameStart(),II->getLength()); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2763 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Info); |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2764 | if (Pos == IdTable->end()) |
| 2765 | continue; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2766 | |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2767 | // Dereferencing the iterator has the effect of populating the |
| 2768 | // IdentifierInfo node with the various declarations it needs. |
| 2769 | (void)*Pos; |
| 2770 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | |
| 2774 | if (Context) |
| 2775 | InitializeContext(*Context); |
| 2776 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2777 | if (DeserializationListener) |
| 2778 | DeserializationListener->ReaderInitialized(this); |
| 2779 | |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2780 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2781 | // the source manager to the file source file from which the preamble was |
| 2782 | // built. This is the only valid way to use a precompiled preamble. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2783 | if (Type == MK_Preamble) { |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2784 | if (OriginalFileID.isInvalid()) { |
| 2785 | SourceLocation Loc |
| 2786 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2787 | if (Loc.isValid()) |
| 2788 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2789 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2790 | else { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2791 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2792 | + OriginalFileID.getOpaqueValue() - 1); |
| 2793 | } |
| 2794 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2795 | if (!OriginalFileID.isInvalid()) |
| 2796 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2797 | } |
| 2798 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2799 | return Success; |
| 2800 | } |
| 2801 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2802 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2803 | ModuleKind Type, |
| 2804 | Module *ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2805 | Module *M; |
| 2806 | bool NewModule; |
| 2807 | std::string ErrorStr; |
| 2808 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2809 | ErrorStr); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2810 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2811 | if (!M) { |
| 2812 | // We couldn't load the module. |
| 2813 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2814 | + ErrorStr; |
| 2815 | Error(Msg); |
| 2816 | return Failure; |
| 2817 | } |
| 2818 | |
| 2819 | if (!NewModule) { |
| 2820 | // We've already loaded this module. |
| 2821 | return Success; |
| 2822 | } |
| 2823 | |
| 2824 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2825 | // module? |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2826 | if (FileName != "-") { |
| 2827 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2828 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2829 | } |
| 2830 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2831 | Module &F = *M; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2832 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2833 | Stream.init(F.StreamFile); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2834 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2835 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2836 | // Sniff for the signature. |
| 2837 | if (Stream.Read(8) != 'C' || |
| 2838 | Stream.Read(8) != 'P' || |
| 2839 | Stream.Read(8) != 'C' || |
| 2840 | Stream.Read(8) != 'H') { |
| 2841 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2842 | return Failure; |
| 2843 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2844 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2845 | while (!Stream.AtEndOfStream()) { |
| 2846 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2847 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2848 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2849 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2850 | return Failure; |
| 2851 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2852 | |
| 2853 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2854 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2855 | // We only know the AST subblock ID. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2856 | switch (BlockID) { |
| 2857 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2858 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2859 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2860 | return Failure; |
| 2861 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2862 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2863 | case AST_BLOCK_ID: |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2864 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2865 | case Success: |
| 2866 | break; |
| 2867 | |
| 2868 | case Failure: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2869 | return Failure; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2870 | |
| 2871 | case IgnorePCH: |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2872 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2873 | // AST block, skipping subblocks, to see if there are other |
| 2874 | // AST blocks elsewhere. |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2875 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2876 | // FIXME: We can't clear loaded slocentries anymore. |
| 2877 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2878 | |
| 2879 | // Remove the stat cache. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2880 | if (F.StatCache) |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2881 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2882 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2883 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2884 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2885 | break; |
| 2886 | default: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2887 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2888 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2889 | return Failure; |
| 2890 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2891 | break; |
| 2892 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2893 | } |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2894 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2895 | // Once read, set the Module bit base offset and update the size in |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2896 | // bits of all files we've seen. |
| 2897 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2898 | TotalModulesSizeInBits += F.SizeInBits; |
| 2899 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2900 | return Success; |
| 2901 | } |
| 2902 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2903 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2904 | PP = &pp; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2905 | |
| 2906 | if (unsigned N = getTotalNumPreprocessedEntities()) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2907 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | 998caea | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2908 | PP->createPreprocessingRecord(true); |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2909 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2910 | PP->getPreprocessingRecord()->allocateLoadedEntities(N); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2911 | } |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2912 | |
| 2913 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2914 | PP->getHeaderSearchInfo().SetExternalSource(this); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2917 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2918 | Context = &Ctx; |
| 2919 | assert(Context && "Passed null context!"); |
| 2920 | |
| 2921 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2922 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2923 | PP->setExternalSource(this); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2924 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2925 | // If we have any update blocks for the TU waiting, we have to add |
| 2926 | // them before we deserialize anything. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2927 | TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2928 | for (ModuleIterator M = ModuleMgr.begin(), MEnd = ModuleMgr.end(); |
| 2929 | M != MEnd; ++M) { |
| 2930 | Module::DeclContextInfosMap::iterator DCU |
| 2931 | = (*M)->DeclContextInfos.find(0); |
| 2932 | if (DCU != (*M)->DeclContextInfos.end()) { |
| 2933 | // Insertion could invalidate map, so grab value first. |
| 2934 | DeclContextInfo Info = DCU->second; |
| 2935 | (*M)->DeclContextInfos.erase(DCU); |
| 2936 | (*M)->DeclContextInfos[TU] = Info; |
| 2937 | } |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2938 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2939 | |
| 2940 | // If there's a listener, notify them that we "read" the translation unit. |
| 2941 | if (DeserializationListener) |
| 2942 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2943 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2944 | // Make sure we load the declaration update records for the translation unit, |
| 2945 | // if there are any. |
| 2946 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
| 2947 | |
| 2948 | // Note that the translation unit has external lexical and visible storage. |
| 2949 | TU->setHasExternalLexicalStorage(true); |
| 2950 | TU->setHasExternalVisibleStorage(true); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2951 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2952 | // FIXME: Find a better way to deal with collisions between these |
| 2953 | // built-in types. Right now, we just ignore the problem. |
| 2954 | |
| 2955 | // Load the special types. |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2956 | if (Context->getBuiltinVaListType().isNull()) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2957 | Context->setBuiltinVaListType( |
| 2958 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2961 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2962 | if (Context->ObjCProtoType.isNull()) |
Douglas Gregor | 09c4aa8 | 2011-08-11 22:04:35 +0000 | [diff] [blame] | 2963 | Context->ObjCProtoType = GetType(Proto); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2964 | } |
| 2965 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2966 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2967 | if (!Context->CFConstantStringTypeDecl) |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2968 | Context->setCFConstantStringType(GetType(String)); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2972 | QualType FileType = GetType(File); |
| 2973 | if (FileType.isNull()) { |
| 2974 | Error("FILE type is NULL"); |
| 2975 | return; |
| 2976 | } |
| 2977 | |
| 2978 | if (!Context->FILEDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2979 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2980 | Context->setFILEDecl(Typedef->getDecl()); |
| 2981 | else { |
| 2982 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2983 | if (!Tag) { |
| 2984 | Error("Invalid FILE type in AST file"); |
| 2985 | return; |
| 2986 | } |
| 2987 | Context->setFILEDecl(Tag->getDecl()); |
| 2988 | } |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2989 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 2993 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2994 | if (Jmp_bufType.isNull()) { |
| 2995 | Error("jmp_buf type is NULL"); |
| 2996 | return; |
| 2997 | } |
| 2998 | |
| 2999 | if (!Context->jmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3000 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 3001 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 3002 | else { |
| 3003 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 3004 | if (!Tag) { |
| 3005 | Error("Invalid jmp_buf type in AST file"); |
| 3006 | return; |
| 3007 | } |
| 3008 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 3009 | } |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 3010 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 3014 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 3015 | if (Sigjmp_bufType.isNull()) { |
| 3016 | Error("sigjmp_buf type is NULL"); |
| 3017 | return; |
| 3018 | } |
| 3019 | |
| 3020 | if (!Context->sigjmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3021 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 3022 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 3023 | else { |
| 3024 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 3025 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 3026 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 3027 | } |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3028 | } |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 3029 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 3030 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 3031 | if (unsigned ObjCIdRedef |
| 3032 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 3033 | if (Context->ObjCIdRedefinitionType.isNull()) |
| 3034 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 3035 | } |
| 3036 | |
| 3037 | if (unsigned ObjCClassRedef |
| 3038 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 3039 | if (Context->ObjCClassRedefinitionType.isNull()) |
| 3040 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 3041 | } |
| 3042 | |
| 3043 | if (unsigned ObjCSelRedef |
| 3044 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 3045 | if (Context->ObjCSelRedefinitionType.isNull()) |
| 3046 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 3047 | } |
| 3048 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3049 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 3050 | |
| 3051 | // If there were any CUDA special declarations, deserialize them. |
| 3052 | if (!CUDASpecialDeclRefs.empty()) { |
| 3053 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 3054 | Context->setcudaConfigureCallDecl( |
| 3055 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 3056 | } |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3059 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3060 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3061 | /// file. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3062 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 71731d6 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 3063 | FileManager &FileMgr, |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 3064 | Diagnostic &Diags) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3065 | // Open the AST file. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3066 | std::string ErrStr; |
| 3067 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 3068 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3069 | if (!Buffer) { |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 3070 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3071 | return std::string(); |
| 3072 | } |
| 3073 | |
| 3074 | // Initialize the stream |
| 3075 | llvm::BitstreamReader StreamFile; |
| 3076 | llvm::BitstreamCursor Stream; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3077 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3078 | (const unsigned char *)Buffer->getBufferEnd()); |
| 3079 | Stream.init(StreamFile); |
| 3080 | |
| 3081 | // Sniff for the signature. |
| 3082 | if (Stream.Read(8) != 'C' || |
| 3083 | Stream.Read(8) != 'P' || |
| 3084 | Stream.Read(8) != 'C' || |
| 3085 | Stream.Read(8) != 'H') { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3086 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3087 | return std::string(); |
| 3088 | } |
| 3089 | |
| 3090 | RecordData Record; |
| 3091 | while (!Stream.AtEndOfStream()) { |
| 3092 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3093 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3094 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 3095 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3096 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3097 | // We only know the AST subblock ID. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3098 | switch (BlockID) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3099 | case AST_BLOCK_ID: |
| 3100 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3101 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3102 | return std::string(); |
| 3103 | } |
| 3104 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3105 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3106 | default: |
| 3107 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3108 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3109 | return std::string(); |
| 3110 | } |
| 3111 | break; |
| 3112 | } |
| 3113 | continue; |
| 3114 | } |
| 3115 | |
| 3116 | if (Code == llvm::bitc::END_BLOCK) { |
| 3117 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3118 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3119 | return std::string(); |
| 3120 | } |
| 3121 | continue; |
| 3122 | } |
| 3123 | |
| 3124 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3125 | Stream.ReadAbbrevRecord(); |
| 3126 | continue; |
| 3127 | } |
| 3128 | |
| 3129 | Record.clear(); |
| 3130 | const char *BlobStart = 0; |
| 3131 | unsigned BlobLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3132 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3133 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3134 | return std::string(BlobStart, BlobLen); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3135 | } |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3136 | |
| 3137 | return std::string(); |
| 3138 | } |
| 3139 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3140 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3141 | /// structure. |
| 3142 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3143 | /// This routine parses the language options from the AST file and then gives |
| 3144 | /// them to the AST listener if one is set. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3145 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3146 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3147 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3148 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3149 | if (Listener) { |
| 3150 | LangOptions LangOpts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3151 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3152 | #define PARSE_LANGOPT(Option) \ |
| 3153 | LangOpts.Option = Record[Idx]; \ |
| 3154 | ++Idx |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3155 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3156 | unsigned Idx = 0; |
| 3157 | PARSE_LANGOPT(Trigraphs); |
| 3158 | PARSE_LANGOPT(BCPLComment); |
| 3159 | PARSE_LANGOPT(DollarIdents); |
| 3160 | PARSE_LANGOPT(AsmPreprocessor); |
| 3161 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 3162 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3163 | PARSE_LANGOPT(ImplicitInt); |
| 3164 | PARSE_LANGOPT(Digraphs); |
| 3165 | PARSE_LANGOPT(HexFloats); |
| 3166 | PARSE_LANGOPT(C99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 3167 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3168 | PARSE_LANGOPT(Microsoft); |
| 3169 | PARSE_LANGOPT(CPlusPlus); |
| 3170 | PARSE_LANGOPT(CPlusPlus0x); |
| 3171 | PARSE_LANGOPT(CXXOperatorNames); |
| 3172 | PARSE_LANGOPT(ObjC1); |
| 3173 | PARSE_LANGOPT(ObjC2); |
| 3174 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 3175 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 3176 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 3177 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 3178 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 3179 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3180 | PARSE_LANGOPT(PascalStrings); |
| 3181 | PARSE_LANGOPT(WritableStrings); |
| 3182 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3183 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3184 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 3185 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 3186 | PARSE_LANGOPT(CXXExceptions); |
| 3187 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 3188 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3189 | PARSE_LANGOPT(NeXTRuntime); |
| 3190 | PARSE_LANGOPT(Freestanding); |
| 3191 | PARSE_LANGOPT(NoBuiltin); |
| 3192 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 3193 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3194 | PARSE_LANGOPT(Blocks); |
| 3195 | PARSE_LANGOPT(EmitAllDecls); |
| 3196 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3197 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 3198 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3199 | PARSE_LANGOPT(HeinousExtensions); |
| 3200 | PARSE_LANGOPT(Optimize); |
| 3201 | PARSE_LANGOPT(OptimizeSize); |
| 3202 | PARSE_LANGOPT(Static); |
| 3203 | PARSE_LANGOPT(PICLevel); |
| 3204 | PARSE_LANGOPT(GNUInline); |
| 3205 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 3206 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3207 | PARSE_LANGOPT(AccessControl); |
| 3208 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 3209 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | a88942a | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 3210 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3211 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 3212 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 3213 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3214 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3215 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3216 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 3217 | PARSE_LANGOPT(CUDA); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 3218 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3219 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | dc1f68d | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 3220 | PARSE_LANGOPT(ElideConstructors); |
| 3221 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | 65b88cd | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 3222 | PARSE_LANGOPT(MRTD); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3223 | PARSE_LANGOPT(ObjCAutoRefCount); |
Douglas Gregor | 49b236a | 2011-08-04 15:46:00 +0000 | [diff] [blame] | 3224 | PARSE_LANGOPT(ObjCInferRelatedReturnType); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3225 | #undef PARSE_LANGOPT |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3226 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3227 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3228 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3229 | |
| 3230 | return false; |
| 3231 | } |
| 3232 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame^] | 3233 | namespace { |
| 3234 | /// \brief Visitor used by ASTReader::ReadPreprocessedEntities() to load |
| 3235 | /// all of the preprocessed entities within a module. |
| 3236 | class ReadPreprocessedEntitiesVisitor { |
| 3237 | ASTReader &Reader; |
| 3238 | |
| 3239 | public: |
| 3240 | explicit ReadPreprocessedEntitiesVisitor(ASTReader &Reader) |
| 3241 | : Reader(Reader) { } |
| 3242 | |
| 3243 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 3244 | if (Preorder) |
| 3245 | return false; |
| 3246 | |
| 3247 | ReadPreprocessedEntitiesVisitor *This |
| 3248 | = static_cast<ReadPreprocessedEntitiesVisitor *>(UserData); |
| 3249 | |
| 3250 | if (!M.PreprocessorDetailCursor.getBitStreamReader()) |
| 3251 | return false; |
| 3252 | |
| 3253 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 3254 | M.PreprocessorDetailCursor.JumpToBit(M.PreprocessorDetailStartOffset); |
| 3255 | while (This->Reader.LoadPreprocessedEntity(M)) { } |
| 3256 | return false; |
| 3257 | } |
| 3258 | }; |
| 3259 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame^] | 3261 | void ASTReader::ReadPreprocessedEntities() { |
| 3262 | ReadPreprocessedEntitiesVisitor Visitor(*this); |
| 3263 | ModuleMgr.visitDepthFirst(&ReadPreprocessedEntitiesVisitor::visit, &Visitor); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3264 | } |
| 3265 | |
Douglas Gregor | 46c5001 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3266 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3267 | RecordLocation Loc = getLocalBitOffset(Offset); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3268 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3269 | // Keep track of where we are in the stream, then jump back there |
| 3270 | // after reading this entity. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3271 | SavedStreamPosition SavedPosition(Loc.F->PreprocessorDetailCursor); |
| 3272 | Loc.F->PreprocessorDetailCursor.JumpToBit(Loc.Offset); |
| 3273 | return LoadPreprocessedEntity(*Loc.F); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3276 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3277 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3278 | Module &F = *(*I); |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 3279 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3280 | HeaderFileInfoTrait Trait(*this, F, &PP->getHeaderSearchInfo(), |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 3281 | F.HeaderFileFrameworkStrings, |
| 3282 | FE->getName()); |
| 3283 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3284 | HeaderFileInfoLookupTable *Table |
| 3285 | = static_cast<HeaderFileInfoLookupTable *>(F.HeaderFileInfoTable); |
| 3286 | if (!Table) |
| 3287 | continue; |
| 3288 | |
| 3289 | // Look in the on-disk hash table for an entry for this file name. |
| 3290 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE->getName(), |
| 3291 | &Trait); |
| 3292 | if (Pos == Table->end()) |
| 3293 | continue; |
| 3294 | |
| 3295 | HeaderFileInfo HFI = *Pos; |
| 3296 | if (Listener) |
| 3297 | Listener->ReadHeaderFileInfo(HFI, FE->getUID()); |
| 3298 | |
| 3299 | return HFI; |
| 3300 | } |
| 3301 | |
| 3302 | return HeaderFileInfo(); |
| 3303 | } |
| 3304 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3305 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3306 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3307 | Module &F = *(*I); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3308 | unsigned Idx = 0; |
| 3309 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3310 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3311 | while (1) { |
| 3312 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3313 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3314 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3315 | break; // Something is messed up but at least avoid infinite loop in |
| 3316 | // release build. |
| 3317 | } |
| 3318 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3319 | if (DiagID == (unsigned)-1) { |
| 3320 | break; // no more diag/map pairs for this location. |
| 3321 | } |
| 3322 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3323 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3324 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3325 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3326 | } |
| 3327 | } |
| 3328 | |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3329 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3330 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3331 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | 3500568 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3332 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3333 | Module *M = I->second; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3334 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3335 | } |
| 3336 | |
| 3337 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3338 | /// |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3339 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3340 | /// routine actually reads the record corresponding to the type at the given |
| 3341 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3342 | /// IDs. |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3343 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3344 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3345 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3346 | |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3347 | // Keep track of where we are in the stream, then jump back there |
| 3348 | // after reading this type. |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3349 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3350 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3351 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3352 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3353 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3354 | Deserializing AType(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3355 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3356 | unsigned Idx = 0; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3357 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3358 | RecordData Record; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3359 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3360 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3361 | case TYPE_EXT_QUAL: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3362 | if (Record.size() != 2) { |
| 3363 | Error("Incorrect encoding of extended qualifier type"); |
| 3364 | return QualType(); |
| 3365 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3366 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3367 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3368 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3369 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3370 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3371 | case TYPE_COMPLEX: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3372 | if (Record.size() != 1) { |
| 3373 | Error("Incorrect encoding of complex type"); |
| 3374 | return QualType(); |
| 3375 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3376 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3377 | return Context->getComplexType(ElemType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3378 | } |
| 3379 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3380 | case TYPE_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3381 | if (Record.size() != 1) { |
| 3382 | Error("Incorrect encoding of pointer type"); |
| 3383 | return QualType(); |
| 3384 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3385 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3386 | return Context->getPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3387 | } |
| 3388 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3389 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3390 | if (Record.size() != 1) { |
| 3391 | Error("Incorrect encoding of block pointer type"); |
| 3392 | return QualType(); |
| 3393 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3394 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3395 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3398 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3399 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3400 | Error("Incorrect encoding of lvalue reference type"); |
| 3401 | return QualType(); |
| 3402 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3403 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3404 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3407 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3408 | if (Record.size() != 1) { |
| 3409 | Error("Incorrect encoding of rvalue reference type"); |
| 3410 | return QualType(); |
| 3411 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3412 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3413 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3416 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | ee776bc | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3417 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3418 | Error("Incorrect encoding of member pointer type"); |
| 3419 | return QualType(); |
| 3420 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3421 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3422 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3423 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3424 | return QualType(); |
| 3425 | |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3426 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3427 | } |
| 3428 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3429 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3430 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3431 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3432 | unsigned IndexTypeQuals = Record[2]; |
| 3433 | unsigned Idx = 3; |
| 3434 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3435 | return Context->getConstantArrayType(ElementType, Size, |
| 3436 | ASM, IndexTypeQuals); |
| 3437 | } |
| 3438 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3439 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3440 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3441 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3442 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3443 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3446 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3447 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3448 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3449 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3450 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3451 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3452 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3453 | ASM, IndexTypeQuals, |
| 3454 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3457 | case TYPE_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3458 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3459 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3460 | return QualType(); |
| 3461 | } |
| 3462 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3463 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3464 | unsigned NumElements = Record[1]; |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3465 | unsigned VecKind = Record[2]; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3466 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3467 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3468 | } |
| 3469 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3470 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3471 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3472 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3473 | return QualType(); |
| 3474 | } |
| 3475 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3476 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3477 | unsigned NumElements = Record[1]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3478 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3481 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3482 | if (Record.size() != 6) { |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3483 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3484 | return QualType(); |
| 3485 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3486 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3487 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3488 | (CallingConv)Record[4], Record[5]); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3489 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3492 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3493 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3494 | |
| 3495 | FunctionProtoType::ExtProtoInfo EPI; |
| 3496 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3497 | /*hasregparm*/ Record[2], |
| 3498 | /*regparm*/ Record[3], |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3499 | static_cast<CallingConv>(Record[4]), |
| 3500 | /*produces*/ Record[5]); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3501 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3502 | unsigned Idx = 6; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3503 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3504 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3505 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3506 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3507 | |
| 3508 | EPI.Variadic = Record[Idx++]; |
| 3509 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3510 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3511 | ExceptionSpecificationType EST = |
| 3512 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3513 | EPI.ExceptionSpecType = EST; |
| 3514 | if (EST == EST_Dynamic) { |
| 3515 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3516 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3517 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3518 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3519 | EPI.Exceptions = Exceptions.data(); |
| 3520 | } else if (EST == EST_ComputedNoexcept) { |
| 3521 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3522 | } |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3523 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3524 | EPI); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3525 | } |
| 3526 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3527 | case TYPE_UNRESOLVED_USING: { |
| 3528 | unsigned Idx = 0; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3529 | return Context->getTypeDeclType( |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3530 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3531 | } |
| 3532 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3533 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3534 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3535 | Error("incorrect encoding of typedef type"); |
| 3536 | return QualType(); |
| 3537 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3538 | unsigned Idx = 0; |
| 3539 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3540 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3541 | if (!Canonical.isNull()) |
| 3542 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3543 | return Context->getTypedefType(Decl, Canonical); |
| 3544 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3545 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3546 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3547 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3548 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3549 | case TYPE_TYPEOF: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3550 | if (Record.size() != 1) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3551 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3552 | return QualType(); |
| 3553 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3554 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3555 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3556 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3557 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3558 | case TYPE_DECLTYPE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3559 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3560 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3561 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3562 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3563 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3564 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 3565 | return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 3566 | } |
| 3567 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3568 | case TYPE_AUTO: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3569 | return Context->getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3570 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3571 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3572 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3573 | Error("incorrect encoding of record type"); |
| 3574 | return QualType(); |
| 3575 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3576 | unsigned Idx = 0; |
| 3577 | bool IsDependent = Record[Idx++]; |
| 3578 | QualType T |
| 3579 | = Context->getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3580 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3581 | return T; |
| 3582 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3583 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3584 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3585 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3586 | Error("incorrect encoding of enum type"); |
| 3587 | return QualType(); |
| 3588 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3589 | unsigned Idx = 0; |
| 3590 | bool IsDependent = Record[Idx++]; |
| 3591 | QualType T |
| 3592 | = Context->getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3593 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3594 | return T; |
| 3595 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3596 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3597 | case TYPE_ATTRIBUTED: { |
| 3598 | if (Record.size() != 3) { |
| 3599 | Error("incorrect encoding of attributed type"); |
| 3600 | return QualType(); |
| 3601 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3602 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3603 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3604 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3605 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3606 | } |
| 3607 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3608 | case TYPE_PAREN: { |
| 3609 | if (Record.size() != 1) { |
| 3610 | Error("incorrect encoding of paren type"); |
| 3611 | return QualType(); |
| 3612 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3613 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3614 | return Context->getParenType(InnerType); |
| 3615 | } |
| 3616 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3617 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | 1732850 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3618 | if (Record.size() != 2) { |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3619 | Error("incorrect encoding of pack expansion type"); |
| 3620 | return QualType(); |
| 3621 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3622 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3623 | if (Pattern.isNull()) |
| 3624 | return QualType(); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3625 | llvm::Optional<unsigned> NumExpansions; |
| 3626 | if (Record[1]) |
| 3627 | NumExpansions = Record[1] - 1; |
| 3628 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3629 | } |
| 3630 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3631 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3632 | unsigned Idx = 0; |
| 3633 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3634 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3635 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3636 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3639 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3640 | unsigned Idx = 0; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3641 | ObjCInterfaceDecl *ItfD |
| 3642 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3643 | return Context->getObjCInterfaceType(ItfD); |
| 3644 | } |
| 3645 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3646 | case TYPE_OBJC_OBJECT: { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3647 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3648 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3649 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3650 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3651 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3652 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3653 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3654 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3655 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3656 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3657 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3658 | QualType Pointee = readType(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3659 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3660 | } |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3661 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3662 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3663 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3664 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3665 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3666 | return |
| 3667 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3668 | Replacement); |
| 3669 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3670 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3671 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3672 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3673 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3674 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3675 | return Context->getSubstTemplateTypeParmPackType( |
| 3676 | cast<TemplateTypeParmType>(Parm), |
| 3677 | ArgPack); |
| 3678 | } |
| 3679 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3680 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3681 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3682 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3683 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3684 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3685 | return |
| 3686 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3687 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3688 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3689 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3690 | unsigned Idx = 0; |
| 3691 | unsigned Depth = Record[Idx++]; |
| 3692 | unsigned Index = Record[Idx++]; |
| 3693 | bool Pack = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3694 | TemplateTypeParmDecl *D |
| 3695 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 3696 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3697 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3698 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3699 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3700 | unsigned Idx = 0; |
| 3701 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3702 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3703 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3704 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3705 | if (!Canon.isNull()) |
| 3706 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3707 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3708 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3709 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3710 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3711 | unsigned Idx = 0; |
| 3712 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3713 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3714 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3715 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3716 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3717 | Args.reserve(NumArgs); |
| 3718 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3719 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3720 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3721 | Args.size(), Args.data()); |
| 3722 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3723 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3724 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3725 | unsigned Idx = 0; |
| 3726 | |
| 3727 | // ArrayType |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3728 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3729 | ArrayType::ArraySizeModifier ASM |
| 3730 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3731 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3732 | |
| 3733 | // DependentSizedArrayType |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3734 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3735 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3736 | |
| 3737 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3738 | IndexTypeQuals, Brackets); |
| 3739 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3740 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3741 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3742 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3743 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3744 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3745 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3746 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3747 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3748 | QualType T; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3749 | if (Underlying.isNull()) |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3750 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3751 | Args.size()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3752 | else |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3753 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3754 | Args.size(), Underlying); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3755 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3756 | return T; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3757 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3758 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3759 | // Suppress a GCC warning |
| 3760 | return QualType(); |
| 3761 | } |
| 3762 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3763 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3764 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3765 | Module &F; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3766 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3767 | const ASTReader::RecordData &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3768 | unsigned &Idx; |
| 3769 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3770 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3771 | unsigned &I) { |
| 3772 | return Reader.ReadSourceLocation(F, R, I); |
| 3773 | } |
| 3774 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3775 | template<typename T> |
| 3776 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3777 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3778 | } |
| 3779 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3780 | public: |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3781 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3782 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3783 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3784 | { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3785 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3786 | // We want compile-time assurance that we've enumerated all of |
| 3787 | // these, so unfortunately we have to declare them first, then |
| 3788 | // define them out-of-line. |
| 3789 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3790 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3791 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3792 | #include "clang/AST/TypeLocNodes.def" |
| 3793 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3794 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3795 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3796 | }; |
| 3797 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3798 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3799 | // nothing to do |
| 3800 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3801 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3802 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3803 | if (TL.needsExtraLocalData()) { |
| 3804 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3805 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3806 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3807 | TL.setModeAttr(Record[Idx++]); |
| 3808 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3809 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3810 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3811 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3812 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3813 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3814 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3815 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3816 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3817 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3818 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3819 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3820 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3821 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3822 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3823 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3824 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3825 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3826 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3827 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3828 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3829 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3830 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3831 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3832 | if (Record[Idx++]) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3833 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3834 | else |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3835 | TL.setSizeExpr(0); |
| 3836 | } |
| 3837 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3838 | VisitArrayTypeLoc(TL); |
| 3839 | } |
| 3840 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3841 | VisitArrayTypeLoc(TL); |
| 3842 | } |
| 3843 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3844 | VisitArrayTypeLoc(TL); |
| 3845 | } |
| 3846 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3847 | DependentSizedArrayTypeLoc TL) { |
| 3848 | VisitArrayTypeLoc(TL); |
| 3849 | } |
| 3850 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3851 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3852 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3853 | } |
| 3854 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3855 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3856 | } |
| 3857 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3858 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3859 | } |
| 3860 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3861 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3862 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3863 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3864 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3865 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3866 | } |
| 3867 | } |
| 3868 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3869 | VisitFunctionTypeLoc(TL); |
| 3870 | } |
| 3871 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3872 | VisitFunctionTypeLoc(TL); |
| 3873 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3874 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3875 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3876 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3877 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3878 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3879 | } |
| 3880 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3881 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3882 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3883 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3884 | } |
| 3885 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3886 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3887 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3888 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3889 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3890 | } |
| 3891 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3892 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3893 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3894 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3895 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3896 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3897 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3898 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3899 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3900 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3901 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3902 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3903 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3904 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3905 | } |
| 3906 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3907 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3908 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3909 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3910 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3911 | if (TL.hasAttrOperand()) { |
| 3912 | SourceRange range; |
| 3913 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3914 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3915 | TL.setAttrOperandParensRange(range); |
| 3916 | } |
| 3917 | if (TL.hasAttrExprOperand()) { |
| 3918 | if (Record[Idx++]) |
| 3919 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3920 | else |
| 3921 | TL.setAttrExprOperand(0); |
| 3922 | } else if (TL.hasAttrEnumOperand()) |
| 3923 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3924 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3925 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3926 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3927 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3928 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3929 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3930 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3931 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3932 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3933 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3934 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3935 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3936 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3937 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3938 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3939 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3940 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3941 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3942 | TL.setArgLocInfo(i, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3943 | Reader.GetTemplateArgumentLocInfo(F, |
| 3944 | TL.getTypePtr()->getArg(i).getKind(), |
| 3945 | Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3946 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3947 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3948 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3949 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3950 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3951 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3952 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3953 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3954 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3955 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3956 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3957 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3958 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3959 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3960 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3961 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3962 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3963 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3964 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3965 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3966 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3967 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3968 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3969 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3970 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3971 | TL.setArgLocInfo(I, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3972 | Reader.GetTemplateArgumentLocInfo(F, |
| 3973 | TL.getTypePtr()->getArg(I).getKind(), |
| 3974 | Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3975 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3976 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3977 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3978 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3979 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3980 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3981 | } |
| 3982 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3983 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3984 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3985 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3986 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3987 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3988 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3989 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3990 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3991 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3992 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3993 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3994 | const RecordData &Record, |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3995 | unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3996 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3997 | if (InfoTy.isNull()) |
| 3998 | return 0; |
| 3999 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4000 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4001 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4002 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4003 | TLR.Visit(TL); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 4004 | return TInfo; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 4005 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4006 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4007 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4008 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 4009 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4010 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4011 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4012 | QualType T; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4013 | switch ((PredefinedTypeIDs)Index) { |
| 4014 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 4015 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 4016 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4017 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4018 | case PREDEF_TYPE_CHAR_U_ID: |
| 4019 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4020 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4021 | T = Context->CharTy; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4022 | break; |
| 4023 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4024 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 4025 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 4026 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 4027 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 4028 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 4029 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 4030 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 4031 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 4032 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 4033 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 4034 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 4035 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 4036 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 4037 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 4038 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 4039 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 4040 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 4041 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4042 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 3199634 | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 4043 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4044 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 4045 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 4046 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 4047 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 4048 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 4049 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4050 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context->getAutoDeductType(); break; |
| 4051 | |
| 4052 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 4053 | T = Context->getAutoRRefDeductType(); |
| 4054 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4058 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4059 | } |
| 4060 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4061 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 4062 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4063 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4064 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 4065 | if (TypesLoaded[Index].isNull()) |
| 4066 | return QualType(); |
| 4067 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4068 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4069 | if (DeserializationListener) |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 4070 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 4071 | TypesLoaded[Index]); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 4072 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4073 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4074 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4077 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4078 | return GetType(getGlobalTypeID(F, LocalID)); |
| 4079 | } |
| 4080 | |
| 4081 | serialization::TypeID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4082 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4083 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 4084 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 4085 | |
| 4086 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 4087 | return LocalID; |
| 4088 | |
| 4089 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4090 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 4091 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 4092 | |
| 4093 | unsigned GlobalIndex = LocalIndex + I->second; |
| 4094 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4095 | } |
| 4096 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4097 | TemplateArgumentLocInfo |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4098 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4099 | TemplateArgument::ArgKind Kind, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4100 | const RecordData &Record, |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4101 | unsigned &Index) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4102 | switch (Kind) { |
| 4103 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4104 | return ReadExpr(F); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4105 | case TemplateArgument::Type: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4106 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4107 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4108 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4109 | Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4110 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4111 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4112 | SourceLocation()); |
| 4113 | } |
| 4114 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4115 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4116 | Index); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4117 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4118 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4119 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4120 | EllipsisLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4121 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4122 | case TemplateArgument::Null: |
| 4123 | case TemplateArgument::Integral: |
| 4124 | case TemplateArgument::Declaration: |
| 4125 | case TemplateArgument::Pack: |
| 4126 | return TemplateArgumentLocInfo(); |
| 4127 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4128 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4129 | return TemplateArgumentLocInfo(); |
| 4130 | } |
| 4131 | |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4132 | TemplateArgumentLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4133 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4134 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4135 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4136 | |
| 4137 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4138 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4139 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4140 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4141 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4142 | Record, Index)); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4143 | } |
| 4144 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4145 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4146 | return GetDecl(ID); |
| 4147 | } |
| 4148 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4149 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 4150 | unsigned &Idx){ |
| 4151 | if (Idx >= Record.size()) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4152 | return 0; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4153 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4154 | unsigned LocalID = Record[Idx++]; |
| 4155 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4159 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4160 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4161 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4162 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4163 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4164 | RecordData Record; |
| 4165 | unsigned Code = Cursor.ReadCode(); |
| 4166 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4167 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4168 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4169 | return 0; |
| 4170 | } |
| 4171 | |
| 4172 | unsigned Idx = 0; |
| 4173 | unsigned NumBases = Record[Idx++]; |
| 4174 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 4175 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4176 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4177 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4178 | return Bases; |
| 4179 | } |
| 4180 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4181 | serialization::DeclID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4182 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4183 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4184 | return LocalID; |
| 4185 | |
| 4186 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4187 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4188 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4189 | |
| 4190 | return LocalID + I->second; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4191 | } |
| 4192 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4193 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4194 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4195 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4196 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4197 | return 0; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4198 | |
| 4199 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 4200 | assert(Context && "No context available?"); |
| 4201 | return Context->getTranslationUnitDecl(); |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4202 | |
| 4203 | case PREDEF_DECL_OBJC_ID_ID: |
| 4204 | assert(Context && "No context available?"); |
| 4205 | return Context->getObjCIdDecl(); |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4206 | |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4207 | case PREDEF_DECL_OBJC_SEL_ID: |
| 4208 | assert(Context && "No context available?"); |
| 4209 | return Context->getObjCSelDecl(); |
| 4210 | |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4211 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 4212 | assert(Context && "No context available?"); |
| 4213 | return Context->getObjCClassDecl(); |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4214 | |
| 4215 | case PREDEF_DECL_INT_128_ID: |
| 4216 | assert(Context && "No context available?"); |
| 4217 | return Context->getInt128Decl(); |
| 4218 | |
| 4219 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 4220 | assert(Context && "No context available?"); |
| 4221 | return Context->getUInt128Decl(); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4224 | return 0; |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4225 | } |
| 4226 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4227 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4228 | |
| 4229 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4230 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4231 | return 0; |
| 4232 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4233 | |
| 4234 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4235 | ReadDeclRecord(ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4236 | if (DeserializationListener) |
| 4237 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4238 | } |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4239 | |
| 4240 | return DeclsLoaded[Index]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4241 | } |
| 4242 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4243 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4244 | const RecordData &Record, |
| 4245 | unsigned &Idx) { |
| 4246 | if (Idx >= Record.size()) { |
| 4247 | Error("Corrupted AST file"); |
| 4248 | return 0; |
| 4249 | } |
| 4250 | |
| 4251 | return getGlobalDeclID(F, Record[Idx++]); |
| 4252 | } |
| 4253 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4254 | /// \brief Resolve the offset of a statement into a statement. |
| 4255 | /// |
| 4256 | /// This operation will read a new statement from the external |
| 4257 | /// source each time it is called, and is meant to be used via a |
| 4258 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4259 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4260 | // Switch case IDs are per Decl. |
| 4261 | ClearSwitchCaseIDs(); |
| 4262 | |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4263 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4264 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4265 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4266 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4267 | } |
| 4268 | |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4269 | namespace { |
| 4270 | class FindExternalLexicalDeclsVisitor { |
| 4271 | ASTReader &Reader; |
| 4272 | const DeclContext *DC; |
| 4273 | bool (*isKindWeWant)(Decl::Kind); |
| 4274 | SmallVectorImpl<Decl*> &Decls; |
| 4275 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4276 | |
| 4277 | public: |
| 4278 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4279 | bool (*isKindWeWant)(Decl::Kind), |
| 4280 | SmallVectorImpl<Decl*> &Decls) |
| 4281 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4282 | { |
| 4283 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4284 | PredefsVisited[I] = false; |
| 4285 | } |
| 4286 | |
| 4287 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4288 | if (Preorder) |
| 4289 | return false; |
| 4290 | |
| 4291 | FindExternalLexicalDeclsVisitor *This |
| 4292 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4293 | |
| 4294 | Module::DeclContextInfosMap::iterator Info |
| 4295 | = M.DeclContextInfos.find(This->DC); |
| 4296 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4297 | return false; |
| 4298 | |
| 4299 | // Load all of the declaration IDs |
| 4300 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4301 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4302 | ID != IDE; ++ID) { |
| 4303 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4304 | continue; |
| 4305 | |
| 4306 | // Don't add predefined declarations to the lexical context more |
| 4307 | // than once. |
| 4308 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4309 | if (This->PredefsVisited[ID->second]) |
| 4310 | continue; |
| 4311 | |
| 4312 | This->PredefsVisited[ID->second] = true; |
| 4313 | } |
| 4314 | |
| 4315 | Decl *D = This->Reader.GetLocalDecl(M, ID->second); |
| 4316 | assert(D && "Null decl in lexical decls"); |
| 4317 | This->Decls.push_back(D); |
| 4318 | } |
| 4319 | |
| 4320 | return false; |
| 4321 | } |
| 4322 | }; |
| 4323 | } |
| 4324 | |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4325 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4326 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4327 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4328 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4329 | // least. Walk all of the modules in the order they were loaded. |
| 4330 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4331 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4332 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4333 | return ELR_Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4336 | namespace { |
| 4337 | /// \brief Module visitor used to perform name lookup into a |
| 4338 | /// declaration context. |
| 4339 | class DeclContextNameLookupVisitor { |
| 4340 | ASTReader &Reader; |
| 4341 | const DeclContext *DC; |
| 4342 | DeclarationName Name; |
| 4343 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4344 | |
| 4345 | public: |
| 4346 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4347 | const DeclContext *DC, DeclarationName Name, |
| 4348 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4349 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4350 | |
| 4351 | static bool visit(Module &M, void *UserData) { |
| 4352 | DeclContextNameLookupVisitor *This |
| 4353 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4354 | |
| 4355 | // Check whether we have any visible declaration information for |
| 4356 | // this context in this module. |
| 4357 | Module::DeclContextInfosMap::iterator Info |
| 4358 | = M.DeclContextInfos.find(This->DC); |
| 4359 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4360 | return false; |
| 4361 | |
| 4362 | // Look for this name within this module. |
| 4363 | ASTDeclContextNameLookupTable *LookupTable = |
| 4364 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4365 | ASTDeclContextNameLookupTable::iterator Pos |
| 4366 | = LookupTable->find(This->Name); |
| 4367 | if (Pos == LookupTable->end()) |
| 4368 | return false; |
| 4369 | |
| 4370 | bool FoundAnything = false; |
| 4371 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4372 | for (; Data.first != Data.second; ++Data.first) { |
| 4373 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4374 | if (!ND) |
| 4375 | continue; |
| 4376 | |
| 4377 | if (ND->getDeclName() != This->Name) { |
| 4378 | assert(!This->Name.getCXXNameType().isNull() && |
| 4379 | "Name mismatch without a type"); |
| 4380 | continue; |
| 4381 | } |
| 4382 | |
| 4383 | // Record this declaration. |
| 4384 | FoundAnything = true; |
| 4385 | This->Decls.push_back(ND); |
| 4386 | } |
| 4387 | |
| 4388 | return FoundAnything; |
| 4389 | } |
| 4390 | }; |
| 4391 | } |
| 4392 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4393 | DeclContext::lookup_result |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4394 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4395 | DeclarationName Name) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4396 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4397 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4398 | if (!Name) |
| 4399 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4400 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4401 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4402 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4403 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4404 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4405 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4406 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4407 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4410 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4411 | assert(Consumer); |
| 4412 | while (!InterestingDecls.empty()) { |
| 4413 | DeclGroupRef DG(InterestingDecls.front()); |
| 4414 | InterestingDecls.pop_front(); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4415 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4416 | } |
| 4417 | } |
| 4418 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4419 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | b985eeb | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4420 | this->Consumer = Consumer; |
| 4421 | |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4422 | if (!Consumer) |
| 4423 | return; |
| 4424 | |
| 4425 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4426 | // Force deserialization of this decl, which will cause it to be queued for |
| 4427 | // passing to the consumer. |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4428 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4429 | } |
Douglas Gregor | f005eac | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4430 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4431 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4432 | } |
| 4433 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4434 | void ASTReader::PrintStats() { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4435 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4436 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4437 | unsigned NumTypesLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4438 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4439 | QualType()); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4440 | unsigned NumDeclsLoaded |
| 4441 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4442 | (Decl *)0); |
| 4443 | unsigned NumIdentifiersLoaded |
| 4444 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4445 | IdentifiersLoaded.end(), |
| 4446 | (IdentifierInfo *)0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4447 | unsigned NumSelectorsLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4448 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4449 | SelectorsLoaded.end(), |
| 4450 | Selector()); |
Douglas Gregor | c3b1dd1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4451 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4452 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4453 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4454 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4455 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4456 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4457 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4458 | if (!TypesLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4459 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4460 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4461 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4462 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4463 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4464 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4465 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4466 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4467 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4468 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4469 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4470 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4471 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4472 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4473 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4474 | if (TotalNumStatements) |
| 4475 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4476 | NumStatementsRead, TotalNumStatements, |
| 4477 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4478 | if (TotalNumMacros) |
| 4479 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4480 | NumMacrosRead, TotalNumMacros, |
| 4481 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4482 | if (TotalLexicalDeclContexts) |
| 4483 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4484 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4485 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4486 | * 100)); |
| 4487 | if (TotalVisibleDeclContexts) |
| 4488 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4489 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4490 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4491 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4492 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4493 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4494 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4495 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4496 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4497 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4498 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4499 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4500 | dump(); |
| 4501 | std::fprintf(stderr, "\n"); |
| 4502 | } |
| 4503 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4504 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4505 | static void |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4506 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4507 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4508 | InitialCapacity> &Map) { |
| 4509 | if (Map.begin() == Map.end()) |
| 4510 | return; |
| 4511 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4512 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4513 | llvm::errs() << Name << ":\n"; |
| 4514 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4515 | I != IEnd; ++I) { |
| 4516 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4517 | << "\n"; |
| 4518 | } |
| 4519 | } |
| 4520 | |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4521 | void ASTReader::dump() { |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4522 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4523 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4524 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4525 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4526 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4527 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4528 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 4529 | dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); |
| 4530 | dumpModuleIDMap("Global preprocessed entity map", |
| 4531 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4532 | |
| 4533 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4534 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4535 | MEnd = ModuleMgr.end(); |
| 4536 | M != MEnd; ++M) |
| 4537 | (*M)->dump(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4540 | /// Return the amount of memory used by memory buffers, breaking down |
| 4541 | /// by heap-backed versus mmap'ed memory. |
| 4542 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4543 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4544 | E = ModuleMgr.end(); I != E; ++I) { |
| 4545 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4546 | size_t bytes = buf->getBufferSize(); |
| 4547 | switch (buf->getBufferKind()) { |
| 4548 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4549 | sizes.malloc_bytes += bytes; |
| 4550 | break; |
| 4551 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4552 | sizes.mmap_bytes += bytes; |
| 4553 | break; |
| 4554 | } |
| 4555 | } |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4556 | } |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4557 | } |
| 4558 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4559 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4560 | SemaObj = &S; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4561 | S.ExternalSource = this; |
| 4562 | |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4563 | // Makes sure any declarations that were deserialized "too early" |
| 4564 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4565 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4566 | if (SemaObj->TUScope) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4567 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4568 | |
| 4569 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4570 | } |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4571 | PreloadedDecls.clear(); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4572 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4573 | // Load the offsets of the declarations that Sema references. |
| 4574 | // They will be lazily deserialized when needed. |
| 4575 | if (!SemaDeclRefs.empty()) { |
| 4576 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | b0f3ae6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4577 | if (!SemaObj->StdNamespace) |
| 4578 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4579 | if (!SemaObj->StdBadAlloc) |
| 4580 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4583 | if (!FPPragmaOptions.empty()) { |
| 4584 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4585 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4586 | } |
| 4587 | |
| 4588 | if (!OpenCLExtensions.empty()) { |
| 4589 | unsigned I = 0; |
| 4590 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4591 | #include "clang/Basic/OpenCLExtensions.def" |
| 4592 | |
| 4593 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4594 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4595 | } |
| 4596 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4597 | namespace { |
| 4598 | /// \brief Visitor class used to look up identifirs in |
| 4599 | class IdentifierLookupVisitor { |
| 4600 | StringRef Name; |
| 4601 | IdentifierInfo *Found; |
| 4602 | public: |
| 4603 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4604 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4605 | static bool visit(Module &M, void *UserData) { |
| 4606 | IdentifierLookupVisitor *This |
| 4607 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 4608 | |
| 4609 | ASTIdentifierLookupTable *IdTable |
| 4610 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 4611 | if (!IdTable) |
| 4612 | return false; |
| 4613 | |
| 4614 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 4615 | This->Name.size()); |
| 4616 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 4617 | if (Pos == IdTable->end()) |
| 4618 | return false; |
| 4619 | |
| 4620 | // Dereferencing the iterator has the effect of building the |
| 4621 | // IdentifierInfo node and populating it with the various |
| 4622 | // declarations it needs. |
| 4623 | This->Found = *Pos; |
| 4624 | return true; |
| 4625 | } |
| 4626 | |
| 4627 | // \brief Retrieve the identifier info found within the module |
| 4628 | // files. |
| 4629 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 4630 | }; |
| 4631 | } |
| 4632 | |
| 4633 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4634 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4635 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4636 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4637 | } |
| 4638 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4639 | namespace clang { |
| 4640 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4641 | /// identifiers stored within a set of AST files. |
| 4642 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4643 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4644 | const ASTReader &Reader; |
| 4645 | |
| 4646 | /// \brief The current index into the chain of AST files stored in |
| 4647 | /// the AST reader. |
| 4648 | unsigned Index; |
| 4649 | |
| 4650 | /// \brief The current position within the identifier lookup table |
| 4651 | /// of the current AST file. |
| 4652 | ASTIdentifierLookupTable::key_iterator Current; |
| 4653 | |
| 4654 | /// \brief The end position within the identifier lookup table of |
| 4655 | /// the current AST file. |
| 4656 | ASTIdentifierLookupTable::key_iterator End; |
| 4657 | |
| 4658 | public: |
| 4659 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4660 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4661 | virtual StringRef Next(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4662 | }; |
| 4663 | } |
| 4664 | |
| 4665 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4666 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4667 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4668 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4669 | Current = IdTable->key_begin(); |
| 4670 | End = IdTable->key_end(); |
| 4671 | } |
| 4672 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4673 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4674 | while (Current == End) { |
| 4675 | // If we have exhausted all of our AST files, we're done. |
| 4676 | if (Index == 0) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4677 | return StringRef(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4678 | |
| 4679 | --Index; |
| 4680 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4681 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4682 | IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4683 | Current = IdTable->key_begin(); |
| 4684 | End = IdTable->key_end(); |
| 4685 | } |
| 4686 | |
| 4687 | // We have any identifiers remaining in the current AST file; return |
| 4688 | // the next one. |
| 4689 | std::pair<const char*, unsigned> Key = *Current; |
| 4690 | ++Current; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4691 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4695 | return new ASTIdentifierIterator(*this); |
| 4696 | } |
| 4697 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4698 | namespace clang { namespace serialization { |
| 4699 | class ReadMethodPoolVisitor { |
| 4700 | ASTReader &Reader; |
| 4701 | Selector Sel; |
| 4702 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4703 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4704 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4705 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4706 | /// declarations. |
| 4707 | ObjCMethodList |
| 4708 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4709 | { |
| 4710 | ObjCMethodList List; |
| 4711 | ObjCMethodList *Prev = 0; |
| 4712 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4713 | if (!List.Method) { |
| 4714 | // This is the first method, which is the easy case. |
| 4715 | List.Method = Vec[I]; |
| 4716 | Prev = &List; |
| 4717 | continue; |
| 4718 | } |
| 4719 | |
| 4720 | ObjCMethodList *Mem = |
| 4721 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4722 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4723 | Prev = Prev->Next; |
| 4724 | } |
| 4725 | |
| 4726 | return List; |
| 4727 | } |
| 4728 | |
| 4729 | public: |
| 4730 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4731 | : Reader(Reader), Sel(Sel) { } |
| 4732 | |
| 4733 | static bool visit(Module &M, void *UserData) { |
| 4734 | ReadMethodPoolVisitor *This |
| 4735 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4736 | |
| 4737 | if (!M.SelectorLookupTable) |
| 4738 | return false; |
| 4739 | |
| 4740 | ASTSelectorLookupTable *PoolTable |
| 4741 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4742 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4743 | if (Pos == PoolTable->end()) |
| 4744 | return false; |
| 4745 | |
| 4746 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4747 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4748 | // disable this tracking when called via LoadSelector. |
| 4749 | // Also, should entries without methods count as misses? |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4750 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4751 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4752 | if (This->Reader.DeserializationListener) |
| 4753 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4754 | This->Sel); |
| 4755 | |
| 4756 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4757 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4758 | return true; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4759 | } |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4760 | |
| 4761 | /// \brief Retrieve the instance methods found by this visitor. |
| 4762 | ObjCMethodList getInstanceMethods() const { |
| 4763 | return buildObjCMethodList(InstanceMethods); |
| 4764 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4765 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4766 | /// \brief Retrieve the instance methods found by this visitor. |
| 4767 | ObjCMethodList getFactoryMethods() const { |
| 4768 | return buildObjCMethodList(FactoryMethods); |
| 4769 | } |
| 4770 | }; |
| 4771 | } } // end namespace clang::serialization |
| 4772 | |
| 4773 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4774 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4775 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4776 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4777 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4778 | Result.first = Visitor.getInstanceMethods(); |
| 4779 | Result.second = Visitor.getFactoryMethods(); |
| 4780 | |
| 4781 | if (!Result.first.Method && !Result.second.Method) |
| 4782 | ++NumMethodPoolMisses; |
| 4783 | return Result; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4784 | } |
| 4785 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4786 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4787 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4788 | Namespaces.clear(); |
| 4789 | |
| 4790 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4791 | if (NamespaceDecl *Namespace |
| 4792 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4793 | Namespaces.push_back(Namespace); |
| 4794 | } |
| 4795 | } |
| 4796 | |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4797 | void ASTReader::ReadTentativeDefinitions( |
| 4798 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4799 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4800 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4801 | if (Var) |
| 4802 | TentativeDefs.push_back(Var); |
| 4803 | } |
| 4804 | TentativeDefinitions.clear(); |
| 4805 | } |
| 4806 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4807 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4808 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4809 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4810 | DeclaratorDecl *D |
| 4811 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4812 | if (D) |
| 4813 | Decls.push_back(D); |
| 4814 | } |
| 4815 | UnusedFileScopedDecls.clear(); |
| 4816 | } |
| 4817 | |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4818 | void ASTReader::ReadDelegatingConstructors( |
| 4819 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4820 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4821 | CXXConstructorDecl *D |
| 4822 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4823 | if (D) |
| 4824 | Decls.push_back(D); |
| 4825 | } |
| 4826 | DelegatingCtorDecls.clear(); |
| 4827 | } |
| 4828 | |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4829 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4830 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4831 | TypedefNameDecl *D |
| 4832 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4833 | if (D) |
| 4834 | Decls.push_back(D); |
| 4835 | } |
| 4836 | ExtVectorDecls.clear(); |
| 4837 | } |
| 4838 | |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4839 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4840 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4841 | CXXRecordDecl *D |
| 4842 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4843 | if (D) |
| 4844 | Decls.push_back(D); |
| 4845 | } |
| 4846 | DynamicClasses.clear(); |
| 4847 | } |
| 4848 | |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4849 | void |
| 4850 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4851 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4852 | NamedDecl *D |
| 4853 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4854 | if (D) |
| 4855 | Decls.push_back(D); |
| 4856 | } |
| 4857 | LocallyScopedExternalDecls.clear(); |
| 4858 | } |
| 4859 | |
Douglas Gregor | 72e357f | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4860 | void ASTReader::ReadReferencedSelectors( |
| 4861 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4862 | if (ReferencedSelectorsData.empty()) |
| 4863 | return; |
| 4864 | |
| 4865 | // If there are @selector references added them to its pool. This is for |
| 4866 | // implementation of -Wselector. |
| 4867 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4868 | unsigned I = 0; |
| 4869 | while (I < DataSize) { |
| 4870 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4871 | SourceLocation SelLoc |
| 4872 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4873 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4874 | } |
| 4875 | ReferencedSelectorsData.clear(); |
| 4876 | } |
| 4877 | |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4878 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4879 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4880 | if (WeakUndeclaredIdentifiers.empty()) |
| 4881 | return; |
| 4882 | |
| 4883 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4884 | IdentifierInfo *WeakId |
| 4885 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4886 | IdentifierInfo *AliasId |
| 4887 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4888 | SourceLocation Loc |
| 4889 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4890 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4891 | WeakInfo WI(AliasId, Loc); |
| 4892 | WI.setUsed(Used); |
| 4893 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4894 | } |
| 4895 | WeakUndeclaredIdentifiers.clear(); |
| 4896 | } |
| 4897 | |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4898 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4899 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4900 | ExternalVTableUse VT; |
| 4901 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4902 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4903 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4904 | VTables.push_back(VT); |
| 4905 | } |
| 4906 | |
| 4907 | VTableUses.clear(); |
| 4908 | } |
| 4909 | |
Douglas Gregor | e39f97c | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4910 | void ASTReader::ReadPendingInstantiations( |
| 4911 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4912 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4913 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4914 | SourceLocation Loc |
| 4915 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4916 | Pending.push_back(std::make_pair(D, Loc)); |
| 4917 | } |
| 4918 | PendingInstantiations.clear(); |
| 4919 | } |
| 4920 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4921 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4922 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4923 | ReadMethodPool(Sel); |
| 4924 | } |
| 4925 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4926 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4927 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4928 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4929 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4930 | if (DeserializationListener) |
| 4931 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4934 | /// \brief Set the globally-visible declarations associated with the given |
| 4935 | /// identifier. |
| 4936 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4937 | /// 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] | 4938 | /// 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] | 4939 | /// them. |
| 4940 | /// |
| 4941 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4942 | /// declarations. |
| 4943 | /// |
| 4944 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4945 | /// visible at global scope. |
| 4946 | /// |
| 4947 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4948 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4949 | /// will not be placed onto the pending queue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4950 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4951 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4952 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4953 | bool Nonrecursive) { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4954 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4955 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4956 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4957 | PII.II = II; |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4958 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4959 | return; |
| 4960 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4961 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4962 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4963 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4964 | if (SemaObj) { |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4965 | if (SemaObj->TUScope) { |
| 4966 | // Introduce this declaration into the translation-unit scope |
| 4967 | // and add it to the declaration chain for this identifier, so |
| 4968 | // that (unqualified) name lookup will find it. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4969 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4970 | } |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4971 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4972 | } else { |
| 4973 | // Queue this declaration so that it will be added to the |
| 4974 | // translation unit scope and identifier's declaration chain |
| 4975 | // once a Sema object is known. |
| 4976 | PreloadedDecls.push_back(D); |
| 4977 | } |
| 4978 | } |
| 4979 | } |
| 4980 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4981 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4982 | if (ID == 0) |
| 4983 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4984 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4985 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4986 | Error("no identifier table in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4987 | return 0; |
| 4988 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4989 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4990 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4991 | ID -= 1; |
| 4992 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4993 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4994 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4995 | Module *M = I->second; |
| 4996 | unsigned Index = ID - M->BaseIdentifierID; |
| 4997 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4998 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4999 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 5000 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | ca42a51 | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 5001 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 5002 | // unsigned integers. This is important to avoid integer overflow when |
| 5003 | // we cast them to 'unsigned'. |
Ted Kremenek | 49c5232 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 5004 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 5005 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 5006 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5007 | IdentifiersLoaded[ID] |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5008 | = &PP->getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5009 | if (DeserializationListener) |
| 5010 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5011 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5012 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 5013 | return IdentifiersLoaded[ID]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5014 | } |
| 5015 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5016 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 5017 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 5018 | } |
| 5019 | |
| 5020 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 5021 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 5022 | return LocalID; |
| 5023 | |
| 5024 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5025 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 5026 | assert(I != M.IdentifierRemap.end() |
| 5027 | && "Invalid index into identifier index remap"); |
| 5028 | |
| 5029 | return LocalID + I->second; |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5030 | } |
| 5031 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5032 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 49f754f | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 5033 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5036 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 5037 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 5038 | } |
| 5039 | |
| 5040 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5041 | if (ID == 0) |
| 5042 | return Selector(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5043 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5044 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 5045 | Error("selector ID out of range in AST file"); |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5046 | return Selector(); |
| 5047 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5048 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5049 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5050 | // Load this selector from the selector table. |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5051 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 5052 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5053 | Module &M = *I->second; |
| 5054 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5055 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5056 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 5057 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 5058 | if (DeserializationListener) |
| 5059 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5062 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5065 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5066 | return DecodeSelector(ID); |
| 5067 | } |
| 5068 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5069 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 5070 | // ID 0 (the null selector) is considered an external selector. |
| 5071 | return getTotalNumSelectors() + 1; |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 5074 | serialization::SelectorID |
| 5075 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 5076 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 5077 | return LocalID; |
| 5078 | |
| 5079 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 5080 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 5081 | assert(I != M.SelectorRemap.end() |
| 5082 | && "Invalid index into identifier index remap"); |
| 5083 | |
| 5084 | return LocalID + I->second; |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5087 | DeclarationName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5088 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5089 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5090 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 5091 | switch (Kind) { |
| 5092 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5093 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5094 | |
| 5095 | case DeclarationName::ObjCZeroArgSelector: |
| 5096 | case DeclarationName::ObjCOneArgSelector: |
| 5097 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 5098 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5099 | |
| 5100 | case DeclarationName::CXXConstructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5101 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5102 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5103 | |
| 5104 | case DeclarationName::CXXDestructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5105 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5106 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5107 | |
| 5108 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5109 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5110 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5111 | |
| 5112 | case DeclarationName::CXXOperatorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 5113 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5114 | (OverloadedOperatorKind)Record[Idx++]); |
| 5115 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5116 | case DeclarationName::CXXLiteralOperatorName: |
| 5117 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5118 | GetIdentifierInfo(F, Record, Idx)); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5119 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5120 | case DeclarationName::CXXUsingDirective: |
| 5121 | return DeclarationName::getUsingDirectiveName(); |
| 5122 | } |
| 5123 | |
| 5124 | // Required to silence GCC warning |
| 5125 | return DeclarationName(); |
| 5126 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5127 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5128 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5129 | DeclarationNameLoc &DNLoc, |
| 5130 | DeclarationName Name, |
| 5131 | const RecordData &Record, unsigned &Idx) { |
| 5132 | switch (Name.getNameKind()) { |
| 5133 | case DeclarationName::CXXConstructorName: |
| 5134 | case DeclarationName::CXXDestructorName: |
| 5135 | case DeclarationName::CXXConversionFunctionName: |
| 5136 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5137 | break; |
| 5138 | |
| 5139 | case DeclarationName::CXXOperatorName: |
| 5140 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5141 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5142 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5143 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5144 | break; |
| 5145 | |
| 5146 | case DeclarationName::CXXLiteralOperatorName: |
| 5147 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5148 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5149 | break; |
| 5150 | |
| 5151 | case DeclarationName::Identifier: |
| 5152 | case DeclarationName::ObjCZeroArgSelector: |
| 5153 | case DeclarationName::ObjCOneArgSelector: |
| 5154 | case DeclarationName::ObjCMultiArgSelector: |
| 5155 | case DeclarationName::CXXUsingDirective: |
| 5156 | break; |
| 5157 | } |
| 5158 | } |
| 5159 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5160 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5161 | DeclarationNameInfo &NameInfo, |
| 5162 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5163 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5164 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5165 | DeclarationNameLoc DNLoc; |
| 5166 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5167 | NameInfo.setInfo(DNLoc); |
| 5168 | } |
| 5169 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5170 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5171 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5172 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5173 | unsigned NumTPLists = Record[Idx++]; |
| 5174 | Info.NumTemplParamLists = NumTPLists; |
| 5175 | if (NumTPLists) { |
| 5176 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 5177 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5178 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5179 | } |
| 5180 | } |
| 5181 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5182 | TemplateName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5183 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5184 | unsigned &Idx) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5185 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5186 | switch (Kind) { |
| 5187 | case TemplateName::Template: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5188 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5189 | |
| 5190 | case TemplateName::OverloadedTemplate: { |
| 5191 | unsigned size = Record[Idx++]; |
| 5192 | UnresolvedSet<8> Decls; |
| 5193 | while (size--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5194 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5195 | |
| 5196 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 5197 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5198 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5199 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5200 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5201 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5202 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5203 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 5204 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5205 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5206 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5207 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5208 | if (Record[Idx++]) // isIdentifier |
| 5209 | return Context->getDependentTemplateName(NNS, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5210 | GetIdentifierInfo(F, Record, |
| 5211 | Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5212 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5213 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5214 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5215 | |
| 5216 | case TemplateName::SubstTemplateTemplateParm: { |
| 5217 | TemplateTemplateParmDecl *param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5218 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5219 | if (!param) return TemplateName(); |
| 5220 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 5221 | return Context->getSubstTemplateTemplateParm(param, replacement); |
| 5222 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5223 | |
| 5224 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5225 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5226 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5227 | if (!Param) |
| 5228 | return TemplateName(); |
| 5229 | |
| 5230 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5231 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5232 | return TemplateName(); |
| 5233 | |
| 5234 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 5235 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5236 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5237 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5238 | assert(0 && "Unhandled template name kind!"); |
| 5239 | return TemplateName(); |
| 5240 | } |
| 5241 | |
| 5242 | TemplateArgument |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5243 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5244 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5245 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5246 | switch (Kind) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5247 | case TemplateArgument::Null: |
| 5248 | return TemplateArgument(); |
| 5249 | case TemplateArgument::Type: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5250 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5251 | case TemplateArgument::Declaration: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5252 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5253 | case TemplateArgument::Integral: { |
| 5254 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5255 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5256 | return TemplateArgument(Value, T); |
| 5257 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5258 | case TemplateArgument::Template: |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5259 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5260 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5261 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5262 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5263 | if (unsigned NumExpansions = Record[Idx++]) |
| 5264 | NumTemplateExpansions = NumExpansions - 1; |
| 5265 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5266 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5267 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5268 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5269 | case TemplateArgument::Pack: { |
| 5270 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5271 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 5272 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5273 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5274 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5275 | } |
| 5276 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5277 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5278 | assert(0 && "Unhandled template argument kind!"); |
| 5279 | return TemplateArgument(); |
| 5280 | } |
| 5281 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5282 | TemplateParameterList * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5283 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5284 | const RecordData &Record, unsigned &Idx) { |
| 5285 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5286 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5287 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5288 | |
| 5289 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5290 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5291 | Params.reserve(NumParams); |
| 5292 | while (NumParams--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5293 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5294 | |
| 5295 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5296 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 5297 | Params.data(), Params.size(), RAngleLoc); |
| 5298 | return TemplateParams; |
| 5299 | } |
| 5300 | |
| 5301 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5302 | ASTReader:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5303 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5304 | Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5305 | unsigned &Idx) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5306 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5307 | TemplArgs.reserve(NumTemplateArgs); |
| 5308 | while (NumTemplateArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5309 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5310 | } |
| 5311 | |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5312 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5313 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5314 | const RecordData &Record, unsigned &Idx) { |
| 5315 | unsigned NumDecls = Record[Idx++]; |
| 5316 | while (NumDecls--) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5317 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5318 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5319 | Set.addDecl(D, AS); |
| 5320 | } |
| 5321 | } |
| 5322 | |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5323 | CXXBaseSpecifier |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5324 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5325 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5326 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5327 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5328 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5329 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5330 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5331 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5332 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5333 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5334 | EllipsisLoc); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5335 | Result.setInheritConstructors(inheritConstructors); |
| 5336 | return Result; |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5337 | } |
| 5338 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5339 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5340 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5341 | unsigned &Idx) { |
| 5342 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5343 | unsigned NumInitializers = Record[Idx++]; |
| 5344 | if (NumInitializers) { |
| 5345 | ASTContext &C = *getContext(); |
| 5346 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5347 | CtorInitializers |
| 5348 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5349 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5350 | TypeSourceInfo *BaseClassInfo = 0; |
| 5351 | bool IsBaseVirtual = false; |
| 5352 | FieldDecl *Member = 0; |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5353 | IndirectFieldDecl *IndirectMember = 0; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5354 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5355 | |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5356 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5357 | switch (Type) { |
| 5358 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5359 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5360 | IsBaseVirtual = Record[Idx++]; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5361 | break; |
| 5362 | |
| 5363 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5364 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5365 | break; |
| 5366 | |
| 5367 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5368 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5369 | break; |
| 5370 | |
| 5371 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5372 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5373 | break; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5374 | } |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5375 | |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5376 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5377 | Expr *Init = ReadExpr(F); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5378 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5379 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5380 | bool IsWritten = Record[Idx++]; |
| 5381 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5382 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5383 | if (IsWritten) { |
| 5384 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5385 | } else { |
| 5386 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5387 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5388 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5389 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5390 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5391 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5392 | CXXCtorInitializer *BOMInit; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5393 | if (Type == CTOR_INITIALIZER_BASE) { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5394 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 5395 | LParenLoc, Init, RParenLoc, |
| 5396 | MemberOrEllipsisLoc); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5397 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 5398 | BOMInit = new (C) CXXCtorInitializer(C, MemberOrEllipsisLoc, LParenLoc, |
| 5399 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5400 | } else if (IsWritten) { |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5401 | if (Member) |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5402 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 5403 | LParenLoc, Init, RParenLoc); |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5404 | else |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5405 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 5406 | MemberOrEllipsisLoc, LParenLoc, |
| 5407 | Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5408 | } else { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5409 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 5410 | LParenLoc, Init, RParenLoc, |
| 5411 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5412 | } |
| 5413 | |
Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5414 | if (IsWritten) |
| 5415 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5416 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5417 | } |
| 5418 | } |
| 5419 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5420 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5421 | } |
| 5422 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5423 | NestedNameSpecifier * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5424 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5425 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5426 | unsigned N = Record[Idx++]; |
| 5427 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5428 | for (unsigned I = 0; I != N; ++I) { |
| 5429 | NestedNameSpecifier::SpecifierKind Kind |
| 5430 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5431 | switch (Kind) { |
| 5432 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5433 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5434 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 5435 | break; |
| 5436 | } |
| 5437 | |
| 5438 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5439 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5440 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 5441 | break; |
| 5442 | } |
| 5443 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5444 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5445 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5446 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 5447 | break; |
| 5448 | } |
| 5449 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5450 | case NestedNameSpecifier::TypeSpec: |
| 5451 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5452 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5453 | if (!T) |
| 5454 | return 0; |
| 5455 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5456 | bool Template = Record[Idx++]; |
| 5457 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 5458 | break; |
| 5459 | } |
| 5460 | |
| 5461 | case NestedNameSpecifier::Global: { |
| 5462 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 5463 | // No associated value, and there can't be a prefix. |
| 5464 | break; |
| 5465 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5466 | } |
Argyrios Kyrtzidis | ad65c69 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5467 | Prev = NNS; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5468 | } |
| 5469 | return NNS; |
| 5470 | } |
| 5471 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5472 | NestedNameSpecifierLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5473 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5474 | unsigned &Idx) { |
| 5475 | unsigned N = Record[Idx++]; |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5476 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5477 | for (unsigned I = 0; I != N; ++I) { |
| 5478 | NestedNameSpecifier::SpecifierKind Kind |
| 5479 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5480 | switch (Kind) { |
| 5481 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5482 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5483 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5484 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5485 | break; |
| 5486 | } |
| 5487 | |
| 5488 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5489 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5490 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5491 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5492 | break; |
| 5493 | } |
| 5494 | |
| 5495 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5496 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5497 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5498 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5499 | break; |
| 5500 | } |
| 5501 | |
| 5502 | case NestedNameSpecifier::TypeSpec: |
| 5503 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5504 | bool Template = Record[Idx++]; |
| 5505 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5506 | if (!T) |
| 5507 | return NestedNameSpecifierLoc(); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5508 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5509 | |
| 5510 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 5511 | Builder.Extend(*Context, |
| 5512 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5513 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5514 | break; |
| 5515 | } |
| 5516 | |
| 5517 | case NestedNameSpecifier::Global: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5518 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5519 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5520 | break; |
| 5521 | } |
| 5522 | } |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5523 | } |
| 5524 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5525 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5528 | SourceRange |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5529 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5530 | unsigned &Idx) { |
| 5531 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5532 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 6d3bc08 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5533 | return SourceRange(beg, end); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5534 | } |
| 5535 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5536 | /// \brief Read an integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5537 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5538 | unsigned BitWidth = Record[Idx++]; |
| 5539 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5540 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5541 | Idx += NumWords; |
| 5542 | return Result; |
| 5543 | } |
| 5544 | |
| 5545 | /// \brief Read a signed integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5546 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5547 | bool isUnsigned = Record[Idx++]; |
| 5548 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5549 | } |
| 5550 | |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5551 | /// \brief Read a floating-point value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5552 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5553 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5554 | } |
| 5555 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5556 | // \brief Read a string |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5557 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5558 | unsigned Len = Record[Idx++]; |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5559 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5560 | Idx += Len; |
| 5561 | return Result; |
| 5562 | } |
| 5563 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5564 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5565 | unsigned &Idx) { |
| 5566 | unsigned Major = Record[Idx++]; |
| 5567 | unsigned Minor = Record[Idx++]; |
| 5568 | unsigned Subminor = Record[Idx++]; |
| 5569 | if (Minor == 0) |
| 5570 | return VersionTuple(Major); |
| 5571 | if (Subminor == 0) |
| 5572 | return VersionTuple(Major, Minor - 1); |
| 5573 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5574 | } |
| 5575 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5576 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5577 | const RecordData &Record, |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5578 | unsigned &Idx) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5579 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5580 | return CXXTemporary::Create(*Context, Decl); |
| 5581 | } |
| 5582 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5583 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5584 | return Diag(SourceLocation(), DiagID); |
| 5585 | } |
| 5586 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5587 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5588 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5589 | } |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5590 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5591 | /// \brief Retrieve the identifier table associated with the |
| 5592 | /// preprocessor. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5593 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 5594 | assert(PP && "Forgot to set Preprocessor ?"); |
| 5595 | return PP->getIdentifierTable(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5596 | } |
| 5597 | |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5598 | /// \brief Record that the given ID maps to the given switch-case |
| 5599 | /// statement. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5600 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5601 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5602 | SwitchCaseStmts[ID] = SC; |
| 5603 | } |
| 5604 | |
| 5605 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5606 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5607 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5608 | return SwitchCaseStmts[ID]; |
| 5609 | } |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5610 | |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5611 | void ASTReader::ClearSwitchCaseIDs() { |
| 5612 | SwitchCaseStmts.clear(); |
| 5613 | } |
| 5614 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5615 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5616 | assert(NumCurrentElementsDeserializing && |
| 5617 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5618 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5619 | // If any identifiers with corresponding top-level declarations have |
| 5620 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5621 | while (!PendingIdentifierInfos.empty()) { |
| 5622 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5623 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5624 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5625 | } |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5626 | |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5627 | // Ready to load previous declarations of Decls that were delayed. |
| 5628 | while (!PendingPreviousDecls.empty()) { |
| 5629 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5630 | PendingPreviousDecls.front().second); |
| 5631 | PendingPreviousDecls.pop_front(); |
| 5632 | } |
| 5633 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5634 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5635 | // decls to the consumer. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5636 | if (Consumer) |
| 5637 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | ad5f95c | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5638 | |
| 5639 | assert(PendingForwardRefs.size() == 0 && |
| 5640 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5641 | } |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5642 | --NumCurrentElementsDeserializing; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5643 | } |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5644 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5645 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5646 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5647 | bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5648 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5649 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 5650 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5651 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5652 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5653 | DisableValidation(DisableValidation), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5654 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5655 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5656 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5657 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5658 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5659 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5660 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5661 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5662 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5663 | { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5664 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5668 | Diagnostic &Diags, StringRef isysroot, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5669 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5670 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5671 | Diags(Diags), SemaObj(0), PP(0), Context(0), |
| 5672 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5673 | RelocatablePCH(false), isysroot(isysroot), |
| 5674 | DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), |
| 5675 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
| 5676 | TotalNumSLocEntries(0), NumStatementsRead(0), |
| 5677 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 5678 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 5679 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5680 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5681 | TotalVisibleDeclContexts(0), TotalModulesSizeInBits(0), |
| 5682 | NumCurrentElementsDeserializing(0), NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5683 | { |
| 5684 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5685 | } |
| 5686 | |
| 5687 | ASTReader::~ASTReader() { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5688 | for (DeclContextVisibleUpdatesPending::iterator |
| 5689 | I = PendingVisibleUpdates.begin(), |
| 5690 | E = PendingVisibleUpdates.end(); |
| 5691 | I != E; ++I) { |
| 5692 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5693 | F = I->second.end(); |
| 5694 | J != F; ++J) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5695 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5696 | } |
| 5697 | } |
| 5698 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5699 | //===----------------------------------------------------------------------===// |
| 5700 | // Module implementation |
| 5701 | //===----------------------------------------------------------------------===// |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5702 | Module::Module(ModuleKind Kind) |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5703 | : Kind(Kind), DirectlyImported(false), SizeInBits(0), |
| 5704 | LocalNumSLocEntries(0), SLocEntryBaseID(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5705 | SLocEntryBaseOffset(0), SLocEntryOffsets(0), |
| 5706 | SLocFileOffsets(0), LocalNumIdentifiers(0), |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 5707 | IdentifierOffsets(0), BaseIdentifierID(0), IdentifierTableData(0), |
| 5708 | IdentifierLookupTable(0), BasePreprocessedEntityID(0), |
| 5709 | LocalNumMacroDefinitions(0), MacroDefinitionOffsets(0), |
| 5710 | BaseMacroDefinitionID(0), LocalNumHeaderFileInfos(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5711 | HeaderFileInfoTableData(0), HeaderFileInfoTable(0), |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 5712 | HeaderFileFrameworkStrings(0), |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 5713 | LocalNumSelectors(0), SelectorOffsets(0), BaseSelectorID(0), |
Sebastian Redl | 949fe9e | 2010-09-22 00:42:27 +0000 | [diff] [blame] | 5714 | SelectorLookupTableData(0), SelectorLookupTable(0), LocalNumDecls(0), |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 5715 | DeclOffsets(0), BaseDeclID(0), |
| 5716 | LocalNumCXXBaseSpecifiers(0), CXXBaseSpecifiersOffsets(0), |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 5717 | LocalNumTypes(0), TypeOffsets(0), BaseTypeIndex(0), StatCache(0), |
Jonathan D. Turner | 269f256 | 2011-07-28 23:15:22 +0000 | [diff] [blame] | 5718 | NumPreallocatedPreprocessingEntities(0) |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5719 | {} |
| 5720 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5721 | Module::~Module() { |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 5722 | for (DeclContextInfosMap::iterator I = DeclContextInfos.begin(), |
| 5723 | E = DeclContextInfos.end(); |
| 5724 | I != E; ++I) { |
| 5725 | if (I->second.NameLookupTableData) |
| 5726 | delete static_cast<ASTDeclContextNameLookupTable*>( |
| 5727 | I->second.NameLookupTableData); |
| 5728 | } |
| 5729 | |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5730 | delete static_cast<ASTIdentifierLookupTable *>(IdentifierLookupTable); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 5731 | delete static_cast<HeaderFileInfoLookupTable *>(HeaderFileInfoTable); |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5732 | delete static_cast<ASTSelectorLookupTable *>(SelectorLookupTable); |
| 5733 | } |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5734 | |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5735 | template<typename Key, typename Offset, unsigned InitialCapacity> |
| 5736 | static void |
| 5737 | dumpLocalRemap(StringRef Name, |
| 5738 | const ContinuousRangeMap<Key, Offset, InitialCapacity> &Map) { |
| 5739 | if (Map.begin() == Map.end()) |
| 5740 | return; |
| 5741 | |
| 5742 | typedef ContinuousRangeMap<Key, Offset, InitialCapacity> MapType; |
| 5743 | llvm::errs() << " " << Name << ":\n"; |
| 5744 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 5745 | I != IEnd; ++I) { |
| 5746 | llvm::errs() << " " << I->first << " -> " << I->second |
| 5747 | << "\n"; |
| 5748 | } |
| 5749 | } |
| 5750 | |
| 5751 | void Module::dump() { |
| 5752 | llvm::errs() << "\nModule: " << FileName << "\n"; |
| 5753 | if (!Imports.empty()) { |
| 5754 | llvm::errs() << " Imports: "; |
| 5755 | for (unsigned I = 0, N = Imports.size(); I != N; ++I) { |
| 5756 | if (I) |
| 5757 | llvm::errs() << ", "; |
| 5758 | llvm::errs() << Imports[I]->FileName; |
| 5759 | } |
| 5760 | llvm::errs() << "\n"; |
| 5761 | } |
| 5762 | |
| 5763 | // Remapping tables. |
| 5764 | llvm::errs() << " Base source location offset: " << SLocEntryBaseOffset |
| 5765 | << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5766 | dumpLocalRemap("Source location offset local -> global map", SLocRemap); |
| 5767 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 5768 | llvm::errs() << " Base identifier ID: " << BaseIdentifierID << '\n' |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 5769 | << " Number of identifiers: " << LocalNumIdentifiers << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5770 | dumpLocalRemap("Identifier ID local -> global map", IdentifierRemap); |
| 5771 | |
| 5772 | llvm::errs() << " Base selector ID: " << BaseSelectorID << '\n' |
| 5773 | << " Number of selectors: " << LocalNumSelectors << '\n'; |
| 5774 | dumpLocalRemap("Selector ID local -> global map", SelectorRemap); |
| 5775 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 5776 | llvm::errs() << " Base preprocessed entity ID: " << BasePreprocessedEntityID |
| 5777 | << '\n' |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 5778 | << " Number of preprocessed entities: " |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 5779 | << NumPreallocatedPreprocessingEntities << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5780 | dumpLocalRemap("Preprocessed entity ID local -> global map", |
| 5781 | PreprocessedEntityRemap); |
| 5782 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 5783 | llvm::errs() << " Base macro definition ID: " << BaseMacroDefinitionID |
| 5784 | << '\n' |
| 5785 | << " Number of macro definitions: " << LocalNumMacroDefinitions |
| 5786 | << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5787 | dumpLocalRemap("Macro definition ID local -> global map", |
| 5788 | MacroDefinitionRemap); |
| 5789 | |
| 5790 | llvm::errs() << " Base type index: " << BaseTypeIndex << '\n' |
| 5791 | << " Number of types: " << LocalNumTypes << '\n'; |
| 5792 | dumpLocalRemap("Type index local -> global map", TypeRemap); |
| 5793 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5794 | llvm::errs() << " Base decl ID: " << BaseDeclID << '\n' |
| 5795 | << " Number of decls: " << LocalNumDecls << '\n'; |
Douglas Gregor | fddf530 | 2011-08-04 19:00:50 +0000 | [diff] [blame] | 5796 | dumpLocalRemap("Decl ID local -> global map", DeclRemap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 5797 | } |
| 5798 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5799 | //===----------------------------------------------------------------------===// |
| 5800 | // Module manager implementation |
| 5801 | //===----------------------------------------------------------------------===// |
| 5802 | |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5803 | Module *ModuleManager::lookup(StringRef Name) { |
| 5804 | const FileEntry *Entry = FileMgr.getFile(Name); |
| 5805 | return Modules[Entry]; |
| 5806 | } |
| 5807 | |
Jonathan D. Turner | db1c9e3 | 2011-08-02 17:40:32 +0000 | [diff] [blame] | 5808 | llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) { |
| 5809 | const FileEntry *Entry = FileMgr.getFile(Name); |
| 5810 | return InMemoryBuffers[Entry]; |
| 5811 | } |
| 5812 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5813 | std::pair<Module *, bool> |
| 5814 | ModuleManager::addModule(StringRef FileName, ModuleKind Type, |
| 5815 | Module *ImportedBy, std::string &ErrorStr) { |
Chad Rosier | 222e187 | 2011-08-18 19:06:24 +0000 | [diff] [blame] | 5816 | const FileEntry *Entry = FileMgr.getFile(FileName); |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5817 | if (!Entry && FileName != "-") { |
| 5818 | ErrorStr = "file not found"; |
| 5819 | return std::make_pair(static_cast<Module*>(0), false); |
| 5820 | } |
| 5821 | |
| 5822 | // Check whether we already loaded this module, before |
| 5823 | Module *&ModuleEntry = Modules[Entry]; |
| 5824 | bool NewModule = false; |
| 5825 | if (!ModuleEntry) { |
| 5826 | // Allocate a new module. |
| 5827 | Module *New = new Module(Type); |
| 5828 | New->FileName = FileName.str(); |
| 5829 | Chain.push_back(New); |
| 5830 | NewModule = true; |
| 5831 | ModuleEntry = New; |
| 5832 | |
| 5833 | // Load the contents of the module |
| 5834 | if (llvm::MemoryBuffer *Buffer = lookupBuffer(FileName)) { |
| 5835 | // The buffer was already provided for us. |
| 5836 | assert(Buffer && "Passed null buffer"); |
| 5837 | New->Buffer.reset(Buffer); |
| 5838 | } else { |
| 5839 | // Open the AST file. |
| 5840 | llvm::error_code ec; |
| 5841 | if (FileName == "-") { |
| 5842 | ec = llvm::MemoryBuffer::getSTDIN(New->Buffer); |
| 5843 | if (ec) |
| 5844 | ErrorStr = ec.message(); |
| 5845 | } else |
| 5846 | New->Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrorStr)); |
| 5847 | |
| 5848 | if (!New->Buffer) |
| 5849 | return std::make_pair(static_cast<Module*>(0), false); |
| 5850 | } |
| 5851 | |
| 5852 | // Initialize the stream |
| 5853 | New->StreamFile.init((const unsigned char *)New->Buffer->getBufferStart(), |
| 5854 | (const unsigned char *)New->Buffer->getBufferEnd()); } |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5855 | |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5856 | if (ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5857 | ModuleEntry->ImportedBy.insert(ImportedBy); |
| 5858 | ImportedBy->Imports.insert(ModuleEntry); |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5859 | } else { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5860 | ModuleEntry->DirectlyImported = true; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 5863 | return std::make_pair(ModuleEntry, NewModule); |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
Jonathan D. Turner | db1c9e3 | 2011-08-02 17:40:32 +0000 | [diff] [blame] | 5866 | void ModuleManager::addInMemoryBuffer(StringRef FileName, |
| 5867 | llvm::MemoryBuffer *Buffer) { |
| 5868 | |
| 5869 | const FileEntry *Entry = FileMgr.getVirtualFile(FileName, |
| 5870 | Buffer->getBufferSize(), 0); |
| 5871 | InMemoryBuffers[Entry] = Buffer; |
| 5872 | } |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5873 | |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5874 | ModuleManager::ModuleManager(const FileSystemOptions &FSO) : FileMgr(FSO) { } |
| 5875 | |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 5876 | ModuleManager::~ModuleManager() { |
| 5877 | for (unsigned i = 0, e = Chain.size(); i != e; ++i) |
| 5878 | delete Chain[e - i - 1]; |
| 5879 | } |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 5880 | |
| 5881 | void ModuleManager::visit(bool (*Visitor)(Module &M, void *UserData), |
| 5882 | void *UserData) { |
| 5883 | unsigned N = size(); |
| 5884 | |
| 5885 | // Record the number of incoming edges for each module. When we |
| 5886 | // encounter a module with no incoming edges, push it into the queue |
| 5887 | // to seed the queue. |
| 5888 | SmallVector<Module *, 4> Queue; |
| 5889 | Queue.reserve(N); |
| 5890 | llvm::DenseMap<Module *, unsigned> UnusedIncomingEdges; |
| 5891 | for (ModuleIterator M = begin(), MEnd = end(); M != MEnd; ++M) { |
| 5892 | if (unsigned Size = (*M)->ImportedBy.size()) |
| 5893 | UnusedIncomingEdges[*M] = Size; |
| 5894 | else |
| 5895 | Queue.push_back(*M); |
| 5896 | } |
| 5897 | |
| 5898 | llvm::SmallPtrSet<Module *, 4> Skipped; |
| 5899 | unsigned QueueStart = 0; |
| 5900 | while (QueueStart < Queue.size()) { |
| 5901 | Module *CurrentModule = Queue[QueueStart++]; |
| 5902 | |
| 5903 | // Check whether this module should be skipped. |
| 5904 | if (Skipped.count(CurrentModule)) |
| 5905 | continue; |
| 5906 | |
| 5907 | if (Visitor(*CurrentModule, UserData)) { |
| 5908 | // The visitor has requested that cut off visitation of any |
| 5909 | // module that the current module depends on. To indicate this |
| 5910 | // behavior, we mark all of the reachable modules as having N |
| 5911 | // incoming edges (which is impossible otherwise). |
| 5912 | SmallVector<Module *, 4> Stack; |
| 5913 | Stack.push_back(CurrentModule); |
| 5914 | Skipped.insert(CurrentModule); |
| 5915 | while (!Stack.empty()) { |
| 5916 | Module *NextModule = Stack.back(); |
| 5917 | Stack.pop_back(); |
| 5918 | |
| 5919 | // For any module that this module depends on, push it on the |
| 5920 | // stack (if it hasn't already been marked as visited). |
| 5921 | for (llvm::SetVector<Module *>::iterator |
| 5922 | M = NextModule->Imports.begin(), |
| 5923 | MEnd = NextModule->Imports.end(); |
| 5924 | M != MEnd; ++M) { |
| 5925 | if (Skipped.insert(*M)) |
| 5926 | Stack.push_back(*M); |
| 5927 | } |
| 5928 | } |
| 5929 | continue; |
| 5930 | } |
| 5931 | |
| 5932 | // For any module that this module depends on, push it on the |
| 5933 | // stack (if it hasn't already been marked as visited). |
| 5934 | for (llvm::SetVector<Module *>::iterator M = CurrentModule->Imports.begin(), |
| 5935 | MEnd = CurrentModule->Imports.end(); |
| 5936 | M != MEnd; ++M) { |
| 5937 | |
| 5938 | // Remove our current module as an impediment to visiting the |
| 5939 | // module we depend on. If we were the last unvisited module |
| 5940 | // that depends on this particular module, push it into the |
| 5941 | // queue to be visited. |
| 5942 | unsigned &NumUnusedEdges = UnusedIncomingEdges[*M]; |
| 5943 | if (NumUnusedEdges && (--NumUnusedEdges == 0)) |
| 5944 | Queue.push_back(*M); |
| 5945 | } |
| 5946 | } |
| 5947 | } |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 5948 | |
| 5949 | /// \brief Perform a depth-first visit of the current module. |
| 5950 | static bool visitDepthFirst(Module &M, |
| 5951 | bool (*Visitor)(Module &M, bool Preorder, |
| 5952 | void *UserData), |
| 5953 | void *UserData, |
| 5954 | llvm::SmallPtrSet<Module *, 4> &Visited) { |
| 5955 | // Preorder visitation |
| 5956 | if (Visitor(M, /*Preorder=*/true, UserData)) |
| 5957 | return true; |
| 5958 | |
| 5959 | // Visit children |
| 5960 | for (llvm::SetVector<Module *>::iterator IM = M.Imports.begin(), |
| 5961 | IMEnd = M.Imports.end(); |
| 5962 | IM != IMEnd; ++IM) { |
| 5963 | if (!Visited.insert(*IM)) |
| 5964 | continue; |
| 5965 | |
| 5966 | if (visitDepthFirst(**IM, Visitor, UserData, Visited)) |
| 5967 | return true; |
| 5968 | } |
| 5969 | |
| 5970 | // Postorder visitation |
| 5971 | return Visitor(M, /*Preorder=*/false, UserData); |
| 5972 | } |
| 5973 | |
| 5974 | void ModuleManager::visitDepthFirst(bool (*Visitor)(Module &M, bool Preorder, |
| 5975 | void *UserData), |
| 5976 | void *UserData) { |
| 5977 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 5978 | for (unsigned I = 0, N = Chain.size(); I != N; ++I) { |
| 5979 | if (!Visited.insert(Chain[I])) |
| 5980 | continue; |
| 5981 | |
| 5982 | if (::visitDepthFirst(*Chain[I], Visitor, UserData, Visited)) |
| 5983 | return; |
| 5984 | } |
| 5985 | } |