ASTReader.h revision fc529f7fcafe7da0b8a32621e13685891e8ce52a
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"
372cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/ADT/SmallVector.h"
38dc3c0d20375bda7775b2fade05b20e315798b9feDaniel Dunbar#include "llvm/ADT/StringRef.h"
39e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis#include "llvm/ADT/DenseSet.h"
402cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include "llvm/Bitcode/BitstreamReader.h"
4103013fa9a0bf1ef4b907f5fec006c8f4000fdd21Michael J. Spencer#include "llvm/Support/DataTypes.h"
42d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor#include <deque>
43025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor#include <map>
442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <string>
452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <utility>
462cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#include <vector>
472cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
482cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace llvm {
492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  class MemoryBuffer;
502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor}
512cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
522cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregornamespace clang {
532cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
547d5c2f241c74e5f8d9ec492e8f9f268e5e9ae41fDouglas Gregorclass AddrLabelExpr;
550af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregorclass ASTConsumer;
562cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass ASTContext;
5795f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregorclass ASTIdentifierIterator;
58f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTUnit; // FIXME: Layering violation and egregious hack.
5968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregorclass Attr;
602cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass Decl;
612cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorclass DeclContext;
626ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass NestedNameSpecifier;
636ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattnerclass CXXBaseSpecifier;
64ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Huntclass CXXConstructorDecl;
65cbb67480094b3bcb5b715acd827cbad55e2a204cSean Huntclass CXXCtorInitializer;
661de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregorclass GotoStmt;
676a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregorclass MacroDefinition;
68668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass NamedDecl;
6956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallclass OpaqueValueExpr;
7014f79002e58556798e86168c63e48d533287eda5Douglas Gregorclass Preprocessor;
71668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregorclass Sema;
72025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregorclass SwitchCase;
73c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTDeserializationListener;
74f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregorclass ASTWriter;
75c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader;
76d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redlclass ASTDeclReader;
77c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass ASTStmtReader;
78c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redlclass TypeLocReader;
79eb19485625c7529ffa644e10829533157a8e8d4fDaniel Dunbarstruct HeaderFileInfo;
800a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregorclass VersionTuple;
8111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
827e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redlstruct PCHPredefinesBlock {
837e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief The file ID for this predefines buffer in a PCH file.
847e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  FileID BufferID;
857e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
867e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// \brief This predefines buffer in a PCH file.
87686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  StringRef Data;
887e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl};
89686775deca8b8685eb90801495880e3abdd844c2Chris Lattnertypedef SmallVector<PCHPredefinesBlock, 2> PCHPredefinesBlocks;
907e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl
91c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Abstract interface for callback invocations by the ASTReader.
9211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis///
93c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// While reading an AST file, the ASTReader will call the methods of the
9411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// listener to pass on specific information. Some of the listener methods can
95c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// return true to indicate to the ASTReader that the information (and
96571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// consequently the AST file) is invalid.
97571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass ASTReaderListener {
9811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
99571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  virtual ~ASTReaderListener();
1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the language options.
10211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
10311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the options are invalid or false otherwise.
10411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
10511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
10611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the target triple.
10911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the target triple is invalid or false otherwise.
111686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual bool ReadTargetTriple(StringRef Triple) {
11211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
11311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
11511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives the contents of the predefines buffer.
11611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
11730c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \param Buffers Information about the predefines buffers.
11811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
1193c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param OriginalFileName The original file name for the AST file, which
1203c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// will appear as an entry in the predefines buffer.
1217b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  ///
12211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \param SuggestedPredefines If necessary, additional definitions are added
12311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// here.
12411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  ///
12511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \returns true to indicate the predefines are invalid or false otherwise.
1267e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
127686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
128277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
129277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    FileManager &FileMgr) {
13011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    return false;
13111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
1321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives a HeaderFileInfo entry.
13412fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID) {}
1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
13611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// \brief Receives __COUNTER__ value.
13711e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value) {}
13811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
13911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis
140571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl/// \brief ASTReaderListener implementation to validate the information of
14111e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis/// the PCH file against an initialized Preprocessor.
142571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redlclass PCHValidator : public ASTReaderListener {
14311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  Preprocessor &PP;
144c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &Reader;
1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14611e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  unsigned NumHeaderInfos;
1471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
14811e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidispublic:
149c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  PCHValidator(Preprocessor &PP, ASTReader &Reader)
15011e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    : PP(PP), Reader(Reader), NumHeaderInfos(0) {}
1511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
15211e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual bool ReadLanguageOptions(const LangOptions &LangOpts);
153686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  virtual bool ReadTargetTriple(StringRef Triple);
1547e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  virtual bool ReadPredefinesBuffer(const PCHPredefinesBlocks &Buffers,
155686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                    StringRef OriginalFileName,
156277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    std::string &SuggestedPredefines,
157277a6e752512cff286190d35cb353ce717e86b18Nick Lewycky                                    FileManager &FileMgr);
15812fab31aa5868b1a6b52246b5a87daa48a338fe2Douglas Gregor  virtual void ReadHeaderFileInfo(const HeaderFileInfo &HFI, unsigned ID);
15911e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  virtual void ReadCounter(unsigned Value);
160d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
161d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekprivate:
162d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  void Error(const char *Msg);
16311e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis};
1642cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
165ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikienamespace serialization {
1665d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner
1673d15ab8d0822637ff5e39594c4f34172241cad2eDouglas Gregorclass ReadMethodPoolVisitor;
168ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
16998339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregornamespace reader {
17098339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor  class ASTIdentifierLookupTrait;
17198339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor}
172ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
17372a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor} // end namespace serialization
174ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
175c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// \brief Reads an AST files chain containing the contents of a translation
176c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// unit.
1772cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
178c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The ASTReader class reads bitstreams (produced by the ASTWriter
1792cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// class) containing the serialized representation of a given
1802cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// abstract syntax tree and its supporting data structures. An
181c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// instance of the ASTReader can be attached to an ASTContext object,
182c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// which will provide access to the contents of the AST files.
1832cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor///
184c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl/// The AST reader provides lazy de-serialization of declarations, as
1852cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// required when traversing the AST. Only those AST nodes that are
1862cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor/// actually required will be de-serialized.
187c43b54cbc10654ed59de797898042e1a05265246Sebastian Redlclass ASTReader
18888a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  : public ExternalPreprocessorSource,
1896a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bcDouglas Gregor    public ExternalPreprocessingRecordSource,
190cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor    public ExternalHeaderFileInfoSource,
19188a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor    public ExternalSemaSource,
1928c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    public IdentifierInfoLookup,
1937f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor    public ExternalIdentifierLookup,
194ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie    public ExternalSLocEntrySource
195cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor{
196e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorpublic:
197c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  enum ASTReadResult { Success, Failure, IgnorePCH };
1981d9f1fe7173e3084325f43c78af812a36d8a2a7cSebastian Redl  /// \brief Types of AST files.
199d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  friend class PCHValidator;
200d527cc06d78fe5afa5f20105b51697637eb02c56Sebastian Redl  friend class ASTDeclReader;
201c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class ASTStmtReader;
20295f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  friend class ASTIdentifierIterator;
20398339b96a8089a6da715487e432c5abfca0ca0dfDouglas Gregor  friend class serialization::reader::ASTIdentifierLookupTrait;
204c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  friend class TypeLocReader;
205f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTWriter;
206f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  friend class ASTUnit; // ASTUnit needs to remap source locations.
2073d15ab8d0822637ff5e39594c4f34172241cad2eDouglas Gregor  friend class serialization::ReadMethodPoolVisitor;
208ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2091a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef serialization::ModuleFile ModuleFile;
21072a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor  typedef serialization::ModuleKind ModuleKind;
2115d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef serialization::ModuleManager ModuleManager;
212ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2135d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleIterator ModuleIterator;
2145d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
2155d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
2165d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner
217e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregorprivate:
218c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief The receiver of some callbacks invoked by ASTReader.
219571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  llvm::OwningPtr<ASTReaderListener> Listener;
2201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
22130c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl  /// \brief The receiver of deserialization events.
222571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  ASTDeserializationListener *DeserializationListener;
22330c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
22411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  SourceManager &SourceMgr;
22511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  FileManager &FileMgr;
226d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  DiagnosticsEngine &Diags;
227ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
228668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief The semantic analysis object that will be processing the
2293c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST files and the translation unit that uses it.
230668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *SemaObj;
231668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
23214f79002e58556798e86168c63e48d533287eda5Douglas Gregor  /// \brief The preprocessor that will be loading the source file.
233712f2fcb70ae2eb0cb684d565e7d2cb76881006bDouglas Gregor  Preprocessor &PP;
23414f79002e58556798e86168c63e48d533287eda5Douglas Gregor
2353c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The AST context into which we'll read the AST files.
236359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  ASTContext &Context;
237ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2380af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  /// \brief The AST consumer.
2390af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor  ASTConsumer *Consumer;
2400af2ca4b6ddc788658069a0994941268ce250fc7Douglas Gregor
2415d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  /// \brief The module manager which manages modules and their dependencies
2425d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner  ModuleManager ModuleMgr;
2439137a5230d3164b96beb14ffb87863234b7d240fSebastian Redl
2448f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  /// \brief A map of global bit offsets to the module that stores entities
2458f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  /// at those bit offsets.
2461a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
2478f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor
248f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  /// \brief A map of negated SLocEntryIDs to the modules containing them.
2491a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
2504ee5a6f9bd82ab3c1a4bdacc0caefe7d5f8bd37aSebastian Redl
2511a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
252ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
253a68c4aff8cd3aada697ad36dc6582d0e09b4b0d2Argyrios Kyrtzidis  /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
254a68c4aff8cd3aada697ad36dc6582d0e09b4b0d2Argyrios Kyrtzidis  /// SourceLocation offsets to the modules containing them.
2552dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
256ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2573c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Types that have already been loaded from the chain.
2581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
2591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// When the pointer at index I is non-NULL, the type with
2603c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// ID = (I + 1) << FastQual::Width has already been loaded
2610953e767ff7817f97b3ab20896b229891eeff45bJohn McCall  std::vector<QualType> TypesLoaded;
2622cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2631a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
264e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner    GlobalTypeMapType;
265e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
266e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// \brief Mapping from global type IDs to the module in which the
267e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// type resides along with the offset that should be added to the
268e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  /// global type ID to produce a local ID.
269e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner  GlobalTypeMapType GlobalTypeMap;
270e9b76c11a88d0af98f32d11a6668d03d45be3123Jonathan D. Turner
2713c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Declarations that have already been loaded from the chain.
2722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
2738f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// When the pointer at index I is non-NULL, the declaration with ID
2748f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  /// = I + 1 has already been loaded.
2758f5dc7fe4d42cea78fa92d1638f753cf65b54cb5Douglas Gregor  std::vector<Decl *> DeclsLoaded;
2762cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
2771a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
27896e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor    GlobalDeclMapType;
279ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
28096e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  /// \brief Mapping from global declaration IDs to the module in which the
2819827a8049a793f23c62ade8f24f0c66c2dbf6741Douglas Gregor  /// declaration resides.
28296e973f2be14c9b82136f74b4108465d24894feaDouglas Gregor  GlobalDeclMapType GlobalDeclMap;
283ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2841a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef std::pair<ModuleFile *, uint64_t> FileOffset;
285686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<FileOffset, 2> FileOffsetsTy;
2867b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
2877b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis      DeclUpdateOffsetsMap;
288ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
2897b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// \brief Declarations that have modifications residing in a later file
2907b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  /// in the chain.
2917b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis  DeclUpdateOffsetsMap DeclUpdateOffsets;
2927b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis
293ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  struct ReplacedDeclInfo {
2941a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *Mod;
295ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    uint64_t Offset;
296ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    unsigned RawLoc;
297ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis
298ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis    ReplacedDeclInfo() : Mod(0), Offset(0), RawLoc(0) {}
2991a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc)
300ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis      : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {}
301ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  };
302ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis
303ef23b6001e8d9715246ca23bd8c3a6887d7844cbArgyrios Kyrtzidis  typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo>
3040b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl      DeclReplacementMap;
3050b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  /// \brief Declarations that have been replaced in a later file in the chain.
3060b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl  DeclReplacementMap ReplacedDecls;
3070b17c61e8f143901ce11b4a6e5129ac63aaeee04Sebastian Redl
3089d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  struct FileDeclsInfo {
3091a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *Mod;
3109d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis    ArrayRef<serialization::LocalDeclID> Decls;
3119d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis
3129d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis    FileDeclsInfo() : Mod(0) {}
3131a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
3149d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis      : Mod(Mod), Decls(Decls) {}
3159d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  };
3169d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis
31710f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis  /// \brief Map from a FileID to the file-level declarations that it contains.
3189d128d04578c62675eeb0cce83066052f9c19c9aArgyrios Kyrtzidis  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
31910f3df54486385e6497c9e5f229ff816e5a6c511Argyrios Kyrtzidis
320e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // Updates for visible decls can occur for other contexts than just the
321e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // TU, and when we read those update records, the actual context will not
322e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // be available yet (unless it's the TU), so have this pending map using the
323e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  // ID as a key. It will be realized when the context is actually loaded.
3241a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef SmallVector<std::pair<void *, ModuleFile*>, 1> DeclContextVisibleUpdates;
325e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
326e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl      DeclContextVisibleUpdatesPending;
3272cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
328e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// \brief Updates to the visible declarations of declaration contexts that
329e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  /// haven't been loaded yet.
330e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl  DeclContextVisibleUpdatesPending PendingVisibleUpdates;
331e1dde811b38e779894150cb1093d57f8411a84f7Sebastian Redl
3322e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  typedef SmallVector<Decl *, 4> ForwardRefs;
3332e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor  typedef llvm::DenseMap<const Decl *, ForwardRefs>
334134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis      PendingForwardRefsMap;
3352e5c15be82f362611c5928ce853d0685ff98c766Douglas Gregor
336134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  /// \brief Forward references that have a definition but the definition decl
337134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  /// is still initializing. When the definition gets read it will update
338134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  /// the DefinitionData pointer of all pending references.
339134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis  PendingForwardRefsMap PendingForwardRefs;
340134db1fff5653c164ef41c898943521c49f6ebabArgyrios Kyrtzidis
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
3458538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  typedef llvm::DenseMap<serialization::DeclID, serialization::DeclID>
3468538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl      FirstLatestDeclIDMap;
347a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis  /// \brief Map of first declarations from a chained PCH that point to the
3483c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// most recent declarations in another AST file.
349a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis  FirstLatestDeclIDMap FirstLatestDeclIDs;
350a865005c74019184e04f7fcdd4d61c31c095a4ffArgyrios Kyrtzidis
351e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  /// \brief Set of ObjC interfaces that have categories chained to them in
352e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  /// other modules.
353e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  llvm::DenseSet<serialization::GlobalDeclID> ObjCChainedCategoriesInterfaces;
354e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis
355681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl  /// \brief Read the records that describe the contents of declcontexts.
3561a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool ReadDeclContextStorage(ModuleFile &M,
3570d95f77ba180aee35b74f3bf9f8543477f3af543Douglas Gregor                              llvm::BitstreamCursor &Cursor,
358681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl                              const std::pair<uint64_t, uint64_t> &Offsets,
3590d95f77ba180aee35b74f3bf9f8543477f3af543Douglas Gregor                              serialization::DeclContextInfo &Info);
360681d7237e1014bf64dd5ead6bf74ae55cdd19e61Sebastian Redl
3612b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// \brief A vector containing identifiers that have already been
3622b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// loaded.
3632b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  ///
3642b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// If the pointer at index I is non-NULL, then it refers to the
3652b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// IdentifierInfo for the identifier with ID=I+1 that has already
3662b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  /// been loaded.
3672b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  std::vector<IdentifierInfo *> IdentifiersLoaded;
368afaf308b779cd8e8fc8c42601b9f383423c15c2dDouglas Gregor
3691a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
37067268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor    GlobalIdentifierMapType;
371ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
37267268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// \brief Mapping from global identifer IDs to the module in which the
37367268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// identifier resides along with the offset that should be added to the
37467268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  /// global identifier ID to produce a local ID.
37567268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor  GlobalIdentifierMapType GlobalIdentifierMap;
37667268d02388d3d25107fa9cf4998c35246255a65Douglas Gregor
37726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief A vector containing submodules that have already been loaded.
37826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  ///
37926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
38026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// indicate that the particular submodule ID has not yet been loaded.
38126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  SmallVector<Module *, 2> SubmodulesLoaded;
38226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
38326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
38426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor    GlobalSubmoduleMapType;
38526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
38626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Mapping from global submodule IDs to the module file in which the
38726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// submodule resides along with the offset that should be added to the
38826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// global submodule ID to produce a local ID.
38926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  GlobalSubmoduleMapType GlobalSubmoduleMap;
39026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
391ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief A set of hidden declarations.
3921329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  typedef llvm::SmallVector<llvm::PointerUnion<Decl *, IdentifierInfo *>, 2>
3931329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor    HiddenNames;
394ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
395ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
396ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
397ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief A mapping from each of the hidden submodules to the deserialized
398ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// declarations in that submodule that could be made visible.
399ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  HiddenNamesMapType HiddenNamesMap;
400ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
40155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
40255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \brief A module import or export that hasn't yet been resolved.
40355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  struct UnresolvedModuleImportExport {
404af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    /// \brief The file in which this module resides.
405af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    ModuleFile *File;
406af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
40755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief The module that is importing or exporting.
40855988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    Module *Mod;
409af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
410af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor    /// \brief The local ID of the module that is being exported.
41155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned ID;
41255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
41355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief Whether this is an import (vs. an export).
41455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned IsImport : 1;
41555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
41655988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    /// \brief Whether this is a wildcard export.
41755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    unsigned IsWildcard : 1;
418af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor  };
419af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
42055988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \brief The set of module imports and exports that still need to be
42155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// resolved.
42255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  llvm::SmallVector<UnresolvedModuleImportExport, 2>
42355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor    UnresolvedModuleImportExports;
424af13bfc3b40aa4a46f4e71d200ecfb10f45297fcDouglas Gregor
4251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief A vector containing selectors that have already been loaded.
42683941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  ///
42783941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// This vector is indexed by the Selector ID (-1). NULL selector
42883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// entries indicate that the particular selector ID has not yet
42983941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor  /// been loaded.
430686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Selector, 16> SelectorsLoaded;
431725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl
4321a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
43396958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor    GlobalSelectorMapType;
434ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
43596958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// \brief Mapping from global selector IDs to the module in which the
43696958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// selector resides along with the offset that should be added to the
43796958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  /// global selector ID to produce a local ID.
43896958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor  GlobalSelectorMapType GlobalSelectorMap;
43996958cbe6fb423ab2446629ead5f1b138398433cDouglas Gregor
440295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Mapping from identifiers that represent macros whose definitions
441295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// have not yet been deserialized to the global offset where the macro
442295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// record resides.
443295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  llvm::DenseMap<IdentifierInfo *, uint64_t> UnreadMacroRecordOffsets;
4444c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor
4451a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
4464c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    GlobalPreprocessedEntityMapType;
447ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
4484c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Mapping from global preprocessing entity IDs to the module in
4494c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// which the preprocessed entity resides along with the offset that should be
4504c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// added to the global preprocessing entitiy ID to produce a local ID.
4514c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
452ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
453892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name CodeGen-relevant special data
454892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is relevant to CodeGen.
455892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
456892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
457892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all declarations that fulfill the criteria of
458892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// "interesting" decls.
459892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
460892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// This contains the data loaded from all EXTERNAL_DEFINITIONS blocks in the
461892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// chain. The referenced declarations are deserialized and passed to the
462892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// consumer eagerly.
463686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> ExternalDefinitions;
464fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
465892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all tentative definitions stored in the the chain.
466892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
467892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema keeps track of all tentative definitions in a TU because it has to
468892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
469892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// the PCH chain must be eagerly deserialized.
470686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> TentativeDefinitions;
471892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
472892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
473892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// used.
474892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
475892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// CodeGen has to emit VTables for these records, so they have to be eagerly
476892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// deserialized.
477686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> VTableUses;
478892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
479f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// \brief A snapshot of the pending instantiations in the chain.
480f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  ///
481f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// This record tracks the instantiations that Sema has to perform at the
482f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// end of the TU. It consists of a pair of values for every pending
483f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// instantiation where the first value is the ID of the decl and the second
484f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  /// is the instantiation location.
485f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor  SmallVector<uint64_t, 64> PendingInstantiations;
486f2abb52acbba25ad93a1ecdc24d994b9694803a1Douglas Gregor
487892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
488892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
489d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  /// \name DiagnosticsEngine-relevant special data
490892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for generating diagnostics
491892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
492892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
493892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
494892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
495686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
4964c0e86b392c5fb0cb771551fc877edb6979be69cDouglas Gregor
497ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// \brief A list of all the delegating constructors we've seen, to diagnose
498ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt  /// cycles.
499686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> DelegatingCtorDecls;
500ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5018451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// \brief Method selectors used in a @selector expression. Used for
5028451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// implementation of -Wselector.
5038451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  SmallVector<uint64_t, 64> ReferencedSelectorsData;
504ebcbe1d3dc7d4f0c1f540a632fa0684dd0a857d5Sean Hunt
505892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
506892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// generating warnings.
507686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
50814c22f20c077cecd68581952a0c227f8c180be03Douglas Gregor
509892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
510892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
511892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
512686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> ExtVectorDecls;
513b81c17092039f39be60e9656a37cffbdf2e2c783Douglas Gregor
514892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
515d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
516892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \name Sema-relevant special data
517892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief Fields containing data that is used for semantic analysis
518892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@{
519892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
520892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all locally scoped external decls in the chain.
521892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
522892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these to validate that the types are consistent across all
523892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// local external declarations.
524686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
525d455add086f1dfa16ae87dc310e49493bbc2b0a6Argyrios Kyrtzidis
526892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of all dynamic class declarations in the chain.
527892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
528892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks these because it checks for the key functions being defined
529892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// at the end of the TU, in which case it directs CodeGen to emit the VTable.
530686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> DynamicClasses;
531892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
532892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// \brief The IDs of the declarations Sema stores directly.
533892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  ///
534892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  /// Sema tracks a few important decls, such as namespace std, directly.
535686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> SemaDeclRefs;
53676c38d385447b7acdff2d7e6b13fa8580e7174a7Argyrios Kyrtzidis
537e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// \brief The IDs of the types ASTContext stores directly.
538e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
539e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// The AST context tracks a few important types, such as va_list, directly.
540686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 16> SpecialTypes;
541e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl
54214b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
54314b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  ///
54414b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// The AST context tracks a few important decls, currently cudaConfigureCall,
54514b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne  /// directly.
546686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
54714b6ba77710d6431794d65c7d58c6f29c3dc956ePeter Collingbourne
54884bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The floating point pragma option settings.
549686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> FPPragmaOptions;
55084bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
55184bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne  /// \brief The OpenCL extension settings.
552686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 1> OpenCLExtensions;
55384bccea1ad9fd8bc1f4ec3d1fc5dd8d15dabffbcPeter Collingbourne
554d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief A list of the namespaces we've seen.
555686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<uint64_t, 4> KnownNamespaces;
556d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
557f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  /// \brief A list of modules that were imported by precompiled headers or
558f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  /// any other non-module AST file.
559f6137e4d15cb6bbd10547267babfc699c1945873Douglas Gregor  SmallVector<serialization::SubmoduleID, 2> ImportedModules;
560892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl  //@}
561892ac04155aad22f8172d06a929e09cf51e8bc68Sebastian Redl
5623c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The original file name that was used to build the primary AST file,
5633c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// which may have been modified for relocatable-pch support.
564b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  std::string OriginalFileName;
565b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
5663c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The actual original file name that was used to build the primary
5673c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// AST file.
5687b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar  std::string ActualOriginalFileName;
5697b5a1210d93ca62ecd61800f245c87259b1f8f79Daniel Dunbar
57031d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  /// \brief The file ID for the original file that was used to build the
57131d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  /// primary AST file.
57231d375f056447d4e2418275d4913661d3bfedb3eDouglas Gregor  FileID OriginalFileID;
573ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5748e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH was originally created in. Used to
5758e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// allow resolving headers even after headers+PCH was moved to a new path.
5768e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string OriginalDir;
5778e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
5788e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  /// \brief The directory that the PCH we are reading is stored in.
5798e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis  std::string CurrentDir;
5808e3df4d0864f0a966c20088ca1a29c3398b7639dArgyrios Kyrtzidis
581e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \brief Whether this precompiled header is a relocatable PCH file.
582e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  bool RelocatablePCH;
5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
5841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief The system include root to be used when loading the
585e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header.
586832d620b4ae0fc5fe28561b885b4cfc65cf5c9abDouglas Gregor  std::string isysroot;
5871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
588fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// \brief Whether to disable the normal validation performed on precompiled
589fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers when they are loaded.
590fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  bool DisableValidation;
591ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
5928ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \brief Whether to disable the use of stat caches in AST files.
5938ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  bool DisableStatCache;
5948ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor
5953c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Mapping from switch-case IDs in the chain to switch-case statements
596e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  ///
597e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// Statements usually don't have IDs, but switch cases need them, so that the
598e41f985c15d15fce8390ebffb49dc75447c8f0f6Sebastian Redl  /// switch statement can refer to them.
599025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  std::map<unsigned, SwitchCase *> SwitchCaseStmts;
600025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
6014fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// \brief The number of stat() calls that hit/missed the stat
6024fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  /// cache.
6034fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor  unsigned NumStatHits, NumStatMisses;
6044fed3f47f6b9e31d603c5c2d1f6d8ec2e1241e57Douglas Gregor
6057f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief The number of source location entries de-serialized from
6067f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// the PCH file.
6077f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  unsigned NumSLocEntriesRead;
6087f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
6093c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of source location entries in the chain.
610518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl  unsigned TotalNumSLocEntries;
611518d8cb31d26ea098eba79274abbfae1b4976853Sebastian Redl
6123e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The number of statements (and expressions) de-serialized
6133c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// from the chain.
6143e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned NumStatementsRead;
6153e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
6163e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  /// \brief The total number of statements (and expressions) stored
6173c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// in the chain.
6183e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor  unsigned TotalNumStatements;
6193e1af84bb0092a1aafb49deaa4ab6664c9a9071bDouglas Gregor
6203c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The number of macros de-serialized from the chain.
62137e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  unsigned NumMacrosRead;
6222512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
6233c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The total number of macros stored in the chain.
624fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMacros;
625fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
626725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  /// \brief The number of selectors that have been read.
627725cd9686a0f5bb6c994cb3e43f58b63567c6860Sebastian Redl  unsigned NumSelectorsRead;
62883941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
629fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of method pool entries that have been read.
630fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolEntriesRead;
63183941df2745d69c05acee3174c7a265c206f70d9Douglas Gregor
632fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The number of times we have looked up a selector in the method
633fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// pool and not found anything interesting.
634fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned NumMethodPoolMisses;
635fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl
636fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  /// \brief The total number of method pool entries in the selector table.
637fa78dec572259aca763457b435744f79d822c5d4Sebastian Redl  unsigned TotalNumMethodPoolEntries;
63837e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor
6392512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of lexical decl contexts read/total.
6402512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
6412512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor
6422512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  /// Number of visible decl contexts read/total.
6432512308525ff328aa992da0b5ee14a488d2ea93aDouglas Gregor  unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
644ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
6451da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  /// Total size of modules, in bits, currently loaded
6461da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  uint64_t TotalModulesSizeInBits;
6471da901467f72d1733704b068e22089813a1962fdJonathan D. Turner
64829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// \brief Number of Decl/types that are currently deserializing.
64929ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  unsigned NumCurrentElementsDeserializing;
6501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6511da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  /// Number of CXX base specifiers currently loaded
6521da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  unsigned NumCXXBaseSpecifiersLoaded;
6531da901467f72d1733704b068e22089813a1962fdJonathan D. Turner
6541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief An IdentifierInfo that has been loaded but whose top-level
655d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// declarations of the same name have not (yet) been loaded.
656d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  struct PendingIdentifierInfo {
657d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor    IdentifierInfo *II;
658686775deca8b8685eb90801495880e3abdd844c2Chris Lattner    SmallVector<uint32_t, 4> DeclIDs;
659d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  };
6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
6613c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief The set of identifiers that were read while the AST reader was
6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// (recursively) loading declarations.
6631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  ///
664d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// The declarations on the identifier chain for these identifiers will be
665d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  /// loaded once the recursive loading has completed.
666d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor  std::deque<PendingIdentifierInfo> PendingIdentifierInfos;
6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
668c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// \brief Contains declarations and definitions that will be
669c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "interesting" to the ASTConsumer, when we get that AST consumer.
670c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  ///
671c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// "Interesting" declarations are those that have data that may
672c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// need to be emitted, such as inline function definitions or
673c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor  /// Objective-C protocols.
674bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  std::deque<Decl *> InterestingDecls;
675c62a2fe1957626bc4b29402b2d0a3694dfaa3280Douglas Gregor
6760895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// \brief We delay loading of the previous declaration chain to avoid
6770895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// deeply nested calls when there are many redeclarations.
6780895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  std::deque<std::pair<Decl *, serialization::DeclID> > PendingPreviousDecls;
6790895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis
680a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief The list of redeclaration chains that still need to be
681a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// reconstructed.
682a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  ///
683a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// Each element is the global declaration ID of the first declaration in
684a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// the chain. Elements in this vector should be unique; use
685a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// PendingDeclChainsKnown to ensure uniqueness.
686a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  llvm::SmallVector<serialization::DeclID, 16> PendingDeclChains;
687a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
688a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief Keeps track of the elements added to PendingDeclChains.
689a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  llvm::SmallSet<serialization::DeclID, 16> PendingDeclChainsKnown;
690a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
6915a174990e84b33b20761f2fde51169400dd87f2eArgyrios Kyrtzidis  /// \brief We delay loading the chain of objc categories after recursive
6925a174990e84b33b20761f2fde51169400dd87f2eArgyrios Kyrtzidis  /// loading of declarations is finished.
6935a174990e84b33b20761f2fde51169400dd87f2eArgyrios Kyrtzidis  std::vector<std::pair<ObjCInterfaceDecl *, serialization::DeclID> >
6945a174990e84b33b20761f2fde51169400dd87f2eArgyrios Kyrtzidis    PendingChainedObjCCategories;
6955a174990e84b33b20761f2fde51169400dd87f2eArgyrios Kyrtzidis
6960895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  /// \brief Ready to load the previous declaration of the given Decl.
6970895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis  void loadAndAttachPreviousDecl(Decl *D, serialization::DeclID ID);
6980895d1513772eca5a20c552976209fd7f58b993fArgyrios Kyrtzidis
699919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
700686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<Stmt *, 16> StmtStack;
701919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
702919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief What kind of records we are reading.
703919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  enum ReadingKind {
704919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    Read_Decl, Read_Type, Read_Stmt
705919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
706919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
707ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief What kind of records we are reading.
708919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  ReadingKind ReadingKind;
709919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
710919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief RAII object to change the reading kind.
711919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  class ReadingKindTracker {
712c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ASTReader &Reader;
713919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    enum ReadingKind PrevKind;
714919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
715919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker(const ReadingKindTracker&); // do not implement
716919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ReadingKindTracker &operator=(const ReadingKindTracker&);// do not implement
717919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
718919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  public:
719c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
720919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      : Reader(reader), PrevKind(Reader.ReadingKind) {
721919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis      Reader.ReadingKind = newKind;
722919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    }
723919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
724919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
725919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  };
726919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
7273c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief All predefines buffers in the chain, to be treated as if
7287e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  /// concatenated.
7297e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  PCHPredefinesBlocks PCHPredefinesBuffers;
73092b059ea944adaa3e00bb53d63a09868a4752547Douglas Gregor
731e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Suggested contents of the predefines buffer, after this
732e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// PCH file has been processed.
733e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  ///
734e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// In most cases, this string will be empty, because the predefines
735e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// buffer computed to build the PCH file will be identical to the
736e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer computed from the command line. However, when
737e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// there are differences that the PCH reader can work around, this
738e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// predefines buffer may contain additional definitions.
739e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  std::string SuggestedPredefines;
7401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
741919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement from the specified cursor.
7421a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Stmt *ReadStmtFromStream(ModuleFile &F);
743919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis
744b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Get a FileEntry out of stored-in-PCH filename, making sure we take
745b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// into account all the necessary relocations.
746686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  const FileEntry *getFileEntry(StringRef filename);
747b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
748e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  void MaybeAddSystemRootToFilename(std::string &Filename);
7491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
75010bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
7511a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor                            ModuleFile *ImportedBy);
7521a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult ReadASTBlock(ModuleFile &F);
7537e9ad8b4fd446ca7cc0e630edee56d8fcc4553deSebastian Redl  bool CheckPredefinesBuffers();
7541a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool ParseLineTable(ModuleFile &F, SmallVectorImpl<uint64_t> &Record);
7551a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult ReadSourceManagerBlock(ModuleFile &F);
756f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  ASTReadResult ReadSLocEntryRecord(int ID);
757f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  llvm::BitstreamCursor &SLocCursorForID(int ID);
7581a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation getImportLocation(ModuleFile *F);
7591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult ReadSubmoduleBlock(ModuleFile &F);
760686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  bool ParseLanguageOptions(const SmallVectorImpl<uint64_t> &Record);
761392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor
762c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  struct RecordLocation {
7631a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    RecordLocation(ModuleFile *M, uint64_t O)
764c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl      : F(M), Offset(O) {}
7651a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    ModuleFile *F;
766c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl    uint64_t Offset;
767c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  };
768aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl
769393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  QualType readTypeRecord(unsigned Index);
770aaec0aa844781dc7c3462ba140e004e589ccd355Sebastian Redl  RecordLocation TypeCursorForIndex(unsigned Index);
7712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  void LoadedDecl(unsigned Index, Decl *D);
772496c709a6f08f5c502b6f592ddd9ed40f953a5e5Douglas Gregor  Decl *ReadDeclRecord(serialization::DeclID ID);
7739d31fa75bc05fe4cb903a7701550f22cfb73ea8bArgyrios Kyrtzidis  RecordLocation DeclCursorForID(serialization::DeclID ID,
7749d31fa75bc05fe4cb903a7701550f22cfb73ea8bArgyrios Kyrtzidis                                 unsigned &RawLocation);
7756bf2b9fbd3e3adc38d4712de79aeaa81d651aa08Douglas Gregor  void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
776a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  void loadPendingDeclChain(serialization::GlobalDeclID ID);
777e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  void loadObjCChainedCategories(serialization::GlobalDeclID ID,
778e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis                                 ObjCInterfaceDecl *D);
779ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
7808f1231b70c2b1f6fe0cee097b447487b26810301Douglas Gregor  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
7811a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
7822dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
7832dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// \brief Returns the first preprocessed entity ID that ends after \arg BLoc.
7842dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
7852dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findBeginPreprocessedEntity(SourceLocation BLoc) const;
7862dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
787ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Returns the first preprocessed entity ID that begins after \arg
788ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// ELoc.
7892dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
7902dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findEndPreprocessedEntity(SourceLocation ELoc) const;
7912dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
7922dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// \brief \arg SLocMapI points at a chunk of a module that contains no
7932dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// preprocessed entities or the entities it contains are not the ones we are
7942dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// looking for. Find the next module that contains entities and return the ID
7952dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// of the first entry.
7962dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  serialization::PreprocessedEntityID
7972dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis    findNextPreprocessedEntity(
7982dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
7992dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
8001a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  /// \brief Returns (ModuleFile, Local index) pair for \arg GlobalIndex of a
801f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// preprocessed entity.
8021a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  std::pair<ModuleFile *, unsigned>
803f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis    getModulePreprocessedEntity(unsigned GlobalIndex);
804f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis
805bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis  void PassInterestingDeclsToConsumer();
8068d39c3ddfc17d9e768a17eb0ce9f11c33bf9d50aArgyrios Kyrtzidis  void PassInterestingDeclToConsumer(Decl *D);
807bb80a8e8887c1ec74ee135d4ad9455eafedf1508Argyrios Kyrtzidis
808917078386b9b5113f33c093e296e10927b00b37eArgyrios Kyrtzidis  void finishPendingActions();
809917078386b9b5113f33c093e296e10927b00b37eArgyrios Kyrtzidis
810a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// \brief Produce an error diagnostic and return true.
811a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  ///
812a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor  /// This routine should only be used for fatal errors that have to
8133c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// do with non-routine failures (e.g., corrupted AST file).
814686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(StringRef Msg);
815686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
816686775deca8b8685eb90801495880e3abdd844c2Chris Lattner             StringRef Arg2 = StringRef());
817a02b147b66ff9f1a22bac4ec7fd1b0d54a40e5bfDouglas Gregor
818c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader(const ASTReader&); // do not implement
819c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ASTReader &operator=(const ASTReader &); // do not implement
8202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregorpublic:
821686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  typedef SmallVector<uint64_t, 64> RecordData;
8222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
8233c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Load the AST file and validate its contents against the given
82411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  /// Preprocessor.
825e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
826e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param PP the preprocessor associated with the context in which this
827e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// precompiled header will be loaded.
828e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
829e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param Context the AST context that this precompiled header will be
830e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// loaded into.
831e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  ///
832e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// \param isysroot If non-NULL, the system include path specified by the
833e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// user. This is only used with relocatable PCH files. If non-NULL,
834e650c8c3bca2f58cad8ffa8aab63126d26e890cdDouglas Gregor  /// a relocatable PCH file will use the default path "/".
835fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  ///
8363c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \param DisableValidation If true, the AST reader will suppress most
837fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// of its regular consistency checking, allowing the use of precompiled
838fae3b2f4743dad616623c4df2fdb0f5128bd36d9Douglas Gregor  /// headers that cannot be determined to be compatible.
8398ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  ///
8408ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// \param DisableStatCache If true, the AST reader will ignore the
8418ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// stat cache in the AST files. This performance pessimization can
8428ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// help when an AST file is being used in cases where the
8438ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// underlying files in the file system may have changed, but
8448ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor  /// parsing should still continue.
845f8a1e51c48761ee1d7803c3fa35ac94f42ebb55eDouglas Gregor  ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "",
8468ef6c8cb6c5627240e2339fd7062c9873f821d7eDouglas Gregor            bool DisableValidation = false, bool DisableStatCache = false);
8471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
848c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  ~ASTReader();
8492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
8502dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  SourceManager &getSourceManager() const { return SourceMgr; }
851ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
85210bc00fd45824f9b5cd139d63af8b0f6d28aaddaDouglas Gregor  /// \brief Load the AST file designated by the given file name.
85372a9ae18553bf8b6bdad84d2c54f73741a47e275Douglas Gregor  ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type);
8541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
855b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// \brief Checks that no file that is stored in PCH is out-of-sync with
856b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis  /// the actual file in the file system.
8571a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ASTReadResult validateFileEntries(ModuleFile &M);
858b68ffb107a86f5e3851e8108c712b64dd16ba258Argyrios Kyrtzidis
8595e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \brief Make the entities in the given module and any of its (non-explicit)
8605e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// submodules visible to name lookup.
8615e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  ///
8625e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \param Mod The module whose names should be made visible.
8635e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  ///
8645e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// \param Visibility The level of visibility to give the names in the module.
8655e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  /// Visibility can only be increased over time.
8665e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor  void makeModuleVisible(Module *Mod,
8675e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor                         Module::NameVisibilityKind NameVisibility);
8685e35693721364673f8196e4f5a370f56b92e6053Douglas Gregor
869ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief Make the names within this set of hidden names visible.
870ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  void makeNamesVisible(const HiddenNames &Names);
871ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
8723c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST callbacks listener.
873571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setListener(ASTReaderListener *listener) {
87411e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis    Listener.reset(listener);
87511e51106329c550d008fad2c657c053d81611ea8Argyrios Kyrtzidis  }
8761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
8773c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Set the AST deserialization listener.
878571db7f0cb31789737be92fce1c1b738e6dbe795Sebastian Redl  void setDeserializationListener(ASTDeserializationListener *Listener);
87930c514c225342844700ed4640ec6d90ddf0e12b2Sebastian Redl
880359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  /// \brief Initializes the ASTContext
881359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  void InitializeContext();
8822cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
883c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner  /// \brief Add in-memory (virtual file) buffer.
884c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner  void addInMemoryBuffer(StringRef &FileName, llvm::MemoryBuffer *Buffer) {
885c24a1eef40207457692a1ad597cefdd0dc8fa149Jonathan D. Turner    ModuleMgr.addInMemoryBuffer(FileName, Buffer);
886b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis  }
887b0f4b9a558933b307073f7cd7753602f94354ae9Argyrios Kyrtzidis
888ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// \brief Finalizes the AST reader's state before writing an AST file to
889ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// disk.
890ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  ///
891ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// This operation may undo temporary state in the AST that should not be
892ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  /// emitted.
893ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor  void finalizeForWriting();
894ecc2c090e7146c029dd9ee9a5a2fd66b275c01c0Douglas Gregor
895e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  /// \brief Retrieve the module manager.
896e95b9198b8b70ce0219cfb89483b41102e02dbf5Douglas Gregor  ModuleManager &getModuleManager() { return ModuleMgr; }
897e19944c93961b7618f4f3f3185f698f46369ea54Steve Naroff
898d10a381d92a60d4f4c126c4e81045c8ad4636a0bDouglas Gregor  /// \brief Retrieve the preprocessor.
899712f2fcb70ae2eb0cb684d565e7d2cb76881006bDouglas Gregor  Preprocessor &getPreprocessor() const { return PP; }
900ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  /// \brief Retrieve the name of the original source file name
902b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor  const std::string &getOriginalSourceFile() { return OriginalFileName; }
903b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
9043c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the name of the original source file name directly from
9053c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// the AST file, without actually loading the AST file.
9063c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  static std::string getOriginalSourceFile(const std::string &ASTFileName,
907389db16c63eec6ecfa9b235155252d8da766e94eArgyrios Kyrtzidis                                           FileManager &FileMgr,
908d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie                                           DiagnosticsEngine &Diags);
909b64c19365deab788753d29c9bc881253c3f16f37Douglas Gregor
910e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// \brief Returns the suggested contents of the predefines buffer,
911e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// which contains a (typically-empty) subset of the predefines
912e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  /// build prior to including the precompiled header.
913e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
914e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis
915e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// \brief Read a preallocated preprocessed entity from the external source.
916e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  ///
917e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// \returns null if an error occurred that prevented the preprocessed
918e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  /// entity from being loaded.
919e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis  virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index);
920e721f95069d42b899c20c1caabdc6184dd42b820Douglas Gregor
9212dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// \brief Returns a pair of [Begin, End) indices of preallocated
9222dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  /// preprocessed entities that \arg Range encompasses.
9232dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis  virtual std::pair<unsigned, unsigned>
9242dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis      findPreprocessedEntitiesInRange(SourceRange Range);
925ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
926f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// \brief Optionally returns true or false if the preallocated preprocessed
927f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  /// entity with index \arg Index came from file \arg FID.
928f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis  virtual llvm::Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
929f226ff9fe8c8db6c5b74a61ce649eda1491c3502Argyrios Kyrtzidis                                                            FileID FID);
9302dbaca748bc3eb6539f417bd8354c930bdf88fa4Argyrios Kyrtzidis
931cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  /// \brief Read the header file information for the given file entry.
932cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor  virtual HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE);
933cfbf1c7536e016dc275139dd842d4a5f059a749fDouglas Gregor
934d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
935f41d3be39980d40849850d3fb90403623cc8459eArgyrios Kyrtzidis
936f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of source locations found in the chain.
9370fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  unsigned getTotalNumSLocs() const {
9380fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl    return TotalNumSLocEntries;
9390fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl  }
9400fa7d0b15ea2a224bfe43ac745d411f915da87ddSebastian Redl
941f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  /// \brief Returns the number of identifiers found in the chain.
942f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  unsigned getTotalNumIdentifiers() const {
943f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl    return static_cast<unsigned>(IdentifiersLoaded.size());
944f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl  }
945f2f0f03d08c6143137a79a8edffc7d41823bc3c7Sebastian Redl
946e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of types found in the chain.
94777a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumTypes() const {
94877a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(TypesLoaded.size());
94977a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
95077a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
951e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of declarations found in the chain.
95277a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  unsigned getTotalNumDecls() const {
95377a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl    return static_cast<unsigned>(DeclsLoaded.size());
95477a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl  }
95577a3c9ede5cdb26b5eb3001e82bb0a36ca997e1fSebastian Redl
95626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Returns the number of submodules known.
95726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  unsigned getTotalNumSubmodules() const {
95826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor    return static_cast<unsigned>(SubmodulesLoaded.size());
95926ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  }
96026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
961e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Returns the number of selectors found in the chain.
962e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  unsigned getTotalNumSelectors() const {
963e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl    return static_cast<unsigned>(SelectorsLoaded.size());
964e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  }
965e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
9664c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// \brief Returns the number of preprocessed entities known to the AST
9674c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  /// reader.
9684c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  unsigned getTotalNumPreprocessedEntities() const {
9694c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    unsigned Result = 0;
9705d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner    for (ModuleConstIterator I = ModuleMgr.begin(),
9715d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner        E = ModuleMgr.end(); I != E; ++I) {
972e24692b30adbe8144597678a0e3354912e99c747Argyrios Kyrtzidis      Result += (*I)->NumPreprocessedEntities;
9735d6d89fef8c7fff8b1a67c943fb5557a2a803468Jonathan D. Turner    }
974ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9754c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor    return Result;
9764c30bb148b53c8063e940ca3e049ba4d270dc9d5Douglas Gregor  }
977ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
9787c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  /// \brief Returns the number of C++ base specifiers found in the chain.
9791da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  unsigned getTotalNumCXXBaseSpecifiers() const {
9801da901467f72d1733704b068e22089813a1962fdJonathan D. Turner    return NumCXXBaseSpecifiersLoaded;
9811da901467f72d1733704b068e22089813a1962fdJonathan D. Turner  }
982ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
983833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// \brief Reads a TemplateArgumentLocInfo appropriate for the
984833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  /// given TemplateArgument kind.
985833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall  TemplateArgumentLocInfo
9861a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
987833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall                             const RecordData &Record, unsigned &Idx);
988833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall
98944f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis  /// \brief Reads a TemplateArgumentLoc.
990577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl  TemplateArgumentLoc
9911a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ReadTemplateArgumentLoc(ModuleFile &F,
992577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                          const RecordData &Record, unsigned &Idx);
99344f8c37e378f716e8cbb600e3800f437cf58f9e5Argyrios Kyrtzidis
994a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall  /// \brief Reads a declarator info from the given record.
9951a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
996577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                    const RecordData &Record, unsigned &Idx);
997a1ee0c548b8aa4aaf93d1917e304e3da13171a08John McCall
9982cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a type ID into a type, potentially building a new
9992cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// type.
10008538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  QualType GetType(serialization::TypeID ID);
10012cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1002393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// \brief Resolve a local type ID within a given AST file into a type.
10031a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1004ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1005393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// \brief Map a local type ID within a given AST file into a global type ID.
10061a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1007ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1008ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Read a type from the current position in the given record, which
1009393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  /// was read from the given AST file.
10101a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1011393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor    if (Idx >= Record.size())
1012393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor      return QualType();
1013ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1014393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor    return getLocalType(F, Record[Idx++]);
1015393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor  }
1016ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1017ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Map from a local declaration ID within a given module to a
1018409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// global declaration ID.
10191a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::DeclID getGlobalDeclID(ModuleFile &F, unsigned LocalID) const;
1020e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis
1021e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  /// \brief Returns true if global DeclID \arg ID originated from module
1022e6b8d68a927368b06ac06cc9ac9e7f60aa966d5fArgyrios Kyrtzidis  /// \arg M.
10231a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1024dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis
1025dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// \brief Returns the source location for the decl \arg ID.
1026dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1027ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10282cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Resolve a declaration ID into a declaration, potentially
10292cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// building a new declaration.
10308538e8d43a3a9bd439c987c0de37bcbf035dd391Sebastian Redl  Decl *GetDecl(serialization::DeclID ID);
103176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Decl *GetExternalDecl(uint32_t ID);
10322cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
103343fd9388d374f29e908e611a686c6137553efa79Jonathan D. Turner  /// \brief Reads a declaration with the given local ID in the given module.
10341a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1035409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return GetDecl(getGlobalDeclID(F, LocalID));
1036409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1037409448c832d27703146b70a1137d86b020f29863Douglas Gregor
103843fd9388d374f29e908e611a686c6137553efa79Jonathan D. Turner  /// \brief Reads a declaration with the given local ID in the given module.
1039409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1040409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The requested declaration, casted to the given return type.
1041409448c832d27703146b70a1137d86b020f29863Douglas Gregor  template<typename T>
10421a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1043409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1044409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1045409448c832d27703146b70a1137d86b020f29863Douglas Gregor
1046a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \brief Map a global declaration ID into the declaration ID used to
1047a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// refer to this declaration within the given module fule.
1048a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  ///
1049a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// \returns the global ID of the given declaration as known in the given
1050a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  /// module file.
1051a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  serialization::DeclID
1052a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1053a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor                                  serialization::DeclID GlobalID);
1054a1be278c4f3a234ff61f04018d26c6beecde1654Douglas Gregor
1055ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// \brief Reads a declaration ID from the given position in a record in the
1056409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
1057409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1058409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The declaration ID read from the record, adjusted to a global ID.
10591a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1060409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                   unsigned &Idx);
1061ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1062409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \brief Reads a declaration from the given position in a record in the
1063409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
10641a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1065409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return GetDecl(ReadDeclID(F, R, I));
1066409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1067ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1068409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \brief Reads a declaration from the given position in a record in the
1069409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// given module.
1070409448c832d27703146b70a1137d86b020f29863Douglas Gregor  ///
1071409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// \returns The declaration read from this location, casted to the given
1072409448c832d27703146b70a1137d86b020f29863Douglas Gregor  /// result type.
1073409448c832d27703146b70a1137d86b020f29863Douglas Gregor  template<typename T>
10741a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1075409448c832d27703146b70a1137d86b020f29863Douglas Gregor    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1076409448c832d27703146b70a1137d86b020f29863Douglas Gregor  }
1077409448c832d27703146b70a1137d86b020f29863Douglas Gregor
1078e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor  /// \brief Read a CXXBaseSpecifiers ID form the given record and
1079e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor  /// return its global bit offset.
10801a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record,
1081e92b8a1dbba150e213c4980710fcb59ec5c5c570Douglas Gregor                                 unsigned &Idx);
1082ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
10837c789c1a3f77f24032aa0bed2afacdb9e094e952Douglas Gregor  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
1084ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1085250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// \brief Resolve the offset of a statement into a statement.
1086250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  ///
1087250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// This operation will read a new statement from the external
1088250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor  /// source each time it is called, and is meant to be used via a
1089887e2b375fc5e00084ec7bf3dd050c2ca399a6d2Chris Lattner  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
109076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
1091250fc9c859fdeed3f200ae911a7e7ea338f38436Douglas Gregor
10926367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
10936367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// specified cursor.  Read the abbreviations that are at the top of the block
10946367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  /// and then leave the cursor pointing into the block.
10956367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner  bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
10966367f6d06308ef29c28d2c1604ded45625caeec9Chris Lattner
109776bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// \brief Finds all the visible declarations with a given name.
109876bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// The current implementation of this method just loads the entire
109976bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  /// lookup table as unmaterialized references.
110076bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  virtual DeclContext::lookup_result
110176bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  FindExternalVisibleDeclsByName(const DeclContext *DC,
110276bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall                                 DeclarationName Name);
110376bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall
11042cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \brief Read all of the declarations lexically stored in a
11052cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
11062cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11072cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param DC The declaration context whose declarations will be
11082cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// read.
11092cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11102cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \param Decls Vector that will contain the declarations loaded
11112cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// from the external source. The caller is responsible for merging
11122cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// these declarations with any declarations already stored in the
11132cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declaration context.
11142cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  ///
11152cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// \returns true if there was an error while reading the
11162cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  /// declarations for this declaration context.
1117ba6ffaf21e465c0926d7fc5fa294ea52f8d45fafDouglas Gregor  virtual ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1118eb5e9986e577b1e2bff3cca5973a2494fb593fbbArgyrios Kyrtzidis                                        bool (*isKindWeWant)(Decl::Kind),
1119686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                                        SmallVectorImpl<Decl*> &Decls);
11202cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
1121dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// \brief Get the decls that are contained in a file in the Offset/Length
1122dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  /// range. \arg Length can be 0 to indicate a point at \arg Offset instead of
1123ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  /// a range.
1124dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis  virtual void FindFileRegionDecls(FileID File, unsigned Offset,unsigned Length,
1125dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis                                   SmallVectorImpl<Decl *> &Decls);
1126dfb332d0081c6641d1dbae6a2aeff757c99cc740Argyrios Kyrtzidis
1127c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we started deserialization of
112829ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type so until FinishedDeserializing is called there may be
112929ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// decls that are initializing. Must be paired with FinishedDeserializing.
113029ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void StartedDeserializing() { ++NumCurrentElementsDeserializing; }
113129ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1132c43b54cbc10654ed59de797898042e1a05265246Sebastian Redl  /// \brief Notify ASTReader that we finished the deserialization of
113329ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  /// a decl or type. Must be paired with StartedDeserializing.
113429ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis  virtual void FinishedDeserializing();
113529ee3a273f58e16df7f2c524ab62a869e44fc9b1Argyrios Kyrtzidis
1136fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// \brief Function that will be invoked when we begin parsing a new
1137fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// translation unit involving this external AST source.
1138fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  ///
1139fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// This function will provide all of the external definitions to
1140fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  /// the ASTConsumer.
1141fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor  virtual void StartTranslationUnit(ASTConsumer *Consumer);
1142fdd0172ca1b3c837f8c2b37d69cc2085234e09faDouglas Gregor
11433c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Print some statistics about AST usage.
11442cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor  virtual void PrintStats();
11452cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
114623d7df5ce30f4a068e13ad6cb81d473365d260dbDouglas Gregor  /// \brief Dump information about the AST reader to standard error.
114723d7df5ce30f4a068e13ad6cb81d473365d260dbDouglas Gregor  void dump();
1148ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1149e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// Return the amount of memory used by memory buffers, breaking down
1150e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  /// by heap-backed versus mmap'ed memory.
1151e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
1152e9b5f3d4acfc2ad6e8b65a4072464e997dea9ed3Ted Kremenek
1153668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Initialize the semantic source with the Sema instance
1154668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// being used to perform semantic analysis on the abstract syntax
1155668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// tree.
1156668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  virtual void InitializeSema(Sema &S);
1157668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1158ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  /// \brief Inform the semantic consumer that Sema is no longer available.
1159ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar  virtual void ForgetSema() { SemaObj = 0; }
1160ec2a4ed278a1112ebf84fdcb80ed66f53d8ec8baDaniel Dunbar
1161668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the IdentifierInfo for the named identifier.
1162668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  ///
11634d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// This routine builds a new IdentifierInfo for the given identifier. If any
11644d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations with this name are visible from translation unit scope, their
11654d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  /// declarations will be deserialized and introduced into the declaration
116688a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// chain of the identifier.
1167d2598368876cfe40bc8465540033bc5b5e58d8afChris Lattner  virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1168686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  IdentifierInfo *get(StringRef Name) {
11694d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar    return get(Name.begin(), Name.end());
11704d5936aaa4e4e2d41fe79101ac9c09444951448fDaniel Dunbar  }
1171668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
117295f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// \brief Retrieve an iterator into the set of all identifiers
117395f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  /// in all loaded AST files.
117495f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor  virtual IdentifierIterator *getIdentifiers() const;
117595f4292cc526c629fead321c7fcfd4fe0f3bc66eDouglas Gregor
1176f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \brief Load the contents of the global method pool for a given
1177f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// selector.
1178f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  ///
1179f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// \returns a pair of Objective-C methods lists containing the
1180f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor  /// instance and factory methods, respectively, with this selector.
11811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  virtual std::pair<ObjCMethodList, ObjCMethodList>
1182f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor    ReadMethodPool(Selector Sel);
1183f0aaf7a59729a4ae0146e3464ee987745be95829Douglas Gregor
1184d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// \brief Load the set of namespaces that are known to the external source,
1185d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  /// which will be used during typo correction.
1186d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor  virtual void ReadKnownNamespaces(
1187686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                           SmallVectorImpl<NamespaceDecl *> &Namespaces);
1188d8bba9c15230d2b1b3893e272106aa79efc50251Douglas Gregor
1189a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor  virtual void ReadTentativeDefinitions(
1190a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor                 SmallVectorImpl<VarDecl *> &TentativeDefs);
1191a862320972e63349524dc9aa744dec1b95f54ba1Douglas Gregor
1192a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor  virtual void ReadUnusedFileScopedDecls(
1193a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor                 SmallVectorImpl<const DeclaratorDecl *> &Decls);
1194a2ee20aa9660851080135219cac5b31fbac08b78Douglas Gregor
11950129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor  virtual void ReadDelegatingConstructors(
11960129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor                 SmallVectorImpl<CXXConstructorDecl *> &Decls);
11970129b561a1452bf057f6b18b6a1de815d487ab81Douglas Gregor
1198d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor  virtual void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls);
1199d58a0a55e64a7c410a80e9d6dcd899e61e99cc4dDouglas Gregor
1200a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor  virtual void ReadDynamicClasses(SmallVectorImpl<CXXRecordDecl *> &Decls);
1201a126f17ca83b985300c1f65cee647bea108db657Douglas Gregor
1202ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor  virtual void ReadLocallyScopedExternalDecls(
1203ec12ce2f6da44bfc9048772327a3924498099d60Douglas Gregor                 SmallVectorImpl<NamedDecl *> &Decls);
1204ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12055b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor  virtual void ReadReferencedSelectors(
12065b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor                 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels);
12075b9dc7caaef0469babc45dd8e713727a136ce517Douglas Gregor
120831e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor  virtual void ReadWeakUndeclaredIdentifiers(
120931e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor                 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI);
121031e37b2d7b4815fdea6a35d49f33005562f0d494Douglas Gregor
1211dfe6543e12eca5c79421378b7fa6b3e8fc403e63Douglas Gregor  virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
1212dfe6543e12eca5c79421378b7fa6b3e8fc403e63Douglas Gregor
12136e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor  virtual void ReadPendingInstantiations(
1214ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie                 SmallVectorImpl<std::pair<ValueDecl *,
12156e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor                                           SourceLocation> > &Pending);
12166e4a3f5c59664af13e02e9bb58c2810b830e3b96Douglas Gregor
1217e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  /// \brief Load a selector from disk, registering its ID if it exists.
1218e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl  void LoadSelector(Selector Sel);
1219e58aa890e8de55bb3146e6ea9fbbba3a58ce30c6Sebastian Redl
12202b3a5a83ea30bde7fa8f9d8e9a0cb12623759bfbDouglas Gregor  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump  void SetGloballyVisibleDecls(IdentifierInfo *II,
1222686775deca8b8685eb90801495880e3abdd844c2Chris Lattner                               const SmallVectorImpl<uint32_t> &DeclIDs,
1223d89275bc865e2b552836c7b33e636d4f86b8de6dDouglas Gregor                               bool Nonrecursive = false);
12241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12250a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  /// \brief Report a diagnostic.
12260a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor  DiagnosticBuilder Diag(unsigned DiagID);
12270a0428e96c6f1e8bef7a481a9eb69a6f6df38951Douglas Gregor
1228e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  /// \brief Report a diagnostic.
1229e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1230e1d918e9fe55e3b34401fd5d420c47ea0f9572c9Douglas Gregor
123195eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12331a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
123495eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor                                    unsigned &Idx) {
123595eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
12367356a31327be9b3c3434a0c88746028980da5684Chris Lattner  }
12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
123895eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor  virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) {
12398c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor    return DecodeIdentifierInfo(ID);
12408c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor  }
12418c5a760b82e73ed90b560090772db97e2ae27b09Douglas Gregor
12421a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1243ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12441a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
124595eab176f51beed44a9bc14c0dcdd37844b23740Douglas Gregor                                                    unsigned LocalID);
1246ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12477f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor  /// \brief Read the source location entry with index ID.
1248f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor  virtual bool ReadSLocEntry(int ID);
12497f94b0b0c6791013d2f72ced9b4bedd3b23673a6Douglas Gregor
125026ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Retrieve the global submodule ID given a module and its local ID
125126ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// number.
125226ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  serialization::SubmoduleID
125326ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
125426ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
125526ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  /// \brief Retrieve the submodule that corresponds to a global submodule ID.
125626ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  ///
125726ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor  Module *getSubmodule(serialization::SubmoduleID GlobalID);
125826ced127b7d443fcf3472463c9f39c2376bd9d70Douglas Gregor
12592d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  /// \brief Retrieve a selector from the given module with its local ID
12602d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  /// number.
12611a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
12622d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor
12632d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor  Selector DecodeSelector(serialization::SelectorID Idx);
12641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
12658451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  virtual Selector GetExternalSelector(serialization::SelectorID ID);
126676bd1f387e6a7b7abfe53f63b3bd429b97bb80f0John McCall  uint32_t GetNumExternalSelectors();
1267719770dcfcb3987e8a2377dcca97955301445eb5Douglas Gregor
12681a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
12692d2689ab787c6d54cb985c28ff3f16370bc01b0fDouglas Gregor    return getLocalSelector(M, Record[Idx++]);
127090cd1bb1baac2a0221f3642de0cbea3244b116e5Steve Naroff  }
1271ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
12728451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// \brief Retrieve the global selector ID that corresponds to this
12738451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor  /// the local selector ID in a given module.
12741a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
12758451ec7e709baf777bec07dc70653e0c523dd120Douglas Gregor                                                unsigned LocalID) const;
12766ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
12776ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a declaration name.
12781a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  DeclarationName ReadDeclarationName(ModuleFile &F,
1279393f249399fe30e9580e1529a7479489e90f3a57Douglas Gregor                                      const RecordData &Record, unsigned &Idx);
12801a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadDeclarationNameLoc(ModuleFile &F,
12814045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              DeclarationNameLoc &DNLoc, DeclarationName Name,
12824045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                              const RecordData &Record, unsigned &Idx);
12831a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
12844045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                               const RecordData &Record, unsigned &Idx);
12854045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis
12861a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
12874045107b7384fd68eed5e3e2f06fc2a47e7be0a6Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
12880a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
12891a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1290409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                               const RecordData &Record,
12916ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner                                               unsigned &Idx);
12926ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
12931a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1294dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    const RecordData &Record,
1295dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor                                                    unsigned &Idx);
1296dc355713be51fcb4ee52d9fd6b4548ceff47fadfDouglas Gregor
12978731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template name.
12981a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
12991aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor                                unsigned &Idx);
13008731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
13018731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis  /// \brief Read a template argument.
13021a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateArgument ReadTemplateArgument(ModuleFile &F,
1303577d4796d358c0e72ebaa023113505226ab51b4fSebastian Redl                                        const RecordData &Record,unsigned &Idx);
1304ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1305dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template parameter list.
13061a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1307c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                                   const RecordData &Record,
1308dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis                                                   unsigned &Idx);
1309ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1310dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  /// \brief Read a template argument array.
1311dd41c14bfd7686b556de2acf6952e21a4f80b7aaArgyrios Kyrtzidis  void
1312686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  ReadTemplateArgumentList(SmallVector<TemplateArgument, 8> &TemplArgs,
13131a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor                           ModuleFile &F, const RecordData &Record,
1314c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                           unsigned &Idx);
13158731ca76acf81826df7048bffd0c44c7c0f96c7fArgyrios Kyrtzidis
131637ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis  /// \brief Read a UnresolvedSet structure.
13171a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set,
131837ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis                         const RecordData &Record, unsigned &Idx);
131937ffed3b7f229844cae2463ff82b527506c86c74Argyrios Kyrtzidis
13200745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis  /// \brief Read a C++ base specifier.
13211a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
13225606220447c7901ba8d80147ddab893bb7949dd5Nick Lewycky                                        const RecordData &Record,unsigned &Idx);
13230745d0a648b75bd304045309276c70a755adaafbArgyrios Kyrtzidis
1324cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  /// \brief Read a CXXCtorInitializer array.
1325cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt  std::pair<CXXCtorInitializer **, unsigned>
13261a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
1327cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt                          unsigned &Idx);
13288e706f4b8da141612861e127610141b8d17a9667Argyrios Kyrtzidis
1329c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  /// \brief Read a source location from raw form.
13301a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
13315a4374812c56aa60672e291b07e14d3696bbb5a6Argyrios Kyrtzidis    SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
13321a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() &&
1333f62d43d2afe1960755a1b5813cae1e5983bcac1bDouglas Gregor           "Cannot find offset to remap.");
13341a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
1335a64ccefdf0ea4e03ec88805d71b0af74950c7472Argyrios Kyrtzidis    return Loc.getLocWithOffset(Remap);
1336c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl  }
1337c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl
13386ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source location.
13391a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
1340c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                                    const RecordData &Record, unsigned& Idx) {
13411a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor    return ReadSourceLocation(ModuleFile, Record[Idx++]);
13426ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  }
13436ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13446ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner  /// \brief Read a source range.
13451a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  SourceRange ReadSourceRange(ModuleFile &F,
1346c3632730cc83ed7b51f0ab5c38997ae5a9439b0cSebastian Redl                              const RecordData &Record, unsigned& Idx);
13476ad9ac097918fbdeb443ea7b99d4db9e49b28534Chris Lattner
13480a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read an integral value
13490a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
13500a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor
13510a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  /// \brief Read a signed integral value
13520a2b45e5885b6b8477b167042c0f6cd1d99a1f13Douglas Gregor  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
13533a2f7e42514ddbec983c61826ce85d3071e23e8eDouglas Gregor
135417fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  /// \brief Read a floating-point value
135517fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor  llvm::APFloat ReadAPFloat(const RecordData &Record, unsigned &Idx);
135617fc223395d51be582fc666bb6ea21bd1dff26dcDouglas Gregor
135768a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  // \brief Read a string
135868a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  std::string ReadString(const RecordData &Record, unsigned &Idx);
135968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
13600a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  /// \brief Read a version tuple.
13610a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor  VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
13620a0d2b179085a52c10402feebeb6db8b4d96a140Douglas Gregor
13631a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
1364409448c832d27703146b70a1137d86b020f29863Douglas Gregor                                 unsigned &Idx);
1365ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
136668a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor  /// \brief Reads attributes from the current stream position.
13671a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
13684eb9fc0449ddbd5239ddc3ae6b6e52880f47dcf7Argyrios Kyrtzidis                      const RecordData &Record, unsigned &Idx);
136968a2eb0cc76267ba0615992fb5e0977853c397b2Douglas Gregor
1370919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads a statement.
13711a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Stmt *ReadStmt(ModuleFile &F);
13720b7489194f9f89fac39d57211c1e7953ae50251fDouglas Gregor
1373919e693e80632d214c1f3110f6ee5d1c0b61f06bArgyrios Kyrtzidis  /// \brief Reads an expression.
13741a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  Expr *ReadExpr(ModuleFile &F);
1375c9490c000f515c29f200a1215328d8ab9a0f3818Douglas Gregor
1376d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-statement operand during statement reading.
1377d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Stmt *ReadSubStmt() {
1378d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(ReadingKind == Read_Stmt &&
1379d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis           "Should be called only during statement reading!");
1380d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // Subexpressions are stored from last to first, so the next Stmt we need
1381d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    // is at the back of the stack.
1382d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    assert(!StmtStack.empty() && "Read too many sub statements!");
1383d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis    return StmtStack.pop_back_val();
1384d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  }
1385d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
1386d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  /// \brief Reads a sub-expression operand during statement reading.
1387d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis  Expr *ReadSubExpr();
1388d98a2ab9275f896df49e42ea4e4b8871610e0f45Argyrios Kyrtzidis
138937e2684abfe38207fdb90620da062bb18c23f29aDouglas Gregor  /// \brief Reads the macro record located at the given offset.
13901a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  void ReadMacroRecord(ModuleFile &F, uint64_t Offset);
1391ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
139286c67d8802a9e0887c31c850188991465ac3c1bdDouglas Gregor  /// \brief Determine the global preprocessed entity ID that corresponds to
139386c67d8802a9e0887c31c850188991465ac3c1bdDouglas Gregor  /// the given local ID within the given module.
1394ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie  serialization::PreprocessedEntityID
13951a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
1396ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
1397295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Note that the identifier is a macro whose record will be loaded
1398295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// from the given AST file at the given (file-local) offset.
13991329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14001329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param II The name of the macro.
14011329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14021329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param F The module file from which the macro definition was deserialized.
14031329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14041329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param Offset The offset into the module file at which the macro
14051329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// definition is located.
14061329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  ///
14071329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  /// \param Visible Whether the macro should be made visible.
14081329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor  void setIdentifierIsMacro(IdentifierInfo *II, ModuleFile &F,
14091329264ce0922b3cec8c8c599108f082105fa0e1Douglas Gregor                            uint64_t Offset, bool Visible);
1410ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
141188a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  /// \brief Read the set of macros defined by this external macro source.
141288a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor  virtual void ReadDefinedMacros();
141388a35862fbe473f2a4f0c19f24dbe536937e1dc6Douglas Gregor
1414295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Read the macro definition for this identifier.
1415295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  virtual void LoadMacroDefinition(IdentifierInfo *II);
1416295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor
1417eee242ff426bf79149f221798966e58688383c1eDouglas Gregor  /// \brief Update an out-of-date identifier.
1418eee242ff426bf79149f221798966e58688383c1eDouglas Gregor  virtual void updateOutOfDateIdentifier(IdentifierInfo &II);
1419eee242ff426bf79149f221798966e58688383c1eDouglas Gregor
1420295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// \brief Read the macro definition corresponding to this iterator
1421295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  /// into the unread macro record offsets table.
1422295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor  void LoadMacroDefinition(
1423295a2a617ac335f590e430ab7fcd98f8ce109251Douglas Gregor                     llvm::DenseMap<IdentifierInfo *, uint64_t>::iterator Pos);
1424ba243b59a1074e0962f6abfa3bb9aa984eac1245David Blaikie
14253c7f4134603d04b44f997b43c0a9def270f25386Sebastian Redl  /// \brief Retrieve the AST context that this AST reader supplements.
1426359427794704666ff7a5a933ace11c5256fa3af7Douglas Gregor  ASTContext &getContext() { return Context; }
1427025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
14286cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // \brief Contains declarations that were loaded before we have
14296cfc1a8b7582b8433b61222502effb018c534393Douglas Gregor  // access to a Sema object.
1430686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<NamedDecl *, 16> PreloadedDecls;
1431668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1432668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the semantic analysis object used to analyze the
1433668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// translation unit in which the precompiled header is being
1434668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// imported.
1435668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  Sema *getSema() { return SemaObj; }
1436668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1437668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// \brief Retrieve the identifier table associated with the
1438668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  /// preprocessor.
1439668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor  IdentifierTable &getIdentifierTable();
1440668c1a4fdcc56bdd050256b1688e116fe84b72dbDouglas Gregor
1441025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Record that the given ID maps to the given switch-case
1442025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// statement.
1443025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
1444025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor
1445025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  /// \brief Retrieve the switch-case statement with the given ID.
1446025452fa0eda63e150cfaeebe64f0a19c96b3a06Douglas Gregor  SwitchCase *getSwitchCaseWithID(unsigned ID);
14471de05feeeafe5b215fe7617594a7076a5192a6e2Douglas Gregor
1448e09a275444576deb2c8d9e2255554242f65d7c00Argyrios Kyrtzidis  void ClearSwitchCaseIDs();
14492cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor};
14502cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
145102602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// \brief Helper class that saves the current stream position and
145202602be3ccc3b29da5b91d2502c3419404992409Chris Lattner/// then restores it when destroyed.
145302602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerstruct SavedStreamPosition {
145402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
145502602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
14561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
145702602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  ~SavedStreamPosition() {
145802602be3ccc3b29da5b91d2502c3419404992409Chris Lattner    Cursor.JumpToBit(Offset);
145902602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  }
14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
146102602be3ccc3b29da5b91d2502c3419404992409Chris Lattnerprivate:
146202602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  llvm::BitstreamCursor &Cursor;
146302602be3ccc3b29da5b91d2502c3419404992409Chris Lattner  uint64_t Offset;
146402602be3ccc3b29da5b91d2502c3419404992409Chris Lattner};
14651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
1466d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenekinline void PCHValidator::Error(const char *Msg) {
1467d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek  Reader.Error(Msg);
1468d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek}
1469d5d7b3f61f82b0fed9d6f02839bc72e528332911Ted Kremenek
14702cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor} // end namespace clang
14712cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor
14722cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor#endif
1473