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); |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 157 | #undef PARSE_LANGOPT_IMPORTANT |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 158 | #undef PARSE_LANGOPT_BENIGN |
| 159 | |
| 160 | return false; |
| 161 | } |
| 162 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 163 | bool PCHValidator::ReadTargetTriple(StringRef Triple) { |
Daniel Dunbar | 20a682d | 2009-11-11 00:52:11 +0000 | [diff] [blame] | 164 | if (Triple == PP.getTargetInfo().getTriple().str()) |
| 165 | return false; |
| 166 | |
| 167 | Reader.Diag(diag::warn_pch_target_triple) |
| 168 | << Triple << PP.getTargetInfo().getTriple().str(); |
| 169 | return true; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 172 | namespace { |
| 173 | struct EmptyStringRef { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 174 | bool operator ()(StringRef r) const { return r.empty(); } |
Benjamin Kramer | 90b5b68 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 175 | }; |
| 176 | struct EmptyBlock { |
| 177 | bool operator ()(const PCHPredefinesBlock &r) const {return r.Data.empty();} |
| 178 | }; |
| 179 | } |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 180 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 181 | static bool EqualConcatenations(SmallVector<StringRef, 2> L, |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 182 | PCHPredefinesBlocks R) { |
| 183 | // First, sum up the lengths. |
| 184 | unsigned LL = 0, RL = 0; |
| 185 | for (unsigned I = 0, N = L.size(); I != N; ++I) { |
| 186 | LL += L[I].size(); |
| 187 | } |
| 188 | for (unsigned I = 0, N = R.size(); I != N; ++I) { |
| 189 | RL += R[I].Data.size(); |
| 190 | } |
| 191 | if (LL != RL) |
| 192 | return false; |
| 193 | if (LL == 0 && RL == 0) |
| 194 | return true; |
| 195 | |
| 196 | // Kick out empty parts, they confuse the algorithm below. |
| 197 | L.erase(std::remove_if(L.begin(), L.end(), EmptyStringRef()), L.end()); |
| 198 | R.erase(std::remove_if(R.begin(), R.end(), EmptyBlock()), R.end()); |
| 199 | |
| 200 | // 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] | 201 | StringRef LR = L[0], RR = R[0].Data; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 202 | unsigned LI = 0, RI = 0, LN = L.size(), RN = R.size(); |
Daniel Dunbar | 01ad0a7 | 2010-07-16 00:00:11 +0000 | [diff] [blame] | 203 | (void) RN; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 204 | for (;;) { |
| 205 | // Compare the current pieces. |
| 206 | if (LR.size() == RR.size()) { |
| 207 | // If they're the same length, it's pretty easy. |
| 208 | if (LR != RR) |
| 209 | return false; |
| 210 | // Both pieces are done, advance. |
| 211 | ++LI; |
| 212 | ++RI; |
| 213 | // If either string is done, they're both done, since they're the same |
| 214 | // length. |
| 215 | if (LI == LN) { |
| 216 | assert(RI == RN && "Strings not the same length after all?"); |
| 217 | return true; |
| 218 | } |
| 219 | LR = L[LI]; |
| 220 | RR = R[RI].Data; |
| 221 | } else if (LR.size() < RR.size()) { |
| 222 | // Right piece is longer. |
| 223 | if (!RR.startswith(LR)) |
| 224 | return false; |
| 225 | ++LI; |
| 226 | assert(LI != LN && "Strings not the same length after all?"); |
| 227 | RR = RR.substr(LR.size()); |
| 228 | LR = L[LI]; |
| 229 | } else { |
| 230 | // Left piece is longer. |
| 231 | if (!LR.startswith(RR)) |
| 232 | return false; |
| 233 | ++RI; |
| 234 | assert(RI != RN && "Strings not the same length after all?"); |
| 235 | LR = LR.substr(RR.size()); |
| 236 | RR = R[RI].Data; |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 241 | static std::pair<FileID, StringRef::size_type> |
| 242 | FindMacro(const PCHPredefinesBlocks &Buffers, StringRef MacroDef) { |
| 243 | std::pair<FileID, StringRef::size_type> Res; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 244 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) { |
| 245 | Res.second = Buffers[I].Data.find(MacroDef); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 246 | if (Res.second != StringRef::npos) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 247 | Res.first = Buffers[I].BufferID; |
| 248 | break; |
| 249 | } |
| 250 | } |
| 251 | return Res; |
| 252 | } |
| 253 | |
| 254 | bool PCHValidator::ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 255 | StringRef OriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 256 | std::string &SuggestedPredefines, |
| 257 | FileManager &FileMgr) { |
Daniel Dunbar | 732ef8a | 2009-11-11 23:58:53 +0000 | [diff] [blame] | 258 | // We are in the context of an implicit include, so the predefines buffer will |
| 259 | // have a #include entry for the PCH file itself (as normalized by the |
| 260 | // preprocessor initialization). Find it and skip over it in the checking |
| 261 | // below. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 262 | llvm::SmallString<256> PCHInclude; |
| 263 | PCHInclude += "#include \""; |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 264 | PCHInclude += NormalizeDashIncludePath(OriginalFileName, FileMgr); |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 265 | PCHInclude += "\"\n"; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 266 | std::pair<StringRef,StringRef> Split = |
| 267 | StringRef(PP.getPredefines()).split(PCHInclude.str()); |
| 268 | StringRef Left = Split.first, Right = Split.second; |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 269 | if (Left == PP.getPredefines()) { |
| 270 | Error("Missing PCH include entry!"); |
| 271 | return true; |
| 272 | } |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 273 | |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 274 | // If the concatenation of all the PCH buffers is equal to the adjusted |
| 275 | // command line, we're done. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 276 | SmallVector<StringRef, 2> CommandLine; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 277 | CommandLine.push_back(Left); |
| 278 | CommandLine.push_back(Right); |
| 279 | if (EqualConcatenations(CommandLine, Buffers)) |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 280 | return false; |
| 281 | |
| 282 | SourceManager &SourceMgr = PP.getSourceManager(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 283 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 284 | // The predefines buffers are different. Determine what the differences are, |
| 285 | // and whether they require us to reject the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 286 | SmallVector<StringRef, 8> PCHLines; |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 287 | for (unsigned I = 0, N = Buffers.size(); I != N; ++I) |
| 288 | Buffers[I].Data.split(PCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 289 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 290 | SmallVector<StringRef, 8> CmdLineLines; |
Daniel Dunbar | 045f917e | 2009-11-13 16:46:11 +0000 | [diff] [blame] | 291 | Left.split(CmdLineLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 292 | |
| 293 | // Pick out implicit #includes after the PCH and don't consider them for |
| 294 | // validation; we will insert them into SuggestedPredefines so that the |
| 295 | // preprocessor includes them. |
| 296 | std::string IncludesAfterPCH; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 297 | SmallVector<StringRef, 8> AfterPCHLines; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 298 | Right.split(AfterPCHLines, "\n", /*MaxSplit=*/-1, /*KeepEmpty=*/false); |
| 299 | for (unsigned i = 0, e = AfterPCHLines.size(); i != e; ++i) { |
| 300 | if (AfterPCHLines[i].startswith("#include ")) { |
| 301 | IncludesAfterPCH += AfterPCHLines[i]; |
| 302 | IncludesAfterPCH += '\n'; |
| 303 | } else { |
| 304 | CmdLineLines.push_back(AfterPCHLines[i]); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | // Make sure we add the includes last into SuggestedPredefines before we |
| 309 | // exit this function. |
| 310 | struct AddIncludesRAII { |
| 311 | std::string &SuggestedPredefines; |
| 312 | std::string &IncludesAfterPCH; |
| 313 | |
| 314 | AddIncludesRAII(std::string &SuggestedPredefines, |
| 315 | std::string &IncludesAfterPCH) |
| 316 | : SuggestedPredefines(SuggestedPredefines), |
| 317 | IncludesAfterPCH(IncludesAfterPCH) { } |
| 318 | ~AddIncludesRAII() { |
| 319 | SuggestedPredefines += IncludesAfterPCH; |
| 320 | } |
| 321 | } AddIncludes(SuggestedPredefines, IncludesAfterPCH); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 322 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 323 | // Sort both sets of predefined buffer lines, since we allow some extra |
| 324 | // definitions and they may appear at any point in the output. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 325 | std::sort(CmdLineLines.begin(), CmdLineLines.end()); |
| 326 | std::sort(PCHLines.begin(), PCHLines.end()); |
| 327 | |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 328 | // Determine which predefines that were used to build the PCH file are missing |
| 329 | // from the command line. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 330 | std::vector<StringRef> MissingPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 331 | std::set_difference(PCHLines.begin(), PCHLines.end(), |
| 332 | CmdLineLines.begin(), CmdLineLines.end(), |
| 333 | std::back_inserter(MissingPredefines)); |
| 334 | |
| 335 | bool MissingDefines = false; |
| 336 | bool ConflictingDefines = false; |
| 337 | for (unsigned I = 0, N = MissingPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 338 | StringRef Missing = MissingPredefines[I]; |
Argyrios Kyrtzidis | 58c6541 | 2010-09-30 16:53:50 +0000 | [diff] [blame] | 339 | if (Missing.startswith("#include ")) { |
| 340 | // An -include was specified when generating the PCH; it is included in |
| 341 | // the PCH, just ignore it. |
| 342 | continue; |
| 343 | } |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 344 | if (!Missing.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 345 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 346 | return true; |
| 347 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 349 | // This is a macro definition. Determine the name of the macro we're |
| 350 | // defining. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 351 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 352 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 353 | = Missing.find_first_of("( \n\r", StartOfMacroName); |
| 354 | assert(EndOfMacroName != std::string::npos && |
| 355 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 356 | StringRef MacroName = Missing.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 357 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 358 | // Determine whether this macro was given a different definition on the |
| 359 | // command line. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 360 | std::string MacroDefStart = "#define " + MacroName.str(); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 361 | std::string::size_type MacroDefLen = MacroDefStart.size(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 362 | SmallVector<StringRef, 8>::iterator ConflictPos |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 363 | = std::lower_bound(CmdLineLines.begin(), CmdLineLines.end(), |
| 364 | MacroDefStart); |
| 365 | for (; ConflictPos != CmdLineLines.end(); ++ConflictPos) { |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 366 | if (!ConflictPos->startswith(MacroDefStart)) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 367 | // Different macro; we're done. |
| 368 | ConflictPos = CmdLineLines.end(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 369 | break; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 370 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | |
| 372 | assert(ConflictPos->size() > MacroDefLen && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 373 | "Invalid #define in predefines buffer?"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | if ((*ConflictPos)[MacroDefLen] != ' ' && |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 375 | (*ConflictPos)[MacroDefLen] != '(') |
| 376 | continue; // Longer macro name; keep trying. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 378 | // We found a conflicting macro definition. |
| 379 | break; |
| 380 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 381 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 382 | if (ConflictPos != CmdLineLines.end()) { |
| 383 | Reader.Diag(diag::warn_cmdline_conflicting_macro_def) |
| 384 | << MacroName; |
| 385 | |
| 386 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 387 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 388 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 389 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 390 | SourceLocation PCHMissingLoc = |
| 391 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 392 | .getFileLocWithOffset(MacroLoc.second); |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 393 | Reader.Diag(PCHMissingLoc, diag::note_pch_macro_defined_as) << MacroName; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 394 | |
| 395 | ConflictingDefines = true; |
| 396 | continue; |
| 397 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 398 | |
Daniel Dunbar | 8665c7e | 2009-11-11 03:45:59 +0000 | [diff] [blame] | 399 | // If the macro doesn't conflict, then we'll just pick up the macro |
| 400 | // 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] | 401 | if (ConflictingDefines) |
| 402 | continue; // Don't complain if there are already conflicting defs |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 403 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 404 | if (!MissingDefines) { |
| 405 | Reader.Diag(diag::warn_cmdline_missing_macro_defs); |
| 406 | MissingDefines = true; |
| 407 | } |
| 408 | |
| 409 | // Show the definition of this macro within the PCH file. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 410 | std::pair<FileID, StringRef::size_type> MacroLoc = |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 411 | FindMacro(Buffers, Missing); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 412 | assert(MacroLoc.second!=StringRef::npos && "Unable to find macro!"); |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 413 | SourceLocation PCHMissingLoc = |
| 414 | SourceMgr.getLocForStartOfFile(MacroLoc.first) |
| 415 | .getFileLocWithOffset(MacroLoc.second); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 416 | Reader.Diag(PCHMissingLoc, diag::note_using_macro_def_from_pch); |
| 417 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 418 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 419 | if (ConflictingDefines) |
| 420 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 421 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 422 | // Determine what predefines were introduced based on command-line |
| 423 | // parameters that were not present when building the PCH |
| 424 | // file. Extra #defines are okay, so long as the identifiers being |
| 425 | // defined were not used within the precompiled header. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 426 | std::vector<StringRef> ExtraPredefines; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 427 | std::set_difference(CmdLineLines.begin(), CmdLineLines.end(), |
| 428 | PCHLines.begin(), PCHLines.end(), |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | std::back_inserter(ExtraPredefines)); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 430 | for (unsigned I = 0, N = ExtraPredefines.size(); I != N; ++I) { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 431 | StringRef &Extra = ExtraPredefines[I]; |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 432 | if (!Extra.startswith("#define ")) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 433 | Reader.Diag(diag::warn_pch_compiler_options_mismatch); |
| 434 | return true; |
| 435 | } |
| 436 | |
| 437 | // This is an extra macro definition. Determine the name of the |
| 438 | // macro we're defining. |
| 439 | std::string::size_type StartOfMacroName = strlen("#define "); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | std::string::size_type EndOfMacroName |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 441 | = Extra.find_first_of("( \n\r", StartOfMacroName); |
| 442 | assert(EndOfMacroName != std::string::npos && |
| 443 | "Couldn't find the end of the macro name"); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 444 | StringRef MacroName = Extra.slice(StartOfMacroName, EndOfMacroName); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 445 | |
| 446 | // Check whether this name was used somewhere in the PCH file. If |
| 447 | // so, defining it as a macro could change behavior, so we reject |
| 448 | // the PCH file. |
Daniel Dunbar | 499baed | 2009-11-11 05:26:28 +0000 | [diff] [blame] | 449 | if (IdentifierInfo *II = Reader.get(MacroName)) { |
Daniel Dunbar | 045c92f | 2009-11-11 00:52:00 +0000 | [diff] [blame] | 450 | Reader.Diag(diag::warn_macro_name_used_in_pch) << II; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 451 | return true; |
| 452 | } |
| 453 | |
| 454 | // Add this definition to the suggested predefines buffer. |
| 455 | SuggestedPredefines += Extra; |
| 456 | SuggestedPredefines += '\n'; |
| 457 | } |
| 458 | |
| 459 | // If we get here, it's because the predefines buffer had compatible |
| 460 | // contents. Accept the PCH file. |
| 461 | return false; |
| 462 | } |
| 463 | |
Douglas Gregor | 5712ebc | 2010-03-16 16:35:32 +0000 | [diff] [blame] | 464 | void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI, |
| 465 | unsigned ID) { |
| 466 | PP.getHeaderSearchInfo().setHeaderFileInfoForUID(HFI, ID); |
| 467 | ++NumHeaderInfos; |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void PCHValidator::ReadCounter(unsigned Value) { |
| 471 | PP.setCounterValue(Value); |
| 472 | } |
| 473 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 474 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 475 | // AST reader implementation |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 476 | //===----------------------------------------------------------------------===// |
| 477 | |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 478 | void |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 479 | ASTReader::setDeserializationListener(ASTDeserializationListener *Listener) { |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 480 | DeserializationListener = Listener; |
Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 481 | } |
| 482 | |
Chris Lattner | 92ba5ff | 2009-04-27 05:14:47 +0000 | [diff] [blame] | 483 | |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 484 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 485 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 486 | return serialization::ComputeHash(Sel); |
| 487 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 488 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 489 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 490 | std::pair<unsigned, unsigned> |
| 491 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 492 | using namespace clang::io; |
| 493 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 494 | unsigned DataLen = ReadUnalignedLE16(d); |
| 495 | return std::make_pair(KeyLen, DataLen); |
| 496 | } |
| 497 | |
| 498 | ASTSelectorLookupTrait::internal_key_type |
| 499 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 500 | using namespace clang::io; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 501 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 502 | unsigned N = ReadUnalignedLE16(d); |
| 503 | IdentifierInfo *FirstII |
| 504 | = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 505 | if (N == 0) |
| 506 | return SelTable.getNullarySelector(FirstII); |
| 507 | else if (N == 1) |
| 508 | return SelTable.getUnarySelector(FirstII); |
| 509 | |
| 510 | SmallVector<IdentifierInfo *, 16> Args; |
| 511 | Args.push_back(FirstII); |
| 512 | for (unsigned I = 1; I != N; ++I) |
| 513 | Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d))); |
| 514 | |
| 515 | return SelTable.getSelector(N, Args.data()); |
| 516 | } |
| 517 | |
| 518 | ASTSelectorLookupTrait::data_type |
| 519 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 520 | unsigned DataLen) { |
| 521 | using namespace clang::io; |
| 522 | |
| 523 | data_type Result; |
| 524 | |
| 525 | Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d)); |
| 526 | unsigned NumInstanceMethods = ReadUnalignedLE16(d); |
| 527 | unsigned NumFactoryMethods = ReadUnalignedLE16(d); |
| 528 | |
| 529 | // Load instance methods |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 530 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 531 | if (ObjCMethodDecl *Method |
| 532 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 533 | Result.Instance.push_back(Method); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 534 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 535 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 536 | // Load factory methods |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 537 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 538 | if (ObjCMethodDecl *Method |
| 539 | = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d))) |
| 540 | Result.Factory.push_back(Method); |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 541 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 543 | return Result; |
| 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 | unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) { |
| 547 | return llvm::HashString(StringRef(a.first, a.second)); |
| 548 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 549 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 550 | std::pair<unsigned, unsigned> |
| 551 | ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 552 | using namespace clang::io; |
| 553 | unsigned DataLen = ReadUnalignedLE16(d); |
| 554 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 555 | return std::make_pair(KeyLen, DataLen); |
| 556 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 557 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 558 | std::pair<const char*, unsigned> |
| 559 | ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) { |
| 560 | assert(n >= 2 && d[n-1] == '\0'); |
| 561 | return std::make_pair((const char*) d, n-1); |
| 562 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 563 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 564 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 565 | const unsigned char* d, |
| 566 | unsigned DataLen) { |
| 567 | using namespace clang::io; |
| 568 | unsigned RawID = ReadUnalignedLE32(d); |
| 569 | bool IsInteresting = RawID & 0x01; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 570 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 571 | // Wipe out the "is interesting" bit. |
| 572 | RawID = RawID >> 1; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 573 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 574 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 575 | if (!IsInteresting) { |
| 576 | // For uninteresting identifiers, just build the IdentifierInfo |
| 577 | // and associate it with the persistent ID. |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 578 | IdentifierInfo *II = KnownII; |
| 579 | if (!II) |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 580 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 581 | Reader.SetIdentifierInfo(ID, II); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 582 | II->setIsFromAST(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 583 | return II; |
| 584 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 586 | unsigned Bits = ReadUnalignedLE16(d); |
| 587 | bool CPlusPlusOperatorKeyword = Bits & 0x01; |
| 588 | Bits >>= 1; |
| 589 | bool HasRevertedTokenIDToIdentifier = Bits & 0x01; |
| 590 | Bits >>= 1; |
| 591 | bool Poisoned = Bits & 0x01; |
| 592 | Bits >>= 1; |
| 593 | bool ExtensionToken = Bits & 0x01; |
| 594 | Bits >>= 1; |
| 595 | bool hasMacroDefinition = Bits & 0x01; |
| 596 | Bits >>= 1; |
| 597 | unsigned ObjCOrBuiltinID = Bits & 0x3FF; |
| 598 | Bits >>= 10; |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 599 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 600 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 601 | DataLen -= 6; |
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 | // Build the IdentifierInfo itself and link the identifier ID with |
| 604 | // the new IdentifierInfo. |
| 605 | IdentifierInfo *II = KnownII; |
| 606 | if (!II) |
| 607 | II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second)); |
| 608 | Reader.SetIdentifierInfo(ID, II); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 609 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 610 | // Set or check the various bits in the IdentifierInfo structure. |
| 611 | // Token IDs are read-only. |
| 612 | if (HasRevertedTokenIDToIdentifier) |
| 613 | II->RevertTokenIDToIdentifier(); |
| 614 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 615 | assert(II->isExtensionToken() == ExtensionToken && |
| 616 | "Incorrect extension token flag"); |
| 617 | (void)ExtensionToken; |
| 618 | if (Poisoned) |
| 619 | II->setIsPoisoned(true); |
| 620 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 621 | "Incorrect C++ operator keyword flag"); |
| 622 | (void)CPlusPlusOperatorKeyword; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 623 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 624 | // If this identifier is a macro, deserialize the macro |
| 625 | // definition. |
| 626 | if (hasMacroDefinition) { |
| 627 | // FIXME: Check for conflicts? |
| 628 | uint32_t Offset = ReadUnalignedLE32(d); |
| 629 | Reader.SetIdentifierIsMacro(II, F, Offset); |
| 630 | DataLen -= 4; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 633 | // Read all of the declarations visible at global scope with this |
| 634 | // name. |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 635 | if (DataLen > 0) { |
| 636 | SmallVector<uint32_t, 4> DeclIDs; |
| 637 | for (; DataLen > 0; DataLen -= 4) |
| 638 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 639 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 642 | II->setIsFromAST(); |
| 643 | return II; |
| 644 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 645 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 646 | unsigned |
| 647 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 648 | llvm::FoldingSetNodeID ID; |
| 649 | ID.AddInteger(Key.Kind); |
| 650 | |
| 651 | switch (Key.Kind) { |
| 652 | case DeclarationName::Identifier: |
| 653 | case DeclarationName::CXXLiteralOperatorName: |
| 654 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 655 | break; |
| 656 | case DeclarationName::ObjCZeroArgSelector: |
| 657 | case DeclarationName::ObjCOneArgSelector: |
| 658 | case DeclarationName::ObjCMultiArgSelector: |
| 659 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 660 | break; |
| 661 | case DeclarationName::CXXOperatorName: |
| 662 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 663 | break; |
| 664 | case DeclarationName::CXXConstructorName: |
| 665 | case DeclarationName::CXXDestructorName: |
| 666 | case DeclarationName::CXXConversionFunctionName: |
| 667 | case DeclarationName::CXXUsingDirective: |
| 668 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 671 | return ID.ComputeHash(); |
| 672 | } |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 673 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 674 | ASTDeclContextNameLookupTrait::internal_key_type |
| 675 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 676 | const external_key_type& Name) const { |
| 677 | DeclNameKey Key; |
| 678 | Key.Kind = Name.getNameKind(); |
| 679 | switch (Name.getNameKind()) { |
| 680 | case DeclarationName::Identifier: |
| 681 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 682 | break; |
| 683 | case DeclarationName::ObjCZeroArgSelector: |
| 684 | case DeclarationName::ObjCOneArgSelector: |
| 685 | case DeclarationName::ObjCMultiArgSelector: |
| 686 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 687 | break; |
| 688 | case DeclarationName::CXXOperatorName: |
| 689 | Key.Data = Name.getCXXOverloadedOperator(); |
| 690 | break; |
| 691 | case DeclarationName::CXXLiteralOperatorName: |
| 692 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 693 | break; |
| 694 | case DeclarationName::CXXConstructorName: |
| 695 | case DeclarationName::CXXDestructorName: |
| 696 | case DeclarationName::CXXConversionFunctionName: |
| 697 | case DeclarationName::CXXUsingDirective: |
| 698 | Key.Data = 0; |
| 699 | break; |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 702 | return Key; |
| 703 | } |
| 704 | |
| 705 | ASTDeclContextNameLookupTrait::external_key_type |
| 706 | ASTDeclContextNameLookupTrait::GetExternalKey( |
| 707 | const internal_key_type& Key) const { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 708 | ASTContext &Context = Reader.getContext(); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 709 | switch (Key.Kind) { |
| 710 | case DeclarationName::Identifier: |
| 711 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 712 | |
| 713 | case DeclarationName::ObjCZeroArgSelector: |
| 714 | case DeclarationName::ObjCOneArgSelector: |
| 715 | case DeclarationName::ObjCMultiArgSelector: |
| 716 | return DeclarationName(Selector(Key.Data)); |
| 717 | |
| 718 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 719 | return Context.DeclarationNames.getCXXConstructorName( |
| 720 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 721 | |
| 722 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 723 | return Context.DeclarationNames.getCXXDestructorName( |
| 724 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 725 | |
| 726 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 727 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 728 | Context.getCanonicalType(Reader.getLocalType(F, Key.Data))); |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 729 | |
| 730 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 731 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 732 | (OverloadedOperatorKind)Key.Data); |
| 733 | |
| 734 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 735 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 736 | (IdentifierInfo*)Key.Data); |
| 737 | |
| 738 | case DeclarationName::CXXUsingDirective: |
| 739 | return DeclarationName::getUsingDirectiveName(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 742 | llvm_unreachable("Invalid Name Kind ?"); |
| 743 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 744 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 745 | std::pair<unsigned, unsigned> |
| 746 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 747 | using namespace clang::io; |
| 748 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 749 | unsigned DataLen = ReadUnalignedLE16(d); |
| 750 | return std::make_pair(KeyLen, DataLen); |
| 751 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 752 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 753 | ASTDeclContextNameLookupTrait::internal_key_type |
| 754 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 755 | using namespace clang::io; |
| 756 | |
| 757 | DeclNameKey Key; |
| 758 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 759 | switch (Key.Kind) { |
| 760 | case DeclarationName::Identifier: |
| 761 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 762 | break; |
| 763 | case DeclarationName::ObjCZeroArgSelector: |
| 764 | case DeclarationName::ObjCOneArgSelector: |
| 765 | case DeclarationName::ObjCMultiArgSelector: |
| 766 | Key.Data = |
| 767 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 768 | .getAsOpaquePtr(); |
| 769 | break; |
| 770 | case DeclarationName::CXXOperatorName: |
| 771 | Key.Data = *d++; // OverloadedOperatorKind |
| 772 | break; |
| 773 | case DeclarationName::CXXLiteralOperatorName: |
| 774 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 775 | break; |
| 776 | case DeclarationName::CXXConstructorName: |
| 777 | case DeclarationName::CXXDestructorName: |
| 778 | case DeclarationName::CXXConversionFunctionName: |
| 779 | case DeclarationName::CXXUsingDirective: |
| 780 | Key.Data = 0; |
| 781 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 784 | return Key; |
| 785 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 786 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 787 | ASTDeclContextNameLookupTrait::data_type |
| 788 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 789 | const unsigned char* d, |
| 790 | unsigned DataLen) { |
| 791 | using namespace clang::io; |
| 792 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 793 | DeclID *Start = (DeclID *)d; |
| 794 | return std::make_pair(Start, Start + NumDecls); |
| 795 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 796 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 797 | bool ASTReader::ReadDeclContextStorage(Module &M, |
| 798 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 799 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 800 | DeclContextInfo &Info) { |
| 801 | SavedStreamPosition SavedPosition(Cursor); |
| 802 | // First the lexical decls. |
| 803 | if (Offsets.first != 0) { |
| 804 | Cursor.JumpToBit(Offsets.first); |
| 805 | |
| 806 | RecordData Record; |
| 807 | const char *Blob; |
| 808 | unsigned BlobLen; |
| 809 | unsigned Code = Cursor.ReadCode(); |
| 810 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 811 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 812 | Error("Expected lexical block"); |
| 813 | return true; |
| 814 | } |
| 815 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 816 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 817 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | // Now the lookup table. |
| 821 | if (Offsets.second != 0) { |
| 822 | Cursor.JumpToBit(Offsets.second); |
| 823 | |
| 824 | RecordData Record; |
| 825 | const char *Blob; |
| 826 | unsigned BlobLen; |
| 827 | unsigned Code = Cursor.ReadCode(); |
| 828 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 829 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 830 | Error("Expected visible lookup table block"); |
| 831 | return true; |
| 832 | } |
| 833 | Info.NameLookupTableData |
| 834 | = ASTDeclContextNameLookupTable::Create( |
| 835 | (const unsigned char *)Blob + Record[0], |
| 836 | (const unsigned char *)Blob, |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 837 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | return false; |
| 841 | } |
| 842 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 843 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 844 | Error(diag::err_fe_pch_malformed, Msg); |
| 845 | } |
| 846 | |
| 847 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 848 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 849 | if (Diags.isDiagnosticInFlight()) |
| 850 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 851 | else |
| 852 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 855 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 856 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 857 | if (Listener) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 858 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 859 | ActualOriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 860 | SuggestedPredefines, |
| 861 | FileMgr); |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 862 | return false; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 865 | //===----------------------------------------------------------------------===// |
| 866 | // Source Manager Deserialization |
| 867 | //===----------------------------------------------------------------------===// |
| 868 | |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 869 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 870 | /// \returns true if there was an error. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 871 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 872 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 873 | unsigned Idx = 0; |
| 874 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 875 | |
| 876 | // Parse the file names |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 877 | std::map<int, int> FileIDs; |
| 878 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 879 | // Extract the file name |
| 880 | unsigned FilenameLen = Record[Idx++]; |
| 881 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 882 | Idx += FilenameLen; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 883 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 9a6b098 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 884 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | // Parse the line entries |
| 888 | std::vector<LineEntry> Entries; |
| 889 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 890 | int FID = Record[Idx++]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 891 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 892 | // Remap FileID from 1-based old view. |
| 893 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 894 | |
| 895 | // Extract the line entries |
| 896 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 897 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 898 | Entries.clear(); |
| 899 | Entries.reserve(NumEntries); |
| 900 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 901 | unsigned FileOffset = Record[Idx++]; |
| 902 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 903 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 904 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 905 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 906 | unsigned IncludeOffset = Record[Idx++]; |
| 907 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 908 | FileKind, IncludeOffset)); |
| 909 | } |
| 910 | LineTable.AddEntry(FID, Entries); |
| 911 | } |
| 912 | |
| 913 | return false; |
| 914 | } |
| 915 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 916 | namespace { |
| 917 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 918 | class ASTStatData { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 919 | public: |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 920 | const ino_t ino; |
| 921 | const dev_t dev; |
| 922 | const mode_t mode; |
| 923 | const time_t mtime; |
| 924 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 925 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 926 | 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] | 927 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 928 | }; |
| 929 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 930 | class ASTStatLookupTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 931 | public: |
| 932 | typedef const char *external_key_type; |
| 933 | typedef const char *internal_key_type; |
| 934 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 935 | typedef ASTStatData data_type; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 936 | |
| 937 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 938 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 942 | |
| 943 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 944 | return strcmp(a, b) == 0; |
| 945 | } |
| 946 | |
| 947 | static std::pair<unsigned, unsigned> |
| 948 | ReadKeyDataLength(const unsigned char*& d) { |
| 949 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 950 | unsigned DataLen = (unsigned) *d++; |
| 951 | return std::make_pair(KeyLen + 1, DataLen); |
| 952 | } |
| 953 | |
| 954 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 955 | return (const char *)d; |
| 956 | } |
| 957 | |
| 958 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 959 | unsigned /*DataLen*/) { |
| 960 | using namespace clang::io; |
| 961 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 962 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 963 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 964 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 965 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 966 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 967 | return data_type(ino, dev, mode, mtime, size); |
| 968 | } |
| 969 | }; |
| 970 | |
| 971 | /// \brief stat() cache for precompiled headers. |
| 972 | /// |
| 973 | /// This cache is very similar to the stat cache used by pretokenized |
| 974 | /// headers. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 975 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 976 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 977 | CacheTy *Cache; |
| 978 | |
| 979 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | public: |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 981 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 982 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 983 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 984 | Cache = CacheTy::Create(Buckets, Base); |
| 985 | } |
| 986 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 987 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 989 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 990 | int *FileDescriptor) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 991 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 992 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 993 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 994 | // 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] | 995 | if (I == Cache->end()) { |
| 996 | ++NumStatMisses; |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 997 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 998 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 999 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1000 | ++NumStatHits; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1001 | ASTStatData Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1002 | |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1003 | StatBuf.st_ino = Data.ino; |
| 1004 | StatBuf.st_dev = Data.dev; |
| 1005 | StatBuf.st_mtime = Data.mtime; |
| 1006 | StatBuf.st_mode = Data.mode; |
| 1007 | StatBuf.st_size = Data.size; |
Chris Lattner | 8f0583d | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1008 | return CacheExists; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1009 | } |
| 1010 | }; |
| 1011 | } // end anonymous namespace |
| 1012 | |
| 1013 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1014 | /// \brief Read a source manager block |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1015 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1016 | using namespace SrcMgr; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1017 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1018 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1019 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1020 | // Set the source-location entry cursor to the current position in |
| 1021 | // the stream. This cursor will be used to read the contents of the |
| 1022 | // source manager block initially, and then lazily read |
| 1023 | // source-location entries as needed. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1024 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1025 | |
| 1026 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1027 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1028 | Error("malformed block record in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1029 | return Failure; |
| 1030 | } |
| 1031 | |
| 1032 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1033 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1034 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1035 | return Failure; |
| 1036 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1037 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1038 | RecordData Record; |
| 1039 | while (true) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1040 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1041 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1042 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1043 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1044 | return Failure; |
| 1045 | } |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1046 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1047 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1048 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1049 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1050 | // No known subblocks, always skip them. |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1051 | SLocEntryCursor.ReadSubBlockID(); |
| 1052 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1053 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1054 | return Failure; |
| 1055 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1056 | continue; |
| 1057 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1058 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1059 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1060 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1061 | continue; |
| 1062 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1064 | // Read a record. |
| 1065 | const char *BlobStart; |
| 1066 | unsigned BlobLen; |
| 1067 | Record.clear(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1068 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1069 | default: // Default behavior: ignore. |
| 1070 | break; |
| 1071 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1072 | case SM_SLOC_FILE_ENTRY: |
| 1073 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1074 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1075 | // Once we hit one of the source location entries, we're done. |
| 1076 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1081 | /// \brief If a header file is not found at the path that we expect it to be |
| 1082 | /// and the PCH file was moved from its original location, try to resolve the |
| 1083 | /// file by assuming that header+PCH were moved together and the header is in |
| 1084 | /// the same place relative to the PCH. |
| 1085 | static std::string |
| 1086 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1087 | const std::string &OriginalDir, |
| 1088 | const std::string &CurrDir) { |
| 1089 | assert(OriginalDir != CurrDir && |
| 1090 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1091 | using namespace llvm::sys; |
| 1092 | llvm::SmallString<128> filePath(Filename); |
| 1093 | fs::make_absolute(filePath); |
| 1094 | assert(path::is_absolute(OriginalDir)); |
| 1095 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1096 | |
| 1097 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1098 | fileDirE = path::end(path::parent_path(filePath)); |
| 1099 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1100 | origDirE = path::end(OriginalDir); |
| 1101 | // Skip the common path components from filePath and OriginalDir. |
| 1102 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1103 | *fileDirI == *origDirI) { |
| 1104 | ++fileDirI; |
| 1105 | ++origDirI; |
| 1106 | } |
| 1107 | for (; origDirI != origDirE; ++origDirI) |
| 1108 | path::append(currPCHPath, ".."); |
| 1109 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1110 | path::append(currPCHPath, path::filename(Filename)); |
| 1111 | return currPCHPath.str(); |
| 1112 | } |
| 1113 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1114 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1115 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1116 | if (ID == 0) |
| 1117 | return Success; |
| 1118 | |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1119 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1120 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1121 | return Failure; |
| 1122 | } |
| 1123 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1124 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1125 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1126 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1127 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1128 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1129 | ++NumSLocEntriesRead; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1131 | if (Code == llvm::bitc::END_BLOCK || |
| 1132 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1133 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1134 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1135 | return Failure; |
| 1136 | } |
| 1137 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1138 | RecordData Record; |
| 1139 | const char *BlobStart; |
| 1140 | unsigned BlobLen; |
| 1141 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1142 | default: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1143 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1144 | return Failure; |
| 1145 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1146 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1147 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1148 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1149 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1150 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1151 | OriginalDir != CurrentDir) { |
| 1152 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1153 | OriginalDir, |
| 1154 | CurrentDir); |
| 1155 | if (!resolved.empty()) |
| 1156 | File = FileMgr.getFile(resolved); |
| 1157 | } |
Axel Naumann | 63fbaed | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1158 | if (File == 0) |
| 1159 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1160 | (time_t)Record[5]); |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1161 | if (File == 0) { |
| 1162 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1163 | ErrorStr += Filename; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1164 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1165 | Error(ErrorStr.c_str()); |
| 1166 | return Failure; |
| 1167 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1169 | if (Record.size() < 6) { |
Ted Kremenek | abb1ddd | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1170 | Error("source location entry is incorrect"); |
| 1171 | return Failure; |
| 1172 | } |
| 1173 | |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1174 | if (!DisableValidation && |
| 1175 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1176 | #if !defined(LLVM_ON_WIN32) |
| 1177 | // In our regression testing, the Windows file system seems to |
| 1178 | // have inconsistent modification times that sometimes |
| 1179 | // erroneously trigger this error-handling path. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1180 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1181 | #endif |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1182 | )) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1183 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1184 | return Failure; |
| 1185 | } |
| 1186 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1187 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1188 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1189 | // This is the module's main file. |
| 1190 | IncludeLoc = getImportLocation(F); |
| 1191 | } |
| 1192 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 26b5c19 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1193 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1194 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1195 | SrcMgr::FileInfo &FileInfo = |
| 1196 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1197 | FileInfo.NumCreatedFIDs = Record[6]; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1198 | if (Record[3]) |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1199 | FileInfo.setHasLineDirectives(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1200 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1201 | break; |
| 1202 | } |
| 1203 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1204 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1205 | const char *Name = BlobStart; |
| 1206 | unsigned Offset = Record[0]; |
| 1207 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1208 | Record.clear(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | unsigned RecCode |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1210 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1211 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1212 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1213 | Error("AST record has invalid code"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1214 | return Failure; |
| 1215 | } |
| 1216 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1217 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1218 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1219 | Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1220 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1221 | BaseOffset + Offset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1223 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1224 | PCHPredefinesBlock Block = { |
| 1225 | BufferID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1226 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1227 | }; |
| 1228 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1229 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1230 | |
| 1231 | break; |
| 1232 | } |
| 1233 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1234 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1235 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | 115b077 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1236 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1237 | ReadSourceLocation(*F, Record[2]), |
| 1238 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1239 | Record[4], |
| 1240 | ID, |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1241 | BaseOffset + Record[0]); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1242 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | return Success; |
| 1247 | } |
| 1248 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1249 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1250 | SourceLocation ASTReader::getImportLocation(Module *F) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1251 | if (F->ImportLoc.isValid()) |
| 1252 | return F->ImportLoc; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1253 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1254 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1255 | // location of its includer. |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1256 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1257 | // Main file is the importer. We assume that it is the first entry in the |
| 1258 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1259 | // the main file entry doesn't exist yet. |
| 1260 | // The very first entry is the invalid instantiation loc, which takes up |
| 1261 | // offsets 0 and 1. |
| 1262 | return SourceLocation::getFromRawEncoding(2U); |
| 1263 | } |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1264 | //return F->Loaders[0]->FirstLoc; |
| 1265 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1268 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1269 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1270 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1271 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1272 | unsigned BlockID) { |
| 1273 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1274 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1275 | return Failure; |
| 1276 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1278 | while (true) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1279 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1280 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1281 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1282 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1283 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1284 | Cursor.JumpToBit(Offset); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1285 | return false; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1286 | } |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1287 | Cursor.ReadAbbrevRecord(); |
| 1288 | } |
| 1289 | } |
| 1290 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1291 | void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1292 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1293 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1294 | // Keep track of where we are in the stream, then jump back there |
| 1295 | // after reading this macro. |
| 1296 | SavedStreamPosition SavedPosition(Stream); |
| 1297 | |
| 1298 | Stream.JumpToBit(Offset); |
| 1299 | RecordData Record; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1300 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1301 | MacroInfo *Macro = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1302 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1303 | while (true) { |
| 1304 | unsigned Code = Stream.ReadCode(); |
| 1305 | switch (Code) { |
| 1306 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1307 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1308 | |
| 1309 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1310 | // No known subblocks, always skip them. |
| 1311 | Stream.ReadSubBlockID(); |
| 1312 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1313 | Error("malformed block record in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1314 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1315 | } |
| 1316 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1317 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1318 | case llvm::bitc::DEFINE_ABBREV: |
| 1319 | Stream.ReadAbbrevRecord(); |
| 1320 | continue; |
| 1321 | default: break; |
| 1322 | } |
| 1323 | |
| 1324 | // Read a record. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1325 | const char *BlobStart = 0; |
| 1326 | unsigned BlobLen = 0; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1327 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1328 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1329 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1330 | BlobLen); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1331 | switch (RecType) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1332 | case PP_MACRO_OBJECT_LIKE: |
| 1333 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1334 | // If we already have a macro, that means that we've hit the end |
| 1335 | // of the definition of the macro we were looking for. We're |
| 1336 | // done. |
| 1337 | if (Macro) |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1338 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1339 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1340 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1341 | if (II == 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1342 | Error("macro must have a name in AST file"); |
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 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1345 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | bool isUsed = Record[2]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1347 | |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1348 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1349 | MI->setIsUsed(isUsed); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1350 | MI->setIsFromAST(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1351 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1352 | unsigned NextIndex = 3; |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1353 | MI->setExportLocation(ReadSourceLocation(F, Record, NextIndex)); |
| 1354 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1355 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1356 | // Decode function-like macro info. |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1357 | bool isC99VarArgs = Record[NextIndex++]; |
| 1358 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1359 | MacroArgs.clear(); |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1360 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1361 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1362 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1363 | |
| 1364 | // Install function-like macro info. |
| 1365 | MI->setIsFunctionLike(); |
| 1366 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1367 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1368 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1369 | PP.getPreprocessorAllocator()); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | // Finally, install the macro. |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1373 | PP.setMacroInfo(II, MI); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1374 | |
| 1375 | // Remember that we saw this macro last so that we add the tokens that |
| 1376 | // form its body to it. |
| 1377 | Macro = MI; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1378 | |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1379 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord()) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1380 | // We have a macro definition. Load it now. |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1381 | PP.getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1382 | getLocalMacroDefinition(F, Record[NextIndex])); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1383 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1384 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1385 | ++NumMacrosRead; |
| 1386 | break; |
| 1387 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1388 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1389 | case PP_TOKEN: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1390 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1391 | // erroneous, just pretend we didn't see this. |
| 1392 | if (Macro == 0) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1393 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1394 | Token Tok; |
| 1395 | Tok.startToken(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1396 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1397 | Tok.setLength(Record[1]); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1398 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1399 | Tok.setIdentifierInfo(II); |
| 1400 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1401 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1402 | Macro->AddTokenToBody(Tok); |
| 1403 | break; |
| 1404 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1405 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1406 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1407 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1408 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1411 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1412 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1413 | switch (Code) { |
| 1414 | case llvm::bitc::END_BLOCK: |
| 1415 | return 0; |
| 1416 | |
| 1417 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1418 | Error("unexpected subblock record in preprocessor detail block"); |
| 1419 | return 0; |
| 1420 | |
| 1421 | case llvm::bitc::DEFINE_ABBREV: |
| 1422 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1423 | return 0; |
| 1424 | |
| 1425 | default: |
| 1426 | break; |
| 1427 | } |
| 1428 | |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1429 | if (!PP.getPreprocessingRecord()) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1430 | Error("no preprocessing record"); |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | // Read the record. |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1435 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1436 | const char *BlobStart = 0; |
| 1437 | unsigned BlobLen = 0; |
| 1438 | RecordData Record; |
| 1439 | PreprocessorDetailRecordTypes RecType = |
| 1440 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1441 | Code, Record, BlobStart, BlobLen); |
| 1442 | switch (RecType) { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1443 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1444 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1445 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1446 | return PE; |
| 1447 | |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1448 | bool isBuiltin = Record[3]; |
| 1449 | MacroExpansion *ME; |
| 1450 | if (isBuiltin) |
| 1451 | ME = new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[4]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1452 | SourceRange(ReadSourceLocation(F, Record[1]), |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 1453 | ReadSourceLocation(F, Record[2]))); |
| 1454 | else |
| 1455 | ME = new (PPRec) MacroExpansion(getLocalMacroDefinition(F, Record[4]), |
| 1456 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1457 | ReadSourceLocation(F, Record[2]))); |
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 |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +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; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1756 | while (!Stream.AtEndOfStream()) { |
| 1757 | unsigned Code = Stream.ReadCode(); |
| 1758 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1759 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1760 | Error("error at end of module block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1761 | return Failure; |
| 1762 | } |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1763 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1764 | return Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1768 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1769 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1770 | // We lazily load the decls block, but we want to set up the |
| 1771 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1772 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1773 | // With the main cursor, we just skip over it. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1774 | F.DeclsCursor = Stream; |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1775 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1776 | // Read the abbrevs. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1777 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1778 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1779 | return Failure; |
| 1780 | } |
| 1781 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1782 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1783 | case DECL_UPDATES_BLOCK_ID: |
| 1784 | if (Stream.SkipBlock()) { |
| 1785 | Error("malformed block record in AST file"); |
| 1786 | return Failure; |
| 1787 | } |
| 1788 | break; |
| 1789 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1790 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1791 | F.MacroCursor = Stream; |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1792 | if (!PP.getExternalSource()) |
| 1793 | PP.setExternalSource(this); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1794 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1795 | if (Stream.SkipBlock() || |
| 1796 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1797 | Error("malformed block record in AST file"); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1798 | return Failure; |
| 1799 | } |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1800 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1801 | break; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1802 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1803 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1804 | F.PreprocessorDetailCursor = Stream; |
| 1805 | if (Stream.SkipBlock() || |
| 1806 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1807 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1808 | Error("malformed preprocessor detail record in AST file"); |
| 1809 | return Failure; |
| 1810 | } |
| 1811 | F.PreprocessorDetailStartOffset |
| 1812 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1813 | |
| 1814 | if (!PP.getPreprocessingRecord()) |
| 1815 | PP.createPreprocessingRecord(true); |
| 1816 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 1817 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1818 | break; |
| 1819 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1820 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1821 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1822 | case Success: |
| 1823 | break; |
| 1824 | |
| 1825 | case Failure: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1826 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1827 | return Failure; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1828 | |
| 1829 | case IgnorePCH: |
| 1830 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1831 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1832 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1833 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1834 | continue; |
| 1835 | } |
| 1836 | |
| 1837 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1838 | Stream.ReadAbbrevRecord(); |
| 1839 | continue; |
| 1840 | } |
| 1841 | |
| 1842 | // Read and process a record. |
| 1843 | Record.clear(); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1844 | const char *BlobStart = 0; |
| 1845 | unsigned BlobLen = 0; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1846 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1847 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1848 | default: // Default behavior: ignore. |
| 1849 | break; |
| 1850 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1851 | case METADATA: { |
| 1852 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1853 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1854 | : diag::warn_pch_version_too_new); |
| 1855 | return IgnorePCH; |
| 1856 | } |
| 1857 | |
| 1858 | RelocatablePCH = Record[4]; |
| 1859 | if (Listener) { |
| 1860 | std::string TargetTriple(BlobStart, BlobLen); |
| 1861 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1862 | return IgnorePCH; |
| 1863 | } |
| 1864 | break; |
| 1865 | } |
| 1866 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1867 | case IMPORTS: { |
| 1868 | // Load each of the imported PCH files. |
| 1869 | unsigned Idx = 0, N = Record.size(); |
| 1870 | while (Idx < N) { |
| 1871 | // Read information about the AST file. |
| 1872 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1873 | unsigned Length = Record[Idx++]; |
| 1874 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1875 | Record.begin() + Idx + Length); |
| 1876 | Idx += Length; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1877 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1878 | // Load the AST file. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1879 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1880 | case Failure: return Failure; |
| 1881 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1882 | case IgnorePCH: return IgnorePCH; |
| 1883 | case Success: break; |
| 1884 | } |
| 1885 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1886 | break; |
| 1887 | } |
| 1888 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1889 | case TYPE_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1890 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1891 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1892 | return Failure; |
| 1893 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1894 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1895 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1896 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1897 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1898 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1899 | if (F.LocalNumTypes > 0) { |
| 1900 | // Introduce the global -> local mapping for types within this module. |
| 1901 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1902 | |
| 1903 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1904 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 1905 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1906 | |
| 1907 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1908 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1909 | break; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1912 | case DECL_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1913 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1914 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1915 | return Failure; |
| 1916 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1917 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1918 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1919 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1920 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1921 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1922 | if (F.LocalNumDecls > 0) { |
| 1923 | // Introduce the global -> local mapping for declarations within this |
| 1924 | // module. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1925 | GlobalDeclMap.insert( |
| 1926 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1927 | |
| 1928 | // Introduce the local -> global mapping for declarations within this |
| 1929 | // module. |
| 1930 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 1931 | F.BaseDeclID - LocalBaseDeclID)); |
| 1932 | |
| 1933 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1934 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1935 | break; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1938 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1939 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1940 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1941 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1942 | Info.NumLexicalDecls |
| 1943 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1944 | TU->setHasExternalLexicalStorage(true); |
Sebastian Redl | 4b1f490 | 2010-07-27 18:24:41 +0000 | [diff] [blame] | 1945 | break; |
| 1946 | } |
| 1947 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1948 | case UPDATE_VISIBLE: { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1949 | unsigned Idx = 0; |
| 1950 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1951 | void *Table = ASTDeclContextNameLookupTable::Create( |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1952 | (const unsigned char *)BlobStart + Record[Idx++], |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1953 | (const unsigned char *)BlobStart, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 1954 | ASTDeclContextNameLookupTrait(*this, F)); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1955 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID) { // Is it the TU? |
| 1956 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1957 | F.DeclContextInfos[TU].NameLookupTableData = Table; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1958 | TU->setHasExternalVisibleStorage(true); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1959 | } else |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1960 | PendingVisibleUpdates[ID].push_back(std::make_pair(Table, &F)); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1964 | case REDECLS_UPDATE_LATEST: { |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1965 | assert(Record.size() % 2 == 0 && "Expected pairs of DeclIDs"); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1966 | for (unsigned i = 0, e = Record.size(); i < e; /* in loop */) { |
| 1967 | DeclID First = ReadDeclID(F, Record, i); |
| 1968 | DeclID Latest = ReadDeclID(F, Record, i); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 1969 | FirstLatestDeclIDs[First] = Latest; |
| 1970 | } |
| 1971 | break; |
| 1972 | } |
| 1973 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1974 | case LANGUAGE_OPTIONS: |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1975 | if (ParseLanguageOptions(Record) && !DisableValidation) |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1976 | return IgnorePCH; |
| 1977 | break; |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1978 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1979 | case IDENTIFIER_TABLE: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1980 | F.IdentifierTableData = BlobStart; |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1981 | if (Record[0]) { |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1982 | F.IdentifierLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1983 | = ASTIdentifierLookupTable::Create( |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1984 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 1985 | (const unsigned char *)F.IdentifierTableData, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1986 | ASTIdentifierLookupTrait(*this, F)); |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 1987 | |
| 1988 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1989 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1990 | break; |
| 1991 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1992 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1993 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1994 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1995 | return Failure; |
| 1996 | } |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1997 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 1998 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1999 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2000 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2001 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2002 | if (F.LocalNumIdentifiers > 0) { |
| 2003 | // Introduce the global -> local mapping for identifiers within this |
| 2004 | // module. |
| 2005 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2006 | &F)); |
| 2007 | |
| 2008 | // Introduce the local -> global mapping for identifiers within this |
| 2009 | // module. |
| 2010 | F.IdentifierRemap.insert( |
| 2011 | std::make_pair(LocalBaseIdentifierID, |
| 2012 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 2013 | |
| 2014 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2015 | + F.LocalNumIdentifiers); |
| 2016 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2017 | break; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2020 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2021 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2022 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2023 | break; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2024 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2025 | case SPECIAL_TYPES: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2026 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2027 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2028 | break; |
| 2029 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2030 | case STATISTICS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2031 | TotalNumStatements += Record[0]; |
| 2032 | TotalNumMacros += Record[1]; |
| 2033 | TotalLexicalDeclContexts += Record[2]; |
| 2034 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2035 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2036 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2037 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2038 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2039 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2040 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2041 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2042 | case DELEGATING_CTORS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2043 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2044 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2045 | break; |
| 2046 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2047 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2048 | if (Record.size() % 4 != 0) { |
| 2049 | Error("invalid weak identifiers record"); |
| 2050 | return Failure; |
| 2051 | } |
| 2052 | |
| 2053 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2054 | // files. This isn't the way to do it :) |
| 2055 | WeakUndeclaredIdentifiers.clear(); |
| 2056 | |
| 2057 | // Translate the weak, undeclared identifiers into global IDs. |
| 2058 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2059 | WeakUndeclaredIdentifiers.push_back( |
| 2060 | getGlobalIdentifierID(F, Record[I++])); |
| 2061 | WeakUndeclaredIdentifiers.push_back( |
| 2062 | getGlobalIdentifierID(F, Record[I++])); |
| 2063 | WeakUndeclaredIdentifiers.push_back( |
| 2064 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2065 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2066 | } |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2067 | break; |
| 2068 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2069 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2070 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2071 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2072 | break; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2073 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2074 | case SELECTOR_OFFSETS: { |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2075 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2076 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2077 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2078 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2079 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2080 | if (F.LocalNumSelectors > 0) { |
| 2081 | // Introduce the global -> local mapping for selectors within this |
| 2082 | // module. |
| 2083 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2084 | |
| 2085 | // Introduce the local -> global mapping for selectors within this |
| 2086 | // module. |
| 2087 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 2088 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2090 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2091 | } |
| 2092 | break; |
| 2093 | } |
| 2094 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2095 | case METHOD_POOL: |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2096 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2097 | if (Record[0]) |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2098 | F.SelectorLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2099 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2100 | F.SelectorLookupTableData + Record[0], |
| 2101 | F.SelectorLookupTableData, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2102 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2103 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2104 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2105 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2106 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2107 | if (!Record.empty()) { |
| 2108 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2109 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2110 | Record[Idx++])); |
| 2111 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2112 | getRawEncoding()); |
| 2113 | } |
| 2114 | } |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2115 | break; |
| 2116 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2117 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2118 | if (!Record.empty() && Listener) |
| 2119 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2120 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2121 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2122 | case SOURCE_LOCATION_OFFSETS: { |
| 2123 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2124 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2125 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2126 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2127 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2128 | // we invert it. Because we invert it, though, we need the other end of |
| 2129 | // the range. |
| 2130 | unsigned RangeStart = |
| 2131 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2132 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2133 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2134 | |
| 2135 | // Initialize the remapping table. |
| 2136 | // Invalid stays invalid. |
| 2137 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2138 | // This module. Base was 2 when being compiled. |
| 2139 | F.SLocRemap.insert(std::make_pair(2U, |
| 2140 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2141 | |
| 2142 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2143 | break; |
| 2144 | } |
| 2145 | |
Douglas Gregor | 5a1797c | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2146 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2147 | // Additional remapping information. |
| 2148 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2149 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2150 | |
| 2151 | // Continuous range maps we may be updating in our module. |
| 2152 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2153 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2154 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2155 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2156 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2157 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2158 | MacroDefinitionRemap(F.MacroDefinitionRemap); |
| 2159 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2160 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2161 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2162 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2163 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2164 | while(Data < DataEnd) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2165 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2166 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2167 | Data += Len; |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2168 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2169 | if (!OM) { |
| 2170 | Error("SourceLocation remap refers to unknown module"); |
| 2171 | return Failure; |
| 2172 | } |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2173 | |
| 2174 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2175 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2176 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
| 2177 | uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data); |
| 2178 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2179 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2180 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2181 | |
| 2182 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2183 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2184 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2185 | IdentifierRemap.insert( |
| 2186 | std::make_pair(IdentifierIDOffset, |
| 2187 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2188 | PreprocessedEntityRemap.insert( |
| 2189 | std::make_pair(PreprocessedEntityIDOffset, |
| 2190 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2191 | MacroDefinitionRemap.insert( |
| 2192 | std::make_pair(MacroDefinitionIDOffset, |
| 2193 | OM->BaseMacroDefinitionID - MacroDefinitionIDOffset)); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2194 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2195 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2196 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2197 | OM->BaseDeclID - DeclIDOffset)); |
| 2198 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2199 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2200 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2201 | } |
| 2202 | break; |
| 2203 | } |
| 2204 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2205 | case SOURCE_MANAGER_LINE_TABLE: |
| 2206 | if (ParseLineTable(F, Record)) |
| 2207 | return Failure; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2208 | break; |
| 2209 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2210 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2211 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2212 | F.LocalNumSLocFileEntries = Record[0]; |
| 2213 | break; |
| 2214 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2215 | case SOURCE_LOCATION_PRELOADS: { |
| 2216 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2217 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | a918bab | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2218 | if (!F.PreloadSLocEntries.empty()) { |
| 2219 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2220 | return Failure; |
| 2221 | } |
| 2222 | |
| 2223 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2224 | break; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2225 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2226 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2227 | case STAT_CACHE: { |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2228 | if (!DisableStatCache) { |
| 2229 | ASTStatCache *MyStatCache = |
| 2230 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2231 | (const unsigned char *)BlobStart, |
| 2232 | NumStatHits, NumStatMisses); |
| 2233 | FileMgr.addStatCache(MyStatCache); |
| 2234 | F.StatCache = MyStatCache; |
| 2235 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2236 | break; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2237 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2238 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2239 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2240 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2241 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2242 | break; |
| 2243 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2244 | case VTABLE_USES: |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2245 | if (Record.size() % 3 != 0) { |
| 2246 | Error("Invalid VTABLE_USES record"); |
| 2247 | return Failure; |
| 2248 | } |
| 2249 | |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2250 | // Later tables overwrite earlier ones. |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2251 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2252 | // the right way to do this. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2253 | VTableUses.clear(); |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2254 | |
| 2255 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2256 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2257 | VTableUses.push_back( |
| 2258 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2259 | VTableUses.push_back(Record[Idx++]); |
| 2260 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2261 | break; |
| 2262 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2263 | case DYNAMIC_CLASSES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2264 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2265 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2266 | break; |
| 2267 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2268 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | bbbc367 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2269 | if (PendingInstantiations.size() % 2 != 0) { |
| 2270 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2271 | return Failure; |
| 2272 | } |
| 2273 | |
| 2274 | // Later lists of pending instantiations overwrite earlier ones. |
| 2275 | // FIXME: This is most certainly wrong for modules. |
| 2276 | PendingInstantiations.clear(); |
| 2277 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2278 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2279 | PendingInstantiations.push_back( |
| 2280 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2281 | } |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2282 | break; |
| 2283 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2284 | case SEMA_DECL_REFS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2285 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2286 | // FIXME: Modules will have some trouble with this. |
| 2287 | SemaDeclRefs.clear(); |
| 2288 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2289 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2290 | break; |
| 2291 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2292 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2293 | // 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] | 2294 | // that's used. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2295 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2296 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2297 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2298 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2299 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2300 | case ORIGINAL_FILE_ID: |
| 2301 | OriginalFileID = FileID::get(Record[0]); |
| 2302 | break; |
| 2303 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2304 | case ORIGINAL_PCH_DIR: |
| 2305 | // The primary AST will be the last to get here, so it will be the one |
| 2306 | // that's used. |
| 2307 | OriginalDir.assign(BlobStart, BlobLen); |
| 2308 | break; |
| 2309 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2310 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 8bd0929 | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2311 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2312 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2313 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2314 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2315 | return IgnorePCH; |
| 2316 | } |
| 2317 | break; |
| 2318 | } |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2319 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2320 | case MACRO_DEFINITION_OFFSETS: { |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2321 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2322 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2323 | unsigned LocalBasePreprocessedEntityID = Record[1]; |
| 2324 | F.LocalNumMacroDefinitions = Record[2]; |
| 2325 | unsigned LocalBaseMacroID = Record[3]; |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2326 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2327 | unsigned StartingID; |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2328 | if (!PP.getPreprocessingRecord()) |
| 2329 | PP.createPreprocessingRecord(true); |
| 2330 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2331 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2332 | StartingID |
| 2333 | = PP.getPreprocessingRecord() |
| 2334 | ->allocateLoadedEntities(F.NumPreallocatedPreprocessingEntities); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2335 | F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); |
| 2336 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2337 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2338 | if (F.NumPreallocatedPreprocessingEntities > 0) { |
| 2339 | // Introduce the global -> local mapping for preprocessed entities in |
| 2340 | // this module. |
| 2341 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2342 | |
| 2343 | // Introduce the local -> global mapping for preprocessed entities in |
| 2344 | // this module. |
| 2345 | F.PreprocessedEntityRemap.insert( |
| 2346 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2347 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2348 | } |
| 2349 | |
| 2350 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2351 | if (F.LocalNumMacroDefinitions > 0) { |
| 2352 | // Introduce the global -> local mapping for macro definitions within |
| 2353 | // this module. |
| 2354 | GlobalMacroDefinitionMap.insert( |
| 2355 | std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); |
| 2356 | |
| 2357 | // Introduce the local -> global mapping for macro definitions within |
| 2358 | // this module. |
| 2359 | F.MacroDefinitionRemap.insert( |
| 2360 | std::make_pair(LocalBaseMacroID, |
| 2361 | F.BaseMacroDefinitionID - LocalBaseMacroID)); |
| 2362 | |
| 2363 | MacroDefinitionsLoaded.resize( |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 2364 | MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2365 | } |
| 2366 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2367 | break; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2370 | case DECL_UPDATE_OFFSETS: { |
| 2371 | if (Record.size() % 2 != 0) { |
| 2372 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2373 | return Failure; |
| 2374 | } |
| 2375 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2376 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2377 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2378 | break; |
| 2379 | } |
| 2380 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2381 | case DECL_REPLACEMENTS: { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2382 | if (Record.size() % 2 != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2383 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2384 | return Failure; |
| 2385 | } |
| 2386 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2387 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2388 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2389 | break; |
| 2390 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2391 | |
| 2392 | case OBJC_CHAINED_CATEGORIES: { |
| 2393 | if (Record.size() % 3 != 0) { |
| 2394 | Error("invalid OBJC_CHAINED_CATEGORIES block in AST file"); |
| 2395 | return Failure; |
| 2396 | } |
| 2397 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) { |
| 2398 | serialization::GlobalDeclID GlobID = getGlobalDeclID(F, Record[I]); |
| 2399 | F.ChainedObjCCategories[GlobID] = std::make_pair(Record[I+1], |
| 2400 | Record[I+2]); |
| 2401 | ObjCChainedCategoriesInterfaces.insert(GlobID); |
| 2402 | } |
| 2403 | break; |
| 2404 | } |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2405 | |
| 2406 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2407 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2408 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2409 | return Failure; |
| 2410 | } |
| 2411 | |
| 2412 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2413 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2414 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2415 | break; |
| 2416 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2417 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2418 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2419 | if (Record.size() % 2 != 0) { |
| 2420 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2421 | return Failure; |
| 2422 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2423 | |
| 2424 | if (F.PragmaDiagMappings.empty()) |
| 2425 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2426 | else |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2427 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2428 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2429 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2430 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2431 | case CUDA_SPECIAL_DECL_REFS: |
| 2432 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2433 | // FIXME: Modules will have trouble with this. |
| 2434 | CUDASpecialDeclRefs.clear(); |
| 2435 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2436 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2437 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2438 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2439 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2440 | F.HeaderFileInfoTableData = BlobStart; |
| 2441 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2442 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2443 | if (Record[0]) { |
| 2444 | F.HeaderFileInfoTable |
| 2445 | = HeaderFileInfoLookupTable::Create( |
| 2446 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2447 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2448 | HeaderFileInfoTrait(*this, F, |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2449 | &PP.getHeaderSearchInfo(), |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2450 | BlobStart + Record[2])); |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2451 | |
| 2452 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 2453 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 2454 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2455 | } |
| 2456 | break; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2459 | case FP_PRAGMA_OPTIONS: |
| 2460 | // Later tables overwrite earlier ones. |
| 2461 | FPPragmaOptions.swap(Record); |
| 2462 | break; |
| 2463 | |
| 2464 | case OPENCL_EXTENSIONS: |
| 2465 | // Later tables overwrite earlier ones. |
| 2466 | OpenCLExtensions.swap(Record); |
| 2467 | break; |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2468 | |
| 2469 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2470 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2471 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2472 | break; |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2473 | |
| 2474 | case KNOWN_NAMESPACES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2475 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2476 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2477 | break; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2478 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2479 | } |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2480 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2481 | return Failure; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2484 | ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) { |
| 2485 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2486 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2487 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2488 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2489 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2490 | if (Code == llvm::bitc::END_BLOCK || |
| 2491 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2492 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2493 | Error("incorrectly-formatted source location entry in AST file"); |
| 2494 | return Failure; |
| 2495 | } |
| 2496 | |
| 2497 | RecordData Record; |
| 2498 | const char *BlobStart; |
| 2499 | unsigned BlobLen; |
| 2500 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2501 | default: |
| 2502 | Error("incorrectly-formatted source location entry in AST file"); |
| 2503 | return Failure; |
| 2504 | |
| 2505 | case SM_SLOC_FILE_ENTRY: { |
| 2506 | StringRef Filename(BlobStart, BlobLen); |
| 2507 | const FileEntry *File = getFileEntry(Filename); |
| 2508 | |
| 2509 | if (File == 0) { |
| 2510 | std::string ErrorStr = "could not find file '"; |
| 2511 | ErrorStr += Filename; |
| 2512 | ErrorStr += "' referenced by AST file"; |
| 2513 | Error(ErrorStr.c_str()); |
| 2514 | return IgnorePCH; |
| 2515 | } |
| 2516 | |
| 2517 | if (Record.size() < 6) { |
| 2518 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2519 | return Failure; |
| 2520 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2521 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2522 | // The stat info from the FileEntry came from the cached stat |
| 2523 | // info of the PCH, so we cannot trust it. |
| 2524 | struct stat StatBuf; |
| 2525 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2526 | StatBuf.st_size = File->getSize(); |
| 2527 | StatBuf.st_mtime = File->getModificationTime(); |
| 2528 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2529 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2530 | if (((off_t)Record[4] != StatBuf.st_size |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2531 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2532 | // In our regression testing, the Windows file system seems to |
| 2533 | // have inconsistent modification times that sometimes |
| 2534 | // erroneously trigger this error-handling path. |
| 2535 | || (time_t)Record[5] != StatBuf.st_mtime |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2536 | #endif |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2537 | )) { |
| 2538 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2539 | return IgnorePCH; |
| 2540 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2541 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2542 | break; |
| 2543 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | return Success; |
| 2548 | } |
| 2549 | |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2550 | namespace { |
| 2551 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 2552 | class IdentifierLookupVisitor { |
| 2553 | StringRef Name; |
| 2554 | IdentifierInfo *Found; |
| 2555 | public: |
| 2556 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
| 2557 | |
| 2558 | static bool visit(Module &M, void *UserData) { |
| 2559 | IdentifierLookupVisitor *This |
| 2560 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 2561 | |
| 2562 | ASTIdentifierLookupTable *IdTable |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 2563 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2564 | if (!IdTable) |
| 2565 | return false; |
| 2566 | |
| 2567 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 2568 | This->Name.size()); |
| 2569 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2570 | if (Pos == IdTable->end()) |
| 2571 | return false; |
| 2572 | |
| 2573 | // Dereferencing the iterator has the effect of building the |
| 2574 | // IdentifierInfo node and populating it with the various |
| 2575 | // declarations it needs. |
| 2576 | This->Found = *Pos; |
| 2577 | return true; |
| 2578 | } |
| 2579 | |
| 2580 | // \brief Retrieve the identifier info found within the module |
| 2581 | // files. |
| 2582 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 2583 | }; |
| 2584 | } |
| 2585 | |
| 2586 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2587 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2588 | ModuleKind Type) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2589 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2590 | case Failure: return Failure; |
| 2591 | case IgnorePCH: return IgnorePCH; |
| 2592 | case Success: break; |
| 2593 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2594 | |
| 2595 | // 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] | 2596 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2597 | // Check the predefines buffers. |
Argyrios Kyrtzidis | 14c32e8 | 2011-09-12 18:09:38 +0000 | [diff] [blame^] | 2598 | if (!DisableValidation && Type != MK_Module && Type != MK_Preamble && |
| 2599 | // FIXME: CheckPredefinesBuffers also sets the SuggestedPredefines; |
| 2600 | // if DisableValidation is true, defines that were set on command-line |
| 2601 | // but not in the PCH file will not be added to SuggestedPredefines. |
| 2602 | CheckPredefinesBuffers()) |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2603 | return IgnorePCH; |
| 2604 | |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2605 | // Initialization of keywords and pragmas occurs before the |
| 2606 | // AST file is read, so there may be some identifiers that were |
| 2607 | // loaded into the IdentifierTable before we intercepted the |
| 2608 | // creation of identifiers. Iterate through the list of known |
| 2609 | // identifiers and determine whether we have to establish |
| 2610 | // preprocessor definitions or top-level identifier declaration |
| 2611 | // chains for those identifiers. |
| 2612 | // |
| 2613 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2614 | // since de-serializing declarations or macro definitions can add |
| 2615 | // new entries into the identifier table, invalidating the |
| 2616 | // iterators. |
| 2617 | // |
| 2618 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2619 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2620 | // AST file(s) if it is uttered in the source. This could save us some |
| 2621 | // module load time. |
| 2622 | SmallVector<IdentifierInfo *, 128> Identifiers; |
| 2623 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 2624 | IdEnd = PP.getIdentifierTable().end(); |
| 2625 | Id != IdEnd; ++Id) |
| 2626 | Identifiers.push_back(Id->second); |
| 2627 | |
| 2628 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2629 | IdentifierLookupVisitor Visitor(Identifiers[I]->getName()); |
| 2630 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2631 | } |
| 2632 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2633 | InitializeContext(); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2634 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2635 | if (DeserializationListener) |
| 2636 | DeserializationListener->ReaderInitialized(this); |
| 2637 | |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2638 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2639 | // the source manager to the file source file from which the preamble was |
| 2640 | // built. This is the only valid way to use a precompiled preamble. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2641 | if (Type == MK_Preamble) { |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2642 | if (OriginalFileID.isInvalid()) { |
| 2643 | SourceLocation Loc |
| 2644 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2645 | if (Loc.isValid()) |
| 2646 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2647 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2648 | else { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2649 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2650 | + OriginalFileID.getOpaqueValue() - 1); |
| 2651 | } |
| 2652 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2653 | if (!OriginalFileID.isInvalid()) |
| 2654 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2655 | } |
| 2656 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2657 | return Success; |
| 2658 | } |
| 2659 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2660 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2661 | ModuleKind Type, |
| 2662 | Module *ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2663 | Module *M; |
| 2664 | bool NewModule; |
| 2665 | std::string ErrorStr; |
| 2666 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2667 | ErrorStr); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2668 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2669 | if (!M) { |
| 2670 | // We couldn't load the module. |
| 2671 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2672 | + ErrorStr; |
| 2673 | Error(Msg); |
| 2674 | return Failure; |
| 2675 | } |
| 2676 | |
| 2677 | if (!NewModule) { |
| 2678 | // We've already loaded this module. |
| 2679 | return Success; |
| 2680 | } |
| 2681 | |
| 2682 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2683 | // module? |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2684 | if (FileName != "-") { |
| 2685 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2686 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2687 | } |
| 2688 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2689 | Module &F = *M; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2690 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2691 | Stream.init(F.StreamFile); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2692 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2693 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2694 | // Sniff for the signature. |
| 2695 | if (Stream.Read(8) != 'C' || |
| 2696 | Stream.Read(8) != 'P' || |
| 2697 | Stream.Read(8) != 'C' || |
| 2698 | Stream.Read(8) != 'H') { |
| 2699 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2700 | return Failure; |
| 2701 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2702 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2703 | while (!Stream.AtEndOfStream()) { |
| 2704 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2705 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2706 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2707 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2708 | return Failure; |
| 2709 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2710 | |
| 2711 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2712 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2713 | // We only know the AST subblock ID. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2714 | switch (BlockID) { |
| 2715 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2716 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2717 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2718 | return Failure; |
| 2719 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2720 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2721 | case AST_BLOCK_ID: |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2722 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2723 | case Success: |
| 2724 | break; |
| 2725 | |
| 2726 | case Failure: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2727 | return Failure; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2728 | |
| 2729 | case IgnorePCH: |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2730 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2731 | // AST block, skipping subblocks, to see if there are other |
| 2732 | // AST blocks elsewhere. |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2733 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2734 | // FIXME: We can't clear loaded slocentries anymore. |
| 2735 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2736 | |
| 2737 | // Remove the stat cache. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2738 | if (F.StatCache) |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2739 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2740 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2741 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2742 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2743 | break; |
| 2744 | default: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2745 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2746 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2747 | return Failure; |
| 2748 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2751 | } |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2752 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2753 | // 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] | 2754 | // bits of all files we've seen. |
| 2755 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2756 | TotalModulesSizeInBits += F.SizeInBits; |
| 2757 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2758 | |
| 2759 | // Make sure that the files this module was built against are still available. |
| 2760 | if (!DisableValidation) { |
| 2761 | switch(validateFileEntries(*M)) { |
| 2762 | case Failure: return Failure; |
| 2763 | case IgnorePCH: return IgnorePCH; |
| 2764 | case Success: break; |
| 2765 | } |
| 2766 | } |
Douglas Gregor | a918bab | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2767 | |
| 2768 | // Preload SLocEntries. |
| 2769 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2770 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 2771 | ASTReadResult Result = ReadSLocEntryRecord(Index); |
| 2772 | if (Result != Success) |
| 2773 | return Failure; |
| 2774 | } |
| 2775 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2776 | |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2777 | return Success; |
| 2778 | } |
| 2779 | |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 2780 | void ASTReader::InitializeContext() { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2781 | // If there's a listener, notify them that we "read" the translation unit. |
| 2782 | if (DeserializationListener) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2783 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2784 | Context.getTranslationUnitDecl()); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2785 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2786 | // Make sure we load the declaration update records for the translation unit, |
| 2787 | // if there are any. |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2788 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 2789 | Context.getTranslationUnitDecl()); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2790 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2791 | // FIXME: Find a better way to deal with collisions between these |
| 2792 | // built-in types. Right now, we just ignore the problem. |
| 2793 | |
| 2794 | // Load the special types. |
Douglas Gregor | abc5fbe | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2795 | if (SpecialTypes.size() > NumSpecialTypeIDs) { |
| 2796 | if (Context.getBuiltinVaListType().isNull()) { |
| 2797 | Context.setBuiltinVaListType( |
| 2798 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
Douglas Gregor | abc5fbe | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2801 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2802 | if (Context.ObjCProtoType.isNull()) |
| 2803 | Context.ObjCProtoType = GetType(Proto); |
| 2804 | } |
| 2805 | |
| 2806 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2807 | if (!Context.CFConstantStringTypeDecl) |
| 2808 | Context.setCFConstantStringType(GetType(String)); |
| 2809 | } |
| 2810 | |
| 2811 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2812 | QualType FileType = GetType(File); |
| 2813 | if (FileType.isNull()) { |
| 2814 | Error("FILE type is NULL"); |
| 2815 | return; |
| 2816 | } |
| 2817 | |
| 2818 | if (!Context.FILEDecl) { |
| 2819 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2820 | Context.setFILEDecl(Typedef->getDecl()); |
| 2821 | else { |
| 2822 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2823 | if (!Tag) { |
| 2824 | Error("Invalid FILE type in AST file"); |
| 2825 | return; |
| 2826 | } |
| 2827 | Context.setFILEDecl(Tag->getDecl()); |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2828 | } |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2829 | } |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2830 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2831 | |
Douglas Gregor | abc5fbe | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2832 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 2833 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2834 | if (Jmp_bufType.isNull()) { |
| 2835 | Error("jmp_buf type is NULL"); |
| 2836 | return; |
| 2837 | } |
| 2838 | |
| 2839 | if (!Context.jmp_bufDecl) { |
| 2840 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2841 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 2842 | else { |
| 2843 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2844 | if (!Tag) { |
| 2845 | Error("Invalid jmp_buf type in AST file"); |
| 2846 | return; |
| 2847 | } |
| 2848 | Context.setjmp_bufDecl(Tag->getDecl()); |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2849 | } |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2850 | } |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2851 | } |
Douglas Gregor | abc5fbe | 2011-09-10 00:30:18 +0000 | [diff] [blame] | 2852 | |
| 2853 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 2854 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2855 | if (Sigjmp_bufType.isNull()) { |
| 2856 | Error("sigjmp_buf type is NULL"); |
| 2857 | return; |
| 2858 | } |
| 2859 | |
| 2860 | if (!Context.sigjmp_bufDecl) { |
| 2861 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2862 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 2863 | else { |
| 2864 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2865 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2866 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 2867 | } |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | if (unsigned ObjCIdRedef |
| 2872 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2873 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 2874 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2875 | } |
| 2876 | |
| 2877 | if (unsigned ObjCClassRedef |
| 2878 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2879 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 2880 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2881 | } |
| 2882 | |
| 2883 | if (unsigned ObjCSelRedef |
| 2884 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2885 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 2886 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2887 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2890 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2891 | |
| 2892 | // If there were any CUDA special declarations, deserialize them. |
| 2893 | if (!CUDASpecialDeclRefs.empty()) { |
| 2894 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2895 | Context.setcudaConfigureCallDecl( |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2896 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2897 | } |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2900 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2901 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2902 | /// file. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2903 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 71731d6 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2904 | FileManager &FileMgr, |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2905 | Diagnostic &Diags) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2906 | // Open the AST file. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2907 | std::string ErrStr; |
| 2908 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2909 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2910 | if (!Buffer) { |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2911 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2912 | return std::string(); |
| 2913 | } |
| 2914 | |
| 2915 | // Initialize the stream |
| 2916 | llvm::BitstreamReader StreamFile; |
| 2917 | llvm::BitstreamCursor Stream; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2918 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2919 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2920 | Stream.init(StreamFile); |
| 2921 | |
| 2922 | // Sniff for the signature. |
| 2923 | if (Stream.Read(8) != 'C' || |
| 2924 | Stream.Read(8) != 'P' || |
| 2925 | Stream.Read(8) != 'C' || |
| 2926 | Stream.Read(8) != 'H') { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2927 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2928 | return std::string(); |
| 2929 | } |
| 2930 | |
| 2931 | RecordData Record; |
| 2932 | while (!Stream.AtEndOfStream()) { |
| 2933 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2934 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2935 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2936 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2937 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2938 | // We only know the AST subblock ID. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2939 | switch (BlockID) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2940 | case AST_BLOCK_ID: |
| 2941 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2942 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2943 | return std::string(); |
| 2944 | } |
| 2945 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2946 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2947 | default: |
| 2948 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2949 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2950 | return std::string(); |
| 2951 | } |
| 2952 | break; |
| 2953 | } |
| 2954 | continue; |
| 2955 | } |
| 2956 | |
| 2957 | if (Code == llvm::bitc::END_BLOCK) { |
| 2958 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2959 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2960 | return std::string(); |
| 2961 | } |
| 2962 | continue; |
| 2963 | } |
| 2964 | |
| 2965 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 2966 | Stream.ReadAbbrevRecord(); |
| 2967 | continue; |
| 2968 | } |
| 2969 | |
| 2970 | Record.clear(); |
| 2971 | const char *BlobStart = 0; |
| 2972 | unsigned BlobLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2973 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2974 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2975 | return std::string(BlobStart, BlobLen); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2976 | } |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2977 | |
| 2978 | return std::string(); |
| 2979 | } |
| 2980 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2981 | /// \brief Parse the record that corresponds to a LangOptions data |
| 2982 | /// structure. |
| 2983 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2984 | /// This routine parses the language options from the AST file and then gives |
| 2985 | /// them to the AST listener if one is set. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2986 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2987 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2988 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2989 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2990 | if (Listener) { |
| 2991 | LangOptions LangOpts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2993 | #define PARSE_LANGOPT(Option) \ |
| 2994 | LangOpts.Option = Record[Idx]; \ |
| 2995 | ++Idx |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2996 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2997 | unsigned Idx = 0; |
| 2998 | PARSE_LANGOPT(Trigraphs); |
| 2999 | PARSE_LANGOPT(BCPLComment); |
| 3000 | PARSE_LANGOPT(DollarIdents); |
| 3001 | PARSE_LANGOPT(AsmPreprocessor); |
| 3002 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 3003 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3004 | PARSE_LANGOPT(ImplicitInt); |
| 3005 | PARSE_LANGOPT(Digraphs); |
| 3006 | PARSE_LANGOPT(HexFloats); |
| 3007 | PARSE_LANGOPT(C99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 3008 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3009 | PARSE_LANGOPT(Microsoft); |
| 3010 | PARSE_LANGOPT(CPlusPlus); |
| 3011 | PARSE_LANGOPT(CPlusPlus0x); |
| 3012 | PARSE_LANGOPT(CXXOperatorNames); |
| 3013 | PARSE_LANGOPT(ObjC1); |
| 3014 | PARSE_LANGOPT(ObjC2); |
| 3015 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 3016 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 3017 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 3018 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 3019 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 3020 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3021 | PARSE_LANGOPT(PascalStrings); |
| 3022 | PARSE_LANGOPT(WritableStrings); |
| 3023 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3024 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3025 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 3026 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 3027 | PARSE_LANGOPT(CXXExceptions); |
| 3028 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 3029 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3030 | PARSE_LANGOPT(NeXTRuntime); |
| 3031 | PARSE_LANGOPT(Freestanding); |
| 3032 | PARSE_LANGOPT(NoBuiltin); |
| 3033 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 3034 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3035 | PARSE_LANGOPT(Blocks); |
| 3036 | PARSE_LANGOPT(EmitAllDecls); |
| 3037 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3038 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 3039 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3040 | PARSE_LANGOPT(HeinousExtensions); |
| 3041 | PARSE_LANGOPT(Optimize); |
| 3042 | PARSE_LANGOPT(OptimizeSize); |
| 3043 | PARSE_LANGOPT(Static); |
| 3044 | PARSE_LANGOPT(PICLevel); |
| 3045 | PARSE_LANGOPT(GNUInline); |
| 3046 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 3047 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3048 | PARSE_LANGOPT(AccessControl); |
| 3049 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 3050 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | a88942a | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 3051 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3052 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 3053 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 3054 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3055 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3056 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3057 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 3058 | PARSE_LANGOPT(CUDA); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 3059 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3060 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | dc1f68d | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 3061 | PARSE_LANGOPT(ElideConstructors); |
| 3062 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | 65b88cd | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 3063 | PARSE_LANGOPT(MRTD); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3064 | PARSE_LANGOPT(ObjCAutoRefCount); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3065 | #undef PARSE_LANGOPT |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3066 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3067 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3068 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3069 | |
| 3070 | return false; |
| 3071 | } |
| 3072 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 3073 | namespace { |
| 3074 | /// \brief Visitor used by ASTReader::ReadPreprocessedEntities() to load |
| 3075 | /// all of the preprocessed entities within a module. |
| 3076 | class ReadPreprocessedEntitiesVisitor { |
| 3077 | ASTReader &Reader; |
| 3078 | |
| 3079 | public: |
| 3080 | explicit ReadPreprocessedEntitiesVisitor(ASTReader &Reader) |
| 3081 | : Reader(Reader) { } |
| 3082 | |
| 3083 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 3084 | if (Preorder) |
| 3085 | return false; |
| 3086 | |
| 3087 | ReadPreprocessedEntitiesVisitor *This |
| 3088 | = static_cast<ReadPreprocessedEntitiesVisitor *>(UserData); |
| 3089 | |
| 3090 | if (!M.PreprocessorDetailCursor.getBitStreamReader()) |
| 3091 | return false; |
| 3092 | |
| 3093 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 3094 | M.PreprocessorDetailCursor.JumpToBit(M.PreprocessorDetailStartOffset); |
| 3095 | while (This->Reader.LoadPreprocessedEntity(M)) { } |
| 3096 | return false; |
| 3097 | } |
| 3098 | }; |
| 3099 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3100 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 3101 | void ASTReader::ReadPreprocessedEntities() { |
| 3102 | ReadPreprocessedEntitiesVisitor Visitor(*this); |
| 3103 | ModuleMgr.visitDepthFirst(&ReadPreprocessedEntitiesVisitor::visit, &Visitor); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
Douglas Gregor | 46c5001 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3106 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3107 | RecordLocation Loc = getLocalBitOffset(Offset); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3108 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3109 | // Keep track of where we are in the stream, then jump back there |
| 3110 | // after reading this entity. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3111 | SavedStreamPosition SavedPosition(Loc.F->PreprocessorDetailCursor); |
| 3112 | Loc.F->PreprocessorDetailCursor.JumpToBit(Loc.Offset); |
| 3113 | return LoadPreprocessedEntity(*Loc.F); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3116 | namespace { |
| 3117 | /// \brief Visitor used to search for information about a header file. |
| 3118 | class HeaderFileInfoVisitor { |
| 3119 | ASTReader &Reader; |
| 3120 | const FileEntry *FE; |
| 3121 | |
| 3122 | llvm::Optional<HeaderFileInfo> HFI; |
| 3123 | |
| 3124 | public: |
| 3125 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3126 | : Reader(Reader), FE(FE) { } |
| 3127 | |
| 3128 | static bool visit(Module &M, void *UserData) { |
| 3129 | HeaderFileInfoVisitor *This |
| 3130 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3131 | |
| 3132 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3133 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3134 | M.HeaderFileFrameworkStrings, |
| 3135 | This->FE->getName()); |
| 3136 | |
| 3137 | HeaderFileInfoLookupTable *Table |
| 3138 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3139 | if (!Table) |
| 3140 | return false; |
| 3141 | |
| 3142 | // Look in the on-disk hash table for an entry for this file name. |
| 3143 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3144 | &Trait); |
| 3145 | if (Pos == Table->end()) |
| 3146 | return false; |
| 3147 | |
| 3148 | This->HFI = *Pos; |
| 3149 | return true; |
| 3150 | } |
| 3151 | |
| 3152 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3153 | }; |
| 3154 | } |
| 3155 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3156 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3157 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3158 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3159 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3160 | if (Listener) |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3161 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3162 | return *HFI; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | return HeaderFileInfo(); |
| 3166 | } |
| 3167 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3168 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3169 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3170 | Module &F = *(*I); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3171 | unsigned Idx = 0; |
| 3172 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3173 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3174 | while (1) { |
| 3175 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3176 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3177 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3178 | break; // Something is messed up but at least avoid infinite loop in |
| 3179 | // release build. |
| 3180 | } |
| 3181 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3182 | if (DiagID == (unsigned)-1) { |
| 3183 | break; // no more diag/map pairs for this location. |
| 3184 | } |
| 3185 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3186 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3187 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3188 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3189 | } |
| 3190 | } |
| 3191 | |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3192 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3193 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3194 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | 3500568 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3195 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3196 | Module *M = I->second; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3197 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3201 | /// |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3202 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3203 | /// routine actually reads the record corresponding to the type at the given |
| 3204 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3205 | /// IDs. |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3206 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3207 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3208 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3209 | |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3210 | // Keep track of where we are in the stream, then jump back there |
| 3211 | // after reading this type. |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3212 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3213 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3214 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3215 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3216 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3217 | Deserializing AType(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3218 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3219 | unsigned Idx = 0; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3220 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3221 | RecordData Record; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3222 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3223 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3224 | case TYPE_EXT_QUAL: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3225 | if (Record.size() != 2) { |
| 3226 | Error("Incorrect encoding of extended qualifier type"); |
| 3227 | return QualType(); |
| 3228 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3229 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3230 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3231 | return Context.getQualifiedType(Base, Quals); |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3232 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3233 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3234 | case TYPE_COMPLEX: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3235 | if (Record.size() != 1) { |
| 3236 | Error("Incorrect encoding of complex type"); |
| 3237 | return QualType(); |
| 3238 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3239 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3240 | return Context.getComplexType(ElemType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3241 | } |
| 3242 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3243 | case TYPE_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3244 | if (Record.size() != 1) { |
| 3245 | Error("Incorrect encoding of pointer type"); |
| 3246 | return QualType(); |
| 3247 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3248 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3249 | return Context.getPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3252 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3253 | if (Record.size() != 1) { |
| 3254 | Error("Incorrect encoding of block pointer type"); |
| 3255 | return QualType(); |
| 3256 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3257 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3258 | return Context.getBlockPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3261 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3262 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3263 | Error("Incorrect encoding of lvalue reference type"); |
| 3264 | return QualType(); |
| 3265 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3266 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3267 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3268 | } |
| 3269 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3270 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3271 | if (Record.size() != 1) { |
| 3272 | Error("Incorrect encoding of rvalue reference type"); |
| 3273 | return QualType(); |
| 3274 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3275 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3276 | return Context.getRValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3277 | } |
| 3278 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3279 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | ee776bc | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3280 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3281 | Error("Incorrect encoding of member pointer type"); |
| 3282 | return QualType(); |
| 3283 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3284 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3285 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3286 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3287 | return QualType(); |
| 3288 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3289 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3290 | } |
| 3291 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3292 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3293 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3294 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3295 | unsigned IndexTypeQuals = Record[2]; |
| 3296 | unsigned Idx = 3; |
| 3297 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3298 | return Context.getConstantArrayType(ElementType, Size, |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3299 | ASM, IndexTypeQuals); |
| 3300 | } |
| 3301 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3302 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3303 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3304 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3305 | unsigned IndexTypeQuals = Record[2]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3306 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3309 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3310 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3311 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3312 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3313 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3314 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3315 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3316 | ASM, IndexTypeQuals, |
| 3317 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3320 | case TYPE_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3321 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3322 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3323 | return QualType(); |
| 3324 | } |
| 3325 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3326 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3327 | unsigned NumElements = Record[1]; |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3328 | unsigned VecKind = Record[2]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3329 | return Context.getVectorType(ElementType, NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3330 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3331 | } |
| 3332 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3333 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3334 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3335 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3336 | return QualType(); |
| 3337 | } |
| 3338 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3339 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3340 | unsigned NumElements = Record[1]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3341 | return Context.getExtVectorType(ElementType, NumElements); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3342 | } |
| 3343 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3344 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3345 | if (Record.size() != 6) { |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3346 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3347 | return QualType(); |
| 3348 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3349 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3350 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3351 | (CallingConv)Record[4], Record[5]); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3352 | return Context.getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3353 | } |
| 3354 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3355 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3356 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3357 | |
| 3358 | FunctionProtoType::ExtProtoInfo EPI; |
| 3359 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3360 | /*hasregparm*/ Record[2], |
| 3361 | /*regparm*/ Record[3], |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3362 | static_cast<CallingConv>(Record[4]), |
| 3363 | /*produces*/ Record[5]); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3364 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3365 | unsigned Idx = 6; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3366 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3367 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3368 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3369 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3370 | |
| 3371 | EPI.Variadic = Record[Idx++]; |
| 3372 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3373 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3374 | ExceptionSpecificationType EST = |
| 3375 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3376 | EPI.ExceptionSpecType = EST; |
| 3377 | if (EST == EST_Dynamic) { |
| 3378 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3379 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3380 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3381 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3382 | EPI.Exceptions = Exceptions.data(); |
| 3383 | } else if (EST == EST_ComputedNoexcept) { |
| 3384 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3385 | } |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3386 | return Context.getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3387 | EPI); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3388 | } |
| 3389 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3390 | case TYPE_UNRESOLVED_USING: { |
| 3391 | unsigned Idx = 0; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3392 | return Context.getTypeDeclType( |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3393 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3394 | } |
| 3395 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3396 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3397 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3398 | Error("incorrect encoding of typedef type"); |
| 3399 | return QualType(); |
| 3400 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3401 | unsigned Idx = 0; |
| 3402 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3403 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3404 | if (!Canonical.isNull()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3405 | Canonical = Context.getCanonicalType(Canonical); |
| 3406 | return Context.getTypedefType(Decl, Canonical); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3407 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3408 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3409 | case TYPE_TYPEOF_EXPR: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3410 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3411 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3412 | case TYPE_TYPEOF: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3413 | if (Record.size() != 1) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3414 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3415 | return QualType(); |
| 3416 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3417 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3418 | return Context.getTypeOfType(UnderlyingType); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3419 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3420 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3421 | case TYPE_DECLTYPE: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3422 | return Context.getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3423 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3424 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3425 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3426 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3427 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3428 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3431 | case TYPE_AUTO: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3432 | return Context.getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3433 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3434 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3435 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3436 | Error("incorrect encoding of record type"); |
| 3437 | return QualType(); |
| 3438 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3439 | unsigned Idx = 0; |
| 3440 | bool IsDependent = Record[Idx++]; |
| 3441 | QualType T |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3442 | = Context.getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3443 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3444 | return T; |
| 3445 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3446 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3447 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3448 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3449 | Error("incorrect encoding of enum type"); |
| 3450 | return QualType(); |
| 3451 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3452 | unsigned Idx = 0; |
| 3453 | bool IsDependent = Record[Idx++]; |
| 3454 | QualType T |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3455 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3456 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3457 | return T; |
| 3458 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3459 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3460 | case TYPE_ATTRIBUTED: { |
| 3461 | if (Record.size() != 3) { |
| 3462 | Error("incorrect encoding of attributed type"); |
| 3463 | return QualType(); |
| 3464 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3465 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3466 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3467 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3468 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3471 | case TYPE_PAREN: { |
| 3472 | if (Record.size() != 1) { |
| 3473 | Error("incorrect encoding of paren type"); |
| 3474 | return QualType(); |
| 3475 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3476 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3477 | return Context.getParenType(InnerType); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3478 | } |
| 3479 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3480 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | 1732850 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3481 | if (Record.size() != 2) { |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3482 | Error("incorrect encoding of pack expansion type"); |
| 3483 | return QualType(); |
| 3484 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3485 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3486 | if (Pattern.isNull()) |
| 3487 | return QualType(); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3488 | llvm::Optional<unsigned> NumExpansions; |
| 3489 | if (Record[1]) |
| 3490 | NumExpansions = Record[1] - 1; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3491 | return Context.getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3492 | } |
| 3493 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3494 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3495 | unsigned Idx = 0; |
| 3496 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3497 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3498 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3499 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3502 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3503 | unsigned Idx = 0; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3504 | ObjCInterfaceDecl *ItfD |
| 3505 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3506 | return Context.getObjCInterfaceType(ItfD); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3509 | case TYPE_OBJC_OBJECT: { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3510 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3511 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3512 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3513 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3514 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3515 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3516 | return Context.getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3517 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3518 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3519 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3520 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3521 | QualType Pointee = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3522 | return Context.getObjCObjectPointerType(Pointee); |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3523 | } |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3524 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3525 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3526 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3527 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3528 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3529 | return |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3530 | Context.getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3531 | Replacement); |
| 3532 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3533 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3534 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3535 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3536 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3537 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3538 | return Context.getSubstTemplateTypeParmPackType( |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3539 | cast<TemplateTypeParmType>(Parm), |
| 3540 | ArgPack); |
| 3541 | } |
| 3542 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3543 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3544 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3545 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3546 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3547 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3548 | return |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3549 | QualType(new (Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3550 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3551 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3552 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3553 | unsigned Idx = 0; |
| 3554 | unsigned Depth = Record[Idx++]; |
| 3555 | unsigned Index = Record[Idx++]; |
| 3556 | bool Pack = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3557 | TemplateTypeParmDecl *D |
| 3558 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3559 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3560 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3561 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3562 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3563 | unsigned Idx = 0; |
| 3564 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3565 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3566 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3567 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3568 | if (!Canon.isNull()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3569 | Canon = Context.getCanonicalType(Canon); |
| 3570 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3571 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3572 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3573 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3574 | unsigned Idx = 0; |
| 3575 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3576 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3577 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3578 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3579 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3580 | Args.reserve(NumArgs); |
| 3581 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3582 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3583 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3584 | Args.size(), Args.data()); |
| 3585 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3586 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3587 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3588 | unsigned Idx = 0; |
| 3589 | |
| 3590 | // ArrayType |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3591 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3592 | ArrayType::ArraySizeModifier ASM |
| 3593 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3594 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3595 | |
| 3596 | // DependentSizedArrayType |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3597 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3598 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3599 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3600 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3601 | IndexTypeQuals, Brackets); |
| 3602 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3603 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3604 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3605 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3606 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3607 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3608 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3609 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3610 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3611 | QualType T; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3612 | if (Underlying.isNull()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3613 | T = Context.getCanonicalTemplateSpecializationType(Name, Args.data(), |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3614 | Args.size()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3615 | else |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3616 | T = Context.getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3617 | Args.size(), Underlying); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3618 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3619 | return T; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3620 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3621 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3622 | // Suppress a GCC warning |
| 3623 | return QualType(); |
| 3624 | } |
| 3625 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3626 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3627 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3628 | Module &F; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3629 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3630 | const ASTReader::RecordData &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3631 | unsigned &Idx; |
| 3632 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3633 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3634 | unsigned &I) { |
| 3635 | return Reader.ReadSourceLocation(F, R, I); |
| 3636 | } |
| 3637 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3638 | template<typename T> |
| 3639 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3640 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3641 | } |
| 3642 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3643 | public: |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3644 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3645 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3646 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3647 | { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3648 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3649 | // We want compile-time assurance that we've enumerated all of |
| 3650 | // these, so unfortunately we have to declare them first, then |
| 3651 | // define them out-of-line. |
| 3652 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3653 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3654 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3655 | #include "clang/AST/TypeLocNodes.def" |
| 3656 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3657 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3658 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3659 | }; |
| 3660 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3661 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3662 | // nothing to do |
| 3663 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3664 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3665 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3666 | if (TL.needsExtraLocalData()) { |
| 3667 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3668 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3669 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3670 | TL.setModeAttr(Record[Idx++]); |
| 3671 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3672 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3673 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3674 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3675 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3676 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3677 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3678 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3679 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3680 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3681 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3682 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3683 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3684 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3685 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3686 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3687 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3688 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3689 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3690 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3691 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3692 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3693 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3694 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3695 | if (Record[Idx++]) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3696 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3697 | else |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3698 | TL.setSizeExpr(0); |
| 3699 | } |
| 3700 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3701 | VisitArrayTypeLoc(TL); |
| 3702 | } |
| 3703 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3704 | VisitArrayTypeLoc(TL); |
| 3705 | } |
| 3706 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3707 | VisitArrayTypeLoc(TL); |
| 3708 | } |
| 3709 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3710 | DependentSizedArrayTypeLoc TL) { |
| 3711 | VisitArrayTypeLoc(TL); |
| 3712 | } |
| 3713 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3714 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3715 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3716 | } |
| 3717 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3718 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3719 | } |
| 3720 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3721 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3722 | } |
| 3723 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3724 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3725 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3726 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3727 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3728 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3729 | } |
| 3730 | } |
| 3731 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3732 | VisitFunctionTypeLoc(TL); |
| 3733 | } |
| 3734 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3735 | VisitFunctionTypeLoc(TL); |
| 3736 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3737 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3738 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3739 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3740 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3741 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3742 | } |
| 3743 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3744 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3745 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3746 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3747 | } |
| 3748 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3749 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3750 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3751 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3752 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3753 | } |
| 3754 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3755 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3756 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3757 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3758 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3759 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3760 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3761 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3762 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3763 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3764 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3765 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3766 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3767 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3768 | } |
| 3769 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc 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 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3772 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3773 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3774 | if (TL.hasAttrOperand()) { |
| 3775 | SourceRange range; |
| 3776 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3777 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3778 | TL.setAttrOperandParensRange(range); |
| 3779 | } |
| 3780 | if (TL.hasAttrExprOperand()) { |
| 3781 | if (Record[Idx++]) |
| 3782 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3783 | else |
| 3784 | TL.setAttrExprOperand(0); |
| 3785 | } else if (TL.hasAttrEnumOperand()) |
| 3786 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3787 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3788 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3789 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3790 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3791 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3792 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3793 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3794 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3795 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3796 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3797 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3798 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3799 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3800 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3801 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3802 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3803 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3804 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3805 | TL.setArgLocInfo(i, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3806 | Reader.GetTemplateArgumentLocInfo(F, |
| 3807 | TL.getTypePtr()->getArg(i).getKind(), |
| 3808 | Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3809 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3810 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3811 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3812 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3813 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3814 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3815 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3816 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3817 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3818 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3819 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3820 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3821 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3822 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3823 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3824 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3825 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3826 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3827 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3828 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3829 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3830 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3831 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3832 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +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 | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3838 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3839 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3840 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3841 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3842 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3843 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3844 | } |
| 3845 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3846 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3847 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3848 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3849 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3850 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3851 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3852 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3853 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3854 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3855 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3856 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3857 | const RecordData &Record, |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3858 | unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3859 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3860 | if (InfoTy.isNull()) |
| 3861 | return 0; |
| 3862 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3863 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3864 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3865 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3866 | TLR.Visit(TL); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3867 | return TInfo; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3868 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3869 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3870 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3871 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3872 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3873 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3874 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3875 | QualType T; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3876 | switch ((PredefinedTypeIDs)Index) { |
| 3877 | case PREDEF_TYPE_NULL_ID: return QualType(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3878 | case PREDEF_TYPE_VOID_ID: T = Context.VoidTy; break; |
| 3879 | case PREDEF_TYPE_BOOL_ID: T = Context.BoolTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3880 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3881 | case PREDEF_TYPE_CHAR_U_ID: |
| 3882 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3883 | // FIXME: Check that the signedness of CharTy is correct! |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3884 | T = Context.CharTy; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3885 | break; |
| 3886 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3887 | case PREDEF_TYPE_UCHAR_ID: T = Context.UnsignedCharTy; break; |
| 3888 | case PREDEF_TYPE_USHORT_ID: T = Context.UnsignedShortTy; break; |
| 3889 | case PREDEF_TYPE_UINT_ID: T = Context.UnsignedIntTy; break; |
| 3890 | case PREDEF_TYPE_ULONG_ID: T = Context.UnsignedLongTy; break; |
| 3891 | case PREDEF_TYPE_ULONGLONG_ID: T = Context.UnsignedLongLongTy; break; |
| 3892 | case PREDEF_TYPE_UINT128_ID: T = Context.UnsignedInt128Ty; break; |
| 3893 | case PREDEF_TYPE_SCHAR_ID: T = Context.SignedCharTy; break; |
| 3894 | case PREDEF_TYPE_WCHAR_ID: T = Context.WCharTy; break; |
| 3895 | case PREDEF_TYPE_SHORT_ID: T = Context.ShortTy; break; |
| 3896 | case PREDEF_TYPE_INT_ID: T = Context.IntTy; break; |
| 3897 | case PREDEF_TYPE_LONG_ID: T = Context.LongTy; break; |
| 3898 | case PREDEF_TYPE_LONGLONG_ID: T = Context.LongLongTy; break; |
| 3899 | case PREDEF_TYPE_INT128_ID: T = Context.Int128Ty; break; |
| 3900 | case PREDEF_TYPE_FLOAT_ID: T = Context.FloatTy; break; |
| 3901 | case PREDEF_TYPE_DOUBLE_ID: T = Context.DoubleTy; break; |
| 3902 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context.LongDoubleTy; break; |
| 3903 | case PREDEF_TYPE_OVERLOAD_ID: T = Context.OverloadTy; break; |
| 3904 | case PREDEF_TYPE_BOUND_MEMBER: T = Context.BoundMemberTy; break; |
| 3905 | case PREDEF_TYPE_DEPENDENT_ID: T = Context.DependentTy; break; |
| 3906 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context.UnknownAnyTy; break; |
| 3907 | case PREDEF_TYPE_NULLPTR_ID: T = Context.NullPtrTy; break; |
| 3908 | case PREDEF_TYPE_CHAR16_ID: T = Context.Char16Ty; break; |
| 3909 | case PREDEF_TYPE_CHAR32_ID: T = Context.Char32Ty; break; |
| 3910 | case PREDEF_TYPE_OBJC_ID: T = Context.ObjCBuiltinIdTy; break; |
| 3911 | case PREDEF_TYPE_OBJC_CLASS: T = Context.ObjCBuiltinClassTy; break; |
| 3912 | case PREDEF_TYPE_OBJC_SEL: T = Context.ObjCBuiltinSelTy; break; |
| 3913 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context.getAutoDeductType(); break; |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3914 | |
| 3915 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 3916 | T = Context.getAutoRRefDeductType(); |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3917 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
| 3920 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3921 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3924 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3925 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3926 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3927 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3928 | if (TypesLoaded[Index].isNull()) |
| 3929 | return QualType(); |
| 3930 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3931 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3932 | if (DeserializationListener) |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3933 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3934 | TypesLoaded[Index]); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3935 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3936 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3937 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3940 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3941 | return GetType(getGlobalTypeID(F, LocalID)); |
| 3942 | } |
| 3943 | |
| 3944 | serialization::TypeID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3945 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3946 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 3947 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 3948 | |
| 3949 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 3950 | return LocalID; |
| 3951 | |
| 3952 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 3953 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 3954 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 3955 | |
| 3956 | unsigned GlobalIndex = LocalIndex + I->second; |
| 3957 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 3958 | } |
| 3959 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3960 | TemplateArgumentLocInfo |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3961 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3962 | TemplateArgument::ArgKind Kind, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3963 | const RecordData &Record, |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3964 | unsigned &Index) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3965 | switch (Kind) { |
| 3966 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3967 | return ReadExpr(F); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3968 | case TemplateArgument::Type: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3969 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3970 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3971 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3972 | Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3973 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3974 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3975 | SourceLocation()); |
| 3976 | } |
| 3977 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3978 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 3979 | Index); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 3980 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3981 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 3982 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 3983 | EllipsisLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 3984 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3985 | case TemplateArgument::Null: |
| 3986 | case TemplateArgument::Integral: |
| 3987 | case TemplateArgument::Declaration: |
| 3988 | case TemplateArgument::Pack: |
| 3989 | return TemplateArgumentLocInfo(); |
| 3990 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 3991 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3992 | return TemplateArgumentLocInfo(); |
| 3993 | } |
| 3994 | |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3995 | TemplateArgumentLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3996 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3997 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3998 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 3999 | |
| 4000 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4001 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4002 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4003 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4004 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4005 | Record, Index)); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4006 | } |
| 4007 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4008 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4009 | return GetDecl(ID); |
| 4010 | } |
| 4011 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4012 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 4013 | unsigned &Idx){ |
| 4014 | if (Idx >= Record.size()) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4015 | return 0; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4016 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4017 | unsigned LocalID = Record[Idx++]; |
| 4018 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4022 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4023 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4024 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4025 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4026 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4027 | RecordData Record; |
| 4028 | unsigned Code = Cursor.ReadCode(); |
| 4029 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4030 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4031 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4032 | return 0; |
| 4033 | } |
| 4034 | |
| 4035 | unsigned Idx = 0; |
| 4036 | unsigned NumBases = Record[Idx++]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4037 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4038 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4039 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4040 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4041 | return Bases; |
| 4042 | } |
| 4043 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4044 | serialization::DeclID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4045 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4046 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4047 | return LocalID; |
| 4048 | |
| 4049 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4050 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4051 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4052 | |
| 4053 | return LocalID + I->second; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4056 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 4057 | Module &M) const { |
| 4058 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4059 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4060 | return &M == I->second; |
| 4061 | } |
| 4062 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4063 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4064 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4065 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4066 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4067 | return 0; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4068 | |
| 4069 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4070 | return Context.getTranslationUnitDecl(); |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4071 | |
| 4072 | case PREDEF_DECL_OBJC_ID_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4073 | return Context.getObjCIdDecl(); |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4074 | |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4075 | case PREDEF_DECL_OBJC_SEL_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4076 | return Context.getObjCSelDecl(); |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4077 | |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4078 | case PREDEF_DECL_OBJC_CLASS_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4079 | return Context.getObjCClassDecl(); |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4080 | |
| 4081 | case PREDEF_DECL_INT_128_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4082 | return Context.getInt128Decl(); |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4083 | |
| 4084 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4085 | return Context.getUInt128Decl(); |
Douglas Gregor | bab8a96 | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4086 | |
| 4087 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4088 | return Context.getObjCInstanceTypeDecl(); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4091 | return 0; |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4092 | } |
| 4093 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4094 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4095 | |
| 4096 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4097 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4098 | return 0; |
| 4099 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4100 | |
| 4101 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4102 | ReadDeclRecord(ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4103 | if (DeserializationListener) |
| 4104 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4105 | } |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4106 | |
| 4107 | return DeclsLoaded[Index]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4108 | } |
| 4109 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4110 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4111 | const RecordData &Record, |
| 4112 | unsigned &Idx) { |
| 4113 | if (Idx >= Record.size()) { |
| 4114 | Error("Corrupted AST file"); |
| 4115 | return 0; |
| 4116 | } |
| 4117 | |
| 4118 | return getGlobalDeclID(F, Record[Idx++]); |
| 4119 | } |
| 4120 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4121 | /// \brief Resolve the offset of a statement into a statement. |
| 4122 | /// |
| 4123 | /// This operation will read a new statement from the external |
| 4124 | /// source each time it is called, and is meant to be used via a |
| 4125 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4126 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4127 | // Switch case IDs are per Decl. |
| 4128 | ClearSwitchCaseIDs(); |
| 4129 | |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4130 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4131 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4132 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4133 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4136 | namespace { |
| 4137 | class FindExternalLexicalDeclsVisitor { |
| 4138 | ASTReader &Reader; |
| 4139 | const DeclContext *DC; |
| 4140 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4141 | |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4142 | SmallVectorImpl<Decl*> &Decls; |
| 4143 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4144 | |
| 4145 | public: |
| 4146 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4147 | bool (*isKindWeWant)(Decl::Kind), |
| 4148 | SmallVectorImpl<Decl*> &Decls) |
| 4149 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4150 | { |
| 4151 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4152 | PredefsVisited[I] = false; |
| 4153 | } |
| 4154 | |
| 4155 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4156 | if (Preorder) |
| 4157 | return false; |
| 4158 | |
| 4159 | FindExternalLexicalDeclsVisitor *This |
| 4160 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4161 | |
| 4162 | Module::DeclContextInfosMap::iterator Info |
| 4163 | = M.DeclContextInfos.find(This->DC); |
| 4164 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4165 | return false; |
| 4166 | |
| 4167 | // Load all of the declaration IDs |
| 4168 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4169 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4170 | ID != IDE; ++ID) { |
| 4171 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4172 | continue; |
| 4173 | |
| 4174 | // Don't add predefined declarations to the lexical context more |
| 4175 | // than once. |
| 4176 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4177 | if (This->PredefsVisited[ID->second]) |
| 4178 | continue; |
| 4179 | |
| 4180 | This->PredefsVisited[ID->second] = true; |
| 4181 | } |
| 4182 | |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4183 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4184 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4185 | This->Decls.push_back(D); |
| 4186 | } |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | return false; |
| 4190 | } |
| 4191 | }; |
| 4192 | } |
| 4193 | |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4194 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4195 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4196 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4197 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4198 | // least. Walk all of the modules in the order they were loaded. |
| 4199 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4200 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4201 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4202 | return ELR_Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4205 | namespace { |
| 4206 | /// \brief Module visitor used to perform name lookup into a |
| 4207 | /// declaration context. |
| 4208 | class DeclContextNameLookupVisitor { |
| 4209 | ASTReader &Reader; |
| 4210 | const DeclContext *DC; |
| 4211 | DeclarationName Name; |
| 4212 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4213 | |
| 4214 | public: |
| 4215 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4216 | const DeclContext *DC, DeclarationName Name, |
| 4217 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4218 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4219 | |
| 4220 | static bool visit(Module &M, void *UserData) { |
| 4221 | DeclContextNameLookupVisitor *This |
| 4222 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4223 | |
| 4224 | // Check whether we have any visible declaration information for |
| 4225 | // this context in this module. |
| 4226 | Module::DeclContextInfosMap::iterator Info |
| 4227 | = M.DeclContextInfos.find(This->DC); |
| 4228 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4229 | return false; |
| 4230 | |
| 4231 | // Look for this name within this module. |
| 4232 | ASTDeclContextNameLookupTable *LookupTable = |
| 4233 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4234 | ASTDeclContextNameLookupTable::iterator Pos |
| 4235 | = LookupTable->find(This->Name); |
| 4236 | if (Pos == LookupTable->end()) |
| 4237 | return false; |
| 4238 | |
| 4239 | bool FoundAnything = false; |
| 4240 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4241 | for (; Data.first != Data.second; ++Data.first) { |
| 4242 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4243 | if (!ND) |
| 4244 | continue; |
| 4245 | |
| 4246 | if (ND->getDeclName() != This->Name) { |
| 4247 | assert(!This->Name.getCXXNameType().isNull() && |
| 4248 | "Name mismatch without a type"); |
| 4249 | continue; |
| 4250 | } |
| 4251 | |
| 4252 | // Record this declaration. |
| 4253 | FoundAnything = true; |
| 4254 | This->Decls.push_back(ND); |
| 4255 | } |
| 4256 | |
| 4257 | return FoundAnything; |
| 4258 | } |
| 4259 | }; |
| 4260 | } |
| 4261 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4262 | DeclContext::lookup_result |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4263 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4264 | DeclarationName Name) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4265 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4266 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4267 | if (!Name) |
| 4268 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4269 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4270 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4271 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4272 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4273 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4274 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4275 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4276 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4279 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4280 | assert(Consumer); |
| 4281 | while (!InterestingDecls.empty()) { |
| 4282 | DeclGroupRef DG(InterestingDecls.front()); |
| 4283 | InterestingDecls.pop_front(); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4284 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4285 | } |
| 4286 | } |
| 4287 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4288 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | b985eeb | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4289 | this->Consumer = Consumer; |
| 4290 | |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4291 | if (!Consumer) |
| 4292 | return; |
| 4293 | |
| 4294 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4295 | // Force deserialization of this decl, which will cause it to be queued for |
| 4296 | // passing to the consumer. |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4297 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4298 | } |
Douglas Gregor | f005eac | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4299 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4300 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4301 | } |
| 4302 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4303 | void ASTReader::PrintStats() { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4304 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4305 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4306 | unsigned NumTypesLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4307 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4308 | QualType()); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4309 | unsigned NumDeclsLoaded |
| 4310 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4311 | (Decl *)0); |
| 4312 | unsigned NumIdentifiersLoaded |
| 4313 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4314 | IdentifiersLoaded.end(), |
| 4315 | (IdentifierInfo *)0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4316 | unsigned NumSelectorsLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4317 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4318 | SelectorsLoaded.end(), |
| 4319 | Selector()); |
Douglas Gregor | c3b1dd1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4320 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4321 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4322 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4323 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4324 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4325 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4326 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4327 | if (!TypesLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4328 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4329 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4330 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4331 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4332 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4333 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4334 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4335 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4336 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4337 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4338 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4339 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4340 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4341 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4342 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4343 | if (TotalNumStatements) |
| 4344 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4345 | NumStatementsRead, TotalNumStatements, |
| 4346 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4347 | if (TotalNumMacros) |
| 4348 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4349 | NumMacrosRead, TotalNumMacros, |
| 4350 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4351 | if (TotalLexicalDeclContexts) |
| 4352 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4353 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4354 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4355 | * 100)); |
| 4356 | if (TotalVisibleDeclContexts) |
| 4357 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4358 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4359 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4360 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4361 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4362 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4363 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4364 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4365 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4366 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4367 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4368 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4369 | dump(); |
| 4370 | std::fprintf(stderr, "\n"); |
| 4371 | } |
| 4372 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4373 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4374 | static void |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4375 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4376 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4377 | InitialCapacity> &Map) { |
| 4378 | if (Map.begin() == Map.end()) |
| 4379 | return; |
| 4380 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4381 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4382 | llvm::errs() << Name << ":\n"; |
| 4383 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4384 | I != IEnd; ++I) { |
| 4385 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4386 | << "\n"; |
| 4387 | } |
| 4388 | } |
| 4389 | |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4390 | void ASTReader::dump() { |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4391 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4392 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4393 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4394 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4395 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4396 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4397 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 4398 | dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); |
| 4399 | dumpModuleIDMap("Global preprocessed entity map", |
| 4400 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4401 | |
| 4402 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4403 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4404 | MEnd = ModuleMgr.end(); |
| 4405 | M != MEnd; ++M) |
| 4406 | (*M)->dump(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4409 | /// Return the amount of memory used by memory buffers, breaking down |
| 4410 | /// by heap-backed versus mmap'ed memory. |
| 4411 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4412 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4413 | E = ModuleMgr.end(); I != E; ++I) { |
| 4414 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4415 | size_t bytes = buf->getBufferSize(); |
| 4416 | switch (buf->getBufferKind()) { |
| 4417 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4418 | sizes.malloc_bytes += bytes; |
| 4419 | break; |
| 4420 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4421 | sizes.mmap_bytes += bytes; |
| 4422 | break; |
| 4423 | } |
| 4424 | } |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4425 | } |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4428 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4429 | SemaObj = &S; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4430 | S.ExternalSource = this; |
| 4431 | |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4432 | // Makes sure any declarations that were deserialized "too early" |
| 4433 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4434 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4435 | if (SemaObj->TUScope) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4436 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4437 | |
| 4438 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4439 | } |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4440 | PreloadedDecls.clear(); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4441 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4442 | // Load the offsets of the declarations that Sema references. |
| 4443 | // They will be lazily deserialized when needed. |
| 4444 | if (!SemaDeclRefs.empty()) { |
| 4445 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | b0f3ae6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4446 | if (!SemaObj->StdNamespace) |
| 4447 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4448 | if (!SemaObj->StdBadAlloc) |
| 4449 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4450 | } |
| 4451 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4452 | if (!FPPragmaOptions.empty()) { |
| 4453 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4454 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4455 | } |
| 4456 | |
| 4457 | if (!OpenCLExtensions.empty()) { |
| 4458 | unsigned I = 0; |
| 4459 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4460 | #include "clang/Basic/OpenCLExtensions.def" |
| 4461 | |
| 4462 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4463 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4464 | } |
| 4465 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4466 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4467 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4468 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4469 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4470 | } |
| 4471 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4472 | namespace clang { |
| 4473 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4474 | /// identifiers stored within a set of AST files. |
| 4475 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4476 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4477 | const ASTReader &Reader; |
| 4478 | |
| 4479 | /// \brief The current index into the chain of AST files stored in |
| 4480 | /// the AST reader. |
| 4481 | unsigned Index; |
| 4482 | |
| 4483 | /// \brief The current position within the identifier lookup table |
| 4484 | /// of the current AST file. |
| 4485 | ASTIdentifierLookupTable::key_iterator Current; |
| 4486 | |
| 4487 | /// \brief The end position within the identifier lookup table of |
| 4488 | /// the current AST file. |
| 4489 | ASTIdentifierLookupTable::key_iterator End; |
| 4490 | |
| 4491 | public: |
| 4492 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4493 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4494 | virtual StringRef Next(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4495 | }; |
| 4496 | } |
| 4497 | |
| 4498 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4499 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4500 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4501 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4502 | Current = IdTable->key_begin(); |
| 4503 | End = IdTable->key_end(); |
| 4504 | } |
| 4505 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4506 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4507 | while (Current == End) { |
| 4508 | // If we have exhausted all of our AST files, we're done. |
| 4509 | if (Index == 0) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4510 | return StringRef(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4511 | |
| 4512 | --Index; |
| 4513 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4514 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4515 | IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4516 | Current = IdTable->key_begin(); |
| 4517 | End = IdTable->key_end(); |
| 4518 | } |
| 4519 | |
| 4520 | // We have any identifiers remaining in the current AST file; return |
| 4521 | // the next one. |
| 4522 | std::pair<const char*, unsigned> Key = *Current; |
| 4523 | ++Current; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4524 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4525 | } |
| 4526 | |
| 4527 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4528 | return new ASTIdentifierIterator(*this); |
| 4529 | } |
| 4530 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4531 | namespace clang { namespace serialization { |
| 4532 | class ReadMethodPoolVisitor { |
| 4533 | ASTReader &Reader; |
| 4534 | Selector Sel; |
| 4535 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4536 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4537 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4538 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4539 | /// declarations. |
| 4540 | ObjCMethodList |
| 4541 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4542 | { |
| 4543 | ObjCMethodList List; |
| 4544 | ObjCMethodList *Prev = 0; |
| 4545 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4546 | if (!List.Method) { |
| 4547 | // This is the first method, which is the easy case. |
| 4548 | List.Method = Vec[I]; |
| 4549 | Prev = &List; |
| 4550 | continue; |
| 4551 | } |
| 4552 | |
| 4553 | ObjCMethodList *Mem = |
| 4554 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4555 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4556 | Prev = Prev->Next; |
| 4557 | } |
| 4558 | |
| 4559 | return List; |
| 4560 | } |
| 4561 | |
| 4562 | public: |
| 4563 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4564 | : Reader(Reader), Sel(Sel) { } |
| 4565 | |
| 4566 | static bool visit(Module &M, void *UserData) { |
| 4567 | ReadMethodPoolVisitor *This |
| 4568 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4569 | |
| 4570 | if (!M.SelectorLookupTable) |
| 4571 | return false; |
| 4572 | |
| 4573 | ASTSelectorLookupTable *PoolTable |
| 4574 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4575 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4576 | if (Pos == PoolTable->end()) |
| 4577 | return false; |
| 4578 | |
| 4579 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4580 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4581 | // disable this tracking when called via LoadSelector. |
| 4582 | // Also, should entries without methods count as misses? |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4583 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4584 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4585 | if (This->Reader.DeserializationListener) |
| 4586 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4587 | This->Sel); |
| 4588 | |
| 4589 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4590 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4591 | return true; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4592 | } |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4593 | |
| 4594 | /// \brief Retrieve the instance methods found by this visitor. |
| 4595 | ObjCMethodList getInstanceMethods() const { |
| 4596 | return buildObjCMethodList(InstanceMethods); |
| 4597 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4598 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4599 | /// \brief Retrieve the instance methods found by this visitor. |
| 4600 | ObjCMethodList getFactoryMethods() const { |
| 4601 | return buildObjCMethodList(FactoryMethods); |
| 4602 | } |
| 4603 | }; |
| 4604 | } } // end namespace clang::serialization |
| 4605 | |
| 4606 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4607 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4608 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4609 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4610 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4611 | Result.first = Visitor.getInstanceMethods(); |
| 4612 | Result.second = Visitor.getFactoryMethods(); |
| 4613 | |
| 4614 | if (!Result.first.Method && !Result.second.Method) |
| 4615 | ++NumMethodPoolMisses; |
| 4616 | return Result; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4617 | } |
| 4618 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4619 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4620 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4621 | Namespaces.clear(); |
| 4622 | |
| 4623 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4624 | if (NamespaceDecl *Namespace |
| 4625 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4626 | Namespaces.push_back(Namespace); |
| 4627 | } |
| 4628 | } |
| 4629 | |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4630 | void ASTReader::ReadTentativeDefinitions( |
| 4631 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4632 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4633 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4634 | if (Var) |
| 4635 | TentativeDefs.push_back(Var); |
| 4636 | } |
| 4637 | TentativeDefinitions.clear(); |
| 4638 | } |
| 4639 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4640 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4641 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4642 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4643 | DeclaratorDecl *D |
| 4644 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4645 | if (D) |
| 4646 | Decls.push_back(D); |
| 4647 | } |
| 4648 | UnusedFileScopedDecls.clear(); |
| 4649 | } |
| 4650 | |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4651 | void ASTReader::ReadDelegatingConstructors( |
| 4652 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4653 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4654 | CXXConstructorDecl *D |
| 4655 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4656 | if (D) |
| 4657 | Decls.push_back(D); |
| 4658 | } |
| 4659 | DelegatingCtorDecls.clear(); |
| 4660 | } |
| 4661 | |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4662 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4663 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4664 | TypedefNameDecl *D |
| 4665 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4666 | if (D) |
| 4667 | Decls.push_back(D); |
| 4668 | } |
| 4669 | ExtVectorDecls.clear(); |
| 4670 | } |
| 4671 | |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4672 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4673 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4674 | CXXRecordDecl *D |
| 4675 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4676 | if (D) |
| 4677 | Decls.push_back(D); |
| 4678 | } |
| 4679 | DynamicClasses.clear(); |
| 4680 | } |
| 4681 | |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4682 | void |
| 4683 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4684 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4685 | NamedDecl *D |
| 4686 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4687 | if (D) |
| 4688 | Decls.push_back(D); |
| 4689 | } |
| 4690 | LocallyScopedExternalDecls.clear(); |
| 4691 | } |
| 4692 | |
Douglas Gregor | 72e357f | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4693 | void ASTReader::ReadReferencedSelectors( |
| 4694 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4695 | if (ReferencedSelectorsData.empty()) |
| 4696 | return; |
| 4697 | |
| 4698 | // If there are @selector references added them to its pool. This is for |
| 4699 | // implementation of -Wselector. |
| 4700 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4701 | unsigned I = 0; |
| 4702 | while (I < DataSize) { |
| 4703 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4704 | SourceLocation SelLoc |
| 4705 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4706 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4707 | } |
| 4708 | ReferencedSelectorsData.clear(); |
| 4709 | } |
| 4710 | |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4711 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4712 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4713 | if (WeakUndeclaredIdentifiers.empty()) |
| 4714 | return; |
| 4715 | |
| 4716 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4717 | IdentifierInfo *WeakId |
| 4718 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4719 | IdentifierInfo *AliasId |
| 4720 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4721 | SourceLocation Loc |
| 4722 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4723 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4724 | WeakInfo WI(AliasId, Loc); |
| 4725 | WI.setUsed(Used); |
| 4726 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4727 | } |
| 4728 | WeakUndeclaredIdentifiers.clear(); |
| 4729 | } |
| 4730 | |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4731 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4732 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4733 | ExternalVTableUse VT; |
| 4734 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4735 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4736 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4737 | VTables.push_back(VT); |
| 4738 | } |
| 4739 | |
| 4740 | VTableUses.clear(); |
| 4741 | } |
| 4742 | |
Douglas Gregor | e39f97c | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4743 | void ASTReader::ReadPendingInstantiations( |
| 4744 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4745 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4746 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4747 | SourceLocation Loc |
| 4748 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4749 | Pending.push_back(std::make_pair(D, Loc)); |
| 4750 | } |
| 4751 | PendingInstantiations.clear(); |
| 4752 | } |
| 4753 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4754 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4755 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4756 | ReadMethodPool(Sel); |
| 4757 | } |
| 4758 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4759 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4760 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4761 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4762 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4763 | if (DeserializationListener) |
| 4764 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4765 | } |
| 4766 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4767 | /// \brief Set the globally-visible declarations associated with the given |
| 4768 | /// identifier. |
| 4769 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4770 | /// 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] | 4771 | /// 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] | 4772 | /// them. |
| 4773 | /// |
| 4774 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4775 | /// declarations. |
| 4776 | /// |
| 4777 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4778 | /// visible at global scope. |
| 4779 | /// |
| 4780 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4781 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4782 | /// will not be placed onto the pending queue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4783 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4784 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4785 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4786 | bool Nonrecursive) { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4787 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4788 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4789 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4790 | PII.II = II; |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4791 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4792 | return; |
| 4793 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4794 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4795 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4796 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4797 | if (SemaObj) { |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4798 | if (SemaObj->TUScope) { |
| 4799 | // Introduce this declaration into the translation-unit scope |
| 4800 | // and add it to the declaration chain for this identifier, so |
| 4801 | // that (unqualified) name lookup will find it. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4802 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4803 | } |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4804 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4805 | } else { |
| 4806 | // Queue this declaration so that it will be added to the |
| 4807 | // translation unit scope and identifier's declaration chain |
| 4808 | // once a Sema object is known. |
| 4809 | PreloadedDecls.push_back(D); |
| 4810 | } |
| 4811 | } |
| 4812 | } |
| 4813 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4814 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4815 | if (ID == 0) |
| 4816 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4817 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4818 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4819 | Error("no identifier table in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4820 | return 0; |
| 4821 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4822 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4823 | ID -= 1; |
| 4824 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4825 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4826 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4827 | Module *M = I->second; |
| 4828 | unsigned Index = ID - M->BaseIdentifierID; |
| 4829 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4830 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4831 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4832 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | ca42a51 | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4833 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4834 | // unsigned integers. This is important to avoid integer overflow when |
| 4835 | // we cast them to 'unsigned'. |
Ted Kremenek | 49c5232 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4836 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4837 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4838 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4839 | IdentifiersLoaded[ID] |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 4840 | = &PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4841 | if (DeserializationListener) |
| 4842 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4843 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4844 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4845 | return IdentifiersLoaded[ID]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4846 | } |
| 4847 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4848 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4849 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4850 | } |
| 4851 | |
| 4852 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4853 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4854 | return LocalID; |
| 4855 | |
| 4856 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4857 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4858 | assert(I != M.IdentifierRemap.end() |
| 4859 | && "Invalid index into identifier index remap"); |
| 4860 | |
| 4861 | return LocalID + I->second; |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4862 | } |
| 4863 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4864 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 49f754f | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4865 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4866 | } |
| 4867 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4868 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4869 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4870 | } |
| 4871 | |
| 4872 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4873 | if (ID == 0) |
| 4874 | return Selector(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4875 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4876 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4877 | Error("selector ID out of range in AST file"); |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4878 | return Selector(); |
| 4879 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4880 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4881 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4882 | // Load this selector from the selector table. |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4883 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 4884 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4885 | Module &M = *I->second; |
| 4886 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4887 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4888 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4889 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4890 | if (DeserializationListener) |
| 4891 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4892 | } |
| 4893 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4894 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4897 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4898 | return DecodeSelector(ID); |
| 4899 | } |
| 4900 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4901 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4902 | // ID 0 (the null selector) is considered an external selector. |
| 4903 | return getTotalNumSelectors() + 1; |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4904 | } |
| 4905 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4906 | serialization::SelectorID |
| 4907 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 4908 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 4909 | return LocalID; |
| 4910 | |
| 4911 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4912 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 4913 | assert(I != M.SelectorRemap.end() |
| 4914 | && "Invalid index into identifier index remap"); |
| 4915 | |
| 4916 | return LocalID + I->second; |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4917 | } |
| 4918 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4919 | DeclarationName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4920 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4921 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4922 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4923 | switch (Kind) { |
| 4924 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4925 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4926 | |
| 4927 | case DeclarationName::ObjCZeroArgSelector: |
| 4928 | case DeclarationName::ObjCOneArgSelector: |
| 4929 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4930 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4931 | |
| 4932 | case DeclarationName::CXXConstructorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4933 | return Context.DeclarationNames.getCXXConstructorName( |
| 4934 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4935 | |
| 4936 | case DeclarationName::CXXDestructorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4937 | return Context.DeclarationNames.getCXXDestructorName( |
| 4938 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4939 | |
| 4940 | case DeclarationName::CXXConversionFunctionName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4941 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 4942 | Context.getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4943 | |
| 4944 | case DeclarationName::CXXOperatorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4945 | return Context.DeclarationNames.getCXXOperatorName( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4946 | (OverloadedOperatorKind)Record[Idx++]); |
| 4947 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4948 | case DeclarationName::CXXLiteralOperatorName: |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 4949 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4950 | GetIdentifierInfo(F, Record, Idx)); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4951 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4952 | case DeclarationName::CXXUsingDirective: |
| 4953 | return DeclarationName::getUsingDirectiveName(); |
| 4954 | } |
| 4955 | |
| 4956 | // Required to silence GCC warning |
| 4957 | return DeclarationName(); |
| 4958 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 4959 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4960 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4961 | DeclarationNameLoc &DNLoc, |
| 4962 | DeclarationName Name, |
| 4963 | const RecordData &Record, unsigned &Idx) { |
| 4964 | switch (Name.getNameKind()) { |
| 4965 | case DeclarationName::CXXConstructorName: |
| 4966 | case DeclarationName::CXXDestructorName: |
| 4967 | case DeclarationName::CXXConversionFunctionName: |
| 4968 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 4969 | break; |
| 4970 | |
| 4971 | case DeclarationName::CXXOperatorName: |
| 4972 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 4973 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4974 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 4975 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4976 | break; |
| 4977 | |
| 4978 | case DeclarationName::CXXLiteralOperatorName: |
| 4979 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 4980 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 4981 | break; |
| 4982 | |
| 4983 | case DeclarationName::Identifier: |
| 4984 | case DeclarationName::ObjCZeroArgSelector: |
| 4985 | case DeclarationName::ObjCOneArgSelector: |
| 4986 | case DeclarationName::ObjCMultiArgSelector: |
| 4987 | case DeclarationName::CXXUsingDirective: |
| 4988 | break; |
| 4989 | } |
| 4990 | } |
| 4991 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4992 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4993 | DeclarationNameInfo &NameInfo, |
| 4994 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4995 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 4996 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 4997 | DeclarationNameLoc DNLoc; |
| 4998 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 4999 | NameInfo.setInfo(DNLoc); |
| 5000 | } |
| 5001 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5002 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5003 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5004 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5005 | unsigned NumTPLists = Record[Idx++]; |
| 5006 | Info.NumTemplParamLists = NumTPLists; |
| 5007 | if (NumTPLists) { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5008 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5009 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5010 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5011 | } |
| 5012 | } |
| 5013 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5014 | TemplateName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5015 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5016 | unsigned &Idx) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5017 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5018 | switch (Kind) { |
| 5019 | case TemplateName::Template: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5020 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5021 | |
| 5022 | case TemplateName::OverloadedTemplate: { |
| 5023 | unsigned size = Record[Idx++]; |
| 5024 | UnresolvedSet<8> Decls; |
| 5025 | while (size--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5026 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5027 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5028 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5029 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5030 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5031 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5032 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5033 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5034 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5035 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5036 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5037 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5038 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5039 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5040 | if (Record[Idx++]) // isIdentifier |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5041 | return Context.getDependentTemplateName(NNS, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5042 | GetIdentifierInfo(F, Record, |
| 5043 | Idx)); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5044 | return Context.getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5045 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5046 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5047 | |
| 5048 | case TemplateName::SubstTemplateTemplateParm: { |
| 5049 | TemplateTemplateParmDecl *param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5050 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5051 | if (!param) return TemplateName(); |
| 5052 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5053 | return Context.getSubstTemplateTemplateParm(param, replacement); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5054 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5055 | |
| 5056 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5057 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5058 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5059 | if (!Param) |
| 5060 | return TemplateName(); |
| 5061 | |
| 5062 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5063 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5064 | return TemplateName(); |
| 5065 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5066 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5067 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5068 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5069 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5070 | assert(0 && "Unhandled template name kind!"); |
| 5071 | return TemplateName(); |
| 5072 | } |
| 5073 | |
| 5074 | TemplateArgument |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5075 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5076 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5077 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5078 | switch (Kind) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5079 | case TemplateArgument::Null: |
| 5080 | return TemplateArgument(); |
| 5081 | case TemplateArgument::Type: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5082 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5083 | case TemplateArgument::Declaration: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5084 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5085 | case TemplateArgument::Integral: { |
| 5086 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5087 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5088 | return TemplateArgument(Value, T); |
| 5089 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5090 | case TemplateArgument::Template: |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5091 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5092 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5093 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5094 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5095 | if (unsigned NumExpansions = Record[Idx++]) |
| 5096 | NumTemplateExpansions = NumExpansions - 1; |
| 5097 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5098 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5099 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5100 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5101 | case TemplateArgument::Pack: { |
| 5102 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5103 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5104 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5105 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5106 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5107 | } |
| 5108 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5109 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5110 | assert(0 && "Unhandled template argument kind!"); |
| 5111 | return TemplateArgument(); |
| 5112 | } |
| 5113 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5114 | TemplateParameterList * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5115 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5116 | const RecordData &Record, unsigned &Idx) { |
| 5117 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5118 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5119 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5120 | |
| 5121 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5122 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5123 | Params.reserve(NumParams); |
| 5124 | while (NumParams--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5125 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5126 | |
| 5127 | TemplateParameterList* TemplateParams = |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5128 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5129 | Params.data(), Params.size(), RAngleLoc); |
| 5130 | return TemplateParams; |
| 5131 | } |
| 5132 | |
| 5133 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5134 | ASTReader:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5135 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5136 | Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5137 | unsigned &Idx) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5138 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5139 | TemplArgs.reserve(NumTemplateArgs); |
| 5140 | while (NumTemplateArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5141 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5142 | } |
| 5143 | |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5144 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5145 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5146 | const RecordData &Record, unsigned &Idx) { |
| 5147 | unsigned NumDecls = Record[Idx++]; |
| 5148 | while (NumDecls--) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5149 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5150 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5151 | Set.addDecl(D, AS); |
| 5152 | } |
| 5153 | } |
| 5154 | |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5155 | CXXBaseSpecifier |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5156 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5157 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5158 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5159 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5160 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5161 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5162 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5163 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5164 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5165 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5166 | EllipsisLoc); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5167 | Result.setInheritConstructors(inheritConstructors); |
| 5168 | return Result; |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5169 | } |
| 5170 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5171 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5172 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5173 | unsigned &Idx) { |
| 5174 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5175 | unsigned NumInitializers = Record[Idx++]; |
| 5176 | if (NumInitializers) { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5177 | CtorInitializers |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5178 | = new (Context) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5179 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5180 | TypeSourceInfo *BaseClassInfo = 0; |
| 5181 | bool IsBaseVirtual = false; |
| 5182 | FieldDecl *Member = 0; |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5183 | IndirectFieldDecl *IndirectMember = 0; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5184 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5185 | |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5186 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5187 | switch (Type) { |
| 5188 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5189 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5190 | IsBaseVirtual = Record[Idx++]; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5191 | break; |
| 5192 | |
| 5193 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5194 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5195 | break; |
| 5196 | |
| 5197 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5198 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5199 | break; |
| 5200 | |
| 5201 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5202 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5203 | break; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5204 | } |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5205 | |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5206 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5207 | Expr *Init = ReadExpr(F); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5208 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5209 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5210 | bool IsWritten = Record[Idx++]; |
| 5211 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5212 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5213 | if (IsWritten) { |
| 5214 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5215 | } else { |
| 5216 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5217 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5218 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5219 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5220 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5221 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5222 | CXXCtorInitializer *BOMInit; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5223 | if (Type == CTOR_INITIALIZER_BASE) { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5224 | BOMInit = new (Context) CXXCtorInitializer(Context, BaseClassInfo, IsBaseVirtual, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5225 | LParenLoc, Init, RParenLoc, |
| 5226 | MemberOrEllipsisLoc); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5227 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5228 | BOMInit = new (Context) CXXCtorInitializer(Context, MemberOrEllipsisLoc, LParenLoc, |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5229 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5230 | } else if (IsWritten) { |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5231 | if (Member) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5232 | BOMInit = new (Context) CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5233 | LParenLoc, Init, RParenLoc); |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5234 | else |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5235 | BOMInit = new (Context) CXXCtorInitializer(Context, IndirectMember, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5236 | MemberOrEllipsisLoc, LParenLoc, |
| 5237 | Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5238 | } else { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5239 | BOMInit = CXXCtorInitializer::Create(Context, Member, MemberOrEllipsisLoc, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5240 | LParenLoc, Init, RParenLoc, |
| 5241 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5244 | if (IsWritten) |
| 5245 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5246 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5247 | } |
| 5248 | } |
| 5249 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5250 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5251 | } |
| 5252 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5253 | NestedNameSpecifier * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5254 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5255 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5256 | unsigned N = Record[Idx++]; |
| 5257 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5258 | for (unsigned I = 0; I != N; ++I) { |
| 5259 | NestedNameSpecifier::SpecifierKind Kind |
| 5260 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5261 | switch (Kind) { |
| 5262 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5263 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5264 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5265 | break; |
| 5266 | } |
| 5267 | |
| 5268 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5269 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5270 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5271 | break; |
| 5272 | } |
| 5273 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5274 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5275 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5276 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5277 | break; |
| 5278 | } |
| 5279 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5280 | case NestedNameSpecifier::TypeSpec: |
| 5281 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5282 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5283 | if (!T) |
| 5284 | return 0; |
| 5285 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5286 | bool Template = Record[Idx++]; |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5287 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5288 | break; |
| 5289 | } |
| 5290 | |
| 5291 | case NestedNameSpecifier::Global: { |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5292 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5293 | // No associated value, and there can't be a prefix. |
| 5294 | break; |
| 5295 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5296 | } |
Argyrios Kyrtzidis | ad65c69 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5297 | Prev = NNS; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5298 | } |
| 5299 | return NNS; |
| 5300 | } |
| 5301 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5302 | NestedNameSpecifierLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5303 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5304 | unsigned &Idx) { |
| 5305 | unsigned N = Record[Idx++]; |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5306 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5307 | for (unsigned I = 0; I != N; ++I) { |
| 5308 | NestedNameSpecifier::SpecifierKind Kind |
| 5309 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5310 | switch (Kind) { |
| 5311 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5312 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5313 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5314 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5315 | break; |
| 5316 | } |
| 5317 | |
| 5318 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5319 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5320 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5321 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5322 | break; |
| 5323 | } |
| 5324 | |
| 5325 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5326 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5327 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5328 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5329 | break; |
| 5330 | } |
| 5331 | |
| 5332 | case NestedNameSpecifier::TypeSpec: |
| 5333 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5334 | bool Template = Record[Idx++]; |
| 5335 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5336 | if (!T) |
| 5337 | return NestedNameSpecifierLoc(); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5338 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5339 | |
| 5340 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5341 | Builder.Extend(Context, |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5342 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5343 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5344 | break; |
| 5345 | } |
| 5346 | |
| 5347 | case NestedNameSpecifier::Global: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5348 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5349 | Builder.MakeGlobal(Context, ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5350 | break; |
| 5351 | } |
| 5352 | } |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5355 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5356 | } |
| 5357 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5358 | SourceRange |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5359 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5360 | unsigned &Idx) { |
| 5361 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5362 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 6d3bc08 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5363 | return SourceRange(beg, end); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5364 | } |
| 5365 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5366 | /// \brief Read an integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5367 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5368 | unsigned BitWidth = Record[Idx++]; |
| 5369 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5370 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5371 | Idx += NumWords; |
| 5372 | return Result; |
| 5373 | } |
| 5374 | |
| 5375 | /// \brief Read a signed integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5376 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5377 | bool isUnsigned = Record[Idx++]; |
| 5378 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5379 | } |
| 5380 | |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5381 | /// \brief Read a floating-point value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5382 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5383 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5384 | } |
| 5385 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5386 | // \brief Read a string |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5387 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5388 | unsigned Len = Record[Idx++]; |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5389 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5390 | Idx += Len; |
| 5391 | return Result; |
| 5392 | } |
| 5393 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5394 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5395 | unsigned &Idx) { |
| 5396 | unsigned Major = Record[Idx++]; |
| 5397 | unsigned Minor = Record[Idx++]; |
| 5398 | unsigned Subminor = Record[Idx++]; |
| 5399 | if (Minor == 0) |
| 5400 | return VersionTuple(Major); |
| 5401 | if (Subminor == 0) |
| 5402 | return VersionTuple(Major, Minor - 1); |
| 5403 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5404 | } |
| 5405 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5406 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5407 | const RecordData &Record, |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5408 | unsigned &Idx) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5409 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 5410 | return CXXTemporary::Create(Context, Decl); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5411 | } |
| 5412 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5413 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5414 | return Diag(SourceLocation(), DiagID); |
| 5415 | } |
| 5416 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5417 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5418 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5419 | } |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5420 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5421 | /// \brief Retrieve the identifier table associated with the |
| 5422 | /// preprocessor. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5423 | IdentifierTable &ASTReader::getIdentifierTable() { |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5424 | return PP.getIdentifierTable(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5425 | } |
| 5426 | |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5427 | /// \brief Record that the given ID maps to the given switch-case |
| 5428 | /// statement. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5429 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5430 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5431 | SwitchCaseStmts[ID] = SC; |
| 5432 | } |
| 5433 | |
| 5434 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5435 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5436 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5437 | return SwitchCaseStmts[ID]; |
| 5438 | } |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5439 | |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5440 | void ASTReader::ClearSwitchCaseIDs() { |
| 5441 | SwitchCaseStmts.clear(); |
| 5442 | } |
| 5443 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5444 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5445 | assert(NumCurrentElementsDeserializing && |
| 5446 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5447 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5448 | // If any identifiers with corresponding top-level declarations have |
| 5449 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5450 | while (!PendingIdentifierInfos.empty()) { |
| 5451 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5452 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5453 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5454 | } |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5455 | |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5456 | // Ready to load previous declarations of Decls that were delayed. |
| 5457 | while (!PendingPreviousDecls.empty()) { |
| 5458 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5459 | PendingPreviousDecls.front().second); |
| 5460 | PendingPreviousDecls.pop_front(); |
| 5461 | } |
| 5462 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5463 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5464 | // decls to the consumer. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5465 | if (Consumer) |
| 5466 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | ad5f95c | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5467 | |
| 5468 | assert(PendingForwardRefs.size() == 0 && |
| 5469 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5470 | } |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5471 | --NumCurrentElementsDeserializing; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5472 | } |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5473 | |
Douglas Gregor | 8835e03 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 5474 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5475 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5476 | bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5477 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5478 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 51825b4 | 2011-09-09 22:02:16 +0000 | [diff] [blame] | 5479 | Diags(PP.getDiagnostics()), SemaObj(0), PP(PP), Context(Context), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5480 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5481 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5482 | DisableValidation(DisableValidation), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5483 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5484 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5485 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5486 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5487 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5488 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5489 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5490 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5491 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5492 | { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5493 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5494 | } |
| 5495 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5496 | ASTReader::~ASTReader() { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5497 | for (DeclContextVisibleUpdatesPending::iterator |
| 5498 | I = PendingVisibleUpdates.begin(), |
| 5499 | E = PendingVisibleUpdates.end(); |
| 5500 | I != E; ++I) { |
| 5501 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5502 | F = I->second.end(); |
| 5503 | J != F; ++J) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5504 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5505 | } |
| 5506 | } |