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; |
| 501 | SelectorTable &SelTable = Reader.getContext()->Selectors; |
| 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. |
| 635 | if (Reader.getContext() == 0) return II; |
| 636 | if (DataLen > 0) { |
| 637 | SmallVector<uint32_t, 4> DeclIDs; |
| 638 | for (; DataLen > 0; DataLen -= 4) |
| 639 | DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d))); |
| 640 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 643 | II->setIsFromAST(); |
| 644 | return II; |
| 645 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 646 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 647 | unsigned |
| 648 | ASTDeclContextNameLookupTrait::ComputeHash(const DeclNameKey &Key) const { |
| 649 | llvm::FoldingSetNodeID ID; |
| 650 | ID.AddInteger(Key.Kind); |
| 651 | |
| 652 | switch (Key.Kind) { |
| 653 | case DeclarationName::Identifier: |
| 654 | case DeclarationName::CXXLiteralOperatorName: |
| 655 | ID.AddString(((IdentifierInfo*)Key.Data)->getName()); |
| 656 | break; |
| 657 | case DeclarationName::ObjCZeroArgSelector: |
| 658 | case DeclarationName::ObjCOneArgSelector: |
| 659 | case DeclarationName::ObjCMultiArgSelector: |
| 660 | ID.AddInteger(serialization::ComputeHash(Selector(Key.Data))); |
| 661 | break; |
| 662 | case DeclarationName::CXXOperatorName: |
| 663 | ID.AddInteger((OverloadedOperatorKind)Key.Data); |
| 664 | break; |
| 665 | case DeclarationName::CXXConstructorName: |
| 666 | case DeclarationName::CXXDestructorName: |
| 667 | case DeclarationName::CXXConversionFunctionName: |
| 668 | case DeclarationName::CXXUsingDirective: |
| 669 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 672 | return ID.ComputeHash(); |
| 673 | } |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 674 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 675 | ASTDeclContextNameLookupTrait::internal_key_type |
| 676 | ASTDeclContextNameLookupTrait::GetInternalKey( |
| 677 | const external_key_type& Name) const { |
| 678 | DeclNameKey Key; |
| 679 | Key.Kind = Name.getNameKind(); |
| 680 | switch (Name.getNameKind()) { |
| 681 | case DeclarationName::Identifier: |
| 682 | Key.Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 683 | break; |
| 684 | case DeclarationName::ObjCZeroArgSelector: |
| 685 | case DeclarationName::ObjCOneArgSelector: |
| 686 | case DeclarationName::ObjCMultiArgSelector: |
| 687 | Key.Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 688 | break; |
| 689 | case DeclarationName::CXXOperatorName: |
| 690 | Key.Data = Name.getCXXOverloadedOperator(); |
| 691 | break; |
| 692 | case DeclarationName::CXXLiteralOperatorName: |
| 693 | Key.Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 694 | break; |
| 695 | case DeclarationName::CXXConstructorName: |
| 696 | case DeclarationName::CXXDestructorName: |
| 697 | case DeclarationName::CXXConversionFunctionName: |
| 698 | case DeclarationName::CXXUsingDirective: |
| 699 | Key.Data = 0; |
| 700 | break; |
Argyrios Kyrtzidis | d32ee89 | 2010-08-20 23:35:55 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 703 | return Key; |
| 704 | } |
| 705 | |
| 706 | ASTDeclContextNameLookupTrait::external_key_type |
| 707 | ASTDeclContextNameLookupTrait::GetExternalKey( |
| 708 | const internal_key_type& Key) const { |
| 709 | ASTContext *Context = Reader.getContext(); |
| 710 | switch (Key.Kind) { |
| 711 | case DeclarationName::Identifier: |
| 712 | return DeclarationName((IdentifierInfo*)Key.Data); |
| 713 | |
| 714 | case DeclarationName::ObjCZeroArgSelector: |
| 715 | case DeclarationName::ObjCOneArgSelector: |
| 716 | case DeclarationName::ObjCMultiArgSelector: |
| 717 | return DeclarationName(Selector(Key.Data)); |
| 718 | |
| 719 | case DeclarationName::CXXConstructorName: |
| 720 | return Context->DeclarationNames.getCXXConstructorName( |
| 721 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
| 722 | |
| 723 | case DeclarationName::CXXDestructorName: |
| 724 | return Context->DeclarationNames.getCXXDestructorName( |
| 725 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
| 726 | |
| 727 | case DeclarationName::CXXConversionFunctionName: |
| 728 | return Context->DeclarationNames.getCXXConversionFunctionName( |
| 729 | Context->getCanonicalType(Reader.getLocalType(F, Key.Data))); |
| 730 | |
| 731 | case DeclarationName::CXXOperatorName: |
| 732 | return Context->DeclarationNames.getCXXOperatorName( |
| 733 | (OverloadedOperatorKind)Key.Data); |
| 734 | |
| 735 | case DeclarationName::CXXLiteralOperatorName: |
| 736 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
| 737 | (IdentifierInfo*)Key.Data); |
| 738 | |
| 739 | case DeclarationName::CXXUsingDirective: |
| 740 | return DeclarationName::getUsingDirectiveName(); |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 743 | llvm_unreachable("Invalid Name Kind ?"); |
| 744 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 745 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 746 | std::pair<unsigned, unsigned> |
| 747 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 748 | using namespace clang::io; |
| 749 | unsigned KeyLen = ReadUnalignedLE16(d); |
| 750 | unsigned DataLen = ReadUnalignedLE16(d); |
| 751 | return std::make_pair(KeyLen, DataLen); |
| 752 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 753 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 754 | ASTDeclContextNameLookupTrait::internal_key_type |
| 755 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 756 | using namespace clang::io; |
| 757 | |
| 758 | DeclNameKey Key; |
| 759 | Key.Kind = (DeclarationName::NameKind)*d++; |
| 760 | switch (Key.Kind) { |
| 761 | case DeclarationName::Identifier: |
| 762 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 763 | break; |
| 764 | case DeclarationName::ObjCZeroArgSelector: |
| 765 | case DeclarationName::ObjCOneArgSelector: |
| 766 | case DeclarationName::ObjCMultiArgSelector: |
| 767 | Key.Data = |
| 768 | (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d)) |
| 769 | .getAsOpaquePtr(); |
| 770 | break; |
| 771 | case DeclarationName::CXXOperatorName: |
| 772 | Key.Data = *d++; // OverloadedOperatorKind |
| 773 | break; |
| 774 | case DeclarationName::CXXLiteralOperatorName: |
| 775 | Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)); |
| 776 | break; |
| 777 | case DeclarationName::CXXConstructorName: |
| 778 | case DeclarationName::CXXDestructorName: |
| 779 | case DeclarationName::CXXConversionFunctionName: |
| 780 | case DeclarationName::CXXUsingDirective: |
| 781 | Key.Data = 0; |
| 782 | break; |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 785 | return Key; |
| 786 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 787 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 788 | ASTDeclContextNameLookupTrait::data_type |
| 789 | ASTDeclContextNameLookupTrait::ReadData(internal_key_type, |
| 790 | const unsigned char* d, |
| 791 | unsigned DataLen) { |
| 792 | using namespace clang::io; |
| 793 | unsigned NumDecls = ReadUnalignedLE16(d); |
| 794 | DeclID *Start = (DeclID *)d; |
| 795 | return std::make_pair(Start, Start + NumDecls); |
| 796 | } |
Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 797 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 798 | bool ASTReader::ReadDeclContextStorage(Module &M, |
| 799 | llvm::BitstreamCursor &Cursor, |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 800 | const std::pair<uint64_t, uint64_t> &Offsets, |
| 801 | DeclContextInfo &Info) { |
| 802 | SavedStreamPosition SavedPosition(Cursor); |
| 803 | // First the lexical decls. |
| 804 | if (Offsets.first != 0) { |
| 805 | Cursor.JumpToBit(Offsets.first); |
| 806 | |
| 807 | RecordData Record; |
| 808 | const char *Blob; |
| 809 | unsigned BlobLen; |
| 810 | unsigned Code = Cursor.ReadCode(); |
| 811 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 812 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 813 | Error("Expected lexical block"); |
| 814 | return true; |
| 815 | } |
| 816 | |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 817 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair*>(Blob); |
| 818 | Info.NumLexicalDecls = BlobLen / sizeof(KindDeclIDPair); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | // Now the lookup table. |
| 822 | if (Offsets.second != 0) { |
| 823 | Cursor.JumpToBit(Offsets.second); |
| 824 | |
| 825 | RecordData Record; |
| 826 | const char *Blob; |
| 827 | unsigned BlobLen; |
| 828 | unsigned Code = Cursor.ReadCode(); |
| 829 | unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen); |
| 830 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 831 | Error("Expected visible lookup table block"); |
| 832 | return true; |
| 833 | } |
| 834 | Info.NameLookupTableData |
| 835 | = ASTDeclContextNameLookupTable::Create( |
| 836 | (const unsigned char *)Blob + Record[0], |
| 837 | (const unsigned char *)Blob, |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 838 | ASTDeclContextNameLookupTrait(*this, M)); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return false; |
| 842 | } |
| 843 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 844 | void ASTReader::Error(StringRef Msg) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 845 | Error(diag::err_fe_pch_malformed, Msg); |
| 846 | } |
| 847 | |
| 848 | void ASTReader::Error(unsigned DiagID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 849 | StringRef Arg1, StringRef Arg2) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 850 | if (Diags.isDiagnosticInFlight()) |
| 851 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 852 | else |
| 853 | Diag(DiagID) << Arg1 << Arg2; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 856 | /// \brief Tell the AST listener about the predefines buffers in the chain. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 857 | bool ASTReader::CheckPredefinesBuffers() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 858 | if (Listener) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 859 | return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 860 | ActualOriginalFileName, |
Nick Lewycky | 3607989 | 2011-02-23 21:16:44 +0000 | [diff] [blame] | 861 | SuggestedPredefines, |
| 862 | FileMgr); |
Douglas Gregor | c379c07 | 2009-04-28 18:58:38 +0000 | [diff] [blame] | 863 | return false; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 864 | } |
| 865 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 866 | //===----------------------------------------------------------------------===// |
| 867 | // Source Manager Deserialization |
| 868 | //===----------------------------------------------------------------------===// |
| 869 | |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 870 | /// \brief Read the line table in the source manager block. |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 871 | /// \returns true if there was an error. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 872 | bool ASTReader::ParseLineTable(Module &F, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 873 | SmallVectorImpl<uint64_t> &Record) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 874 | unsigned Idx = 0; |
| 875 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 876 | |
| 877 | // Parse the file names |
Douglas Gregor | a885465 | 2009-04-13 17:12:42 +0000 | [diff] [blame] | 878 | std::map<int, int> FileIDs; |
| 879 | for (int I = 0, N = Record[Idx++]; I != N; ++I) { |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 880 | // Extract the file name |
| 881 | unsigned FilenameLen = Record[Idx++]; |
| 882 | std::string Filename(&Record[Idx], &Record[Idx] + FilenameLen); |
| 883 | Idx += FilenameLen; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 884 | MaybeAddSystemRootToFilename(Filename); |
Jay Foad | 9a6b098 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 885 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | // Parse the line entries |
| 889 | std::vector<LineEntry> Entries; |
| 890 | while (Idx < Record.size()) { |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 891 | int FID = Record[Idx++]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 892 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 893 | // Remap FileID from 1-based old view. |
| 894 | FID += F.SLocEntryBaseID - 1; |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 895 | |
| 896 | // Extract the line entries |
| 897 | unsigned NumEntries = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 898 | assert(NumEntries && "Numentries is 00000"); |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 899 | Entries.clear(); |
| 900 | Entries.reserve(NumEntries); |
| 901 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 902 | unsigned FileOffset = Record[Idx++]; |
| 903 | unsigned LineNo = Record[Idx++]; |
Argyrios Kyrtzidis | e3029a7 | 2010-07-02 11:55:05 +0000 | [diff] [blame] | 904 | int FilenameID = FileIDs[Record[Idx++]]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 905 | SrcMgr::CharacteristicKind FileKind |
Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 906 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 907 | unsigned IncludeOffset = Record[Idx++]; |
| 908 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 909 | FileKind, IncludeOffset)); |
| 910 | } |
| 911 | LineTable.AddEntry(FID, Entries); |
| 912 | } |
| 913 | |
| 914 | return false; |
| 915 | } |
| 916 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 917 | namespace { |
| 918 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 919 | class ASTStatData { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 920 | public: |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 921 | const ino_t ino; |
| 922 | const dev_t dev; |
| 923 | const mode_t mode; |
| 924 | const time_t mtime; |
| 925 | const off_t size; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 926 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 927 | 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] | 928 | : ino(i), dev(d), mode(mo), mtime(m), size(s) {} |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 929 | }; |
| 930 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 931 | class ASTStatLookupTrait { |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 932 | public: |
| 933 | typedef const char *external_key_type; |
| 934 | typedef const char *internal_key_type; |
| 935 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 936 | typedef ASTStatData data_type; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 937 | |
| 938 | static unsigned ComputeHash(const char *path) { |
Daniel Dunbar | f8502d5 | 2009-10-17 23:52:28 +0000 | [diff] [blame] | 939 | return llvm::HashString(path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | static internal_key_type GetInternalKey(const char *path) { return path; } |
| 943 | |
| 944 | static bool EqualKey(internal_key_type a, internal_key_type b) { |
| 945 | return strcmp(a, b) == 0; |
| 946 | } |
| 947 | |
| 948 | static std::pair<unsigned, unsigned> |
| 949 | ReadKeyDataLength(const unsigned char*& d) { |
| 950 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 951 | unsigned DataLen = (unsigned) *d++; |
| 952 | return std::make_pair(KeyLen + 1, DataLen); |
| 953 | } |
| 954 | |
| 955 | static internal_key_type ReadKey(const unsigned char *d, unsigned) { |
| 956 | return (const char *)d; |
| 957 | } |
| 958 | |
| 959 | static data_type ReadData(const internal_key_type, const unsigned char *d, |
| 960 | unsigned /*DataLen*/) { |
| 961 | using namespace clang::io; |
| 962 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 963 | ino_t ino = (ino_t) ReadUnalignedLE32(d); |
| 964 | dev_t dev = (dev_t) ReadUnalignedLE32(d); |
| 965 | mode_t mode = (mode_t) ReadUnalignedLE16(d); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 966 | time_t mtime = (time_t) ReadUnalignedLE64(d); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 967 | off_t size = (off_t) ReadUnalignedLE64(d); |
| 968 | return data_type(ino, dev, mode, mtime, size); |
| 969 | } |
| 970 | }; |
| 971 | |
| 972 | /// \brief stat() cache for precompiled headers. |
| 973 | /// |
| 974 | /// This cache is very similar to the stat cache used by pretokenized |
| 975 | /// headers. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 976 | class ASTStatCache : public FileSystemStatCache { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 977 | typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 978 | CacheTy *Cache; |
| 979 | |
| 980 | unsigned &NumStatHits, &NumStatMisses; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | public: |
Chris Lattner | 2a6fa47 | 2010-11-23 19:28:12 +0000 | [diff] [blame] | 982 | ASTStatCache(const unsigned char *Buckets, const unsigned char *Base, |
| 983 | unsigned &NumStatHits, unsigned &NumStatMisses) |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 984 | : Cache(0), NumStatHits(NumStatHits), NumStatMisses(NumStatMisses) { |
| 985 | Cache = CacheTy::Create(Buckets, Base); |
| 986 | } |
| 987 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 988 | ~ASTStatCache() { delete Cache; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 990 | LookupResult getStat(const char *Path, struct stat &StatBuf, |
| 991 | int *FileDescriptor) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 992 | // Do the lookup for the file's data in the AST file. |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 993 | CacheTy::iterator I = Cache->find(Path); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 994 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 995 | // 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] | 996 | if (I == Cache->end()) { |
| 997 | ++NumStatMisses; |
Chris Lattner | dd27843 | 2010-11-23 21:17:56 +0000 | [diff] [blame] | 998 | return statChained(Path, StatBuf, FileDescriptor); |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 999 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1001 | ++NumStatHits; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1002 | ASTStatData Data = *I; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 | |
Chris Lattner | 226efd3 | 2010-11-23 19:19:34 +0000 | [diff] [blame] | 1004 | StatBuf.st_ino = Data.ino; |
| 1005 | StatBuf.st_dev = Data.dev; |
| 1006 | StatBuf.st_mtime = Data.mtime; |
| 1007 | StatBuf.st_mode = Data.mode; |
| 1008 | StatBuf.st_size = Data.size; |
Chris Lattner | 8f0583d | 2010-11-23 20:05:15 +0000 | [diff] [blame] | 1009 | return CacheExists; |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 1010 | } |
| 1011 | }; |
| 1012 | } // end anonymous namespace |
| 1013 | |
| 1014 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1015 | /// \brief Read a source manager block |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1016 | ASTReader::ASTReadResult ASTReader::ReadSourceManagerBlock(Module &F) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1017 | using namespace SrcMgr; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1018 | |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1019 | llvm::BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1020 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1021 | // Set the source-location entry cursor to the current position in |
| 1022 | // the stream. This cursor will be used to read the contents of the |
| 1023 | // source manager block initially, and then lazily read |
| 1024 | // source-location entries as needed. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1025 | SLocEntryCursor = F.Stream; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1026 | |
| 1027 | // The stream itself is going to skip over the source manager block. |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1028 | if (F.Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1029 | Error("malformed block record in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1030 | return Failure; |
| 1031 | } |
| 1032 | |
| 1033 | // Enter the source manager block. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1034 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1035 | Error("malformed source manager block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1036 | return Failure; |
| 1037 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1038 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1039 | RecordData Record; |
| 1040 | while (true) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1041 | unsigned Code = SLocEntryCursor.ReadCode(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1042 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1043 | if (SLocEntryCursor.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1044 | Error("error at end of Source Manager block in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1045 | return Failure; |
| 1046 | } |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1047 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1048 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1050 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1051 | // No known subblocks, always skip them. |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1052 | SLocEntryCursor.ReadSubBlockID(); |
| 1053 | if (SLocEntryCursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1054 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1055 | return Failure; |
| 1056 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1057 | continue; |
| 1058 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1060 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1061 | SLocEntryCursor.ReadAbbrevRecord(); |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1062 | continue; |
| 1063 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1065 | // Read a record. |
| 1066 | const char *BlobStart; |
| 1067 | unsigned BlobLen; |
| 1068 | Record.clear(); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1069 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1070 | default: // Default behavior: ignore. |
| 1071 | break; |
| 1072 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1073 | case SM_SLOC_FILE_ENTRY: |
| 1074 | case SM_SLOC_BUFFER_ENTRY: |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1075 | case SM_SLOC_EXPANSION_ENTRY: |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1076 | // Once we hit one of the source location entries, we're done. |
| 1077 | return Success; |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1082 | /// \brief If a header file is not found at the path that we expect it to be |
| 1083 | /// and the PCH file was moved from its original location, try to resolve the |
| 1084 | /// file by assuming that header+PCH were moved together and the header is in |
| 1085 | /// the same place relative to the PCH. |
| 1086 | static std::string |
| 1087 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1088 | const std::string &OriginalDir, |
| 1089 | const std::string &CurrDir) { |
| 1090 | assert(OriginalDir != CurrDir && |
| 1091 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1092 | using namespace llvm::sys; |
| 1093 | llvm::SmallString<128> filePath(Filename); |
| 1094 | fs::make_absolute(filePath); |
| 1095 | assert(path::is_absolute(OriginalDir)); |
| 1096 | llvm::SmallString<128> currPCHPath(CurrDir); |
| 1097 | |
| 1098 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1099 | fileDirE = path::end(path::parent_path(filePath)); |
| 1100 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1101 | origDirE = path::end(OriginalDir); |
| 1102 | // Skip the common path components from filePath and OriginalDir. |
| 1103 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1104 | *fileDirI == *origDirI) { |
| 1105 | ++fileDirI; |
| 1106 | ++origDirI; |
| 1107 | } |
| 1108 | for (; origDirI != origDirE; ++origDirI) |
| 1109 | path::append(currPCHPath, ".."); |
| 1110 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1111 | path::append(currPCHPath, path::filename(Filename)); |
| 1112 | return currPCHPath.str(); |
| 1113 | } |
| 1114 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1115 | /// \brief Read in the source location entry with the given ID. |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1116 | ASTReader::ASTReadResult ASTReader::ReadSLocEntryRecord(int ID) { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1117 | if (ID == 0) |
| 1118 | return Success; |
| 1119 | |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1120 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1121 | Error("source location entry ID out-of-range for AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1122 | return Failure; |
| 1123 | } |
| 1124 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1125 | Module *F = GlobalSLocEntryMap.find(-ID)->second; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1126 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1127 | llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1128 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1129 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1130 | ++NumSLocEntriesRead; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1131 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1132 | if (Code == llvm::bitc::END_BLOCK || |
| 1133 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 1134 | Code == llvm::bitc::DEFINE_ABBREV) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1135 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1136 | return Failure; |
| 1137 | } |
| 1138 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1139 | RecordData Record; |
| 1140 | const char *BlobStart; |
| 1141 | unsigned BlobLen; |
| 1142 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1143 | default: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1144 | Error("incorrectly-formatted source location entry in AST file"); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1145 | return Failure; |
| 1146 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1147 | case SM_SLOC_FILE_ENTRY: { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1148 | std::string Filename(BlobStart, BlobStart + BlobLen); |
| 1149 | MaybeAddSystemRootToFilename(Filename); |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 1150 | const FileEntry *File = FileMgr.getFile(Filename); |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1151 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1152 | OriginalDir != CurrentDir) { |
| 1153 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1154 | OriginalDir, |
| 1155 | CurrentDir); |
| 1156 | if (!resolved.empty()) |
| 1157 | File = FileMgr.getFile(resolved); |
| 1158 | } |
Axel Naumann | 63fbaed | 2011-01-27 10:55:51 +0000 | [diff] [blame] | 1159 | if (File == 0) |
| 1160 | File = FileMgr.getVirtualFile(Filename, (off_t)Record[4], |
| 1161 | (time_t)Record[5]); |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1162 | if (File == 0) { |
| 1163 | std::string ErrorStr = "could not find file '"; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1164 | ErrorStr += Filename; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1165 | ErrorStr += "' referenced by AST file"; |
Chris Lattner | d20dc87 | 2009-06-15 04:35:16 +0000 | [diff] [blame] | 1166 | Error(ErrorStr.c_str()); |
| 1167 | return Failure; |
| 1168 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1170 | if (Record.size() < 6) { |
Ted Kremenek | abb1ddd | 2010-03-18 21:23:05 +0000 | [diff] [blame] | 1171 | Error("source location entry is incorrect"); |
| 1172 | return Failure; |
| 1173 | } |
| 1174 | |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1175 | if (!DisableValidation && |
| 1176 | ((off_t)Record[4] != File->getSize() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1177 | #if !defined(LLVM_ON_WIN32) |
| 1178 | // In our regression testing, the Windows file system seems to |
| 1179 | // have inconsistent modification times that sometimes |
| 1180 | // erroneously trigger this error-handling path. |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1181 | || (time_t)Record[5] != File->getModificationTime() |
Douglas Gregor | 08288f2 | 2010-04-09 15:54:22 +0000 | [diff] [blame] | 1182 | #endif |
Douglas Gregor | ce3a829 | 2010-07-27 00:27:13 +0000 | [diff] [blame] | 1183 | )) { |
Argyrios Kyrtzidis | daa41f5 | 2011-04-25 22:23:56 +0000 | [diff] [blame] | 1184 | Error(diag::err_fe_pch_file_modified, Filename); |
Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1185 | return Failure; |
| 1186 | } |
| 1187 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1188 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1189 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1190 | // This is the module's main file. |
| 1191 | IncludeLoc = getImportLocation(F); |
| 1192 | } |
| 1193 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, |
Chris Lattner | 26b5c19 | 2010-11-23 09:19:42 +0000 | [diff] [blame] | 1194 | (SrcMgr::CharacteristicKind)Record[2], |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1195 | ID, BaseOffset + Record[0]); |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1196 | SrcMgr::FileInfo &FileInfo = |
| 1197 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1198 | FileInfo.NumCreatedFIDs = Record[6]; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1199 | if (Record[3]) |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1200 | FileInfo.setHasLineDirectives(); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1201 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1202 | break; |
| 1203 | } |
| 1204 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1205 | case SM_SLOC_BUFFER_ENTRY: { |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1206 | const char *Name = BlobStart; |
| 1207 | unsigned Offset = Record[0]; |
| 1208 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1209 | Record.clear(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | unsigned RecCode |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1211 | = SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1212 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1213 | if (RecCode != SM_SLOC_BUFFER_BLOB) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1214 | Error("AST record has invalid code"); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 1215 | return Failure; |
| 1216 | } |
| 1217 | |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1218 | llvm::MemoryBuffer *Buffer |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1219 | = llvm::MemoryBuffer::getMemBuffer(StringRef(BlobStart, BlobLen - 1), |
Chris Lattner | 58c7934 | 2010-04-05 22:42:27 +0000 | [diff] [blame] | 1220 | Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1221 | FileID BufferID = SourceMgr.createFileIDForMemBuffer(Buffer, ID, |
| 1222 | BaseOffset + Offset); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1224 | if (strcmp(Name, "<built-in>") == 0) { |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1225 | PCHPredefinesBlock Block = { |
| 1226 | BufferID, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1227 | StringRef(BlobStart, BlobLen - 1) |
Sebastian Redl | 75fbb3b | 2010-07-14 17:49:11 +0000 | [diff] [blame] | 1228 | }; |
| 1229 | PCHPredefinesBuffers.push_back(Block); |
Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 1230 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1231 | |
| 1232 | break; |
| 1233 | } |
| 1234 | |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1235 | case SM_SLOC_EXPANSION_ENTRY: { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1236 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
Chandler Carruth | 115b077 | 2011-07-26 03:03:05 +0000 | [diff] [blame] | 1237 | SourceMgr.createExpansionLoc(SpellingLoc, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1238 | ReadSourceLocation(*F, Record[2]), |
| 1239 | ReadSourceLocation(*F, Record[3]), |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1240 | Record[4], |
| 1241 | ID, |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1242 | BaseOffset + Record[0]); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1243 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | } |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | return Success; |
| 1248 | } |
| 1249 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1250 | /// \brief Find the location where the module F is imported. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1251 | SourceLocation ASTReader::getImportLocation(Module *F) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1252 | if (F->ImportLoc.isValid()) |
| 1253 | return F->ImportLoc; |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1254 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1255 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1256 | // location of its includer. |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1257 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1258 | // Main file is the importer. We assume that it is the first entry in the |
| 1259 | // entry table. We can't ask the manager, because at the time of PCH loading |
| 1260 | // the main file entry doesn't exist yet. |
| 1261 | // The very first entry is the invalid instantiation loc, which takes up |
| 1262 | // offsets 0 and 1. |
| 1263 | return SourceLocation::getFromRawEncoding(2U); |
| 1264 | } |
Jonathan D. Turner | 10d5201 | 2011-07-29 18:09:09 +0000 | [diff] [blame] | 1265 | //return F->Loaders[0]->FirstLoc; |
| 1266 | return F->ImportedBy[0]->FirstLoc; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1269 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1270 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1271 | /// and then leave the cursor pointing into the block. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1272 | bool ASTReader::ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1273 | unsigned BlockID) { |
| 1274 | if (Cursor.EnterSubBlock(BlockID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1275 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1276 | return Failure; |
| 1277 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1278 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1279 | while (true) { |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1280 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1281 | unsigned Code = Cursor.ReadCode(); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1282 | |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1283 | // We expect all abbrevs to be at the start of the block. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1284 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1285 | Cursor.JumpToBit(Offset); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1286 | return false; |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1287 | } |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1288 | Cursor.ReadAbbrevRecord(); |
| 1289 | } |
| 1290 | } |
| 1291 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1292 | void ASTReader::ReadMacroRecord(Module &F, uint64_t Offset) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1293 | assert(PP && "Forgot to set Preprocessor ?"); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1294 | llvm::BitstreamCursor &Stream = F.MacroCursor; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1296 | // Keep track of where we are in the stream, then jump back there |
| 1297 | // after reading this macro. |
| 1298 | SavedStreamPosition SavedPosition(Stream); |
| 1299 | |
| 1300 | Stream.JumpToBit(Offset); |
| 1301 | RecordData Record; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1302 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1303 | MacroInfo *Macro = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1304 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1305 | while (true) { |
| 1306 | unsigned Code = Stream.ReadCode(); |
| 1307 | switch (Code) { |
| 1308 | case llvm::bitc::END_BLOCK: |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1309 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1310 | |
| 1311 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1312 | // No known subblocks, always skip them. |
| 1313 | Stream.ReadSubBlockID(); |
| 1314 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1315 | Error("malformed block record in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1316 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1317 | } |
| 1318 | continue; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1319 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1320 | case llvm::bitc::DEFINE_ABBREV: |
| 1321 | Stream.ReadAbbrevRecord(); |
| 1322 | continue; |
| 1323 | default: break; |
| 1324 | } |
| 1325 | |
| 1326 | // Read a record. |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1327 | const char *BlobStart = 0; |
| 1328 | unsigned BlobLen = 0; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1329 | Record.clear(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1330 | PreprocessorRecordTypes RecType = |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1331 | (PreprocessorRecordTypes)Stream.ReadRecord(Code, Record, BlobStart, |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1332 | BlobLen); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1333 | switch (RecType) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1334 | case PP_MACRO_OBJECT_LIKE: |
| 1335 | case PP_MACRO_FUNCTION_LIKE: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1336 | // If we already have a macro, that means that we've hit the end |
| 1337 | // of the definition of the macro we were looking for. We're |
| 1338 | // done. |
| 1339 | if (Macro) |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1340 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1341 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1342 | IdentifierInfo *II = getLocalIdentifier(F, Record[0]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1343 | if (II == 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1344 | Error("macro must have a name in AST file"); |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1345 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1346 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1347 | SourceLocation Loc = ReadSourceLocation(F, Record[1]); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1348 | bool isUsed = Record[2]; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1349 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1350 | MacroInfo *MI = PP->AllocateMacroInfo(Loc); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1351 | MI->setIsUsed(isUsed); |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1352 | MI->setIsFromAST(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1353 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1354 | unsigned NextIndex = 3; |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1355 | MI->setExportLocation(ReadSourceLocation(F, Record, NextIndex)); |
| 1356 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1357 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1358 | // Decode function-like macro info. |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1359 | bool isC99VarArgs = Record[NextIndex++]; |
| 1360 | bool isGNUVarArgs = Record[NextIndex++]; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1361 | MacroArgs.clear(); |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1362 | unsigned NumArgs = Record[NextIndex++]; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1363 | for (unsigned i = 0; i != NumArgs; ++i) |
Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 1364 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1365 | |
| 1366 | // Install function-like macro info. |
| 1367 | MI->setIsFunctionLike(); |
| 1368 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1369 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
Douglas Gregor | 038c338 | 2009-05-22 22:45:36 +0000 | [diff] [blame] | 1370 | MI->setArgumentList(MacroArgs.data(), MacroArgs.size(), |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1371 | PP->getPreprocessorAllocator()); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | // Finally, install the macro. |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1375 | PP->setMacroInfo(II, MI); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1376 | |
| 1377 | // Remember that we saw this macro last so that we add the tokens that |
| 1378 | // form its body to it. |
| 1379 | Macro = MI; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1380 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1381 | if (NextIndex + 1 == Record.size() && PP->getPreprocessingRecord()) { |
| 1382 | // We have a macro definition. Load it now. |
| 1383 | PP->getPreprocessingRecord()->RegisterMacroDefinition(Macro, |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1384 | getLocalMacroDefinition(F, Record[NextIndex])); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1385 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1386 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1387 | ++NumMacrosRead; |
| 1388 | break; |
| 1389 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1391 | case PP_TOKEN: { |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1392 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1393 | // erroneous, just pretend we didn't see this. |
| 1394 | if (Macro == 0) break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1396 | Token Tok; |
| 1397 | Tok.startToken(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1398 | Tok.setLocation(ReadSourceLocation(F, Record[0])); |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1399 | Tok.setLength(Record[1]); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1400 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[2])) |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1401 | Tok.setIdentifierInfo(II); |
| 1402 | Tok.setKind((tok::TokenKind)Record[3]); |
| 1403 | Tok.setFlag((Token::TokenFlags)Record[4]); |
| 1404 | Macro->AddTokenToBody(Tok); |
| 1405 | break; |
| 1406 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1407 | } |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1408 | } |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 1409 | |
Douglas Gregor | 7cb0d01 | 2011-08-04 18:09:14 +0000 | [diff] [blame] | 1410 | return; |
Douglas Gregor | c3366a5 | 2009-04-21 23:56:24 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1413 | PreprocessedEntity *ASTReader::LoadPreprocessedEntity(Module &F) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1414 | assert(PP && "Forgot to set Preprocessor ?"); |
| 1415 | unsigned Code = F.PreprocessorDetailCursor.ReadCode(); |
| 1416 | switch (Code) { |
| 1417 | case llvm::bitc::END_BLOCK: |
| 1418 | return 0; |
| 1419 | |
| 1420 | case llvm::bitc::ENTER_SUBBLOCK: |
| 1421 | Error("unexpected subblock record in preprocessor detail block"); |
| 1422 | return 0; |
| 1423 | |
| 1424 | case llvm::bitc::DEFINE_ABBREV: |
| 1425 | Error("unexpected abbrevation record in preprocessor detail block"); |
| 1426 | return 0; |
| 1427 | |
| 1428 | default: |
| 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | if (!PP->getPreprocessingRecord()) { |
| 1433 | Error("no preprocessing record"); |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
| 1437 | // Read the record. |
| 1438 | PreprocessingRecord &PPRec = *PP->getPreprocessingRecord(); |
| 1439 | const char *BlobStart = 0; |
| 1440 | unsigned BlobLen = 0; |
| 1441 | RecordData Record; |
| 1442 | PreprocessorDetailRecordTypes RecType = |
| 1443 | (PreprocessorDetailRecordTypes)F.PreprocessorDetailCursor.ReadRecord( |
| 1444 | Code, Record, BlobStart, BlobLen); |
| 1445 | switch (RecType) { |
Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1446 | case PPD_MACRO_EXPANSION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1447 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1448 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1449 | return PE; |
| 1450 | |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame^] | 1451 | bool isBuiltin = Record[3]; |
| 1452 | MacroExpansion *ME; |
| 1453 | if (isBuiltin) |
| 1454 | ME = new (PPRec) MacroExpansion(getLocalIdentifier(F, Record[4]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1455 | SourceRange(ReadSourceLocation(F, Record[1]), |
Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame^] | 1456 | ReadSourceLocation(F, Record[2]))); |
| 1457 | else |
| 1458 | ME = new (PPRec) MacroExpansion(getLocalMacroDefinition(F, Record[4]), |
| 1459 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1460 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1461 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ME); |
Chandler Carruth | a88a2218 | 2011-07-14 08:20:46 +0000 | [diff] [blame] | 1462 | return ME; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | case PPD_MACRO_DEFINITION: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1466 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1467 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1468 | return PE; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1469 | |
| 1470 | unsigned MacroDefID = getGlobalMacroDefinitionID(F, Record[1]); |
| 1471 | if (MacroDefID > MacroDefinitionsLoaded.size()) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1472 | Error("out-of-bounds macro definition record"); |
| 1473 | return 0; |
| 1474 | } |
| 1475 | |
| 1476 | // Decode the identifier info and then check again; if the macro is |
| 1477 | // still defined and associated with the identifier, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1478 | IdentifierInfo *II = getLocalIdentifier(F, Record[4]); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1479 | if (!MacroDefinitionsLoaded[MacroDefID - 1]) { |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1480 | MacroDefinition *MD |
| 1481 | = new (PPRec) MacroDefinition(II, |
| 1482 | ReadSourceLocation(F, Record[5]), |
| 1483 | SourceRange( |
| 1484 | ReadSourceLocation(F, Record[2]), |
| 1485 | ReadSourceLocation(F, Record[3]))); |
| 1486 | |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1487 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, MD); |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1488 | MacroDefinitionsLoaded[MacroDefID - 1] = MD; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1489 | |
| 1490 | if (DeserializationListener) |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1491 | DeserializationListener->MacroDefinitionRead(MacroDefID, MD); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1492 | } |
| 1493 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1494 | return MacroDefinitionsLoaded[MacroDefID - 1]; |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | case PPD_INCLUSION_DIRECTIVE: { |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1498 | PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[0]); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1499 | if (PreprocessedEntity *PE = PPRec.getLoadedPreprocessedEntity(GlobalID-1)) |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1500 | return PE; |
| 1501 | |
| 1502 | const char *FullFileNameStart = BlobStart + Record[3]; |
| 1503 | const FileEntry *File |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1504 | = PP->getFileManager().getFile(StringRef(FullFileNameStart, |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1505 | BlobLen - Record[3])); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1506 | |
| 1507 | // FIXME: Stable encoding |
| 1508 | InclusionDirective::InclusionKind Kind |
| 1509 | = static_cast<InclusionDirective::InclusionKind>(Record[5]); |
| 1510 | InclusionDirective *ID |
| 1511 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1512 | StringRef(BlobStart, Record[3]), |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1513 | Record[4], |
| 1514 | File, |
| 1515 | SourceRange(ReadSourceLocation(F, Record[1]), |
| 1516 | ReadSourceLocation(F, Record[2]))); |
Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 1517 | PPRec.setLoadedPreallocatedEntity(GlobalID - 1, ID); |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1518 | return ID; |
| 1519 | } |
| 1520 | } |
| 1521 | |
| 1522 | Error("invalid offset in preprocessor detail block"); |
| 1523 | return 0; |
| 1524 | } |
| 1525 | |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1526 | PreprocessedEntityID |
| 1527 | ASTReader::getGlobalPreprocessedEntityID(Module &M, unsigned LocalID) { |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 1528 | ContinuousRangeMap<uint32_t, int, 2>::iterator |
| 1529 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1530 | assert(I != M.PreprocessedEntityRemap.end() |
| 1531 | && "Invalid index into preprocessed entity index remap"); |
| 1532 | |
| 1533 | return LocalID + I->second; |
Douglas Gregor | caed7c6 | 2011-07-28 22:39:26 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1536 | unsigned HeaderFileInfoTrait::ComputeHash(const char *path) { |
| 1537 | return llvm::HashString(llvm::sys::path::filename(path)); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1538 | } |
Douglas Gregor | d44252e | 2011-08-25 20:47:51 +0000 | [diff] [blame] | 1539 | |
| 1540 | HeaderFileInfoTrait::internal_key_type |
| 1541 | HeaderFileInfoTrait::GetInternalKey(const char *path) { return path; } |
| 1542 | |
| 1543 | bool HeaderFileInfoTrait::EqualKey(internal_key_type a, internal_key_type b) { |
| 1544 | if (strcmp(a, b) == 0) |
| 1545 | return true; |
| 1546 | |
| 1547 | if (llvm::sys::path::filename(a) != llvm::sys::path::filename(b)) |
| 1548 | return false; |
| 1549 | |
| 1550 | // The file names match, but the path names don't. stat() the files to |
| 1551 | // see if they are the same. |
| 1552 | struct stat StatBufA, StatBufB; |
| 1553 | if (StatSimpleCache(a, &StatBufA) || StatSimpleCache(b, &StatBufB)) |
| 1554 | return false; |
| 1555 | |
| 1556 | return StatBufA.st_ino == StatBufB.st_ino; |
| 1557 | } |
| 1558 | |
| 1559 | std::pair<unsigned, unsigned> |
| 1560 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1561 | unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d); |
| 1562 | unsigned DataLen = (unsigned) *d++; |
| 1563 | return std::make_pair(KeyLen + 1, DataLen); |
| 1564 | } |
| 1565 | |
| 1566 | HeaderFileInfoTrait::data_type |
| 1567 | HeaderFileInfoTrait::ReadData(const internal_key_type, const unsigned char *d, |
| 1568 | unsigned DataLen) { |
| 1569 | const unsigned char *End = d + DataLen; |
| 1570 | using namespace clang::io; |
| 1571 | HeaderFileInfo HFI; |
| 1572 | unsigned Flags = *d++; |
| 1573 | HFI.isImport = (Flags >> 5) & 0x01; |
| 1574 | HFI.isPragmaOnce = (Flags >> 4) & 0x01; |
| 1575 | HFI.DirInfo = (Flags >> 2) & 0x03; |
| 1576 | HFI.Resolved = (Flags >> 1) & 0x01; |
| 1577 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1578 | HFI.NumIncludes = ReadUnalignedLE16(d); |
| 1579 | HFI.ControllingMacroID = Reader.getGlobalDeclID(M, ReadUnalignedLE32(d)); |
| 1580 | if (unsigned FrameworkOffset = ReadUnalignedLE32(d)) { |
| 1581 | // The framework offset is 1 greater than the actual offset, |
| 1582 | // since 0 is used as an indicator for "no framework name". |
| 1583 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1584 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1585 | } |
| 1586 | |
| 1587 | assert(End == d && "Wrong data length in HeaderFileInfo deserialization"); |
| 1588 | (void)End; |
| 1589 | |
| 1590 | // This HeaderFileInfo was externally loaded. |
| 1591 | HFI.External = true; |
| 1592 | return HFI; |
| 1593 | } |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1594 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1595 | void ASTReader::SetIdentifierIsMacro(IdentifierInfo *II, Module &F, |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1596 | uint64_t LocalOffset) { |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1597 | // Note that this identifier has a macro definition. |
| 1598 | II->setHasMacroDefinition(true); |
| 1599 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1600 | // Adjust the offset to a global offset. |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 1601 | UnreadMacroRecordOffsets[II] = F.GlobalBitOffset + LocalOffset; |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1604 | void ASTReader::ReadDefinedMacros() { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1605 | for (ModuleReverseIterator I = ModuleMgr.rbegin(), |
| 1606 | E = ModuleMgr.rend(); I != E; ++I) { |
| 1607 | llvm::BitstreamCursor &MacroCursor = (*I)->MacroCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1608 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1609 | // If there was no preprocessor block, skip this file. |
| 1610 | if (!MacroCursor.getBitStreamReader()) |
| 1611 | continue; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1612 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1613 | llvm::BitstreamCursor Cursor = MacroCursor; |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 1614 | Cursor.JumpToBit((*I)->MacroStartOffset); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 1615 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1616 | RecordData Record; |
| 1617 | while (true) { |
| 1618 | unsigned Code = Cursor.ReadCode(); |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1619 | if (Code == llvm::bitc::END_BLOCK) |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1620 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1621 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1622 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1623 | // No known subblocks, always skip them. |
| 1624 | Cursor.ReadSubBlockID(); |
| 1625 | if (Cursor.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1626 | Error("malformed block record in AST file"); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1627 | return; |
| 1628 | } |
| 1629 | continue; |
| 1630 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1631 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1632 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1633 | Cursor.ReadAbbrevRecord(); |
| 1634 | continue; |
| 1635 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 1636 | |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1637 | // Read a record. |
| 1638 | const char *BlobStart; |
| 1639 | unsigned BlobLen; |
| 1640 | Record.clear(); |
| 1641 | switch (Cursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 1642 | default: // Default behavior: ignore. |
| 1643 | break; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1644 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1645 | case PP_MACRO_OBJECT_LIKE: |
| 1646 | case PP_MACRO_FUNCTION_LIKE: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 1647 | getLocalIdentifier(**I, Record[0]); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1648 | break; |
| 1649 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1650 | case PP_TOKEN: |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1651 | // Ignore tokens. |
| 1652 | break; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1653 | } |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1654 | } |
| 1655 | } |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1656 | |
| 1657 | // Drain the unread macro-record offsets map. |
| 1658 | while (!UnreadMacroRecordOffsets.empty()) |
| 1659 | LoadMacroDefinition(UnreadMacroRecordOffsets.begin()); |
| 1660 | } |
| 1661 | |
| 1662 | void ASTReader::LoadMacroDefinition( |
| 1663 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos) { |
| 1664 | assert(Pos != UnreadMacroRecordOffsets.end() && "Unknown macro definition"); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1665 | uint64_t Offset = Pos->second; |
| 1666 | UnreadMacroRecordOffsets.erase(Pos); |
| 1667 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 1668 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 1669 | ReadMacroRecord(*Loc.F, Loc.Offset); |
Douglas Gregor | 5ef9e33 | 2010-10-30 00:23:06 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | void ASTReader::LoadMacroDefinition(IdentifierInfo *II) { |
| 1673 | llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos |
| 1674 | = UnreadMacroRecordOffsets.find(II); |
| 1675 | LoadMacroDefinition(Pos); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1676 | } |
| 1677 | |
Sebastian Redl | 50e2658 | 2010-09-15 19:54:06 +0000 | [diff] [blame] | 1678 | MacroDefinition *ASTReader::getMacroDefinition(MacroID ID) { |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1679 | if (ID == 0 || ID > MacroDefinitionsLoaded.size()) |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1680 | return 0; |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1681 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1682 | if (!MacroDefinitionsLoaded[ID - 1]) { |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 1683 | GlobalMacroDefinitionMapType::iterator I =GlobalMacroDefinitionMap.find(ID); |
| 1684 | assert(I != GlobalMacroDefinitionMap.end() && |
| 1685 | "Corrupted global macro definition map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1686 | Module &M = *I->second; |
| 1687 | unsigned Index = ID - 1 - M.BaseMacroDefinitionID; |
| 1688 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 1689 | M.PreprocessorDetailCursor.JumpToBit(M.MacroDefinitionOffsets[Index]); |
| 1690 | LoadPreprocessedEntity(M); |
Sebastian Redl | 4e6c567 | 2010-07-21 22:31:37 +0000 | [diff] [blame] | 1691 | } |
| 1692 | |
Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 1693 | return MacroDefinitionsLoaded[ID - 1]; |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1696 | const FileEntry *ASTReader::getFileEntry(StringRef filenameStrRef) { |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 1697 | std::string Filename = filenameStrRef; |
| 1698 | MaybeAddSystemRootToFilename(Filename); |
| 1699 | const FileEntry *File = FileMgr.getFile(Filename); |
| 1700 | if (File == 0 && !OriginalDir.empty() && !CurrentDir.empty() && |
| 1701 | OriginalDir != CurrentDir) { |
| 1702 | std::string resolved = resolveFileRelativeToOriginalDir(Filename, |
| 1703 | OriginalDir, |
| 1704 | CurrentDir); |
| 1705 | if (!resolved.empty()) |
| 1706 | File = FileMgr.getFile(resolved); |
| 1707 | } |
| 1708 | |
| 1709 | return File; |
| 1710 | } |
| 1711 | |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1712 | MacroID ASTReader::getGlobalMacroDefinitionID(Module &M, unsigned LocalID) { |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 1713 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 1714 | return LocalID; |
| 1715 | |
| 1716 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 1717 | = M.MacroDefinitionRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 1718 | assert(I != M.MacroDefinitionRemap.end() && |
| 1719 | "Invalid index into macro definition ID remap"); |
| 1720 | |
| 1721 | return LocalID + I->second; |
Douglas Gregor | 035611e | 2011-07-28 22:16:57 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1724 | /// \brief If we are loading a relocatable PCH file, and the filename is |
| 1725 | /// not an absolute path, add the system root to the beginning of the file |
| 1726 | /// name. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1727 | void ASTReader::MaybeAddSystemRootToFilename(std::string &Filename) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1728 | // If this is not a relocatable PCH file, there's nothing to do. |
| 1729 | if (!RelocatablePCH) |
| 1730 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1731 | |
Michael J. Spencer | f28df4c | 2010-12-17 21:22:22 +0000 | [diff] [blame] | 1732 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1733 | return; |
| 1734 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1735 | if (isysroot.empty()) { |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1736 | // If no system root was given, default to '/' |
| 1737 | Filename.insert(Filename.begin(), '/'); |
| 1738 | return; |
| 1739 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1740 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1741 | unsigned Length = isysroot.size(); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1742 | if (isysroot[Length - 1] != '/') |
| 1743 | Filename.insert(Filename.begin(), '/'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1744 | |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 1745 | Filename.insert(Filename.begin(), isysroot.begin(), isysroot.end()); |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 1748 | ASTReader::ASTReadResult |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 1749 | ASTReader::ReadASTBlock(Module &F) { |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1750 | llvm::BitstreamCursor &Stream = F.Stream; |
| 1751 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1752 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1753 | Error("malformed block record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1754 | return Failure; |
| 1755 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1756 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1757 | // Read all of the records and blocks for the ASt file. |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1758 | RecordData Record; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1759 | while (!Stream.AtEndOfStream()) { |
| 1760 | unsigned Code = Stream.ReadCode(); |
| 1761 | if (Code == llvm::bitc::END_BLOCK) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1762 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1763 | Error("error at end of module block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1764 | return Failure; |
| 1765 | } |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1766 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1767 | return Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 1771 | switch (Stream.ReadSubBlockID()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1772 | case DECLTYPES_BLOCK_ID: |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1773 | // We lazily load the decls block, but we want to set up the |
| 1774 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 1775 | // cursor to it, enter the block and read the abbrevs in that block. |
| 1776 | // With the main cursor, we just skip over it. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1777 | F.DeclsCursor = Stream; |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1778 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 1779 | // Read the abbrevs. |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1780 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1781 | Error("malformed block record in AST file"); |
Chris Lattner | e78a6be | 2009-04-27 01:05:14 +0000 | [diff] [blame] | 1782 | return Failure; |
| 1783 | } |
| 1784 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1785 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 1786 | case DECL_UPDATES_BLOCK_ID: |
| 1787 | if (Stream.SkipBlock()) { |
| 1788 | Error("malformed block record in AST file"); |
| 1789 | return Failure; |
| 1790 | } |
| 1791 | break; |
| 1792 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1793 | case PREPROCESSOR_BLOCK_ID: |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 1794 | F.MacroCursor = Stream; |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 1795 | if (PP) |
| 1796 | PP->setExternalSource(this); |
| 1797 | |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1798 | if (Stream.SkipBlock() || |
| 1799 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1800 | Error("malformed block record in AST file"); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1801 | return Failure; |
| 1802 | } |
Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 1803 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
Chris Lattner | c523d8e | 2009-04-11 21:15:38 +0000 | [diff] [blame] | 1804 | break; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 1805 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 1806 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 1807 | F.PreprocessorDetailCursor = Stream; |
| 1808 | if (Stream.SkipBlock() || |
| 1809 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 1810 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 1811 | Error("malformed preprocessor detail record in AST file"); |
| 1812 | return Failure; |
| 1813 | } |
| 1814 | F.PreprocessorDetailStartOffset |
| 1815 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 1816 | break; |
| 1817 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1818 | case SOURCE_MANAGER_BLOCK_ID: |
Sebastian Redl | 393f8b7 | 2010-07-19 20:52:06 +0000 | [diff] [blame] | 1819 | switch (ReadSourceManagerBlock(F)) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1820 | case Success: |
| 1821 | break; |
| 1822 | |
| 1823 | case Failure: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1824 | Error("malformed source manager block in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1825 | return Failure; |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 1826 | |
| 1827 | case IgnorePCH: |
| 1828 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1829 | } |
Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1830 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 1831 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1832 | continue; |
| 1833 | } |
| 1834 | |
| 1835 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 1836 | Stream.ReadAbbrevRecord(); |
| 1837 | continue; |
| 1838 | } |
| 1839 | |
| 1840 | // Read and process a record. |
| 1841 | Record.clear(); |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1842 | const char *BlobStart = 0; |
| 1843 | unsigned BlobLen = 0; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1844 | switch ((ASTRecordTypes)Stream.ReadRecord(Code, Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 1845 | &BlobStart, &BlobLen)) { |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1846 | default: // Default behavior: ignore. |
| 1847 | break; |
| 1848 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1849 | case METADATA: { |
| 1850 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 1851 | Diag(Record[0] < VERSION_MAJOR? diag::warn_pch_version_too_old |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1852 | : diag::warn_pch_version_too_new); |
| 1853 | return IgnorePCH; |
| 1854 | } |
| 1855 | |
| 1856 | RelocatablePCH = Record[4]; |
| 1857 | if (Listener) { |
| 1858 | std::string TargetTriple(BlobStart, BlobLen); |
| 1859 | if (Listener->ReadTargetTriple(TargetTriple)) |
| 1860 | return IgnorePCH; |
| 1861 | } |
| 1862 | break; |
| 1863 | } |
| 1864 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1865 | case IMPORTS: { |
| 1866 | // Load each of the imported PCH files. |
| 1867 | unsigned Idx = 0, N = Record.size(); |
| 1868 | while (Idx < N) { |
| 1869 | // Read information about the AST file. |
| 1870 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 1871 | unsigned Length = Record[Idx++]; |
| 1872 | llvm::SmallString<128> ImportedFile(Record.begin() + Idx, |
| 1873 | Record.begin() + Idx + Length); |
| 1874 | Idx += Length; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1875 | |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1876 | // Load the AST file. |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1877 | switch(ReadASTCore(ImportedFile, ImportedKind, &F)) { |
Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1878 | case Failure: return Failure; |
| 1879 | // If we have to ignore the dependency, we'll have to ignore this too. |
| 1880 | case IgnorePCH: return IgnorePCH; |
| 1881 | case Success: break; |
| 1882 | } |
| 1883 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 1884 | break; |
| 1885 | } |
| 1886 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1887 | case TYPE_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1888 | if (F.LocalNumTypes != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1889 | Error("duplicate TYPE_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1890 | return Failure; |
| 1891 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1892 | F.TypeOffsets = (const uint32_t *)BlobStart; |
| 1893 | F.LocalNumTypes = Record[0]; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1894 | unsigned LocalBaseTypeIndex = Record[1]; |
| 1895 | F.BaseTypeIndex = getTotalNumTypes(); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 1896 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1897 | if (F.LocalNumTypes > 0) { |
| 1898 | // Introduce the global -> local mapping for types within this module. |
| 1899 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 1900 | |
| 1901 | // Introduce the local -> global mapping for types within this module. |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 1902 | F.TypeRemap.insert(std::make_pair(LocalBaseTypeIndex, |
| 1903 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1904 | |
| 1905 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 1906 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1907 | break; |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1910 | case DECL_OFFSET: { |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1911 | if (F.LocalNumDecls != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1912 | Error("duplicate DECL_OFFSET record in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1913 | return Failure; |
| 1914 | } |
Sebastian Redl | 9e68799 | 2010-07-19 22:06:55 +0000 | [diff] [blame] | 1915 | F.DeclOffsets = (const uint32_t *)BlobStart; |
| 1916 | F.LocalNumDecls = Record[0]; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1917 | unsigned LocalBaseDeclID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 1918 | F.BaseDeclID = getTotalNumDecls(); |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 1919 | |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1920 | if (F.LocalNumDecls > 0) { |
| 1921 | // Introduce the global -> local mapping for declarations within this |
| 1922 | // module. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1923 | GlobalDeclMap.insert( |
| 1924 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1925 | |
| 1926 | // Introduce the local -> global mapping for declarations within this |
| 1927 | // module. |
| 1928 | F.DeclRemap.insert(std::make_pair(LocalBaseDeclID, |
| 1929 | F.BaseDeclID - LocalBaseDeclID)); |
| 1930 | |
| 1931 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 1932 | } |
Douglas Gregor | 1e9bf3b | 2009-04-10 17:25:41 +0000 | [diff] [blame] | 1933 | break; |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1936 | case TU_UPDATE_LEXICAL: { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1937 | DeclContext *TU = Context ? Context->getTranslationUnitDecl() : 0; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 1938 | DeclContextInfo &Info = F.DeclContextInfos[TU]; |
| 1939 | Info.LexicalDecls = reinterpret_cast<const KindDeclIDPair *>(BlobStart); |
| 1940 | Info.NumLexicalDecls |
| 1941 | = static_cast<unsigned int>(BlobLen / sizeof(KindDeclIDPair)); |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1942 | if (TU) |
| 1943 | TU->setHasExternalLexicalStorage(true); |
| 1944 | |
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 | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 1955 | if (ID == PREDEF_DECL_TRANSLATION_UNIT_ID && Context) { // Is it the TU? |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 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 | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1987 | if (PP) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 1988 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 1989 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
| 1990 | } |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 1991 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1992 | break; |
| 1993 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 1994 | case IDENTIFIER_OFFSET: { |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1995 | if (F.LocalNumIdentifiers != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 1996 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 1997 | return Failure; |
| 1998 | } |
Sebastian Redl | bd1b5be | 2010-07-19 22:28:42 +0000 | [diff] [blame] | 1999 | F.IdentifierOffsets = (const uint32_t *)BlobStart; |
| 2000 | F.LocalNumIdentifiers = Record[0]; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2001 | unsigned LocalBaseIdentifierID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2002 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 2003 | |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2004 | if (F.LocalNumIdentifiers > 0) { |
| 2005 | // Introduce the global -> local mapping for identifiers within this |
| 2006 | // module. |
| 2007 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 2008 | &F)); |
| 2009 | |
| 2010 | // Introduce the local -> global mapping for identifiers within this |
| 2011 | // module. |
| 2012 | F.IdentifierRemap.insert( |
| 2013 | std::make_pair(LocalBaseIdentifierID, |
| 2014 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 2015 | |
| 2016 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2017 | + F.LocalNumIdentifiers); |
| 2018 | } |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2019 | break; |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2022 | case EXTERNAL_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2023 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2024 | ExternalDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 2025 | break; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2026 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2027 | case SPECIAL_TYPES: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 2028 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2029 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 2030 | break; |
| 2031 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2032 | case STATISTICS: |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2033 | TotalNumStatements += Record[0]; |
| 2034 | TotalNumMacros += Record[1]; |
| 2035 | TotalLexicalDeclContexts += Record[2]; |
| 2036 | TotalVisibleDeclContexts += Record[3]; |
Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 2037 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2038 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2039 | case UNUSED_FILESCOPED_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2040 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2041 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Tanya Lattner | 9007380 | 2010-02-12 00:07:30 +0000 | [diff] [blame] | 2042 | break; |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2043 | |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2044 | case DELEGATING_CTORS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2045 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2046 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2047 | break; |
| 2048 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2049 | case WEAK_UNDECLARED_IDENTIFIERS: |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 2050 | if (Record.size() % 4 != 0) { |
| 2051 | Error("invalid weak identifiers record"); |
| 2052 | return Failure; |
| 2053 | } |
| 2054 | |
| 2055 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| 2056 | // files. This isn't the way to do it :) |
| 2057 | WeakUndeclaredIdentifiers.clear(); |
| 2058 | |
| 2059 | // Translate the weak, undeclared identifiers into global IDs. |
| 2060 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2061 | WeakUndeclaredIdentifiers.push_back( |
| 2062 | getGlobalIdentifierID(F, Record[I++])); |
| 2063 | WeakUndeclaredIdentifiers.push_back( |
| 2064 | getGlobalIdentifierID(F, Record[I++])); |
| 2065 | WeakUndeclaredIdentifiers.push_back( |
| 2066 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2067 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2068 | } |
Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 2069 | break; |
| 2070 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2071 | case LOCALLY_SCOPED_EXTERNAL_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2072 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2073 | LocallyScopedExternalDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 2074 | break; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2075 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2076 | case SELECTOR_OFFSETS: { |
Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 2077 | F.SelectorOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2078 | F.LocalNumSelectors = Record[0]; |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2079 | unsigned LocalBaseSelectorID = Record[1]; |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2080 | F.BaseSelectorID = getTotalNumSelectors(); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 2081 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2082 | if (F.LocalNumSelectors > 0) { |
| 2083 | // Introduce the global -> local mapping for selectors within this |
| 2084 | // module. |
| 2085 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 2086 | |
| 2087 | // Introduce the local -> global mapping for selectors within this |
| 2088 | // module. |
| 2089 | F.SelectorRemap.insert(std::make_pair(LocalBaseSelectorID, |
| 2090 | F.BaseSelectorID - LocalBaseSelectorID)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2091 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2092 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 2093 | } |
| 2094 | break; |
| 2095 | } |
| 2096 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2097 | case METHOD_POOL: |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2098 | F.SelectorLookupTableData = (const unsigned char *)BlobStart; |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 2099 | if (Record[0]) |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2100 | F.SelectorLookupTable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2101 | = ASTSelectorLookupTable::Create( |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 2102 | F.SelectorLookupTableData + Record[0], |
| 2103 | F.SelectorLookupTableData, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2104 | ASTSelectorLookupTrait(*this, F)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 2105 | TotalNumMethodPoolEntries += Record[1]; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2106 | break; |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2107 | |
Sebastian Redl | 96371b4 | 2010-09-22 00:42:30 +0000 | [diff] [blame] | 2108 | case REFERENCED_SELECTOR_POOL: |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 2109 | if (!Record.empty()) { |
| 2110 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2111 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 2112 | Record[Idx++])); |
| 2113 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2114 | getRawEncoding()); |
| 2115 | } |
| 2116 | } |
Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 2117 | break; |
| 2118 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2119 | case PP_COUNTER_VALUE: |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2120 | if (!Record.empty() && Listener) |
| 2121 | Listener->ReadCounter(Record[0]); |
Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2122 | break; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2123 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2124 | case SOURCE_LOCATION_OFFSETS: { |
| 2125 | F.SLocEntryOffsets = (const uint32_t *)BlobStart; |
Sebastian Redl | b293a45 | 2010-07-20 21:20:32 +0000 | [diff] [blame] | 2126 | F.LocalNumSLocEntries = Record[0]; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2127 | llvm::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 2128 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, Record[1]); |
| 2129 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2130 | // we invert it. Because we invert it, though, we need the other end of |
| 2131 | // the range. |
| 2132 | unsigned RangeStart = |
| 2133 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2134 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2135 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2136 | |
| 2137 | // Initialize the remapping table. |
| 2138 | // Invalid stays invalid. |
| 2139 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 2140 | // This module. Base was 2 when being compiled. |
| 2141 | F.SLocRemap.insert(std::make_pair(2U, |
| 2142 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2143 | |
| 2144 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2145 | break; |
| 2146 | } |
| 2147 | |
Douglas Gregor | 5a1797c | 2011-08-01 16:01:55 +0000 | [diff] [blame] | 2148 | case MODULE_OFFSET_MAP: { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2149 | // Additional remapping information. |
| 2150 | const unsigned char *Data = (const unsigned char*)BlobStart; |
| 2151 | const unsigned char *DataEnd = Data + BlobLen; |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2152 | |
| 2153 | // Continuous range maps we may be updating in our module. |
| 2154 | ContinuousRangeMap<uint32_t, int, 2>::Builder SLocRemap(F.SLocRemap); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2155 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 2156 | IdentifierRemap(F.IdentifierRemap); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2157 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2158 | PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 2159 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2160 | MacroDefinitionRemap(F.MacroDefinitionRemap); |
| 2161 | ContinuousRangeMap<uint32_t, int, 2>::Builder |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2162 | SelectorRemap(F.SelectorRemap); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2163 | ContinuousRangeMap<uint32_t, int, 2>::Builder DeclRemap(F.DeclRemap); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2164 | ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap); |
| 2165 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2166 | while(Data < DataEnd) { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2167 | uint16_t Len = io::ReadUnalignedLE16(Data); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2168 | StringRef Name = StringRef((const char*)Data, Len); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2169 | Data += Len; |
Jonathan D. Turner | b2b0823 | 2011-07-26 18:21:30 +0000 | [diff] [blame] | 2170 | Module *OM = ModuleMgr.lookup(Name); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2171 | if (!OM) { |
| 2172 | Error("SourceLocation remap refers to unknown module"); |
| 2173 | return Failure; |
| 2174 | } |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2175 | |
| 2176 | uint32_t SLocOffset = io::ReadUnalignedLE32(Data); |
| 2177 | uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data); |
| 2178 | uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data); |
| 2179 | uint32_t MacroDefinitionIDOffset = io::ReadUnalignedLE32(Data); |
| 2180 | uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data); |
| 2181 | uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2182 | uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data); |
Douglas Gregor | 0065990 | 2011-08-02 10:56:51 +0000 | [diff] [blame] | 2183 | |
| 2184 | // Source location offset is mapped to OM->SLocEntryBaseOffset. |
| 2185 | SLocRemap.insert(std::make_pair(SLocOffset, |
| 2186 | static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset))); |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 2187 | IdentifierRemap.insert( |
| 2188 | std::make_pair(IdentifierIDOffset, |
| 2189 | OM->BaseIdentifierID - IdentifierIDOffset)); |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2190 | PreprocessedEntityRemap.insert( |
| 2191 | std::make_pair(PreprocessedEntityIDOffset, |
| 2192 | OM->BasePreprocessedEntityID - PreprocessedEntityIDOffset)); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2193 | MacroDefinitionRemap.insert( |
| 2194 | std::make_pair(MacroDefinitionIDOffset, |
| 2195 | OM->BaseMacroDefinitionID - MacroDefinitionIDOffset)); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 2196 | SelectorRemap.insert(std::make_pair(SelectorIDOffset, |
| 2197 | OM->BaseSelectorID - SelectorIDOffset)); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2198 | DeclRemap.insert(std::make_pair(DeclIDOffset, |
| 2199 | OM->BaseDeclID - DeclIDOffset)); |
| 2200 | |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2201 | TypeRemap.insert(std::make_pair(TypeIndexOffset, |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 2202 | OM->BaseTypeIndex - TypeIndexOffset)); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2203 | } |
| 2204 | break; |
| 2205 | } |
| 2206 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2207 | case SOURCE_MANAGER_LINE_TABLE: |
| 2208 | if (ParseLineTable(F, Record)) |
| 2209 | return Failure; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2210 | break; |
| 2211 | |
Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 2212 | case FILE_SOURCE_LOCATION_OFFSETS: |
| 2213 | F.SLocFileOffsets = (const uint32_t *)BlobStart; |
| 2214 | F.LocalNumSLocFileEntries = Record[0]; |
| 2215 | break; |
| 2216 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2217 | case SOURCE_LOCATION_PRELOADS: { |
| 2218 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2219 | // which is based off F.SLocEntryBaseID. |
Douglas Gregor | a918bab | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2220 | if (!F.PreloadSLocEntries.empty()) { |
| 2221 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 2222 | return Failure; |
| 2223 | } |
| 2224 | |
| 2225 | F.PreloadSLocEntries.swap(Record); |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2226 | break; |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2227 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2228 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2229 | case STAT_CACHE: { |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 2230 | if (!DisableStatCache) { |
| 2231 | ASTStatCache *MyStatCache = |
| 2232 | new ASTStatCache((const unsigned char *)BlobStart + Record[0], |
| 2233 | (const unsigned char *)BlobStart, |
| 2234 | NumStatHits, NumStatMisses); |
| 2235 | FileMgr.addStatCache(MyStatCache); |
| 2236 | F.StatCache = MyStatCache; |
| 2237 | } |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2238 | break; |
Douglas Gregor | d2eb58a | 2009-10-16 18:18:30 +0000 | [diff] [blame] | 2239 | } |
Kovarththanan Rajaratnam | 39f2fbd1 | 2010-03-07 19:10:13 +0000 | [diff] [blame] | 2240 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2241 | case EXT_VECTOR_DECLS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2242 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2243 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 2244 | break; |
| 2245 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2246 | case VTABLE_USES: |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2247 | if (Record.size() % 3 != 0) { |
| 2248 | Error("Invalid VTABLE_USES record"); |
| 2249 | return Failure; |
| 2250 | } |
| 2251 | |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2252 | // Later tables overwrite earlier ones. |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2253 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 2254 | // the right way to do this. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2255 | VTableUses.clear(); |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 2256 | |
| 2257 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 2258 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 2259 | VTableUses.push_back( |
| 2260 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 2261 | VTableUses.push_back(Record[Idx++]); |
| 2262 | } |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2263 | break; |
| 2264 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2265 | case DYNAMIC_CLASSES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2266 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2267 | DynamicClasses.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 2268 | break; |
| 2269 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2270 | case PENDING_IMPLICIT_INSTANTIATIONS: |
Douglas Gregor | bbbc367 | 2011-07-28 19:26:52 +0000 | [diff] [blame] | 2271 | if (PendingInstantiations.size() % 2 != 0) { |
| 2272 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 2273 | return Failure; |
| 2274 | } |
| 2275 | |
| 2276 | // Later lists of pending instantiations overwrite earlier ones. |
| 2277 | // FIXME: This is most certainly wrong for modules. |
| 2278 | PendingInstantiations.clear(); |
| 2279 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 2280 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 2281 | PendingInstantiations.push_back( |
| 2282 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2283 | } |
Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2286 | case SEMA_DECL_REFS: |
Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 2287 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2288 | // FIXME: Modules will have some trouble with this. |
| 2289 | SemaDeclRefs.clear(); |
| 2290 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2291 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 2292 | break; |
| 2293 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2294 | case ORIGINAL_FILE_NAME: |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2295 | // 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] | 2296 | // that's used. |
Daniel Dunbar | 000c4ff | 2009-11-11 05:29:04 +0000 | [diff] [blame] | 2297 | ActualOriginalFileName.assign(BlobStart, BlobLen); |
| 2298 | OriginalFileName = ActualOriginalFileName; |
Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 2299 | MaybeAddSystemRootToFilename(OriginalFileName); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2300 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2301 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2302 | case ORIGINAL_FILE_ID: |
| 2303 | OriginalFileID = FileID::get(Record[0]); |
| 2304 | break; |
| 2305 | |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2306 | case ORIGINAL_PCH_DIR: |
| 2307 | // The primary AST will be the last to get here, so it will be the one |
| 2308 | // that's used. |
| 2309 | OriginalDir.assign(BlobStart, BlobLen); |
| 2310 | break; |
| 2311 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2312 | case VERSION_CONTROL_BRANCH_REVISION: { |
Ted Kremenek | 8bd0929 | 2010-02-12 23:31:14 +0000 | [diff] [blame] | 2313 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2314 | StringRef ASTBranch(BlobStart, BlobLen); |
| 2315 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2316 | Diag(diag::warn_pch_different_branch) << ASTBranch << CurBranch; |
Douglas Gregor | d54f3a1 | 2009-10-05 21:07:28 +0000 | [diff] [blame] | 2317 | return IgnorePCH; |
| 2318 | } |
| 2319 | break; |
| 2320 | } |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2321 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2322 | case MACRO_DEFINITION_OFFSETS: { |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2323 | F.MacroDefinitionOffsets = (const uint32_t *)BlobStart; |
| 2324 | F.NumPreallocatedPreprocessingEntities = Record[0]; |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2325 | unsigned LocalBasePreprocessedEntityID = Record[1]; |
| 2326 | F.LocalNumMacroDefinitions = Record[2]; |
| 2327 | unsigned LocalBaseMacroID = Record[3]; |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2328 | |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2329 | unsigned StartingID; |
| 2330 | if (PP) { |
| 2331 | if (!PP->getPreprocessingRecord()) |
| 2332 | PP->createPreprocessingRecord(true); |
| 2333 | if (!PP->getPreprocessingRecord()->getExternalSource()) |
| 2334 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2335 | StartingID |
| 2336 | = PP->getPreprocessingRecord() |
| 2337 | ->allocateLoadedEntities(F.NumPreallocatedPreprocessingEntities); |
| 2338 | } else { |
| 2339 | // FIXME: We'll eventually want to kill this path, since it assumes |
| 2340 | // a particular allocation strategy in the preprocessing record. |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2341 | StartingID = getTotalNumPreprocessedEntities() |
| 2342 | - F.NumPreallocatedPreprocessingEntities; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2343 | } |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 2344 | F.BaseMacroDefinitionID = getTotalNumMacroDefinitions(); |
| 2345 | F.BasePreprocessedEntityID = StartingID; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2347 | if (F.NumPreallocatedPreprocessingEntities > 0) { |
| 2348 | // Introduce the global -> local mapping for preprocessed entities in |
| 2349 | // this module. |
| 2350 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 2351 | |
| 2352 | // Introduce the local -> global mapping for preprocessed entities in |
| 2353 | // this module. |
| 2354 | F.PreprocessedEntityRemap.insert( |
| 2355 | std::make_pair(LocalBasePreprocessedEntityID, |
| 2356 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 2357 | } |
| 2358 | |
| 2359 | |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2360 | if (F.LocalNumMacroDefinitions > 0) { |
| 2361 | // Introduce the global -> local mapping for macro definitions within |
| 2362 | // this module. |
| 2363 | GlobalMacroDefinitionMap.insert( |
| 2364 | std::make_pair(getTotalNumMacroDefinitions() + 1, &F)); |
| 2365 | |
| 2366 | // Introduce the local -> global mapping for macro definitions within |
| 2367 | // this module. |
| 2368 | F.MacroDefinitionRemap.insert( |
| 2369 | std::make_pair(LocalBaseMacroID, |
| 2370 | F.BaseMacroDefinitionID - LocalBaseMacroID)); |
| 2371 | |
| 2372 | MacroDefinitionsLoaded.resize( |
Douglas Gregor | 270e014 | 2011-07-20 01:29:15 +0000 | [diff] [blame] | 2373 | MacroDefinitionsLoaded.size() + F.LocalNumMacroDefinitions); |
Douglas Gregor | a863b4b | 2011-08-04 16:36:56 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2376 | break; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2379 | case DECL_UPDATE_OFFSETS: { |
| 2380 | if (Record.size() % 2 != 0) { |
| 2381 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 2382 | return Failure; |
| 2383 | } |
| 2384 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2385 | DeclUpdateOffsets[getGlobalDeclID(F, Record[I])] |
| 2386 | .push_back(std::make_pair(&F, Record[I+1])); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | } |
| 2389 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2390 | case DECL_REPLACEMENTS: { |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2391 | if (Record.size() % 2 != 0) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2392 | Error("invalid DECL_REPLACEMENTS block in AST file"); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2393 | return Failure; |
| 2394 | } |
| 2395 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2396 | ReplacedDecls[getGlobalDeclID(F, Record[I])] |
| 2397 | = std::make_pair(&F, Record[I+1]); |
Sebastian Redl | e7c1fe6 | 2010-08-13 00:28:03 +0000 | [diff] [blame] | 2398 | break; |
| 2399 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 2400 | |
| 2401 | case OBJC_CHAINED_CATEGORIES: { |
| 2402 | if (Record.size() % 3 != 0) { |
| 2403 | Error("invalid OBJC_CHAINED_CATEGORIES block in AST file"); |
| 2404 | return Failure; |
| 2405 | } |
| 2406 | for (unsigned I = 0, N = Record.size(); I != N; I += 3) { |
| 2407 | serialization::GlobalDeclID GlobID = getGlobalDeclID(F, Record[I]); |
| 2408 | F.ChainedObjCCategories[GlobID] = std::make_pair(Record[I+1], |
| 2409 | Record[I+2]); |
| 2410 | ObjCChainedCategoriesInterfaces.insert(GlobID); |
| 2411 | } |
| 2412 | break; |
| 2413 | } |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2414 | |
| 2415 | case CXX_BASE_SPECIFIER_OFFSETS: { |
| 2416 | if (F.LocalNumCXXBaseSpecifiers != 0) { |
| 2417 | Error("duplicate CXX_BASE_SPECIFIER_OFFSETS record in AST file"); |
| 2418 | return Failure; |
| 2419 | } |
| 2420 | |
| 2421 | F.LocalNumCXXBaseSpecifiers = Record[0]; |
| 2422 | F.CXXBaseSpecifiersOffsets = (const uint32_t *)BlobStart; |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 2423 | NumCXXBaseSpecifiersLoaded += F.LocalNumCXXBaseSpecifiers; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 2424 | break; |
| 2425 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2426 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2427 | case DIAG_PRAGMA_MAPPINGS: |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2428 | if (Record.size() % 2 != 0) { |
| 2429 | Error("invalid DIAG_USER_MAPPINGS block in AST file"); |
| 2430 | return Failure; |
| 2431 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2432 | |
| 2433 | if (F.PragmaDiagMappings.empty()) |
| 2434 | F.PragmaDiagMappings.swap(Record); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2435 | else |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2436 | F.PragmaDiagMappings.insert(F.PragmaDiagMappings.end(), |
| 2437 | Record.begin(), Record.end()); |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2438 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2439 | |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2440 | case CUDA_SPECIAL_DECL_REFS: |
| 2441 | // Later tables overwrite earlier ones. |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2442 | // FIXME: Modules will have trouble with this. |
| 2443 | CUDASpecialDeclRefs.clear(); |
| 2444 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2445 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2446 | break; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2447 | |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2448 | case HEADER_SEARCH_TABLE: { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2449 | F.HeaderFileInfoTableData = BlobStart; |
| 2450 | F.LocalNumHeaderFileInfos = Record[1]; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2451 | F.HeaderFileFrameworkStrings = BlobStart + Record[2]; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2452 | if (Record[0]) { |
| 2453 | F.HeaderFileInfoTable |
| 2454 | = HeaderFileInfoLookupTable::Create( |
| 2455 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2456 | (const unsigned char *)F.HeaderFileInfoTableData, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 2457 | HeaderFileInfoTrait(*this, F, |
| 2458 | PP? &PP->getHeaderSearchInfo() : 0, |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2459 | BlobStart + Record[2])); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2460 | if (PP) |
| 2461 | PP->getHeaderSearchInfo().SetExternalSource(this); |
| 2462 | } |
| 2463 | break; |
Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 2466 | case FP_PRAGMA_OPTIONS: |
| 2467 | // Later tables overwrite earlier ones. |
| 2468 | FPPragmaOptions.swap(Record); |
| 2469 | break; |
| 2470 | |
| 2471 | case OPENCL_EXTENSIONS: |
| 2472 | // Later tables overwrite earlier ones. |
| 2473 | OpenCLExtensions.swap(Record); |
| 2474 | break; |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2475 | |
| 2476 | case TENTATIVE_DEFINITIONS: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2477 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2478 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 2479 | break; |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2480 | |
| 2481 | case KNOWN_NAMESPACES: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 2482 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2483 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 2484 | break; |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 2485 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2486 | } |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2487 | Error("premature end of bitstream in AST file"); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2488 | return Failure; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2491 | ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) { |
| 2492 | llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor; |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2493 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2494 | for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) { |
| 2495 | SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]); |
| 2496 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 2497 | if (Code == llvm::bitc::END_BLOCK || |
| 2498 | Code == llvm::bitc::ENTER_SUBBLOCK || |
| 2499 | Code == llvm::bitc::DEFINE_ABBREV) { |
| 2500 | Error("incorrectly-formatted source location entry in AST file"); |
| 2501 | return Failure; |
| 2502 | } |
| 2503 | |
| 2504 | RecordData Record; |
| 2505 | const char *BlobStart; |
| 2506 | unsigned BlobLen; |
| 2507 | switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) { |
| 2508 | default: |
| 2509 | Error("incorrectly-formatted source location entry in AST file"); |
| 2510 | return Failure; |
| 2511 | |
| 2512 | case SM_SLOC_FILE_ENTRY: { |
| 2513 | StringRef Filename(BlobStart, BlobLen); |
| 2514 | const FileEntry *File = getFileEntry(Filename); |
| 2515 | |
| 2516 | if (File == 0) { |
| 2517 | std::string ErrorStr = "could not find file '"; |
| 2518 | ErrorStr += Filename; |
| 2519 | ErrorStr += "' referenced by AST file"; |
| 2520 | Error(ErrorStr.c_str()); |
| 2521 | return IgnorePCH; |
| 2522 | } |
| 2523 | |
| 2524 | if (Record.size() < 6) { |
| 2525 | Error("source location entry is incorrect"); |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2526 | return Failure; |
| 2527 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2528 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2529 | // The stat info from the FileEntry came from the cached stat |
| 2530 | // info of the PCH, so we cannot trust it. |
| 2531 | struct stat StatBuf; |
| 2532 | if (::stat(File->getName(), &StatBuf) != 0) { |
| 2533 | StatBuf.st_size = File->getSize(); |
| 2534 | StatBuf.st_mtime = File->getModificationTime(); |
| 2535 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2536 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2537 | if (((off_t)Record[4] != StatBuf.st_size |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2538 | #if !defined(LLVM_ON_WIN32) |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2539 | // In our regression testing, the Windows file system seems to |
| 2540 | // have inconsistent modification times that sometimes |
| 2541 | // erroneously trigger this error-handling path. |
| 2542 | || (time_t)Record[5] != StatBuf.st_mtime |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2543 | #endif |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2544 | )) { |
| 2545 | Error(diag::err_fe_pch_file_modified, Filename); |
| 2546 | return IgnorePCH; |
| 2547 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2548 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
Argyrios Kyrtzidis | 460132d | 2011-06-01 05:43:53 +0000 | [diff] [blame] | 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | return Success; |
| 2555 | } |
| 2556 | |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2557 | namespace { |
| 2558 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 2559 | class IdentifierLookupVisitor { |
| 2560 | StringRef Name; |
| 2561 | IdentifierInfo *Found; |
| 2562 | public: |
| 2563 | explicit IdentifierLookupVisitor(StringRef Name) : Name(Name), Found() { } |
| 2564 | |
| 2565 | static bool visit(Module &M, void *UserData) { |
| 2566 | IdentifierLookupVisitor *This |
| 2567 | = static_cast<IdentifierLookupVisitor *>(UserData); |
| 2568 | |
| 2569 | ASTIdentifierLookupTable *IdTable |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 2570 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2571 | if (!IdTable) |
| 2572 | return false; |
| 2573 | |
| 2574 | std::pair<const char*, unsigned> Key(This->Name.begin(), |
| 2575 | This->Name.size()); |
| 2576 | ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key); |
| 2577 | if (Pos == IdTable->end()) |
| 2578 | return false; |
| 2579 | |
| 2580 | // Dereferencing the iterator has the effect of building the |
| 2581 | // IdentifierInfo node and populating it with the various |
| 2582 | // declarations it needs. |
| 2583 | This->Found = *Pos; |
| 2584 | return true; |
| 2585 | } |
| 2586 | |
| 2587 | // \brief Retrieve the identifier info found within the module |
| 2588 | // files. |
| 2589 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 2590 | }; |
| 2591 | } |
| 2592 | |
| 2593 | |
Sebastian Redl | 009e7f2 | 2010-10-05 16:15:19 +0000 | [diff] [blame] | 2594 | ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2595 | ModuleKind Type) { |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2596 | switch(ReadASTCore(FileName, Type, /*ImportedBy=*/0)) { |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2597 | case Failure: return Failure; |
| 2598 | case IgnorePCH: return IgnorePCH; |
| 2599 | case Success: break; |
| 2600 | } |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2601 | |
| 2602 | // 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] | 2603 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2604 | // Check the predefines buffers. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2605 | if (!DisableValidation && Type != MK_Module && CheckPredefinesBuffers()) |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2606 | return IgnorePCH; |
| 2607 | |
| 2608 | if (PP) { |
| 2609 | // Initialization of keywords and pragmas occurs before the |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2610 | // AST file is read, so there may be some identifiers that were |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2611 | // loaded into the IdentifierTable before we intercepted the |
| 2612 | // creation of identifiers. Iterate through the list of known |
| 2613 | // identifiers and determine whether we have to establish |
| 2614 | // preprocessor definitions or top-level identifier declaration |
| 2615 | // chains for those identifiers. |
| 2616 | // |
| 2617 | // We copy the IdentifierInfo pointers to a small vector first, |
| 2618 | // since de-serializing declarations or macro definitions can add |
| 2619 | // new entries into the identifier table, invalidating the |
| 2620 | // iterators. |
Douglas Gregor | 9125bd6 | 2011-07-27 16:30:06 +0000 | [diff] [blame] | 2621 | // |
| 2622 | // FIXME: We need a lazier way to load this information, e.g., by marking |
| 2623 | // the identifier data as 'dirty', so that it will be looked up in the |
| 2624 | // AST file(s) if it is uttered in the source. This could save us some |
| 2625 | // module load time. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2626 | SmallVector<IdentifierInfo *, 128> Identifiers; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2627 | for (IdentifierTable::iterator Id = PP->getIdentifierTable().begin(), |
| 2628 | IdEnd = PP->getIdentifierTable().end(); |
| 2629 | Id != IdEnd; ++Id) |
| 2630 | Identifiers.push_back(Id->second); |
Douglas Gregor | d09937f | 2011-08-25 21:19:59 +0000 | [diff] [blame] | 2631 | |
| 2632 | for (unsigned I = 0, N = Identifiers.size(); I != N; ++I) { |
| 2633 | IdentifierLookupVisitor Visitor(Identifiers[I]->getName()); |
| 2634 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | if (Context) |
| 2639 | InitializeContext(*Context); |
| 2640 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 2641 | if (DeserializationListener) |
| 2642 | DeserializationListener->ReaderInitialized(this); |
| 2643 | |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2644 | // If this AST file is a precompiled preamble, then set the main file ID of |
| 2645 | // the source manager to the file source file from which the preamble was |
| 2646 | // built. This is the only valid way to use a precompiled preamble. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2647 | if (Type == MK_Preamble) { |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2648 | if (OriginalFileID.isInvalid()) { |
| 2649 | SourceLocation Loc |
| 2650 | = SourceMgr.getLocation(FileMgr.getFile(getOriginalSourceFile()), 1, 1); |
| 2651 | if (Loc.isValid()) |
| 2652 | OriginalFileID = SourceMgr.getDecomposedLoc(Loc).first; |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2653 | } |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2654 | else { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 2655 | OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2656 | + OriginalFileID.getOpaqueValue() - 1); |
| 2657 | } |
| 2658 | |
Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 2659 | if (!OriginalFileID.isInvalid()) |
| 2660 | SourceMgr.SetPreambleFileID(OriginalFileID); |
Douglas Gregor | 936a5b4 | 2010-11-30 05:23:00 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2663 | return Success; |
| 2664 | } |
| 2665 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2666 | ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName, |
Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 2667 | ModuleKind Type, |
| 2668 | Module *ImportedBy) { |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2669 | Module *M; |
| 2670 | bool NewModule; |
| 2671 | std::string ErrorStr; |
| 2672 | llvm::tie(M, NewModule) = ModuleMgr.addModule(FileName, Type, ImportedBy, |
| 2673 | ErrorStr); |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2674 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2675 | if (!M) { |
| 2676 | // We couldn't load the module. |
| 2677 | std::string Msg = "Unable to load module \"" + FileName.str() + "\": " |
| 2678 | + ErrorStr; |
| 2679 | Error(Msg); |
| 2680 | return Failure; |
| 2681 | } |
| 2682 | |
| 2683 | if (!NewModule) { |
| 2684 | // We've already loaded this module. |
| 2685 | return Success; |
| 2686 | } |
| 2687 | |
| 2688 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 2689 | // module? |
Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 2690 | if (FileName != "-") { |
| 2691 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 2692 | if (CurrentDir.empty()) CurrentDir = "."; |
| 2693 | } |
| 2694 | |
Douglas Gregor | 4dd3e94 | 2011-08-19 02:29:29 +0000 | [diff] [blame] | 2695 | Module &F = *M; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2696 | llvm::BitstreamCursor &Stream = F.Stream; |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2697 | Stream.init(F.StreamFile); |
Sebastian Redl | fa06144 | 2010-07-21 20:07:32 +0000 | [diff] [blame] | 2698 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2699 | |
Sebastian Redl | c2e6dbf | 2010-07-17 00:12:06 +0000 | [diff] [blame] | 2700 | // Sniff for the signature. |
| 2701 | if (Stream.Read(8) != 'C' || |
| 2702 | Stream.Read(8) != 'P' || |
| 2703 | Stream.Read(8) != 'C' || |
| 2704 | Stream.Read(8) != 'H') { |
| 2705 | Diag(diag::err_not_a_pch_file) << FileName; |
| 2706 | return Failure; |
| 2707 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2708 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2709 | while (!Stream.AtEndOfStream()) { |
| 2710 | unsigned Code = Stream.ReadCode(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2711 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2712 | if (Code != llvm::bitc::ENTER_SUBBLOCK) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2713 | Error("invalid record at top-level of AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2714 | return Failure; |
| 2715 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2716 | |
| 2717 | unsigned BlockID = Stream.ReadSubBlockID(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 2718 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2719 | // We only know the AST subblock ID. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2720 | switch (BlockID) { |
| 2721 | case llvm::bitc::BLOCKINFO_BLOCK_ID: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2722 | if (Stream.ReadBlockInfoBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2723 | Error("malformed BlockInfoBlock in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2724 | return Failure; |
| 2725 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2726 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2727 | case AST_BLOCK_ID: |
Sebastian Redl | 3e31c72 | 2010-08-18 23:56:56 +0000 | [diff] [blame] | 2728 | switch (ReadASTBlock(F)) { |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2729 | case Success: |
| 2730 | break; |
| 2731 | |
| 2732 | case Failure: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2733 | return Failure; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2734 | |
| 2735 | case IgnorePCH: |
Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 2736 | // FIXME: We could consider reading through to the end of this |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2737 | // AST block, skipping subblocks, to see if there are other |
| 2738 | // AST blocks elsewhere. |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2739 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2740 | // FIXME: We can't clear loaded slocentries anymore. |
| 2741 | //SourceMgr.ClearPreallocatedSLocEntries(); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2742 | |
| 2743 | // Remove the stat cache. |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 2744 | if (F.StatCache) |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2745 | FileMgr.removeStatCache((ASTStatCache*)F.StatCache); |
Douglas Gregor | 0bc1293 | 2009-04-27 21:28:04 +0000 | [diff] [blame] | 2746 | |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2747 | return IgnorePCH; |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 2748 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2749 | break; |
| 2750 | default: |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2751 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2752 | Error("malformed block record in AST file"); |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 2753 | return Failure; |
| 2754 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2757 | } |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2758 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 2759 | // 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] | 2760 | // bits of all files we've seen. |
| 2761 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 2762 | TotalModulesSizeInBits += F.SizeInBits; |
| 2763 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2764 | |
| 2765 | // Make sure that the files this module was built against are still available. |
| 2766 | if (!DisableValidation) { |
| 2767 | switch(validateFileEntries(*M)) { |
| 2768 | case Failure: return Failure; |
| 2769 | case IgnorePCH: return IgnorePCH; |
| 2770 | case Success: break; |
| 2771 | } |
| 2772 | } |
Douglas Gregor | a918bab | 2011-08-25 21:09:44 +0000 | [diff] [blame] | 2773 | |
| 2774 | // Preload SLocEntries. |
| 2775 | for (unsigned I = 0, N = M->PreloadSLocEntries.size(); I != N; ++I) { |
| 2776 | int Index = int(M->PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 2777 | ASTReadResult Result = ReadSLocEntryRecord(Index); |
| 2778 | if (Result != Success) |
| 2779 | return Failure; |
| 2780 | } |
| 2781 | |
Douglas Gregor | 2fdb6b5 | 2011-08-25 20:58:51 +0000 | [diff] [blame] | 2782 | |
Sebastian Redl | 2abc038 | 2010-07-16 20:41:52 +0000 | [diff] [blame] | 2783 | return Success; |
| 2784 | } |
| 2785 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2786 | void ASTReader::setPreprocessor(Preprocessor &pp) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2787 | PP = &pp; |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2788 | |
| 2789 | if (unsigned N = getTotalNumPreprocessedEntities()) { |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2790 | if (!PP->getPreprocessingRecord()) |
Douglas Gregor | 998caea | 2011-05-06 16:33:08 +0000 | [diff] [blame] | 2791 | PP->createPreprocessingRecord(true); |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2792 | PP->getPreprocessingRecord()->SetExternalSource(*this); |
| 2793 | PP->getPreprocessingRecord()->allocateLoadedEntities(N); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2794 | } |
Douglas Gregor | 4a9c39a | 2011-07-21 00:47:40 +0000 | [diff] [blame] | 2795 | |
| 2796 | PP->getHeaderSearchInfo().SetExternalLookup(this); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 2797 | PP->getHeaderSearchInfo().SetExternalSource(this); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2800 | void ASTReader::InitializeContext(ASTContext &Ctx) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2801 | Context = &Ctx; |
| 2802 | assert(Context && "Passed null context!"); |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 2803 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2804 | assert(PP && "Forgot to set Preprocessor ?"); |
| 2805 | PP->getIdentifierTable().setExternalIdentifierLookup(this); |
Douglas Gregor | 9882a5a | 2010-01-04 19:18:44 +0000 | [diff] [blame] | 2806 | PP->setExternalSource(this); |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 2807 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2808 | // If we have any update blocks for the TU waiting, we have to add |
| 2809 | // them before we deserialize anything. |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2810 | TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl(); |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 2811 | for (ModuleIterator M = ModuleMgr.begin(), MEnd = ModuleMgr.end(); |
| 2812 | M != MEnd; ++M) { |
| 2813 | Module::DeclContextInfosMap::iterator DCU |
| 2814 | = (*M)->DeclContextInfos.find(0); |
| 2815 | if (DCU != (*M)->DeclContextInfos.end()) { |
| 2816 | // Insertion could invalidate map, so grab value first. |
| 2817 | DeclContextInfo Info = DCU->second; |
| 2818 | (*M)->DeclContextInfos.erase(DCU); |
| 2819 | (*M)->DeclContextInfos[TU] = Info; |
| 2820 | } |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2821 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2822 | |
| 2823 | // If there's a listener, notify them that we "read" the translation unit. |
| 2824 | if (DeserializationListener) |
| 2825 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
Douglas Gregor | aa43301 | 2010-10-01 01:18:02 +0000 | [diff] [blame] | 2826 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 2827 | // Make sure we load the declaration update records for the translation unit, |
| 2828 | // if there are any. |
| 2829 | loadDeclUpdateRecords(PREDEF_DECL_TRANSLATION_UNIT_ID, TU); |
| 2830 | |
| 2831 | // Note that the translation unit has external lexical and visible storage. |
| 2832 | TU->setHasExternalLexicalStorage(true); |
| 2833 | TU->setHasExternalVisibleStorage(true); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2834 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2835 | // FIXME: Find a better way to deal with collisions between these |
| 2836 | // built-in types. Right now, we just ignore the problem. |
| 2837 | |
| 2838 | // Load the special types. |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2839 | if (Context->getBuiltinVaListType().isNull()) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2840 | Context->setBuiltinVaListType( |
| 2841 | GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2844 | if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) { |
| 2845 | if (Context->ObjCProtoType.isNull()) |
Douglas Gregor | 09c4aa8 | 2011-08-11 22:04:35 +0000 | [diff] [blame] | 2846 | Context->ObjCProtoType = GetType(Proto); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2847 | } |
| 2848 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2849 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 2850 | if (!Context->CFConstantStringTypeDecl) |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2851 | Context->setCFConstantStringType(GetType(String)); |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 2855 | QualType FileType = GetType(File); |
| 2856 | if (FileType.isNull()) { |
| 2857 | Error("FILE type is NULL"); |
| 2858 | return; |
| 2859 | } |
| 2860 | |
| 2861 | if (!Context->FILEDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2862 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 2863 | Context->setFILEDecl(Typedef->getDecl()); |
| 2864 | else { |
| 2865 | const TagType *Tag = FileType->getAs<TagType>(); |
| 2866 | if (!Tag) { |
| 2867 | Error("Invalid FILE type in AST file"); |
| 2868 | return; |
| 2869 | } |
| 2870 | Context->setFILEDecl(Tag->getDecl()); |
| 2871 | } |
Douglas Gregor | 27821ce | 2009-07-07 16:35:42 +0000 | [diff] [blame] | 2872 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) { |
| 2876 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 2877 | if (Jmp_bufType.isNull()) { |
| 2878 | Error("jmp_buf type is NULL"); |
| 2879 | return; |
| 2880 | } |
| 2881 | |
| 2882 | if (!Context->jmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2883 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 2884 | Context->setjmp_bufDecl(Typedef->getDecl()); |
| 2885 | else { |
| 2886 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 2887 | if (!Tag) { |
| 2888 | Error("Invalid jmp_buf type in AST file"); |
| 2889 | return; |
| 2890 | } |
| 2891 | Context->setjmp_bufDecl(Tag->getDecl()); |
| 2892 | } |
Mike Stump | a4de80b | 2009-07-28 02:25:19 +0000 | [diff] [blame] | 2893 | } |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) { |
| 2897 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 2898 | if (Sigjmp_bufType.isNull()) { |
| 2899 | Error("sigjmp_buf type is NULL"); |
| 2900 | return; |
| 2901 | } |
| 2902 | |
| 2903 | if (!Context->sigjmp_bufDecl) { |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2904 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 2905 | Context->setsigjmp_bufDecl(Typedef->getDecl()); |
| 2906 | else { |
| 2907 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 2908 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 2909 | Context->setsigjmp_bufDecl(Tag->getDecl()); |
| 2910 | } |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 2911 | } |
Jonathan D. Turner | f07f131 | 2011-08-05 23:07:10 +0000 | [diff] [blame] | 2912 | } |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 2913 | |
Douglas Gregor | aa8a827 | 2011-08-11 22:18:49 +0000 | [diff] [blame] | 2914 | if (unsigned ObjCIdRedef |
| 2915 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 2916 | if (Context->ObjCIdRedefinitionType.isNull()) |
| 2917 | Context->ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 2918 | } |
| 2919 | |
| 2920 | if (unsigned ObjCClassRedef |
| 2921 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 2922 | if (Context->ObjCClassRedefinitionType.isNull()) |
| 2923 | Context->ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 2924 | } |
| 2925 | |
| 2926 | if (unsigned ObjCSelRedef |
| 2927 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 2928 | if (Context->ObjCSelRedefinitionType.isNull()) |
| 2929 | Context->ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 2930 | } |
| 2931 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2932 | ReadPragmaDiagnosticMappings(Context->getDiagnostics()); |
Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 2933 | |
| 2934 | // If there were any CUDA special declarations, deserialize them. |
| 2935 | if (!CUDASpecialDeclRefs.empty()) { |
| 2936 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 2937 | Context->setcudaConfigureCallDecl( |
| 2938 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 2939 | } |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2942 | /// \brief Retrieve the name of the original source file name |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2943 | /// directly from the AST file, without actually loading the AST |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2944 | /// file. |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2945 | std::string ASTReader::getOriginalSourceFile(const std::string &ASTFileName, |
Argyrios Kyrtzidis | 71731d6 | 2010-11-03 22:45:23 +0000 | [diff] [blame] | 2946 | FileManager &FileMgr, |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2947 | Diagnostic &Diags) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2948 | // Open the AST file. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2949 | std::string ErrStr; |
| 2950 | llvm::OwningPtr<llvm::MemoryBuffer> Buffer; |
Chris Lattner | 5159f61 | 2010-11-23 08:35:12 +0000 | [diff] [blame] | 2951 | Buffer.reset(FileMgr.getBufferForFile(ASTFileName, &ErrStr)); |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2952 | if (!Buffer) { |
Daniel Dunbar | 3b95148 | 2009-12-03 09:13:06 +0000 | [diff] [blame] | 2953 | Diags.Report(diag::err_fe_unable_to_read_pch_file) << ErrStr; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2954 | return std::string(); |
| 2955 | } |
| 2956 | |
| 2957 | // Initialize the stream |
| 2958 | llvm::BitstreamReader StreamFile; |
| 2959 | llvm::BitstreamCursor Stream; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2960 | StreamFile.init((const unsigned char *)Buffer->getBufferStart(), |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2961 | (const unsigned char *)Buffer->getBufferEnd()); |
| 2962 | Stream.init(StreamFile); |
| 2963 | |
| 2964 | // Sniff for the signature. |
| 2965 | if (Stream.Read(8) != 'C' || |
| 2966 | Stream.Read(8) != 'P' || |
| 2967 | Stream.Read(8) != 'C' || |
| 2968 | Stream.Read(8) != 'H') { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2969 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2970 | return std::string(); |
| 2971 | } |
| 2972 | |
| 2973 | RecordData Record; |
| 2974 | while (!Stream.AtEndOfStream()) { |
| 2975 | unsigned Code = Stream.ReadCode(); |
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 | if (Code == llvm::bitc::ENTER_SUBBLOCK) { |
| 2978 | unsigned BlockID = Stream.ReadSubBlockID(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2979 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2980 | // We only know the AST subblock ID. |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2981 | switch (BlockID) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2982 | case AST_BLOCK_ID: |
| 2983 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2984 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2985 | return std::string(); |
| 2986 | } |
| 2987 | break; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2988 | |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2989 | default: |
| 2990 | if (Stream.SkipBlock()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 2991 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 2992 | return std::string(); |
| 2993 | } |
| 2994 | break; |
| 2995 | } |
| 2996 | continue; |
| 2997 | } |
| 2998 | |
| 2999 | if (Code == llvm::bitc::END_BLOCK) { |
| 3000 | if (Stream.ReadBlockEnd()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3001 | Diags.Report(diag::err_fe_pch_error_at_end_block) << ASTFileName; |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3002 | return std::string(); |
| 3003 | } |
| 3004 | continue; |
| 3005 | } |
| 3006 | |
| 3007 | if (Code == llvm::bitc::DEFINE_ABBREV) { |
| 3008 | Stream.ReadAbbrevRecord(); |
| 3009 | continue; |
| 3010 | } |
| 3011 | |
| 3012 | Record.clear(); |
| 3013 | const char *BlobStart = 0; |
| 3014 | unsigned BlobLen = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3015 | if (Stream.ReadRecord(Code, Record, &BlobStart, &BlobLen) |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3016 | == ORIGINAL_FILE_NAME) |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3017 | return std::string(BlobStart, BlobLen); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | } |
Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 3019 | |
| 3020 | return std::string(); |
| 3021 | } |
| 3022 | |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3023 | /// \brief Parse the record that corresponds to a LangOptions data |
| 3024 | /// structure. |
| 3025 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3026 | /// This routine parses the language options from the AST file and then gives |
| 3027 | /// them to the AST listener if one is set. |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3028 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3029 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3030 | bool ASTReader::ParseLanguageOptions( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3031 | const SmallVectorImpl<uint64_t> &Record) { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3032 | if (Listener) { |
| 3033 | LangOptions LangOpts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3034 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3035 | #define PARSE_LANGOPT(Option) \ |
| 3036 | LangOpts.Option = Record[Idx]; \ |
| 3037 | ++Idx |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3038 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3039 | unsigned Idx = 0; |
| 3040 | PARSE_LANGOPT(Trigraphs); |
| 3041 | PARSE_LANGOPT(BCPLComment); |
| 3042 | PARSE_LANGOPT(DollarIdents); |
| 3043 | PARSE_LANGOPT(AsmPreprocessor); |
| 3044 | PARSE_LANGOPT(GNUMode); |
Chandler Carruth | e03aa55 | 2010-04-17 20:17:31 +0000 | [diff] [blame] | 3045 | PARSE_LANGOPT(GNUKeywords); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3046 | PARSE_LANGOPT(ImplicitInt); |
| 3047 | PARSE_LANGOPT(Digraphs); |
| 3048 | PARSE_LANGOPT(HexFloats); |
| 3049 | PARSE_LANGOPT(C99); |
Peter Collingbourne | a686b5f | 2011-04-15 00:35:23 +0000 | [diff] [blame] | 3050 | PARSE_LANGOPT(C1X); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3051 | PARSE_LANGOPT(Microsoft); |
| 3052 | PARSE_LANGOPT(CPlusPlus); |
| 3053 | PARSE_LANGOPT(CPlusPlus0x); |
| 3054 | PARSE_LANGOPT(CXXOperatorNames); |
| 3055 | PARSE_LANGOPT(ObjC1); |
| 3056 | PARSE_LANGOPT(ObjC2); |
| 3057 | PARSE_LANGOPT(ObjCNonFragileABI); |
Fariborz Jahanian | 4587803 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 3058 | PARSE_LANGOPT(ObjCNonFragileABI2); |
Fariborz Jahanian | 13f3b2f | 2011-01-07 18:59:25 +0000 | [diff] [blame] | 3059 | PARSE_LANGOPT(AppleKext); |
Ted Kremenek | 1d56c9e | 2010-12-23 21:35:43 +0000 | [diff] [blame] | 3060 | PARSE_LANGOPT(ObjCDefaultSynthProperties); |
Douglas Gregor | a860e6a | 2011-06-14 23:20:43 +0000 | [diff] [blame] | 3061 | PARSE_LANGOPT(ObjCInferRelatedResultType); |
Fariborz Jahanian | 62c5602 | 2010-04-22 21:01:59 +0000 | [diff] [blame] | 3062 | PARSE_LANGOPT(NoConstantCFStrings); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3063 | PARSE_LANGOPT(PascalStrings); |
| 3064 | PARSE_LANGOPT(WritableStrings); |
| 3065 | PARSE_LANGOPT(LaxVectorConversions); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3066 | PARSE_LANGOPT(AltiVec); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3067 | PARSE_LANGOPT(Exceptions); |
Anders Carlsson | ce8dd3a | 2011-02-19 23:53:54 +0000 | [diff] [blame] | 3068 | PARSE_LANGOPT(ObjCExceptions); |
Anders Carlsson | 6bbd268 | 2011-02-23 03:04:54 +0000 | [diff] [blame] | 3069 | PARSE_LANGOPT(CXXExceptions); |
| 3070 | PARSE_LANGOPT(SjLjExceptions); |
Douglas Gregor | dbe3927 | 2011-02-01 15:15:22 +0000 | [diff] [blame] | 3071 | PARSE_LANGOPT(MSBitfields); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3072 | PARSE_LANGOPT(NeXTRuntime); |
| 3073 | PARSE_LANGOPT(Freestanding); |
| 3074 | PARSE_LANGOPT(NoBuiltin); |
| 3075 | PARSE_LANGOPT(ThreadsafeStatics); |
Douglas Gregor | b3286fe | 2009-09-03 14:36:33 +0000 | [diff] [blame] | 3076 | PARSE_LANGOPT(POSIXThreads); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3077 | PARSE_LANGOPT(Blocks); |
| 3078 | PARSE_LANGOPT(EmitAllDecls); |
| 3079 | PARSE_LANGOPT(MathErrno); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3080 | LangOpts.setSignedOverflowBehavior((LangOptions::SignedOverflowBehaviorTy) |
| 3081 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3082 | PARSE_LANGOPT(HeinousExtensions); |
| 3083 | PARSE_LANGOPT(Optimize); |
| 3084 | PARSE_LANGOPT(OptimizeSize); |
| 3085 | PARSE_LANGOPT(Static); |
| 3086 | PARSE_LANGOPT(PICLevel); |
| 3087 | PARSE_LANGOPT(GNUInline); |
| 3088 | PARSE_LANGOPT(NoInline); |
Chandler Carruth | 7ffce73 | 2011-04-23 20:05:38 +0000 | [diff] [blame] | 3089 | PARSE_LANGOPT(Deprecated); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3090 | PARSE_LANGOPT(AccessControl); |
| 3091 | PARSE_LANGOPT(CharIsSigned); |
John Thompson | ed4e295 | 2009-11-05 20:14:16 +0000 | [diff] [blame] | 3092 | PARSE_LANGOPT(ShortWChar); |
Argyrios Kyrtzidis | a88942a | 2011-01-15 02:56:16 +0000 | [diff] [blame] | 3093 | PARSE_LANGOPT(ShortEnums); |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3094 | LangOpts.setGCMode((LangOptions::GCMode)Record[Idx++]); |
John McCall | 457a04e | 2010-10-22 21:05:15 +0000 | [diff] [blame] | 3095 | LangOpts.setVisibilityMode((Visibility)Record[Idx++]); |
Daniel Dunbar | 143021e | 2009-09-21 04:16:19 +0000 | [diff] [blame] | 3096 | LangOpts.setStackProtectorMode((LangOptions::StackProtectorMode) |
Chris Lattner | 51924e51 | 2010-06-26 21:25:03 +0000 | [diff] [blame] | 3097 | Record[Idx++]); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3098 | PARSE_LANGOPT(InstantiationDepth); |
Nate Begeman | f291166 | 2009-06-25 23:01:11 +0000 | [diff] [blame] | 3099 | PARSE_LANGOPT(OpenCL); |
Peter Collingbourne | 546d079 | 2010-12-01 19:14:57 +0000 | [diff] [blame] | 3100 | PARSE_LANGOPT(CUDA); |
Mike Stump | d954638 | 2009-12-12 01:27:46 +0000 | [diff] [blame] | 3101 | PARSE_LANGOPT(CatchUndefined); |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3102 | PARSE_LANGOPT(DefaultFPContract); |
Roman Divacky | dc1f68d | 2011-03-01 17:36:40 +0000 | [diff] [blame] | 3103 | PARSE_LANGOPT(ElideConstructors); |
| 3104 | PARSE_LANGOPT(SpellChecking); |
Roman Divacky | 65b88cd | 2011-03-01 17:40:53 +0000 | [diff] [blame] | 3105 | PARSE_LANGOPT(MRTD); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3106 | PARSE_LANGOPT(ObjCAutoRefCount); |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3107 | #undef PARSE_LANGOPT |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3108 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 3109 | return Listener->ReadLanguageOptions(LangOpts); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3110 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 3111 | |
| 3112 | return false; |
| 3113 | } |
| 3114 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 3115 | namespace { |
| 3116 | /// \brief Visitor used by ASTReader::ReadPreprocessedEntities() to load |
| 3117 | /// all of the preprocessed entities within a module. |
| 3118 | class ReadPreprocessedEntitiesVisitor { |
| 3119 | ASTReader &Reader; |
| 3120 | |
| 3121 | public: |
| 3122 | explicit ReadPreprocessedEntitiesVisitor(ASTReader &Reader) |
| 3123 | : Reader(Reader) { } |
| 3124 | |
| 3125 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 3126 | if (Preorder) |
| 3127 | return false; |
| 3128 | |
| 3129 | ReadPreprocessedEntitiesVisitor *This |
| 3130 | = static_cast<ReadPreprocessedEntitiesVisitor *>(UserData); |
| 3131 | |
| 3132 | if (!M.PreprocessorDetailCursor.getBitStreamReader()) |
| 3133 | return false; |
| 3134 | |
| 3135 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 3136 | M.PreprocessorDetailCursor.JumpToBit(M.PreprocessorDetailStartOffset); |
| 3137 | while (This->Reader.LoadPreprocessedEntity(M)) { } |
| 3138 | return false; |
| 3139 | } |
| 3140 | }; |
| 3141 | } |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3142 | |
Douglas Gregor | 14f7716 | 2011-08-25 18:03:05 +0000 | [diff] [blame] | 3143 | void ASTReader::ReadPreprocessedEntities() { |
| 3144 | ReadPreprocessedEntitiesVisitor Visitor(*this); |
| 3145 | ModuleMgr.visitDepthFirst(&ReadPreprocessedEntitiesVisitor::visit, &Visitor); |
Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
Douglas Gregor | 46c5001 | 2011-02-11 19:46:30 +0000 | [diff] [blame] | 3148 | PreprocessedEntity *ASTReader::ReadPreprocessedEntityAtOffset(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3149 | RecordLocation Loc = getLocalBitOffset(Offset); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3150 | |
Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 3151 | // Keep track of where we are in the stream, then jump back there |
| 3152 | // after reading this entity. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 3153 | SavedStreamPosition SavedPosition(Loc.F->PreprocessorDetailCursor); |
| 3154 | Loc.F->PreprocessorDetailCursor.JumpToBit(Loc.Offset); |
| 3155 | return LoadPreprocessedEntity(*Loc.F); |
Douglas Gregor | f88e35b | 2010-11-30 06:16:57 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3158 | namespace { |
| 3159 | /// \brief Visitor used to search for information about a header file. |
| 3160 | class HeaderFileInfoVisitor { |
| 3161 | ASTReader &Reader; |
| 3162 | const FileEntry *FE; |
| 3163 | |
| 3164 | llvm::Optional<HeaderFileInfo> HFI; |
| 3165 | |
| 3166 | public: |
| 3167 | HeaderFileInfoVisitor(ASTReader &Reader, const FileEntry *FE) |
| 3168 | : Reader(Reader), FE(FE) { } |
| 3169 | |
| 3170 | static bool visit(Module &M, void *UserData) { |
| 3171 | HeaderFileInfoVisitor *This |
| 3172 | = static_cast<HeaderFileInfoVisitor *>(UserData); |
| 3173 | |
| 3174 | HeaderFileInfoTrait Trait(This->Reader, M, |
| 3175 | &This->Reader.getPreprocessor().getHeaderSearchInfo(), |
| 3176 | M.HeaderFileFrameworkStrings, |
| 3177 | This->FE->getName()); |
| 3178 | |
| 3179 | HeaderFileInfoLookupTable *Table |
| 3180 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 3181 | if (!Table) |
| 3182 | return false; |
| 3183 | |
| 3184 | // Look in the on-disk hash table for an entry for this file name. |
| 3185 | HeaderFileInfoLookupTable::iterator Pos = Table->find(This->FE->getName(), |
| 3186 | &Trait); |
| 3187 | if (Pos == Table->end()) |
| 3188 | return false; |
| 3189 | |
| 3190 | This->HFI = *Pos; |
| 3191 | return true; |
| 3192 | } |
| 3193 | |
| 3194 | llvm::Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 3195 | }; |
| 3196 | } |
| 3197 | |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3198 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3199 | HeaderFileInfoVisitor Visitor(*this, FE); |
| 3200 | ModuleMgr.visit(&HeaderFileInfoVisitor::visit, &Visitor); |
| 3201 | if (llvm::Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) { |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3202 | if (Listener) |
Douglas Gregor | 69e9464 | 2011-08-25 18:14:34 +0000 | [diff] [blame] | 3203 | Listener->ReadHeaderFileInfo(*HFI, FE->getUID()); |
| 3204 | return *HFI; |
Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | return HeaderFileInfo(); |
| 3208 | } |
| 3209 | |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3210 | void ASTReader::ReadPragmaDiagnosticMappings(Diagnostic &Diag) { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 3211 | for (ModuleIterator I = ModuleMgr.begin(), E = ModuleMgr.end(); I != E; ++I) { |
| 3212 | Module &F = *(*I); |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 3213 | unsigned Idx = 0; |
| 3214 | while (Idx < F.PragmaDiagMappings.size()) { |
| 3215 | SourceLocation Loc = ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 3216 | while (1) { |
| 3217 | assert(Idx < F.PragmaDiagMappings.size() && |
| 3218 | "Invalid data, didn't find '-1' marking end of diag/map pairs"); |
| 3219 | if (Idx >= F.PragmaDiagMappings.size()) { |
| 3220 | break; // Something is messed up but at least avoid infinite loop in |
| 3221 | // release build. |
| 3222 | } |
| 3223 | unsigned DiagID = F.PragmaDiagMappings[Idx++]; |
| 3224 | if (DiagID == (unsigned)-1) { |
| 3225 | break; // no more diag/map pairs for this location. |
| 3226 | } |
| 3227 | diag::Mapping Map = (diag::Mapping)F.PragmaDiagMappings[Idx++]; |
| 3228 | Diag.setDiagnosticMapping(DiagID, Map, Loc); |
| 3229 | } |
Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 3230 | } |
Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 3231 | } |
| 3232 | } |
| 3233 | |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3234 | /// \brief Get the correct cursor and offset for loading a type. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3235 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3236 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
Jonathan D. Turner | 3500568 | 2011-07-20 21:31:32 +0000 | [diff] [blame] | 3237 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 3238 | Module *M = I->second; |
Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3239 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /// \brief Read and return the type with the given index.. |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3243 | /// |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3244 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 3245 | /// routine actually reads the record corresponding to the type at the given |
| 3246 | /// location. It is a helper routine for GetType, which deals with reading type |
| 3247 | /// IDs. |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3248 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3249 | RecordLocation Loc = TypeCursorForIndex(Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3250 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Sebastian Redl | 3452281 | 2010-07-16 17:50:48 +0000 | [diff] [blame] | 3251 | |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3252 | // Keep track of where we are in the stream, then jump back there |
| 3253 | // after reading this type. |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3254 | SavedStreamPosition SavedPosition(DeclsCursor); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3255 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3256 | ReadingKindTracker ReadingKind(Read_Type, *this); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 3257 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3258 | // Note that we are loading a type record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3259 | Deserializing AType(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3260 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3261 | unsigned Idx = 0; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3262 | DeclsCursor.JumpToBit(Loc.Offset); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3263 | RecordData Record; |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3264 | unsigned Code = DeclsCursor.ReadCode(); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3265 | switch ((TypeCode)DeclsCursor.ReadRecord(Code, Record)) { |
| 3266 | case TYPE_EXT_QUAL: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3267 | if (Record.size() != 2) { |
| 3268 | Error("Incorrect encoding of extended qualifier type"); |
| 3269 | return QualType(); |
| 3270 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3271 | QualType Base = readType(*Loc.F, Record, Idx); |
| 3272 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3273 | return Context->getQualifiedType(Base, Quals); |
Douglas Gregor | 455b8f4 | 2009-04-15 22:00:08 +0000 | [diff] [blame] | 3274 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3275 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3276 | case TYPE_COMPLEX: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3277 | if (Record.size() != 1) { |
| 3278 | Error("Incorrect encoding of complex type"); |
| 3279 | return QualType(); |
| 3280 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3281 | QualType ElemType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3282 | return Context->getComplexType(ElemType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3283 | } |
| 3284 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3285 | case TYPE_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3286 | if (Record.size() != 1) { |
| 3287 | Error("Incorrect encoding of pointer type"); |
| 3288 | return QualType(); |
| 3289 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3290 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3291 | return Context->getPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3292 | } |
| 3293 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3294 | case TYPE_BLOCK_POINTER: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3295 | if (Record.size() != 1) { |
| 3296 | Error("Incorrect encoding of block pointer type"); |
| 3297 | return QualType(); |
| 3298 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3299 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3300 | return Context->getBlockPointerType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3301 | } |
| 3302 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3303 | case TYPE_LVALUE_REFERENCE: { |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3304 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3305 | Error("Incorrect encoding of lvalue reference type"); |
| 3306 | return QualType(); |
| 3307 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3308 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Richard Smith | 0f53846 | 2011-04-12 10:38:03 +0000 | [diff] [blame] | 3309 | return Context->getLValueReferenceType(PointeeType, Record[1]); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3312 | case TYPE_RVALUE_REFERENCE: { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3313 | if (Record.size() != 1) { |
| 3314 | Error("Incorrect encoding of rvalue reference type"); |
| 3315 | return QualType(); |
| 3316 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3317 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3318 | return Context->getRValueReferenceType(PointeeType); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3321 | case TYPE_MEMBER_POINTER: { |
Argyrios Kyrtzidis | ee776bc | 2010-07-02 11:55:15 +0000 | [diff] [blame] | 3322 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3323 | Error("Incorrect encoding of member pointer type"); |
| 3324 | return QualType(); |
| 3325 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3326 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 3327 | QualType ClassType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 3328 | if (PointeeType.isNull() || ClassType.isNull()) |
| 3329 | return QualType(); |
| 3330 | |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3331 | return Context->getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3332 | } |
| 3333 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3334 | case TYPE_CONSTANT_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3335 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3336 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3337 | unsigned IndexTypeQuals = Record[2]; |
| 3338 | unsigned Idx = 3; |
| 3339 | llvm::APInt Size = ReadAPInt(Record, Idx); |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3340 | return Context->getConstantArrayType(ElementType, Size, |
| 3341 | ASM, IndexTypeQuals); |
| 3342 | } |
| 3343 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3344 | case TYPE_INCOMPLETE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3345 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3346 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3347 | unsigned IndexTypeQuals = Record[2]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3348 | return Context->getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3351 | case TYPE_VARIABLE_ARRAY: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3352 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 3353 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 3354 | unsigned IndexTypeQuals = Record[2]; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3355 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 3356 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 3357 | return Context->getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
Douglas Gregor | 0431825 | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 3358 | ASM, IndexTypeQuals, |
| 3359 | SourceRange(LBLoc, RBLoc)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3362 | case TYPE_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3363 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3364 | Error("incorrect encoding of vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3365 | return QualType(); |
| 3366 | } |
| 3367 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3368 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3369 | unsigned NumElements = Record[1]; |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3370 | unsigned VecKind = Record[2]; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3371 | return Context->getVectorType(ElementType, NumElements, |
Bob Wilson | aeb5644 | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 3372 | (VectorType::VectorKind)VecKind); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3373 | } |
| 3374 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3375 | case TYPE_EXT_VECTOR: { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 3376 | if (Record.size() != 3) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3377 | Error("incorrect encoding of extended vector type in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3378 | return QualType(); |
| 3379 | } |
| 3380 | |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3381 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3382 | unsigned NumElements = Record[1]; |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3383 | return Context->getExtVectorType(ElementType, NumElements); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3384 | } |
| 3385 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3386 | case TYPE_FUNCTION_NO_PROTO: { |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3387 | if (Record.size() != 6) { |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 3388 | Error("incorrect encoding of no-proto function type"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3389 | return QualType(); |
| 3390 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3391 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3392 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| 3393 | (CallingConv)Record[4], Record[5]); |
Rafael Espindola | c50c27c | 2010-03-30 20:24:48 +0000 | [diff] [blame] | 3394 | return Context->getFunctionNoProtoType(ResultType, Info); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3397 | case TYPE_FUNCTION_PROTO: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3398 | QualType ResultType = readType(*Loc.F, Record, Idx); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3399 | |
| 3400 | FunctionProtoType::ExtProtoInfo EPI; |
| 3401 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
Eli Friedman | c5b20b5 | 2011-04-09 08:18:08 +0000 | [diff] [blame] | 3402 | /*hasregparm*/ Record[2], |
| 3403 | /*regparm*/ Record[3], |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3404 | static_cast<CallingConv>(Record[4]), |
| 3405 | /*produces*/ Record[5]); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3406 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 3407 | unsigned Idx = 6; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3408 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3409 | SmallVector<QualType, 16> ParamTypes; |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3410 | for (unsigned I = 0; I != NumParams; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3411 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3412 | |
| 3413 | EPI.Variadic = Record[Idx++]; |
| 3414 | EPI.TypeQuals = Record[Idx++]; |
Douglas Gregor | db9d664 | 2011-01-26 05:01:58 +0000 | [diff] [blame] | 3415 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3416 | ExceptionSpecificationType EST = |
| 3417 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| 3418 | EPI.ExceptionSpecType = EST; |
| 3419 | if (EST == EST_Dynamic) { |
| 3420 | EPI.NumExceptions = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3421 | SmallVector<QualType, 2> Exceptions; |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3422 | for (unsigned I = 0; I != EPI.NumExceptions; ++I) |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3423 | Exceptions.push_back(readType(*Loc.F, Record, Idx)); |
Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 3424 | EPI.Exceptions = Exceptions.data(); |
| 3425 | } else if (EST == EST_ComputedNoexcept) { |
| 3426 | EPI.NoexceptExpr = ReadExpr(*Loc.F); |
| 3427 | } |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 3428 | return Context->getFunctionType(ResultType, ParamTypes.data(), NumParams, |
John McCall | db40c7f | 2010-12-14 08:05:40 +0000 | [diff] [blame] | 3429 | EPI); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3430 | } |
| 3431 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3432 | case TYPE_UNRESOLVED_USING: { |
| 3433 | unsigned Idx = 0; |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3434 | return Context->getTypeDeclType( |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3435 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 3436 | } |
| 3437 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3438 | case TYPE_TYPEDEF: { |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3439 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3440 | Error("incorrect encoding of typedef type"); |
| 3441 | return QualType(); |
| 3442 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3443 | unsigned Idx = 0; |
| 3444 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3445 | QualType Canonical = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3446 | if (!Canonical.isNull()) |
| 3447 | Canonical = Context->getCanonicalType(Canonical); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3448 | return Context->getTypedefType(Decl, Canonical); |
| 3449 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3450 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3451 | case TYPE_TYPEOF_EXPR: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3452 | return Context->getTypeOfExprType(ReadExpr(*Loc.F)); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3453 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3454 | case TYPE_TYPEOF: { |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3455 | if (Record.size() != 1) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3456 | Error("incorrect encoding of typeof(type) in AST file"); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3457 | return QualType(); |
| 3458 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3459 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3460 | return Context->getTypeOfType(UnderlyingType); |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3461 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3462 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3463 | case TYPE_DECLTYPE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3464 | return Context->getDecltypeType(ReadExpr(*Loc.F)); |
Anders Carlsson | 81df7b8 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 3465 | |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3466 | case TYPE_UNARY_TRANSFORM: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3467 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 3468 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3469 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 3470 | return Context->getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 3471 | } |
| 3472 | |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3473 | case TYPE_AUTO: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3474 | return Context->getAutoType(readType(*Loc.F, Record, Idx)); |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3475 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3476 | case TYPE_RECORD: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3477 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3478 | Error("incorrect encoding of record type"); |
| 3479 | return QualType(); |
| 3480 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3481 | unsigned Idx = 0; |
| 3482 | bool IsDependent = Record[Idx++]; |
| 3483 | QualType T |
| 3484 | = Context->getRecordType(ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3485 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3486 | return T; |
| 3487 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3488 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3489 | case TYPE_ENUM: { |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3490 | if (Record.size() != 2) { |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 3491 | Error("incorrect encoding of enum type"); |
| 3492 | return QualType(); |
| 3493 | } |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3494 | unsigned Idx = 0; |
| 3495 | bool IsDependent = Record[Idx++]; |
| 3496 | QualType T |
| 3497 | = Context->getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3498 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3499 | return T; |
| 3500 | } |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 3501 | |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3502 | case TYPE_ATTRIBUTED: { |
| 3503 | if (Record.size() != 3) { |
| 3504 | Error("incorrect encoding of attributed type"); |
| 3505 | return QualType(); |
| 3506 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3507 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 3508 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3509 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 3510 | return Context->getAttributedType(kind, modifiedType, equivalentType); |
| 3511 | } |
| 3512 | |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3513 | case TYPE_PAREN: { |
| 3514 | if (Record.size() != 1) { |
| 3515 | Error("incorrect encoding of paren type"); |
| 3516 | return QualType(); |
| 3517 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3518 | QualType InnerType = readType(*Loc.F, Record, Idx); |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3519 | return Context->getParenType(InnerType); |
| 3520 | } |
| 3521 | |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3522 | case TYPE_PACK_EXPANSION: { |
Douglas Gregor | 1732850 | 2011-02-01 15:24:58 +0000 | [diff] [blame] | 3523 | if (Record.size() != 2) { |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3524 | Error("incorrect encoding of pack expansion type"); |
| 3525 | return QualType(); |
| 3526 | } |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3527 | QualType Pattern = readType(*Loc.F, Record, Idx); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3528 | if (Pattern.isNull()) |
| 3529 | return QualType(); |
Douglas Gregor | 0dca5fd | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 3530 | llvm::Optional<unsigned> NumExpansions; |
| 3531 | if (Record[1]) |
| 3532 | NumExpansions = Record[1] - 1; |
| 3533 | return Context->getPackExpansionType(Pattern, NumExpansions); |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3534 | } |
| 3535 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3536 | case TYPE_ELABORATED: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3537 | unsigned Idx = 0; |
| 3538 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3539 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3540 | QualType NamedType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3541 | return Context->getElaboratedType(Keyword, NNS, NamedType); |
John McCall | fcc33b0 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3544 | case TYPE_OBJC_INTERFACE: { |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3545 | unsigned Idx = 0; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3546 | ObjCInterfaceDecl *ItfD |
| 3547 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3548 | return Context->getObjCInterfaceType(ItfD); |
| 3549 | } |
| 3550 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3551 | case TYPE_OBJC_OBJECT: { |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3552 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3553 | QualType Base = readType(*Loc.F, Record, Idx); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3554 | unsigned NumProtos = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3555 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3556 | for (unsigned I = 0; I != NumProtos; ++I) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3557 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3558 | return Context->getObjCObjectType(Base, Protos.data(), NumProtos); |
Chris Lattner | 587cbe1 | 2009-04-22 06:45:28 +0000 | [diff] [blame] | 3559 | } |
Douglas Gregor | 85c0fcd | 2009-04-13 20:46:52 +0000 | [diff] [blame] | 3560 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3561 | case TYPE_OBJC_OBJECT_POINTER: { |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3562 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3563 | QualType Pointee = readType(*Loc.F, Record, Idx); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3564 | return Context->getObjCObjectPointerType(Pointee); |
Chris Lattner | 6e054af | 2009-04-22 06:40:03 +0000 | [diff] [blame] | 3565 | } |
Argyrios Kyrtzidis | a7a36df | 2009-09-29 19:42:55 +0000 | [diff] [blame] | 3566 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3567 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3568 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3569 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 3570 | QualType Replacement = readType(*Loc.F, Record, Idx); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3571 | return |
| 3572 | Context->getSubstTemplateTypeParmType(cast<TemplateTypeParmType>(Parm), |
| 3573 | Replacement); |
| 3574 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3575 | |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3576 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 3577 | unsigned Idx = 0; |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3578 | QualType Parm = readType(*Loc.F, Record, Idx); |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3579 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 3580 | return Context->getSubstTemplateTypeParmPackType( |
| 3581 | cast<TemplateTypeParmType>(Parm), |
| 3582 | ArgPack); |
| 3583 | } |
| 3584 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3585 | case TYPE_INJECTED_CLASS_NAME: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3586 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3587 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3588 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3589 | // for AST reading, too much interdependencies. |
Argyrios Kyrtzidis | dab33c5 | 2010-07-02 11:55:20 +0000 | [diff] [blame] | 3590 | return |
| 3591 | QualType(new (*Context, TypeAlignment) InjectedClassNameType(D, TST), 0); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3592 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3593 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3594 | case TYPE_TEMPLATE_TYPE_PARM: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3595 | unsigned Idx = 0; |
| 3596 | unsigned Depth = Record[Idx++]; |
| 3597 | unsigned Index = Record[Idx++]; |
| 3598 | bool Pack = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3599 | TemplateTypeParmDecl *D |
| 3600 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
Chandler Carruth | 0883632 | 2011-05-01 00:51:33 +0000 | [diff] [blame] | 3601 | return Context->getTemplateTypeParmType(Depth, Index, Pack, D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3602 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3603 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3604 | case TYPE_DEPENDENT_NAME: { |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3605 | unsigned Idx = 0; |
| 3606 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3607 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3608 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3609 | QualType Canon = readType(*Loc.F, Record, Idx); |
Douglas Gregor | f86c939 | 2010-10-26 00:51:02 +0000 | [diff] [blame] | 3610 | if (!Canon.isNull()) |
| 3611 | Canon = Context->getCanonicalType(Canon); |
Argyrios Kyrtzidis | e929095 | 2010-07-02 11:55:24 +0000 | [diff] [blame] | 3612 | return Context->getDependentNameType(Keyword, NNS, Name, Canon); |
Argyrios Kyrtzidis | bfcacee | 2010-06-24 08:57:31 +0000 | [diff] [blame] | 3613 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3614 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3615 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3616 | unsigned Idx = 0; |
| 3617 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3618 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 3619 | const IdentifierInfo *Name = this->GetIdentifierInfo(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3620 | unsigned NumArgs = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3621 | SmallVector<TemplateArgument, 8> Args; |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3622 | Args.reserve(NumArgs); |
| 3623 | while (NumArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3624 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
Argyrios Kyrtzidis | f0f7a79 | 2010-06-25 16:24:58 +0000 | [diff] [blame] | 3625 | return Context->getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| 3626 | Args.size(), Args.data()); |
| 3627 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 3628 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3629 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3630 | unsigned Idx = 0; |
| 3631 | |
| 3632 | // ArrayType |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3633 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3634 | ArrayType::ArraySizeModifier ASM |
| 3635 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 3636 | unsigned IndexTypeQuals = Record[Idx++]; |
| 3637 | |
| 3638 | // DependentSizedArrayType |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3639 | Expr *NumElts = ReadExpr(*Loc.F); |
| 3640 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | 4a57bd0 | 2010-06-30 08:49:25 +0000 | [diff] [blame] | 3641 | |
| 3642 | return Context->getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 3643 | IndexTypeQuals, Brackets); |
| 3644 | } |
Argyrios Kyrtzidis | 106caf92 | 2010-06-19 19:28:53 +0000 | [diff] [blame] | 3645 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3646 | case TYPE_TEMPLATE_SPECIALIZATION: { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3647 | unsigned Idx = 0; |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3648 | bool IsDependent = Record[Idx++]; |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 3649 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3650 | SmallVector<TemplateArgument, 8> Args; |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3651 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3652 | QualType Underlying = readType(*Loc.F, Record, Idx); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3653 | QualType T; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3654 | if (Underlying.isNull()) |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3655 | T = Context->getCanonicalTemplateSpecializationType(Name, Args.data(), |
| 3656 | Args.size()); |
Argyrios Kyrtzidis | 45a83f9 | 2010-07-02 11:55:11 +0000 | [diff] [blame] | 3657 | else |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3658 | T = Context->getTemplateSpecializationType(Name, Args.data(), |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3659 | Args.size(), Underlying); |
John McCall | 424cec9 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 3660 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
Argyrios Kyrtzidis | a4ed181 | 2010-07-08 13:09:53 +0000 | [diff] [blame] | 3661 | return T; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 3662 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3663 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3664 | // Suppress a GCC warning |
| 3665 | return QualType(); |
| 3666 | } |
| 3667 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3668 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3669 | ASTReader &Reader; |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3670 | Module &F; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3671 | llvm::BitstreamCursor &DeclsCursor; |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3672 | const ASTReader::RecordData &Record; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3673 | unsigned &Idx; |
| 3674 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3675 | SourceLocation ReadSourceLocation(const ASTReader::RecordData &R, |
| 3676 | unsigned &I) { |
| 3677 | return Reader.ReadSourceLocation(F, R, I); |
| 3678 | } |
| 3679 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3680 | template<typename T> |
| 3681 | T *ReadDeclAs(const ASTReader::RecordData &Record, unsigned &Idx) { |
| 3682 | return Reader.ReadDeclAs<T>(F, Record, Idx); |
| 3683 | } |
| 3684 | |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3685 | public: |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3686 | TypeLocReader(ASTReader &Reader, Module &F, |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 3687 | const ASTReader::RecordData &Record, unsigned &Idx) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3688 | : Reader(Reader), F(F), DeclsCursor(F.DeclsCursor), Record(Record), Idx(Idx) |
| 3689 | { } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3690 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3691 | // We want compile-time assurance that we've enumerated all of |
| 3692 | // these, so unfortunately we have to declare them first, then |
| 3693 | // define them out-of-line. |
| 3694 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3695 | #define TYPELOC(CLASS, PARENT) \ |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3696 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3697 | #include "clang/AST/TypeLocNodes.def" |
| 3698 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3699 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 3700 | void VisitArrayTypeLoc(ArrayTypeLoc); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3701 | }; |
| 3702 | |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3703 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3704 | // nothing to do |
| 3705 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3706 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3707 | TL.setBuiltinLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 3708 | if (TL.needsExtraLocalData()) { |
| 3709 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 3710 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 3711 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 3712 | TL.setModeAttr(Record[Idx++]); |
| 3713 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3714 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3715 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3716 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3717 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3718 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3719 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3720 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3721 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3722 | TL.setCaretLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3723 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3724 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3725 | TL.setAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3726 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3727 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3728 | TL.setAmpAmpLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3729 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3730 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3731 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
Abramo Bagnara | 50935784 | 2011-03-05 14:42:21 +0000 | [diff] [blame] | 3732 | TL.setClassTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3733 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3734 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3735 | TL.setLBracketLoc(ReadSourceLocation(Record, Idx)); |
| 3736 | TL.setRBracketLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3737 | if (Record[Idx++]) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3738 | TL.setSizeExpr(Reader.ReadExpr(F)); |
Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 3739 | else |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3740 | TL.setSizeExpr(0); |
| 3741 | } |
| 3742 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 3743 | VisitArrayTypeLoc(TL); |
| 3744 | } |
| 3745 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 3746 | VisitArrayTypeLoc(TL); |
| 3747 | } |
| 3748 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 3749 | VisitArrayTypeLoc(TL); |
| 3750 | } |
| 3751 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 3752 | DependentSizedArrayTypeLoc TL) { |
| 3753 | VisitArrayTypeLoc(TL); |
| 3754 | } |
| 3755 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 3756 | DependentSizedExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3757 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3758 | } |
| 3759 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3760 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3761 | } |
| 3762 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3763 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3764 | } |
| 3765 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
Abramo Bagnara | f2a79d9 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 3766 | TL.setLocalRangeBegin(ReadSourceLocation(Record, Idx)); |
| 3767 | TL.setLocalRangeEnd(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 3768 | TL.setTrailingReturn(Record[Idx++]); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3769 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 3770 | TL.setArg(i, ReadDeclAs<ParmVarDecl>(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3771 | } |
| 3772 | } |
| 3773 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 3774 | VisitFunctionTypeLoc(TL); |
| 3775 | } |
| 3776 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 3777 | VisitFunctionTypeLoc(TL); |
| 3778 | } |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3779 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3780 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 3781 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3782 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3783 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3784 | } |
| 3785 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3786 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3787 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3788 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3789 | } |
| 3790 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3791 | TL.setTypeofLoc(ReadSourceLocation(Record, Idx)); |
| 3792 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3793 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3794 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3795 | } |
| 3796 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3797 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3798 | } |
Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 3799 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 3800 | TL.setKWLoc(ReadSourceLocation(Record, Idx)); |
| 3801 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3802 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3803 | TL.setUnderlyingTInfo(Reader.GetTypeSourceInfo(F, Record, Idx)); |
| 3804 | } |
Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 3805 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 3806 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3807 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3808 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3809 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3810 | } |
| 3811 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3812 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3813 | } |
John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 3814 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 3815 | TL.setAttrNameLoc(ReadSourceLocation(Record, Idx)); |
| 3816 | if (TL.hasAttrOperand()) { |
| 3817 | SourceRange range; |
| 3818 | range.setBegin(ReadSourceLocation(Record, Idx)); |
| 3819 | range.setEnd(ReadSourceLocation(Record, Idx)); |
| 3820 | TL.setAttrOperandParensRange(range); |
| 3821 | } |
| 3822 | if (TL.hasAttrExprOperand()) { |
| 3823 | if (Record[Idx++]) |
| 3824 | TL.setAttrExprOperand(Reader.ReadExpr(F)); |
| 3825 | else |
| 3826 | TL.setAttrExprOperand(0); |
| 3827 | } else if (TL.hasAttrEnumOperand()) |
| 3828 | TL.setAttrEnumOperandLoc(ReadSourceLocation(Record, Idx)); |
| 3829 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3830 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3831 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3832 | } |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3833 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 3834 | SubstTemplateTypeParmTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3835 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 3836 | } |
Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 3837 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 3838 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 3839 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3840 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3841 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 3842 | TemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3843 | TL.setTemplateNameLoc(ReadSourceLocation(Record, Idx)); |
| 3844 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3845 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 3846 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 3847 | TL.setArgLocInfo(i, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3848 | Reader.GetTemplateArgumentLocInfo(F, |
| 3849 | TL.getTypePtr()->getArg(i).getKind(), |
| 3850 | Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3851 | } |
Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 3852 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 3853 | TL.setLParenLoc(ReadSourceLocation(Record, Idx)); |
| 3854 | TL.setRParenLoc(ReadSourceLocation(Record, Idx)); |
| 3855 | } |
Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 3856 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3857 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 844cb50 | 2011-03-01 18:12:44 +0000 | [diff] [blame] | 3858 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3859 | } |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3860 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3861 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 3862 | } |
Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 3863 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3864 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | 3d0da5f | 2011-03-01 01:34:45 +0000 | [diff] [blame] | 3865 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3866 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3867 | } |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3868 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 3869 | DependentTemplateSpecializationTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3870 | TL.setKeywordLoc(ReadSourceLocation(Record, Idx)); |
Douglas Gregor | a7a795b | 2011-03-01 20:11:18 +0000 | [diff] [blame] | 3871 | TL.setQualifierLoc(Reader.ReadNestedNameSpecifierLoc(F, Record, Idx)); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3872 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
| 3873 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3874 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3875 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 3876 | TL.setArgLocInfo(I, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3877 | Reader.GetTemplateArgumentLocInfo(F, |
| 3878 | TL.getTypePtr()->getArg(I).getKind(), |
| 3879 | Record, Idx)); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 3880 | } |
Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 3881 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 3882 | TL.setEllipsisLoc(ReadSourceLocation(Record, Idx)); |
| 3883 | } |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3884 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3885 | TL.setNameLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 3886 | } |
| 3887 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 3888 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3889 | TL.setLAngleLoc(ReadSourceLocation(Record, Idx)); |
| 3890 | TL.setRAngleLoc(ReadSourceLocation(Record, Idx)); |
John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 3891 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3892 | TL.setProtocolLoc(i, ReadSourceLocation(Record, Idx)); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3893 | } |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3894 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3895 | TL.setStarLoc(ReadSourceLocation(Record, Idx)); |
John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 3896 | } |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3897 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3898 | TypeSourceInfo *ASTReader::GetTypeSourceInfo(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 3899 | const RecordData &Record, |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3900 | unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3901 | QualType InfoTy = readType(F, Record, Idx); |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3902 | if (InfoTy.isNull()) |
| 3903 | return 0; |
| 3904 | |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3905 | TypeSourceInfo *TInfo = getContext()->CreateTypeSourceInfo(InfoTy); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3906 | TypeLocReader TLR(*this, F, Record, Idx); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3907 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3908 | TLR.Visit(TL); |
John McCall | bcd0350 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 3909 | return TInfo; |
John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 3910 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3911 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3912 | QualType ASTReader::GetType(TypeID ID) { |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3913 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 3914 | unsigned Index = ID >> Qualifiers::FastWidth; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3915 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3916 | if (Index < NUM_PREDEF_TYPE_IDS) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3917 | QualType T; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3918 | switch ((PredefinedTypeIDs)Index) { |
| 3919 | case PREDEF_TYPE_NULL_ID: return QualType(); |
| 3920 | case PREDEF_TYPE_VOID_ID: T = Context->VoidTy; break; |
| 3921 | case PREDEF_TYPE_BOOL_ID: T = Context->BoolTy; break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3922 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3923 | case PREDEF_TYPE_CHAR_U_ID: |
| 3924 | case PREDEF_TYPE_CHAR_S_ID: |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3925 | // FIXME: Check that the signedness of CharTy is correct! |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 3926 | T = Context->CharTy; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3927 | break; |
| 3928 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3929 | case PREDEF_TYPE_UCHAR_ID: T = Context->UnsignedCharTy; break; |
| 3930 | case PREDEF_TYPE_USHORT_ID: T = Context->UnsignedShortTy; break; |
| 3931 | case PREDEF_TYPE_UINT_ID: T = Context->UnsignedIntTy; break; |
| 3932 | case PREDEF_TYPE_ULONG_ID: T = Context->UnsignedLongTy; break; |
| 3933 | case PREDEF_TYPE_ULONGLONG_ID: T = Context->UnsignedLongLongTy; break; |
| 3934 | case PREDEF_TYPE_UINT128_ID: T = Context->UnsignedInt128Ty; break; |
| 3935 | case PREDEF_TYPE_SCHAR_ID: T = Context->SignedCharTy; break; |
| 3936 | case PREDEF_TYPE_WCHAR_ID: T = Context->WCharTy; break; |
| 3937 | case PREDEF_TYPE_SHORT_ID: T = Context->ShortTy; break; |
| 3938 | case PREDEF_TYPE_INT_ID: T = Context->IntTy; break; |
| 3939 | case PREDEF_TYPE_LONG_ID: T = Context->LongTy; break; |
| 3940 | case PREDEF_TYPE_LONGLONG_ID: T = Context->LongLongTy; break; |
| 3941 | case PREDEF_TYPE_INT128_ID: T = Context->Int128Ty; break; |
| 3942 | case PREDEF_TYPE_FLOAT_ID: T = Context->FloatTy; break; |
| 3943 | case PREDEF_TYPE_DOUBLE_ID: T = Context->DoubleTy; break; |
| 3944 | case PREDEF_TYPE_LONGDOUBLE_ID: T = Context->LongDoubleTy; break; |
| 3945 | case PREDEF_TYPE_OVERLOAD_ID: T = Context->OverloadTy; break; |
John McCall | 0009fcc | 2011-04-26 20:42:42 +0000 | [diff] [blame] | 3946 | case PREDEF_TYPE_BOUND_MEMBER: T = Context->BoundMemberTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3947 | case PREDEF_TYPE_DEPENDENT_ID: T = Context->DependentTy; break; |
John McCall | 3199634 | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 3948 | case PREDEF_TYPE_UNKNOWN_ANY: T = Context->UnknownAnyTy; break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3949 | case PREDEF_TYPE_NULLPTR_ID: T = Context->NullPtrTy; break; |
| 3950 | case PREDEF_TYPE_CHAR16_ID: T = Context->Char16Ty; break; |
| 3951 | case PREDEF_TYPE_CHAR32_ID: T = Context->Char32Ty; break; |
| 3952 | case PREDEF_TYPE_OBJC_ID: T = Context->ObjCBuiltinIdTy; break; |
| 3953 | case PREDEF_TYPE_OBJC_CLASS: T = Context->ObjCBuiltinClassTy; break; |
| 3954 | case PREDEF_TYPE_OBJC_SEL: T = Context->ObjCBuiltinSelTy; break; |
Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 3955 | case PREDEF_TYPE_AUTO_DEDUCT: T = Context->getAutoDeductType(); break; |
| 3956 | |
| 3957 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 3958 | T = Context->getAutoRRefDeductType(); |
| 3959 | break; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | assert(!T.isNull() && "Unknown predefined type"); |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3963 | return T.withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3964 | } |
| 3965 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3966 | Index -= NUM_PREDEF_TYPE_IDS; |
Sebastian Redl | 837a6cb | 2010-07-20 22:37:49 +0000 | [diff] [blame] | 3967 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3968 | if (TypesLoaded[Index].isNull()) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3969 | TypesLoaded[Index] = readTypeRecord(Index); |
Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 3970 | if (TypesLoaded[Index].isNull()) |
| 3971 | return QualType(); |
| 3972 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 3973 | TypesLoaded[Index]->setFromAST(); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 3974 | if (DeserializationListener) |
Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 3975 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 3976 | TypesLoaded[Index]); |
Sebastian Redl | 409183f | 2010-07-14 20:26:45 +0000 | [diff] [blame] | 3977 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3978 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 3979 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 3980 | } |
| 3981 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3982 | QualType ASTReader::getLocalType(Module &F, unsigned LocalID) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 3983 | return GetType(getGlobalTypeID(F, LocalID)); |
| 3984 | } |
| 3985 | |
| 3986 | serialization::TypeID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 3987 | ASTReader::getGlobalTypeID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 3988 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 3989 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 3990 | |
| 3991 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 3992 | return LocalID; |
| 3993 | |
| 3994 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 3995 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 3996 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 3997 | |
| 3998 | unsigned GlobalIndex = LocalIndex + I->second; |
| 3999 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 4000 | } |
| 4001 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4002 | TemplateArgumentLocInfo |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4003 | ASTReader::GetTemplateArgumentLocInfo(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4004 | TemplateArgument::ArgKind Kind, |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4005 | const RecordData &Record, |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4006 | unsigned &Index) { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4007 | switch (Kind) { |
| 4008 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4009 | return ReadExpr(F); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4010 | case TemplateArgument::Type: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4011 | return GetTypeSourceInfo(F, Record, Index); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4012 | case TemplateArgument::Template: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4013 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4014 | Index); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4015 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4016 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4017 | SourceLocation()); |
| 4018 | } |
| 4019 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4020 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| 4021 | Index); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 4022 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4023 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 4024 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 4025 | EllipsisLoc); |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 4026 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4027 | case TemplateArgument::Null: |
| 4028 | case TemplateArgument::Integral: |
| 4029 | case TemplateArgument::Declaration: |
| 4030 | case TemplateArgument::Pack: |
| 4031 | return TemplateArgumentLocInfo(); |
| 4032 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 4033 | llvm_unreachable("unexpected template argument loc"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 4034 | return TemplateArgumentLocInfo(); |
| 4035 | } |
| 4036 | |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4037 | TemplateArgumentLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4038 | ASTReader::ReadTemplateArgumentLoc(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 4039 | const RecordData &Record, unsigned &Index) { |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4040 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 4041 | |
| 4042 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 4043 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 4044 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 4045 | } |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 4046 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 4047 | Record, Index)); |
Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 4048 | } |
| 4049 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4050 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4051 | return GetDecl(ID); |
| 4052 | } |
| 4053 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4054 | uint64_t ASTReader::readCXXBaseSpecifiers(Module &M, const RecordData &Record, |
| 4055 | unsigned &Idx){ |
| 4056 | if (Idx >= Record.size()) |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4057 | return 0; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4058 | |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 4059 | unsigned LocalID = Record[Idx++]; |
| 4060 | return getGlobalBitOffset(M, M.CXXBaseSpecifiersOffsets[LocalID - 1]); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
| 4063 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4064 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4065 | llvm::BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4066 | SavedStreamPosition SavedPosition(Cursor); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4067 | Cursor.JumpToBit(Loc.Offset); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4068 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 4069 | RecordData Record; |
| 4070 | unsigned Code = Cursor.ReadCode(); |
| 4071 | unsigned RecCode = Cursor.ReadRecord(Code, Record); |
| 4072 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 4073 | Error("Malformed AST file: missing C++ base specifiers"); |
| 4074 | return 0; |
| 4075 | } |
| 4076 | |
| 4077 | unsigned Idx = 0; |
| 4078 | unsigned NumBases = Record[Idx++]; |
| 4079 | void *Mem = Context->Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 4080 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 4081 | for (unsigned I = 0; I != NumBases; ++I) |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4082 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 4083 | return Bases; |
| 4084 | } |
| 4085 | |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4086 | serialization::DeclID |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4087 | ASTReader::getGlobalDeclID(Module &F, unsigned LocalID) const { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4088 | if (LocalID < NUM_PREDEF_DECL_IDS) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4089 | return LocalID; |
| 4090 | |
| 4091 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4092 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4093 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 4094 | |
| 4095 | return LocalID + I->second; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4096 | } |
| 4097 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4098 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 4099 | Module &M) const { |
| 4100 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(ID); |
| 4101 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 4102 | return &M == I->second; |
| 4103 | } |
| 4104 | |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4105 | Decl *ASTReader::GetDecl(DeclID ID) { |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4106 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 4107 | switch ((PredefinedDeclIDs)ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4108 | case PREDEF_DECL_NULL_ID: |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4109 | return 0; |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4110 | |
| 4111 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 4112 | assert(Context && "No context available?"); |
| 4113 | return Context->getTranslationUnitDecl(); |
Douglas Gregor | 3ea7269 | 2011-08-12 05:46:01 +0000 | [diff] [blame] | 4114 | |
| 4115 | case PREDEF_DECL_OBJC_ID_ID: |
| 4116 | assert(Context && "No context available?"); |
| 4117 | return Context->getObjCIdDecl(); |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4118 | |
Douglas Gregor | 52e0280 | 2011-08-12 06:17:30 +0000 | [diff] [blame] | 4119 | case PREDEF_DECL_OBJC_SEL_ID: |
| 4120 | assert(Context && "No context available?"); |
| 4121 | return Context->getObjCSelDecl(); |
| 4122 | |
Douglas Gregor | 0a58618 | 2011-08-12 05:59:41 +0000 | [diff] [blame] | 4123 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 4124 | assert(Context && "No context available?"); |
| 4125 | return Context->getObjCClassDecl(); |
Douglas Gregor | 801c99d | 2011-08-12 06:49:56 +0000 | [diff] [blame] | 4126 | |
| 4127 | case PREDEF_DECL_INT_128_ID: |
| 4128 | assert(Context && "No context available?"); |
| 4129 | return Context->getInt128Decl(); |
| 4130 | |
| 4131 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 4132 | assert(Context && "No context available?"); |
| 4133 | return Context->getUInt128Decl(); |
Douglas Gregor | bab8a96 | 2011-09-08 01:46:34 +0000 | [diff] [blame] | 4134 | |
| 4135 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 4136 | assert(Context && "No context available?"); |
| 4137 | return Context->getObjCInstanceTypeDecl(); |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4138 | } |
| 4139 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4140 | return 0; |
Douglas Gregor | 6f8912e | 2011-08-03 16:05:40 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4143 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 4144 | |
| 4145 | if (Index > DeclsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4146 | Error("declaration ID out-of-range for AST file"); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4147 | return 0; |
| 4148 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4149 | |
| 4150 | if (!DeclsLoaded[Index]) { |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 4151 | ReadDeclRecord(ID); |
Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 4152 | if (DeserializationListener) |
| 4153 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 4154 | } |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4155 | |
| 4156 | return DeclsLoaded[Index]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4157 | } |
| 4158 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4159 | serialization::DeclID ASTReader::ReadDeclID(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 4160 | const RecordData &Record, |
| 4161 | unsigned &Idx) { |
| 4162 | if (Idx >= Record.size()) { |
| 4163 | Error("Corrupted AST file"); |
| 4164 | return 0; |
| 4165 | } |
| 4166 | |
| 4167 | return getGlobalDeclID(F, Record[Idx++]); |
| 4168 | } |
| 4169 | |
Chris Lattner | 9c28af0 | 2009-04-27 05:46:25 +0000 | [diff] [blame] | 4170 | /// \brief Resolve the offset of a statement into a statement. |
| 4171 | /// |
| 4172 | /// This operation will read a new statement from the external |
| 4173 | /// source each time it is called, and is meant to be used via a |
| 4174 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4175 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 4176 | // Switch case IDs are per Decl. |
| 4177 | ClearSwitchCaseIDs(); |
| 4178 | |
Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 4179 | // Offset here is a global offset across the entire chain. |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4180 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 4181 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| 4182 | return ReadStmtFromStream(*Loc.F); |
Douglas Gregor | 3c3aa61 | 2009-04-18 00:07:54 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4185 | namespace { |
| 4186 | class FindExternalLexicalDeclsVisitor { |
| 4187 | ASTReader &Reader; |
| 4188 | const DeclContext *DC; |
| 4189 | bool (*isKindWeWant)(Decl::Kind); |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4190 | |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4191 | SmallVectorImpl<Decl*> &Decls; |
| 4192 | bool PredefsVisited[NUM_PREDEF_DECL_IDS]; |
| 4193 | |
| 4194 | public: |
| 4195 | FindExternalLexicalDeclsVisitor(ASTReader &Reader, const DeclContext *DC, |
| 4196 | bool (*isKindWeWant)(Decl::Kind), |
| 4197 | SmallVectorImpl<Decl*> &Decls) |
| 4198 | : Reader(Reader), DC(DC), isKindWeWant(isKindWeWant), Decls(Decls) |
| 4199 | { |
| 4200 | for (unsigned I = 0; I != NUM_PREDEF_DECL_IDS; ++I) |
| 4201 | PredefsVisited[I] = false; |
| 4202 | } |
| 4203 | |
| 4204 | static bool visit(Module &M, bool Preorder, void *UserData) { |
| 4205 | if (Preorder) |
| 4206 | return false; |
| 4207 | |
| 4208 | FindExternalLexicalDeclsVisitor *This |
| 4209 | = static_cast<FindExternalLexicalDeclsVisitor *>(UserData); |
| 4210 | |
| 4211 | Module::DeclContextInfosMap::iterator Info |
| 4212 | = M.DeclContextInfos.find(This->DC); |
| 4213 | if (Info == M.DeclContextInfos.end() || !Info->second.LexicalDecls) |
| 4214 | return false; |
| 4215 | |
| 4216 | // Load all of the declaration IDs |
| 4217 | for (const KindDeclIDPair *ID = Info->second.LexicalDecls, |
| 4218 | *IDE = ID + Info->second.NumLexicalDecls; |
| 4219 | ID != IDE; ++ID) { |
| 4220 | if (This->isKindWeWant && !This->isKindWeWant((Decl::Kind)ID->first)) |
| 4221 | continue; |
| 4222 | |
| 4223 | // Don't add predefined declarations to the lexical context more |
| 4224 | // than once. |
| 4225 | if (ID->second < NUM_PREDEF_DECL_IDS) { |
| 4226 | if (This->PredefsVisited[ID->second]) |
| 4227 | continue; |
| 4228 | |
| 4229 | This->PredefsVisited[ID->second] = true; |
| 4230 | } |
| 4231 | |
Douglas Gregor | 4e4c83e | 2011-08-26 22:04:51 +0000 | [diff] [blame] | 4232 | if (Decl *D = This->Reader.GetLocalDecl(M, ID->second)) { |
| 4233 | if (!This->DC->isDeclInLexicalTraversal(D)) |
| 4234 | This->Decls.push_back(D); |
| 4235 | } |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4236 | } |
| 4237 | |
| 4238 | return false; |
| 4239 | } |
| 4240 | }; |
| 4241 | } |
| 4242 | |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4243 | ExternalLoadResult ASTReader::FindExternalLexicalDecls(const DeclContext *DC, |
Argyrios Kyrtzidis | 0e88a56 | 2010-10-14 20:14:34 +0000 | [diff] [blame] | 4244 | bool (*isKindWeWant)(Decl::Kind), |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4245 | SmallVectorImpl<Decl*> &Decls) { |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4246 | // There might be lexical decls in multiple modules, for the TU at |
Douglas Gregor | 1257f97 | 2011-08-24 21:27:34 +0000 | [diff] [blame] | 4247 | // least. Walk all of the modules in the order they were loaded. |
| 4248 | FindExternalLexicalDeclsVisitor Visitor(*this, DC, isKindWeWant, Decls); |
| 4249 | ModuleMgr.visitDepthFirst(&FindExternalLexicalDeclsVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4250 | ++NumLexicalDeclContextsRead; |
Douglas Gregor | 3d0adb3 | 2011-07-15 21:46:17 +0000 | [diff] [blame] | 4251 | return ELR_Success; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4254 | namespace { |
| 4255 | /// \brief Module visitor used to perform name lookup into a |
| 4256 | /// declaration context. |
| 4257 | class DeclContextNameLookupVisitor { |
| 4258 | ASTReader &Reader; |
| 4259 | const DeclContext *DC; |
| 4260 | DeclarationName Name; |
| 4261 | SmallVectorImpl<NamedDecl *> &Decls; |
| 4262 | |
| 4263 | public: |
| 4264 | DeclContextNameLookupVisitor(ASTReader &Reader, |
| 4265 | const DeclContext *DC, DeclarationName Name, |
| 4266 | SmallVectorImpl<NamedDecl *> &Decls) |
| 4267 | : Reader(Reader), DC(DC), Name(Name), Decls(Decls) { } |
| 4268 | |
| 4269 | static bool visit(Module &M, void *UserData) { |
| 4270 | DeclContextNameLookupVisitor *This |
| 4271 | = static_cast<DeclContextNameLookupVisitor *>(UserData); |
| 4272 | |
| 4273 | // Check whether we have any visible declaration information for |
| 4274 | // this context in this module. |
| 4275 | Module::DeclContextInfosMap::iterator Info |
| 4276 | = M.DeclContextInfos.find(This->DC); |
| 4277 | if (Info == M.DeclContextInfos.end() || !Info->second.NameLookupTableData) |
| 4278 | return false; |
| 4279 | |
| 4280 | // Look for this name within this module. |
| 4281 | ASTDeclContextNameLookupTable *LookupTable = |
| 4282 | (ASTDeclContextNameLookupTable*)Info->second.NameLookupTableData; |
| 4283 | ASTDeclContextNameLookupTable::iterator Pos |
| 4284 | = LookupTable->find(This->Name); |
| 4285 | if (Pos == LookupTable->end()) |
| 4286 | return false; |
| 4287 | |
| 4288 | bool FoundAnything = false; |
| 4289 | ASTDeclContextNameLookupTrait::data_type Data = *Pos; |
| 4290 | for (; Data.first != Data.second; ++Data.first) { |
| 4291 | NamedDecl *ND = This->Reader.GetLocalDeclAs<NamedDecl>(M, *Data.first); |
| 4292 | if (!ND) |
| 4293 | continue; |
| 4294 | |
| 4295 | if (ND->getDeclName() != This->Name) { |
| 4296 | assert(!This->Name.getCXXNameType().isNull() && |
| 4297 | "Name mismatch without a type"); |
| 4298 | continue; |
| 4299 | } |
| 4300 | |
| 4301 | // Record this declaration. |
| 4302 | FoundAnything = true; |
| 4303 | This->Decls.push_back(ND); |
| 4304 | } |
| 4305 | |
| 4306 | return FoundAnything; |
| 4307 | } |
| 4308 | }; |
| 4309 | } |
| 4310 | |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4311 | DeclContext::lookup_result |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4312 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4313 | DeclarationName Name) { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4314 | assert(DC->hasExternalVisibleStorage() && |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4315 | "DeclContext has no visible decls in storage"); |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4316 | if (!Name) |
| 4317 | return DeclContext::lookup_result(DeclContext::lookup_iterator(0), |
| 4318 | DeclContext::lookup_iterator(0)); |
Ted Kremenek | 1ff615c | 2010-03-18 00:56:54 +0000 | [diff] [blame] | 4319 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4320 | SmallVector<NamedDecl *, 64> Decls; |
Douglas Gregor | 94619c8 | 2011-08-24 19:03:07 +0000 | [diff] [blame] | 4321 | DeclContextNameLookupVisitor Visitor(*this, DC, Name, Decls); |
| 4322 | ModuleMgr.visit(&DeclContextNameLookupVisitor::visit, &Visitor); |
Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 4323 | ++NumVisibleDeclContextsRead; |
Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 4324 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
John McCall | 75b960e | 2010-06-01 09:23:16 +0000 | [diff] [blame] | 4325 | return const_cast<DeclContext*>(DC)->lookup(Name); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4326 | } |
| 4327 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4328 | void ASTReader::PassInterestingDeclsToConsumer() { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4329 | assert(Consumer); |
| 4330 | while (!InterestingDecls.empty()) { |
| 4331 | DeclGroupRef DG(InterestingDecls.front()); |
| 4332 | InterestingDecls.pop_front(); |
Sebastian Redl | eaa4ade | 2010-08-11 18:52:41 +0000 | [diff] [blame] | 4333 | Consumer->HandleInterestingDecl(DG); |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4337 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
Douglas Gregor | b985eeb | 2009-04-22 19:09:20 +0000 | [diff] [blame] | 4338 | this->Consumer = Consumer; |
| 4339 | |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4340 | if (!Consumer) |
| 4341 | return; |
| 4342 | |
| 4343 | for (unsigned I = 0, N = ExternalDefinitions.size(); I != N; ++I) { |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4344 | // Force deserialization of this decl, which will cause it to be queued for |
| 4345 | // passing to the consumer. |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 4346 | GetDecl(ExternalDefinitions[I]); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4347 | } |
Douglas Gregor | f005eac | 2009-04-25 00:41:30 +0000 | [diff] [blame] | 4348 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 4349 | PassInterestingDeclsToConsumer(); |
Douglas Gregor | 1a0d0b9 | 2009-04-14 00:24:19 +0000 | [diff] [blame] | 4350 | } |
| 4351 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4352 | void ASTReader::PrintStats() { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4353 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4354 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4355 | unsigned NumTypesLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4356 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 4357 | QualType()); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4358 | unsigned NumDeclsLoaded |
| 4359 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 4360 | (Decl *)0); |
| 4361 | unsigned NumIdentifiersLoaded |
| 4362 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 4363 | IdentifiersLoaded.end(), |
| 4364 | (IdentifierInfo *)0); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4365 | unsigned NumSelectorsLoaded |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4366 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 4367 | SelectorsLoaded.end(), |
| 4368 | Selector()); |
Douglas Gregor | c3b1dd1 | 2009-04-13 20:50:16 +0000 | [diff] [blame] | 4369 | |
Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4370 | std::fprintf(stderr, " %u stat cache hits\n", NumStatHits); |
| 4371 | std::fprintf(stderr, " %u stat cache misses\n", NumStatMisses); |
Douglas Gregor | 49bf76b | 2011-07-21 18:46:38 +0000 | [diff] [blame] | 4372 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4373 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 4374 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 4375 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4376 | if (!TypesLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4377 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4378 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 4379 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 4380 | if (!DeclsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4381 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
Douglas Gregor | 745ed14 | 2009-04-25 18:35:21 +0000 | [diff] [blame] | 4382 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 4383 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4384 | if (!IdentifiersLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4385 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4386 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 4387 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4388 | if (!SelectorsLoaded.empty()) |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4389 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4390 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 4391 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4392 | if (TotalNumStatements) |
| 4393 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 4394 | NumStatementsRead, TotalNumStatements, |
| 4395 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 4396 | if (TotalNumMacros) |
| 4397 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 4398 | NumMacrosRead, TotalNumMacros, |
| 4399 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 4400 | if (TotalLexicalDeclContexts) |
| 4401 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 4402 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 4403 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 4404 | * 100)); |
| 4405 | if (TotalVisibleDeclContexts) |
| 4406 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 4407 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 4408 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 4409 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4410 | if (TotalNumMethodPoolEntries) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4411 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4412 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 4413 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4414 | * 100)); |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4415 | std::fprintf(stderr, " %u method pool misses\n", NumMethodPoolMisses); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4416 | } |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4417 | std::fprintf(stderr, "\n"); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4418 | dump(); |
| 4419 | std::fprintf(stderr, "\n"); |
| 4420 | } |
| 4421 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4422 | template<typename Key, typename Module, unsigned InitialCapacity> |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4423 | static void |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4424 | dumpModuleIDMap(StringRef Name, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4425 | const ContinuousRangeMap<Key, Module *, |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4426 | InitialCapacity> &Map) { |
| 4427 | if (Map.begin() == Map.end()) |
| 4428 | return; |
| 4429 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4430 | typedef ContinuousRangeMap<Key, Module *, InitialCapacity> MapType; |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4431 | llvm::errs() << Name << ":\n"; |
| 4432 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 4433 | I != IEnd; ++I) { |
| 4434 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 4435 | << "\n"; |
| 4436 | } |
| 4437 | } |
| 4438 | |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4439 | void ASTReader::dump() { |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4440 | llvm::errs() << "*** PCH/Module Remappings:\n"; |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 4441 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
Douglas Gregor | 204b871 | 2011-07-21 19:50:14 +0000 | [diff] [blame] | 4442 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
Douglas Gregor | 8ab4ea8 | 2011-07-29 00:21:44 +0000 | [diff] [blame] | 4443 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4444 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4445 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 4446 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 4447 | dumpModuleIDMap("Global macro definition map", GlobalMacroDefinitionMap); |
| 4448 | dumpModuleIDMap("Global preprocessed entity map", |
| 4449 | GlobalPreprocessedEntityMap); |
Douglas Gregor | 1cc9c06 | 2011-08-02 11:12:41 +0000 | [diff] [blame] | 4450 | |
| 4451 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 4452 | for (ModuleManager::ModuleConstIterator M = ModuleMgr.begin(), |
| 4453 | MEnd = ModuleMgr.end(); |
| 4454 | M != MEnd; ++M) |
| 4455 | (*M)->dump(); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4456 | } |
| 4457 | |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4458 | /// Return the amount of memory used by memory buffers, breaking down |
| 4459 | /// by heap-backed versus mmap'ed memory. |
| 4460 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4461 | for (ModuleConstIterator I = ModuleMgr.begin(), |
| 4462 | E = ModuleMgr.end(); I != E; ++I) { |
| 4463 | if (llvm::MemoryBuffer *buf = (*I)->Buffer.get()) { |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4464 | size_t bytes = buf->getBufferSize(); |
| 4465 | switch (buf->getBufferKind()) { |
| 4466 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 4467 | sizes.malloc_bytes += bytes; |
| 4468 | break; |
| 4469 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 4470 | sizes.mmap_bytes += bytes; |
| 4471 | break; |
| 4472 | } |
| 4473 | } |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4474 | } |
Ted Kremenek | 5e1ed7b | 2011-04-28 23:46:20 +0000 | [diff] [blame] | 4475 | } |
| 4476 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4477 | void ASTReader::InitializeSema(Sema &S) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4478 | SemaObj = &S; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4479 | S.ExternalSource = this; |
| 4480 | |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4481 | // Makes sure any declarations that were deserialized "too early" |
| 4482 | // still get added to the identifier's declaration chains. |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4483 | for (unsigned I = 0, N = PreloadedDecls.size(); I != N; ++I) { |
| 4484 | if (SemaObj->TUScope) |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4485 | SemaObj->TUScope->AddDecl(PreloadedDecls[I]); |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4486 | |
| 4487 | SemaObj->IdResolver.AddDecl(PreloadedDecls[I]); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4488 | } |
Douglas Gregor | 7cd60f7 | 2009-04-22 21:15:06 +0000 | [diff] [blame] | 4489 | PreloadedDecls.clear(); |
Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4490 | |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4491 | // Load the offsets of the declarations that Sema references. |
| 4492 | // They will be lazily deserialized when needed. |
| 4493 | if (!SemaDeclRefs.empty()) { |
| 4494 | assert(SemaDeclRefs.size() == 2 && "More decl refs than expected!"); |
Douglas Gregor | b0f3ae6 | 2011-07-28 00:57:24 +0000 | [diff] [blame] | 4495 | if (!SemaObj->StdNamespace) |
| 4496 | SemaObj->StdNamespace = SemaDeclRefs[0]; |
| 4497 | if (!SemaObj->StdBadAlloc) |
| 4498 | SemaObj->StdBadAlloc = SemaDeclRefs[1]; |
Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4499 | } |
| 4500 | |
Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4501 | if (!FPPragmaOptions.empty()) { |
| 4502 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 4503 | SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0]; |
| 4504 | } |
| 4505 | |
| 4506 | if (!OpenCLExtensions.empty()) { |
| 4507 | unsigned I = 0; |
| 4508 | #define OPENCLEXT(nm) SemaObj->OpenCLFeatures.nm = OpenCLExtensions[I++]; |
| 4509 | #include "clang/Basic/OpenCLExtensions.def" |
| 4510 | |
| 4511 | assert(OpenCLExtensions.size() == I && "Wrong number of OPENCL_EXTENSIONS"); |
| 4512 | } |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4515 | IdentifierInfo* ASTReader::get(const char *NameStart, const char *NameEnd) { |
Douglas Gregor | ab443b9 | 2011-08-20 04:39:52 +0000 | [diff] [blame] | 4516 | IdentifierLookupVisitor Visitor(StringRef(NameStart, NameEnd - NameStart)); |
| 4517 | ModuleMgr.visit(IdentifierLookupVisitor::visit, &Visitor); |
| 4518 | return Visitor.getIdentifierInfo(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4521 | namespace clang { |
| 4522 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 4523 | /// identifiers stored within a set of AST files. |
| 4524 | class ASTIdentifierIterator : public IdentifierIterator { |
| 4525 | /// \brief The AST reader whose identifiers are being enumerated. |
| 4526 | const ASTReader &Reader; |
| 4527 | |
| 4528 | /// \brief The current index into the chain of AST files stored in |
| 4529 | /// the AST reader. |
| 4530 | unsigned Index; |
| 4531 | |
| 4532 | /// \brief The current position within the identifier lookup table |
| 4533 | /// of the current AST file. |
| 4534 | ASTIdentifierLookupTable::key_iterator Current; |
| 4535 | |
| 4536 | /// \brief The end position within the identifier lookup table of |
| 4537 | /// the current AST file. |
| 4538 | ASTIdentifierLookupTable::key_iterator End; |
| 4539 | |
| 4540 | public: |
| 4541 | explicit ASTIdentifierIterator(const ASTReader &Reader); |
| 4542 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4543 | virtual StringRef Next(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4544 | }; |
| 4545 | } |
| 4546 | |
| 4547 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader) |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4548 | : Reader(Reader), Index(Reader.ModuleMgr.size() - 1) { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4549 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4550 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index].IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4551 | Current = IdTable->key_begin(); |
| 4552 | End = IdTable->key_end(); |
| 4553 | } |
| 4554 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4555 | StringRef ASTIdentifierIterator::Next() { |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4556 | while (Current == End) { |
| 4557 | // If we have exhausted all of our AST files, we're done. |
| 4558 | if (Index == 0) |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4559 | return StringRef(); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4560 | |
| 4561 | --Index; |
| 4562 | ASTIdentifierLookupTable *IdTable |
Jonathan D. Turner | 16f57d3 | 2011-07-25 20:32:21 +0000 | [diff] [blame] | 4563 | = (ASTIdentifierLookupTable *)Reader.ModuleMgr[Index]. |
| 4564 | IdentifierLookupTable; |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4565 | Current = IdTable->key_begin(); |
| 4566 | End = IdTable->key_end(); |
| 4567 | } |
| 4568 | |
| 4569 | // We have any identifiers remaining in the current AST file; return |
| 4570 | // the next one. |
| 4571 | std::pair<const char*, unsigned> Key = *Current; |
| 4572 | ++Current; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4573 | return StringRef(Key.first, Key.second); |
Douglas Gregor | 57756ea | 2010-10-14 22:11:03 +0000 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | IdentifierIterator *ASTReader::getIdentifiers() const { |
| 4577 | return new ASTIdentifierIterator(*this); |
| 4578 | } |
| 4579 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4580 | namespace clang { namespace serialization { |
| 4581 | class ReadMethodPoolVisitor { |
| 4582 | ASTReader &Reader; |
| 4583 | Selector Sel; |
| 4584 | llvm::SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 4585 | llvm::SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4586 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4587 | /// \brief Build an ObjCMethodList from a vector of Objective-C method |
| 4588 | /// declarations. |
| 4589 | ObjCMethodList |
| 4590 | buildObjCMethodList(const SmallVectorImpl<ObjCMethodDecl *> &Vec) const |
| 4591 | { |
| 4592 | ObjCMethodList List; |
| 4593 | ObjCMethodList *Prev = 0; |
| 4594 | for (unsigned I = 0, N = Vec.size(); I != N; ++I) { |
| 4595 | if (!List.Method) { |
| 4596 | // This is the first method, which is the easy case. |
| 4597 | List.Method = Vec[I]; |
| 4598 | Prev = &List; |
| 4599 | continue; |
| 4600 | } |
| 4601 | |
| 4602 | ObjCMethodList *Mem = |
| 4603 | Reader.getSema()->BumpAlloc.Allocate<ObjCMethodList>(); |
| 4604 | Prev->Next = new (Mem) ObjCMethodList(Vec[I], 0); |
| 4605 | Prev = Prev->Next; |
| 4606 | } |
| 4607 | |
| 4608 | return List; |
| 4609 | } |
| 4610 | |
| 4611 | public: |
| 4612 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel) |
| 4613 | : Reader(Reader), Sel(Sel) { } |
| 4614 | |
| 4615 | static bool visit(Module &M, void *UserData) { |
| 4616 | ReadMethodPoolVisitor *This |
| 4617 | = static_cast<ReadMethodPoolVisitor *>(UserData); |
| 4618 | |
| 4619 | if (!M.SelectorLookupTable) |
| 4620 | return false; |
| 4621 | |
| 4622 | ASTSelectorLookupTable *PoolTable |
| 4623 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 4624 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(This->Sel); |
| 4625 | if (Pos == PoolTable->end()) |
| 4626 | return false; |
| 4627 | |
| 4628 | ++This->Reader.NumSelectorsRead; |
Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 4629 | // FIXME: Not quite happy with the statistics here. We probably should |
| 4630 | // disable this tracking when called via LoadSelector. |
| 4631 | // Also, should entries without methods count as misses? |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4632 | ++This->Reader.NumMethodPoolEntriesRead; |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4633 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4634 | if (This->Reader.DeserializationListener) |
| 4635 | This->Reader.DeserializationListener->SelectorRead(Data.ID, |
| 4636 | This->Sel); |
| 4637 | |
| 4638 | This->InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 4639 | This->FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 4640 | return true; |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4641 | } |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4642 | |
| 4643 | /// \brief Retrieve the instance methods found by this visitor. |
| 4644 | ObjCMethodList getInstanceMethods() const { |
| 4645 | return buildObjCMethodList(InstanceMethods); |
| 4646 | } |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4647 | |
Douglas Gregor | c10edd6 | 2011-08-25 14:51:20 +0000 | [diff] [blame] | 4648 | /// \brief Retrieve the instance methods found by this visitor. |
| 4649 | ObjCMethodList getFactoryMethods() const { |
| 4650 | return buildObjCMethodList(FactoryMethods); |
| 4651 | } |
| 4652 | }; |
| 4653 | } } // end namespace clang::serialization |
| 4654 | |
| 4655 | std::pair<ObjCMethodList, ObjCMethodList> |
| 4656 | ASTReader::ReadMethodPool(Selector Sel) { |
| 4657 | ReadMethodPoolVisitor Visitor(*this, Sel); |
| 4658 | ModuleMgr.visit(&ReadMethodPoolVisitor::visit, &Visitor); |
| 4659 | std::pair<ObjCMethodList, ObjCMethodList> Result; |
| 4660 | Result.first = Visitor.getInstanceMethods(); |
| 4661 | Result.second = Visitor.getFactoryMethods(); |
| 4662 | |
| 4663 | if (!Result.first.Method && !Result.second.Method) |
| 4664 | ++NumMethodPoolMisses; |
| 4665 | return Result; |
Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4668 | void ASTReader::ReadKnownNamespaces( |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4669 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4670 | Namespaces.clear(); |
| 4671 | |
| 4672 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 4673 | if (NamespaceDecl *Namespace |
| 4674 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 4675 | Namespaces.push_back(Namespace); |
| 4676 | } |
| 4677 | } |
| 4678 | |
Douglas Gregor | eb08bd4 | 2011-07-27 20:58:46 +0000 | [diff] [blame] | 4679 | void ASTReader::ReadTentativeDefinitions( |
| 4680 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 4681 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 4682 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 4683 | if (Var) |
| 4684 | TentativeDefs.push_back(Var); |
| 4685 | } |
| 4686 | TentativeDefinitions.clear(); |
| 4687 | } |
| 4688 | |
Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4689 | void ASTReader::ReadUnusedFileScopedDecls( |
| 4690 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 4691 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 4692 | DeclaratorDecl *D |
| 4693 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 4694 | if (D) |
| 4695 | Decls.push_back(D); |
| 4696 | } |
| 4697 | UnusedFileScopedDecls.clear(); |
| 4698 | } |
| 4699 | |
Douglas Gregor | bae3120 | 2011-07-27 21:57:17 +0000 | [diff] [blame] | 4700 | void ASTReader::ReadDelegatingConstructors( |
| 4701 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 4702 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 4703 | CXXConstructorDecl *D |
| 4704 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 4705 | if (D) |
| 4706 | Decls.push_back(D); |
| 4707 | } |
| 4708 | DelegatingCtorDecls.clear(); |
| 4709 | } |
| 4710 | |
Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4711 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 4712 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 4713 | TypedefNameDecl *D |
| 4714 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 4715 | if (D) |
| 4716 | Decls.push_back(D); |
| 4717 | } |
| 4718 | ExtVectorDecls.clear(); |
| 4719 | } |
| 4720 | |
Douglas Gregor | 3200219 | 2011-07-28 00:53:40 +0000 | [diff] [blame] | 4721 | void ASTReader::ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls) { |
| 4722 | for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) { |
| 4723 | CXXRecordDecl *D |
| 4724 | = dyn_cast_or_null<CXXRecordDecl>(GetDecl(DynamicClasses[I])); |
| 4725 | if (D) |
| 4726 | Decls.push_back(D); |
| 4727 | } |
| 4728 | DynamicClasses.clear(); |
| 4729 | } |
| 4730 | |
Douglas Gregor | dc5c958 | 2011-07-28 14:20:37 +0000 | [diff] [blame] | 4731 | void |
| 4732 | ASTReader::ReadLocallyScopedExternalDecls(SmallVectorImpl<NamedDecl *> &Decls) { |
| 4733 | for (unsigned I = 0, N = LocallyScopedExternalDecls.size(); I != N; ++I) { |
| 4734 | NamedDecl *D |
| 4735 | = dyn_cast_or_null<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I])); |
| 4736 | if (D) |
| 4737 | Decls.push_back(D); |
| 4738 | } |
| 4739 | LocallyScopedExternalDecls.clear(); |
| 4740 | } |
| 4741 | |
Douglas Gregor | 72e357f | 2011-07-28 14:54:22 +0000 | [diff] [blame] | 4742 | void ASTReader::ReadReferencedSelectors( |
| 4743 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 4744 | if (ReferencedSelectorsData.empty()) |
| 4745 | return; |
| 4746 | |
| 4747 | // If there are @selector references added them to its pool. This is for |
| 4748 | // implementation of -Wselector. |
| 4749 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 4750 | unsigned I = 0; |
| 4751 | while (I < DataSize) { |
| 4752 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 4753 | SourceLocation SelLoc |
| 4754 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 4755 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 4756 | } |
| 4757 | ReferencedSelectorsData.clear(); |
| 4758 | } |
| 4759 | |
Douglas Gregor | 1c4bfe5 | 2011-07-28 18:09:57 +0000 | [diff] [blame] | 4760 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 4761 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 4762 | if (WeakUndeclaredIdentifiers.empty()) |
| 4763 | return; |
| 4764 | |
| 4765 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| 4766 | IdentifierInfo *WeakId |
| 4767 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4768 | IdentifierInfo *AliasId |
| 4769 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 4770 | SourceLocation Loc |
| 4771 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 4772 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 4773 | WeakInfo WI(AliasId, Loc); |
| 4774 | WI.setUsed(Used); |
| 4775 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 4776 | } |
| 4777 | WeakUndeclaredIdentifiers.clear(); |
| 4778 | } |
| 4779 | |
Douglas Gregor | 4daf6a3 | 2011-07-28 19:11:31 +0000 | [diff] [blame] | 4780 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 4781 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 4782 | ExternalVTableUse VT; |
| 4783 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 4784 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 4785 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 4786 | VTables.push_back(VT); |
| 4787 | } |
| 4788 | |
| 4789 | VTableUses.clear(); |
| 4790 | } |
| 4791 | |
Douglas Gregor | e39f97c | 2011-07-28 19:49:54 +0000 | [diff] [blame] | 4792 | void ASTReader::ReadPendingInstantiations( |
| 4793 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 4794 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 4795 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 4796 | SourceLocation Loc |
| 4797 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 4798 | Pending.push_back(std::make_pair(D, Loc)); |
| 4799 | } |
| 4800 | PendingInstantiations.clear(); |
| 4801 | } |
| 4802 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4803 | void ASTReader::LoadSelector(Selector Sel) { |
Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4804 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 4805 | ReadMethodPool(Sel); |
| 4806 | } |
| 4807 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4808 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4809 | assert(ID && "Non-zero identifier ID required"); |
Douglas Gregor | 6f00bf8 | 2009-04-28 21:53:25 +0000 | [diff] [blame] | 4810 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 4811 | IdentifiersLoaded[ID - 1] = II; |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4812 | if (DeserializationListener) |
| 4813 | DeserializationListener->IdentifierRead(ID, II); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 4814 | } |
| 4815 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4816 | /// \brief Set the globally-visible declarations associated with the given |
| 4817 | /// identifier. |
| 4818 | /// |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4819 | /// 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] | 4820 | /// 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] | 4821 | /// them. |
| 4822 | /// |
| 4823 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 4824 | /// declarations. |
| 4825 | /// |
| 4826 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 4827 | /// visible at global scope. |
| 4828 | /// |
| 4829 | /// \param Nonrecursive should be true to indicate that the caller knows that |
| 4830 | /// this call is non-recursive, and therefore the globally-visible declarations |
| 4831 | /// will not be placed onto the pending queue. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4832 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4833 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4834 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4835 | bool Nonrecursive) { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 4836 | if (NumCurrentElementsDeserializing && !Nonrecursive) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4837 | PendingIdentifierInfos.push_back(PendingIdentifierInfo()); |
| 4838 | PendingIdentifierInfo &PII = PendingIdentifierInfos.back(); |
| 4839 | PII.II = II; |
Benjamin Kramer | 25f9ea6 | 2010-09-06 23:43:28 +0000 | [diff] [blame] | 4840 | PII.DeclIDs.append(DeclIDs.begin(), DeclIDs.end()); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4841 | return; |
| 4842 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4843 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4844 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 4845 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 4846 | if (SemaObj) { |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4847 | if (SemaObj->TUScope) { |
| 4848 | // Introduce this declaration into the translation-unit scope |
| 4849 | // and add it to the declaration chain for this identifier, so |
| 4850 | // that (unqualified) name lookup will find it. |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 4851 | SemaObj->TUScope->AddDecl(D); |
Douglas Gregor | 6fd55e0 | 2010-08-13 03:15:25 +0000 | [diff] [blame] | 4852 | } |
Douglas Gregor | 2fb99df | 2010-09-24 23:29:12 +0000 | [diff] [blame] | 4853 | SemaObj->IdResolver.AddDeclToIdentifierChain(II, D); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 4854 | } else { |
| 4855 | // Queue this declaration so that it will be added to the |
| 4856 | // translation unit scope and identifier's declaration chain |
| 4857 | // once a Sema object is known. |
| 4858 | PreloadedDecls.push_back(D); |
| 4859 | } |
| 4860 | } |
| 4861 | } |
| 4862 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4863 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4864 | if (ID == 0) |
| 4865 | return 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4866 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4867 | if (IdentifiersLoaded.empty()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4868 | Error("no identifier table in AST file"); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4869 | return 0; |
| 4870 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4871 | |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 4872 | assert(PP && "Forgot to set Preprocessor ?"); |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4873 | ID -= 1; |
| 4874 | if (!IdentifiersLoaded[ID]) { |
Douglas Gregor | 19d2635 | 2011-07-20 00:59:32 +0000 | [diff] [blame] | 4875 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 4876 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4877 | Module *M = I->second; |
| 4878 | unsigned Index = ID - M->BaseIdentifierID; |
| 4879 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
Douglas Gregor | 5287b4e | 2009-04-25 21:04:17 +0000 | [diff] [blame] | 4880 | |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4881 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 4882 | // Extract that 16-bit length to avoid having to execute strlen(). |
Ted Kremenek | ca42a51 | 2009-10-23 04:45:31 +0000 | [diff] [blame] | 4883 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 4884 | // unsigned integers. This is important to avoid integer overflow when |
| 4885 | // we cast them to 'unsigned'. |
Ted Kremenek | 49c5232 | 2009-10-23 03:57:22 +0000 | [diff] [blame] | 4886 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 4887 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 4888 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4889 | IdentifiersLoaded[ID] |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4890 | = &PP->getIdentifierTable().get(StringRef(Str, StrLen)); |
Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4891 | if (DeserializationListener) |
| 4892 | DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]); |
Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 4893 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4894 | |
Sebastian Redl | c713b96 | 2010-07-21 00:46:22 +0000 | [diff] [blame] | 4895 | return IdentifiersLoaded[ID]; |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4898 | IdentifierInfo *ASTReader::getLocalIdentifier(Module &M, unsigned LocalID) { |
| 4899 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 4900 | } |
| 4901 | |
| 4902 | IdentifierID ASTReader::getGlobalIdentifierID(Module &M, unsigned LocalID) { |
Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 4903 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 4904 | return LocalID; |
| 4905 | |
| 4906 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4907 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 4908 | assert(I != M.IdentifierRemap.end() |
| 4909 | && "Invalid index into identifier index remap"); |
| 4910 | |
| 4911 | return LocalID + I->second; |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 4914 | bool ASTReader::ReadSLocEntry(int ID) { |
Douglas Gregor | 49f754f | 2011-04-20 00:21:03 +0000 | [diff] [blame] | 4915 | return ReadSLocEntryRecord(ID) != Success; |
Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 4916 | } |
| 4917 | |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4918 | Selector ASTReader::getLocalSelector(Module &M, unsigned LocalID) { |
| 4919 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 4920 | } |
| 4921 | |
| 4922 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4923 | if (ID == 0) |
| 4924 | return Selector(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4925 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4926 | if (ID > SelectorsLoaded.size()) { |
Sebastian Redl | d44cd6a | 2010-08-18 23:57:06 +0000 | [diff] [blame] | 4927 | Error("selector ID out of range in AST file"); |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4928 | return Selector(); |
| 4929 | } |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4930 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4931 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == 0) { |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4932 | // Load this selector from the selector table. |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4933 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 4934 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4935 | Module &M = *I->second; |
| 4936 | ASTSelectorLookupTrait Trait(*this, M); |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4937 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4938 | SelectorsLoaded[ID - 1] = |
Douglas Gregor | bab6d2c | 2011-07-29 00:56:45 +0000 | [diff] [blame] | 4939 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
Douglas Gregor | 2262d28 | 2011-07-20 01:10:58 +0000 | [diff] [blame] | 4940 | if (DeserializationListener) |
| 4941 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4944 | return SelectorsLoaded[ID - 1]; |
Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 4945 | } |
| 4946 | |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4947 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4948 | return DecodeSelector(ID); |
| 4949 | } |
| 4950 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 4951 | uint32_t ASTReader::GetNumExternalSelectors() { |
Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 4952 | // ID 0 (the null selector) is considered an external selector. |
| 4953 | return getTotalNumSelectors() + 1; |
Douglas Gregor | d720daf | 2010-04-06 17:30:22 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 4956 | serialization::SelectorID |
| 4957 | ASTReader::getGlobalSelectorID(Module &M, unsigned LocalID) const { |
| 4958 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 4959 | return LocalID; |
| 4960 | |
| 4961 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 4962 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 4963 | assert(I != M.SelectorRemap.end() |
| 4964 | && "Invalid index into identifier index remap"); |
| 4965 | |
| 4966 | return LocalID + I->second; |
Douglas Gregor | 3f8f04f | 2011-07-28 14:41:43 +0000 | [diff] [blame] | 4967 | } |
| 4968 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4969 | DeclarationName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 4970 | ASTReader::ReadDeclarationName(Module &F, |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4971 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4972 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 4973 | switch (Kind) { |
| 4974 | case DeclarationName::Identifier: |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 4975 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4976 | |
| 4977 | case DeclarationName::ObjCZeroArgSelector: |
| 4978 | case DeclarationName::ObjCOneArgSelector: |
| 4979 | case DeclarationName::ObjCMultiArgSelector: |
Douglas Gregor | 074fdc5 | 2011-07-28 21:16:51 +0000 | [diff] [blame] | 4980 | return DeclarationName(ReadSelector(F, Record, Idx)); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4981 | |
| 4982 | case DeclarationName::CXXConstructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4983 | return Context->DeclarationNames.getCXXConstructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4984 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4985 | |
| 4986 | case DeclarationName::CXXDestructorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4987 | return Context->DeclarationNames.getCXXDestructorName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4988 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4989 | |
| 4990 | case DeclarationName::CXXConversionFunctionName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4991 | return Context->DeclarationNames.getCXXConversionFunctionName( |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 4992 | Context->getCanonicalType(readType(F, Record, Idx))); |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4993 | |
| 4994 | case DeclarationName::CXXOperatorName: |
Chris Lattner | 8575daa | 2009-04-27 21:45:14 +0000 | [diff] [blame] | 4995 | return Context->DeclarationNames.getCXXOperatorName( |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4996 | (OverloadedOperatorKind)Record[Idx++]); |
| 4997 | |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 4998 | case DeclarationName::CXXLiteralOperatorName: |
| 4999 | return Context->DeclarationNames.getCXXLiteralOperatorName( |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5000 | GetIdentifierInfo(F, Record, Idx)); |
Alexis Hunt | 3d221f2 | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 5001 | |
Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5002 | case DeclarationName::CXXUsingDirective: |
| 5003 | return DeclarationName::getUsingDirectiveName(); |
| 5004 | } |
| 5005 | |
| 5006 | // Required to silence GCC warning |
| 5007 | return DeclarationName(); |
| 5008 | } |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5009 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5010 | void ASTReader::ReadDeclarationNameLoc(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5011 | DeclarationNameLoc &DNLoc, |
| 5012 | DeclarationName Name, |
| 5013 | const RecordData &Record, unsigned &Idx) { |
| 5014 | switch (Name.getNameKind()) { |
| 5015 | case DeclarationName::CXXConstructorName: |
| 5016 | case DeclarationName::CXXDestructorName: |
| 5017 | case DeclarationName::CXXConversionFunctionName: |
| 5018 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5019 | break; |
| 5020 | |
| 5021 | case DeclarationName::CXXOperatorName: |
| 5022 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 5023 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5024 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 5025 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5026 | break; |
| 5027 | |
| 5028 | case DeclarationName::CXXLiteralOperatorName: |
| 5029 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 5030 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 5031 | break; |
| 5032 | |
| 5033 | case DeclarationName::Identifier: |
| 5034 | case DeclarationName::ObjCZeroArgSelector: |
| 5035 | case DeclarationName::ObjCOneArgSelector: |
| 5036 | case DeclarationName::ObjCMultiArgSelector: |
| 5037 | case DeclarationName::CXXUsingDirective: |
| 5038 | break; |
| 5039 | } |
| 5040 | } |
| 5041 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5042 | void ASTReader::ReadDeclarationNameInfo(Module &F, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5043 | DeclarationNameInfo &NameInfo, |
| 5044 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5045 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5046 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 5047 | DeclarationNameLoc DNLoc; |
| 5048 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 5049 | NameInfo.setInfo(DNLoc); |
| 5050 | } |
| 5051 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5052 | void ASTReader::ReadQualifierInfo(Module &F, QualifierInfo &Info, |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5053 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 5054 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5055 | unsigned NumTPLists = Record[Idx++]; |
| 5056 | Info.NumTemplParamLists = NumTPLists; |
| 5057 | if (NumTPLists) { |
| 5058 | Info.TemplParamLists = new (*Context) TemplateParameterList*[NumTPLists]; |
| 5059 | for (unsigned i=0; i != NumTPLists; ++i) |
| 5060 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 5061 | } |
| 5062 | } |
| 5063 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5064 | TemplateName |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5065 | ASTReader::ReadTemplateName(Module &F, const RecordData &Record, |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5066 | unsigned &Idx) { |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5067 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5068 | switch (Kind) { |
| 5069 | case TemplateName::Template: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5070 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5071 | |
| 5072 | case TemplateName::OverloadedTemplate: { |
| 5073 | unsigned size = Record[Idx++]; |
| 5074 | UnresolvedSet<8> Decls; |
| 5075 | while (size--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5076 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5077 | |
| 5078 | return Context->getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 5079 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5080 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5081 | case TemplateName::QualifiedTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5082 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5083 | bool hasTemplKeyword = Record[Idx++]; |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5084 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5085 | return Context->getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 5086 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5087 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5088 | case TemplateName::DependentTemplate: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5089 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5090 | if (Record[Idx++]) // isIdentifier |
| 5091 | return Context->getDependentTemplateName(NNS, |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5092 | GetIdentifierInfo(F, Record, |
| 5093 | Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5094 | return Context->getDependentTemplateName(NNS, |
Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5095 | (OverloadedOperatorKind)Record[Idx++]); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5096 | } |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5097 | |
| 5098 | case TemplateName::SubstTemplateTemplateParm: { |
| 5099 | TemplateTemplateParmDecl *param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5100 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
John McCall | d9dfe3a | 2011-06-30 08:33:18 +0000 | [diff] [blame] | 5101 | if (!param) return TemplateName(); |
| 5102 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 5103 | return Context->getSubstTemplateTemplateParm(param, replacement); |
| 5104 | } |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5105 | |
| 5106 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 5107 | TemplateTemplateParmDecl *Param |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5108 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5109 | if (!Param) |
| 5110 | return TemplateName(); |
| 5111 | |
| 5112 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 5113 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 5114 | return TemplateName(); |
| 5115 | |
| 5116 | return Context->getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 5117 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5118 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5119 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5120 | assert(0 && "Unhandled template name kind!"); |
| 5121 | return TemplateName(); |
| 5122 | } |
| 5123 | |
| 5124 | TemplateArgument |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5125 | ASTReader::ReadTemplateArgument(Module &F, |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 5126 | const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5127 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 5128 | switch (Kind) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5129 | case TemplateArgument::Null: |
| 5130 | return TemplateArgument(); |
| 5131 | case TemplateArgument::Type: |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5132 | return TemplateArgument(readType(F, Record, Idx)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5133 | case TemplateArgument::Declaration: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5134 | return TemplateArgument(ReadDecl(F, Record, Idx)); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5135 | case TemplateArgument::Integral: { |
| 5136 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5137 | QualType T = readType(F, Record, Idx); |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 5138 | return TemplateArgument(Value, T); |
| 5139 | } |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5140 | case TemplateArgument::Template: |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5141 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5142 | case TemplateArgument::TemplateExpansion: { |
Douglas Gregor | 5590be0 | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 5143 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 5144 | llvm::Optional<unsigned> NumTemplateExpansions; |
| 5145 | if (unsigned NumExpansions = Record[Idx++]) |
| 5146 | NumTemplateExpansions = NumExpansions - 1; |
| 5147 | return TemplateArgument(Name, NumTemplateExpansions); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 5148 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5149 | case TemplateArgument::Expression: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5150 | return TemplateArgument(ReadExpr(F)); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5151 | case TemplateArgument::Pack: { |
| 5152 | unsigned NumArgs = Record[Idx++]; |
Douglas Gregor | 1ccc841 | 2010-11-07 23:05:16 +0000 | [diff] [blame] | 5153 | TemplateArgument *Args = new (*Context) TemplateArgument[NumArgs]; |
| 5154 | for (unsigned I = 0; I != NumArgs; ++I) |
| 5155 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| 5156 | return TemplateArgument(Args, NumArgs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5157 | } |
| 5158 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5159 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 5160 | assert(0 && "Unhandled template argument kind!"); |
| 5161 | return TemplateArgument(); |
| 5162 | } |
| 5163 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5164 | TemplateParameterList * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5165 | ASTReader::ReadTemplateParameterList(Module &F, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5166 | const RecordData &Record, unsigned &Idx) { |
| 5167 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 5168 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 5169 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5170 | |
| 5171 | unsigned NumParams = Record[Idx++]; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5172 | SmallVector<NamedDecl *, 16> Params; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5173 | Params.reserve(NumParams); |
| 5174 | while (NumParams--) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5175 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5176 | |
| 5177 | TemplateParameterList* TemplateParams = |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5178 | TemplateParameterList::Create(*Context, TemplateLoc, LAngleLoc, |
| 5179 | Params.data(), Params.size(), RAngleLoc); |
| 5180 | return TemplateParams; |
| 5181 | } |
| 5182 | |
| 5183 | void |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5184 | ASTReader:: |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5185 | ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs, |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5186 | Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5187 | unsigned &Idx) { |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5188 | unsigned NumTemplateArgs = Record[Idx++]; |
| 5189 | TemplArgs.reserve(NumTemplateArgs); |
| 5190 | while (NumTemplateArgs--) |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5191 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx)); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5192 | } |
| 5193 | |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5194 | /// \brief Read a UnresolvedSet structure. |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5195 | void ASTReader::ReadUnresolvedSet(Module &F, UnresolvedSetImpl &Set, |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5196 | const RecordData &Record, unsigned &Idx) { |
| 5197 | unsigned NumDecls = Record[Idx++]; |
| 5198 | while (NumDecls--) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5199 | NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5200 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| 5201 | Set.addDecl(D, AS); |
| 5202 | } |
| 5203 | } |
| 5204 | |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5205 | CXXBaseSpecifier |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5206 | ASTReader::ReadCXXBaseSpecifier(Module &F, |
Nick Lewycky | 19b9f95 | 2010-07-26 16:56:01 +0000 | [diff] [blame] | 5207 | const RecordData &Record, unsigned &Idx) { |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5208 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 5209 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 5210 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5211 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5212 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 5213 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5214 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5215 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Douglas Gregor | 752a595 | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 5216 | EllipsisLoc); |
Sebastian Redl | 0890502 | 2011-02-05 19:23:19 +0000 | [diff] [blame] | 5217 | Result.setInheritConstructors(inheritConstructors); |
| 5218 | return Result; |
Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5219 | } |
| 5220 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5221 | std::pair<CXXCtorInitializer **, unsigned> |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5222 | ASTReader::ReadCXXCtorInitializers(Module &F, const RecordData &Record, |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5223 | unsigned &Idx) { |
| 5224 | CXXCtorInitializer **CtorInitializers = 0; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5225 | unsigned NumInitializers = Record[Idx++]; |
| 5226 | if (NumInitializers) { |
| 5227 | ASTContext &C = *getContext(); |
| 5228 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5229 | CtorInitializers |
| 5230 | = new (C) CXXCtorInitializer*[NumInitializers]; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5231 | for (unsigned i=0; i != NumInitializers; ++i) { |
| 5232 | TypeSourceInfo *BaseClassInfo = 0; |
| 5233 | bool IsBaseVirtual = false; |
| 5234 | FieldDecl *Member = 0; |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5235 | IndirectFieldDecl *IndirectMember = 0; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5236 | CXXConstructorDecl *Target = 0; |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5237 | |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5238 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 5239 | switch (Type) { |
| 5240 | case CTOR_INITIALIZER_BASE: |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5241 | BaseClassInfo = GetTypeSourceInfo(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5242 | IsBaseVirtual = Record[Idx++]; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5243 | break; |
| 5244 | |
| 5245 | case CTOR_INITIALIZER_DELEGATING: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5246 | Target = ReadDeclAs<CXXConstructorDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5247 | break; |
| 5248 | |
| 5249 | case CTOR_INITIALIZER_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5250 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5251 | break; |
| 5252 | |
| 5253 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5254 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5255 | break; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5256 | } |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5257 | |
Douglas Gregor | 44e7df6 | 2011-01-04 00:32:56 +0000 | [diff] [blame] | 5258 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5259 | Expr *Init = ReadExpr(F); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5260 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 5261 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5262 | bool IsWritten = Record[Idx++]; |
| 5263 | unsigned SourceOrderOrNumArrayIndices; |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5264 | SmallVector<VarDecl *, 8> Indices; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5265 | if (IsWritten) { |
| 5266 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5267 | } else { |
| 5268 | SourceOrderOrNumArrayIndices = Record[Idx++]; |
| 5269 | Indices.reserve(SourceOrderOrNumArrayIndices); |
| 5270 | for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i) |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5271 | Indices.push_back(ReadDeclAs<VarDecl>(F, Record, Idx)); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5272 | } |
Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5273 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5274 | CXXCtorInitializer *BOMInit; |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5275 | if (Type == CTOR_INITIALIZER_BASE) { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5276 | BOMInit = new (C) CXXCtorInitializer(C, BaseClassInfo, IsBaseVirtual, |
| 5277 | LParenLoc, Init, RParenLoc, |
| 5278 | MemberOrEllipsisLoc); |
Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5279 | } else if (Type == CTOR_INITIALIZER_DELEGATING) { |
| 5280 | BOMInit = new (C) CXXCtorInitializer(C, MemberOrEllipsisLoc, LParenLoc, |
| 5281 | Target, Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5282 | } else if (IsWritten) { |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5283 | if (Member) |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5284 | BOMInit = new (C) CXXCtorInitializer(C, Member, MemberOrEllipsisLoc, |
| 5285 | LParenLoc, Init, RParenLoc); |
Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5286 | else |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5287 | BOMInit = new (C) CXXCtorInitializer(C, IndirectMember, |
| 5288 | MemberOrEllipsisLoc, LParenLoc, |
| 5289 | Init, RParenLoc); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5290 | } else { |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5291 | BOMInit = CXXCtorInitializer::Create(C, Member, MemberOrEllipsisLoc, |
| 5292 | LParenLoc, Init, RParenLoc, |
| 5293 | Indices.data(), Indices.size()); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
Argyrios Kyrtzidis | d05f3e3 | 2010-09-06 19:04:27 +0000 | [diff] [blame] | 5296 | if (IsWritten) |
| 5297 | BOMInit->setSourceOrder(SourceOrderOrNumArrayIndices); |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5298 | CtorInitializers[i] = BOMInit; |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5299 | } |
| 5300 | } |
| 5301 | |
Alexis Hunt | 1d79265 | 2011-01-08 20:30:50 +0000 | [diff] [blame] | 5302 | return std::make_pair(CtorInitializers, NumInitializers); |
Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5303 | } |
| 5304 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5305 | NestedNameSpecifier * |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5306 | ASTReader::ReadNestedNameSpecifier(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5307 | const RecordData &Record, unsigned &Idx) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5308 | unsigned N = Record[Idx++]; |
| 5309 | NestedNameSpecifier *NNS = 0, *Prev = 0; |
| 5310 | for (unsigned I = 0; I != N; ++I) { |
| 5311 | NestedNameSpecifier::SpecifierKind Kind |
| 5312 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5313 | switch (Kind) { |
| 5314 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5315 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5316 | NNS = NestedNameSpecifier::Create(*Context, Prev, II); |
| 5317 | break; |
| 5318 | } |
| 5319 | |
| 5320 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5321 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5322 | NNS = NestedNameSpecifier::Create(*Context, Prev, NS); |
| 5323 | break; |
| 5324 | } |
| 5325 | |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5326 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5327 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 5328 | NNS = NestedNameSpecifier::Create(*Context, Prev, Alias); |
| 5329 | break; |
| 5330 | } |
| 5331 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5332 | case NestedNameSpecifier::TypeSpec: |
| 5333 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | 903b7e9 | 2011-07-22 00:38:23 +0000 | [diff] [blame] | 5334 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
Douglas Gregor | 0cdc832 | 2010-12-10 17:03:06 +0000 | [diff] [blame] | 5335 | if (!T) |
| 5336 | return 0; |
| 5337 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5338 | bool Template = Record[Idx++]; |
| 5339 | NNS = NestedNameSpecifier::Create(*Context, Prev, Template, T); |
| 5340 | break; |
| 5341 | } |
| 5342 | |
| 5343 | case NestedNameSpecifier::Global: { |
| 5344 | NNS = NestedNameSpecifier::GlobalSpecifier(*Context); |
| 5345 | // No associated value, and there can't be a prefix. |
| 5346 | break; |
| 5347 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5348 | } |
Argyrios Kyrtzidis | ad65c69 | 2010-07-07 15:46:30 +0000 | [diff] [blame] | 5349 | Prev = NNS; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5350 | } |
| 5351 | return NNS; |
| 5352 | } |
| 5353 | |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5354 | NestedNameSpecifierLoc |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5355 | ASTReader::ReadNestedNameSpecifierLoc(Module &F, const RecordData &Record, |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5356 | unsigned &Idx) { |
| 5357 | unsigned N = Record[Idx++]; |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5358 | NestedNameSpecifierLocBuilder Builder; |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5359 | for (unsigned I = 0; I != N; ++I) { |
| 5360 | NestedNameSpecifier::SpecifierKind Kind |
| 5361 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 5362 | switch (Kind) { |
| 5363 | case NestedNameSpecifier::Identifier: { |
Douglas Gregor | a3e4153 | 2011-07-28 20:55:49 +0000 | [diff] [blame] | 5364 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5365 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5366 | Builder.Extend(*Context, II, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5367 | break; |
| 5368 | } |
| 5369 | |
| 5370 | case NestedNameSpecifier::Namespace: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5371 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5372 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5373 | Builder.Extend(*Context, NS, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5374 | break; |
| 5375 | } |
| 5376 | |
| 5377 | case NestedNameSpecifier::NamespaceAlias: { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5378 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5379 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5380 | Builder.Extend(*Context, Alias, Range.getBegin(), Range.getEnd()); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5381 | break; |
| 5382 | } |
| 5383 | |
| 5384 | case NestedNameSpecifier::TypeSpec: |
| 5385 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5386 | bool Template = Record[Idx++]; |
| 5387 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 5388 | if (!T) |
| 5389 | return NestedNameSpecifierLoc(); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5390 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5391 | |
| 5392 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| 5393 | Builder.Extend(*Context, |
| 5394 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 5395 | T->getTypeLoc(), ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5396 | break; |
| 5397 | } |
| 5398 | |
| 5399 | case NestedNameSpecifier::Global: { |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5400 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5401 | Builder.MakeGlobal(*Context, ColonColonLoc); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5402 | break; |
| 5403 | } |
| 5404 | } |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5405 | } |
| 5406 | |
Douglas Gregor | 9b27251 | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 5407 | return Builder.getWithLocInContext(*Context); |
Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5408 | } |
| 5409 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5410 | SourceRange |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5411 | ASTReader::ReadSourceRange(Module &F, const RecordData &Record, |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 5412 | unsigned &Idx) { |
| 5413 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 5414 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
Daniel Dunbar | 6d3bc08 | 2010-06-02 15:47:10 +0000 | [diff] [blame] | 5415 | return SourceRange(beg, end); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5416 | } |
| 5417 | |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5418 | /// \brief Read an integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5419 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5420 | unsigned BitWidth = Record[Idx++]; |
| 5421 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 5422 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 5423 | Idx += NumWords; |
| 5424 | return Result; |
| 5425 | } |
| 5426 | |
| 5427 | /// \brief Read a signed integral value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5428 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | 1daeb69 | 2009-04-13 18:14:40 +0000 | [diff] [blame] | 5429 | bool isUnsigned = Record[Idx++]; |
| 5430 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 5431 | } |
| 5432 | |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5433 | /// \brief Read a floating-point value |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5434 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5435 | return llvm::APFloat(ReadAPInt(Record, Idx)); |
| 5436 | } |
| 5437 | |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5438 | // \brief Read a string |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5439 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5440 | unsigned Len = Record[Idx++]; |
Jay Foad | 7d0479f | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 5441 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 5442 | Idx += Len; |
| 5443 | return Result; |
| 5444 | } |
| 5445 | |
Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 5446 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 5447 | unsigned &Idx) { |
| 5448 | unsigned Major = Record[Idx++]; |
| 5449 | unsigned Minor = Record[Idx++]; |
| 5450 | unsigned Subminor = Record[Idx++]; |
| 5451 | if (Minor == 0) |
| 5452 | return VersionTuple(Major); |
| 5453 | if (Subminor == 0) |
| 5454 | return VersionTuple(Major, Minor - 1); |
| 5455 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 5456 | } |
| 5457 | |
Douglas Gregor | a6895d8 | 2011-07-22 16:00:58 +0000 | [diff] [blame] | 5458 | CXXTemporary *ASTReader::ReadCXXTemporary(Module &F, |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5459 | const RecordData &Record, |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5460 | unsigned &Idx) { |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 5461 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5462 | return CXXTemporary::Create(*Context, Decl); |
| 5463 | } |
| 5464 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5465 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) { |
Douglas Gregor | 92863e4 | 2009-04-10 23:10:45 +0000 | [diff] [blame] | 5466 | return Diag(SourceLocation(), DiagID); |
| 5467 | } |
| 5468 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5469 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 5470 | return Diags.Report(Loc, DiagID); |
Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 5471 | } |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5472 | |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5473 | /// \brief Retrieve the identifier table associated with the |
| 5474 | /// preprocessor. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5475 | IdentifierTable &ASTReader::getIdentifierTable() { |
Argyrios Kyrtzidis | 366985d | 2009-06-19 00:03:23 +0000 | [diff] [blame] | 5476 | assert(PP && "Forgot to set Preprocessor ?"); |
| 5477 | return PP->getIdentifierTable(); |
Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 5478 | } |
| 5479 | |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5480 | /// \brief Record that the given ID maps to the given switch-case |
| 5481 | /// statement. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5482 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5483 | assert(SwitchCaseStmts[ID] == 0 && "Already have a SwitchCase with this ID"); |
| 5484 | SwitchCaseStmts[ID] = SC; |
| 5485 | } |
| 5486 | |
| 5487 | /// \brief Retrieve the switch-case statement with the given ID. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5488 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 5489 | assert(SwitchCaseStmts[ID] != 0 && "No SwitchCase with this ID"); |
| 5490 | return SwitchCaseStmts[ID]; |
| 5491 | } |
Douglas Gregor | 6cc68a4 | 2009-04-17 18:18:49 +0000 | [diff] [blame] | 5492 | |
Argyrios Kyrtzidis | d9f526f | 2010-10-28 09:29:32 +0000 | [diff] [blame] | 5493 | void ASTReader::ClearSwitchCaseIDs() { |
| 5494 | SwitchCaseStmts.clear(); |
| 5495 | } |
| 5496 | |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 5497 | void ASTReader::FinishedDeserializing() { |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5498 | assert(NumCurrentElementsDeserializing && |
| 5499 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 5500 | if (NumCurrentElementsDeserializing == 1) { |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5501 | // If any identifiers with corresponding top-level declarations have |
| 5502 | // been loaded, load those declarations now. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5503 | while (!PendingIdentifierInfos.empty()) { |
| 5504 | SetGloballyVisibleDecls(PendingIdentifierInfos.front().II, |
| 5505 | PendingIdentifierInfos.front().DeclIDs, true); |
| 5506 | PendingIdentifierInfos.pop_front(); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5507 | } |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5508 | |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 5509 | // Ready to load previous declarations of Decls that were delayed. |
| 5510 | while (!PendingPreviousDecls.empty()) { |
| 5511 | loadAndAttachPreviousDecl(PendingPreviousDecls.front().first, |
| 5512 | PendingPreviousDecls.front().second); |
| 5513 | PendingPreviousDecls.pop_front(); |
| 5514 | } |
| 5515 | |
Argyrios Kyrtzidis | 903ccd6 | 2010-07-07 15:46:26 +0000 | [diff] [blame] | 5516 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 5517 | // decls to the consumer. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5518 | if (Consumer) |
| 5519 | PassInterestingDeclsToConsumer(); |
Argyrios Kyrtzidis | ad5f95c | 2010-10-24 17:26:31 +0000 | [diff] [blame] | 5520 | |
| 5521 | assert(PendingForwardRefs.size() == 0 && |
| 5522 | "Some forward refs did not get linked to the definition!"); |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5523 | } |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 5524 | --NumCurrentElementsDeserializing; |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 5525 | } |
Douglas Gregor | b473b07 | 2010-08-19 00:28:17 +0000 | [diff] [blame] | 5526 | |
Douglas Gregor | 8835e03 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 5527 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
Douglas Gregor | c567ba2 | 2011-07-22 16:35:34 +0000 | [diff] [blame] | 5528 | StringRef isysroot, bool DisableValidation, |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5529 | bool DisableStatCache) |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5530 | : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), |
| 5531 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
Douglas Gregor | 8835e03 | 2011-09-02 00:26:20 +0000 | [diff] [blame] | 5532 | Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(&Context), |
Jonathan D. Turner | ecc2740 | 2011-07-28 17:20:23 +0000 | [diff] [blame] | 5533 | Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), |
| 5534 | RelocatablePCH(false), isysroot(isysroot), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5535 | DisableValidation(DisableValidation), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5536 | DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5537 | NumSLocEntriesRead(0), TotalNumSLocEntries(0), |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5538 | NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), |
| 5539 | TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), |
| 5540 | NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), |
| 5541 | NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), |
Jonathan D. Turner | 3766fdb | 2011-07-21 21:15:19 +0000 | [diff] [blame] | 5542 | NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), |
| 5543 | TotalModulesSizeInBits(0), NumCurrentElementsDeserializing(0), |
| 5544 | NumCXXBaseSpecifiersLoaded(0) |
Douglas Gregor | 606c4ac | 2011-02-05 19:42:43 +0000 | [diff] [blame] | 5545 | { |
Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5546 | SourceMgr.setExternalSLocEntrySource(this); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5547 | } |
| 5548 | |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5549 | ASTReader::~ASTReader() { |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5550 | for (DeclContextVisibleUpdatesPending::iterator |
| 5551 | I = PendingVisibleUpdates.begin(), |
| 5552 | E = PendingVisibleUpdates.end(); |
| 5553 | I != E; ++I) { |
| 5554 | for (DeclContextVisibleUpdates::iterator J = I->second.begin(), |
| 5555 | F = I->second.end(); |
| 5556 | J != F; ++J) |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 5557 | delete static_cast<ASTDeclContextNameLookupTable*>(J->first); |
Sebastian Redl | d7dce0a | 2010-08-24 00:50:04 +0000 | [diff] [blame] | 5558 | } |
| 5559 | } |