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" |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 16 | #include "clang/Serialization/ModuleManager.h" |
Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 17 | #include "ASTCommon.h" |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 18 | #include "ASTReaderInternals.h" |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/FrontendDiagnostic.h" |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/Utils.h" |
Douglas Gregor | c3a6ade | 2010-08-12 20:07:10 +0000 | [diff] [blame] | 21 | #include "clang/Sema/Sema.h" |
John McCall | cc14d1f | 2010-08-24 08:50:51 +0000 | [diff] [blame] | 22 | #include "clang/Sema/Scope.h" |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 23 | #include "clang/AST/ASTConsumer.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 24 | #include "clang/AST/ASTContext.h" |
John McCall | 19c1bfd | 2010-08-25 05:32:35 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 26 | #include "clang/AST/Expr.h" |
John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 27 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 28 | #include "clang/AST/NestedNameSpecifier.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 29 | #include "clang/AST/Type.h" |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 30 | #include "clang/AST/TypeLocVisitor.h" |
Chris Lattner | 34321bc | 2009-04-10 21:41:48 +0000 | [diff] [blame] | 31 | #include "clang/Lex/MacroInfo.h" |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 32 | #include "clang/Lex/PreprocessingRecord.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 33 | #include "clang/Lex/Preprocessor.h" |
Steve Naroff | 3fa455a | 2009-04-24 20:03:17 +0000 | [diff] [blame] | 34 | #include "clang/Lex/HeaderSearch.h" |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 35 | #include "clang/Basic/OnDiskHashTable.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 36 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 37 | #include "clang/Basic/SourceManagerInternals.h" |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileManager.h" |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 39 | #include "clang/Basic/FileSystemStatCache.h" |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 40 | #include "clang/Basic/TargetInfo.h" |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 41 | #include "clang/Basic/Version.h" |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 42 | #include "clang/Basic/VersionTuple.h" |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 43 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 44 | #include "llvm/Bitcode/BitstreamReader.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MemoryBuffer.h" |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 46 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 47 | #include "llvm/Support/FileSystem.h" |
Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 48 | #include "llvm/Support/Path.h" |
Michael J. Spencer | f25faaa | 2010-12-09 17:36:38 +0000 | [diff] [blame] | 49 | #include "llvm/Support/system_error.h" |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 50 | #include <algorithm> |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 51 | #include <iterator> |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 52 | #include <cstdio> |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 53 | #include <sys/stat.h> |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 54 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 55 | using namespace clang; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 56 | using namespace clang::serialization; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 57 | using namespace clang::serialization::reader; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 58 | |
| 59 | //===----------------------------------------------------------------------===// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 60 | // PCH validator implementation |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 61 | //===----------------------------------------------------------------------===// |
| 62 | |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 63 | ASTReaderListener::~ASTReaderListener() {} |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 64 | |
| 65 | bool |
| 66 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts) { |
| 67 | const LangOptions &PPLangOpts = PP.getLangOptions(); |
| 68 | #define PARSE_LANGOPT_BENIGN(Option) |
| 69 | #define PARSE_LANGOPT_IMPORTANT(Option, DiagID) \ |
| 70 | if (PPLangOpts.Option != LangOpts.Option) { \ |
| 71 | Reader.Diag(DiagID) << LangOpts.Option << PPLangOpts.Option; \ |
| 72 | return true; \ |
| 73 | } |
| 74 | |
| 75 | PARSE_LANGOPT_BENIGN(Trigraphs); |
| 76 | PARSE_LANGOPT_BENIGN(BCPLComment); |
| 77 | PARSE_LANGOPT_BENIGN(DollarIdents); |
| 78 | PARSE_LANGOPT_BENIGN(AsmPreprocessor); |
| 79 | PARSE_LANGOPT_IMPORTANT(GNUMode, diag::warn_pch_gnu_extensions); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 80 | PARSE_LANGOPT_IMPORTANT(GNUKeywords, diag::warn_pch_gnu_keywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 81 | PARSE_LANGOPT_BENIGN(ImplicitInt); |
| 82 | PARSE_LANGOPT_BENIGN(Digraphs); |
| 83 | PARSE_LANGOPT_BENIGN(HexFloats); |
| 84 | PARSE_LANGOPT_IMPORTANT(C99, diag::warn_pch_c99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 85 | PARSE_LANGOPT_IMPORTANT(C1X, diag::warn_pch_c1x); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 86 | PARSE_LANGOPT_IMPORTANT(Microsoft, diag::warn_pch_microsoft_extensions); |
Michael J. Spencer | 4992ca4b | 2010-10-21 05:21:48 +0000 | [diff] [blame] | 87 | PARSE_LANGOPT_BENIGN(MSCVersion); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 88 | PARSE_LANGOPT_IMPORTANT(CPlusPlus, diag::warn_pch_cplusplus); |
| 89 | PARSE_LANGOPT_IMPORTANT(CPlusPlus0x, diag::warn_pch_cplusplus0x); |
| 90 | PARSE_LANGOPT_BENIGN(CXXOperatorName); |
| 91 | PARSE_LANGOPT_IMPORTANT(ObjC1, diag::warn_pch_objective_c); |
| 92 | PARSE_LANGOPT_IMPORTANT(ObjC2, diag::warn_pch_objective_c2); |
| 93 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI, diag::warn_pch_nonfragile_abi); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 94 | PARSE_LANGOPT_IMPORTANT(ObjCNonFragileABI2, diag::warn_pch_nonfragile_abi2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 95 | PARSE_LANGOPT_IMPORTANT(AppleKext, diag::warn_pch_apple_kext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 96 | PARSE_LANGOPT_IMPORTANT(ObjCDefaultSynthProperties, |
| 97 | diag::warn_pch_objc_auto_properties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 98 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedResultType) |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 99 | PARSE_LANGOPT_IMPORTANT(NoConstantCFStrings, |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 100 | diag::warn_pch_no_constant_cfstrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 101 | PARSE_LANGOPT_BENIGN(PascalStrings); |
| 102 | PARSE_LANGOPT_BENIGN(WritableStrings); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | PARSE_LANGOPT_IMPORTANT(LaxVectorConversions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 104 | diag::warn_pch_lax_vector_conversions); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 105 | PARSE_LANGOPT_IMPORTANT(AltiVec, diag::warn_pch_altivec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 106 | PARSE_LANGOPT_IMPORTANT(Exceptions, diag::warn_pch_exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 107 | PARSE_LANGOPT_IMPORTANT(ObjCExceptions, diag::warn_pch_objc_exceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 108 | PARSE_LANGOPT_IMPORTANT(CXXExceptions, diag::warn_pch_cxx_exceptions); |
| 109 | PARSE_LANGOPT_IMPORTANT(SjLjExceptions, diag::warn_pch_sjlj_exceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 110 | PARSE_LANGOPT_IMPORTANT(MSBitfields, diag::warn_pch_ms_bitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 111 | PARSE_LANGOPT_IMPORTANT(NeXTRuntime, diag::warn_pch_objc_runtime); |
| 112 | PARSE_LANGOPT_IMPORTANT(Freestanding, diag::warn_pch_freestanding); |
| 113 | PARSE_LANGOPT_IMPORTANT(NoBuiltin, diag::warn_pch_builtins); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | PARSE_LANGOPT_IMPORTANT(ThreadsafeStatics, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 115 | diag::warn_pch_thread_safe_statics); |
Daniel Dunbar | a77eaeb | 2009-09-03 04:54:28 +0000 | [diff] [blame] | 116 | PARSE_LANGOPT_IMPORTANT(POSIXThreads, diag::warn_pch_posix_threads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 117 | PARSE_LANGOPT_IMPORTANT(Blocks, diag::warn_pch_blocks); |
| 118 | PARSE_LANGOPT_BENIGN(EmitAllDecls); |
| 119 | PARSE_LANGOPT_IMPORTANT(MathErrno, diag::warn_pch_math_errno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 120 | PARSE_LANGOPT_BENIGN(getSignedOverflowBehavior()); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | PARSE_LANGOPT_IMPORTANT(HeinousExtensions, |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 122 | diag::warn_pch_heinous_extensions); |
| 123 | // FIXME: Most of the options below are benign if the macro wasn't |
| 124 | // used. Unfortunately, this means that a PCH compiled without |
| 125 | // optimization can't be used with optimization turned on, even |
| 126 | // though the only thing that changes is whether __OPTIMIZE__ was |
| 127 | // defined... but if __OPTIMIZE__ never showed up in the header, it |
| 128 | // doesn't matter. We could consider making this some special kind |
| 129 | // of check. |
| 130 | PARSE_LANGOPT_IMPORTANT(Optimize, diag::warn_pch_optimize); |
| 131 | PARSE_LANGOPT_IMPORTANT(OptimizeSize, diag::warn_pch_optimize_size); |
| 132 | PARSE_LANGOPT_IMPORTANT(Static, diag::warn_pch_static); |
| 133 | PARSE_LANGOPT_IMPORTANT(PICLevel, diag::warn_pch_pic_level); |
| 134 | PARSE_LANGOPT_IMPORTANT(GNUInline, diag::warn_pch_gnu_inline); |
| 135 | PARSE_LANGOPT_IMPORTANT(NoInline, diag::warn_pch_no_inline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 136 | PARSE_LANGOPT_IMPORTANT(Deprecated, diag::warn_pch_deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 137 | PARSE_LANGOPT_IMPORTANT(AccessControl, diag::warn_pch_access_control); |
| 138 | PARSE_LANGOPT_IMPORTANT(CharIsSigned, diag::warn_pch_char_signed); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 139 | PARSE_LANGOPT_IMPORTANT(ShortWChar, diag::warn_pch_short_wchar); |
Argyrios Kyrtzidis | 74825bc | 2010-10-08 00:25:19 +0000 | [diff] [blame] | 140 | PARSE_LANGOPT_IMPORTANT(ShortEnums, diag::warn_pch_short_enums); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 141 | if ((PPLangOpts.getGCMode() != 0) != (LangOpts.getGCMode() != 0)) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | Reader.Diag(diag::warn_pch_gc_mode) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 143 | << LangOpts.getGCMode() << PPLangOpts.getGCMode(); |
| 144 | return true; |
| 145 | } |
| 146 | PARSE_LANGOPT_BENIGN(getVisibilityMode()); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 147 | PARSE_LANGOPT_IMPORTANT(getStackProtectorMode(), |
| 148 | diag::warn_pch_stack_protector); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 149 | PARSE_LANGOPT_BENIGN(InstantiationDepth); |
Nate Begeman | 9d90579 | 2009-06-25 22:57:40 +0000 | [diff] [blame] | 150 | PARSE_LANGOPT_IMPORTANT(OpenCL, diag::warn_pch_opencl); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 151 | PARSE_LANGOPT_IMPORTANT(CUDA, diag::warn_pch_cuda); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 152 | PARSE_LANGOPT_BENIGN(CatchUndefined); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 153 | PARSE_LANGOPT_BENIGN(DefaultFPContract); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 154 | PARSE_LANGOPT_IMPORTANT(ElideConstructors, diag::warn_pch_elide_constructors); |
Douglas Gregor | 8ed0c0b | 2010-07-09 17:35:33 +0000 | [diff] [blame] | 155 | PARSE_LANGOPT_BENIGN(SpellChecking); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 156 | PARSE_LANGOPT_IMPORTANT(ObjCAutoRefCount, diag::warn_pch_auto_ref_count); |
| 157 | PARSE_LANGOPT_BENIGN(ObjCInferRelatedReturnType); |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 158 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 159 | #undef PARSE_LANGOPT_BENIGN |
| 160 | |
| 161 | return false; |
| 162 | } |
| 163 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 164 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | 20a682d | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 165 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 166 | return false; |
| 167 | |
| 168 | Reader.Diag(diag::warn_pch_target_triple) |
| 169 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 170 | return true; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 173 | namespace { |
| 174 | struct EmptyStringRef { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 175 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 176 | }; |
| 177 | struct EmptyBlock { |
| 178 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 179 | }; |
| 180 | } |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 181 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 182 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 183 | PCHPredefinesBlocks R) { |
| 184 | // First, sum up the lengths. |
| 185 | unsigned LL = 0, RL = 0; |
| 186 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 187 | LL += L[I].size(); |
| 188 | } |
| 189 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 190 | RL += R[I].Data.size(); |
| 191 | } |
| 192 | if (LL != RL) |
| 193 | return false; |
| 194 | if (LL == 0 && RL == 0) |
| 195 | return true; |
| 196 | |
| 197 | // Kick out empty parts, they confuse the algorithm below. |
| 198 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 199 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 200 | |
| 201 | // 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] | 202 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 203 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | 01ad0a7 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 204 | (void) RN; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 205 | for (;;) { |
| 206 | // Compare the current pieces. |
| 207 | if (LR.size() == RR.size()) { |
| 208 | // If they're the same length, it's pretty easy. |
| 209 | if (LR != RR) |
| 210 | return false; |
| 211 | // Both pieces are done, advance. |
| 212 | ++LI; |
| 213 | ++RI; |
| 214 | // If either string is done, they're both done, since they're the same |
| 215 | // length. |
| 216 | if (LI == LN) { |
| 217 | assert(RI == RN && "Strings not the same length after all?"); |
| 218 | return true; |
| 219 | } |
| 220 | LR = L[LI]; |
| 221 | RR = R[RI].Data; |
| 222 | } else if (LR.size() < RR.size()) { |
| 223 | // Right piece is longer. |
| 224 | if (!RR.startswith(LR)) |
| 225 | return false; |
| 226 | ++LI; |
| 227 | assert(LI != LN && "Strings not the same length after all?"); |
| 228 | RR = RR.substr(LR.size()); |
| 229 | LR = L[LI]; |
| 230 | } else { |
| 231 | // Left piece is longer. |
| 232 | if (!LR.startswith(RR)) |
| 233 | return false; |
| 234 | ++RI; |
| 235 | assert(RI != RN && "Strings not the same length after all?"); |
| 236 | LR = LR.substr(RR.size()); |
| 237 | RR = R[RI].Data; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 242 | static std::pair<FileID, StringRef::size_type> |
| 243 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 244 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 245 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 246 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 247 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 248 | Res.first = Buffers[I].BufferID; |
| 249 | break; |
| 250 | } |
| 251 | } |
| 252 | return Res; |
| 253 | } |
| 254 | |
| 255 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 256 | StringRef OriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 257 | std::string &SuggestedPredefines, |
| 258 | FileManager &FileMgr) { |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 259 | // We are in the context of an implicit include, so the predefines buffer will |
| 260 | // have a #include entry for the PCH file itself (as normalized by the |
| 261 | // preprocessor initialization). Find it and skip over it in the checking |
| 262 | // below. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 263 | llvm::SmallString<256> PCHInclude; |
| 264 | PCHInclude += "#include \""; |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 265 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 266 | PCHInclude += "\"\n"; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 267 | std::pair<StringRef,StringRef> Split = |
| 268 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 269 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 270 | if (Left == PP.getPredefines()) { |
| 271 | Error("Missing PCH include entry!"); |
| 272 | return true; |
| 273 | } |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 274 | |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 275 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 276 | // command line, we're done. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 277 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 278 | CommandLine.push_back(Left); |
| 279 | CommandLine.push_back(Right); |
| 280 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 281 | return false; |
| 282 | |
| 283 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 285 | // The predefines buffers are different. Determine what the differences are, |
| 286 | // and whether they require us to reject the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 287 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 288 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 289 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 290 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 291 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 292 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 293 | |
| 294 | // Pick out implicit #includes after the PCH and don't consider them for |
| 295 | // validation; we will insert them into SuggestedPredefines so that the |
| 296 | // preprocessor includes them. |
| 297 | std::string IncludesAfterPCH; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 298 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 299 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 300 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 301 | if (AfterPCHLines[i].startswith("#include ")) { |
| 302 | IncludesAfterPCH += AfterPCHLines[i]; |
| 303 | IncludesAfterPCH += '\n'; |
| 304 | } else { |
| 305 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // Make sure we add the includes last into SuggestedPredefines before we |
| 310 | // exit this function. |
| 311 | struct AddIncludesRAII { |
| 312 | std::string &SuggestedPredefines; |
| 313 | std::string &IncludesAfterPCH; |
| 314 | |
| 315 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 316 | std::string &IncludesAfterPCH) |
| 317 | : SuggestedPredefines(SuggestedPredefines), |
| 318 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 319 | ~AddIncludesRAII() { |
| 320 | SuggestedPredefines += IncludesAfterPCH; |
| 321 | } |
| 322 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 323 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 324 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 325 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 326 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 327 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 328 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 329 | // Determine which predefines that were used to build the PCH file are missing |
| 330 | // from the command line. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 331 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 332 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 333 | CmdLineLines.begin(), CmdLineLines.end(), |
| 334 | std::back_inserter(MissingPredefines)); |
| 335 | |
| 336 | bool MissingDefines = false; |
| 337 | bool ConflictingDefines = false; |
| 338 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 339 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 340 | if (Missing.startswith("#include ")) { |
| 341 | // An -include was specified when generating the PCH; it is included in |
| 342 | // the PCH, just ignore it. |
| 343 | continue; |
| 344 | } |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 345 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 346 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 347 | return true; |
| 348 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 350 | // This is a macro definition. Determine the name of the macro we're |
| 351 | // defining. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 352 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 353 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 354 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 355 | assert(EndOfMacroName != std::string::npos && |
| 356 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 357 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 358 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 359 | // Determine whether this macro was given a different definition on the |
| 360 | // command line. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 361 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 362 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 363 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 364 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 365 | MacroDefStart); |
| 366 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 367 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 368 | // Different macro; we're done. |
| 369 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | break; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 371 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 372 | |
| 373 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 374 | "Invalid #define in predefines buffer?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 376 | (*ConflictPos)[MacroDefLen] != '(') |
| 377 | continue; // Longer macro name; keep trying. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 379 | // We found a conflicting macro definition. |
| 380 | break; |
| 381 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 382 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 383 | if (ConflictPos != CmdLineLines.end()) { |
| 384 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 385 | << MacroName; |
| 386 | |
| 387 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 388 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 389 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 390 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 391 | SourceLocation PCHMissingLoc = |
| 392 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 393 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 394 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 395 | |
| 396 | ConflictingDefines = true; |
| 397 | continue; |
| 398 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 400 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 401 | // 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] | 402 | if (ConflictingDefines) |
| 403 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 405 | if (!MissingDefines) { |
| 406 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 407 | MissingDefines = true; |
| 408 | } |
| 409 | |
| 410 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 411 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 412 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 413 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 414 | SourceLocation PCHMissingLoc = |
| 415 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 416 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 417 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 418 | } |
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 | if (ConflictingDefines) |
| 421 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 423 | // Determine what predefines were introduced based on command-line |
| 424 | // parameters that were not present when building the PCH |
| 425 | // file. Extra #defines are okay, so long as the identifiers being |
| 426 | // defined were not used within the precompiled header. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 427 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 428 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 429 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 431 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 432 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 433 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 434 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 435 | return true; |
| 436 | } |
| 437 | |
| 438 | // This is an extra macro definition. Determine the name of the |
| 439 | // macro we're defining. |
| 440 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 442 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 443 | assert(EndOfMacroName != std::string::npos && |
| 444 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 445 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 446 | |
| 447 | // Check whether this name was used somewhere in the PCH file. If |
| 448 | // so, defining it as a macro could change behavior, so we reject |
| 449 | // the PCH file. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 450 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 045c92f | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 451 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 452 | return true; |
| 453 | } |
| 454 | |
| 455 | // Add this definition to the suggested predefines buffer. |
| 456 | SuggestedPredefines += Extra; |
| 457 | SuggestedPredefines += '\n'; |
| 458 | } |
| 459 | |
| 460 | // If we get here, it's because the predefines buffer had compatible |
| 461 | // contents. Accept the PCH file. |
| 462 | return false; |
| 463 | } |
| 464 | |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 465 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 466 | unsigned ID) { |
| 467 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 468 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void PCHValidator::ReadCounter(unsigned Value) { |
| 472 | PP.setCounterValue(Value); |
| 473 | } |
| 474 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 475 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 476 | // AST reader implementation |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 477 | //===----------------------------------------------------------------------===// |
| 478 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 479 | void |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 480 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 481 | DeserializationListener = Listener; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 484 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 485 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 486 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 487 | return serialization::ComputeHash(Sel); |
| 488 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 489 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 490 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 491 | std::pair<unsigned, unsigned> |
| 492 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 493 | using namespace clang::io; |
| 494 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 495 | unsigned DataLen = ReadUnalignedLE16(d); |
| 496 | return std::make_pair(KeyLen, DataLen); |
| 497 | } |
| 498 | |
| 499 | ASTSelectorLookupTrait::internal_key_type |
| 500 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 501 | using namespace clang::io; |
| 502 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
| 503 | unsigned N = ReadUnalignedLE16(d); |
| 504 | IdentifierInfo *FirstII |
| 505 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 506 | if (N == 0) |
| 507 | return SelTable.getNullarySelector(FirstII); |
| 508 | else if (N == 1) |
| 509 | return SelTable.getUnarySelector(FirstII); |
| 510 | |
| 511 | SmallVector<IdentifierInfo *, 16> Args; |
| 512 | Args.push_back(FirstII); |
| 513 | for (unsigned I = 1; I != N; ++I) |
| 514 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 515 | |
| 516 | return SelTable.getSelector(N, Args.data()); |
| 517 | } |
| 518 | |
| 519 | ASTSelectorLookupTrait::data_type |
| 520 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 521 | unsigned DataLen) { |
| 522 | using namespace clang::io; |
| 523 | |
| 524 | data_type Result; |
| 525 | |
| 526 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 527 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 528 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 529 | |
| 530 | // Load instance methods |
| 531 | ObjCMethodList *Prev = 0; |
| 532 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 533 | if (ObjCMethodDecl *Method |
| 534 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 535 | Result.Instance.push_back(Method); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 536 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 537 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 538 | // Load factory methods |
| 539 | Prev = 0; |
| 540 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 541 | if (ObjCMethodDecl *Method |
| 542 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 543 | Result.Factory.push_back(Method); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 544 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 545 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 546 | return Result; |
| 547 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 548 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 549 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 550 | return llvm::HashString(StringRef(a.first, a.second)); |
| 551 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 553 | std::pair<unsigned, unsigned> |
| 554 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 555 | using namespace clang::io; |
| 556 | unsigned DataLen = ReadUnalignedLE16(d); |
| 557 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 558 | return std::make_pair(KeyLen, DataLen); |
| 559 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 560 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 561 | std::pair<const char*, unsigned> |
| 562 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 563 | assert(n >= 2 && d[n-1] == '\0'); |
| 564 | return std::make_pair((const char*) d, n-1); |
| 565 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 566 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 567 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 568 | const unsigned char* d, |
| 569 | unsigned DataLen) { |
| 570 | using namespace clang::io; |
| 571 | unsigned RawID = ReadUnalignedLE32(d); |
| 572 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 574 | // Wipe out the "is interesting" bit. |
| 575 | RawID = RawID >> 1; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 576 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 577 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 578 | if (!IsInteresting) { |
| 579 | // For uninteresting identifiers, just build the IdentifierInfo |
| 580 | // and associate it with the persistent ID. |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 581 | IdentifierInfo *II = KnownII; |
| 582 | if (!II) |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 583 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 584 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 585 | II->setIsFromAST(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 586 | return II; |
| 587 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 588 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 589 | unsigned Bits = ReadUnalignedLE16(d); |
| 590 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 591 | Bits >>= 1; |
| 592 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 593 | Bits >>= 1; |
| 594 | bool Poisoned = Bits & 0x01; |
| 595 | Bits >>= 1; |
| 596 | bool ExtensionToken = Bits & 0x01; |
| 597 | Bits >>= 1; |
| 598 | bool hasMacroDefinition = Bits & 0x01; |
| 599 | Bits >>= 1; |
| 600 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 601 | Bits >>= 10; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 602 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 603 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 604 | DataLen -= 6; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 605 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 606 | // Build the IdentifierInfo itself and link the identifier ID with |
| 607 | // the new IdentifierInfo. |
| 608 | IdentifierInfo *II = KnownII; |
| 609 | if (!II) |
| 610 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
| 611 | Reader.SetIdentifierInfo(ID, II); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 612 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 613 | // Set or check the various bits in the IdentifierInfo structure. |
| 614 | // Token IDs are read-only. |
| 615 | if (HasRevertedTokenIDToIdentifier) |
| 616 | II->RevertTokenIDToIdentifier(); |
| 617 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 618 | assert(II->isExtensionToken() == ExtensionToken && |
| 619 | "Incorrect extension token flag"); |
| 620 | (void)ExtensionToken; |
| 621 | if (Poisoned) |
| 622 | II->setIsPoisoned(true); |
| 623 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 624 | "Incorrect C++ operator keyword flag"); |
| 625 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 626 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 627 | // If this identifier is a macro, deserialize the macro |
| 628 | // definition. |
| 629 | if (hasMacroDefinition) { |
| 630 | // FIXME: Check for conflicts? |
| 631 | uint32_t Offset = ReadUnalignedLE32(d); |
| 632 | Reader.SetIdentifierIsMacro(II, F, Offset); |
| 633 | DataLen -= 4; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 636 | // Read all of the declarations visible at global scope with this |
| 637 | // name. |
| 638 | if (Reader.getContext() == 0) return II; |
| 639 | if (DataLen > 0) { |
| 640 | SmallVector<uint32_t, 4> DeclIDs; |
| 641 | for (; DataLen > 0; DataLen -= 4) |
| 642 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 643 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 646 | II->setIsFromAST(); |
| 647 | return II; |
| 648 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 649 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 650 | unsigned |
| 651 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 652 | llvm::FoldingSetNodeID ID; |
| 653 | ID.AddInteger(Key.Kind); |
| 654 | |
| 655 | switch (Key.Kind) { |
| 656 | case DeclarationName::Identifier: |
| 657 | case DeclarationName::CXXLiteralOperatorName: |
| 658 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 659 | break; |
| 660 | case DeclarationName::ObjCZeroArgSelector: |
| 661 | case DeclarationName::ObjCOneArgSelector: |
| 662 | case DeclarationName::ObjCMultiArgSelector: |
| 663 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 664 | break; |
| 665 | case DeclarationName::CXXOperatorName: |
| 666 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 667 | break; |
| 668 | case DeclarationName::CXXConstructorName: |
| 669 | case DeclarationName::CXXDestructorName: |
| 670 | case DeclarationName::CXXConversionFunctionName: |
| 671 | case DeclarationName::CXXUsingDirective: |
| 672 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 675 | return ID.ComputeHash(); |
| 676 | } |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 677 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 678 | ASTDeclContextNameLookupTrait::internal_key_type |
| 679 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 680 | const external_key_type& Name) const { |
| 681 | DeclNameKey Key; |
| 682 | Key.Kind = Name.getNameKind(); |
| 683 | switch (Name.getNameKind()) { |
| 684 | case DeclarationName::Identifier: |
| 685 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 686 | break; |
| 687 | case DeclarationName::ObjCZeroArgSelector: |
| 688 | case DeclarationName::ObjCOneArgSelector: |
| 689 | case DeclarationName::ObjCMultiArgSelector: |
| 690 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 691 | break; |
| 692 | case DeclarationName::CXXOperatorName: |
| 693 | Key.Data = Name.getCXXOverloadedOperator(); |
| 694 | break; |
| 695 | case DeclarationName::CXXLiteralOperatorName: |
| 696 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 697 | break; |
| 698 | case DeclarationName::CXXConstructorName: |
| 699 | case DeclarationName::CXXDestructorName: |
| 700 | case DeclarationName::CXXConversionFunctionName: |
| 701 | case DeclarationName::CXXUsingDirective: |
| 702 | Key.Data = 0; |
| 703 | break; |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 706 | return Key; |
| 707 | } |
| 708 | |
| 709 | ASTDeclContextNameLookupTrait::external_key_type |
| 710 | ASTDeclContextNameLookupTrait::GetExternalKey( |
| 711 | const internal_key_type& Key) const { |
| 712 | ASTContext *Context = Reader.getContext(); |
| 713 | switch (Key.Kind) { |
| 714 | case DeclarationName::Identifier: |
| 715 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 716 | |
| 717 | case DeclarationName::ObjCZeroArgSelector: |
| 718 | case DeclarationName::ObjCOneArgSelector: |
| 719 | case DeclarationName::ObjCMultiArgSelector: |
| 720 | return DeclarationName(Selector(Key.Data)); |
| 721 | |
| 722 | case DeclarationName::CXXConstructorName: |
| 723 | return Context->DeclarationNames.getCXXConstructorName( |
| 724 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
| 725 | |
| 726 | case DeclarationName::CXXDestructorName: |
| 727 | return Context->DeclarationNames.getCXXDestructorName( |
| 728 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
| 729 | |
| 730 | case DeclarationName::CXXConversionFunctionName: |
| 731 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 732 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
| 733 | |
| 734 | case DeclarationName::CXXOperatorName: |
| 735 | return Context->DeclarationNames.getCXXOperatorName( |
| 736 | (OverloadedOperatorKind)Key.Data); |
| 737 | |
| 738 | case DeclarationName::CXXLiteralOperatorName: |
| 739 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 740 | (IdentifierInfo*)Key.Data); |
| 741 | |
| 742 | case DeclarationName::CXXUsingDirective: |
| 743 | return DeclarationName::getUsingDirectiveName(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 746 | llvm_unreachable("Invalid Name Kind ?"); |
| 747 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 748 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 749 | std::pair<unsigned, unsigned> |
| 750 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 751 | using namespace clang::io; |
| 752 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 753 | unsigned DataLen = ReadUnalignedLE16(d); |
| 754 | return std::make_pair(KeyLen, DataLen); |
| 755 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 756 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 757 | ASTDeclContextNameLookupTrait::internal_key_type |
| 758 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 759 | using namespace clang::io; |
| 760 | |
| 761 | DeclNameKey Key; |
| 762 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 763 | switch (Key.Kind) { |
| 764 | case DeclarationName::Identifier: |
| 765 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 766 | break; |
| 767 | case DeclarationName::ObjCZeroArgSelector: |
| 768 | case DeclarationName::ObjCOneArgSelector: |
| 769 | case DeclarationName::ObjCMultiArgSelector: |
| 770 | Key.Data = |
| 771 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 772 | .getAsOpaquePtr(); |
| 773 | break; |
| 774 | case DeclarationName::CXXOperatorName: |
| 775 | Key.Data = *d++; // OverloadedOperatorKind |
| 776 | break; |
| 777 | case DeclarationName::CXXLiteralOperatorName: |
| 778 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 779 | break; |
| 780 | case DeclarationName::CXXConstructorName: |
| 781 | case DeclarationName::CXXDestructorName: |
| 782 | case DeclarationName::CXXConversionFunctionName: |
| 783 | case DeclarationName::CXXUsingDirective: |
| 784 | Key.Data = 0; |
| 785 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 788 | return Key; |
| 789 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 790 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 791 | ASTDeclContextNameLookupTrait::data_type |
| 792 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 793 | const unsigned char* d, |
| 794 | unsigned DataLen) { |
| 795 | using namespace clang::io; |
| 796 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 797 | DeclID *Start = (DeclID *)d; |
| 798 | return std::make_pair(Start, Start + NumDecls); |
| 799 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 800 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 801 | bool ASTReader::ReadDeclContextStorage(Module &M, |
| 802 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 803 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 804 | DeclContextInfo &Info) { |
| 805 | SavedStreamPosition SavedPosition(Cursor); |
| 806 | // First the lexical decls. |
| 807 | if (Offsets.first != 0) { |
| 808 | Cursor.JumpToBit(Offsets.first); |
| 809 | |
| 810 | RecordData Record; |
| 811 | const char *Blob; |
| 812 | unsigned BlobLen; |
| 813 | unsigned Code = Cursor.ReadCode(); |
| 814 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 815 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 816 | Error("Expected lexical block"); |
| 817 | return true; |
| 818 | } |
| 819 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 820 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 821 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | // Now the lookup table. |
| 825 | if (Offsets.second != 0) { |
| 826 | Cursor.JumpToBit(Offsets.second); |
| 827 | |
| 828 | RecordData Record; |
| 829 | const char *Blob; |
| 830 | unsigned BlobLen; |
| 831 | unsigned Code = Cursor.ReadCode(); |
| 832 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 833 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 834 | Error("Expected visible lookup table block"); |
| 835 | return true; |
| 836 | } |
| 837 | Info.NameLookupTableData |
| 838 | = ASTDeclContextNameLookupTable::Create( |
| 839 | (const unsigned char *)Blob + Record[0], |
| 840 | (const unsigned char *)Blob, |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 841 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | return false; |
| 845 | } |
| 846 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 847 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 848 | Error(diag::err_fe_pch_malformed, Msg); |
| 849 | } |
| 850 | |
| 851 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 852 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 853 | if (Diags.isDiagnosticInFlight()) |
| 854 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 855 | else |
| 856 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 857 | } |
| 858 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 859 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 860 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 861 | if (Listener) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 862 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 863 | ActualOriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 864 | SuggestedPredefines, |
| 865 | FileMgr); |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 866 | return false; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 869 | //===----------------------------------------------------------------------===// |
| 870 | // Source Manager Deserialization |
| 871 | //===----------------------------------------------------------------------===// |
| 872 | |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 873 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 874 | /// \returns true if there was an error. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 875 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 876 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 877 | unsigned Idx = 0; |
| 878 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 879 | |
| 880 | // Parse the file names |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 881 | std::map<int, int> FileIDs; |
| 882 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 883 | // Extract the file name |
| 884 | unsigned FilenameLen = Record[Idx++]; |
| 885 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 886 | Idx += FilenameLen; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 887 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 9a6b098 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 888 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | // Parse the line entries |
| 892 | std::vector<LineEntry> Entries; |
| 893 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 894 | int FID = Record[Idx++]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 895 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 896 | // Remap FileID from 1-based old view. |
| 897 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 898 | |
| 899 | // Extract the line entries |
| 900 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 901 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 902 | Entries.clear(); |
| 903 | Entries.reserve(NumEntries); |
| 904 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 905 | unsigned FileOffset = Record[Idx++]; |
| 906 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 907 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 909 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 910 | unsigned IncludeOffset = Record[Idx++]; |
| 911 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 912 | FileKind, IncludeOffset)); |
| 913 | } |
| 914 | LineTable.AddEntry(FID, Entries); |
| 915 | } |
| 916 | |
| 917 | return false; |
| 918 | } |
| 919 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 920 | namespace { |
| 921 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 922 | class ASTStatData { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 923 | public: |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 924 | const ino_t ino; |
| 925 | const dev_t dev; |
| 926 | const mode_t mode; |
| 927 | const time_t mtime; |
| 928 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 930 | 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] | 931 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 932 | }; |
| 933 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 934 | class ASTStatLookupTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 935 | public: |
| 936 | typedef const char *external_key_type; |
| 937 | typedef const char *internal_key_type; |
| 938 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 939 | typedef ASTStatData data_type; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 940 | |
| 941 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 942 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 946 | |
| 947 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 948 | return strcmp(a, b) == 0; |
| 949 | } |
| 950 | |
| 951 | static std::pair<unsigned, unsigned> |
| 952 | ReadKeyDataLength(const unsigned char*& d) { |
| 953 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 954 | unsigned DataLen = (unsigned) *d++; |
| 955 | return std::make_pair(KeyLen + 1, DataLen); |
| 956 | } |
| 957 | |
| 958 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 959 | return (const char *)d; |
| 960 | } |
| 961 | |
| 962 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 963 | unsigned /*DataLen*/) { |
| 964 | using namespace clang::io; |
| 965 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 966 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 967 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 968 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 970 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 971 | return data_type(ino, dev, mode, mtime, size); |
| 972 | } |
| 973 | }; |
| 974 | |
| 975 | /// \brief stat() cache for precompiled headers. |
| 976 | /// |
| 977 | /// This cache is very similar to the stat cache used by pretokenized |
| 978 | /// headers. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 979 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 980 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 981 | CacheTy *Cache; |
| 982 | |
| 983 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 984 | public: |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 985 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 986 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 987 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 988 | Cache = CacheTy::Create(Buckets, Base); |
| 989 | } |
| 990 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 991 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 993 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 994 | int *FileDescriptor) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 995 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 996 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 997 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 998 | // 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] | 999 | if (I == Cache->end()) { |
| 1000 | ++NumStatMisses; |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 1001 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1002 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1004 | ++NumStatHits; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1005 | ASTStatData Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1007 | StatBuf.st_ino = Data.ino; |
| 1008 | StatBuf.st_dev = Data.dev; |
| 1009 | StatBuf.st_mtime = Data.mtime; |
| 1010 | StatBuf.st_mode = Data.mode; |
| 1011 | StatBuf.st_size = Data.size; |
Chris Lattner | 8f0583d | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1012 | return CacheExists; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1013 | } |
| 1014 | }; |
| 1015 | } // end anonymous namespace |
| 1016 | |
| 1017 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1018 | /// \brief Read a source manager block |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1019 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1020 | using namespace SrcMgr; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1021 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1022 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1023 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1024 | // Set the source-location entry cursor to the current position in |
| 1025 | // the stream. This cursor will be used to read the contents of the |
| 1026 | // source manager block initially, and then lazily read |
| 1027 | // source-location entries as needed. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1028 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1029 | |
| 1030 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1031 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1032 | Error("malformed block record in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1033 | return Failure; |
| 1034 | } |
| 1035 | |
| 1036 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1037 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1038 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1039 | return Failure; |
| 1040 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1041 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1042 | RecordData Record; |
| 1043 | while (true) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1044 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1045 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1046 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1047 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1048 | return Failure; |
| 1049 | } |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1050 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1051 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1052 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1053 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1054 | // No known subblocks, always skip them. |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1055 | SLocEntryCursor.ReadSubBlockID(); |
| 1056 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1057 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1058 | return Failure; |
| 1059 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1060 | continue; |
| 1061 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1063 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1064 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1065 | continue; |
| 1066 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1067 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1068 | // Read a record. |
| 1069 | const char *BlobStart; |
| 1070 | unsigned BlobLen; |
| 1071 | Record.clear(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1072 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1073 | default: // Default behavior: ignore. |
| 1074 | break; |
| 1075 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1076 | case SM_SLOC_FILE_ENTRY: |
| 1077 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1078 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1079 | // Once we hit one of the source location entries, we're done. |
| 1080 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1085 | /// \brief If a header file is not found at the path that we expect it to be |
| 1086 | /// and the PCH file was moved from its original location, try to resolve the |
| 1087 | /// file by assuming that header+PCH were moved together and the header is in |
| 1088 | /// the same place relative to the PCH. |
| 1089 | static std::string |
| 1090 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1091 | const std::string &OriginalDir, |
| 1092 | const std::string &CurrDir) { |
| 1093 | assert(OriginalDir != CurrDir && |
| 1094 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1095 | using namespace llvm::sys; |
| 1096 | llvm::SmallString<128> filePath(Filename); |
| 1097 | fs::make_absolute(filePath); |
| 1098 | assert(path::is_absolute(OriginalDir)); |
| 1099 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1100 | |
| 1101 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1102 | fileDirE = path::end(path::parent_path(filePath)); |
| 1103 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1104 | origDirE = path::end(OriginalDir); |
| 1105 | // Skip the common path components from filePath and OriginalDir. |
| 1106 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1107 | *fileDirI == *origDirI) { |
| 1108 | ++fileDirI; |
| 1109 | ++origDirI; |
| 1110 | } |
| 1111 | for (; origDirI != origDirE; ++origDirI) |
| 1112 | path::append(currPCHPath, ".."); |
| 1113 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1114 | path::append(currPCHPath, path::filename(Filename)); |
| 1115 | return currPCHPath.str(); |
| 1116 | } |
| 1117 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1118 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1119 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1120 | if (ID == 0) |
| 1121 | return Success; |
| 1122 | |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1123 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1124 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1125 | return Failure; |
| 1126 | } |
| 1127 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1128 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1129 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1130 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1131 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1132 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1133 | ++NumSLocEntriesRead; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1134 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1135 | if (Code == llvm::bitc::END_BLOCK || |
| 1136 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1137 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1138 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | return Failure; |
| 1140 | } |
| 1141 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1142 | RecordData Record; |
| 1143 | const char *BlobStart; |
| 1144 | unsigned BlobLen; |
| 1145 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1146 | default: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1147 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1148 | return Failure; |
| 1149 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1150 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1151 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1152 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1153 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1154 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1155 | OriginalDir != CurrentDir) { |
| 1156 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1157 | OriginalDir, |
| 1158 | CurrentDir); |
| 1159 | if (!resolved.empty()) |
| 1160 | File = FileMgr.getFile(resolved); |
| 1161 | } |
Axel Naumann | 63fbaed | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1162 | if (File == 0) |
| 1163 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1164 | (time_t)Record[5]); |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1165 | if (File == 0) { |
| 1166 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1167 | ErrorStr += Filename; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1168 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1169 | Error(ErrorStr.c_str()); |
| 1170 | return Failure; |
| 1171 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1173 | if (Record.size() < 6) { |
Ted Kremenek | abb1ddd | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1174 | Error("source location entry is incorrect"); |
| 1175 | return Failure; |
| 1176 | } |
| 1177 | |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1178 | if (!DisableValidation && |
| 1179 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1180 | #if !defined(LLVM_ON_WIN32) |
| 1181 | // In our regression testing, the Windows file system seems to |
| 1182 | // have inconsistent modification times that sometimes |
| 1183 | // erroneously trigger this error-handling path. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1184 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1185 | #endif |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1186 | )) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1187 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1188 | return Failure; |
| 1189 | } |
| 1190 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1191 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1192 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1193 | // This is the module's main file. |
| 1194 | IncludeLoc = getImportLocation(F); |
| 1195 | } |
| 1196 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 26b5c19 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1197 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1198 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1199 | SrcMgr::FileInfo &FileInfo = |
| 1200 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1201 | FileInfo.NumCreatedFIDs = Record[6]; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1202 | if (Record[3]) |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1203 | FileInfo.setHasLineDirectives(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1204 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1205 | break; |
| 1206 | } |
| 1207 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1208 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1209 | const char *Name = BlobStart; |
| 1210 | unsigned Offset = Record[0]; |
| 1211 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1212 | Record.clear(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | unsigned RecCode |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1214 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1215 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1216 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1217 | Error("AST record has invalid code"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1218 | return Failure; |
| 1219 | } |
| 1220 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1221 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1222 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1223 | Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1224 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1225 | BaseOffset + Offset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1227 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1228 | PCHPredefinesBlock Block = { |
| 1229 | BufferID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1230 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1231 | }; |
| 1232 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1233 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1234 | |
| 1235 | break; |
| 1236 | } |
| 1237 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1238 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1239 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | 115b077 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1240 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1241 | ReadSourceLocation(*F, Record[2]), |
| 1242 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1243 | Record[4], |
| 1244 | ID, |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1245 | BaseOffset + Record[0]); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1246 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1247 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | return Success; |
| 1251 | } |
| 1252 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1253 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1254 | SourceLocation ASTReader::getImportLocation(Module *F) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1255 | if (F->ImportLoc.isValid()) |
| 1256 | return F->ImportLoc; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1257 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1258 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1259 | // location of its includer. |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1260 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1261 | // Main file is the importer. We assume that it is the first entry in the |
| 1262 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1263 | // the main file entry doesn't exist yet. |
| 1264 | // The very first entry is the invalid instantiation loc, which takes up |
| 1265 | // offsets 0 and 1. |
| 1266 | return SourceLocation::getFromRawEncoding(2U); |
| 1267 | } |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1268 | //return F->Loaders[0]->FirstLoc; |
| 1269 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1272 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1273 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1274 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1275 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1276 | unsigned BlockID) { |
| 1277 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1278 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1279 | return Failure; |
| 1280 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1281 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1282 | while (true) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1283 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1284 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1285 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1286 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1287 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1288 | Cursor.JumpToBit(Offset); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1289 | return false; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1290 | } |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1291 | Cursor.ReadAbbrevRecord(); |
| 1292 | } |
| 1293 | } |
| 1294 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1295 | void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1296 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1297 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1298 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1299 | // Keep track of where we are in the stream, then jump back there |
| 1300 | // after reading this macro. |
| 1301 | SavedStreamPosition SavedPosition(Stream); |
| 1302 | |
| 1303 | Stream.JumpToBit(Offset); |
| 1304 | RecordData Record; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1305 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1306 | MacroInfo *Macro = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1307 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1308 | while (true) { |
| 1309 | unsigned Code = Stream.ReadCode(); |
| 1310 | switch (Code) { |
| 1311 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1312 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1313 | |
| 1314 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1315 | // No known subblocks, always skip them. |
| 1316 | Stream.ReadSubBlockID(); |
| 1317 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1318 | Error("malformed block record in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1319 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1320 | } |
| 1321 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1322 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1323 | case llvm::bitc::DEFINE_ABBREV: |
| 1324 | Stream.ReadAbbrevRecord(); |
| 1325 | continue; |
| 1326 | default: break; |
| 1327 | } |
| 1328 | |
| 1329 | // Read a record. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1330 | const char *BlobStart = 0; |
| 1331 | unsigned BlobLen = 0; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1332 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1333 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1334 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1335 | BlobLen); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1336 | switch (RecType) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1337 | case PP_MACRO_OBJECT_LIKE: |
| 1338 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1339 | // If we already have a macro, that means that we've hit the end |
| 1340 | // of the definition of the macro we were looking for. We're |
| 1341 | // done. |
| 1342 | if (Macro) |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1343 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1344 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1345 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | if (II == 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1347 | Error("macro must have a name in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1348 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1349 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1350 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1351 | bool isUsed = Record[2]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1353 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1354 | MI->setIsUsed(isUsed); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1355 | MI->setIsFromAST(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1356 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1357 | unsigned NextIndex = 3; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1358 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1359 | // Decode function-like macro info. |
| 1360 | bool isC99VarArgs = Record[3]; |
| 1361 | bool isGNUVarArgs = Record[4]; |
| 1362 | MacroArgs.clear(); |
| 1363 | unsigned NumArgs = Record[5]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1364 | NextIndex = 6 + NumArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1365 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1366 | MacroArgs.push_back(getLocalIdentifier(F, Record[6+i])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1367 | |
| 1368 | // Install function-like macro info. |
| 1369 | MI->setIsFunctionLike(); |
| 1370 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1371 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1372 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1373 | PP->getPreprocessorAllocator()); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | // Finally, install the macro. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1377 | PP->setMacroInfo(II, MI); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1378 | |
| 1379 | // Remember that we saw this macro last so that we add the tokens that |
| 1380 | // form its body to it. |
| 1381 | Macro = MI; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1382 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1383 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1384 | // We have a macro definition. Load it now. |
| 1385 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1386 | getLocalMacroDefinition(F, Record[NextIndex])); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1387 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1388 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1389 | ++NumMacrosRead; |
| 1390 | break; |
| 1391 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1392 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1393 | case PP_TOKEN: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1394 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1395 | // erroneous, just pretend we didn't see this. |
| 1396 | if (Macro == 0) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1397 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1398 | Token Tok; |
| 1399 | Tok.startToken(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1400 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1401 | Tok.setLength(Record[1]); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1402 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1403 | Tok.setIdentifierInfo(II); |
| 1404 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1405 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1406 | Macro->AddTokenToBody(Tok); |
| 1407 | break; |
| 1408 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1409 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1410 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1411 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1412 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1415 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1416 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1417 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1418 | switch (Code) { |
| 1419 | case llvm::bitc::END_BLOCK: |
| 1420 | return 0; |
| 1421 | |
| 1422 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1423 | Error("unexpected subblock record in preprocessor detail block"); |
| 1424 | return 0; |
| 1425 | |
| 1426 | case llvm::bitc::DEFINE_ABBREV: |
| 1427 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1428 | return 0; |
| 1429 | |
| 1430 | default: |
| 1431 | break; |
| 1432 | } |
| 1433 | |
| 1434 | if (!PP->getPreprocessingRecord()) { |
| 1435 | Error("no preprocessing record"); |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | // Read the record. |
| 1440 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1441 | const char *BlobStart = 0; |
| 1442 | unsigned BlobLen = 0; |
| 1443 | RecordData Record; |
| 1444 | PreprocessorDetailRecordTypes RecType = |
| 1445 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1446 | Code, Record, BlobStart, BlobLen); |
| 1447 | switch (RecType) { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1448 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1449 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1450 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1451 | return PE; |
| 1452 | |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1453 | MacroExpansion *ME = |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1454 | new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1455 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1456 | ReadSourceLocation(F, Record[2])), |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1457 | getLocalMacroDefinition(F, Record[4])); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1458 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ME); |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1459 | return ME; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | case PPD_MACRO_DEFINITION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1463 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1464 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1465 | return PE; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1466 | |
| 1467 | unsigned MacroDefID = getGlobalMacroDefinitionID(F, Record[1]); |
| 1468 | if (MacroDefID > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1469 | Error("out-of-bounds macro definition record"); |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | // Decode the identifier info and then check again; if the macro is |
| 1474 | // still defined and associated with the identifier, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1475 | IdentifierInfo *II = getLocalIdentifier(F, Record[4]); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1476 | if (!MacroDefinitionsLoaded[MacroDefID - 1]) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1477 | MacroDefinition *MD |
| 1478 | = new (PPRec) MacroDefinition(II, |
| 1479 | ReadSourceLocation(F, Record[5]), |
| 1480 | SourceRange( |
| 1481 | ReadSourceLocation(F, Record[2]), |
| 1482 | ReadSourceLocation(F, Record[3]))); |
| 1483 | |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1484 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, MD); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1485 | MacroDefinitionsLoaded[MacroDefID - 1] = MD; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1486 | |
| 1487 | if (DeserializationListener) |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1488 | DeserializationListener->MacroDefinitionRead(MacroDefID, MD); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1489 | } |
| 1490 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1491 | return MacroDefinitionsLoaded[MacroDefID - 1]; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | case PPD_INCLUSION_DIRECTIVE: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1495 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1496 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1497 | return PE; |
| 1498 | |
| 1499 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1500 | const FileEntry *File |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1501 | = PP->getFileManager().getFile(StringRef(FullFileNameStart, |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1502 | BlobLen - Record[3])); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1503 | |
| 1504 | // FIXME: Stable encoding |
| 1505 | InclusionDirective::InclusionKind Kind |
| 1506 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1507 | InclusionDirective *ID |
| 1508 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1509 | StringRef(BlobStart, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1510 | Record[4], |
| 1511 | File, |
| 1512 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1513 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1514 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ID); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1515 | return ID; |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | Error("invalid offset in preprocessor detail block"); |
| 1520 | return 0; |
| 1521 | } |
| 1522 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1523 | PreprocessedEntityID |
| 1524 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) { |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1525 | ContinuousRangeMap<uint32_t, int, 2>::iterator |
| 1526 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1527 | assert(I != M.PreprocessedEntityRemap.end() |
| 1528 | && "Invalid index into preprocessed entity index remap"); |
| 1529 | |
| 1530 | return LocalID + I->second; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1533 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1534 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1535 | } |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1536 | |
| 1537 | HeaderFileInfoTrait::internal_key_type |
| 1538 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1539 | |
| 1540 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1541 | if (strcmp(a, b) == 0) |
| 1542 | return true; |
| 1543 | |
| 1544 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1545 | return false; |
| 1546 | |
| 1547 | // The file names match, but the path names don't. stat() the files to |
| 1548 | // see if they are the same. |
| 1549 | struct stat StatBufA, StatBufB; |
| 1550 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1551 | return false; |
| 1552 | |
| 1553 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1554 | } |
| 1555 | |
| 1556 | std::pair<unsigned, unsigned> |
| 1557 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1558 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1559 | unsigned DataLen = (unsigned) *d++; |
| 1560 | return std::make_pair(KeyLen + 1, DataLen); |
| 1561 | } |
| 1562 | |
| 1563 | HeaderFileInfoTrait::data_type |
| 1564 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1565 | unsigned DataLen) { |
| 1566 | const unsigned char *End = d + DataLen; |
| 1567 | using namespace clang::io; |
| 1568 | HeaderFileInfo HFI; |
| 1569 | unsigned Flags = *d++; |
| 1570 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1571 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1572 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1573 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1574 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1575 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1576 | HFI.ControllingMacroID = Reader.getGlobalDeclID(M, ReadUnalignedLE32(d)); |
| 1577 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1578 | // The framework offset is 1 greater than the actual offset, |
| 1579 | // since 0 is used as an indicator for "no framework name". |
| 1580 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1581 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1582 | } |
| 1583 | |
| 1584 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1585 | (void)End; |
| 1586 | |
| 1587 | // This HeaderFileInfo was externally loaded. |
| 1588 | HFI.External = true; |
| 1589 | return HFI; |
| 1590 | } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1591 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1592 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1593 | uint64_t LocalOffset) { |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1594 | // Note that this identifier has a macro definition. |
| 1595 | II->setHasMacroDefinition(true); |
| 1596 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1597 | // Adjust the offset to a global offset. |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1598 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1601 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1602 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1603 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1604 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1605 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1606 | // If there was no preprocessor block, skip this file. |
| 1607 | if (!MacroCursor.getBitStreamReader()) |
| 1608 | continue; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1609 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1610 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1611 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1612 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1613 | RecordData Record; |
| 1614 | while (true) { |
| 1615 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1616 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1617 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1618 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1619 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1620 | // No known subblocks, always skip them. |
| 1621 | Cursor.ReadSubBlockID(); |
| 1622 | if (Cursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1623 | Error("malformed block record in AST file"); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1624 | return; |
| 1625 | } |
| 1626 | continue; |
| 1627 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1628 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1629 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1630 | Cursor.ReadAbbrevRecord(); |
| 1631 | continue; |
| 1632 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1633 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1634 | // Read a record. |
| 1635 | const char *BlobStart; |
| 1636 | unsigned BlobLen; |
| 1637 | Record.clear(); |
| 1638 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1639 | default: // Default behavior: ignore. |
| 1640 | break; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1641 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1642 | case PP_MACRO_OBJECT_LIKE: |
| 1643 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1644 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1645 | break; |
| 1646 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1647 | case PP_TOKEN: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1648 | // Ignore tokens. |
| 1649 | break; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1650 | } |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1651 | } |
| 1652 | } |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1653 | |
| 1654 | // Drain the unread macro-record offsets map. |
| 1655 | while (!UnreadMacroRecordOffsets.empty()) |
| 1656 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1657 | } |
| 1658 | |
| 1659 | void ASTReader::LoadMacroDefinition( |
| 1660 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1661 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1662 | uint64_t Offset = Pos->second; |
| 1663 | UnreadMacroRecordOffsets.erase(Pos); |
| 1664 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1665 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1666 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1670 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1671 | = UnreadMacroRecordOffsets.find(II); |
| 1672 | LoadMacroDefinition(Pos); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1675 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1676 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1677 | return 0; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1678 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1679 | if (!MacroDefinitionsLoaded[ID - 1]) { |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 1680 | GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID); |
| 1681 | assert(I != GlobalMacroDefinitionMap.end() && |
| 1682 | "Corrupted global macro definition map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1683 | Module &M = *I->second; |
| 1684 | unsigned Index = ID - 1 - M.BaseMacroDefinitionID; |
| 1685 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 1686 | M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]); |
| 1687 | LoadPreprocessedEntity(M); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1688 | } |
| 1689 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1690 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1693 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1694 | std::string Filename = filenameStrRef; |
| 1695 | MaybeAddSystemRootToFilename(Filename); |
| 1696 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1697 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1698 | OriginalDir != CurrentDir) { |
| 1699 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1700 | OriginalDir, |
| 1701 | CurrentDir); |
| 1702 | if (!resolved.empty()) |
| 1703 | File = FileMgr.getFile(resolved); |
| 1704 | } |
| 1705 | |
| 1706 | return File; |
| 1707 | } |
| 1708 | |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1709 | MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) { |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1710 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 1711 | return LocalID; |
| 1712 | |
| 1713 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 1714 | = M.MacroDefinitionRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 1715 | assert(I != M.MacroDefinitionRemap.end() && |
| 1716 | "Invalid index into macro definition ID remap"); |
| 1717 | |
| 1718 | return LocalID + I->second; |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1721 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1722 | /// not an absolute path, add the system root to the beginning of the file |
| 1723 | /// name. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1724 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1725 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1726 | if (!RelocatablePCH) |
| 1727 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1728 | |
Michael J. Spencer | f28df4c | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1729 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1730 | return; |
| 1731 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1732 | if (isysroot.empty()) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1733 | // If no system root was given, default to '/' |
| 1734 | Filename.insert(Filename.begin(), '/'); |
| 1735 | return; |
| 1736 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1737 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1738 | unsigned Length = isysroot.size(); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1739 | if (isysroot[Length - 1] != '/') |
| 1740 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1741 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1742 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1745 | ASTReader::ASTReadResult |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1746 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1747 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1748 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1749 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1750 | Error("malformed block record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1751 | return Failure; |
| 1752 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1753 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1754 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1755 | RecordData Record; |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1756 | bool First = true; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1757 | while (!Stream.AtEndOfStream()) { |
| 1758 | unsigned Code = Stream.ReadCode(); |
| 1759 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1760 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1761 | Error("error at end of module block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1762 | return Failure; |
| 1763 | } |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1764 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1765 | return Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1769 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1770 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1771 | // We lazily load the decls block, but we want to set up the |
| 1772 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1773 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1774 | // With the main cursor, we just skip over it. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1775 | F.DeclsCursor = Stream; |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1776 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1777 | // Read the abbrevs. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1778 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1779 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1780 | return Failure; |
| 1781 | } |
| 1782 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1783 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1784 | case DECL_UPDATES_BLOCK_ID: |
| 1785 | if (Stream.SkipBlock()) { |
| 1786 | Error("malformed block record in AST file"); |
| 1787 | return Failure; |
| 1788 | } |
| 1789 | break; |
| 1790 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1791 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1792 | F.MacroCursor = Stream; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1793 | if (PP) |
| 1794 | PP->setExternalSource(this); |
| 1795 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1796 | if (Stream.SkipBlock() || |
| 1797 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1798 | Error("malformed block record in AST file"); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1799 | return Failure; |
| 1800 | } |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1801 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1802 | break; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1803 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1804 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1805 | F.PreprocessorDetailCursor = Stream; |
| 1806 | if (Stream.SkipBlock() || |
| 1807 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1808 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1809 | Error("malformed preprocessor detail record in AST file"); |
| 1810 | return Failure; |
| 1811 | } |
| 1812 | F.PreprocessorDetailStartOffset |
| 1813 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1814 | break; |
| 1815 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1816 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1817 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1818 | case Success: |
| 1819 | break; |
| 1820 | |
| 1821 | case Failure: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1822 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1823 | return Failure; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1824 | |
| 1825 | case IgnorePCH: |
| 1826 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1827 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1828 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1829 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1830 | First = false; |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1831 | continue; |
| 1832 | } |
| 1833 | |
| 1834 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1835 | Stream.ReadAbbrevRecord(); |
| 1836 | continue; |
| 1837 | } |
| 1838 | |
| 1839 | // Read and process a record. |
| 1840 | Record.clear(); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1841 | const char *BlobStart = 0; |
| 1842 | unsigned BlobLen = 0; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1843 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1844 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1845 | default: // Default behavior: ignore. |
| 1846 | break; |
| 1847 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1848 | case METADATA: { |
| 1849 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1850 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1851 | : diag::warn_pch_version_too_new); |
| 1852 | return IgnorePCH; |
| 1853 | } |
| 1854 | |
| 1855 | RelocatablePCH = Record[4]; |
| 1856 | if (Listener) { |
| 1857 | std::string TargetTriple(BlobStart, BlobLen); |
| 1858 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1859 | return IgnorePCH; |
| 1860 | } |
| 1861 | break; |
| 1862 | } |
| 1863 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1864 | case IMPORTS: { |
| 1865 | // Load each of the imported PCH files. |
| 1866 | unsigned Idx = 0, N = Record.size(); |
| 1867 | while (Idx < N) { |
| 1868 | // Read information about the AST file. |
| 1869 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1870 | unsigned Length = Record[Idx++]; |
| 1871 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1872 | Record.begin() + Idx + Length); |
| 1873 | Idx += Length; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1874 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1875 | // Load the AST file. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1876 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1877 | case Failure: return Failure; |
| 1878 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1879 | case IgnorePCH: return IgnorePCH; |
| 1880 | case Success: break; |
| 1881 | } |
| 1882 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1883 | break; |
| 1884 | } |
| 1885 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1886 | case TYPE_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1887 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1888 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1889 | return Failure; |
| 1890 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1891 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1892 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1893 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1894 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1895 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1896 | if (F.LocalNumTypes > 0) { |
| 1897 | // Introduce the global -> local mapping for types within this module. |
| 1898 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1899 | |
| 1900 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1901 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 1902 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1903 | |
| 1904 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1905 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1906 | break; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1907 | } |
| 1908 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1909 | case DECL_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1910 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1911 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1912 | return Failure; |
| 1913 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1914 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1915 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1916 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1917 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1918 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1919 | if (F.LocalNumDecls > 0) { |
| 1920 | // Introduce the global -> local mapping for declarations within this |
| 1921 | // module. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1922 | GlobalDeclMap.insert( |
| 1923 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1924 | |
| 1925 | // Introduce the local -> global mapping for declarations within this |
| 1926 | // module. |
| 1927 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 1928 | F.BaseDeclID - LocalBaseDeclID)); |
| 1929 | |
| 1930 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1931 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1932 | break; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1935 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1936 | DeclContext *TU = Context ? Context->getTranslationUnitDecl() : 0; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1937 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1938 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1939 | Info.NumLexicalDecls |
| 1940 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1941 | if (TU) |
| 1942 | TU->setHasExternalLexicalStorage(true); |
| 1943 | |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1944 | break; |
| 1945 | } |
| 1946 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1947 | case UPDATE_VISIBLE: { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1948 | unsigned Idx = 0; |
| 1949 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1950 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1951 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1952 | (const unsigned char *)BlobStart, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1953 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1954 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID && Context) { // Is it the TU? |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1955 | DeclContext *TU = Context->getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1956 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1957 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1958 | } else |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1959 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1960 | break; |
| 1961 | } |
| 1962 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1963 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1964 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1965 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 1966 | DeclID First = ReadDeclID(F, Record, i); |
| 1967 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1968 | FirstLatestDeclIDs[First] = Latest; |
| 1969 | } |
| 1970 | break; |
| 1971 | } |
| 1972 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1973 | case LANGUAGE_OPTIONS: |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1974 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1975 | return IgnorePCH; |
| 1976 | break; |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1977 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1978 | case IDENTIFIER_TABLE: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1979 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1980 | if (Record[0]) { |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1981 | F.IdentifierLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1982 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1983 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1984 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1985 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1986 | if (PP) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1987 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1988 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 1989 | } |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1990 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1991 | break; |
| 1992 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1993 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1994 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1995 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1996 | return Failure; |
| 1997 | } |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1998 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1999 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2000 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2001 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2002 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2003 | if (F.LocalNumIdentifiers > 0) { |
| 2004 | // Introduce the global -> local mapping for identifiers within this |
| 2005 | // module. |
| 2006 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2007 | &F)); |
| 2008 | |
| 2009 | // Introduce the local -> global mapping for identifiers within this |
| 2010 | // module. |
| 2011 | F.IdentifierRemap.insert( |
| 2012 | std::make_pair(LocalBaseIdentifierID, |
| 2013 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 2014 | |
| 2015 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2016 | + F.LocalNumIdentifiers); |
| 2017 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2018 | break; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2021 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2022 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2023 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2024 | break; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2025 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2026 | case SPECIAL_TYPES: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2027 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2028 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2029 | break; |
| 2030 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2031 | case STATISTICS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2032 | TotalNumStatements += Record[0]; |
| 2033 | TotalNumMacros += Record[1]; |
| 2034 | TotalLexicalDeclContexts += Record[2]; |
| 2035 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2036 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2037 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2038 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2039 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2040 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2041 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2042 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2043 | case DELEGATING_CTORS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2044 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2045 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2046 | break; |
| 2047 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2048 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2049 | if (Record.size() % 4 != 0) { |
| 2050 | Error("invalid weak identifiers record"); |
| 2051 | return Failure; |
| 2052 | } |
| 2053 | |
| 2054 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2055 | // files. This isn't the way to do it :) |
| 2056 | WeakUndeclaredIdentifiers.clear(); |
| 2057 | |
| 2058 | // Translate the weak, undeclared identifiers into global IDs. |
| 2059 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2060 | WeakUndeclaredIdentifiers.push_back( |
| 2061 | getGlobalIdentifierID(F, Record[I++])); |
| 2062 | WeakUndeclaredIdentifiers.push_back( |
| 2063 | getGlobalIdentifierID(F, Record[I++])); |
| 2064 | WeakUndeclaredIdentifiers.push_back( |
| 2065 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2066 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2067 | } |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2068 | break; |
| 2069 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2070 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2071 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2072 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2073 | break; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2074 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2075 | case SELECTOR_OFFSETS: { |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2076 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2077 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2078 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2079 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2080 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2081 | if (F.LocalNumSelectors > 0) { |
| 2082 | // Introduce the global -> local mapping for selectors within this |
| 2083 | // module. |
| 2084 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2085 | |
| 2086 | // Introduce the local -> global mapping for selectors within this |
| 2087 | // module. |
| 2088 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 2089 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2090 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2091 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2092 | } |
| 2093 | break; |
| 2094 | } |
| 2095 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2096 | case METHOD_POOL: |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2097 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2098 | if (Record[0]) |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2099 | F.SelectorLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2100 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2101 | F.SelectorLookupTableData + Record[0], |
| 2102 | F.SelectorLookupTableData, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2103 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2104 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2105 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2106 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2107 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2108 | if (!Record.empty()) { |
| 2109 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2110 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2111 | Record[Idx++])); |
| 2112 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2113 | getRawEncoding()); |
| 2114 | } |
| 2115 | } |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2116 | break; |
| 2117 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2118 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2119 | if (!Record.empty() && Listener) |
| 2120 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2121 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2122 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2123 | case SOURCE_LOCATION_OFFSETS: { |
| 2124 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2125 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2126 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2127 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2128 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2129 | // we invert it. Because we invert it, though, we need the other end of |
| 2130 | // the range. |
| 2131 | unsigned RangeStart = |
| 2132 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2133 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2134 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2135 | |
| 2136 | // Initialize the remapping table. |
| 2137 | // Invalid stays invalid. |
| 2138 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2139 | // This module. Base was 2 when being compiled. |
| 2140 | F.SLocRemap.insert(std::make_pair(2U, |
| 2141 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2142 | |
| 2143 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2144 | break; |
| 2145 | } |
| 2146 | |
Douglas Gregor | 5a1797c | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2147 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2148 | // Additional remapping information. |
| 2149 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2150 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2151 | |
| 2152 | // Continuous range maps we may be updating in our module. |
| 2153 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2154 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2155 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2156 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2157 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2158 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2159 | MacroDefinitionRemap(F.MacroDefinitionRemap); |
| 2160 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2161 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2162 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2163 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2164 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2165 | while(Data < DataEnd) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2166 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2167 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2168 | Data += Len; |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2169 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2170 | if (!OM) { |
| 2171 | Error("SourceLocation remap refers to unknown module"); |
| 2172 | return Failure; |
| 2173 | } |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2174 | |
| 2175 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2176 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2177 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
| 2178 | uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data); |
| 2179 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2180 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2181 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2182 | |
| 2183 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2184 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2185 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2186 | IdentifierRemap.insert( |
| 2187 | std::make_pair(IdentifierIDOffset, |
| 2188 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2189 | PreprocessedEntityRemap.insert( |
| 2190 | std::make_pair(PreprocessedEntityIDOffset, |
| 2191 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2192 | MacroDefinitionRemap.insert( |
| 2193 | std::make_pair(MacroDefinitionIDOffset, |
| 2194 | OM->BaseMacroDefinitionID - MacroDefinitionIDOffset)); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2195 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2196 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2197 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2198 | OM->BaseDeclID - DeclIDOffset)); |
| 2199 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2200 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2201 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2202 | } |
| 2203 | break; |
| 2204 | } |
| 2205 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2206 | case SOURCE_MANAGER_LINE_TABLE: |
| 2207 | if (ParseLineTable(F, Record)) |
| 2208 | return Failure; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2209 | break; |
| 2210 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2211 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2212 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2213 | F.LocalNumSLocFileEntries = Record[0]; |
| 2214 | break; |
| 2215 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2216 | case SOURCE_LOCATION_PRELOADS: { |
| 2217 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2218 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | a918bab | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2219 | if (!F.PreloadSLocEntries.empty()) { |
| 2220 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2221 | return Failure; |
| 2222 | } |
| 2223 | |
| 2224 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2225 | break; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2226 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2227 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2228 | case STAT_CACHE: { |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2229 | if (!DisableStatCache) { |
| 2230 | ASTStatCache *MyStatCache = |
| 2231 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2232 | (const unsigned char *)BlobStart, |
| 2233 | NumStatHits, NumStatMisses); |
| 2234 | FileMgr.addStatCache(MyStatCache); |
| 2235 | F.StatCache = MyStatCache; |
| 2236 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2237 | break; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2238 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2239 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2240 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2241 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2242 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2243 | break; |
| 2244 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2245 | case VTABLE_USES: |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2246 | if (Record.size() % 3 != 0) { |
| 2247 | Error("Invalid VTABLE_USES record"); |
| 2248 | return Failure; |
| 2249 | } |
| 2250 | |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2251 | // Later tables overwrite earlier ones. |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2252 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2253 | // the right way to do this. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2254 | VTableUses.clear(); |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2255 | |
| 2256 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2257 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2258 | VTableUses.push_back( |
| 2259 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2260 | VTableUses.push_back(Record[Idx++]); |
| 2261 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2264 | case DYNAMIC_CLASSES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2265 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2266 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2267 | break; |
| 2268 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2269 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | bbbc367 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2270 | if (PendingInstantiations.size() % 2 != 0) { |
| 2271 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2272 | return Failure; |
| 2273 | } |
| 2274 | |
| 2275 | // Later lists of pending instantiations overwrite earlier ones. |
| 2276 | // FIXME: This is most certainly wrong for modules. |
| 2277 | PendingInstantiations.clear(); |
| 2278 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2279 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2280 | PendingInstantiations.push_back( |
| 2281 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2282 | } |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2283 | break; |
| 2284 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2285 | case SEMA_DECL_REFS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2286 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2287 | // FIXME: Modules will have some trouble with this. |
| 2288 | SemaDeclRefs.clear(); |
| 2289 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2290 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2293 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2294 | // 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] | 2295 | // that's used. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2296 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2297 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2298 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2299 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2300 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2301 | case ORIGINAL_FILE_ID: |
| 2302 | OriginalFileID = FileID::get(Record[0]); |
| 2303 | break; |
| 2304 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2305 | case ORIGINAL_PCH_DIR: |
| 2306 | // The primary AST will be the last to get here, so it will be the one |
| 2307 | // that's used. |
| 2308 | OriginalDir.assign(BlobStart, BlobLen); |
| 2309 | break; |
| 2310 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2311 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 8bd0929 | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2312 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2313 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2314 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2315 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2316 | return IgnorePCH; |
| 2317 | } |
| 2318 | break; |
| 2319 | } |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2320 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2321 | case MACRO_DEFINITION_OFFSETS: { |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2322 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2323 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2324 | unsigned LocalBasePreprocessedEntityID = Record[1]; |
| 2325 | F.LocalNumMacroDefinitions = Record[2]; |
| 2326 | unsigned LocalBaseMacroID = Record[3]; |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2327 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2328 | unsigned StartingID; |
| 2329 | if (PP) { |
| 2330 | if (!PP->getPreprocessingRecord()) |
| 2331 | PP->createPreprocessingRecord(true); |
| 2332 | if (!PP->getPreprocessingRecord()->getExternalSource()) |
| 2333 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2334 | StartingID |
| 2335 | = PP->getPreprocessingRecord() |
| 2336 | ->allocateLoadedEntities(F.NumPreallocatedPreprocessingEntities); |
| 2337 | } else { |
| 2338 | // FIXME: We'll eventually want to kill this path, since it assumes |
| 2339 | // a particular allocation strategy in the preprocessing record. |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2340 | StartingID = getTotalNumPreprocessedEntities() |
| 2341 | - F.NumPreallocatedPreprocessingEntities; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2342 | } |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2343 | F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); |
| 2344 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2345 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2346 | if (F.NumPreallocatedPreprocessingEntities > 0) { |
| 2347 | // Introduce the global -> local mapping for preprocessed entities in |
| 2348 | // this module. |
| 2349 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2350 | |
| 2351 | // Introduce the local -> global mapping for preprocessed entities in |
| 2352 | // this module. |
| 2353 | F.PreprocessedEntityRemap.insert( |
| 2354 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2355 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2356 | } |
| 2357 | |
| 2358 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2359 | if (F.LocalNumMacroDefinitions > 0) { |
| 2360 | // Introduce the global -> local mapping for macro definitions within |
| 2361 | // this module. |
| 2362 | GlobalMacroDefinitionMap.insert( |
| 2363 | std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); |
| 2364 | |
| 2365 | // Introduce the local -> global mapping for macro definitions within |
| 2366 | // this module. |
| 2367 | F.MacroDefinitionRemap.insert( |
| 2368 | std::make_pair(LocalBaseMacroID, |
| 2369 | F.BaseMacroDefinitionID - LocalBaseMacroID)); |
| 2370 | |
| 2371 | MacroDefinitionsLoaded.resize( |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 2372 | MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2375 | break; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2376 | } |
| 2377 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2378 | case DECL_UPDATE_OFFSETS: { |
| 2379 | if (Record.size() % 2 != 0) { |
| 2380 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2381 | return Failure; |
| 2382 | } |
| 2383 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2384 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2385 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2386 | break; |
| 2387 | } |
| 2388 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2389 | case DECL_REPLACEMENTS: { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2390 | if (Record.size() % 2 != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2391 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2392 | return Failure; |
| 2393 | } |
| 2394 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2395 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2396 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2397 | break; |
| 2398 | } |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2399 | |
| 2400 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2401 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2402 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2403 | return Failure; |
| 2404 | } |
| 2405 | |
| 2406 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2407 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2408 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2409 | break; |
| 2410 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2411 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2412 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2413 | if (Record.size() % 2 != 0) { |
| 2414 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2415 | return Failure; |
| 2416 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2417 | |
| 2418 | if (F.PragmaDiagMappings.empty()) |
| 2419 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2420 | else |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2421 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2422 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2423 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2424 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2425 | case CUDA_SPECIAL_DECL_REFS: |
| 2426 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2427 | // FIXME: Modules will have trouble with this. |
| 2428 | CUDASpecialDeclRefs.clear(); |
| 2429 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2430 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2431 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2432 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2433 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2434 | F.HeaderFileInfoTableData = BlobStart; |
| 2435 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2436 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2437 | if (Record[0]) { |
| 2438 | F.HeaderFileInfoTable |
| 2439 | = HeaderFileInfoLookupTable::Create( |
| 2440 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2441 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2442 | HeaderFileInfoTrait(*this, F, |
| 2443 | PP? &PP->getHeaderSearchInfo() : 0, |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2444 | BlobStart + Record[2])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2445 | if (PP) |
| 2446 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2447 | } |
| 2448 | break; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2451 | case FP_PRAGMA_OPTIONS: |
| 2452 | // Later tables overwrite earlier ones. |
| 2453 | FPPragmaOptions.swap(Record); |
| 2454 | break; |
| 2455 | |
| 2456 | case OPENCL_EXTENSIONS: |
| 2457 | // Later tables overwrite earlier ones. |
| 2458 | OpenCLExtensions.swap(Record); |
| 2459 | break; |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2460 | |
| 2461 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2462 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2463 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2464 | break; |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2465 | |
| 2466 | case KNOWN_NAMESPACES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2467 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2468 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2469 | break; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2470 | } |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 2471 | First = false; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2472 | } |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2473 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2474 | return Failure; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2477 | ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) { |
| 2478 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2479 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2480 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2481 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2482 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2483 | if (Code == llvm::bitc::END_BLOCK || |
| 2484 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2485 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2486 | Error("incorrectly-formatted source location entry in AST file"); |
| 2487 | return Failure; |
| 2488 | } |
| 2489 | |
| 2490 | RecordData Record; |
| 2491 | const char *BlobStart; |
| 2492 | unsigned BlobLen; |
| 2493 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2494 | default: |
| 2495 | Error("incorrectly-formatted source location entry in AST file"); |
| 2496 | return Failure; |
| 2497 | |
| 2498 | case SM_SLOC_FILE_ENTRY: { |
| 2499 | StringRef Filename(BlobStart, BlobLen); |
| 2500 | const FileEntry *File = getFileEntry(Filename); |
| 2501 | |
| 2502 | if (File == 0) { |
| 2503 | std::string ErrorStr = "could not find file '"; |
| 2504 | ErrorStr += Filename; |
| 2505 | ErrorStr += "' referenced by AST file"; |
| 2506 | Error(ErrorStr.c_str()); |
| 2507 | return IgnorePCH; |
| 2508 | } |
| 2509 | |
| 2510 | if (Record.size() < 6) { |
| 2511 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2512 | return Failure; |
| 2513 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2514 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2515 | // The stat info from the FileEntry came from the cached stat |
| 2516 | // info of the PCH, so we cannot trust it. |
| 2517 | struct stat StatBuf; |
| 2518 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2519 | StatBuf.st_size = File->getSize(); |
| 2520 | StatBuf.st_mtime = File->getModificationTime(); |
| 2521 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2522 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2523 | if (((off_t)Record[4] != StatBuf.st_size |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2524 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2525 | // In our regression testing, the Windows file system seems to |
| 2526 | // have inconsistent modification times that sometimes |
| 2527 | // erroneously trigger this error-handling path. |
| 2528 | || (time_t)Record[5] != StatBuf.st_mtime |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2529 | #endif |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2530 | )) { |
| 2531 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2532 | return IgnorePCH; |
| 2533 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2534 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | return Success; |
| 2541 | } |
| 2542 | |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame^] | 2543 | namespace { |
| 2544 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 2545 | class IdentifierLookupVisitor { |
| 2546 | StringRef Name; |
| 2547 | IdentifierInfo *Found; |
| 2548 | public: |
| 2549 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
| 2550 | |
| 2551 | static bool visit(Module &M, void *UserData) { |
| 2552 | IdentifierLookupVisitor *This |
| 2553 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 2554 | |
| 2555 | ASTIdentifierLookupTable *IdTable |
| 2556 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 2557 | if (!IdTable) |
| 2558 | return false; |
| 2559 | |
| 2560 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 2561 | This->Name.size()); |
| 2562 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2563 | if (Pos == IdTable->end()) |
| 2564 | return false; |
| 2565 | |
| 2566 | // Dereferencing the iterator has the effect of building the |
| 2567 | // IdentifierInfo node and populating it with the various |
| 2568 | // declarations it needs. |
| 2569 | This->Found = *Pos; |
| 2570 | return true; |
| 2571 | } |
| 2572 | |
| 2573 | // \brief Retrieve the identifier info found within the module |
| 2574 | // files. |
| 2575 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 2576 | }; |
| 2577 | } |
| 2578 | |
| 2579 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2580 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2581 | ModuleKind Type) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2582 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2583 | case Failure: return Failure; |
| 2584 | case IgnorePCH: return IgnorePCH; |
| 2585 | case Success: break; |
| 2586 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2587 | |
| 2588 | // Here comes stuff that we only do once the entire chain is loaded. |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2589 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2590 | // Check the predefines buffers. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2591 | if (!DisableValidation && Type != MK_Module && CheckPredefinesBuffers()) |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2592 | return IgnorePCH; |
| 2593 | |
| 2594 | if (PP) { |
| 2595 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2596 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2597 | // loaded into the IdentifierTable before we intercepted the |
| 2598 | // creation of identifiers. Iterate through the list of known |
| 2599 | // identifiers and determine whether we have to establish |
| 2600 | // preprocessor definitions or top-level identifier declaration |
| 2601 | // chains for those identifiers. |
| 2602 | // |
| 2603 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2604 | // since de-serializing declarations or macro definitions can add |
| 2605 | // new entries into the identifier table, invalidating the |
| 2606 | // iterators. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2607 | // |
| 2608 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2609 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2610 | // AST file(s) if it is uttered in the source. This could save us some |
| 2611 | // module load time. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2612 | SmallVector<IdentifierInfo *, 128> Identifiers; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2613 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2614 | IdEnd = PP->getIdentifierTable().end(); |
| 2615 | Id != IdEnd; ++Id) |
| 2616 | Identifiers.push_back(Id->second); |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame^] | 2617 | |
| 2618 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2619 | IdentifierLookupVisitor Visitor(Identifiers[I]->getName()); |
| 2620 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | if (Context) |
| 2625 | InitializeContext(*Context); |
| 2626 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2627 | if (DeserializationListener) |
| 2628 | DeserializationListener->ReaderInitialized(this); |
| 2629 | |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2630 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2631 | // the source manager to the file source file from which the preamble was |
| 2632 | // built. This is the only valid way to use a precompiled preamble. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2633 | if (Type == MK_Preamble) { |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2634 | if (OriginalFileID.isInvalid()) { |
| 2635 | SourceLocation Loc |
| 2636 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2637 | if (Loc.isValid()) |
| 2638 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2639 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2640 | else { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2641 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2642 | + OriginalFileID.getOpaqueValue() - 1); |
| 2643 | } |
| 2644 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2645 | if (!OriginalFileID.isInvalid()) |
| 2646 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2649 | return Success; |
| 2650 | } |
| 2651 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2652 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2653 | ModuleKind Type, |
| 2654 | Module *ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2655 | Module *M; |
| 2656 | bool NewModule; |
| 2657 | std::string ErrorStr; |
| 2658 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2659 | ErrorStr); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2660 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2661 | if (!M) { |
| 2662 | // We couldn't load the module. |
| 2663 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2664 | + ErrorStr; |
| 2665 | Error(Msg); |
| 2666 | return Failure; |
| 2667 | } |
| 2668 | |
| 2669 | if (!NewModule) { |
| 2670 | // We've already loaded this module. |
| 2671 | return Success; |
| 2672 | } |
| 2673 | |
| 2674 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2675 | // module? |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2676 | if (FileName != "-") { |
| 2677 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2678 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2679 | } |
| 2680 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2681 | Module &F = *M; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2682 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2683 | Stream.init(F.StreamFile); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2684 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2685 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2686 | // Sniff for the signature. |
| 2687 | if (Stream.Read(8) != 'C' || |
| 2688 | Stream.Read(8) != 'P' || |
| 2689 | Stream.Read(8) != 'C' || |
| 2690 | Stream.Read(8) != 'H') { |
| 2691 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2692 | return Failure; |
| 2693 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2694 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2695 | while (!Stream.AtEndOfStream()) { |
| 2696 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2697 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2698 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2699 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2700 | return Failure; |
| 2701 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2702 | |
| 2703 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2704 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2705 | // We only know the AST subblock ID. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2706 | switch (BlockID) { |
| 2707 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2708 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2709 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2710 | return Failure; |
| 2711 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2712 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2713 | case AST_BLOCK_ID: |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2714 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2715 | case Success: |
| 2716 | break; |
| 2717 | |
| 2718 | case Failure: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2719 | return Failure; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2720 | |
| 2721 | case IgnorePCH: |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2722 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2723 | // AST block, skipping subblocks, to see if there are other |
| 2724 | // AST blocks elsewhere. |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2725 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2726 | // FIXME: We can't clear loaded slocentries anymore. |
| 2727 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2728 | |
| 2729 | // Remove the stat cache. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2730 | if (F.StatCache) |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2731 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2732 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2733 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2734 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2735 | break; |
| 2736 | default: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2737 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2738 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2739 | return Failure; |
| 2740 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2741 | break; |
| 2742 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2743 | } |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2744 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2745 | // 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] | 2746 | // bits of all files we've seen. |
| 2747 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2748 | TotalModulesSizeInBits += F.SizeInBits; |
| 2749 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2750 | |
| 2751 | // Make sure that the files this module was built against are still available. |
| 2752 | if (!DisableValidation) { |
| 2753 | switch(validateFileEntries(*M)) { |
| 2754 | case Failure: return Failure; |
| 2755 | case IgnorePCH: return IgnorePCH; |
| 2756 | case Success: break; |
| 2757 | } |
| 2758 | } |
Douglas Gregor | a918bab | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2759 | |
| 2760 | // Preload SLocEntries. |
| 2761 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2762 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 2763 | ASTReadResult Result = ReadSLocEntryRecord(Index); |
| 2764 | if (Result != Success) |
| 2765 | return Failure; |
| 2766 | } |
| 2767 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2768 | |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2769 | return Success; |
| 2770 | } |
| 2771 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2772 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2773 | PP = &pp; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2774 | |
| 2775 | if (unsigned N = getTotalNumPreprocessedEntities()) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2776 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | 998caea | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2777 | PP->createPreprocessingRecord(true); |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2778 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2779 | PP->getPreprocessingRecord()->allocateLoadedEntities(N); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2780 | } |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2781 | |
| 2782 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2783 | PP->getHeaderSearchInfo().SetExternalSource(this); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2786 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2787 | Context = &Ctx; |
| 2788 | assert(Context && "Passed null context!"); |
| 2789 | |
| 2790 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2791 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2792 | PP->setExternalSource(this); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2793 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2794 | // If we have any update blocks for the TU waiting, we have to add |
| 2795 | // them before we deserialize anything. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2796 | TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2797 | for (ModuleIterator M = ModuleMgr.begin(), MEnd = ModuleMgr.end(); |
| 2798 | M != MEnd; ++M) { |
| 2799 | Module::DeclContextInfosMap::iterator DCU |
| 2800 | = (*M)->DeclContextInfos.find(0); |
| 2801 | if (DCU != (*M)->DeclContextInfos.end()) { |
| 2802 | // Insertion could invalidate map, so grab value first. |
| 2803 | DeclContextInfo Info = DCU->second; |
| 2804 | (*M)->DeclContextInfos.erase(DCU); |
| 2805 | (*M)->DeclContextInfos[TU] = Info; |
| 2806 | } |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2807 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2808 | |
| 2809 | // If there's a listener, notify them that we "read" the translation unit. |
| 2810 | if (DeserializationListener) |
| 2811 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2812 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2813 | // Make sure we load the declaration update records for the translation unit, |
| 2814 | // if there are any. |
| 2815 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
| 2816 | |
| 2817 | // Note that the translation unit has external lexical and visible storage. |
| 2818 | TU->setHasExternalLexicalStorage(true); |
| 2819 | TU->setHasExternalVisibleStorage(true); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2820 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2821 | // FIXME: Find a better way to deal with collisions between these |
| 2822 | // built-in types. Right now, we just ignore the problem. |
| 2823 | |
| 2824 | // Load the special types. |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2825 | if (Context->getBuiltinVaListType().isNull()) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2826 | Context->setBuiltinVaListType( |
| 2827 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2828 | } |
| 2829 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2830 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2831 | if (Context->ObjCProtoType.isNull()) |
Douglas Gregor | 09c4aa8 | 2011-08-11 22:04:35 +0000 | [diff] [blame] | 2832 | Context->ObjCProtoType = GetType(Proto); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2835 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2836 | if (!Context->CFConstantStringTypeDecl) |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2837 | Context->setCFConstantStringType(GetType(String)); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2841 | QualType FileType = GetType(File); |
| 2842 | if (FileType.isNull()) { |
| 2843 | Error("FILE type is NULL"); |
| 2844 | return; |
| 2845 | } |
| 2846 | |
| 2847 | if (!Context->FILEDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2848 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2849 | Context->setFILEDecl(Typedef->getDecl()); |
| 2850 | else { |
| 2851 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2852 | if (!Tag) { |
| 2853 | Error("Invalid FILE type in AST file"); |
| 2854 | return; |
| 2855 | } |
| 2856 | Context->setFILEDecl(Tag->getDecl()); |
| 2857 | } |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2858 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 2862 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2863 | if (Jmp_bufType.isNull()) { |
| 2864 | Error("jmp_buf type is NULL"); |
| 2865 | return; |
| 2866 | } |
| 2867 | |
| 2868 | if (!Context->jmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2869 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2870 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2871 | else { |
| 2872 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2873 | if (!Tag) { |
| 2874 | Error("Invalid jmp_buf type in AST file"); |
| 2875 | return; |
| 2876 | } |
| 2877 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2878 | } |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2879 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
| 2882 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 2883 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2884 | if (Sigjmp_bufType.isNull()) { |
| 2885 | Error("sigjmp_buf type is NULL"); |
| 2886 | return; |
| 2887 | } |
| 2888 | |
| 2889 | if (!Context->sigjmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2890 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2891 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2892 | else { |
| 2893 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2894 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2895 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2896 | } |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2897 | } |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2898 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2899 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2900 | if (unsigned ObjCIdRedef |
| 2901 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2902 | if (Context->ObjCIdRedefinitionType.isNull()) |
| 2903 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2904 | } |
| 2905 | |
| 2906 | if (unsigned ObjCClassRedef |
| 2907 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2908 | if (Context->ObjCClassRedefinitionType.isNull()) |
| 2909 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2910 | } |
| 2911 | |
| 2912 | if (unsigned ObjCSelRedef |
| 2913 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2914 | if (Context->ObjCSelRedefinitionType.isNull()) |
| 2915 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2916 | } |
| 2917 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2918 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2919 | |
| 2920 | // If there were any CUDA special declarations, deserialize them. |
| 2921 | if (!CUDASpecialDeclRefs.empty()) { |
| 2922 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2923 | Context->setcudaConfigureCallDecl( |
| 2924 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2925 | } |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2926 | } |
| 2927 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2928 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2929 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2930 | /// file. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2931 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 71731d6 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2932 | FileManager &FileMgr, |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2933 | Diagnostic &Diags) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2934 | // Open the AST file. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2935 | std::string ErrStr; |
| 2936 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2937 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2938 | if (!Buffer) { |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2939 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2940 | return std::string(); |
| 2941 | } |
| 2942 | |
| 2943 | // Initialize the stream |
| 2944 | llvm::BitstreamReader StreamFile; |
| 2945 | llvm::BitstreamCursor Stream; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2946 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2947 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2948 | Stream.init(StreamFile); |
| 2949 | |
| 2950 | // Sniff for the signature. |
| 2951 | if (Stream.Read(8) != 'C' || |
| 2952 | Stream.Read(8) != 'P' || |
| 2953 | Stream.Read(8) != 'C' || |
| 2954 | Stream.Read(8) != 'H') { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2955 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2956 | return std::string(); |
| 2957 | } |
| 2958 | |
| 2959 | RecordData Record; |
| 2960 | while (!Stream.AtEndOfStream()) { |
| 2961 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2962 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2963 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2964 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2965 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2966 | // We only know the AST subblock ID. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2967 | switch (BlockID) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2968 | case AST_BLOCK_ID: |
| 2969 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2970 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2971 | return std::string(); |
| 2972 | } |
| 2973 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2975 | default: |
| 2976 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2977 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2978 | return std::string(); |
| 2979 | } |
| 2980 | break; |
| 2981 | } |
| 2982 | continue; |
| 2983 | } |
| 2984 | |
| 2985 | if (Code == llvm::bitc::END_BLOCK) { |
| 2986 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2987 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2988 | return std::string(); |
| 2989 | } |
| 2990 | continue; |
| 2991 | } |
| 2992 | |
| 2993 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2994 | Stream.ReadAbbrevRecord(); |
| 2995 | continue; |
| 2996 | } |
| 2997 | |
| 2998 | Record.clear(); |
| 2999 | const char *BlobStart = 0; |
| 3000 | unsigned BlobLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3001 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3002 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3003 | return std::string(BlobStart, BlobLen); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3004 | } |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3005 | |
| 3006 | return std::string(); |
| 3007 | } |
| 3008 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3009 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3010 | /// structure. |
| 3011 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3012 | /// This routine parses the language options from the AST file and then gives |
| 3013 | /// them to the AST listener if one is set. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3014 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3015 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3016 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3017 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3018 | if (Listener) { |
| 3019 | LangOptions LangOpts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3020 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3021 | #define PARSE_LANGOPT(Option) \ |
| 3022 | LangOpts.Option = Record[Idx]; \ |
| 3023 | ++Idx |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3024 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3025 | unsigned Idx = 0; |
| 3026 | PARSE_LANGOPT(Trigraphs); |
| 3027 | PARSE_LANGOPT(BCPLComment); |
| 3028 | PARSE_LANGOPT(DollarIdents); |
| 3029 | PARSE_LANGOPT(AsmPreprocessor); |
| 3030 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 3031 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3032 | PARSE_LANGOPT(ImplicitInt); |
| 3033 | PARSE_LANGOPT(Digraphs); |
| 3034 | PARSE_LANGOPT(HexFloats); |
| 3035 | PARSE_LANGOPT(C99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 3036 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3037 | PARSE_LANGOPT(Microsoft); |
| 3038 | PARSE_LANGOPT(CPlusPlus); |
| 3039 | PARSE_LANGOPT(CPlusPlus0x); |
| 3040 | PARSE_LANGOPT(CXXOperatorNames); |
| 3041 | PARSE_LANGOPT(ObjC1); |
| 3042 | PARSE_LANGOPT(ObjC2); |
| 3043 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 3044 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 3045 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 3046 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 3047 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 3048 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3049 | PARSE_LANGOPT(PascalStrings); |
| 3050 | PARSE_LANGOPT(WritableStrings); |
| 3051 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3052 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3053 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 3054 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 3055 | PARSE_LANGOPT(CXXExceptions); |
| 3056 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 3057 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3058 | PARSE_LANGOPT(NeXTRuntime); |
| 3059 | PARSE_LANGOPT(Freestanding); |
| 3060 | PARSE_LANGOPT(NoBuiltin); |
| 3061 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 3062 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3063 | PARSE_LANGOPT(Blocks); |
| 3064 | PARSE_LANGOPT(EmitAllDecls); |
| 3065 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3066 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 3067 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3068 | PARSE_LANGOPT(HeinousExtensions); |
| 3069 | PARSE_LANGOPT(Optimize); |
| 3070 | PARSE_LANGOPT(OptimizeSize); |
| 3071 | PARSE_LANGOPT(Static); |
| 3072 | PARSE_LANGOPT(PICLevel); |
| 3073 | PARSE_LANGOPT(GNUInline); |
| 3074 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 3075 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3076 | PARSE_LANGOPT(AccessControl); |
| 3077 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 3078 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | a88942a | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 3079 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3080 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 3081 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 3082 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3083 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3084 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3085 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 3086 | PARSE_LANGOPT(CUDA); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 3087 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3088 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | dc1f68d | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 3089 | PARSE_LANGOPT(ElideConstructors); |
| 3090 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | 65b88cd | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 3091 | PARSE_LANGOPT(MRTD); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3092 | PARSE_LANGOPT(ObjCAutoRefCount); |
Douglas Gregor | 49b236a | 2011-08-04 15:46:00 +0000 | [diff] [blame] | 3093 | PARSE_LANGOPT(ObjCInferRelatedReturnType); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3094 | #undef PARSE_LANGOPT |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3095 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3096 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3097 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3098 | |
| 3099 | return false; |
| 3100 | } |
| 3101 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 3102 | namespace { |
| 3103 | /// \brief Visitor used by ASTReader::ReadPreprocessedEntities() to load |
| 3104 | /// all of the preprocessed entities within a module. |
| 3105 | class ReadPreprocessedEntitiesVisitor { |
| 3106 | ASTReader &Reader; |
| 3107 | |
| 3108 | public: |
| 3109 | explicit ReadPreprocessedEntitiesVisitor(ASTReader &Reader) |
| 3110 | : Reader(Reader) { } |
| 3111 | |
| 3112 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 3113 | if (Preorder) |
| 3114 | return false; |
| 3115 | |
| 3116 | ReadPreprocessedEntitiesVisitor *This |
| 3117 | = static_cast<ReadPreprocessedEntitiesVisitor *>(UserData); |
| 3118 | |
| 3119 | if (!M.PreprocessorDetailCursor.getBitStreamReader()) |
| 3120 | return false; |
| 3121 | |
| 3122 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 3123 | M.PreprocessorDetailCursor.JumpToBit(M.PreprocessorDetailStartOffset); |
| 3124 | while (This->Reader.LoadPreprocessedEntity(M)) { } |
| 3125 | return false; |
| 3126 | } |
| 3127 | }; |
| 3128 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3129 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 3130 | void ASTReader::ReadPreprocessedEntities() { |
| 3131 | ReadPreprocessedEntitiesVisitor Visitor(*this); |
| 3132 | ModuleMgr.visitDepthFirst(&ReadPreprocessedEntitiesVisitor::visit, &Visitor); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Douglas Gregor | 46c5001 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3135 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3136 | RecordLocation Loc = getLocalBitOffset(Offset); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3137 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3138 | // Keep track of where we are in the stream, then jump back there |
| 3139 | // after reading this entity. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3140 | SavedStreamPosition SavedPosition(Loc.F->PreprocessorDetailCursor); |
| 3141 | Loc.F->PreprocessorDetailCursor.JumpToBit(Loc.Offset); |
| 3142 | return LoadPreprocessedEntity(*Loc.F); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3145 | namespace { |
| 3146 | /// \brief Visitor used to search for information about a header file. |
| 3147 | class HeaderFileInfoVisitor { |
| 3148 | ASTReader &Reader; |
| 3149 | const FileEntry *FE; |
| 3150 | |
| 3151 | llvm::Optional<HeaderFileInfo> HFI; |
| 3152 | |
| 3153 | public: |
| 3154 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3155 | : Reader(Reader), FE(FE) { } |
| 3156 | |
| 3157 | static bool visit(Module &M, void *UserData) { |
| 3158 | HeaderFileInfoVisitor *This |
| 3159 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3160 | |
| 3161 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3162 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3163 | M.HeaderFileFrameworkStrings, |
| 3164 | This->FE->getName()); |
| 3165 | |
| 3166 | HeaderFileInfoLookupTable *Table |
| 3167 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3168 | if (!Table) |
| 3169 | return false; |
| 3170 | |
| 3171 | // Look in the on-disk hash table for an entry for this file name. |
| 3172 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3173 | &Trait); |
| 3174 | if (Pos == Table->end()) |
| 3175 | return false; |
| 3176 | |
| 3177 | This->HFI = *Pos; |
| 3178 | return true; |
| 3179 | } |
| 3180 | |
| 3181 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3182 | }; |
| 3183 | } |
| 3184 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3185 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3186 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3187 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3188 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3189 | if (Listener) |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3190 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3191 | return *HFI; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | return HeaderFileInfo(); |
| 3195 | } |
| 3196 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3197 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3198 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3199 | Module &F = *(*I); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3200 | unsigned Idx = 0; |
| 3201 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3202 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3203 | while (1) { |
| 3204 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3205 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3206 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3207 | break; // Something is messed up but at least avoid infinite loop in |
| 3208 | // release build. |
| 3209 | } |
| 3210 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3211 | if (DiagID == (unsigned)-1) { |
| 3212 | break; // no more diag/map pairs for this location. |
| 3213 | } |
| 3214 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3215 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3216 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3217 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3221 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3222 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3223 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | 3500568 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3224 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3225 | Module *M = I->second; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3226 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3230 | /// |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3231 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3232 | /// routine actually reads the record corresponding to the type at the given |
| 3233 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3234 | /// IDs. |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3235 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3236 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3237 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3238 | |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3239 | // Keep track of where we are in the stream, then jump back there |
| 3240 | // after reading this type. |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3241 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3242 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3243 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3244 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3245 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3246 | Deserializing AType(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3247 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3248 | unsigned Idx = 0; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3249 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3250 | RecordData Record; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3251 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3252 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3253 | case TYPE_EXT_QUAL: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3254 | if (Record.size() != 2) { |
| 3255 | Error("Incorrect encoding of extended qualifier type"); |
| 3256 | return QualType(); |
| 3257 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3258 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3259 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3260 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3261 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3262 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3263 | case TYPE_COMPLEX: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3264 | if (Record.size() != 1) { |
| 3265 | Error("Incorrect encoding of complex type"); |
| 3266 | return QualType(); |
| 3267 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3268 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3269 | return Context->getComplexType(ElemType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3272 | case TYPE_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3273 | if (Record.size() != 1) { |
| 3274 | Error("Incorrect encoding of pointer type"); |
| 3275 | return QualType(); |
| 3276 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3277 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3278 | return Context->getPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3279 | } |
| 3280 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3281 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3282 | if (Record.size() != 1) { |
| 3283 | Error("Incorrect encoding of block pointer type"); |
| 3284 | return QualType(); |
| 3285 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3286 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3287 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3290 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3291 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3292 | Error("Incorrect encoding of lvalue reference type"); |
| 3293 | return QualType(); |
| 3294 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3295 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3296 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3299 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3300 | if (Record.size() != 1) { |
| 3301 | Error("Incorrect encoding of rvalue reference type"); |
| 3302 | return QualType(); |
| 3303 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3304 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3305 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3306 | } |
| 3307 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3308 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | ee776bc | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3309 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3310 | Error("Incorrect encoding of member pointer type"); |
| 3311 | return QualType(); |
| 3312 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3313 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3314 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3315 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3316 | return QualType(); |
| 3317 | |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3318 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3321 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3322 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3323 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3324 | unsigned IndexTypeQuals = Record[2]; |
| 3325 | unsigned Idx = 3; |
| 3326 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3327 | return Context->getConstantArrayType(ElementType, Size, |
| 3328 | ASM, IndexTypeQuals); |
| 3329 | } |
| 3330 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3331 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3332 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3333 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3334 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3335 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3338 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3339 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3340 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3341 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3342 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3343 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3344 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3345 | ASM, IndexTypeQuals, |
| 3346 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3347 | } |
| 3348 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3349 | case TYPE_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3350 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3351 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3352 | return QualType(); |
| 3353 | } |
| 3354 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3355 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3356 | unsigned NumElements = Record[1]; |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3357 | unsigned VecKind = Record[2]; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3358 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3359 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3362 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3363 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3364 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3365 | return QualType(); |
| 3366 | } |
| 3367 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3368 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3369 | unsigned NumElements = Record[1]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3370 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3373 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3374 | if (Record.size() != 6) { |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3375 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3376 | return QualType(); |
| 3377 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3378 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3379 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3380 | (CallingConv)Record[4], Record[5]); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3381 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3384 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3385 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3386 | |
| 3387 | FunctionProtoType::ExtProtoInfo EPI; |
| 3388 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3389 | /*hasregparm*/ Record[2], |
| 3390 | /*regparm*/ Record[3], |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3391 | static_cast<CallingConv>(Record[4]), |
| 3392 | /*produces*/ Record[5]); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3393 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3394 | unsigned Idx = 6; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3395 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3396 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3397 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3398 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3399 | |
| 3400 | EPI.Variadic = Record[Idx++]; |
| 3401 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3402 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3403 | ExceptionSpecificationType EST = |
| 3404 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3405 | EPI.ExceptionSpecType = EST; |
| 3406 | if (EST == EST_Dynamic) { |
| 3407 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3408 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3409 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3410 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3411 | EPI.Exceptions = Exceptions.data(); |
| 3412 | } else if (EST == EST_ComputedNoexcept) { |
| 3413 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3414 | } |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3415 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3416 | EPI); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3417 | } |
| 3418 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3419 | case TYPE_UNRESOLVED_USING: { |
| 3420 | unsigned Idx = 0; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3421 | return Context->getTypeDeclType( |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3422 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3423 | } |
| 3424 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3425 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3426 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3427 | Error("incorrect encoding of typedef type"); |
| 3428 | return QualType(); |
| 3429 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3430 | unsigned Idx = 0; |
| 3431 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3432 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3433 | if (!Canonical.isNull()) |
| 3434 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3435 | return Context->getTypedefType(Decl, Canonical); |
| 3436 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3437 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3438 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3439 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3440 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3441 | case TYPE_TYPEOF: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3442 | if (Record.size() != 1) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3443 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3444 | return QualType(); |
| 3445 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3446 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3447 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3448 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3449 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3450 | case TYPE_DECLTYPE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3451 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3452 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3453 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3454 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3455 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3456 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 3457 | return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 3458 | } |
| 3459 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3460 | case TYPE_AUTO: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3461 | return Context->getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3462 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3463 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3464 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3465 | Error("incorrect encoding of record type"); |
| 3466 | return QualType(); |
| 3467 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3468 | unsigned Idx = 0; |
| 3469 | bool IsDependent = Record[Idx++]; |
| 3470 | QualType T |
| 3471 | = Context->getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3472 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3473 | return T; |
| 3474 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3475 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3476 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3477 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3478 | Error("incorrect encoding of enum type"); |
| 3479 | return QualType(); |
| 3480 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3481 | unsigned Idx = 0; |
| 3482 | bool IsDependent = Record[Idx++]; |
| 3483 | QualType T |
| 3484 | = Context->getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3485 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3486 | return T; |
| 3487 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3488 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3489 | case TYPE_ATTRIBUTED: { |
| 3490 | if (Record.size() != 3) { |
| 3491 | Error("incorrect encoding of attributed type"); |
| 3492 | return QualType(); |
| 3493 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3494 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3495 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3496 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3497 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3498 | } |
| 3499 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3500 | case TYPE_PAREN: { |
| 3501 | if (Record.size() != 1) { |
| 3502 | Error("incorrect encoding of paren type"); |
| 3503 | return QualType(); |
| 3504 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3505 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3506 | return Context->getParenType(InnerType); |
| 3507 | } |
| 3508 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3509 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | 1732850 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3510 | if (Record.size() != 2) { |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3511 | Error("incorrect encoding of pack expansion type"); |
| 3512 | return QualType(); |
| 3513 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3514 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3515 | if (Pattern.isNull()) |
| 3516 | return QualType(); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3517 | llvm::Optional<unsigned> NumExpansions; |
| 3518 | if (Record[1]) |
| 3519 | NumExpansions = Record[1] - 1; |
| 3520 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3521 | } |
| 3522 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3523 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3524 | unsigned Idx = 0; |
| 3525 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3526 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3527 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3528 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3531 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3532 | unsigned Idx = 0; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3533 | ObjCInterfaceDecl *ItfD |
| 3534 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3535 | return Context->getObjCInterfaceType(ItfD); |
| 3536 | } |
| 3537 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3538 | case TYPE_OBJC_OBJECT: { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3539 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3540 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3541 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3542 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3543 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3544 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3545 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3546 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3547 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3548 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3549 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3550 | QualType Pointee = readType(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3551 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3552 | } |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3553 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3554 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3555 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3556 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3557 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3558 | return |
| 3559 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3560 | Replacement); |
| 3561 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3562 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3563 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3564 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3565 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3566 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3567 | return Context->getSubstTemplateTypeParmPackType( |
| 3568 | cast<TemplateTypeParmType>(Parm), |
| 3569 | ArgPack); |
| 3570 | } |
| 3571 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3572 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3573 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3574 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3575 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3576 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3577 | return |
| 3578 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3579 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3580 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3581 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3582 | unsigned Idx = 0; |
| 3583 | unsigned Depth = Record[Idx++]; |
| 3584 | unsigned Index = Record[Idx++]; |
| 3585 | bool Pack = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3586 | TemplateTypeParmDecl *D |
| 3587 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 3588 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3589 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3590 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3591 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3592 | unsigned Idx = 0; |
| 3593 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3594 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3595 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3596 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3597 | if (!Canon.isNull()) |
| 3598 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3599 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3600 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3601 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3602 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3603 | unsigned Idx = 0; |
| 3604 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3605 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3606 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3607 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3608 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3609 | Args.reserve(NumArgs); |
| 3610 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3611 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3612 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3613 | Args.size(), Args.data()); |
| 3614 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3615 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3616 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3617 | unsigned Idx = 0; |
| 3618 | |
| 3619 | // ArrayType |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3620 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3621 | ArrayType::ArraySizeModifier ASM |
| 3622 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3623 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3624 | |
| 3625 | // DependentSizedArrayType |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3626 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3627 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3628 | |
| 3629 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3630 | IndexTypeQuals, Brackets); |
| 3631 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3632 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3633 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3634 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3635 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3636 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3637 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3638 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3639 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3640 | QualType T; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3641 | if (Underlying.isNull()) |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3642 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3643 | Args.size()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3644 | else |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3645 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3646 | Args.size(), Underlying); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3647 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3648 | return T; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3649 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3650 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3651 | // Suppress a GCC warning |
| 3652 | return QualType(); |
| 3653 | } |
| 3654 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3655 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3656 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3657 | Module &F; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3658 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3659 | const ASTReader::RecordData &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3660 | unsigned &Idx; |
| 3661 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3662 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3663 | unsigned &I) { |
| 3664 | return Reader.ReadSourceLocation(F, R, I); |
| 3665 | } |
| 3666 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3667 | template<typename T> |
| 3668 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3669 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3670 | } |
| 3671 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3672 | public: |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3673 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3674 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3675 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3676 | { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3677 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3678 | // We want compile-time assurance that we've enumerated all of |
| 3679 | // these, so unfortunately we have to declare them first, then |
| 3680 | // define them out-of-line. |
| 3681 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3682 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3683 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3684 | #include "clang/AST/TypeLocNodes.def" |
| 3685 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3686 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3687 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3688 | }; |
| 3689 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3690 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3691 | // nothing to do |
| 3692 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3693 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3694 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3695 | if (TL.needsExtraLocalData()) { |
| 3696 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3697 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3698 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3699 | TL.setModeAttr(Record[Idx++]); |
| 3700 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3701 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3702 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3703 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3704 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3705 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3706 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3707 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3708 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3709 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3710 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3711 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3712 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3713 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3714 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3715 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3716 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3717 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3718 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3719 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3720 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3721 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3722 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3723 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3724 | if (Record[Idx++]) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3725 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3726 | else |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3727 | TL.setSizeExpr(0); |
| 3728 | } |
| 3729 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3730 | VisitArrayTypeLoc(TL); |
| 3731 | } |
| 3732 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3733 | VisitArrayTypeLoc(TL); |
| 3734 | } |
| 3735 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3736 | VisitArrayTypeLoc(TL); |
| 3737 | } |
| 3738 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3739 | DependentSizedArrayTypeLoc TL) { |
| 3740 | VisitArrayTypeLoc(TL); |
| 3741 | } |
| 3742 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3743 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3744 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3745 | } |
| 3746 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3747 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3748 | } |
| 3749 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3750 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3751 | } |
| 3752 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3753 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3754 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3755 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3756 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3757 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3758 | } |
| 3759 | } |
| 3760 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3761 | VisitFunctionTypeLoc(TL); |
| 3762 | } |
| 3763 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3764 | VisitFunctionTypeLoc(TL); |
| 3765 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3766 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3767 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3768 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3769 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3770 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3771 | } |
| 3772 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3773 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3774 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3775 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3776 | } |
| 3777 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3778 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3779 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3780 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3781 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3782 | } |
| 3783 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3784 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3785 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3786 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3787 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3788 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3789 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3790 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3791 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3792 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3793 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3794 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3795 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3796 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3797 | } |
| 3798 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3799 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3800 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3801 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3802 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3803 | if (TL.hasAttrOperand()) { |
| 3804 | SourceRange range; |
| 3805 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3806 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3807 | TL.setAttrOperandParensRange(range); |
| 3808 | } |
| 3809 | if (TL.hasAttrExprOperand()) { |
| 3810 | if (Record[Idx++]) |
| 3811 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3812 | else |
| 3813 | TL.setAttrExprOperand(0); |
| 3814 | } else if (TL.hasAttrEnumOperand()) |
| 3815 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3816 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3817 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3818 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3819 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3820 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3821 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3822 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3823 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3824 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3825 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3826 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3827 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3828 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3829 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3830 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3831 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3832 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3833 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3834 | TL.setArgLocInfo(i, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3835 | Reader.GetTemplateArgumentLocInfo(F, |
| 3836 | TL.getTypePtr()->getArg(i).getKind(), |
| 3837 | Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3838 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3839 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3840 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3841 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3842 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3843 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3844 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3845 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3846 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3847 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3848 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3849 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3850 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3851 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3852 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3853 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3854 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3855 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3856 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3857 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3858 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3859 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3860 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3861 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3862 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3863 | TL.setArgLocInfo(I, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3864 | Reader.GetTemplateArgumentLocInfo(F, |
| 3865 | TL.getTypePtr()->getArg(I).getKind(), |
| 3866 | Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3867 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3868 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3869 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3870 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3871 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3872 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3873 | } |
| 3874 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3875 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3876 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3877 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3878 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3879 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3880 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3881 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3882 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3883 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3884 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3885 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3886 | const RecordData &Record, |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3887 | unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3888 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3889 | if (InfoTy.isNull()) |
| 3890 | return 0; |
| 3891 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3892 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3893 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3894 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3895 | TLR.Visit(TL); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3896 | return TInfo; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3897 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3898 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3899 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3900 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3901 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3902 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3903 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3904 | QualType T; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3905 | switch ((PredefinedTypeIDs)Index) { |
| 3906 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3907 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3908 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3909 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3910 | case PREDEF_TYPE_CHAR_U_ID: |
| 3911 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3912 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3913 | T = Context->CharTy; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3914 | break; |
| 3915 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3916 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3917 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3918 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3919 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3920 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3921 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3922 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3923 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3924 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3925 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3926 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3927 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3928 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3929 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3930 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3931 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3932 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 3933 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3934 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 3199634 | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 3935 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3936 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3937 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3938 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3939 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3940 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3941 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3942 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context->getAutoDeductType(); break; |
| 3943 | |
| 3944 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 3945 | T = Context->getAutoRRefDeductType(); |
| 3946 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3950 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3953 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3954 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3955 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3956 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3957 | if (TypesLoaded[Index].isNull()) |
| 3958 | return QualType(); |
| 3959 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3960 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3961 | if (DeserializationListener) |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3962 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3963 | TypesLoaded[Index]); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3964 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3965 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3966 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3969 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3970 | return GetType(getGlobalTypeID(F, LocalID)); |
| 3971 | } |
| 3972 | |
| 3973 | serialization::TypeID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3974 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3975 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 3976 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 3977 | |
| 3978 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 3979 | return LocalID; |
| 3980 | |
| 3981 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 3982 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 3983 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 3984 | |
| 3985 | unsigned GlobalIndex = LocalIndex + I->second; |
| 3986 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 3987 | } |
| 3988 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3989 | TemplateArgumentLocInfo |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3990 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3991 | TemplateArgument::ArgKind Kind, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3992 | const RecordData &Record, |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3993 | unsigned &Index) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3994 | switch (Kind) { |
| 3995 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3996 | return ReadExpr(F); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3997 | case TemplateArgument::Type: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3998 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3999 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4000 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4001 | Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4002 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4003 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4004 | SourceLocation()); |
| 4005 | } |
| 4006 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4007 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4008 | Index); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4009 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4010 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4011 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4012 | EllipsisLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4013 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4014 | case TemplateArgument::Null: |
| 4015 | case TemplateArgument::Integral: |
| 4016 | case TemplateArgument::Declaration: |
| 4017 | case TemplateArgument::Pack: |
| 4018 | return TemplateArgumentLocInfo(); |
| 4019 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4020 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4021 | return TemplateArgumentLocInfo(); |
| 4022 | } |
| 4023 | |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4024 | TemplateArgumentLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4025 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4026 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4027 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4028 | |
| 4029 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4030 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4031 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4032 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4033 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4034 | Record, Index)); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4035 | } |
| 4036 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4037 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4038 | return GetDecl(ID); |
| 4039 | } |
| 4040 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4041 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 4042 | unsigned &Idx){ |
| 4043 | if (Idx >= Record.size()) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4044 | return 0; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4045 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4046 | unsigned LocalID = Record[Idx++]; |
| 4047 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4048 | } |
| 4049 | |
| 4050 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4051 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4052 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4053 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4054 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4055 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4056 | RecordData Record; |
| 4057 | unsigned Code = Cursor.ReadCode(); |
| 4058 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4059 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4060 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4061 | return 0; |
| 4062 | } |
| 4063 | |
| 4064 | unsigned Idx = 0; |
| 4065 | unsigned NumBases = Record[Idx++]; |
| 4066 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 4067 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4068 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4069 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4070 | return Bases; |
| 4071 | } |
| 4072 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4073 | serialization::DeclID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4074 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4075 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4076 | return LocalID; |
| 4077 | |
| 4078 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4079 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4080 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4081 | |
| 4082 | return LocalID + I->second; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4083 | } |
| 4084 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4085 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4086 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4087 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4088 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4089 | return 0; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4090 | |
| 4091 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 4092 | assert(Context && "No context available?"); |
| 4093 | return Context->getTranslationUnitDecl(); |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4094 | |
| 4095 | case PREDEF_DECL_OBJC_ID_ID: |
| 4096 | assert(Context && "No context available?"); |
| 4097 | return Context->getObjCIdDecl(); |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4098 | |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4099 | case PREDEF_DECL_OBJC_SEL_ID: |
| 4100 | assert(Context && "No context available?"); |
| 4101 | return Context->getObjCSelDecl(); |
| 4102 | |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4103 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 4104 | assert(Context && "No context available?"); |
| 4105 | return Context->getObjCClassDecl(); |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4106 | |
| 4107 | case PREDEF_DECL_INT_128_ID: |
| 4108 | assert(Context && "No context available?"); |
| 4109 | return Context->getInt128Decl(); |
| 4110 | |
| 4111 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 4112 | assert(Context && "No context available?"); |
| 4113 | return Context->getUInt128Decl(); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4116 | return 0; |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4119 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4120 | |
| 4121 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4122 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4123 | return 0; |
| 4124 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4125 | |
| 4126 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4127 | ReadDeclRecord(ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4128 | if (DeserializationListener) |
| 4129 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4130 | } |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4131 | |
| 4132 | return DeclsLoaded[Index]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4133 | } |
| 4134 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4135 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4136 | const RecordData &Record, |
| 4137 | unsigned &Idx) { |
| 4138 | if (Idx >= Record.size()) { |
| 4139 | Error("Corrupted AST file"); |
| 4140 | return 0; |
| 4141 | } |
| 4142 | |
| 4143 | return getGlobalDeclID(F, Record[Idx++]); |
| 4144 | } |
| 4145 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4146 | /// \brief Resolve the offset of a statement into a statement. |
| 4147 | /// |
| 4148 | /// This operation will read a new statement from the external |
| 4149 | /// source each time it is called, and is meant to be used via a |
| 4150 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4151 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4152 | // Switch case IDs are per Decl. |
| 4153 | ClearSwitchCaseIDs(); |
| 4154 | |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4155 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4156 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4157 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4158 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4161 | namespace { |
| 4162 | class FindExternalLexicalDeclsVisitor { |
| 4163 | ASTReader &Reader; |
| 4164 | const DeclContext *DC; |
| 4165 | bool (*isKindWeWant)(Decl::Kind); |
| 4166 | SmallVectorImpl<Decl*> &Decls; |
| 4167 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4168 | |
| 4169 | public: |
| 4170 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4171 | bool (*isKindWeWant)(Decl::Kind), |
| 4172 | SmallVectorImpl<Decl*> &Decls) |
| 4173 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4174 | { |
| 4175 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4176 | PredefsVisited[I] = false; |
| 4177 | } |
| 4178 | |
| 4179 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4180 | if (Preorder) |
| 4181 | return false; |
| 4182 | |
| 4183 | FindExternalLexicalDeclsVisitor *This |
| 4184 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4185 | |
| 4186 | Module::DeclContextInfosMap::iterator Info |
| 4187 | = M.DeclContextInfos.find(This->DC); |
| 4188 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4189 | return false; |
| 4190 | |
| 4191 | // Load all of the declaration IDs |
| 4192 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4193 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4194 | ID != IDE; ++ID) { |
| 4195 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4196 | continue; |
| 4197 | |
| 4198 | // Don't add predefined declarations to the lexical context more |
| 4199 | // than once. |
| 4200 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4201 | if (This->PredefsVisited[ID->second]) |
| 4202 | continue; |
| 4203 | |
| 4204 | This->PredefsVisited[ID->second] = true; |
| 4205 | } |
| 4206 | |
| 4207 | Decl *D = This->Reader.GetLocalDecl(M, ID->second); |
| 4208 | assert(D && "Null decl in lexical decls"); |
| 4209 | This->Decls.push_back(D); |
| 4210 | } |
| 4211 | |
| 4212 | return false; |
| 4213 | } |
| 4214 | }; |
| 4215 | } |
| 4216 | |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4217 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4218 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4219 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4220 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4221 | // least. Walk all of the modules in the order they were loaded. |
| 4222 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4223 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4224 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4225 | return ELR_Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4226 | } |
| 4227 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4228 | namespace { |
| 4229 | /// \brief Module visitor used to perform name lookup into a |
| 4230 | /// declaration context. |
| 4231 | class DeclContextNameLookupVisitor { |
| 4232 | ASTReader &Reader; |
| 4233 | const DeclContext *DC; |
| 4234 | DeclarationName Name; |
| 4235 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4236 | |
| 4237 | public: |
| 4238 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4239 | const DeclContext *DC, DeclarationName Name, |
| 4240 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4241 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4242 | |
| 4243 | static bool visit(Module &M, void *UserData) { |
| 4244 | DeclContextNameLookupVisitor *This |
| 4245 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4246 | |
| 4247 | // Check whether we have any visible declaration information for |
| 4248 | // this context in this module. |
| 4249 | Module::DeclContextInfosMap::iterator Info |
| 4250 | = M.DeclContextInfos.find(This->DC); |
| 4251 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4252 | return false; |
| 4253 | |
| 4254 | // Look for this name within this module. |
| 4255 | ASTDeclContextNameLookupTable *LookupTable = |
| 4256 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4257 | ASTDeclContextNameLookupTable::iterator Pos |
| 4258 | = LookupTable->find(This->Name); |
| 4259 | if (Pos == LookupTable->end()) |
| 4260 | return false; |
| 4261 | |
| 4262 | bool FoundAnything = false; |
| 4263 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4264 | for (; Data.first != Data.second; ++Data.first) { |
| 4265 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4266 | if (!ND) |
| 4267 | continue; |
| 4268 | |
| 4269 | if (ND->getDeclName() != This->Name) { |
| 4270 | assert(!This->Name.getCXXNameType().isNull() && |
| 4271 | "Name mismatch without a type"); |
| 4272 | continue; |
| 4273 | } |
| 4274 | |
| 4275 | // Record this declaration. |
| 4276 | FoundAnything = true; |
| 4277 | This->Decls.push_back(ND); |
| 4278 | } |
| 4279 | |
| 4280 | return FoundAnything; |
| 4281 | } |
| 4282 | }; |
| 4283 | } |
| 4284 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4285 | DeclContext::lookup_result |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4286 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4287 | DeclarationName Name) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4288 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4289 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4290 | if (!Name) |
| 4291 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4292 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4293 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4294 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4295 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4296 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4297 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4298 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4299 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4300 | } |
| 4301 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4302 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4303 | assert(Consumer); |
| 4304 | while (!InterestingDecls.empty()) { |
| 4305 | DeclGroupRef DG(InterestingDecls.front()); |
| 4306 | InterestingDecls.pop_front(); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4307 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4308 | } |
| 4309 | } |
| 4310 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4311 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | b985eeb | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4312 | this->Consumer = Consumer; |
| 4313 | |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4314 | if (!Consumer) |
| 4315 | return; |
| 4316 | |
| 4317 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4318 | // Force deserialization of this decl, which will cause it to be queued for |
| 4319 | // passing to the consumer. |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4320 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4321 | } |
Douglas Gregor | f005eac | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4322 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4323 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4324 | } |
| 4325 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4326 | void ASTReader::PrintStats() { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4327 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4328 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4329 | unsigned NumTypesLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4330 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4331 | QualType()); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4332 | unsigned NumDeclsLoaded |
| 4333 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4334 | (Decl *)0); |
| 4335 | unsigned NumIdentifiersLoaded |
| 4336 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4337 | IdentifiersLoaded.end(), |
| 4338 | (IdentifierInfo *)0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4339 | unsigned NumSelectorsLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4340 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4341 | SelectorsLoaded.end(), |
| 4342 | Selector()); |
Douglas Gregor | c3b1dd1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4343 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4344 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4345 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4346 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4347 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4348 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4349 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4350 | if (!TypesLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4351 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4352 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4353 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4354 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4355 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4356 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4357 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4358 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4359 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4360 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4361 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4362 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4363 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4364 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4365 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4366 | if (TotalNumStatements) |
| 4367 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4368 | NumStatementsRead, TotalNumStatements, |
| 4369 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4370 | if (TotalNumMacros) |
| 4371 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4372 | NumMacrosRead, TotalNumMacros, |
| 4373 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4374 | if (TotalLexicalDeclContexts) |
| 4375 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4376 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4377 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4378 | * 100)); |
| 4379 | if (TotalVisibleDeclContexts) |
| 4380 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4381 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4382 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4383 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4384 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4385 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4386 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4387 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4388 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4389 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4390 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4391 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4392 | dump(); |
| 4393 | std::fprintf(stderr, "\n"); |
| 4394 | } |
| 4395 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4396 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4397 | static void |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4398 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4399 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4400 | InitialCapacity> &Map) { |
| 4401 | if (Map.begin() == Map.end()) |
| 4402 | return; |
| 4403 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4404 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4405 | llvm::errs() << Name << ":\n"; |
| 4406 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4407 | I != IEnd; ++I) { |
| 4408 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4409 | << "\n"; |
| 4410 | } |
| 4411 | } |
| 4412 | |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4413 | void ASTReader::dump() { |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4414 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4415 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4416 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4417 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4418 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4419 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4420 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 4421 | dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); |
| 4422 | dumpModuleIDMap("Global preprocessed entity map", |
| 4423 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4424 | |
| 4425 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4426 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4427 | MEnd = ModuleMgr.end(); |
| 4428 | M != MEnd; ++M) |
| 4429 | (*M)->dump(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4430 | } |
| 4431 | |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4432 | /// Return the amount of memory used by memory buffers, breaking down |
| 4433 | /// by heap-backed versus mmap'ed memory. |
| 4434 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4435 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4436 | E = ModuleMgr.end(); I != E; ++I) { |
| 4437 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4438 | size_t bytes = buf->getBufferSize(); |
| 4439 | switch (buf->getBufferKind()) { |
| 4440 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4441 | sizes.malloc_bytes += bytes; |
| 4442 | break; |
| 4443 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4444 | sizes.mmap_bytes += bytes; |
| 4445 | break; |
| 4446 | } |
| 4447 | } |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4448 | } |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4451 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4452 | SemaObj = &S; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4453 | S.ExternalSource = this; |
| 4454 | |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4455 | // Makes sure any declarations that were deserialized "too early" |
| 4456 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4457 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4458 | if (SemaObj->TUScope) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4459 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4460 | |
| 4461 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4462 | } |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4463 | PreloadedDecls.clear(); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4464 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4465 | // Load the offsets of the declarations that Sema references. |
| 4466 | // They will be lazily deserialized when needed. |
| 4467 | if (!SemaDeclRefs.empty()) { |
| 4468 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | b0f3ae6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4469 | if (!SemaObj->StdNamespace) |
| 4470 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4471 | if (!SemaObj->StdBadAlloc) |
| 4472 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4473 | } |
| 4474 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4475 | if (!FPPragmaOptions.empty()) { |
| 4476 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4477 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4478 | } |
| 4479 | |
| 4480 | if (!OpenCLExtensions.empty()) { |
| 4481 | unsigned I = 0; |
| 4482 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4483 | #include "clang/Basic/OpenCLExtensions.def" |
| 4484 | |
| 4485 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4486 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4489 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4490 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4491 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4492 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4493 | } |
| 4494 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4495 | namespace clang { |
| 4496 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4497 | /// identifiers stored within a set of AST files. |
| 4498 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4499 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4500 | const ASTReader &Reader; |
| 4501 | |
| 4502 | /// \brief The current index into the chain of AST files stored in |
| 4503 | /// the AST reader. |
| 4504 | unsigned Index; |
| 4505 | |
| 4506 | /// \brief The current position within the identifier lookup table |
| 4507 | /// of the current AST file. |
| 4508 | ASTIdentifierLookupTable::key_iterator Current; |
| 4509 | |
| 4510 | /// \brief The end position within the identifier lookup table of |
| 4511 | /// the current AST file. |
| 4512 | ASTIdentifierLookupTable::key_iterator End; |
| 4513 | |
| 4514 | public: |
| 4515 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4516 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4517 | virtual StringRef Next(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4518 | }; |
| 4519 | } |
| 4520 | |
| 4521 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4522 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4523 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4524 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4525 | Current = IdTable->key_begin(); |
| 4526 | End = IdTable->key_end(); |
| 4527 | } |
| 4528 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4529 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4530 | while (Current == End) { |
| 4531 | // If we have exhausted all of our AST files, we're done. |
| 4532 | if (Index == 0) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4533 | return StringRef(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4534 | |
| 4535 | --Index; |
| 4536 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4537 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4538 | IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4539 | Current = IdTable->key_begin(); |
| 4540 | End = IdTable->key_end(); |
| 4541 | } |
| 4542 | |
| 4543 | // We have any identifiers remaining in the current AST file; return |
| 4544 | // the next one. |
| 4545 | std::pair<const char*, unsigned> Key = *Current; |
| 4546 | ++Current; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4547 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4551 | return new ASTIdentifierIterator(*this); |
| 4552 | } |
| 4553 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4554 | namespace clang { namespace serialization { |
| 4555 | class ReadMethodPoolVisitor { |
| 4556 | ASTReader &Reader; |
| 4557 | Selector Sel; |
| 4558 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4559 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4560 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4561 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4562 | /// declarations. |
| 4563 | ObjCMethodList |
| 4564 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4565 | { |
| 4566 | ObjCMethodList List; |
| 4567 | ObjCMethodList *Prev = 0; |
| 4568 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4569 | if (!List.Method) { |
| 4570 | // This is the first method, which is the easy case. |
| 4571 | List.Method = Vec[I]; |
| 4572 | Prev = &List; |
| 4573 | continue; |
| 4574 | } |
| 4575 | |
| 4576 | ObjCMethodList *Mem = |
| 4577 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4578 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4579 | Prev = Prev->Next; |
| 4580 | } |
| 4581 | |
| 4582 | return List; |
| 4583 | } |
| 4584 | |
| 4585 | public: |
| 4586 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4587 | : Reader(Reader), Sel(Sel) { } |
| 4588 | |
| 4589 | static bool visit(Module &M, void *UserData) { |
| 4590 | ReadMethodPoolVisitor *This |
| 4591 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4592 | |
| 4593 | if (!M.SelectorLookupTable) |
| 4594 | return false; |
| 4595 | |
| 4596 | ASTSelectorLookupTable *PoolTable |
| 4597 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4598 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4599 | if (Pos == PoolTable->end()) |
| 4600 | return false; |
| 4601 | |
| 4602 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4603 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4604 | // disable this tracking when called via LoadSelector. |
| 4605 | // Also, should entries without methods count as misses? |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4606 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4607 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4608 | if (This->Reader.DeserializationListener) |
| 4609 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4610 | This->Sel); |
| 4611 | |
| 4612 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4613 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4614 | return true; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4615 | } |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4616 | |
| 4617 | /// \brief Retrieve the instance methods found by this visitor. |
| 4618 | ObjCMethodList getInstanceMethods() const { |
| 4619 | return buildObjCMethodList(InstanceMethods); |
| 4620 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4621 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4622 | /// \brief Retrieve the instance methods found by this visitor. |
| 4623 | ObjCMethodList getFactoryMethods() const { |
| 4624 | return buildObjCMethodList(FactoryMethods); |
| 4625 | } |
| 4626 | }; |
| 4627 | } } // end namespace clang::serialization |
| 4628 | |
| 4629 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4630 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4631 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4632 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4633 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4634 | Result.first = Visitor.getInstanceMethods(); |
| 4635 | Result.second = Visitor.getFactoryMethods(); |
| 4636 | |
| 4637 | if (!Result.first.Method && !Result.second.Method) |
| 4638 | ++NumMethodPoolMisses; |
| 4639 | return Result; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4642 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4643 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4644 | Namespaces.clear(); |
| 4645 | |
| 4646 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4647 | if (NamespaceDecl *Namespace |
| 4648 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4649 | Namespaces.push_back(Namespace); |
| 4650 | } |
| 4651 | } |
| 4652 | |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4653 | void ASTReader::ReadTentativeDefinitions( |
| 4654 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4655 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4656 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4657 | if (Var) |
| 4658 | TentativeDefs.push_back(Var); |
| 4659 | } |
| 4660 | TentativeDefinitions.clear(); |
| 4661 | } |
| 4662 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4663 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4664 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4665 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4666 | DeclaratorDecl *D |
| 4667 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4668 | if (D) |
| 4669 | Decls.push_back(D); |
| 4670 | } |
| 4671 | UnusedFileScopedDecls.clear(); |
| 4672 | } |
| 4673 | |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4674 | void ASTReader::ReadDelegatingConstructors( |
| 4675 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4676 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4677 | CXXConstructorDecl *D |
| 4678 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4679 | if (D) |
| 4680 | Decls.push_back(D); |
| 4681 | } |
| 4682 | DelegatingCtorDecls.clear(); |
| 4683 | } |
| 4684 | |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4685 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4686 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4687 | TypedefNameDecl *D |
| 4688 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4689 | if (D) |
| 4690 | Decls.push_back(D); |
| 4691 | } |
| 4692 | ExtVectorDecls.clear(); |
| 4693 | } |
| 4694 | |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4695 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4696 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4697 | CXXRecordDecl *D |
| 4698 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4699 | if (D) |
| 4700 | Decls.push_back(D); |
| 4701 | } |
| 4702 | DynamicClasses.clear(); |
| 4703 | } |
| 4704 | |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4705 | void |
| 4706 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4707 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4708 | NamedDecl *D |
| 4709 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4710 | if (D) |
| 4711 | Decls.push_back(D); |
| 4712 | } |
| 4713 | LocallyScopedExternalDecls.clear(); |
| 4714 | } |
| 4715 | |
Douglas Gregor | 72e357f | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4716 | void ASTReader::ReadReferencedSelectors( |
| 4717 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4718 | if (ReferencedSelectorsData.empty()) |
| 4719 | return; |
| 4720 | |
| 4721 | // If there are @selector references added them to its pool. This is for |
| 4722 | // implementation of -Wselector. |
| 4723 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4724 | unsigned I = 0; |
| 4725 | while (I < DataSize) { |
| 4726 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4727 | SourceLocation SelLoc |
| 4728 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4729 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4730 | } |
| 4731 | ReferencedSelectorsData.clear(); |
| 4732 | } |
| 4733 | |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4734 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4735 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4736 | if (WeakUndeclaredIdentifiers.empty()) |
| 4737 | return; |
| 4738 | |
| 4739 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4740 | IdentifierInfo *WeakId |
| 4741 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4742 | IdentifierInfo *AliasId |
| 4743 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4744 | SourceLocation Loc |
| 4745 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4746 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4747 | WeakInfo WI(AliasId, Loc); |
| 4748 | WI.setUsed(Used); |
| 4749 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4750 | } |
| 4751 | WeakUndeclaredIdentifiers.clear(); |
| 4752 | } |
| 4753 | |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4754 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4755 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4756 | ExternalVTableUse VT; |
| 4757 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4758 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4759 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4760 | VTables.push_back(VT); |
| 4761 | } |
| 4762 | |
| 4763 | VTableUses.clear(); |
| 4764 | } |
| 4765 | |
Douglas Gregor | e39f97c | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4766 | void ASTReader::ReadPendingInstantiations( |
| 4767 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4768 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4769 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4770 | SourceLocation Loc |
| 4771 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4772 | Pending.push_back(std::make_pair(D, Loc)); |
| 4773 | } |
| 4774 | PendingInstantiations.clear(); |
| 4775 | } |
| 4776 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4777 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4778 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4779 | ReadMethodPool(Sel); |
| 4780 | } |
| 4781 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4782 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4783 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4784 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4785 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4786 | if (DeserializationListener) |
| 4787 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4788 | } |
| 4789 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4790 | /// \brief Set the globally-visible declarations associated with the given |
| 4791 | /// identifier. |
| 4792 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4793 | /// 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] | 4794 | /// 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] | 4795 | /// them. |
| 4796 | /// |
| 4797 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4798 | /// declarations. |
| 4799 | /// |
| 4800 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4801 | /// visible at global scope. |
| 4802 | /// |
| 4803 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4804 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4805 | /// will not be placed onto the pending queue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4806 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4807 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4808 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4809 | bool Nonrecursive) { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4810 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4811 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4812 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4813 | PII.II = II; |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4814 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4815 | return; |
| 4816 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4818 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4819 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4820 | if (SemaObj) { |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4821 | if (SemaObj->TUScope) { |
| 4822 | // Introduce this declaration into the translation-unit scope |
| 4823 | // and add it to the declaration chain for this identifier, so |
| 4824 | // that (unqualified) name lookup will find it. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4825 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4826 | } |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4827 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4828 | } else { |
| 4829 | // Queue this declaration so that it will be added to the |
| 4830 | // translation unit scope and identifier's declaration chain |
| 4831 | // once a Sema object is known. |
| 4832 | PreloadedDecls.push_back(D); |
| 4833 | } |
| 4834 | } |
| 4835 | } |
| 4836 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4837 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4838 | if (ID == 0) |
| 4839 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4840 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4841 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4842 | Error("no identifier table in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4843 | return 0; |
| 4844 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4845 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4846 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4847 | ID -= 1; |
| 4848 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4849 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4850 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4851 | Module *M = I->second; |
| 4852 | unsigned Index = ID - M->BaseIdentifierID; |
| 4853 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4854 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4855 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4856 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | ca42a51 | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4857 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4858 | // unsigned integers. This is important to avoid integer overflow when |
| 4859 | // we cast them to 'unsigned'. |
Ted Kremenek | 49c5232 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4860 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4861 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4862 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4863 | IdentifiersLoaded[ID] |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4864 | = &PP->getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4865 | if (DeserializationListener) |
| 4866 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4867 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4868 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4869 | return IdentifiersLoaded[ID]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4870 | } |
| 4871 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4872 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4873 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4874 | } |
| 4875 | |
| 4876 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4877 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4878 | return LocalID; |
| 4879 | |
| 4880 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4881 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4882 | assert(I != M.IdentifierRemap.end() |
| 4883 | && "Invalid index into identifier index remap"); |
| 4884 | |
| 4885 | return LocalID + I->second; |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4886 | } |
| 4887 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4888 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 49f754f | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4889 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4890 | } |
| 4891 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4892 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4893 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4894 | } |
| 4895 | |
| 4896 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4897 | if (ID == 0) |
| 4898 | return Selector(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4899 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4900 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4901 | Error("selector ID out of range in AST file"); |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4902 | return Selector(); |
| 4903 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4904 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4905 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4906 | // Load this selector from the selector table. |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4907 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 4908 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4909 | Module &M = *I->second; |
| 4910 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4911 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4912 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4913 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4914 | if (DeserializationListener) |
| 4915 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4918 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4921 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4922 | return DecodeSelector(ID); |
| 4923 | } |
| 4924 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4925 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4926 | // ID 0 (the null selector) is considered an external selector. |
| 4927 | return getTotalNumSelectors() + 1; |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4928 | } |
| 4929 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4930 | serialization::SelectorID |
| 4931 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 4932 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 4933 | return LocalID; |
| 4934 | |
| 4935 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4936 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 4937 | assert(I != M.SelectorRemap.end() |
| 4938 | && "Invalid index into identifier index remap"); |
| 4939 | |
| 4940 | return LocalID + I->second; |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4941 | } |
| 4942 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4943 | DeclarationName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4944 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4945 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4946 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4947 | switch (Kind) { |
| 4948 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4949 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4950 | |
| 4951 | case DeclarationName::ObjCZeroArgSelector: |
| 4952 | case DeclarationName::ObjCOneArgSelector: |
| 4953 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4954 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4955 | |
| 4956 | case DeclarationName::CXXConstructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4957 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4958 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4959 | |
| 4960 | case DeclarationName::CXXDestructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4961 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4962 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4963 | |
| 4964 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4965 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4966 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4967 | |
| 4968 | case DeclarationName::CXXOperatorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4969 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4970 | (OverloadedOperatorKind)Record[Idx++]); |
| 4971 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4972 | case DeclarationName::CXXLiteralOperatorName: |
| 4973 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4974 | GetIdentifierInfo(F, Record, Idx)); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4975 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4976 | case DeclarationName::CXXUsingDirective: |
| 4977 | return DeclarationName::getUsingDirectiveName(); |
| 4978 | } |
| 4979 | |
| 4980 | // Required to silence GCC warning |
| 4981 | return DeclarationName(); |
| 4982 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4983 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4984 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4985 | DeclarationNameLoc &DNLoc, |
| 4986 | DeclarationName Name, |
| 4987 | const RecordData &Record, unsigned &Idx) { |
| 4988 | switch (Name.getNameKind()) { |
| 4989 | case DeclarationName::CXXConstructorName: |
| 4990 | case DeclarationName::CXXDestructorName: |
| 4991 | case DeclarationName::CXXConversionFunctionName: |
| 4992 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4993 | break; |
| 4994 | |
| 4995 | case DeclarationName::CXXOperatorName: |
| 4996 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4997 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4998 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4999 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5000 | break; |
| 5001 | |
| 5002 | case DeclarationName::CXXLiteralOperatorName: |
| 5003 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5004 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5005 | break; |
| 5006 | |
| 5007 | case DeclarationName::Identifier: |
| 5008 | case DeclarationName::ObjCZeroArgSelector: |
| 5009 | case DeclarationName::ObjCOneArgSelector: |
| 5010 | case DeclarationName::ObjCMultiArgSelector: |
| 5011 | case DeclarationName::CXXUsingDirective: |
| 5012 | break; |
| 5013 | } |
| 5014 | } |
| 5015 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5016 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5017 | DeclarationNameInfo &NameInfo, |
| 5018 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5019 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5020 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5021 | DeclarationNameLoc DNLoc; |
| 5022 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5023 | NameInfo.setInfo(DNLoc); |
| 5024 | } |
| 5025 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5026 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5027 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5028 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5029 | unsigned NumTPLists = Record[Idx++]; |
| 5030 | Info.NumTemplParamLists = NumTPLists; |
| 5031 | if (NumTPLists) { |
| 5032 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 5033 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5034 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5035 | } |
| 5036 | } |
| 5037 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5038 | TemplateName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5039 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5040 | unsigned &Idx) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5041 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5042 | switch (Kind) { |
| 5043 | case TemplateName::Template: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5044 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5045 | |
| 5046 | case TemplateName::OverloadedTemplate: { |
| 5047 | unsigned size = Record[Idx++]; |
| 5048 | UnresolvedSet<8> Decls; |
| 5049 | while (size--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5050 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5051 | |
| 5052 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 5053 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5054 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5055 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5056 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5057 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5058 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5059 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 5060 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5061 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5062 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5063 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5064 | if (Record[Idx++]) // isIdentifier |
| 5065 | return Context->getDependentTemplateName(NNS, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5066 | GetIdentifierInfo(F, Record, |
| 5067 | Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5068 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5069 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5070 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5071 | |
| 5072 | case TemplateName::SubstTemplateTemplateParm: { |
| 5073 | TemplateTemplateParmDecl *param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5074 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5075 | if (!param) return TemplateName(); |
| 5076 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 5077 | return Context->getSubstTemplateTemplateParm(param, replacement); |
| 5078 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5079 | |
| 5080 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5081 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5082 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5083 | if (!Param) |
| 5084 | return TemplateName(); |
| 5085 | |
| 5086 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5087 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5088 | return TemplateName(); |
| 5089 | |
| 5090 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 5091 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5092 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5093 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5094 | assert(0 && "Unhandled template name kind!"); |
| 5095 | return TemplateName(); |
| 5096 | } |
| 5097 | |
| 5098 | TemplateArgument |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5099 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5100 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5101 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5102 | switch (Kind) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5103 | case TemplateArgument::Null: |
| 5104 | return TemplateArgument(); |
| 5105 | case TemplateArgument::Type: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5106 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5107 | case TemplateArgument::Declaration: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5108 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5109 | case TemplateArgument::Integral: { |
| 5110 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5111 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5112 | return TemplateArgument(Value, T); |
| 5113 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5114 | case TemplateArgument::Template: |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5115 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5116 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5117 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5118 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5119 | if (unsigned NumExpansions = Record[Idx++]) |
| 5120 | NumTemplateExpansions = NumExpansions - 1; |
| 5121 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5122 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5123 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5124 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5125 | case TemplateArgument::Pack: { |
| 5126 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5127 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 5128 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5129 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5130 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5131 | } |
| 5132 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5133 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5134 | assert(0 && "Unhandled template argument kind!"); |
| 5135 | return TemplateArgument(); |
| 5136 | } |
| 5137 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5138 | TemplateParameterList * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5139 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5140 | const RecordData &Record, unsigned &Idx) { |
| 5141 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5142 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5143 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5144 | |
| 5145 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5146 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5147 | Params.reserve(NumParams); |
| 5148 | while (NumParams--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5149 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5150 | |
| 5151 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5152 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 5153 | Params.data(), Params.size(), RAngleLoc); |
| 5154 | return TemplateParams; |
| 5155 | } |
| 5156 | |
| 5157 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5158 | ASTReader:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5159 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5160 | Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5161 | unsigned &Idx) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5162 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5163 | TemplArgs.reserve(NumTemplateArgs); |
| 5164 | while (NumTemplateArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5165 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5166 | } |
| 5167 | |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5168 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5169 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5170 | const RecordData &Record, unsigned &Idx) { |
| 5171 | unsigned NumDecls = Record[Idx++]; |
| 5172 | while (NumDecls--) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5173 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5174 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5175 | Set.addDecl(D, AS); |
| 5176 | } |
| 5177 | } |
| 5178 | |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5179 | CXXBaseSpecifier |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5180 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5181 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5182 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5183 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5184 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5185 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5186 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5187 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5188 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5189 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5190 | EllipsisLoc); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5191 | Result.setInheritConstructors(inheritConstructors); |
| 5192 | return Result; |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5193 | } |
| 5194 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5195 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5196 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5197 | unsigned &Idx) { |
| 5198 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5199 | unsigned NumInitializers = Record[Idx++]; |
| 5200 | if (NumInitializers) { |
| 5201 | ASTContext &C = *getContext(); |
| 5202 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5203 | CtorInitializers |
| 5204 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5205 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5206 | TypeSourceInfo *BaseClassInfo = 0; |
| 5207 | bool IsBaseVirtual = false; |
| 5208 | FieldDecl *Member = 0; |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5209 | IndirectFieldDecl *IndirectMember = 0; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5210 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5211 | |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5212 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5213 | switch (Type) { |
| 5214 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5215 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5216 | IsBaseVirtual = Record[Idx++]; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5217 | break; |
| 5218 | |
| 5219 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5220 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5221 | break; |
| 5222 | |
| 5223 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5224 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5225 | break; |
| 5226 | |
| 5227 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5228 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5229 | break; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5230 | } |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5231 | |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5232 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5233 | Expr *Init = ReadExpr(F); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5234 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5235 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5236 | bool IsWritten = Record[Idx++]; |
| 5237 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5238 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5239 | if (IsWritten) { |
| 5240 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5241 | } else { |
| 5242 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5243 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5244 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5245 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5246 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5247 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5248 | CXXCtorInitializer *BOMInit; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5249 | if (Type == CTOR_INITIALIZER_BASE) { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5250 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 5251 | LParenLoc, Init, RParenLoc, |
| 5252 | MemberOrEllipsisLoc); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5253 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 5254 | BOMInit = new (C) CXXCtorInitializer(C, MemberOrEllipsisLoc, LParenLoc, |
| 5255 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5256 | } else if (IsWritten) { |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5257 | if (Member) |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5258 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 5259 | LParenLoc, Init, RParenLoc); |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5260 | else |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5261 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 5262 | MemberOrEllipsisLoc, LParenLoc, |
| 5263 | Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5264 | } else { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5265 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 5266 | LParenLoc, Init, RParenLoc, |
| 5267 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5270 | if (IsWritten) |
| 5271 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5272 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5273 | } |
| 5274 | } |
| 5275 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5276 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5277 | } |
| 5278 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5279 | NestedNameSpecifier * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5280 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5281 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5282 | unsigned N = Record[Idx++]; |
| 5283 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5284 | for (unsigned I = 0; I != N; ++I) { |
| 5285 | NestedNameSpecifier::SpecifierKind Kind |
| 5286 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5287 | switch (Kind) { |
| 5288 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5289 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5290 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 5291 | break; |
| 5292 | } |
| 5293 | |
| 5294 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5295 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5296 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 5297 | break; |
| 5298 | } |
| 5299 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5300 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5301 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5302 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 5303 | break; |
| 5304 | } |
| 5305 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5306 | case NestedNameSpecifier::TypeSpec: |
| 5307 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5308 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5309 | if (!T) |
| 5310 | return 0; |
| 5311 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5312 | bool Template = Record[Idx++]; |
| 5313 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 5314 | break; |
| 5315 | } |
| 5316 | |
| 5317 | case NestedNameSpecifier::Global: { |
| 5318 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 5319 | // No associated value, and there can't be a prefix. |
| 5320 | break; |
| 5321 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5322 | } |
Argyrios Kyrtzidis | ad65c69 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5323 | Prev = NNS; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5324 | } |
| 5325 | return NNS; |
| 5326 | } |
| 5327 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5328 | NestedNameSpecifierLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5329 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5330 | unsigned &Idx) { |
| 5331 | unsigned N = Record[Idx++]; |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5332 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5333 | for (unsigned I = 0; I != N; ++I) { |
| 5334 | NestedNameSpecifier::SpecifierKind Kind |
| 5335 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5336 | switch (Kind) { |
| 5337 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5338 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5339 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5340 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5341 | break; |
| 5342 | } |
| 5343 | |
| 5344 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5345 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5346 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5347 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5348 | break; |
| 5349 | } |
| 5350 | |
| 5351 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5352 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5353 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5354 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5355 | break; |
| 5356 | } |
| 5357 | |
| 5358 | case NestedNameSpecifier::TypeSpec: |
| 5359 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5360 | bool Template = Record[Idx++]; |
| 5361 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5362 | if (!T) |
| 5363 | return NestedNameSpecifierLoc(); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5364 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5365 | |
| 5366 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 5367 | Builder.Extend(*Context, |
| 5368 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5369 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5370 | break; |
| 5371 | } |
| 5372 | |
| 5373 | case NestedNameSpecifier::Global: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5374 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5375 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5376 | break; |
| 5377 | } |
| 5378 | } |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5381 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5384 | SourceRange |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5385 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5386 | unsigned &Idx) { |
| 5387 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5388 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 6d3bc08 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5389 | return SourceRange(beg, end); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5392 | /// \brief Read an integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5393 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5394 | unsigned BitWidth = Record[Idx++]; |
| 5395 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5396 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5397 | Idx += NumWords; |
| 5398 | return Result; |
| 5399 | } |
| 5400 | |
| 5401 | /// \brief Read a signed integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5402 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5403 | bool isUnsigned = Record[Idx++]; |
| 5404 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5405 | } |
| 5406 | |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5407 | /// \brief Read a floating-point value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5408 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5409 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5410 | } |
| 5411 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5412 | // \brief Read a string |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5413 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5414 | unsigned Len = Record[Idx++]; |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5415 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5416 | Idx += Len; |
| 5417 | return Result; |
| 5418 | } |
| 5419 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5420 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5421 | unsigned &Idx) { |
| 5422 | unsigned Major = Record[Idx++]; |
| 5423 | unsigned Minor = Record[Idx++]; |
| 5424 | unsigned Subminor = Record[Idx++]; |
| 5425 | if (Minor == 0) |
| 5426 | return VersionTuple(Major); |
| 5427 | if (Subminor == 0) |
| 5428 | return VersionTuple(Major, Minor - 1); |
| 5429 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5430 | } |
| 5431 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5432 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5433 | const RecordData &Record, |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5434 | unsigned &Idx) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5435 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5436 | return CXXTemporary::Create(*Context, Decl); |
| 5437 | } |
| 5438 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5439 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5440 | return Diag(SourceLocation(), DiagID); |
| 5441 | } |
| 5442 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5443 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5444 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5445 | } |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5446 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5447 | /// \brief Retrieve the identifier table associated with the |
| 5448 | /// preprocessor. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5449 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 5450 | assert(PP && "Forgot to set Preprocessor ?"); |
| 5451 | return PP->getIdentifierTable(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5452 | } |
| 5453 | |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5454 | /// \brief Record that the given ID maps to the given switch-case |
| 5455 | /// statement. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5456 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5457 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5458 | SwitchCaseStmts[ID] = SC; |
| 5459 | } |
| 5460 | |
| 5461 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5462 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5463 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5464 | return SwitchCaseStmts[ID]; |
| 5465 | } |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5466 | |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5467 | void ASTReader::ClearSwitchCaseIDs() { |
| 5468 | SwitchCaseStmts.clear(); |
| 5469 | } |
| 5470 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5471 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5472 | assert(NumCurrentElementsDeserializing && |
| 5473 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5474 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5475 | // If any identifiers with corresponding top-level declarations have |
| 5476 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5477 | while (!PendingIdentifierInfos.empty()) { |
| 5478 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5479 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5480 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5481 | } |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5482 | |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5483 | // Ready to load previous declarations of Decls that were delayed. |
| 5484 | while (!PendingPreviousDecls.empty()) { |
| 5485 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5486 | PendingPreviousDecls.front().second); |
| 5487 | PendingPreviousDecls.pop_front(); |
| 5488 | } |
| 5489 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5490 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5491 | // decls to the consumer. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5492 | if (Consumer) |
| 5493 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | ad5f95c | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5494 | |
| 5495 | assert(PendingForwardRefs.size() == 0 && |
| 5496 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5497 | } |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5498 | --NumCurrentElementsDeserializing; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5499 | } |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5500 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5501 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5502 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5503 | bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5504 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5505 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 5506 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5507 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5508 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5509 | DisableValidation(DisableValidation), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5510 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5511 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5512 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5513 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5514 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5515 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5516 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5517 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5518 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5519 | { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5520 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5524 | Diagnostic &Diags, StringRef isysroot, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5525 | bool DisableValidation, bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5526 | : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5527 | Diags(Diags), SemaObj(0), PP(0), Context(0), |
| 5528 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5529 | RelocatablePCH(false), isysroot(isysroot), |
| 5530 | DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), |
| 5531 | NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), |
| 5532 | TotalNumSLocEntries(0), NumStatementsRead(0), |
| 5533 | TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), |
| 5534 | NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), |
Sebastian Redl | c1d035f | 2010-09-22 20:19:08 +0000 | [diff] [blame] | 5535 | TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), |
| 5536 | TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5537 | TotalVisibleDeclContexts(0), TotalModulesSizeInBits(0), |
| 5538 | NumCurrentElementsDeserializing(0), NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5539 | { |
| 5540 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
| 5543 | ASTReader::~ASTReader() { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5544 | for (DeclContextVisibleUpdatesPending::iterator |
| 5545 | I = PendingVisibleUpdates.begin(), |
| 5546 | E = PendingVisibleUpdates.end(); |
| 5547 | I != E; ++I) { |
| 5548 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5549 | F = I->second.end(); |
| 5550 | J != F; ++J) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5551 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5552 | } |
| 5553 | } |