16ab7cd853e9c15cf986a8a7c3db1f8d20e275409Sebastian Redl//===--- ASTReader.h - AST File Reader --------------------------*- C++ -*-===//
22cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
32cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//                     The LLVM Compiler Infrastructure
42cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
52cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// This file is distributed under the University of Illinois Open Source
62cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor// License. See LICENSE.TXT for details.
72cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
82cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
92cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
10c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl//  This file defines the ASTReader class, which reads AST files.
112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//
122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor//===----------------------------------------------------------------------===//
138b12273c86ede439edf52d35b170fd32b2ed49d4Sebastian Redl
14f29f0a28c4d9599b389bbb6d186e14af753dc5a3Sebastian Redl#ifndef LLVM_CLANG_FRONTEND_AST_READER_H
15f29f0a28c4d9599b389bbb6d186e14af753dc5a3Sebastian Redl#define LLVM_CLANG_FRONTEND_AST_READER_H
162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1705a07605322dfef2b017781042043a261c5a89cdSebastian Redl#include "clang/Serialization/ASTBitCodes.h"
18f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor#include "clang/Serialization/ContinuousRangeMap.h"
1998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "clang/Serialization/Module.h"
2098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor#include "clang/Serialization/ModuleManager.h"
21668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Sema/ExternalSemaSource.h"
22c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl#include "clang/AST/DeclarationName.h"
23f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor#include "clang/AST/DeclObjC.h"
24833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall#include "clang/AST/TemplateBase.h"
2588a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor#include "clang/Lex/ExternalPreprocessorSource.h"
26cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor#include "clang/Lex/HeaderSearch.h"
276a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor#include "clang/Lex/PreprocessingRecord.h"
280a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor#include "clang/Basic/Diagnostic.h"
291afb661bc5444462a246cefa0effa61ef25fab29Jonathan D. Turner#include "clang/Basic/FileManager.h"
301afb661bc5444462a246cefa0effa61ef25fab29Jonathan D. Turner#include "clang/Basic/FileSystemOptions.h"
31668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor#include "clang/Basic/IdentifierTable.h"
327f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor#include "clang/Basic/SourceManager.h"
3317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor#include "llvm/ADT/APFloat.h"
340a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APInt.h"
350a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor#include "llvm/ADT/APSInt.h"
362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/OwningPtr.h"
370f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor#include "llvm/ADT/SmallPtrSet.h"
380f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor#include "llvm/ADT/SmallSet.h"
392cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/SmallVector.h"
40dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar#include "llvm/ADT/StringRef.h"
41e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis#include "llvm/ADT/DenseSet.h"
422cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamReader.h"
4303013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/DataTypes.h"
44d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor#include <deque>
45025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor#include <map>
462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <string>
472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <utility>
482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <vector>
492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace llvm {
512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  class MemoryBuffer;
522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
542cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace clang {
552cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
567d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregorclass AddrLabelExpr;
570af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregorclass ASTConsumer;
582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass ASTContext;
5995f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregorclass ASTIdentifierIterator;
60f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTUnit; // FIXME: Layering violation and egregious hack.
6168a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregorclass Attr;
622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass Decl;
632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass DeclContext;
646ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass NestedNameSpecifier;
656ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass CXXBaseSpecifier;
66ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Huntclass CXXConstructorDecl;
67cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
681de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregorclass GotoStmt;
696a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregorclass MacroDefinition;
70668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass NamedDecl;
7156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr;
7214f79002e58556798e86168c63e48d533287eda5Douglas Gregorclass Preprocessor;
73668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass Sema;
74025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorclass SwitchCase;
75c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTDeserializationListener;
76f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTWriter;
77c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader;
78d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redlclass ASTDeclReader;
79c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTStmtReader;
80c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass TypeLocReader;
81eb19485625c7529ffa644e10829533157a8e8d4fDaniel Dunbarstruct HeaderFileInfo;
820a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregorclass VersionTuple;
8311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
847e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redlstruct PCHPredefinesBlock {
857e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief The file ID for this predefines buffer in a PCH file.
867e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  FileID BufferID;
877e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
887e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief This predefines buffer in a PCH file.
89686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef Data;
907e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl};
91686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks;
927e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
93c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Abstract interface for callback invocations by the ASTReader.
9411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis///
95c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// While reading an AST file, the ASTReader will call the methods of the
9611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// listener to pass on specific information. Some of the listener methods can
97c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// return true to indicate to the ASTReader that the information (and
98571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// consequently the AST file) is invalid.
99571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass ASTReaderListener {
10011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
101571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  virtual ~ASTReaderListener();
1021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the language options.
10411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
10511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the options are invalid or false otherwise.
10611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
10711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
10811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the target triple.
11111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the target triple is invalid or false otherwise.
113686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual bool ReadTargetTriple(StringRef Triple) {
11411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
11511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the contents of the predefines buffer.
11811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11930c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \param Buffers Information about the predefines buffers.
12011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
1213c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param OriginalFileName The original file name for the AST file, which
1223c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// will appear as an entry in the predefines buffer.
1237b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  ///
12411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \param SuggestedPredefines If necessary, additional definitions are added
12511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// here.
12611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
12711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the predefines are invalid or false otherwise.
1287e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
129686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
130277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
131277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    FileManager &FileMgr) {
13211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
13311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives a HeaderFileInfo entry.
13612fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives __COUNTER__ value.
13911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value) {}
14011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
14111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
142571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// \brief ASTReaderListener implementation to validate the information of
14311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// the PCH file against an initialized Preprocessor.
144571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass PCHValidator : public ASTReaderListener {
14511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor &PP;
146c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &Reader;
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  unsigned NumHeaderInfos;
1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
151c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  PCHValidator(Preprocessor &PP, ASTReader &Reader)
15211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
155686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual bool ReadTargetTriple(StringRef Triple);
1567e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
157686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
158277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
159277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    FileManager &FileMgr);
16012fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
16111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value);
162d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
163d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekprivate:
164d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  void Error(const char *Msg);
16511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
1662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
167ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikienamespace serialization {
1685d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner
1693d15ab8d0822637ff5e39594c4f34172241cad2eDouglas Gregorclass ReadMethodPoolVisitor;
170ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregornamespace reader {
17298339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor  class ASTIdentifierLookupTrait;
173b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer  /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
174b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer  typedef OnDiskChainedHashTable<ASTDeclContextNameLookupTrait>
175b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer    ASTDeclContextNameLookupTable;
17698339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor}
177ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17872a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor} // end namespace serialization
179ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
180c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Reads an AST files chain containing the contents of a translation
181c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// unit.
1822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
183c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The ASTReader class reads bitstreams (produced by the ASTWriter
1842cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// class) containing the serialized representation of a given
1852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// abstract syntax tree and its supporting data structures. An
186c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// instance of the ASTReader can be attached to an ASTContext object,
187c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// which will provide access to the contents of the AST files.
1882cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
189c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The AST reader provides lazy de-serialization of declarations, as
1902cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// required when traversing the AST. Only those AST nodes that are
1912cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// actually required will be de-serialized.
192c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader
19388a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  : public ExternalPreprocessorSource,
1946a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    public ExternalPreprocessingRecordSource,
195cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    public ExternalHeaderFileInfoSource,
19688a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor    public ExternalSemaSource,
1978c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    public IdentifierInfoLookup,
1987f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor    public ExternalIdentifierLookup,
199ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    public ExternalSLocEntrySource
200cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor{
201e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorpublic:
202260611a32535c851237926bfcf78869b13c07d5bJohn McCall  typedef SmallVector<uint64_t, 64> RecordData;
203260611a32535c851237926bfcf78869b13c07d5bJohn McCall
204c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  enum ASTReadResult { Success, Failure, IgnorePCH };
2051d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  /// \brief Types of AST files.
206d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  friend class PCHValidator;
207d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
208c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class ASTStmtReader;
20995f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  friend class ASTIdentifierIterator;
21098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor  friend class serialization::reader::ASTIdentifierLookupTrait;
211c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class TypeLocReader;
212f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTWriter;
213f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTUnit; // ASTUnit needs to remap source locations.
2143d15ab8d0822637ff5e39594c4f34172241cad2eDouglas Gregor  friend class serialization::ReadMethodPoolVisitor;
215ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2161a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef serialization::ModuleFile ModuleFile;
21772a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor  typedef serialization::ModuleKind ModuleKind;
2185d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef serialization::ModuleManager ModuleManager;
219ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2205d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleIterator ModuleIterator;
2215d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
2225d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
2235d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner
224e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorprivate:
225c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief The receiver of some callbacks invoked by ASTReader.
2266f42b62b6194f53bcbc349f5d17388e1936535d7Dylan Noblesmith  OwningPtr<ASTReaderListener> Listener;
2271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22830c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \brief The receiver of deserialization events.
229571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTDeserializationListener *DeserializationListener;
23030c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
23111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  SourceManager &SourceMgr;
23211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  FileManager &FileMgr;
233d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &Diags;
234ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
235668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief The semantic analysis object that will be processing the
2363c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST files and the translation unit that uses it.
237668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *SemaObj;
238668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
23914f79002e58556798e86168c63e48d533287eda5Douglas Gregor  /// \brief The preprocessor that will be loading the source file.
240712f2fcb70ae2eb0cb684d565e7d2cb76881006bDouglas Gregor  Preprocessor &PP;
24114f79002e58556798e86168c63e48d533287eda5Douglas Gregor
2423c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The AST context into which we'll read the AST files.
243359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  ASTContext &Context;
244ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2450af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  /// \brief The AST consumer.
2460af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  ASTConsumer *Consumer;
2470af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor
2485d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  /// \brief The module manager which manages modules and their dependencies
2495d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  ModuleManager ModuleMgr;
2509137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
2518f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  /// \brief A map of global bit offsets to the module that stores entities
2528f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  /// at those bit offsets.
2531a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
2548f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor
255f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief A map of negated SLocEntryIDs to the modules containing them.
2561a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
2574ee5a6f9bd82ab3c1a4bdacc0caefe7d5f8bd37aSebastian Redl
2581a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
259ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
260a68c4aff8cd3aada697ad36dc6582d0e09b4b0d2Argyrios Kyrtzidis  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
261a68c4aff8cd3aada697ad36dc6582d0e09b4b0d2Argyrios Kyrtzidis  /// SourceLocation offsets to the modules containing them.
2622dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
263ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2643c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Types that have already been loaded from the chain.
2651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
2661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// When the pointer at index I is non-NULL, the type with
2673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// ID = (I + 1) << FastQual::Width has already been loaded
2680953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::vector<QualType> TypesLoaded;
2692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2701a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
271e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner    GlobalTypeMapType;
272e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
273e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// \brief Mapping from global type IDs to the module in which the
274e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// type resides along with the offset that should be added to the
275e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// global type ID to produce a local ID.
276e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  GlobalTypeMapType GlobalTypeMap;
277e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
2783c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Declarations that have already been loaded from the chain.
2792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
2808f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// When the pointer at index I is non-NULL, the declaration with ID
2818f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// = I + 1 has already been loaded.
2828f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  std::vector<Decl *> DeclsLoaded;
2832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2841a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
28596e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor    GlobalDeclMapType;
286ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
28796e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  /// \brief Mapping from global declaration IDs to the module in which the
2889827a8049a793f23c62ade8f24f0c66c2dbf6741Douglas Gregor  /// declaration resides.
28996e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  GlobalDeclMapType GlobalDeclMap;
290ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2911a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef std::pair<ModuleFile *, uint64_t> FileOffset;
292686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
2937b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
2947b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis      DeclUpdateOffsetsMap;
295ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2967b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// \brief Declarations that have modifications residing in a later file
2977b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// in the chain.
2987b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  DeclUpdateOffsetsMap DeclUpdateOffsets;
2997b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis
300ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  struct ReplacedDeclInfo {
3011a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *Mod;
302ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    uint64_t Offset;
303ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    unsigned RawLoc;
304ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis
305ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {}
3061a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc)
307ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis      : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {}
308ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  };
309ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis
310ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo>
3110b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl      DeclReplacementMap;
3120b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  /// \brief Declarations that have been replaced in a later file in the chain.
3130b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  DeclReplacementMap ReplacedDecls;
3140b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl
3159d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  struct FileDeclsInfo {
3161a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *Mod;
3179d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis    ArrayRef<serialization::LocalDeclID> Decls;
3189d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis
3199d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis    FileDeclsInfo() : Mod(0) {}
3201a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
3219d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis      : Mod(Mod), Decls(Decls) {}
3229d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  };
3239d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis
32410f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis  /// \brief Map from a FileID to the file-level declarations that it contains.
3259d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
32610f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis
327e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // Updates for visible decls can occur for other contexts than just the
328e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // TU, and when we read those update records, the actual context will not
329e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // be available yet (unless it's the TU), so have this pending map using the
330e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // ID as a key. It will be realized when the context is actually loaded.
331b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer  typedef
332b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer    SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
333b1758c662524e18d65d260188fdcbbdee6a9316bBenjamin Kramer                          ModuleFile*>, 1> DeclContextVisibleUpdates;
334e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
335e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl      DeclContextVisibleUpdatesPending;
3362cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
337e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// \brief Updates to the visible declarations of declaration contexts that
338e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// haven't been loaded yet.
339e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  DeclContextVisibleUpdatesPending PendingVisibleUpdates;
3402e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
341fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  /// \brief The set of C++ or Objective-C classes that have forward
342fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  /// declarations that have not yet been linked to their definitions.
343fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
344fc529f7fcafe7da0b8a32621e13685891e8ce52aDouglas Gregor
345681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  /// \brief Read the records that describe the contents of declcontexts.
3461a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool ReadDeclContextStorage(ModuleFile &M,
3470d95f77ba180aee35b74f3bf9f8543477f3af543Douglas Gregor                              llvm::BitstreamCursor &Cursor,
348681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              const std::pair<uint64_t, uint64_t> &Offsets,
3490d95f77ba180aee35b74f3bf9f8543477f3af543Douglas Gregor                              serialization::DeclContextInfo &Info);
350681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl
3512b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// \brief A vector containing identifiers that have already been
3522b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// loaded.
3532b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  ///
3542b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// If the pointer at index I is non-NULL, then it refers to the
3552b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// IdentifierInfo for the identifier with ID=I+1 that has already
3562b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// been loaded.
3572b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  std::vector<IdentifierInfo *> IdentifiersLoaded;
358afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor
3591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
36067268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor    GlobalIdentifierMapType;
361ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
36267268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// \brief Mapping from global identifer IDs to the module in which the
36367268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// identifier resides along with the offset that should be added to the
36467268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// global identifier ID to produce a local ID.
36567268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  GlobalIdentifierMapType GlobalIdentifierMap;
36667268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor
36726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief A vector containing submodules that have already been loaded.
36826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  ///
36926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
37026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// indicate that the particular submodule ID has not yet been loaded.
37126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  SmallVector<Module *, 2> SubmodulesLoaded;
37226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
37326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
37426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor    GlobalSubmoduleMapType;
37526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
37626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Mapping from global submodule IDs to the module file in which the
37726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// submodule resides along with the offset that should be added to the
37826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// global submodule ID to produce a local ID.
37926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  GlobalSubmoduleMapType GlobalSubmoduleMap;
38026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
381ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief A set of hidden declarations.
3821329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  typedef llvm::SmallVector<llvm::PointerUnion<Decl *, IdentifierInfo *>, 2>
3831329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor    HiddenNames;
384ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
385ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
386ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
387ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief A mapping from each of the hidden submodules to the deserialized
388ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// declarations in that submodule that could be made visible.
389ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  HiddenNamesMapType HiddenNamesMap;
390ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
39155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
39255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \brief A module import or export that hasn't yet been resolved.
39355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  struct UnresolvedModuleImportExport {
394af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    /// \brief The file in which this module resides.
395af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    ModuleFile *File;
396af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
39755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief The module that is importing or exporting.
39855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    Module *Mod;
399af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
400af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    /// \brief The local ID of the module that is being exported.
40155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned ID;
40255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
40355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief Whether this is an import (vs. an export).
40455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned IsImport : 1;
40555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
40655988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief Whether this is a wildcard export.
40755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned IsWildcard : 1;
408af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor  };
409af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
41055988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \brief The set of module imports and exports that still need to be
41155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// resolved.
41255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  llvm::SmallVector<UnresolvedModuleImportExport, 2>
41355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    UnresolvedModuleImportExports;
414af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
4151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief A vector containing selectors that have already been loaded.
41683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  ///
41783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// This vector is indexed by the Selector ID (-1). NULL selector
41883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// entries indicate that the particular selector ID has not yet
41983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// been loaded.
420686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Selector, 16> SelectorsLoaded;
421725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
4221a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
42396958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor    GlobalSelectorMapType;
424ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
42596958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// \brief Mapping from global selector IDs to the module in which the
42696958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// selector resides along with the offset that should be added to the
42796958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// global selector ID to produce a local ID.
42896958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  GlobalSelectorMapType GlobalSelectorMap;
42996958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor
4308efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// \brief The generation number of the last time we loaded data from the
4318efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// global method pool for this selector.
4328efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
4338efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor
434295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Mapping from identifiers that represent macros whose definitions
435295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// have not yet been deserialized to the global offset where the macro
436295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// record resides.
437295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  llvm::DenseMap<IdentifierInfo *, uint64_t> UnreadMacroRecordOffsets;
4384c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4391a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
4404c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    GlobalPreprocessedEntityMapType;
441ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4424c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Mapping from global preprocessing entity IDs to the module in
4434c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// which the preprocessed entity resides along with the offset that should be
4444c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// added to the global preprocessing entitiy ID to produce a local ID.
4454c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
446ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
447892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name CodeGen-relevant special data
448892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is relevant to CodeGen.
449892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
450892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
451892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all declarations that fulfill the criteria of
452892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// "interesting" decls.
453892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
454892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the
455892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// chain. The referenced declarations are deserialized and passed to the
456892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// consumer eagerly.
457686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> ExternalDefinitions;
458fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
459bed28ac1d1463adca3ecf24fca5c30646fa9dbb2Sylvestre Ledru  /// \brief The IDs of all tentative definitions stored in the chain.
460892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
461892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema keeps track of all tentative definitions in a TU because it has to
462892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
463892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// the PCH chain must be eagerly deserialized.
464686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> TentativeDefinitions;
465892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
466892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
467892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// used.
468892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
469892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// CodeGen has to emit VTables for these records, so they have to be eagerly
470892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// deserialized.
471686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> VTableUses;
472892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
473f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// \brief A snapshot of the pending instantiations in the chain.
474f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  ///
475f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// This record tracks the instantiations that Sema has to perform at the
476f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// end of the TU. It consists of a pair of values for every pending
477f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// instantiation where the first value is the ID of the decl and the second
478f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// is the instantiation location.
479f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  SmallVector<uint64_t, 64> PendingInstantiations;
480f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor
481892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
482892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
483d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// \name DiagnosticsEngine-relevant special data
484892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for generating diagnostics
485892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
486892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
487892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
488892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
489686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
4904c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor
491ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// \brief A list of all the delegating constructors we've seen, to diagnose
492ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// cycles.
493686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> DelegatingCtorDecls;
494ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4958451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// \brief Method selectors used in a @selector expression. Used for
4968451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// implementation of -Wselector.
4978451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  SmallVector<uint64_t, 64> ReferencedSelectorsData;
498ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt
499892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
500892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
501686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
50214c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor
503892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
504892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
505892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
506686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> ExtVectorDecls;
507b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor
508892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
509d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
510892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name Sema-relevant special data
511892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for semantic analysis
512892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
513892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
514892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all locally scoped external decls in the chain.
515892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
516892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these to validate that the types are consistent across all
517892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// local external declarations.
518686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
519d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
520892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all dynamic class declarations in the chain.
521892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
522892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these because it checks for the key functions being defined
523892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// at the end of the TU, in which case it directs CodeGen to emit the VTable.
524686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> DynamicClasses;
525892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
526892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of the declarations Sema stores directly.
527892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
528892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks a few important decls, such as namespace std, directly.
529686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> SemaDeclRefs;
53076c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis
531e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// \brief The IDs of the types ASTContext stores directly.
532e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
533e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// The AST context tracks a few important types, such as va_list, directly.
534686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> SpecialTypes;
535e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl
53614b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
53714b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  ///
53814b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// The AST context tracks a few important decls, currently cudaConfigureCall,
53914b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// directly.
540686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
54114b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne
54284bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The floating point pragma option settings.
543686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> FPPragmaOptions;
54484bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
54584bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The OpenCL extension settings.
546686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> OpenCLExtensions;
54784bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
548d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief A list of the namespaces we've seen.
549686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> KnownNamespaces;
550d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
551f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  /// \brief A list of modules that were imported by precompiled headers or
552f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  /// any other non-module AST file.
553f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  SmallVector<serialization::SubmoduleID, 2> ImportedModules;
554892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
555892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
5563c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The original file name that was used to build the primary AST file,
5573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// which may have been modified for relocatable-pch support.
558b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  std::string OriginalFileName;
559b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
5603c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The actual original file name that was used to build the primary
5613c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST file.
5627b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  std::string ActualOriginalFileName;
5637b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar
56431d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  /// \brief The file ID for the original file that was used to build the
56531d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  /// primary AST file.
56631d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  FileID OriginalFileID;
567ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5688e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH was originally created in. Used to
5698e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// allow resolving headers even after headers+PCH was moved to a new path.
5708e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string OriginalDir;
5718e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
5728e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH we are reading is stored in.
5738e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string CurrentDir;
5748e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
575e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \brief Whether this precompiled header is a relocatable PCH file.
576e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  bool RelocatablePCH;
5771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief The system include root to be used when loading the
579e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header.
580832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor  std::string isysroot;
5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
582fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// \brief Whether to disable the normal validation performed on precompiled
583fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers when they are loaded.
584fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  bool DisableValidation;
585ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5868ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \brief Whether to disable the use of stat caches in AST files.
5878ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  bool DisableStatCache;
5888ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor
589bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// \brief Whether to accept an AST file with compiler errors.
590bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  bool AllowASTWithCompilerErrors;
591bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis
592057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  /// \brief The current "generation" of the module file import stack, which
593057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  /// indicates how many separate module file load operations have occurred.
594057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  unsigned CurrentGeneration;
595057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor
59612dcc64eebf7aaffb71392fba74fcb69f35d3b2eArgyrios Kyrtzidis  typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
5973c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
598e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
599e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// Statements usually don't have IDs, but switch cases need them, so that the
600e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// switch statement can refer to them.
60112dcc64eebf7aaffb71392fba74fcb69f35d3b2eArgyrios Kyrtzidis  SwitchCaseMapTy SwitchCaseStmts;
602025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
60312dcc64eebf7aaffb71392fba74fcb69f35d3b2eArgyrios Kyrtzidis  SwitchCaseMapTy *CurrSwitchCaseStmts;
604b88acb018a0d5e897ce291da2664edfd7bd58f5cArgyrios Kyrtzidis
6054fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// \brief The number of stat() calls that hit/missed the stat
6064fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// cache.
6074fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  unsigned NumStatHits, NumStatMisses;
6084fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor
6097f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief The number of source location entries de-serialized from
6107f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// the PCH file.
6117f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  unsigned NumSLocEntriesRead;
6127f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
6133c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of source location entries in the chain.
614518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl  unsigned TotalNumSLocEntries;
615518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
6163e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The number of statements (and expressions) de-serialized
6173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// from the chain.
6183e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned NumStatementsRead;
6193e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
6203e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The total number of statements (and expressions) stored
6213c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// in the chain.
6223e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned TotalNumStatements;
6233e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
6243c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of macros de-serialized from the chain.
62537e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  unsigned NumMacrosRead;
6262512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
6273c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The total number of macros stored in the chain.
628fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMacros;
629fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
630725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// \brief The number of selectors that have been read.
631725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  unsigned NumSelectorsRead;
63283941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
633fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of method pool entries that have been read.
634fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolEntriesRead;
63583941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
636fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of times we have looked up a selector in the method
637fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// pool and not found anything interesting.
638fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolMisses;
639fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
640fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The total number of method pool entries in the selector table.
641fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMethodPoolEntries;
64237e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
6432512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of lexical decl contexts read/total.
6442512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
6452512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
6462512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of visible decl contexts read/total.
6472512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
648ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6491da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  /// Total size of modules, in bits, currently loaded
6501da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  uint64_t TotalModulesSizeInBits;
6511da901467f72d1733704b068e22089813a1962fdJonathan D. Turner
65229ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// \brief Number of Decl/types that are currently deserializing.
65329ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  unsigned NumCurrentElementsDeserializing;
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
65544d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// \brief Set true while we are in the process of passing deserialized
65644d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// "interesting" decls to consumer inside FinishedDeserializing().
65744d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// This is used as a guard to avoid recursively repeating the process of
65844d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  /// passing decls to consumer.
65944d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis  bool PassingDeclsToConsumer;
66044d2dbdce49d1fca3826d543ba875bb82f759091Argyrios Kyrtzidis
6611da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  /// Number of CXX base specifiers currently loaded
6621da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  unsigned NumCXXBaseSpecifiersLoaded;
6631da901467f72d1733704b068e22089813a1962fdJonathan D. Turner
6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief An IdentifierInfo that has been loaded but whose top-level
665d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// declarations of the same name have not (yet) been loaded.
666d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  struct PendingIdentifierInfo {
667d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor    IdentifierInfo *II;
668686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint32_t, 4> DeclIDs;
669d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  };
6701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6713c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of identifiers that were read while the AST reader was
6721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// (recursively) loading declarations.
6731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
674d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// The declarations on the identifier chain for these identifiers will be
675d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// loaded once the recursive loading has completed.
676d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6788efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// \brief The generation number of each identifier, which keeps track of
6798efca6bb688d32fd7c0d91b504ef3307f97ee66aDouglas Gregor  /// the last time we loaded information about this identifier.
680057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
681057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor
682c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// \brief Contains declarations and definitions that will be
683c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "interesting" to the ASTConsumer, when we get that AST consumer.
684c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  ///
685c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "Interesting" declarations are those that have data that may
686c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// need to be emitted, such as inline function definitions or
687c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// Objective-C protocols.
688bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  std::deque<Decl *> InterestingDecls;
689c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor
6902171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  /// \brief The set of redeclarable declaraations that have been deserialized
6912171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  /// since the last time the declaration chains were linked.
6922171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor  llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
6932171bf1caba4d4b9eeb6a91efac4300b41f38b07Douglas Gregor
694a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief The list of redeclaration chains that still need to be
695a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// reconstructed.
696a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  ///
697a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// Each element is the global declaration ID of the first declaration in
698a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// the chain. Elements in this vector should be unique; use
699a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// PendingDeclChainsKnown to ensure uniqueness.
700a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  llvm::SmallVector<serialization::DeclID, 16> PendingDeclChains;
701a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
702a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief Keeps track of the elements added to PendingDeclChains.
703a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
704a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
705cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// \brief The set of Objective-C categories that have been deserialized
706cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// since the last time the declaration chains were linked.
707cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
708cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor
709cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// \brief The set of Objective-C class definitions that have already been
710cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// loaded, for which we will need to check for categories whenever a new
711cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// module is loaded.
712cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  llvm::SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
713cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor
7140f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  typedef llvm::DenseMap<Decl *, llvm::SmallVector<serialization::DeclID, 2> >
7150f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor    MergedDeclsMap;
7160f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor
7170f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  /// \brief A mapping from canonical declarations to the set of additional
7180f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  /// (global, previously-canonical) declaration IDs that have been merged with
7190f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  /// that canonical declaration.
7200f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor  MergedDeclsMap MergedDecls;
7210f75323264b93a318ac9007eb5ec5b233c444068Douglas Gregor
722c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  typedef llvm::DenseMap<serialization::GlobalDeclID,
723c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor                         llvm::SmallVector<serialization::DeclID, 2> >
724c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor    StoredMergedDeclsMap;
725c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor
726c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// \brief A mapping from canonical declaration IDs to the set of additional
727c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// declaration IDs that have been merged with that canonical declaration.
728c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  ///
729c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// This is the deserialized representation of the entries in MergedDecls.
730c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// When we query entries in MergedDecls, they will be augmented with entries
731c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// from StoredMergedDecls.
732c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  StoredMergedDeclsMap StoredMergedDecls;
733c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor
734c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// \brief Combine the stored merged declarations for the given canonical
735c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// declaration into the set of merged declarations.
736c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  ///
737c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// \returns An iterator into MergedDecls that corresponds to the position of
738c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  /// the given canonical declaration.
739c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  MergedDeclsMap::iterator
740c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor  combineStoredMergedDecls(Decl *Canon, serialization::GlobalDeclID CanonID);
741c3cfd2ab3338d47861ece597212f21b972ebe727Douglas Gregor
7420895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// \brief Ready to load the previous declaration of the given Decl.
7430895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID);
7440895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis
745919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
746686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Stmt *, 16> StmtStack;
747919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
748919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
749919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  enum ReadingKind {
750919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    Read_Decl, Read_Type, Read_Stmt
751919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
752919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
753ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief What kind of records we are reading.
754919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  ReadingKind ReadingKind;
755919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
756919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief RAII object to change the reading kind.
757919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  class ReadingKindTracker {
758c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ASTReader &Reader;
759919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    enum ReadingKind PrevKind;
760919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
761919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker(const ReadingKindTracker&); // do not implement
762919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement
763919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
764919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  public:
765c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
766919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      : Reader(reader), PrevKind(Reader.ReadingKind) {
767919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      Reader.ReadingKind = newKind;
768919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    }
769919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
770919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
771919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
772919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
7733c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief All predefines buffers in the chain, to be treated as if
7747e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// concatenated.
7757e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  PCHPredefinesBlocks PCHPredefinesBuffers;
77692b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor
777e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Suggested contents of the predefines buffer, after this
778e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// PCH file has been processed.
779e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  ///
780e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// In most cases, this string will be empty, because the predefines
781e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// buffer computed to build the PCH file will be identical to the
782e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer computed from the command line. However, when
783e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// there are differences that the PCH reader can work around, this
784e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer may contain additional definitions.
785e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  std::string SuggestedPredefines;
7861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
787919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement from the specified cursor.
7881a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Stmt *ReadStmtFromStream(ModuleFile &F);
789919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
790b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take
791b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// into account all the necessary relocations.
792686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  const FileEntry *getFileEntry(StringRef filename);
793b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
794e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  void MaybeAddSystemRootToFilename(std::string &Filename);
7951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
79610bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
7971a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor                            ModuleFile *ImportedBy);
7981a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult ReadASTBlock(ModuleFile &F);
7997e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  bool CheckPredefinesBuffers();
8001a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record);
8011a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult ReadSourceManagerBlock(ModuleFile &F);
802f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  ASTReadResult ReadSLocEntryRecord(int ID);
803f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  llvm::BitstreamCursor &SLocCursorForID(int ID);
8041a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation getImportLocation(ModuleFile *F);
8051a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult ReadSubmoduleBlock(ModuleFile &F);
806260611a32535c851237926bfcf78869b13c07d5bJohn McCall  bool ParseLanguageOptions(const RecordData &Record);
807392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor
808c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  struct RecordLocation {
8091a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    RecordLocation(ModuleFile *M, uint64_t O)
810c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl      : F(M), Offset(O) {}
8111a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *F;
812c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    uint64_t Offset;
813c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  };
814aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
815393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  QualType readTypeRecord(unsigned Index);
816aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  RecordLocation TypeCursorForIndex(unsigned Index);
8172cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  void LoadedDecl(unsigned Index, Decl *D);
818496c709a6f08f5c502b6f592ddd9ed40f953a5e5Douglas Gregor  Decl *ReadDeclRecord(serialization::DeclID ID);
8199d31fa75bc05fe4cb903a7701550f22cfb73ea8bArgyrios Kyrtzidis  RecordLocation DeclCursorForID(serialization::DeclID ID,
8209d31fa75bc05fe4cb903a7701550f22cfb73ea8bArgyrios Kyrtzidis                                 unsigned &RawLocation);
8216bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor  void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
822a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  void loadPendingDeclChain(serialization::GlobalDeclID ID);
823cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
824cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor                          unsigned PreviousGeneration = 0);
825ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
8268f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
8271a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
8282dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
829a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \brief Returns the first preprocessed entity ID that ends after BLoc.
8302dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
8312dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findBeginPreprocessedEntity(SourceLocation BLoc) const;
8322dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
833a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \brief Returns the first preprocessed entity ID that begins after ELoc.
8342dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
8352dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findEndPreprocessedEntity(SourceLocation ELoc) const;
8362dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
837a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \brief Find the next module that contains entities and return the ID
8382dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// of the first entry.
839a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// \arg SLocMapI points at a chunk of a module that contains no
840a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// preprocessed entities or the entities it contains are not the
841a7b7d1a7394394d33c18f7dda400a9a12cae2c78James Dennett  /// ones we are looking for.
8422dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
8432dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findNextPreprocessedEntity(
8442dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
8452dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
8461a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  /// \brief Returns (ModuleFile, Local index) pair for \arg GlobalIndex of a
847f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// preprocessed entity.
8481a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  std::pair<ModuleFile *, unsigned>
849f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis    getModulePreprocessedEntity(unsigned GlobalIndex);
850f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
851bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  void PassInterestingDeclsToConsumer();
8528d39c3ddfc17d9e768a17eb0ce9f11c33bf9d50aArgyrios Kyrtzidis  void PassInterestingDeclToConsumer(Decl *D);
853bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis
854917078386b9b5113f33c093e296e10927b00b37eArgyrios Kyrtzidis  void finishPendingActions();
855917078386b9b5113f33c093e296e10927b00b37eArgyrios Kyrtzidis
856a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// \brief Produce an error diagnostic and return true.
857a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  ///
858a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// This routine should only be used for fatal errors that have to
8593c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// do with non-routine failures (e.g., corrupted AST file).
860686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(StringRef Msg);
861686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
862686775deca8b8685eb90801495880e3abdd844c2Chris Lattner             StringRef Arg2 = StringRef());
863a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor
864c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader(const ASTReader&); // do not implement
865c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &operator=(const ASTReader &); // do not implement
8662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorpublic:
8673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file and validate its contents against the given
86811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// Preprocessor.
869e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
870e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param PP the preprocessor associated with the context in which this
871e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header will be loaded.
872e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
873e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Context the AST context that this precompiled header will be
874e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// loaded into.
875e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
876e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
877e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
878e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
879fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
8803c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
881fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
882fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
8838ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  ///
8848ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \param DisableStatCache If true, the AST reader will ignore the
8858ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// stat cache in the AST files. This performance pessimization can
8868ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// help when an AST file is being used in cases where the
8878ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// underlying files in the file system may have changed, but
8888ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// parsing should still continue.
889bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  ///
890bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
891bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// AST file the was created out of an AST with compiler errors,
892bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis  /// otherwise it will reject it.
893f8a1e51c48761ee1d7803c3fa35ac94f42ebb55eDouglas Gregor  ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
894bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis            bool DisableValidation = false, bool DisableStatCache = false,
895bef35c91b594f66216f4aab303b71a6c5ab7abcfArgyrios Kyrtzidis            bool AllowASTWithCompilerErrors = false);
8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
897c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ~ASTReader();
8982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
8992dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  SourceManager &getSourceManager() const { return SourceMgr; }
900ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
90110bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor  /// \brief Load the AST file designated by the given file name.
90272a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor  ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type);
9031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
904b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Checks that no file that is stored in PCH is out-of-sync with
905b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// the actual file in the file system.
9061a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult validateFileEntries(ModuleFile &M);
907b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
9085e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \brief Make the entities in the given module and any of its (non-explicit)
9095e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// submodules visible to name lookup.
9105e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  ///
9115e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \param Mod The module whose names should be made visible.
9125e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  ///
91316ae9de07730832945204877d752db7f1c070962James Dennett  /// \param NameVisibility The level of visibility to give the names in the
91416ae9de07730832945204877d752db7f1c070962James Dennett  /// module.  Visibility can only be increased over time.
9155e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  void makeModuleVisible(Module *Mod,
9165e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor                         Module::NameVisibilityKind NameVisibility);
9175e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor
918ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief Make the names within this set of hidden names visible.
919ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  void makeNamesVisible(const HiddenNames &Names);
920ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
9213c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST callbacks listener.
922571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setListener(ASTReaderListener *listener) {
92311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    Listener.reset(listener);
92411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
9251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
9263c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST deserialization listener.
927571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setDeserializationListener(ASTDeserializationListener *Listener);
92830c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
929359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  /// \brief Initializes the ASTContext
930359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  void InitializeContext();
9312cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
932c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner  /// \brief Add in-memory (virtual file) buffer.
933c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner  void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) {
934c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner    ModuleMgr.addInMemoryBuffer(FileName, Buffer);
935b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  }
936b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis
937ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief Finalizes the AST reader's state before writing an AST file to
938ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// disk.
939ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  ///
940ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// This operation may undo temporary state in the AST that should not be
941ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// emitted.
942ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  void finalizeForWriting();
943ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
944e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  /// \brief Retrieve the module manager.
945e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  ModuleManager &getModuleManager() { return ModuleMgr; }
946e19944c93961b7618f4f3f3185f698f46369ea54Steve Naroff
947d10a381d92a60d4f4c126c4e81045c8ad4636a0bDouglas Gregor  /// \brief Retrieve the preprocessor.
948712f2fcb70ae2eb0cb684d565e7d2cb76881006bDouglas Gregor  Preprocessor &getPreprocessor() const { return PP; }
949ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the name of the original source file name
951b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  const std::string &getOriginalSourceFile() { return OriginalFileName; }
952b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
9533c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the original source file name directly from
9543c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// the AST file, without actually loading the AST file.
9553c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  static std::string getOriginalSourceFile(const std::string &ASTFileName,
956389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis                                           FileManager &FileMgr,
957d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                                           DiagnosticsEngine &Diags);
958b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
959e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Returns the suggested contents of the predefines buffer,
960e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// which contains a (typically-empty) subset of the predefines
961e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// build prior to including the precompiled header.
962e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
963e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
964e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// \brief Read a preallocated preprocessed entity from the external source.
965e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  ///
966e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// \returns null if an error occurred that prevented the preprocessed
967e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// entity from being loaded.
968e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index);
969e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor
9702dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// \brief Returns a pair of [Begin, End) indices of preallocated
9712dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// preprocessed entities that \arg Range encompasses.
9722dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  virtual std::pair<unsigned, unsigned>
9732dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis      findPreprocessedEntitiesInRange(SourceRange Range);
974ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
975f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// \brief Optionally returns true or false if the preallocated preprocessed
976f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// entity with index \arg Index came from file \arg FID.
977f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
978f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis                                                            FileID FID);
9792dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
980cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Read the header file information for the given file entry.
981cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE);
982cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
983d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
984f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis
985f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of source locations found in the chain.
9860fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  unsigned getTotalNumSLocs() const {
9870fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl    return TotalNumSLocEntries;
9880fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  }
9890fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl
990f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of identifiers found in the chain.
991f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  unsigned getTotalNumIdentifiers() const {
992f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl    return static_cast<unsigned>(IdentifiersLoaded.size());
993f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  }
994f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl
995e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of types found in the chain.
99677a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumTypes() const {
99777a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(TypesLoaded.size());
99877a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
99977a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
1000e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of declarations found in the chain.
100177a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumDecls() const {
100277a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(DeclsLoaded.size());
100377a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
100477a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
100526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Returns the number of submodules known.
100626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  unsigned getTotalNumSubmodules() const {
100726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor    return static_cast<unsigned>(SubmodulesLoaded.size());
100826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  }
100926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
1010e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of selectors found in the chain.
1011e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  unsigned getTotalNumSelectors() const {
1012e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl    return static_cast<unsigned>(SelectorsLoaded.size());
1013e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  }
1014e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
10154c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Returns the number of preprocessed entities known to the AST
10164c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// reader.
10174c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  unsigned getTotalNumPreprocessedEntities() const {
10184c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    unsigned Result = 0;
10195d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner    for (ModuleConstIterator I = ModuleMgr.begin(),
10205d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner        E = ModuleMgr.end(); I != E; ++I) {
1021e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis      Result += (*I)->NumPreprocessedEntities;
10225d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner    }
1023ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10244c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    return Result;
10254c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  }
1026ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10277c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  /// \brief Returns the number of C++ base specifiers found in the chain.
10281da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  unsigned getTotalNumCXXBaseSpecifiers() const {
10291da901467f72d1733704b068e22089813a1962fdJonathan D. Turner    return NumCXXBaseSpecifiersLoaded;
10301da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  }
1031ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1032833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1033833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// given TemplateArgument kind.
1034833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo
10351a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1036833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                             const RecordData &Record, unsigned &Idx);
1037833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
103844f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis  /// \brief Reads a TemplateArgumentLoc.
1039577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TemplateArgumentLoc
10401a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ReadTemplateArgumentLoc(ModuleFile &F,
1041577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                          const RecordData &Record, unsigned &Idx);
104244f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis
1043a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  /// \brief Reads a declarator info from the given record.
10441a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1045577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                    const RecordData &Record, unsigned &Idx);
1046a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
10472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a type ID into a type, potentially building a new
10482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// type.
10498538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  QualType GetType(serialization::TypeID ID);
10502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1051393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// \brief Resolve a local type ID within a given AST file into a type.
10521a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1053ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1054393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// \brief Map a local type ID within a given AST file into a global type ID.
10551a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1056ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1057ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Read a type from the current position in the given record, which
1058393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// was read from the given AST file.
10591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1060393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor    if (Idx >= Record.size())
1061393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor      return QualType();
1062ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1063393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor    return getLocalType(F, Record[Idx++]);
1064393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  }
1065ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1066ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Map from a local declaration ID within a given module to a
1067409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// global declaration ID.
10681a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::DeclID getGlobalDeclID(ModuleFile &F, unsigned LocalID) const;
1069e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis
1070e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  /// \brief Returns true if global DeclID \arg ID originated from module
1071e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  /// \arg M.
10721a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1073dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis
1074cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// \brief Retrieve the module file that owns the given declaration, or NULL
1075cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  /// if the declaration is not from a module file.
1076cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor  ModuleFile *getOwningModuleFile(Decl *D);
1077cff9f26ce0ed76d555cd33b3dca84dd5cdf376afDouglas Gregor
1078dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// \brief Returns the source location for the decl \arg ID.
1079dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1080ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10812cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a declaration ID into a declaration, potentially
10822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// building a new declaration.
10838538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *GetDecl(serialization::DeclID ID);
108476bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Decl *GetExternalDecl(uint32_t ID);
10852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
108643fd9388d374f29e908e611a686c6137553efa79Jonathan D. Turner  /// \brief Reads a declaration with the given local ID in the given module.
10871a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1088409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return GetDecl(getGlobalDeclID(F, LocalID));
1089409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1090409448c832d27703146b70a1137d86b020f29863Douglas Gregor
109143fd9388d374f29e908e611a686c6137553efa79Jonathan D. Turner  /// \brief Reads a declaration with the given local ID in the given module.
1092409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1093409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The requested declaration, casted to the given return type.
1094409448c832d27703146b70a1137d86b020f29863Douglas Gregor  template<typename T>
10951a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1096409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1097409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1098409448c832d27703146b70a1137d86b020f29863Douglas Gregor
1099a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief Map a global declaration ID into the declaration ID used to
1100a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// refer to this declaration within the given module fule.
1101a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  ///
1102a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \returns the global ID of the given declaration as known in the given
1103a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// module file.
1104a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  serialization::DeclID
1105a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1106a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor                                  serialization::DeclID GlobalID);
1107a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
1108ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Reads a declaration ID from the given position in a record in the
1109409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
1110409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1111409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The declaration ID read from the record, adjusted to a global ID.
11121a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1113409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                   unsigned &Idx);
1114ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1115409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \brief Reads a declaration from the given position in a record in the
1116409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
11171a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1118409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return GetDecl(ReadDeclID(F, R, I));
1119409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1120ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1121409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \brief Reads a declaration from the given position in a record in the
1122409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
1123409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1124409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The declaration read from this location, casted to the given
1125409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// result type.
1126409448c832d27703146b70a1137d86b020f29863Douglas Gregor  template<typename T>
11271a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1128409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1129409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1130409448c832d27703146b70a1137d86b020f29863Douglas Gregor
1131e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor  /// \brief Read a CXXBaseSpecifiers ID form the given record and
1132e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor  /// return its global bit offset.
11331a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record,
1134e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor                                 unsigned &Idx);
1135ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
11367c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
1137ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1138250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// \brief Resolve the offset of a statement into a statement.
1139250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  ///
1140250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// This operation will read a new statement from the external
1141250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// source each time it is called, and is meant to be used via a
1142887e2b375fc5e00084ec7bf3dd050c2ca399a6d2Chris Lattner  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
114376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
1144250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor
11456367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
11466367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// specified cursor.  Read the abbreviations that are at the top of the block
11476367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// and then leave the cursor pointing into the block.
11486367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
11496367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner
115076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// \brief Finds all the visible declarations with a given name.
115176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// The current implementation of this method just loads the entire
115276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// lookup table as unmaterialized references.
115376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual DeclContext::lookup_result
115476bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  FindExternalVisibleDeclsByName(const DeclContext *DC,
115576bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall                                 DeclarationName Name);
115676bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall
11572cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Read all of the declarations lexically stored in a
11582cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
11592cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param DC The declaration context whose declarations will be
11612cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// read.
11622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11632cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param Decls Vector that will contain the declarations loaded
11642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// from the external source. The caller is responsible for merging
11652cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// these declarations with any declarations already stored in the
11662cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
11672cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11682cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \returns true if there was an error while reading the
11692cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declarations for this declaration context.
1170ba6ffaf21e465c0926d7fc5fa294ea52f8d45fafDouglas Gregor  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1171eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis                                        bool (*isKindWeWant)(Decl::Kind),
1172686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                        SmallVectorImpl<Decl*> &Decls);
11732cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1174dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// \brief Get the decls that are contained in a file in the Offset/Length
1175dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// range. \arg Length can be 0 to indicate a point at \arg Offset instead of
1176ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// a range.
1177dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
1178dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis                                   SmallVectorImpl<Decl *> &Decls);
1179dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis
1180c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we started deserialization of
118129ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type so until FinishedDeserializing is called there may be
118229ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// decls that are initializing. Must be paired with FinishedDeserializing.
118329ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; }
118429ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1185c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we finished the deserialization of
118629ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type. Must be paired with StartedDeserializing.
118729ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void FinishedDeserializing();
118829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1189fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// \brief Function that will be invoked when we begin parsing a new
1190fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// translation unit involving this external AST source.
1191fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  ///
1192fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// This function will provide all of the external definitions to
1193fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// the ASTConsumer.
1194fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  virtual void StartTranslationUnit(ASTConsumer *Consumer);
1195fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
11963c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Print some statistics about AST usage.
11972cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  virtual void PrintStats();
11982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
119923d7df5ce30f4a068e13ad6cb81d473365d260dbDouglas Gregor  /// \brief Dump information about the AST reader to standard error.
120023d7df5ce30f4a068e13ad6cb81d473365d260dbDouglas Gregor  void dump();
1201ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1202e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// Return the amount of memory used by memory buffers, breaking down
1203e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// by heap-backed versus mmap'ed memory.
1204e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
1205e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek
1206668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Initialize the semantic source with the Sema instance
1207668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// being used to perform semantic analysis on the abstract syntax
1208668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// tree.
1209668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  virtual void InitializeSema(Sema &S);
1210668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1211ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  /// \brief Inform the semantic consumer that Sema is no longer available.
1212ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  virtual void ForgetSema() { SemaObj = 0; }
1213ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar
1214668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the IdentifierInfo for the named identifier.
1215668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  ///
12164d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// This routine builds a new IdentifierInfo for the given identifier. If any
12174d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations with this name are visible from translation unit scope, their
12184d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations will be deserialized and introduced into the declaration
121988a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// chain of the identifier.
1220d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1221686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  IdentifierInfo *get(StringRef Name) {
12224d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar    return get(Name.begin(), Name.end());
12234d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  }
1224668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
122595f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// \brief Retrieve an iterator into the set of all identifiers
122695f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// in all loaded AST files.
122795f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  virtual IdentifierIterator *getIdentifiers() const;
122895f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor
1229f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \brief Load the contents of the global method pool for a given
1230f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// selector.
12315ac4b6917aa34fae6da64036539023a6155a3d48Douglas Gregor  virtual void ReadMethodPool(Selector Sel);
1232f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor
1233d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief Load the set of namespaces that are known to the external source,
1234d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// which will be used during typo correction.
1235d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  virtual void ReadKnownNamespaces(
1236686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
1237d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
1238a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor  virtual void ReadTentativeDefinitions(
1239a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor                 SmallVectorImpl<VarDecl *> &TentativeDefs);
1240a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor
1241a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor  virtual void ReadUnusedFileScopedDecls(
1242a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor                 SmallVectorImpl<const DeclaratorDecl *> &Decls);
1243a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor
12440129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor  virtual void ReadDelegatingConstructors(
12450129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor                 SmallVectorImpl<CXXConstructorDecl *> &Decls);
12460129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor
1247d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor  virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls);
1248d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor
1249a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor  virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls);
1250a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor
1251ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor  virtual void ReadLocallyScopedExternalDecls(
1252ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor                 SmallVectorImpl<NamedDecl *> &Decls);
1253ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12545b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor  virtual void ReadReferencedSelectors(
12555b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor                 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels);
12565b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor
125731e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor  virtual void ReadWeakUndeclaredIdentifiers(
125831e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor                 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI);
125931e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor
1260dfe6543e12eca5c79421378b7fa6b3e8fc403e63Douglas Gregor  virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
1261dfe6543e12eca5c79421378b7fa6b3e8fc403e63Douglas Gregor
12626e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor  virtual void ReadPendingInstantiations(
1263ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                 SmallVectorImpl<std::pair<ValueDecl *,
12646e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor                                           SourceLocation> > &Pending);
12656e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor
1266e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Load a selector from disk, registering its ID if it exists.
1267e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  void LoadSelector(Selector Sel);
1268e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
12692b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SetGloballyVisibleDecls(IdentifierInfo *II,
1271686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               const SmallVectorImpl<uint32_t> &DeclIDs,
1272d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor                               bool Nonrecursive = false);
12731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12740a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  /// \brief Report a diagnostic.
12750a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  DiagnosticBuilder Diag(unsigned DiagID);
12760a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
1277e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  /// \brief Report a diagnostic.
1278e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1279e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor
128095eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12821a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
128395eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor                                    unsigned &Idx) {
128495eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
12857356a31327be9b3c3434a0c88746028980da5684Chris Lattner  }
12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
128795eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor  virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) {
12888c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    return DecodeIdentifierInfo(ID);
12898c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  }
12908c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
12911a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1292ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12931a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
129495eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor                                                    unsigned LocalID);
1295ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12967f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief Read the source location entry with index ID.
1297f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  virtual bool ReadSLocEntry(int ID);
12987f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
129926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Retrieve the global submodule ID given a module and its local ID
130026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// number.
130126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  serialization::SubmoduleID
130226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
130326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
130426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
130526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  ///
130626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  Module *getSubmodule(serialization::SubmoduleID GlobalID);
130726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
13082d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  /// \brief Retrieve a selector from the given module with its local ID
13092d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  /// number.
13101a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
13112d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor
13122d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  Selector DecodeSelector(serialization::SelectorID Idx);
13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13148451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  virtual Selector GetExternalSelector(serialization::SelectorID ID);
131576bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  uint32_t GetNumExternalSelectors();
1316719770dcfcb3987e8a2377dcca97955301445eb5Douglas Gregor
13171a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
13182d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor    return getLocalSelector(M, Record[Idx++]);
131990cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  }
1320ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
13218451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// \brief Retrieve the global selector ID that corresponds to this
13228451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// the local selector ID in a given module.
13231a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
13248451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor                                                unsigned LocalID) const;
13256ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13266ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a declaration name.
13271a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  DeclarationName ReadDeclarationName(ModuleFile &F,
1328393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor                                      const RecordData &Record, unsigned &Idx);
13291a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadDeclarationNameLoc(ModuleFile &F,
13304045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              DeclarationNameLoc &DNLoc, DeclarationName Name,
13314045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              const RecordData &Record, unsigned &Idx);
13321a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
13334045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                               const RecordData &Record, unsigned &Idx);
13344045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
13351a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
13364045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
13370a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
13381a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1339409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                               const RecordData &Record,
13406ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner                                               unsigned &Idx);
13416ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13421a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1343dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    const RecordData &Record,
1344dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    unsigned &Idx);
1345dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor
13468731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template name.
13471a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
13481aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                unsigned &Idx);
13498731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
13508731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template argument.
13511a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateArgument ReadTemplateArgument(ModuleFile &F,
1352577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                        const RecordData &Record,unsigned &Idx);
1353ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1354dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template parameter list.
13551a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1356c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                                   const RecordData &Record,
1357dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis                                                   unsigned &Idx);
1358ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1359dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template argument array.
1360dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  void
1361686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs,
13621a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor                           ModuleFile &F, const RecordData &Record,
1363c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                           unsigned &Idx);
13648731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
136537ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  /// \brief Read a UnresolvedSet structure.
13661a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set,
136737ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
136837ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis
13690745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis  /// \brief Read a C++ base specifier.
13701a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
13715606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky                                        const RecordData &Record,unsigned &Idx);
13720745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis
1373cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  /// \brief Read a CXXCtorInitializer array.
1374cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  std::pair<CXXCtorInitializer **, unsigned>
13751a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
1376cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                          unsigned &Idx);
13778e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis
1378c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  /// \brief Read a source location from raw form.
13791a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
13805a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis    SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
13811a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() &&
1382f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor           "Cannot find offset to remap.");
13831a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
1384a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis    return Loc.getLocWithOffset(Remap);
1385c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  }
1386c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl
13876ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source location.
13881a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
1389c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                    const RecordData &Record, unsigned& Idx) {
13901a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    return ReadSourceLocation(ModuleFile, Record[Idx++]);
13916ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  }
13926ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13936ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source range.
13941a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceRange ReadSourceRange(ModuleFile &F,
1395c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                              const RecordData &Record, unsigned& Idx);
13966ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13970a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read an integral value
13980a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
13990a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
14000a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read a signed integral value
14010a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
14023a2f7e42514ddbec983c61826ce85d3071e23e8eDouglas Gregor
140317fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Read a floating-point value
140417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx);
140517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
140668a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  // \brief Read a string
140768a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  std::string ReadString(const RecordData &Record, unsigned &Idx);
140868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
14090a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Read a version tuple.
14100a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
14110a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
14121a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
1413409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                 unsigned &Idx);
1414ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
141568a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  /// \brief Reads attributes from the current stream position.
14161a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
14174eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis                      const RecordData &Record, unsigned &Idx);
141868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
1419919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement.
14201a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Stmt *ReadStmt(ModuleFile &F);
14210b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1422919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads an expression.
14231a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Expr *ReadExpr(ModuleFile &F);
1424c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor
1425d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-statement operand during statement reading.
1426d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Stmt *ReadSubStmt() {
1427d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(ReadingKind == Read_Stmt &&
1428d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis           "Should be called only during statement reading!");
1429d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // Subexpressions are stored from last to first, so the next Stmt we need
1430d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // is at the back of the stack.
1431d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(!StmtStack.empty() && "Read too many sub statements!");
1432d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    return StmtStack.pop_back_val();
1433d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  }
1434d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
1435d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-expression operand during statement reading.
1436d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Expr *ReadSubExpr();
1437d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
143837e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  /// \brief Reads the macro record located at the given offset.
14391a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadMacroRecord(ModuleFile &F, uint64_t Offset);
1440ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
144186c67d8802a9e0887c31c850188991465ac3c1bdDouglas Gregor  /// \brief Determine the global preprocessed entity ID that corresponds to
144286c67d8802a9e0887c31c850188991465ac3c1bdDouglas Gregor  /// the given local ID within the given module.
1443ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  serialization::PreprocessedEntityID
14441a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
1445ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1446295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Note that the identifier is a macro whose record will be loaded
1447295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// from the given AST file at the given (file-local) offset.
14481329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14491329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param II The name of the macro.
14501329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14511329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param F The module file from which the macro definition was deserialized.
14521329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14531329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param Offset The offset into the module file at which the macro
14541329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// definition is located.
14551329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14561329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param Visible Whether the macro should be made visible.
14571329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  void setIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F,
14581329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor                            uint64_t Offset, bool Visible);
1459ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
146088a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// \brief Read the set of macros defined by this external macro source.
146188a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  virtual void ReadDefinedMacros();
146288a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor
1463295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Read the macro definition for this identifier.
1464295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  virtual void LoadMacroDefinition(IdentifierInfo *II);
1465295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor
1466eee242ff426bf79149f221798966e58688383c1eDouglas Gregor  /// \brief Update an out-of-date identifier.
1467eee242ff426bf79149f221798966e58688383c1eDouglas Gregor  virtual void updateOutOfDateIdentifier(IdentifierInfo &II);
1468eee242ff426bf79149f221798966e58688383c1eDouglas Gregor
1469057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  /// \brief Note that this identifier is up-to-date.
1470057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor  void markIdentifierUpToDate(IdentifierInfo *II);
1471057df20b3107cef764052d271c89b8591b98b3ceDouglas Gregor
1472295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Read the macro definition corresponding to this iterator
1473295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// into the unread macro record offsets table.
1474295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  void LoadMacroDefinition(
1475295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor                     llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos);
1476ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1477643586fe4fcd42b0978efd3566832ab4dce50367Argyrios Kyrtzidis  /// \brief Load all external visible decls in the given DeclContext.
1478b346d2f419ec7d7ce6b20780d518490338efa7deNick Lewycky  void completeVisibleDeclsMap(const DeclContext *DC);
1479643586fe4fcd42b0978efd3566832ab4dce50367Argyrios Kyrtzidis
14803c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the AST context that this AST reader supplements.
1481359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  ASTContext &getContext() { return Context; }
1482025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
14836cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // \brief Contains declarations that were loaded before we have
14846cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // access to a Sema object.
1485686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<NamedDecl *, 16> PreloadedDecls;
1486668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1487668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the semantic analysis object used to analyze the
1488668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// translation unit in which the precompiled header is being
1489668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// imported.
1490668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *getSema() { return SemaObj; }
1491668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1492668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the identifier table associated with the
1493668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// preprocessor.
1494668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  IdentifierTable &getIdentifierTable();
1495668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1496025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Record that the given ID maps to the given switch-case
1497025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// statement.
1498025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
1499025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1500025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Retrieve the switch-case statement with the given ID.
1501025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SwitchCase *getSwitchCaseWithID(unsigned ID);
15021de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1503e09a275444576deb2c8d9e2255554242f65d7c00Argyrios Kyrtzidis  void ClearSwitchCaseIDs();
1504aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko
1505aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  /// \brief Cursors for comments blocks.
1506aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  SmallVector<std::pair<llvm::BitstreamCursor,
1507aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko                        serialization::ModuleFile *>, 8> CommentsCursors;
1508aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko
1509aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  /// \brief Loads comments ranges.
1510aa0cd85838f2a024e589ea4e8c2094130065af21Dmitri Gribenko  void ReadComments();
15112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor};
15122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
151302602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// \brief Helper class that saves the current stream position and
151402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// then restores it when destroyed.
151502602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerstruct SavedStreamPosition {
151602602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
151702602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
151902602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  ~SavedStreamPosition() {
152002602be3ccc3b29da5b91d2502c3419404992409Chris Lattner    Cursor.JumpToBit(Offset);
152102602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  }
15221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
152302602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerprivate:
152402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  llvm::BitstreamCursor &Cursor;
152502602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  uint64_t Offset;
152602602be3ccc3b29da5b91d2502c3419404992409Chris Lattner};
15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1528d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekinline void PCHValidator::Error(const char *Msg) {
1529d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  Reader.Error(Msg);
1530d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek}
1531d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
15322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} // end namespace clang
15332cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
15342cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1535